@@ -5429,17 +5429,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
54295429 ( ! isExternalModule ( currentSourceFile ) && resolver . isTopLevelValueImportEqualsWithEntityName ( node ) ) ) {
54305430 emitLeadingComments ( node ) ;
54315431 emitStart ( node ) ;
5432- if ( isES6ExportedDeclaration ( node ) ) {
5433- write ( "export " ) ;
5434- write ( "var " ) ;
5432+
5433+ // variable declaration for import-equals declaration can be hoisted in system modules
5434+ // in this case 'var' should be omitted and emit should contain only initialization
5435+ let variableDeclarationIsHoisted = shouldHoistVariable ( node , /*checkIfSourceFileLevelDecl*/ true ) ;
5436+
5437+ // is it top level export import v = a.b.c in system module?
5438+ // if yes - it needs to be rewritten as exporter('v', v = a.b.c)
5439+ let isExported = isSourceFileLevelDeclarationInSystemJsModule ( node , /*isExported*/ true ) ;
5440+
5441+ if ( ! variableDeclarationIsHoisted ) {
5442+ Debug . assert ( ! isExported ) ;
5443+
5444+ if ( isES6ExportedDeclaration ( node ) ) {
5445+ write ( "export " ) ;
5446+ write ( "var " ) ;
5447+ }
5448+ else if ( ! ( node . flags & NodeFlags . Export ) ) {
5449+ write ( "var " ) ;
5450+ }
54355451 }
5436- else if ( ! ( node . flags & NodeFlags . Export ) ) {
5437- write ( "var " ) ;
5452+
5453+
5454+ if ( isExported ) {
5455+ write ( `${ exportFunctionForFile } ("` ) ;
5456+ emitNodeWithoutSourceMap ( node . name ) ;
5457+ write ( `", ` ) ;
54385458 }
5459+
54395460 emitModuleMemberName ( node ) ;
54405461 write ( " = " ) ;
54415462 emit ( node . moduleReference ) ;
5442- write ( ";" ) ;
5463+
5464+ if ( isExported ) {
5465+ write ( ")" ) ;
5466+ }
5467+
5468+ write ( ";" ) ;
54435469 emitEnd ( node ) ;
54445470 emitExportImportAssignments ( node ) ;
54455471 emitTrailingComments ( node ) ;
@@ -5965,6 +5991,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
59655991 }
59665992 return ;
59675993 }
5994+
5995+ if ( isInternalModuleImportEqualsDeclaration ( node ) ) {
5996+ if ( ! hoistedVars ) {
5997+ hoistedVars = [ ] ;
5998+ }
5999+
6000+ hoistedVars . push ( node . name ) ;
6001+ return ;
6002+ }
59686003
59696004 if ( isBindingPattern ( node ) ) {
59706005 forEach ( ( < BindingPattern > node ) . elements , visit ) ;
@@ -6169,14 +6204,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
61696204 writeLine ( ) ;
61706205 for ( let i = startIndex ; i < node . statements . length ; ++ i ) {
61716206 let statement = node . statements [ i ] ;
6172- // - imports/exports are not emitted for system modules
6207+ // - external module related imports/exports are not emitted for system modules
61736208 // - function declarations are not emitted because they were already hoisted
61746209 switch ( statement . kind ) {
61756210 case SyntaxKind . ExportDeclaration :
61766211 case SyntaxKind . ImportDeclaration :
6177- case SyntaxKind . ImportEqualsDeclaration :
61786212 case SyntaxKind . FunctionDeclaration :
61796213 continue ;
6214+ case SyntaxKind . ImportEqualsDeclaration :
6215+ if ( ! isInternalModuleImportEqualsDeclaration ( statement ) ) {
6216+ continue ;
6217+ }
61806218 }
61816219 writeLine ( ) ;
61826220 emit ( statement ) ;
0 commit comments