mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 20:25:23 -06:00
emit export star only if export will yield anything with value side
This commit is contained in:
parent
381c0260ff
commit
43051eab84
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user