From 28318f09ed358b2baa155141bc715c25f658a2eb Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sat, 16 Sep 2023 12:32:07 +0800 Subject: [PATCH] fix(es/compat): Handle `PrivateName` in `logical_assignments` (#7958) **Related issue:** - Closes #7956 --- .../fixture/issues-7xxx/7956/input/1/.swcrc | 10 ++++++++++ .../fixture/issues-7xxx/7956/input/1/index.js | 20 +++++++++++++++++++ .../issues-7xxx/7956/output/1/index.js | 19 ++++++++++++++++++ .../src/es2021/logical_assignments.rs | 3 --- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-7xxx/7956/input/1/.swcrc create mode 100644 crates/swc/tests/fixture/issues-7xxx/7956/input/1/index.js create mode 100644 crates/swc/tests/fixture/issues-7xxx/7956/output/1/index.js diff --git a/crates/swc/tests/fixture/issues-7xxx/7956/input/1/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7956/input/1/.swcrc new file mode 100644 index 000000000000..8bc1355a1287 --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7956/input/1/.swcrc @@ -0,0 +1,10 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript" + } + }, + "env": { + "targets": "chrome 74" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-7xxx/7956/input/1/index.js b/crates/swc/tests/fixture/issues-7xxx/7956/input/1/index.js new file mode 100644 index 000000000000..7a82e0a7559e --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7956/input/1/index.js @@ -0,0 +1,20 @@ +class A { + #a; + b() { + this.#a ||= 1; + } + c(x) { + x.#a ||= 1; + } + log() { + console.log(this.#a); + } +} + +const x = new A(); +x.b(); +x.log(); + +const y = new A(); +y.c(y); +y.log(); diff --git a/crates/swc/tests/fixture/issues-7xxx/7956/output/1/index.js b/crates/swc/tests/fixture/issues-7xxx/7956/output/1/index.js new file mode 100644 index 000000000000..59abcd5ac33f --- /dev/null +++ b/crates/swc/tests/fixture/issues-7xxx/7956/output/1/index.js @@ -0,0 +1,19 @@ +class A { + #a; + b() { + this.#a || (this.#a = 1); + } + c(x) { + var _x; + (_x = x).#a || (_x.#a = 1); + } + log() { + console.log(this.#a); + } +} +const x = new A(); +x.b(); +x.log(); +const y = new A(); +y.c(y); +y.log(); diff --git a/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs b/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs index 988e0ad5fb76..9fec74c43204 100644 --- a/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs +++ b/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs @@ -123,9 +123,6 @@ impl VisitMut for Operators { }; let (left_prop, right_prop) = match m.prop.take() { - MemberProp::PrivateName(_) => { - unreachable!("private should be removed by class_properties") - } MemberProp::Computed(c) => { let (left, right) = self.memorize_prop(c); (left.into(), right.into())