Skip to content

Commit

Permalink
Fix crash when using inlineDynamicImports with no-treeshake (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 27, 2021
1 parent df3b2a5 commit 27d560e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Module.ts
Expand Up @@ -362,17 +362,18 @@ export default class Module {
}
necessaryDependencies.add(variable.module!);
}
if (this.options.treeshake && this.info.hasModuleSideEffects !== 'no-treeshake') {
this.addRelevantSideEffectDependencies(
relevantDependencies,
necessaryDependencies,
alwaysCheckedDependencies
);
} else {
if (!this.options.treeshake || this.info.hasModuleSideEffects === 'no-treeshake') {
for (const dependency of this.dependencies) {
relevantDependencies.add(dependency);
if (dependency instanceof ExternalModule || dependency.isIncluded()) {
relevantDependencies.add(dependency);
}
}
}
this.addRelevantSideEffectDependencies(
relevantDependencies,
necessaryDependencies,
alwaysCheckedDependencies
);
for (const dependency of necessaryDependencies) {
relevantDependencies.add(dependency);
}
Expand Down
29 changes: 29 additions & 0 deletions test/function/samples/inline-dynamic-no-treeshake/_config.js
@@ -0,0 +1,29 @@
const MAGIC_ENTRY = 'main';

module.exports = {
description: 'handles inlining dynamic imports when treeshaking is disabled for modules (#4098)',
options: {
input: MAGIC_ENTRY,
output: {
inlineDynamicImports: true
},
plugins: [
{
name: 'magic-modules',
buildStart() {
this.emitFile({ type: 'chunk', id: './dep.js' });
},
async resolveId(source) {
if (source === MAGIC_ENTRY) {
return { id: source, moduleSideEffects: 'no-treeshake' };
}
return null;
},
async load(id) {
if (id !== MAGIC_ENTRY) return null;
return `import {foo} from './reexport.js';assert.strictEqual(foo, 1);`;
}
}
]
}
};
1 change: 1 addition & 0 deletions test/function/samples/inline-dynamic-no-treeshake/dep.js
@@ -0,0 +1 @@
export const foo = 1;
@@ -0,0 +1 @@
export * from './dep.js';

0 comments on commit 27d560e

Please sign in to comment.