Skip to content

Commit bc68604

Browse files
author
Kanchalai Tanglertsampan
committed
Always emit "__esModule" unless there is export =
1 parent eedc465 commit bc68604

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ 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 shouldAppendEsModuleMarker: boolean; // A boolean indicating whether "__esModule" should be emitted
4948

5049
return transformSourceFile;
5150

@@ -63,7 +62,6 @@ namespace ts {
6362

6463
currentSourceFile = node;
6564
currentModuleInfo = collectExternalModuleInfo(node, resolver, compilerOptions);
66-
shouldAppendEsModuleMarker = false;
6765
moduleInfoMap[getOriginalNodeId(node)] = currentModuleInfo;
6866

6967
// Perform the transformation.
@@ -90,7 +88,7 @@ namespace ts {
9088
addRange(statements, endLexicalEnvironment());
9189
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
9290

93-
if (shouldAppendEsModuleMarker) {
91+
if (!currentModuleInfo.exportEquals) {
9492
append(statements, createUnderscoreUnderscoreESModule());
9593
}
9694

@@ -387,7 +385,7 @@ namespace ts {
387385
// Append the 'export =' statement if provided.
388386
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true);
389387

390-
if (shouldAppendEsModuleMarker) {
388+
if (!currentModuleInfo.exportEquals) {
391389
append(statements, createUnderscoreUnderscoreESModule());
392390
}
393391

@@ -674,7 +672,6 @@ namespace ts {
674672
}
675673

676674
const generatedName = getGeneratedNameForNode(node);
677-
shouldAppendEsModuleMarker = true;
678675

679676
if (node.exportClause) {
680677
const statements: Statement[] = [];
@@ -850,13 +847,6 @@ namespace ts {
850847
let variables: VariableDeclaration[];
851848
let expressions: Expression[];
852849

853-
const parseTreeNode = getParseTreeNode(node);
854-
if (parseTreeNode && !shouldAppendEsModuleMarker) {
855-
// class declaration get down-level transformed to be variable statement
856-
shouldAppendEsModuleMarker = (parseTreeNode.kind === SyntaxKind.VariableStatement || parseTreeNode.kind === SyntaxKind.ClassDeclaration || parseTreeNode.kind === SyntaxKind.ImportEqualsDeclaration)
857-
&& hasModifier(parseTreeNode, ModifierFlags.Export);
858-
}
859-
860850
if (hasModifier(node, ModifierFlags.Export)) {
861851
let modifiers: NodeArray<Modifier>;
862852

@@ -1146,7 +1136,6 @@ namespace ts {
11461136
* @param allowComments Whether to allow comments on the export.
11471137
*/
11481138
function appendExportStatement(statements: Statement[] | undefined, exportName: Identifier, expression: Expression, location?: TextRange, allowComments?: boolean): Statement[] | undefined {
1149-
shouldAppendEsModuleMarker = true;
11501139
statements = append(statements, createExportStatement(exportName, expression, location, allowComments));
11511140
return statements;
11521141
}

0 commit comments

Comments
 (0)