From 43051eab84e093ac4a20f9db60c85d04e83f7bf3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 8 Apr 2016 14:29:16 -0700 Subject: [PATCH] emit export star only if export will yield anything with value side --- src/compiler/transformers/module/module.ts | 12 ++++++------ src/compiler/transformers/module/system.ts | 8 ++++---- src/compiler/utilities.ts | 10 ++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index ad6fd2000fb..440aec62e3b 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -31,7 +31,7 @@ namespace ts { let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; let exportSpecifiers: Map; let exportEquals: ExportAssignment; - let hasExportStars: boolean; + let hasExportStarsToExportValues: boolean; return transformSourceFile; @@ -45,7 +45,7 @@ namespace ts { currentSourceFile = node; // Collect information about the external module. - ({ externalImports, exportSpecifiers, exportEquals, hasExportStars } = collectExternalModuleInfo(node, resolver)); + ({ externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues } = collectExternalModuleInfo(node, resolver)); // Perform the transformation. const updated = transformModuleDelegates[moduleKind](node); @@ -55,7 +55,7 @@ namespace ts { externalImports = undefined; exportSpecifiers = undefined; exportEquals = undefined; - hasExportStars = false; + hasExportStarsToExportValues = false; return updated; } @@ -77,7 +77,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false); const updated = updateSourceFile(node, statements); - if (hasExportStars) { + if (hasExportStarsToExportValues) { setNodeEmitFlags(updated, NodeEmitFlags.EmitExportStar | getNodeEmitFlags(node)); } @@ -200,7 +200,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true); const body = createBlock(statements, /*location*/ undefined, /*multiLine*/ true); - if (hasExportStars) { + if (hasExportStarsToExportValues) { // If we have any `export * from ...` declarations // we need to inform the emitter to add the __export helper. setNodeEmitFlags(body, NodeEmitFlags.EmitExportStar); @@ -442,7 +442,7 @@ namespace ts { return singleOrMany(statements); } - else { + else if (resolver.moduleExportsSomeValue(node.moduleSpecifier)) { // export * from "mod"; return createStatement( createCall( diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 81c657b158c..c18425a8bda 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -37,7 +37,7 @@ namespace ts { let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; let exportSpecifiers: Map; let exportEquals: ExportAssignment; - let hasExportStars: boolean; + let hasExportStarsToExportValues: boolean; let exportFunctionForFile: Identifier; let contextObjectForFile: Identifier; let exportedLocalNames: Identifier[]; @@ -62,7 +62,7 @@ namespace ts { externalImports = undefined; exportSpecifiers = undefined; exportEquals = undefined; - hasExportStars = false; + hasExportStarsToExportValues = false; exportFunctionForFile = undefined; contextObjectForFile = undefined; exportedLocalNames = undefined; @@ -89,7 +89,7 @@ namespace ts { Debug.assert(!exportFunctionForFile); // Collect information about the external module and dependency groups. - ({ externalImports, exportSpecifiers, exportEquals, hasExportStars } = collectExternalModuleInfo(node, resolver)); + ({ externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues } = collectExternalModuleInfo(node, resolver)); // Make sure that the name of the 'exports' function does not conflict with // existing identifiers. @@ -253,7 +253,7 @@ namespace ts { } function addExportStarIfNeeded(statements: Statement[]) { - if (!hasExportStars) { + if (!hasExportStarsToExportValues) { return; } // when resolving exports local exported entries/indirect exported entries in the module diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index aaaf699834d..a3d07142875 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2984,7 +2984,7 @@ namespace ts { const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; const exportSpecifiers: Map = {}; let exportEquals: ExportAssignment = undefined; - let hasExportStars = false; + let hasExportStarsToExportValues = false; for (const node of sourceFile.statements) { switch (node.kind) { case SyntaxKind.ImportDeclaration: @@ -3009,8 +3009,10 @@ namespace ts { if ((node).moduleSpecifier) { if (!(node).exportClause) { // export * from "mod" - externalImports.push(node); - hasExportStars = true; + if (resolver.moduleExportsSomeValue((node).moduleSpecifier)) { + externalImports.push(node); + hasExportStarsToExportValues = true; + } } else if (resolver.isValueAliasDeclaration(getOriginalNode(node))) { // export { x, y } from "mod" where at least one export is a value symbol @@ -3040,7 +3042,7 @@ namespace ts { } } - return { externalImports, exportSpecifiers, exportEquals, hasExportStars }; + return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues }; } export function getInitializedVariables(node: VariableDeclarationList) {