Repository: swc-project/swc (rust)

Issue:
`obj = foo, obj && ...` should be optimized as `obj = foo && ...`
### Describe the feature

<img width="589" alt="image" src="https://user-images.githubusercontent.com/29931815/187592711-924ab124-3d00-4fba-acb1-b8e805ed251a.png">

### Babel plugin or link to the feature description

_No response_

### Additional context

_No response_

Pull request description:
test(es/minifier): Add a test for a fixed issue
**Description:**


**Related issue (if exists):**


 - Closes #5684

Patch:
diff --git a/crates/swc_ecma_minifier/scripts/update-list.sh b/crates/swc_ecma_minifier/scripts/update-list.sh
index 9cbb3a0546..305684235a 100755
--- a/crates/swc_ecma_minifier/scripts/update-list.sh
+++ b/crates/swc_ecma_minifier/scripts/update-list.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# This script updates golden.txt and TODO.txt
+# This script updates passing.txt and TODO.txt
 # 
 #
 # Note that even if a test is ignored, this script will invoke it.
@@ -14,14 +14,14 @@ function sortFile() {
 
 # Clean the ignore list
 echo '' > tests/TODO.txt
-echo '' > tests/golden.txt
+echo '' > tests/passing.txt
 mv tests/postponed.txt tests/postponed.tmp.txt
 echo '' > tests/postponed.txt
 
 export SWC_RUN=0
 export SWC_CHECK=0
 
-# Update golden.txt
+# Update passing.txt
 cargo test --features concurrent --test compress fixture_tests__terser__compress__ \
   | grep 'fixture_tests__terser__compress__' \
   | grep 'js .\.\. ok$' \
@@ -29,12 +29,12 @@ cargo test --features concurrent --test compress fixture_tests__terser__compress
   | sed -e 's! ... ok!!' \
   | sed -e 's!__!/!g' \
   | sed -e 's!_js!.js!' \
-  >> tests/golden.txt
+  >> tests/passing.txt
 
-sortFile tests/golden.txt
+sortFile tests/passing.txt
 
 # Don't mark passing tests as postponed
-comm -23 tests/postponed.tmp.txt tests/golden.txt > tests/nodup.txt
+comm -23 tests/postponed.tmp.txt tests/passing.txt > tests/nodup.txt
 mv tests/nodup.txt tests/postponed.txt
 rm tests/postponed.tmp.txt
 


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/compress.rs b/crates/swc_ecma_minifier/tests/compress.rs
index 15f5f574c2..f558f0582b 100644
--- a/crates/swc_ecma_minifier/tests/compress.rs
+++ b/crates/swc_ecma_minifier/tests/compress.rs
@@ -61,7 +61,7 @@ fn is_ignored(path: &Path) -> bool {
             .collect()
     });
 
-    static GOLDEN: Lazy<Vec<String>> = Lazy::new(|| load_txt("tests/golden.txt"));
+    static GOLDEN: Lazy<Vec<String>> = Lazy::new(|| load_txt("tests/passing.txt"));
 
     let s = path.to_string_lossy().replace('-', "_").replace('\\', "/");
 
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5684/analysis-snapshot.rust-debug b/crates/swc_ecma_minifier/tests/fixture/issues/5684/analysis-snapshot.rust-debug
new file mode 100644
index 0000000000..06e3d1c3fa
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5684/analysis-snapshot.rust-debug
@@ -0,0 +1,82 @@
+TestSnapshot {
+    vars: [
+        (
+            (
+                Atom('obj' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 3,
+                cond_init: false,
+                declared: true,
+                declared_count: 1,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 2,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: true,
+                has_property_access: true,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: false,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: false,
+                used_in_cond: true,
+                var_kind: Some(
+                    "var",
+                ),
+                var_initialized: true,
+                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('unknown' type=static),
+                #2,
+            ),
+            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/5684/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/5684/config.json
new file mode 100644
index 0000000000..1b9f4f35ac
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5684/config.json
@@ -0,0 +1,5 @@
+{
+    "defaults": true,
+    "toplevel": true,
+    "passes": 1
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5684/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/5684/input.js
new file mode 100644
index 0000000000..953d2a1214
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5684/input.js
@@ -0,0 +1,2 @@
+var obj;
+obj = unknown(), obj && obj.__esModule;
\ No newline at end of file
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.js
new file mode 100644
index 0000000000..d410fee96d
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.js
@@ -0,0 +1,2 @@
+var obj;
+(obj = unknown()) && obj.__esModule;
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.mangleOnly.js b/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.mangleOnly.js
new file mode 100644
index 0000000000..0385433f36
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5684/output.mangleOnly.js
@@ -0,0 +1,2 @@
+var n;
+n = unknown(), n && n.__esModule;