Repository: swc-project/swc (rust)

Issue:
Minifier would generate invalid lhs
### Describe the bug

Found when updating test in #5342

### Input code

```typescript
({
    x: 0
}).x = _iter[_i];
```


### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.220&code=H4sIAAAAAAAAA9Oo5lIAggorBQOuWk29CgVbhfjMktSi6PjMWGsAoRGqBx0AAAA%3D&config=H4sIAAAAAAAAA22TQXLDIAxF7%2BJ1F50ue4DuegaGgHBIAXmQSOPJ5O4Vjg1x0p31%2FCXEl7gOJzLD53WYdCbI9YvmxPoyfA48T0Am%2B4mHt4FJkNOB4CaBziOwSIA%2B3j%2Fe5XdAJFgFb0P0ybu5FjMYpwxE9VuSSoTE1HQ6Z%2FyVkHOR6IAYQKeXWGlSPjGMkHuqwRD0RKDOOreMeprOnjDtUGGwaso4PdBkPXtMUmxjFrRVBi004DMY9mfoEqkhkkTSWOtkgRYOZRyrgXclnHUomlstuCw2yIkt74ieWLmS6AntOr2j%2ByVXlXcqA5ecNs0Jfdr58AMgfQZNlHSEnrlwJ3PYK90%2FKp%2BcDJHnRmXCvasEo1xOee%2FaDWvXkNl3tzLYYqDe0PTiK9xdiLwFBc6J2y2Zfj2bYy9WlxFdC8U17foM7qHa9mlP6wq8wC%2Fpih%2FHsfKo%2BfjMaI4HDC8lIvAR7QsWIxifYZbtvUzPtCQLYjPYhx%2BFatjWVIbPqEJ9bZvPshCSo8aAh7a%2B8iijTmNby1sFaEsF18U8ea1iRMR0ouHWn%2Bi2U%2FS9qpdqfzFN4fsXBAAA

### Expected behavior

```js
_iter[_i];
```

### Actual behavior

```js
"use strict";
0 = _iter[_i];
```

### Version

1.2.220

### Additional context

_No response_

Pull request description:
fix(es/minifier): ignore member expr with obj lit in assign position
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- 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):**
closes #5343 

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 146cc82a72..3ce3f2a35c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -200,7 +200,7 @@ dependencies = [
 
 [[package]]
 name = "binding_core_wasm"
-version = "1.2.220"
+version = "1.2.221"
 dependencies = [
  "anyhow",
  "console_error_panic_hook",
diff --git a/crates/binding_core_wasm/Cargo.toml b/crates/binding_core_wasm/Cargo.toml
index 9edfe54bd0..d243460de0 100644
--- a/crates/binding_core_wasm/Cargo.toml
+++ b/crates/binding_core_wasm/Cargo.toml
@@ -6,7 +6,7 @@ license = "Apache-2.0"
 name = "binding_core_wasm"
 publish = false
 repository = "https://github.com/swc-project/swc.git"
-version = "1.2.220"
+version = "1.2.221"
 
 [lib]
 bench = false
diff --git a/crates/swc_ecma_ast/src/operators.rs b/crates/swc_ecma_ast/src/operators.rs
index db013e4e66..3df73ee8b1 100644
--- a/crates/swc_ecma_ast/src/operators.rs
+++ b/crates/swc_ecma_ast/src/operators.rs
@@ -181,6 +181,10 @@ impl AssignOp {
             op!("??=") => Some(op!("??")),
         }
     }
+
+    pub fn may_short_circuit(&self) -> bool {
+        matches!(self, op!("??=") | op!("||=") | op!("&&="))
+    }
 }
 
 #[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs
index d7d0f2964b..d063deebd9 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/mod.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/mod.rs
@@ -829,14 +829,28 @@ where
                 return Some(e.take());
             }
 
-            Expr::MetaProp(_)
-            | Expr::Await(_)
-            | Expr::New(..)
-            | Expr::Call(..)
-            | Expr::Yield(_)
-            | Expr::Assign(_)
-            | Expr::PrivateName(_)
-            | Expr::Update(_) => return Some(e.take()),
+            Expr::Assign(AssignExpr {
+                op, left, right, ..
+            }) if left.is_expr() && !op.may_short_circuit() => {
+                if let PatOrExpr::Expr(expr) = left {
+                    if let Expr::Member(m) = &**expr {
+                        if !expr.may_have_side_effects(&self.expr_ctx) && m.obj.is_object() {
+                            if self.should_preserve_property_access(
+                                &m.obj,
+                                PropertyAccessOpts {
+                                    allow_getter: true,
+                                    only_ident: false,
+                                },
+                            ) {
+                                return Some(e.take());
+                            } else {
+                                return Some(*right.take());
+                            }
+                        }
+                    }
+                }
+                return Some(e.take());
+            }
 
             // We drop `f.g` in
             //
