@@ -45,7 +45,7 @@ namespace ts {
4545 let currentSourceFile : SourceFile ; // The current file.
4646 let currentModuleInfo : ExternalModuleInfo ; // The ExternalModuleInfo for the current file.
4747 let noSubstitution : boolean [ ] ; // Set of nodes for which substitution rules should be ignored.
48- let shouldAppendUnderscoreUnderscoreEsModule : boolean ; // A boolean indicating whether "__esModule" should be emitted
48+ let shouldAppendEsModuleMarker : boolean ; // A boolean indicating whether "__esModule" should be emitted
4949
5050 return transformSourceFile ;
5151
@@ -63,7 +63,7 @@ namespace ts {
6363
6464 currentSourceFile = node ;
6565 currentModuleInfo = collectExternalModuleInfo ( node , resolver , compilerOptions ) ;
66- shouldAppendUnderscoreUnderscoreEsModule = false ;
66+ shouldAppendEsModuleMarker = false ;
6767 moduleInfoMap [ getOriginalNodeId ( node ) ] = currentModuleInfo ;
6868
6969 // Perform the transformation.
@@ -90,7 +90,7 @@ namespace ts {
9090 addRange ( statements , endLexicalEnvironment ( ) ) ;
9191 addExportEqualsIfNeeded ( statements , /*emitAsReturn*/ false ) ;
9292
93- if ( shouldAppendUnderscoreUnderscoreEsModule ) {
93+ if ( shouldAppendEsModuleMarker ) {
9494 append ( statements , createUnderscoreUnderscoreESModule ( ) ) ;
9595 }
9696
@@ -383,7 +383,7 @@ namespace ts {
383383 // Append the 'export =' statement if provided.
384384 addExportEqualsIfNeeded ( statements , /*emitAsReturn*/ true ) ;
385385
386- if ( shouldAppendUnderscoreUnderscoreEsModule ) {
386+ if ( shouldAppendEsModuleMarker ) {
387387 append ( statements , createUnderscoreUnderscoreESModule ( ) ) ;
388388 }
389389
@@ -666,7 +666,7 @@ namespace ts {
666666 }
667667
668668 const generatedName = getGeneratedNameForNode ( node ) ;
669- shouldAppendUnderscoreUnderscoreEsModule = true ;
669+ shouldAppendEsModuleMarker = true ;
670670
671671 if ( node . exportClause ) {
672672 const statements : Statement [ ] = [ ] ;
@@ -833,9 +833,10 @@ namespace ts {
833833 let expressions : Expression [ ] ;
834834
835835 const parseTreeNode = getParseTreeNode ( node ) ;
836- if ( ! shouldAppendUnderscoreUnderscoreEsModule ) {
836+ if ( parseTreeNode && ! shouldAppendEsModuleMarker ) {
837837 // class declaration get down-level transformed to be variable statement
838- shouldAppendUnderscoreUnderscoreEsModule = ( parseTreeNode . kind === SyntaxKind . VariableStatement || parseTreeNode . kind === SyntaxKind . ClassDeclaration ) && hasModifier ( parseTreeNode , ModifierFlags . Export ) ;
838+ shouldAppendEsModuleMarker = ( parseTreeNode . kind === SyntaxKind . VariableStatement || parseTreeNode . kind === SyntaxKind . ClassDeclaration || parseTreeNode . kind === SyntaxKind . ImportEqualsDeclaration )
839+ && hasModifier ( parseTreeNode , ModifierFlags . Export ) ;
839840 }
840841
841842 if ( hasModifier ( node , ModifierFlags . Export ) ) {
@@ -1125,7 +1126,7 @@ namespace ts {
11251126 * @param allowComments Whether to allow comments on the export.
11261127 */
11271128 function appendExportStatement ( statements : Statement [ ] | undefined , exportName : Identifier , expression : Expression , location ?: TextRange , allowComments ?: boolean ) : Statement [ ] | undefined {
1128- shouldAppendUnderscoreUnderscoreEsModule = true ;
1129+ shouldAppendEsModuleMarker = true ;
11291130 statements = append ( statements , createExportStatement ( exportName , expression , location , allowComments ) ) ;
11301131 return statements ;
11311132 }
0 commit comments