@@ -5429,17 +5429,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5429
5429
( ! isExternalModule ( currentSourceFile ) && resolver . isTopLevelValueImportEqualsWithEntityName ( node ) ) ) {
5430
5430
emitLeadingComments ( node ) ;
5431
5431
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
+ }
5435
5451
}
5436
- else if ( ! ( node . flags & NodeFlags . Export ) ) {
5437
- write ( "var " ) ;
5452
+
5453
+
5454
+ if ( isExported ) {
5455
+ write ( `${ exportFunctionForFile } ("` ) ;
5456
+ emitNodeWithoutSourceMap ( node . name ) ;
5457
+ write ( `", ` ) ;
5438
5458
}
5459
+
5439
5460
emitModuleMemberName ( node ) ;
5440
5461
write ( " = " ) ;
5441
5462
emit ( node . moduleReference ) ;
5442
- write ( ";" ) ;
5463
+
5464
+ if ( isExported ) {
5465
+ write ( ")" ) ;
5466
+ }
5467
+
5468
+ write ( ";" ) ;
5443
5469
emitEnd ( node ) ;
5444
5470
emitExportImportAssignments ( node ) ;
5445
5471
emitTrailingComments ( node ) ;
@@ -5965,6 +5991,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
5965
5991
}
5966
5992
return ;
5967
5993
}
5994
+
5995
+ if ( isInternalModuleImportEqualsDeclaration ( node ) ) {
5996
+ if ( ! hoistedVars ) {
5997
+ hoistedVars = [ ] ;
5998
+ }
5999
+
6000
+ hoistedVars . push ( node . name ) ;
6001
+ return ;
6002
+ }
5968
6003
5969
6004
if ( isBindingPattern ( node ) ) {
5970
6005
forEach ( ( < BindingPattern > node ) . elements , visit ) ;
@@ -6169,14 +6204,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
6169
6204
writeLine ( ) ;
6170
6205
for ( let i = startIndex ; i < node . statements . length ; ++ i ) {
6171
6206
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
6173
6208
// - function declarations are not emitted because they were already hoisted
6174
6209
switch ( statement . kind ) {
6175
6210
case SyntaxKind . ExportDeclaration :
6176
6211
case SyntaxKind . ImportDeclaration :
6177
- case SyntaxKind . ImportEqualsDeclaration :
6178
6212
case SyntaxKind . FunctionDeclaration :
6179
6213
continue ;
6214
+ case SyntaxKind . ImportEqualsDeclaration :
6215
+ if ( ! isInternalModuleImportEqualsDeclaration ( statement ) ) {
6216
+ continue ;
6217
+ }
6180
6218
}
6181
6219
writeLine ( ) ;
6182
6220
emit ( statement ) ;
0 commit comments