Skip to content

Commit 1573264

Browse files
authored
fix: should analyze correct variable for dynamic import (#11768)
1 parent 617fe7a commit 1573264

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/rspack_plugin_javascript/src/parser_plugin/import_parser_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl JavascriptParserPlugin for ImportParserPlugin {
140140
&& call.callee.is_import()
141141
&& let Some(binding) = declarator.name.as_ident()
142142
{
143+
parser.define_variable(binding.id.sym.clone());
143144
tag_dynamic_import_referenced(parser, call, binding.id.sym.clone());
144145
}
145146
None

tests/rspack-test/normalCases/chunks/statical-dynamic-import/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ it("should analyze arguments in call member chain", async () => {
6060
expect(m2.usedExports).toEqual(["a", "usedExports"]);
6161
})());
6262
});
63+
64+
it("should analyze usage of variable that in correct scope", async () => {
65+
var m = { b: 1 };
66+
expect(m.b).toBe(1);
67+
await (async () => {
68+
var m = await import("./dir4/a?3");
69+
expect(m.a).toBe(1);
70+
expect(m.usedExports).toEqual(["a", "usedExports"]);
71+
})();
72+
});

0 commit comments

Comments
 (0)