Include reexported names in list of exported names (#38809)

This commit is contained in:
Wesley Wigham
2020-06-15 15:17:08 -07:00
committed by GitHub
parent 6a777ff6b3
commit 4bda7ce8e5
56 changed files with 92 additions and 52 deletions

View File

@@ -339,37 +339,6 @@ namespace ts {
}
}
for (const externalImport of moduleInfo.externalImports) {
if (externalImport.kind !== SyntaxKind.ExportDeclaration) {
continue;
}
if (!externalImport.exportClause) {
// export * from ...
continue;
}
if (isNamedExports(externalImport.exportClause)) {
for (const element of externalImport.exportClause.elements) {
// write name of indirectly exported entry, i.e. 'export {x} from ...'
exportedNames.push(
createPropertyAssignment(
createLiteral(idText(element.name || element.propertyName)),
createTrue()
)
);
}
}
else {
exportedNames.push(
createPropertyAssignment(
createLiteral(idText(externalImport.exportClause.name)),
createTrue()
)
);
}
}
const exportedNamesStorageRef = createUniqueName("exportedNames");
statements.push(
createVariableStatement(

View File

@@ -112,26 +112,22 @@ namespace ts {
// export * as ns from "mod"
// export { x, y } from "mod"
externalImports.push(<ExportDeclaration>node);
if (isNamedExports((node as ExportDeclaration).exportClause!)) {
addExportedNamesForExportDeclaration(node as ExportDeclaration);
}
else {
const name = ((node as ExportDeclaration).exportClause as NamespaceExport).name;
if (!uniqueExports.get(idText(name))) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
uniqueExports.set(idText(name), true);
exportedNames = append(exportedNames, name);
}
}
}
}
else {
// export { x, y }
for (const specifier of cast((<ExportDeclaration>node).exportClause, isNamedExports).elements) {
if (!uniqueExports.get(idText(specifier.name))) {
const name = specifier.propertyName || specifier.name;
exportSpecifiers.add(idText(name), specifier);
const decl = resolver.getReferencedImportDeclaration(name)
|| resolver.getReferencedValueDeclaration(name);
if (decl) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name);
}
uniqueExports.set(idText(specifier.name), true);
exportedNames = append(exportedNames, specifier.name);
}
}
addExportedNamesForExportDeclaration(node as ExportDeclaration);
}
break;
@@ -200,6 +196,25 @@ namespace ts {
}
return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration };
function addExportedNamesForExportDeclaration(node: ExportDeclaration) {
for (const specifier of cast(node.exportClause, isNamedExports).elements) {
if (!uniqueExports.get(idText(specifier.name))) {
const name = specifier.propertyName || specifier.name;
exportSpecifiers.add(idText(name), specifier);
const decl = resolver.getReferencedImportDeclaration(name)
|| resolver.getReferencedValueDeclaration(name);
if (decl) {
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name);
}
uniqueExports.set(idText(specifier.name), true);
exportedNames = append(exportedNames, specifier.name);
}
}
}
}
function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map<boolean>, exportedNames: Identifier[] | undefined) {