@@ -863,6 +877,15 @@ where
             // TODO: Check if it is a pure property access.
             Expr::Member(_) => return Some(e.take()),
 
+            Expr::MetaProp(_)
+            | Expr::Await(_)
+            | Expr::New(..)
+            | Expr::Call(..)
+            | Expr::Yield(_)
+            | Expr::Assign(_)
+            | Expr::PrivateName(_)
+            | Expr::Update(_) => return Some(e.take()),
+
             // Not supported. (At least at the moment)
             Expr::JSXMember(_)
             | Expr::JSXNamespacedName(_)
@@ -1844,6 +1867,7 @@ where
         {
             let ctx = Ctx {
                 in_var_decl_of_for_in_or_of_loop: true,
+                is_exact_lhs_of_assign: n.left.is_pat(),
                 ..self.ctx
             };
             n.left.visit_mut_with(&mut *self.with_ctx(ctx));
@@ -1865,6 +1889,7 @@ where
         {
             let ctx = Ctx {
                 in_var_decl_of_for_in_or_of_loop: true,
+                is_exact_lhs_of_assign: n.left.is_pat(),
                 ..self.ctx
             };
             n.left.visit_mut_with(&mut *self.with_ctx(ctx));
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/props.rs b/crates/swc_ecma_minifier/src/compress/optimize/props.rs
index b5a8a8ab35..6b9bff6cda 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/props.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/props.rs
@@ -230,11 +230,7 @@ where
             return;
         }
 
-        if self.ctx.is_update_arg {
-            return;
-        }
-
-        if self.ctx.is_callee {
+        if self.ctx.is_update_arg || self.ctx.is_callee || self.ctx.is_exact_lhs_of_assign {
             return;
         }
 
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs
index ee82c34e8e..a2c53911b3 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/unused.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/unused.rs
@@ -566,10 +566,7 @@ where
         let assign = match e {
             Expr::Assign(AssignExpr { op: op!("="), .. }) => return,
             // RHS may not be evaluated
-            Expr::Assign(AssignExpr {
-                op: op!("&&=") | op!("||=") | op!("&&="),
-                ..
-            }) => return,
+            Expr::Assign(AssignExpr { op, .. }) if op.may_short_circuit() => return,
             Expr::Assign(e) => e,
             _ => return,
         };
diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs
index 2f3fa5eeab..3305604750 100644
--- a/crates/swc_ecma_utils/src/lib.rs
+++ b/crates/swc_ecma_utils/src/lib.rs
@@ -1274,6 +1274,16 @@ pub trait ExprExt {
                 ..
             }) => left.may_have_side_effects(ctx) || right.may_have_side_effects(ctx),
 
+            Expr::Member(MemberExpr { obj, prop, .. }) if obj.is_object() => {
+                if obj.may_have_side_effects(ctx) {
+                    return true;
+                }
+                match prop {
+                    MemberProp::Computed(c) => c.expr.may_have_side_effects(ctx),
+                    MemberProp::Ident(_) | MemberProp::PrivateName(_) => false,
+                }
+            }
+
             //TODO
             Expr::Tpl(_) => true,
             Expr::TaggedTpl(_) => true,
@@ -1331,12 +1341,12 @@ pub trait ExprExt {
                     || alt.may_have_side_effects(ctx)
             }
 
-            Expr::Object(ObjectLit { ref props, .. }) => props.iter().any(|node| match node {
+            Expr::Object(ObjectLit { props, .. }) => props.iter().any(|node| match node {
                 PropOrSpread::Prop(node) => match &**node {
                     Prop::Shorthand(..) => false,
-                    Prop::KeyValue(KeyValueProp { ref key, ref value }) => {
-                        let k = match *key {
-                            PropName::Computed(ref e) => e.expr.may_have_side_effects(ctx),
+                    Prop::KeyValue(KeyValueProp { key, value }) => {
+                        let k = match key {
+                            PropName::Computed(e) => e.expr.may_have_side_effects(ctx),
                             _ => false,
                         };
 
@@ -1344,7 +1354,8 @@ pub trait ExprExt {
                     }
                     _ => true,
                 },
-                PropOrSpread::Spread(SpreadElement { expr, .. }) => expr.may_have_side_effects(ctx),
+                // may trigger getter
+                PropOrSpread::Spread(_) => true,
             }),
 
             Expr::JSXMember(..)
diff --git a/package.json b/package.json
index 05f2e0e5a6..b00cb6b300 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "@swc/core",
-    "version": "1.2.220",
+    "version": "1.2.221",
     "description": "Super-fast alternative for babel",
     "homepage": "https://swc.rs",
     "main": "./index.js",
@@ -173,4 +173,4 @@
         "postinstall.js",
         "crates/binding_core_wasm/pkg/binding_core_wasm.d.ts"
     ]
-}
\ No newline at end of file
+}


Test patch:
diff --git a/crates/swc/tests/tsc-references/assignmentCompatWithDiscriminatedUnion_es5.2.minified.js b/crates/swc/tests/tsc-references/assignmentCompatWithDiscriminatedUnion_es5.2.minified.js
index 0c22ae7ada..051b9980c9 100644
--- a/crates/swc/tests/tsc-references/assignmentCompatWithDiscriminatedUnion_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/assignmentCompatWithDiscriminatedUnion_es5.2.minified.js
@@ -9,5 +9,5 @@ Example1 || (Example1 = {}), t = s, Example2 || (Example2 = {}), t = s, Example3
     var getAxisType = function() {
         return "categorical";
     };
-    getAxisType(), void 0 = getAxisType();
+    getAxisType(), getAxisType();
 }(GH12052 || (GH12052 = {})), GH18421 || (GH18421 = {}), GH15907 || (GH15907 = {}), GH20889 || (GH20889 = {}), GH39357 || (GH39357 = {});
diff --git a/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es2015.2.minified.js b/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es2015.2.minified.js
index 8f2a3a1b32..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es2015.2.minified.js
@@ -1,1 +0,0 @@
-({}).SomeName;
diff --git a/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es5.2.minified.js b/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es5.2.minified.js
index 8f2a3a1b32..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/checkJsdocTypedefOnlySourceFile_es5.2.minified.js
@@ -1,1 +0,0 @@
-({}).SomeName;
diff --git a/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es2015.2.minified.js b/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es2015.2.minified.js
index 1fa2fa9c2f..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es2015.2.minified.js
@@ -1,3 +0,0 @@
-({}).B = class {
-    m() {}
-};
diff --git a/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es5.2.minified.js b/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es5.2.minified.js
index 51ea44b5e7..1adbda0bc1 100644
--- a/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/checkSpecialPropertyAssignments_es5.2.minified.js
@@ -1,8 +1,1 @@
 import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
-({}).B = function() {
-    "use strict";
-    function _class() {
-        _class_call_check(this, _class);
-    }
-    return _class.prototype.m = function() {}, _class;
-}();
diff --git a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES5_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES5_es5.2.minified.js
index 91d1b49544..1dd1a9f473 100644
--- a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES5_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES5_es5.2.minified.js
@@ -1,4 +1,4 @@
-(void 0).a1, ({}).a2;
+(void 0).a1;
 var tmp = {
     b21: "world"
 };
diff --git a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES6_es5.2.minified.js b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES6_es5.2.minified.js
index 91d1b49544..1dd1a9f473 100644
--- a/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES6_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/destructuringObjectBindingPatternAndAssignment1ES6_es5.2.minified.js
@@ -1,4 +1,4 @@
-(void 0).a1, ({}).a2;
+(void 0).a1;
 var tmp = {
     b21: "world"
 };
diff --git a/crates/swc/tests/tsc-references/intersectionReductionStrict_es5.2.minified.js b/crates/swc/tests/tsc-references/intersectionReductionStrict_es5.2.minified.js
index 8e97984a3e..ba06a21691 100644
--- a/crates/swc/tests/tsc-references/intersectionReductionStrict_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/intersectionReductionStrict_es5.2.minified.js
@@ -1,9 +1,2 @@
-ab.kind;
-var Tag1, Tag2, x2 = {
-    a: "foo",
-    b: !0
-};
-({
-    a: "foo",
-    b: 42
-})[k] = "bar", x2[k] = "bar", Tag1 || (Tag1 = {}), Tag2 || (Tag2 = {}), s2 = s1 = s2, t2 = t1 = t2;
+var Tag1, Tag2;
+ab.kind, Tag1 || (Tag1 = {}), Tag2 || (Tag2 = {}), s2 = s1 = s2, t2 = t1 = t2;
diff --git a/crates/swc/tests/tsc-references/intersectionReduction_es5.2.minified.js b/crates/swc/tests/tsc-references/intersectionReduction_es5.2.minified.js
index db729185a5..3c6b65448a 100644
--- a/crates/swc/tests/tsc-references/intersectionReduction_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/intersectionReduction_es5.2.minified.js
@@ -1,9 +1,2 @@
-ab.kind, f10(a1), f10(a2);
-var Tag1, Tag2, x2 = {
-    a: "foo",
-    b: !0
-};
-({
-    a: "foo",
-    b: 42
-})[k] = "bar", x2[k] = "bar", Tag1 || (Tag1 = {}), Tag2 || (Tag2 = {}), s2 = s1 = s2, t2 = t1 = t2;
+var Tag1, Tag2;
+ab.kind, f10(a1), f10(a2), Tag1 || (Tag1 = {}), Tag2 || (Tag2 = {}), s2 = s1 = s2, t2 = t1 = t2;
diff --git a/crates/swc/tests/tsc-references/jsContainerMergeJsContainer_es5.2.minified.js b/crates/swc/tests/tsc-references/jsContainerMergeJsContainer_es5.2.minified.js
index 1500631efa..428268b78d 100644
--- a/crates/swc/tests/tsc-references/jsContainerMergeJsContainer_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsContainerMergeJsContainer_es5.2.minified.js
@@ -1,2 +1,1 @@
-({}).d = function() {};
 a.d.prototype = {};
diff --git a/crates/swc/tests/tsc-references/jsContainerMergeTsDeclaration3_es5.2.minified.js b/crates/swc/tests/tsc-references/jsContainerMergeTsDeclaration3_es5.2.minified.js
index 831d0ef8e9..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/jsContainerMergeTsDeclaration3_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsContainerMergeTsDeclaration3_es5.2.minified.js
@@ -1,1 +0,0 @@
-({}).d = {};
diff --git a/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es2015.2.minified.js
index ccecfab354..8d59b5c70a 100644
--- a/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es2015.2.minified.js
@@ -1,2 +1,1 @@
-({}).a = 0, ({}).a = 0;
 variable.a = 1, new C().member.a = 1, new C().initializedMember.a = 1, obj.property.a = 1, arr[0].a = 1, getObj().a = 1;
diff --git a/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es5.2.minified.js b/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es5.2.minified.js
index 220eafc898..b7f7aea9a8 100644
--- a/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsObjectsMarkedAsOpenEnded_es5.2.minified.js
@@ -1,8 +1,6 @@
 import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
-({}).a = 0;
 var C = function() {
     "use strict";
     _class_call_check(this, C), this.initializedMember = {}, this.member = {}, this.member.a = 0;
 };
-({}).a = 0;
 variable.a = 1, new C().member.a = 1, new C().initializedMember.a = 1, obj.property.a = 1, arr[0].a = 1, getObj().a = 1;
diff --git a/crates/swc/tests/tsc-references/literalTypesAndDestructuring_es5.2.minified.js b/crates/swc/tests/tsc-references/literalTypesAndDestructuring_es5.2.minified.js
index 5a074be568..de23a8b5ff 100644
--- a/crates/swc/tests/tsc-references/literalTypesAndDestructuring_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/literalTypesAndDestructuring_es5.2.minified.js
@@ -1,1 +1,1 @@
-x.a, x.a, x.a, x.a, x.a, x.a, x.a, x.a, ({}).bar;
+x.a, x.a, x.a, x.a, x.a, x.a, x.a, x.a;
diff --git a/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es2015.2.minified.js b/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es2015.2.minified.js
index 1334a098a0..36842b905c 100644
--- a/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es2015.2.minified.js
@@ -1,2 +1,1 @@
-let guid = "21EC2020-3AEA-4069-A2DD-08002B30309D";
-({})[guid] = 123, ({})[12345] = "hello", guid.toLowerCase(), 12345..toPrecision(0);
+12345..toPrecision(0);
diff --git a/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es5.2.minified.js b/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es5.2.minified.js
index 3d1b60e115..36842b905c 100644
--- a/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/operatorsAndIntersectionTypes_es5.2.minified.js
@@ -1,2 +1,1 @@
-var guid = "21EC2020-3AEA-4069-A2DD-08002B30309D";
-({})[guid] = 123, ({})[12345] = "hello", guid.toLowerCase(), 12345..toPrecision(0);
+12345..toPrecision(0);
diff --git a/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es2015.2.minified.js b/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es2015.2.minified.js
index 252fdac067..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es2015.2.minified.js
@@ -1,1 +0,0 @@
-({})[0] = 1;
diff --git a/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es5.2.minified.js b/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es5.2.minified.js
index 252fdac067..e69de29bb2 100644
--- a/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/propertyAssignmentOnParenthesizedNumber_es5.2.minified.js
@@ -1,1 +0,0 @@
-({})[0] = 1;
diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es2015.2.minified.js
index 3a5120ba4f..b5d76a02c8 100644
--- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es2015.2.minified.js
@@ -1,7 +1,2 @@
 var x;
 Outer.Inner.Message = function() {}, new Outer.Inner().name, x.name;
-({}).Inner = class {
-    name() {
-        return 'hi';
-    }
-};
diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es5.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es5.2.minified.js
index 8d7e9bf37c..ff05f601f0 100644
--- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment24_es5.2.minified.js
@@ -1,12 +1,3 @@
 var x;
 Outer.Inner.Message = function() {}, new Outer.Inner().name, x.name;
 import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
-({}).Inner = function() {
-    "use strict";
-    function _class() {
-        _class_call_check(this, _class);
-    }
-    return _class.prototype.name = function() {
-        return "hi";
-    }, _class;
-}();
diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es2015.2.minified.js
index dca6716f4f..74aa765d9a 100644
--- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es2015.2.minified.js
@@ -1,2 +1,1 @@
-({}).commands = {};
 N.commands.a = 111, N.commands.b = function() {};
diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es5.2.minified.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es5.2.minified.js
index dca6716f4f..74aa765d9a 100644
--- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment34_es5.2.minified.js
@@ -1,2 +1,1 @@
-({}).commands = {};
 N.commands.a = 111, N.commands.b = function() {};
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5343/analysis-snapshot.rust-debug b/crates/swc_ecma_minifier/tests/fixture/issues/5343/analysis-snapshot.rust-debug
new file mode 100644
index 0000000000..33d3565f1b
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5343/analysis-snapshot.rust-debug
@@ -0,0 +1,156 @@
+TestSnapshot {
+    vars: [
+        (
+            (
+                Atom('_i' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 1,
+                cond_init: false,
+                declared: false,
+                declared_count: 0,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 1,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: false,
+                has_property_access: false,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: true,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: false,
+                used_in_cond: false,
+                var_kind: None,
+                var_initialized: false,
+                declared_as_catch_param: false,
+                no_side_effect_for_member_access: false,
+                used_as_callee: false,
+                used_as_arg: false,
+                pure_fn: false,
+                infects: [],
+            },
+        ),
+        (
+            (
+                Atom('_iter' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 1,
+                cond_init: false,
+                declared: false,
+                declared_count: 0,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 1,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: false,
+                has_property_access: true,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: true,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: false,
+                used_in_cond: false,
+                var_kind: None,
+                var_initialized: false,
+                declared_as_catch_param: false,
+                no_side_effect_for_member_access: false,
+                used_as_callee: false,
+                used_as_arg: false,
+                pure_fn: false,
+                infects: [],
+            },
+        ),
+        (
+            (
+                Atom('console' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 1,
+                cond_init: false,
+                declared: false,
+                declared_count: 0,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 1,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: false,
+                has_property_access: true,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: true,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: true,
+                used_in_cond: true,
+                var_kind: None,
+                var_initialized: false,
+                declared_as_catch_param: false,
+                no_side_effect_for_member_access: false,
+                used_as_callee: false,
+                used_as_arg: false,
+                pure_fn: false,
+                infects: [],
+            },
+        ),
+        (
+            (
+                Atom('iter' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 1,
+                cond_init: false,
+                declared: false,
+                declared_count: 0,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 1,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: false,
+                has_property_access: false,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: true,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: false,
+                used_in_cond: false,
+                var_kind: None,
+                var_initialized: false,
+                declared_as_catch_param: false,
+                no_side_effect_for_member_access: false,
+                used_as_callee: true,
+                used_as_arg: false,
+                pure_fn: false,
+                infects: [],
+            },
+        ),
+    ],
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5343/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/5343/input.js
new file mode 100644
index 0000000000..ddb2622ee8
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5343/input.js
@@ -0,0 +1,9 @@
+({
+    x: 0,
+}.x = _iter[_i]);
+
+for ({
+    x: 0,
+}.x of iter()) {
+    console.log(123);
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.js
new file mode 100644
index 0000000000..35b919fc86
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.js
@@ -0,0 +1,3 @@
+for (({
+    x: 0
+}).x of (_iter[_i], iter()))console.log(123);
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.mangleOnly.js b/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.mangleOnly.js
new file mode 100644
index 0000000000..8ba8dfcd11
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5343/output.mangleOnly.js
@@ -0,0 +1,8 @@
+({
+    x: 0
+}.x = _iter[_i]);
+for ({
+    x: 0
+}.x of iter()){
+    console.log(123);
+}