Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle double reexports from external namespaces #4159

Merged
merged 1 commit into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';