Skip to content

Commit 3277bbf

Browse files
authored
Properly handle double reexports from external namespaces (#4159)
1 parent 5e49df7 commit 3277bbf

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/Module.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,15 @@ export default class Module {
533533
const foundNamespaceReexport =
534534
name in this.namespaceReexportsByName
535535
? this.namespaceReexportsByName[name]
536-
: (this.namespaceReexportsByName[name] = this.getVariableFromNamespaceReexports(
536+
: this.getVariableFromNamespaceReexports(
537537
name,
538538
importerForSideEffects,
539539
searchedNamesAndModules,
540540
skipExternalNamespaceReexports
541-
));
541+
);
542+
if (!skipExternalNamespaceReexports) {
543+
this.namespaceReexportsByName[name] = foundNamespaceReexport;
544+
}
542545
if (foundNamespaceReexport) {
543546
return foundNamespaceReexport;
544547
}
@@ -1012,8 +1015,18 @@ export default class Module {
10121015
skipExternalNamespaceReexports = false
10131016
): Variable | null {
10141017
let foundSyntheticDeclaration: SyntheticNamedExportVariable | null = null;
1015-
const skipExternalNamespaceValues = new Set([true, skipExternalNamespaceReexports]);
1016-
for (const skipExternalNamespaces of skipExternalNamespaceValues) {
1018+
const skipExternalNamespaceValues = [{ searchedNamesAndModules, skipExternalNamespaces: true }];
1019+
if (!skipExternalNamespaceReexports) {
1020+
const clonedSearchedNamesAndModules = new Map<string, Set<Module | ExternalModule>>();
1021+
for (const [name, modules] of searchedNamesAndModules || []) {
1022+
clonedSearchedNamesAndModules.set(name, new Set(modules));
1023+
}
1024+
skipExternalNamespaceValues.push({
1025+
searchedNamesAndModules: clonedSearchedNamesAndModules,
1026+
skipExternalNamespaces: false
1027+
});
1028+
}
1029+
for (const { skipExternalNamespaces, searchedNamesAndModules } of skipExternalNamespaceValues) {
10171030
const foundDeclarations = new Set<Variable>();
10181031
for (const module of this.exportAllModules) {
10191032
if (module instanceof Module || !skipExternalNamespaces) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const assert = require('assert');
2+
3+
module.exports = {
4+
description: 'handles chained namespace reexports from externals',
5+
options: {
6+
external: 'external'
7+
},
8+
context: {
9+
require(id) {
10+
assert.strictEqual(id, 'external');
11+
return { foo: 42 };
12+
}
13+
},
14+
exports({ foo }) {
15+
assert.strictEqual(foo, 42);
16+
}
17+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './second.js';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { foo } from './first.js';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'external';

0 commit comments

Comments
 (0)