From 3eae61276ac8a117de1c2eec5f0b5d1435166ca3 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Sat, 31 Aug 2024 01:52:53 +0800 Subject: [PATCH 1/2] Fix --- .../src/visitors/dependency/parser/walk.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 c1bb257e1ec..f270d85b944 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs @@ -542,18 +542,26 @@ impl<'parser> JavascriptParser<'parser> { 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 { - self.walk_statement(Statement::Block(body)); - } + self.in_function_scope(true, std::iter::empty(), |parser| { + if let Some(body) = &getter.body { + parser.walk_statement(Statement::Block(body)); + } + }); self.top_level_scope = was_top_level; } 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) = &setter.body { - self.walk_statement(Statement::Block(body)); - } + self.in_function_scope( + true, + std::iter::once(Cow::Borrowed(setter.param.as_ref())), + |parser| { + if let Some(body) = &setter.body { + parser.walk_statement(Statement::Block(body)); + } + }, + ); self.top_level_scope = was_top_level; } Prop::Method(method) => { From 800d50dd7d9de59341d1fb3519c0421bba13ff28 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Sat, 31 Aug 2024 02:04:50 +0800 Subject: [PATCH 2/2] Add testcase --- .../parsing/harmony-import-specifier/a.js | 1 + .../parsing/harmony-import-specifier/index.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/a.js create mode 100644 packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/a.js b/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/a.js new file mode 100644 index 00000000000..f3d752fc55a --- /dev/null +++ b/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/a.js @@ -0,0 +1 @@ +export class Texture {} diff --git a/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/index.js b/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/index.js new file mode 100644 index 00000000000..f591beac8ea --- /dev/null +++ b/packages/rspack-test-tools/tests/normalCases/parsing/harmony-import-specifier/index.js @@ -0,0 +1,16 @@ +import { Texture as e } from "./a.js"; + +it("should not parse when logical and with `false && unknown = false`", function () { + var index_es_e = {}; + var index_es_Ce = { + get exports() { + return index_es_e; + }, + set exports(e) { + index_es_e = e; + } + }; + console.log.bind(null, e); + index_es_Ce.exports = 1; + expect(index_es_Ce.exports).toBe(1) +}); \ No newline at end of file