Skip to content

Commit

Permalink
Do not add tree-shaken variables to namespaces when inlining dynamic …
Browse files Browse the repository at this point in the history
…imports (#5047)
  • Loading branch information
lukastaegert authored Jun 26, 2023
1 parent 7ed978f commit 83d21a4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,9 @@ export default class Chunk {
if (!this.outputOptions.preserveModules && this.includedNamespaces.has(module)) {
const memberVariables = module.namespace.getMemberVariables();
for (const variable of Object.values(memberVariables)) {
moduleImports.add(variable);
if (variable.included) {
moduleImports.add(variable);
}
}
}
for (let variable of moduleImports) {
Expand Down
2 changes: 1 addition & 1 deletion src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export default class Module {
) {
for (const exportName of [...this.getReexports(), ...this.getExports()]) {
const [exportedVariable] = this.getVariableForExportName(exportName);
if (exportedVariable) {
if (exportedVariable?.included) {
dependencyVariables.add(exportedVariable);
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/form/samples/inline-with-reexport/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = defineTest({
description: 'handles inlining dynamic imports when the imported module contains reexports',
options: {
output: {
inlineDynamicImports: true
}
}
});
5 changes: 5 additions & 0 deletions test/form/samples/inline-with-reexport/_expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Promise.resolve().then(function () { return a; });

var a = /*#__PURE__*/Object.freeze({
__proto__: null
});
1 change: 1 addition & 0 deletions test/form/samples/inline-with-reexport/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { b } from './b.js';
1 change: 1 addition & 0 deletions test/form/samples/inline-with-reexport/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b = 42;
1 change: 1 addition & 0 deletions test/form/samples/inline-with-reexport/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import('./a.js');

0 comments on commit 83d21a4

Please sign in to comment.