Skip to content

Commit 4bda7ce

Browse files
authored
Include reexported names in list of exported names (microsoft#38809)
1 parent 6a777ff commit 4bda7ce

File tree

56 files changed

+92
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+92
-52
lines changed

src/compiler/transformers/module/system.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -339,37 +339,6 @@ namespace ts {
339339
}
340340
}
341341

342-
for (const externalImport of moduleInfo.externalImports) {
343-
if (externalImport.kind !== SyntaxKind.ExportDeclaration) {
344-
continue;
345-
}
346-
347-
if (!externalImport.exportClause) {
348-
// export * from ...
349-
continue;
350-
}
351-
352-
if (isNamedExports(externalImport.exportClause)) {
353-
for (const element of externalImport.exportClause.elements) {
354-
// write name of indirectly exported entry, i.e. 'export {x} from ...'
355-
exportedNames.push(
356-
createPropertyAssignment(
357-
createLiteral(idText(element.name || element.propertyName)),
358-
createTrue()
359-
)
360-
);
361-
}
362-
}
363-
else {
364-
exportedNames.push(
365-
createPropertyAssignment(
366-
createLiteral(idText(externalImport.exportClause.name)),
367-
createTrue()
368-
)
369-
);
370-
}
371-
}
372-
373342
const exportedNamesStorageRef = createUniqueName("exportedNames");
374343
statements.push(
375344
createVariableStatement(

src/compiler/transformers/utilities.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,22 @@ namespace ts {
112112
// export * as ns from "mod"
113113
// export { x, y } from "mod"
114114
externalImports.push(<ExportDeclaration>node);
115+
if (isNamedExports((node as ExportDeclaration).exportClause!)) {
116+
addExportedNamesForExportDeclaration(node as ExportDeclaration);
117+
}
118+
else {
119+
const name = ((node as ExportDeclaration).exportClause as NamespaceExport).name;
120+
if (!uniqueExports.get(idText(name))) {
121+
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name);
122+
uniqueExports.set(idText(name), true);
123+
exportedNames = append(exportedNames, name);
124+
}
125+
}
115126
}
116127
}
117128
else {
118129
// export { x, y }
119-
for (const specifier of cast((<ExportDeclaration>node).exportClause, isNamedExports).elements) {
120-
if (!uniqueExports.get(idText(specifier.name))) {
121-
const name = specifier.propertyName || specifier.name;
122-
exportSpecifiers.add(idText(name), specifier);
123-
124-
const decl = resolver.getReferencedImportDeclaration(name)
125-
|| resolver.getReferencedValueDeclaration(name);
126-
127-
if (decl) {
128-
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name);
129-
}
130-
131-
uniqueExports.set(idText(specifier.name), true);
132-
exportedNames = append(exportedNames, specifier.name);
133-
}
134-
}
130+
addExportedNamesForExportDeclaration(node as ExportDeclaration);
135131
}
136132
break;
137133

@@ -200,6 +196,25 @@ namespace ts {
200196
}
201197

202198
return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration };
199+
200+
function addExportedNamesForExportDeclaration(node: ExportDeclaration) {
201+
for (const specifier of cast(node.exportClause, isNamedExports).elements) {
202+
if (!uniqueExports.get(idText(specifier.name))) {
203+
const name = specifier.propertyName || specifier.name;
204+
exportSpecifiers.add(idText(name), specifier);
205+
206+
const decl = resolver.getReferencedImportDeclaration(name)
207+
|| resolver.getReferencedValueDeclaration(name);
208+
209+
if (decl) {
210+
multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name);
211+
}
212+
213+
uniqueExports.set(idText(specifier.name), true);
214+
exportedNames = append(exportedNames, specifier.name);
215+
}
216+
}
217+
}
203218
}
204219

205220
function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map<boolean>, exportedNames: Identifier[] | undefined) {

tests/baselines/reference/ambientShorthand_reExport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
2626
o[k2] = m[k];
2727
}));
2828
exports.__esModule = true;
29+
exports.x = void 0;
2930
var jquery_1 = require("jquery");
3031
__createBinding(exports, jquery_1, "x");
3132
//// [reExportAll.js]

tests/baselines/reference/commentsOnRequireStatement.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exports.subject1 = 10;
2929
//// [2.js]
3030
"use strict";
3131
Object.defineProperty(exports, "__esModule", { value: true });
32+
exports.subject1 = exports.subject = void 0;
3233
/* blah0 */
3334
// blah
3435
// blah

tests/baselines/reference/constEnumPreserveEmitReexport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
3636
o[k2] = m[k];
3737
}));
3838
exports.__esModule = true;
39+
exports["default"] = void 0;
3940
var ConstEnum_1 = require("./ConstEnum");
4041
__createBinding(exports, ConstEnum_1, "MyConstEnum", "default");

tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ exports.x = 10;
3737
//// [client.js]
3838
"use strict";
3939
Object.defineProperty(exports, "__esModule", { value: true });
40+
exports.x = exports.instantiatedModule = exports.c2 = exports.c = void 0;
4041
var server_1 = require("./server");
4142
Object.defineProperty(exports, "c", { enumerable: true, get: function () { return server_1.c; } });
4243
var server_2 = require("./server");

tests/baselines/reference/es6ExportEqualsInterop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
220220
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
221221
};
222222
exports.__esModule = true;
223+
exports.a0 = exports.a9 = exports.a8 = exports.a7 = exports.a6 = exports.a5 = exports.a4 = exports.a3 = exports.a2 = exports.a1 = void 0;
223224
var z2 = require("variable");
224225
var z3 = require("interface-variable");
225226
var z4 = require("module");

tests/baselines/reference/esModuleInteropWithExportStar(target=es3).js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
3737
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
3838
};
3939
exports.__esModule = true;
40+
exports.y = exports.x = void 0;
4041
var fs = __importStar(require("./fs"));
4142
fs;
4243
__exportStar(require("./fs"), exports);

tests/baselines/reference/esModuleInteropWithExportStar(target=es5).js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
3737
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
3838
};
3939
Object.defineProperty(exports, "__esModule", { value: true });
40+
exports.y = exports.x = void 0;
4041
var fs = __importStar(require("./fs"));
4142
fs;
4243
__exportStar(require("./fs"), exports);

tests/baselines/reference/exportAsNamespace1(module=amd).js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ define(["require", "exports"], function (require, exports) {
2727
define(["require", "exports", "./0"], function (require, exports, ns) {
2828
"use strict";
2929
exports.__esModule = true;
30+
exports.ns = void 0;
3031
exports.ns = ns;
3132
ns.a;
3233
ns.b;

0 commit comments

Comments
 (0)