Skip to content

Commit a4d095d

Browse files
authored
fix: should always walk import then arguments (#11760)
1 parent 9fd2b1d commit a4d095d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

crates/rspack_plugin_javascript/src/parser_plugin/import_parser_plugin.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,13 @@ impl JavascriptParserPlugin for ImportParserPlugin {
433433
}
434434
};
435435

436-
if let Some(ns_obj) = referenced_fulfilled_ns_obj
437-
&& let Some(import_then) = import_then
438-
{
439-
walk_import_then_fulfilled_callback(parser, node, &import_then.args[0].expr, ns_obj);
440-
parser.walk_expr_or_spread(&import_then.args[1..]);
436+
if let Some(import_then) = import_then {
437+
if let Some(ns_obj) = referenced_fulfilled_ns_obj {
438+
walk_import_then_fulfilled_callback(parser, node, &import_then.args[0].expr, ns_obj);
439+
parser.walk_expr_or_spread(&import_then.args[1..]);
440+
} else {
441+
parser.walk_expr_or_spread(&import_then.args);
442+
}
441443
}
442444

443445
if let Some(import_references) = parser

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ it("should analyze arguments in call member chain", async () => {
8282
})());
8383
});
8484
});
85+
86+
it("should analyze then arguments", async () => {
87+
await import("../statical-dynamic-import/dir4/lib?3").then(() => {
88+
return import("../statical-dynamic-import/dir4/a?3").then(m2 => {
89+
expect(m2.a).toBe(1);
90+
expect(m2.usedExports).toEqual(["a", "usedExports"]);
91+
});
92+
});
93+
})

0 commit comments

Comments
 (0)