From c0ac84fdbd36bcfd6b08ccaccbd04adf6b1becf7 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 3 Feb 2017 17:38:17 -0800 Subject: [PATCH] Give a better name for the boolean variable; emit __esmodule for export import --- src/compiler/transformers/module/module.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 68f49dba42c..ebd004337f9 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -45,7 +45,7 @@ namespace ts { let currentSourceFile: SourceFile; // The current file. let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file. let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored. - let shouldAppendUnderscoreUnderscoreEsModule: boolean; // A boolean indicating whether "__esModule" should be emitted + let shouldAppendEsModuleMarker: boolean; // A boolean indicating whether "__esModule" should be emitted return transformSourceFile; @@ -63,7 +63,7 @@ namespace ts { currentSourceFile = node; currentModuleInfo = collectExternalModuleInfo(node, resolver, compilerOptions); - shouldAppendUnderscoreUnderscoreEsModule = false; + shouldAppendEsModuleMarker = false; moduleInfoMap[getOriginalNodeId(node)] = currentModuleInfo; // Perform the transformation. @@ -90,7 +90,7 @@ namespace ts { addRange(statements, endLexicalEnvironment()); addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false); - if (shouldAppendUnderscoreUnderscoreEsModule) { + if (shouldAppendEsModuleMarker) { append(statements, createUnderscoreUnderscoreESModule()); } @@ -383,7 +383,7 @@ namespace ts { // Append the 'export =' statement if provided. addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true); - if (shouldAppendUnderscoreUnderscoreEsModule) { + if (shouldAppendEsModuleMarker) { append(statements, createUnderscoreUnderscoreESModule()); } @@ -666,7 +666,7 @@ namespace ts { } const generatedName = getGeneratedNameForNode(node); - shouldAppendUnderscoreUnderscoreEsModule = true; + shouldAppendEsModuleMarker = true; if (node.exportClause) { const statements: Statement[] = []; @@ -833,9 +833,10 @@ namespace ts { let expressions: Expression[]; const parseTreeNode = getParseTreeNode(node); - if (!shouldAppendUnderscoreUnderscoreEsModule) { + if (parseTreeNode && !shouldAppendEsModuleMarker) { // class declaration get down-level transformed to be variable statement - shouldAppendUnderscoreUnderscoreEsModule = (parseTreeNode.kind === SyntaxKind.VariableStatement || parseTreeNode.kind === SyntaxKind.ClassDeclaration) && hasModifier(parseTreeNode, ModifierFlags.Export); + shouldAppendEsModuleMarker = (parseTreeNode.kind === SyntaxKind.VariableStatement || parseTreeNode.kind === SyntaxKind.ClassDeclaration || parseTreeNode.kind === SyntaxKind.ImportEqualsDeclaration) + && hasModifier(parseTreeNode, ModifierFlags.Export); } if (hasModifier(node, ModifierFlags.Export)) { @@ -1125,7 +1126,7 @@ namespace ts { * @param allowComments Whether to allow comments on the export. */ function appendExportStatement(statements: Statement[] | undefined, exportName: Identifier, expression: Expression, location?: TextRange, allowComments?: boolean): Statement[] | undefined { - shouldAppendUnderscoreUnderscoreEsModule = true; + shouldAppendEsModuleMarker = true; statements = append(statements, createExportStatement(exportName, expression, location, allowComments)); return statements; }