Skip to content

Commit ed071a9

Browse files
author
Kanchalai Tanglertsampan
committed
Only emit ESModule marker when there is no export equal and the file is external module
1 parent 3295ca3 commit ed071a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ namespace ts {
5555
* @param node The SourceFile node.
5656
*/
5757
function transformSourceFile(node: SourceFile) {
58-
if (isDeclarationFile(node)
59-
|| !(isExternalModule(node)
60-
|| compilerOptions.isolatedModules)) {
58+
if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules)) {
6159
return node;
6260
}
6361

@@ -74,6 +72,14 @@ namespace ts {
7472
return aggregateTransformFlags(updated);
7573
}
7674

75+
76+
function shouldEmitUnderscoreUnderscoreESModule() {
77+
if (!currentModuleInfo.exportEquals && isExternalModule(currentSourceFile)) {
78+
return true;
79+
}
80+
return false;
81+
}
82+
7783
/**
7884
* Transforms a SourceFile into a CommonJS module.
7985
*
@@ -85,7 +91,7 @@ namespace ts {
8591
const statements: Statement[] = [];
8692
const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, sourceElementVisitor);
8793

88-
if (!currentModuleInfo.exportEquals) {
94+
if (shouldEmitUnderscoreUnderscoreESModule()) {
8995
append(statements, createUnderscoreUnderscoreESModule());
9096
}
9197

@@ -378,7 +384,7 @@ namespace ts {
378384
const statements: Statement[] = [];
379385
const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, sourceElementVisitor);
380386

381-
if (!currentModuleInfo.exportEquals) {
387+
if (shouldEmitUnderscoreUnderscoreESModule()) {
382388
append(statements, createUnderscoreUnderscoreESModule());
383389
}
384390

0 commit comments

Comments
 (0)