Skip to content

Commit

Permalink
Properly handle double reexports from external namespaces (#4159)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 30, 2021
1 parent 5e49df7 commit 3277bbf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Module.ts
Expand Up @@ -533,12 +533,15 @@ export default class Module {
const foundNamespaceReexport =
name in this.namespaceReexportsByName
? this.namespaceReexportsByName[name]
: (this.namespaceReexportsByName[name] = this.getVariableFromNamespaceReexports(
: this.getVariableFromNamespaceReexports(
name,
importerForSideEffects,
searchedNamesAndModules,
skipExternalNamespaceReexports
));
);
if (!skipExternalNamespaceReexports) {
this.namespaceReexportsByName[name] = foundNamespaceReexport;
}
if (foundNamespaceReexport) {
return foundNamespaceReexport;
}
Expand Down Expand Up @@ -1012,8 +1015,18 @@ export default class Module {
skipExternalNamespaceReexports = false
): Variable | null {
let foundSyntheticDeclaration: SyntheticNamedExportVariable | null = null;
const skipExternalNamespaceValues = new Set([true, skipExternalNamespaceReexports]);
for (const skipExternalNamespaces of skipExternalNamespaceValues) {
const skipExternalNamespaceValues = [{ searchedNamesAndModules, skipExternalNamespaces: true }];
if (!skipExternalNamespaceReexports) {
const clonedSearchedNamesAndModules = new Map<string, Set<Module | ExternalModule>>();
for (const [name, modules] of searchedNamesAndModules || []) {
clonedSearchedNamesAndModules.set(name, new Set(modules));
}
skipExternalNamespaceValues.push({
searchedNamesAndModules: clonedSearchedNamesAndModules,
skipExternalNamespaces: false
});
}
for (const { skipExternalNamespaces, searchedNamesAndModules } of skipExternalNamespaceValues) {
const foundDeclarations = new Set<Variable>();
for (const module of this.exportAllModules) {
if (module instanceof Module || !skipExternalNamespaces) {
Expand Down
17 changes: 17 additions & 0 deletions test/function/samples/double-namespace-reexport/_config.js
@@ -0,0 +1,17 @@
const assert = require('assert');

module.exports = {
description: 'handles chained namespace reexports from externals',
options: {
external: 'external'
},
context: {
require(id) {
assert.strictEqual(id, 'external');
return { foo: 42 };
}
},
exports({ foo }) {
assert.strictEqual(foo, 42);
}
};
1 change: 1 addition & 0 deletions test/function/samples/double-namespace-reexport/first.js
@@ -0,0 +1 @@
export * from './second.js';
1 change: 1 addition & 0 deletions test/function/samples/double-namespace-reexport/main.js
@@ -0,0 +1 @@
export { foo } from './first.js';
1 change: 1 addition & 0 deletions test/function/samples/double-namespace-reexport/second.js
@@ -0,0 +1 @@
export * from 'external';

0 comments on commit 3277bbf

Please sign in to comment.