From e84bdc094e40f225f12732116f5fd55e108e518b Mon Sep 17 00:00:00 2001 From: Fy <1114550440@qq.com> Date: Mon, 26 Feb 2024 20:18:23 +0800 Subject: [PATCH] fix: should visit prop-name in getter/setter (#5773) --- .../src/visitors/dependency/parser/walk.rs | 6 ++++-- .../configCases/parsing/getter-import-specifier/a.js | 1 + .../parsing/getter-import-specifier/index.js | 11 +++++++++++ .../parsing/getter-import-specifier/webpack.config.js | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/rspack/tests/configCases/parsing/getter-import-specifier/a.js create mode 100644 packages/rspack/tests/configCases/parsing/getter-import-specifier/index.js create mode 100644 packages/rspack/tests/configCases/parsing/getter-import-specifier/webpack.config.js diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs index 4ee46914fd3..0711a0db276 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs @@ -547,6 +547,7 @@ impl<'parser> JavascriptParser<'parser> { Prop::KeyValue(kv) => self.walk_key_value_prop(kv), Prop::Assign(assign) => self.walk_expression(&assign.value), Prop::Getter(getter) => { + self.walk_prop_name(&getter.key); let was_top_level = self.top_level_scope; self.top_level_scope = TopLevelScope::False; if let Some(body) = &getter.body { @@ -554,10 +555,11 @@ impl<'parser> JavascriptParser<'parser> { } self.top_level_scope = was_top_level; } - Prop::Setter(seeter) => { + Prop::Setter(setter) => { + self.walk_prop_name(&setter.key); let was_top_level = self.top_level_scope; self.top_level_scope = TopLevelScope::False; - if let Some(body) = &seeter.body { + if let Some(body) = &setter.body { self.walk_block_statement(body); } self.top_level_scope = was_top_level; diff --git a/packages/rspack/tests/configCases/parsing/getter-import-specifier/a.js b/packages/rspack/tests/configCases/parsing/getter-import-specifier/a.js new file mode 100644 index 00000000000..6cd1d0075d4 --- /dev/null +++ b/packages/rspack/tests/configCases/parsing/getter-import-specifier/a.js @@ -0,0 +1 @@ +module.exports = "a"; diff --git a/packages/rspack/tests/configCases/parsing/getter-import-specifier/index.js b/packages/rspack/tests/configCases/parsing/getter-import-specifier/index.js new file mode 100644 index 00000000000..358961c0a54 --- /dev/null +++ b/packages/rspack/tests/configCases/parsing/getter-import-specifier/index.js @@ -0,0 +1,11 @@ +import a from "./a"; + +const obj = { + get [a]() { + return "success"; + } +}; + +it("should compile", () => { + expect(obj[a]).toBe("success"); +}); diff --git a/packages/rspack/tests/configCases/parsing/getter-import-specifier/webpack.config.js b/packages/rspack/tests/configCases/parsing/getter-import-specifier/webpack.config.js new file mode 100644 index 00000000000..0ed6583dd31 --- /dev/null +++ b/packages/rspack/tests/configCases/parsing/getter-import-specifier/webpack.config.js @@ -0,0 +1,3 @@ +module.exports = { + mode: "none" +};