Repository: swc-project/swc (rust)

Issue:
Does not transform `&&=` “logical AND assignment” operator
### Describe the bug

(similar to #1788) swc does not transform the [Logical AND assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment) operator (`&&=`).

### Input code

```typescript
const swc = require('@swc/core');
swc.transformSync(`a ||= b`, {});  // a || (a = b);
swc.transformSync(`a &&= b`, {});  // a &&= b;
```


### Config
N/A


### Expected behavior

The `&&=` operator is transformed by SWC, like the `||=` and `??=` operators are.

### Actual behavior

The `&&=` operator is left untransformed.

### Version

1.2.127

### Additional context

_No response_

Pull request:
fix(es/compat): transform `logical and assignment` (`&&=`) operator
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**
<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
- fix #3224 

Patch:
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 5225229786..fb0afd1fa4 100644
--- a/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2021/logical_assignments.rs
@@ -34,13 +34,7 @@ impl VisitMut for Operators {
         match e {
             Expr::Assign(AssignExpr {
                 span,
-                op: op @ op!("||="),
-                left: PatOrExpr::Expr(left),
-                right,
-            })
-            | Expr::Assign(AssignExpr {
-                span,
-                op: op @ op!("??="),
+                op: op @ (op!("&&=") | op!("||=") | op!("??=")),
                 left: PatOrExpr::Expr(left),
                 right,
             }) if left.is_ident() || left.is_member() || left.is_super_prop() => {
@@ -89,13 +83,16 @@ impl VisitMut for Operators {
                     right: right.take(),
                 }));
 
+                let op = match *op {
+                    op!("??=") => op!("??"),
+                    op!("&&=") => op!("&&"),
+                    op!("||=") => op!("||"),
+                    _ => unreachable!(),
+                };
+
                 *e = Expr::Bin(BinExpr {
                     span: *span,
-                    op: if *op == op!("??=") {
-                        op!("??")
-                    } else {
-                        op!("||")
-                    },
+                    op,
                     left: left_expr,
                     right,
                 });


Test patch:
diff --git a/crates/swc/tests/tsc-references/logicalAssignment1_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment1_es2015.1.normal.js
index f07a5e819a..153eb7c641 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment1_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment1_es2015.1.normal.js
@@ -1,9 +1,9 @@
-a &&= "foo";
+a && (a = "foo");
 b || (b = "foo");
 c !== null && c !== void 0 ? c : c = "foo";
-d &&= 42;
+d && (d = 42);
 e || (e = 42);
 f !== null && f !== void 0 ? f : f = 42;
-g &&= 42;
+g && (g = 42);
 h || (h = 42);
 i !== null && i !== void 0 ? i : i = 42;
diff --git a/crates/swc/tests/tsc-references/logicalAssignment1_es2015.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment1_es2015.2.minified.js
index 07f041e674..7d90706962 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment1_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment1_es2015.2.minified.js
@@ -1,1 +1,1 @@
-a &&= "foo", b || (b = "foo"), null != c || (c = "foo"), d &&= 42, e || (e = 42), null != f || (f = 42), g &&= 42, h || (h = 42), null != i || (i = 42);
+a && (a = "foo"), b || (b = "foo"), null != c || (c = "foo"), d && (d = 42), e || (e = 42), null != f || (f = 42), g && (g = 42), h || (h = 42), null != i || (i = 42);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment1_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment1_es5.1.normal.js
index f07a5e819a..153eb7c641 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment1_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment1_es5.1.normal.js
@@ -1,9 +1,9 @@
-a &&= "foo";
+a && (a = "foo");
 b || (b = "foo");
 c !== null && c !== void 0 ? c : c = "foo";
-d &&= 42;
+d && (d = 42);
 e || (e = 42);
 f !== null && f !== void 0 ? f : f = 42;
-g &&= 42;
+g && (g = 42);
 h || (h = 42);
 i !== null && i !== void 0 ? i : i = 42;
diff --git a/crates/swc/tests/tsc-references/logicalAssignment1_es5.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment1_es5.2.minified.js
index 07f041e674..7d90706962 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment1_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment1_es5.2.minified.js
@@ -1,1 +1,1 @@
-a &&= "foo", b || (b = "foo"), null != c || (c = "foo"), d &&= 42, e || (e = 42), null != f || (f = 42), g &&= 42, h || (h = 42), null != i || (i = 42);
+a && (a = "foo"), b || (b = "foo"), null != c || (c = "foo"), d && (d = 42), e || (e = 42), null != f || (f = 42), g && (g = 42), h || (h = 42), null != i || (i = 42);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment2_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment2_es2015.1.normal.js
index d3e698be16..199c62c179 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment2_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment2_es2015.1.normal.js
@@ -1,13 +1,13 @@
-var _b, _c, _foo, _foo1, _ref, _ref1;
-a.baz &&= result.baz;
+var _a, _b, _c, _foo, _foo1, _foo2, _ref, _ref1, _ref2;
+(_a = a).baz && (_a.baz = result.baz);
 (_b = b).baz || (_b.baz = result.baz);
 var _baz;
 (_baz = (_c = c).baz) !== null && _baz !== void 0 ? _baz : _c.baz = result.baz;
-a.foo["baz"] &&= result.foo.baz;
-(_foo = b.foo)["baz"] || (_foo["baz"] = result.foo.baz);
+(_foo = a.foo)["baz"] && (_foo["baz"] = result.foo.baz);
+(_foo1 = b.foo)["baz"] || (_foo1["baz"] = result.foo.baz);
 var ref;
-(ref = (_foo1 = c.foo)["baz"]) !== null && ref !== void 0 ? ref : _foo1["baz"] = result.foo.baz;
-a.foo.bar().baz &&= result.foo.bar().baz;
-(_ref = b.foo.bar()).baz || (_ref.baz = result.foo.bar().baz);
+(ref = (_foo2 = c.foo)["baz"]) !== null && ref !== void 0 ? ref : _foo2["baz"] = result.foo.baz;
+(_ref = a.foo.bar()).baz && (_ref.baz = result.foo.bar().baz);
+(_ref1 = b.foo.bar()).baz || (_ref1.baz = result.foo.bar().baz);
 var _baz1;
-(_baz1 = (_ref1 = c.foo.bar()).baz) !== null && _baz1 !== void 0 ? _baz1 : _ref1.baz = result.foo.bar().baz;
+(_baz1 = (_ref2 = c.foo.bar()).baz) !== null && _baz1 !== void 0 ? _baz1 : _ref2.baz = result.foo.bar().baz;
diff --git a/crates/swc/tests/tsc-references/logicalAssignment2_es2015.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment2_es2015.2.minified.js
index d7c088f50c..d19c3c2ff5 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment2_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment2_es2015.2.minified.js
@@ -1,2 +1,2 @@
-var _b, _c, _foo, _foo1, _ref, _ref1, _baz, ref, _baz1;
-a.baz &&= result.baz, (_b = b).baz || (_b.baz = result.baz), null !== (_baz = (_c = c).baz) && void 0 !== _baz || (_c.baz = result.baz), a.foo.baz &&= result.foo.baz, (_foo = b.foo).baz || (_foo.baz = result.foo.baz), null !== (ref = (_foo1 = c.foo).baz) && void 0 !== ref || (_foo1.baz = result.foo.baz), a.foo.bar().baz &&= result.foo.bar().baz, (_ref = b.foo.bar()).baz || (_ref.baz = result.foo.bar().baz), null !== (_baz1 = (_ref1 = c.foo.bar()).baz) && void 0 !== _baz1 || (_ref1.baz = result.foo.bar().baz);
+var _a, _b, _c, _foo, _foo1, _foo2, _ref, _ref1, _ref2, _baz, ref, _baz1;
+(_a = a).baz && (_a.baz = result.baz), (_b = b).baz || (_b.baz = result.baz), null !== (_baz = (_c = c).baz) && void 0 !== _baz || (_c.baz = result.baz), (_foo = a.foo).baz && (_foo.baz = result.foo.baz), (_foo1 = b.foo).baz || (_foo1.baz = result.foo.baz), null !== (ref = (_foo2 = c.foo).baz) && void 0 !== ref || (_foo2.baz = result.foo.baz), (_ref = a.foo.bar()).baz && (_ref.baz = result.foo.bar().baz), (_ref1 = b.foo.bar()).baz || (_ref1.baz = result.foo.bar().baz), null !== (_baz1 = (_ref2 = c.foo.bar()).baz) && void 0 !== _baz1 || (_ref2.baz = result.foo.bar().baz);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment2_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment2_es5.1.normal.js
index d3e698be16..199c62c179 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment2_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment2_es5.1.normal.js
@@ -1,13 +1,13 @@
-var _b, _c, _foo, _foo1, _ref, _ref1;
-a.baz &&= result.baz;
+var _a, _b, _c, _foo, _foo1, _foo2, _ref, _ref1, _ref2;
+(_a = a).baz && (_a.baz = result.baz);
 (_b = b).baz || (_b.baz = result.baz);
 var _baz;
 (_baz = (_c = c).baz) !== null && _baz !== void 0 ? _baz : _c.baz = result.baz;
-a.foo["baz"] &&= result.foo.baz;
-(_foo = b.foo)["baz"] || (_foo["baz"] = result.foo.baz);
+(_foo = a.foo)["baz"] && (_foo["baz"] = result.foo.baz);
+(_foo1 = b.foo)["baz"] || (_foo1["baz"] = result.foo.baz);
 var ref;
-(ref = (_foo1 = c.foo)["baz"]) !== null && ref !== void 0 ? ref : _foo1["baz"] = result.foo.baz;
-a.foo.bar().baz &&= result.foo.bar().baz;
-(_ref = b.foo.bar()).baz || (_ref.baz = result.foo.bar().baz);
+(ref = (_foo2 = c.foo)["baz"]) !== null && ref !== void 0 ? ref : _foo2["baz"] = result.foo.baz;
+(_ref = a.foo.bar()).baz && (_ref.baz = result.foo.bar().baz);
+(_ref1 = b.foo.bar()).baz || (_ref1.baz = result.foo.bar().baz);
 var _baz1;
-(_baz1 = (_ref1 = c.foo.bar()).baz) !== null && _baz1 !== void 0 ? _baz1 : _ref1.baz = result.foo.bar().baz;
+(_baz1 = (_ref2 = c.foo.bar()).baz) !== null && _baz1 !== void 0 ? _baz1 : _ref2.baz = result.foo.bar().baz;
diff --git a/crates/swc/tests/tsc-references/logicalAssignment2_es5.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment2_es5.2.minified.js
index d7c088f50c..d19c3c2ff5 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment2_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment2_es5.2.minified.js
@@ -1,2 +1,2 @@
-var _b, _c, _foo, _foo1, _ref, _ref1, _baz, ref, _baz1;
-a.baz &&= result.baz, (_b = b).baz || (_b.baz = result.baz), null !== (_baz = (_c = c).baz) && void 0 !== _baz || (_c.baz = result.baz), a.foo.baz &&= result.foo.baz, (_foo = b.foo).baz || (_foo.baz = result.foo.baz), null !== (ref = (_foo1 = c.foo).baz) && void 0 !== ref || (_foo1.baz = result.foo.baz), a.foo.bar().baz &&= result.foo.bar().baz, (_ref = b.foo.bar()).baz || (_ref.baz = result.foo.bar().baz), null !== (_baz1 = (_ref1 = c.foo.bar()).baz) && void 0 !== _baz1 || (_ref1.baz = result.foo.bar().baz);
+var _a, _b, _c, _foo, _foo1, _foo2, _ref, _ref1, _ref2, _baz, ref, _baz1;
+(_a = a).baz && (_a.baz = result.baz), (_b = b).baz || (_b.baz = result.baz), null !== (_baz = (_c = c).baz) && void 0 !== _baz || (_c.baz = result.baz), (_foo = a.foo).baz && (_foo.baz = result.foo.baz), (_foo1 = b.foo).baz || (_foo1.baz = result.foo.baz), null !== (ref = (_foo2 = c.foo).baz) && void 0 !== ref || (_foo2.baz = result.foo.baz), (_ref = a.foo.bar()).baz && (_ref.baz = result.foo.bar().baz), (_ref1 = b.foo.bar()).baz || (_ref1.baz = result.foo.bar().baz), null !== (_baz1 = (_ref2 = c.foo.bar()).baz) && void 0 !== _baz1 || (_ref2.baz = result.foo.bar().baz);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment4_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment4_es2015.1.normal.js
index 2c0acdd21d..b32664727f 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment4_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment4_es2015.1.normal.js
@@ -17,11 +17,11 @@ function foo4(results) {
 }
 function doSomethingWithAlias(thing, defaultValue) {
     if (v === 1) {
-        if (thing &&= thing.original) {
+        if (thing && (thing = thing.original)) {
             thing.name;
         }
     } else if (v === 2) {
-        if (thing &&= defaultValue) {
+        if (thing && (thing = defaultValue)) {
             thing.name;
             defaultValue.name;
         }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment4_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment4_es5.1.normal.js
index 2c0acdd21d..b32664727f 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment4_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment4_es5.1.normal.js
@@ -17,11 +17,11 @@ function foo4(results) {
 }
 function doSomethingWithAlias(thing, defaultValue) {
     if (v === 1) {
-        if (thing &&= thing.original) {
+        if (thing && (thing = thing.original)) {
             thing.name;
         }
     } else if (v === 2) {
-        if (thing &&= defaultValue) {
+        if (thing && (thing = defaultValue)) {
             thing.name;
             defaultValue.name;
         }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment5_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment5_es2015.1.normal.js
index 61c97f615d..5d014b5dd0 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment5_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment5_es2015.1.normal.js
@@ -11,8 +11,8 @@ function foo2(f) {
     f(42);
 }
 function foo3(f) {
-    f &&= (a)=>a
-    ;
+    f && (f = (a)=>a
+    );
     f(42);
 }
 function bar1(f) {
@@ -26,7 +26,7 @@ function bar2(f) {
     f(42);
 }
 function bar3(f) {
-    f &&= (f.toString(), (a)=>a
-    );
+    f && (f = (f.toString(), (a)=>a
+    ));
     f(42);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment5_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment5_es5.1.normal.js
index 14f4650983..59837b9c71 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment5_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment5_es5.1.normal.js
@@ -13,9 +13,9 @@ function foo2(f) {
     f(42);
 }
 function foo3(f) {
-    f &&= function(a) {
+    f && (f = function(a) {
         return a;
-    };
+    });
     f(42);
 }
 function bar1(f) {
@@ -31,8 +31,8 @@ function bar2(f) {
     f(42);
 }
 function bar3(f) {
-    f &&= (f.toString(), function(a) {
+    f && (f = (f.toString(), function(a) {
         return a;
-    });
+    }));
     f(42);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment6_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment6_es2015.1.normal.js
index 37c27e86f2..32b2539a40 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment6_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment6_es2015.1.normal.js
@@ -7,5 +7,5 @@ function foo2(results, results1) {
     (results !== null && results !== void 0 ? results : results = results1 !== null && results1 !== void 0 ? results1 : results1 = []).push(100);
 }
 function foo3(results, results1) {
-    (results &&= results1 &&= []).push(100);
+    (results && (results = results1 && (results1 = []))).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment6_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment6_es5.1.normal.js
index 37c27e86f2..32b2539a40 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment6_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment6_es5.1.normal.js
@@ -7,5 +7,5 @@ function foo2(results, results1) {
     (results !== null && results !== void 0 ? results : results = results1 !== null && results1 !== void 0 ? results1 : results1 = []).push(100);
 }
 function foo3(results, results1) {
-    (results &&= results1 &&= []).push(100);
+    (results && (results = results1 && (results1 = []))).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment7_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment7_es2015.1.normal.js
index 37c27e86f2..32b2539a40 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment7_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment7_es2015.1.normal.js
@@ -7,5 +7,5 @@ function foo2(results, results1) {
     (results !== null && results !== void 0 ? results : results = results1 !== null && results1 !== void 0 ? results1 : results1 = []).push(100);
 }
 function foo3(results, results1) {
-    (results &&= results1 &&= []).push(100);
+    (results && (results = results1 && (results1 = []))).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment7_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment7_es5.1.normal.js
index 37c27e86f2..32b2539a40 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment7_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment7_es5.1.normal.js
@@ -7,5 +7,5 @@ function foo2(results, results1) {
     (results !== null && results !== void 0 ? results : results = results1 !== null && results1 !== void 0 ? results1 : results1 = []).push(100);
 }
 function foo3(results, results1) {
-    (results &&= results1 &&= []).push(100);
+    (results && (results = results1 && (results1 = []))).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment8_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment8_es2015.1.normal.js
index e21826d1ea..696910752a 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment8_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment8_es2015.1.normal.js
@@ -8,5 +8,5 @@ function foo2(results) {
 }
 function foo3(results) {
     var ref;
-    (results &&= (ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && ref !== void 0 ? ref : []).push(100);
+    (results && (results = (ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && ref !== void 0 ? ref : [])).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment8_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment8_es5.1.normal.js
index e21826d1ea..696910752a 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment8_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment8_es5.1.normal.js
@@ -8,5 +8,5 @@ function foo2(results) {
 }
 function foo3(results) {
     var ref;
-    (results &&= (ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && ref !== void 0 ? ref : []).push(100);
+    (results && (results = (ref = bar === null || bar === void 0 ? void 0 : bar.value) !== null && ref !== void 0 ? ref : [])).push(100);
 }
diff --git a/crates/swc/tests/tsc-references/logicalAssignment9_es2015.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment9_es2015.1.normal.js
index 070e3bc730..5b4ab97938 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment9_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment9_es2015.1.normal.js
@@ -1,4 +1,4 @@
-var _x;
+var _x, _x1;
 var _a;
 (_a = (_x = x).a) !== null && _a !== void 0 ? _a : _x.a = true;
-x.a &&= false;
+(_x1 = x).a && (_x1.a = false);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment9_es2015.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment9_es2015.2.minified.js
index 9cd8249665..67a1d65919 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment9_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment9_es2015.2.minified.js
@@ -1,2 +1,2 @@
-var _x, _a;
-null !== (_a = (_x = x).a) && void 0 !== _a || (_x.a = !0), x.a &&= !1;
+var _x, _x1, _a;
+null !== (_a = (_x = x).a) && void 0 !== _a || (_x.a = !0), (_x1 = x).a && (_x1.a = !1);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment9_es5.1.normal.js b/crates/swc/tests/tsc-references/logicalAssignment9_es5.1.normal.js
index 070e3bc730..5b4ab97938 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment9_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment9_es5.1.normal.js
@@ -1,4 +1,4 @@
-var _x;
+var _x, _x1;
 var _a;
 (_a = (_x = x).a) !== null && _a !== void 0 ? _a : _x.a = true;
-x.a &&= false;
+(_x1 = x).a && (_x1.a = false);
diff --git a/crates/swc/tests/tsc-references/logicalAssignment9_es5.2.minified.js b/crates/swc/tests/tsc-references/logicalAssignment9_es5.2.minified.js
index 9cd8249665..67a1d65919 100644
--- a/crates/swc/tests/tsc-references/logicalAssignment9_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/logicalAssignment9_es5.2.minified.js
@@ -1,2 +1,2 @@
-var _x, _a;
-null !== (_a = (_x = x).a) && void 0 !== _a || (_x.a = !0), x.a &&= !1;
+var _x, _x1, _a;
+null !== (_a = (_x = x).a) && void 0 !== _a || (_x.a = !0), (_x1 = x).a && (_x1.a = !1);
diff --git a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs
index 3770445b49..ece493dc25 100644
--- a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs
+++ b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs
@@ -13,16 +13,32 @@ fn syntax() -> Syntax {
     })
 }
 
-test!(syntax(), |_| tr(), logical_ident, "a ||= b", "a || (a = b)");
+test!(
+    syntax(),
+    |_| tr(),
+    logical_ident,
+    "
+    a ||= b
+    a &&= b
+    ",
+    "
+    a || (a = b);
+    a && (a = b);
+    "
+);
 
 test!(
     syntax(),
     |_| tr(),
     logical_member,
-    "a.b ||= b",
+    r#"
+    a.b ||= b
+    a.b &&= b
+    "#,
     "
-    var _a;
+    var _a, _a1;
     (_a = a).b || (_a.b = b);
+    (_a1 = a).b && (_a1.b = b);
     "
 );