Skip to content

Commit

Permalink
fix: generate code correctly for dynamically importing the same file …
Browse files Browse the repository at this point in the history
…twice and destructuring
  • Loading branch information
alexander-akait authored Sep 11, 2024
2 parents 64e8e33 + d8343ed commit 85644e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/dependencies/ContextDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ class ContextDependency extends Dependency {
this.options.include
)} ${regExpToString(this.options.exclude)} ` +
`${this.options.mode} ${this.options.chunkName} ` +
`${JSON.stringify(this.options.groupOptions)}`
`${JSON.stringify(this.options.groupOptions)}` +
`${
this.options.referencedExports
? ` ${JSON.stringify(this.options.referencedExports)}`
: ""
}`
);
}

Expand Down
9 changes: 9 additions & 0 deletions test/cases/context/issue-18752/folder/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function generateSummary() {
return 1;
}
export function entityActionQueue() {
return 2;
}
export function bar() {
return 3;
}
18 changes: 18 additions & 0 deletions test/cases/context/issue-18752/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
it("should work with importing the same file twice and destructuring", async () => {
const type = "file";
const { generateSummary } = await import(
/* webpackInclude: /[/\\]folder[/\\](?!.*\.test).*\.m?js$/ */
/* webpackChunkName: "chunk-name" */
/* webpackMode: "lazy-once" */
`./folder/${type}.js`
);
expect(typeof generateSummary).toBe("function");

const { entityActionQueue } = await import(
/* webpackInclude: /[/\\]folder[/\\](?!.*\.test).*\.m?js$/ */
/* webpackChunkName: "chunk-name" */
/* webpackMode: "lazy-once" */
`./folder/${type}.js`
);
expect(typeof entityActionQueue).toBe("function");
});

0 comments on commit 85644e8

Please sign in to comment.