Merge pull request #7972 from Microsoft/exportStarOfNonValues

emit export star only if export will yield anything with value side
This commit is contained in:
Vladimir Matveev
2016-04-08 23:18:43 -07:00
5 changed files with 32 additions and 15 deletions
+16
View File
@@ -23,6 +23,8 @@ namespace ts {
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
return visitImportDeclaration(<ImportDeclaration>node);
case SyntaxKind.ImportEqualsDeclaration:
return visitImportEqualsDeclaration(<ImportEqualsDeclaration>node);
case SyntaxKind.ImportClause:
return visitImportClause(<ImportClause>node);
case SyntaxKind.NamedImports:
@@ -30,11 +32,25 @@ namespace ts {
return visitNamedBindings(<NamedImportBindings>node);
case SyntaxKind.ImportSpecifier:
return visitImportSpecifier(<ImportSpecifier>node);
case SyntaxKind.ExportAssignment:
return visitExportAssignment(<ExportAssignment>node);
}
return node;
}
function visitExportAssignment(node: ExportAssignment): ExportDeclaration {
if (node.isExportEquals) {
return undefined; // do not emit export equals for ES6
}
const original = getOriginalNode(node);
return nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original) ? node: undefined;
}
function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): ImportEqualsDeclaration {
return !isExternalModuleImportEqualsDeclaration(node) || resolver.isReferencedAliasDeclaration(node) ? node : undefined;
}
function visitImportDeclaration(node: ImportDeclaration) {
if (node.importClause) {
const newImportClause = visitNode(node.importClause, visitor, isImportClause);
+6 -6
View File
@@ -31,7 +31,7 @@ namespace ts {
let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[];
let exportSpecifiers: Map<ExportSpecifier[]>;
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(
+4 -4
View File
@@ -37,7 +37,7 @@ namespace ts {
let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[];
let exportSpecifiers: Map<ExportSpecifier[]>;
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
+6 -4
View File
@@ -2984,7 +2984,7 @@ namespace ts {
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
const exportSpecifiers: Map<ExportSpecifier[]> = {};
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 ((<ExportDeclaration>node).moduleSpecifier) {
if (!(<ExportDeclaration>node).exportClause) {
// export * from "mod"
externalImports.push(<ExportDeclaration>node);
hasExportStars = true;
if (resolver.moduleExportsSomeValue((<ExportDeclaration>node).moduleSpecifier)) {
externalImports.push(<ExportDeclaration>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) {
@@ -7,7 +7,6 @@ export = f;
//// [es6ExportEquals.js]
export function f() { }
export = f;
//// [es6ExportEquals.d.ts]