Repository: swc-project/swc (rust)

Issue:
Minifier converts array to string value incorrectly when `void 0` is in array
### Describe the bug

String representation of array should convert `null` or `undefined` to empty string.
Currently raw `null` or `undefined` is handled well, but with `void 0` element, minifier cannot handle correctly.

### Input code

```typescript
console.log([void 0] + 'swc');
```


### Config

_No response_

### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.6-nightly-20240307.1&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP14guy89MUTCIVdBWUC8uT1bXtOYCAGbAdn0fAAAA&config=H4sIAAAAAAAAA32UO3LjMAyG%2B5zCozrFjostcoDtcgYOTYIyvXxoCNCxJuO7L0TJj40hdRI%2B%2FAAJgPh%2B2%2B26E5ruY%2FfNn%2Fwz6IJQ7v9swTGRvrClAxM1muIH6t5v9IQTcjogNNN1Jh3p0gM1Fe5%2F7feLogs5I9wUiy365N34nNPkOBRAfLKxlUPWCInwf%2F3CSv6aAJX6bD%2FkHECnDaI0Kp8IeihSYJND0AOCOusiRJlOqovHLKWYYCWwaih5EHmynnxOnPOVWtBWmWxBQL6AIX8GSca5WJaQryfcp2ELh9r3rc8%2F1HDWoWoScsKltYRPK0Q9Zo%2BkXE1SCWe4UoMZLsX9qfROFaBa0qvulH1a6clfAK5A0IhJR5DiNg%2FH87SmdptKnxyPLI0C5%2FmWbpmg56Iq751Q2akyUMhL3Sxgq4GpskY6zoJXyofeggLneFaE0PjlyRylpDQOkJ0AuL%2FaSVM1A3V%2FhSt8ehAb%2BA%2FfkuQBWzyipuM6xTEecthIEIGO2W44cCsor%2BPCW%2BIyrPOaLPBogBVdKjbwugT4AVBWoe3Ll9ng58ERVR%2Fy4bEmFofrfQ9HnfrHe59X8dvi0MVsa4PLkp%2F6O6%2Fm393D6baF7wfvPH7elC3p9R%2BoYzQdMAYAAA%3D%3D

### SWC Info output

_No response_

### Expected behavior

```javascript
console.log('swc');
```

### Actual behavior

```javascript
console.log('undefinedswc');
```

### Version

1.4.5

### Additional context

_No response_

Pull request:
fix(es/minifier): Fix evaluation of array literals with `void 0`
**Description:**


**Related issue:**

 - Closes #8706

Patch:
diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs
index 61562fedf5..2963edaca1 100644
--- a/crates/swc_ecma_utils/src/lib.rs
+++ b/crates/swc_ecma_utils/src/lib.rs
@@ -1027,6 +1027,16 @@ pub trait ExprExt {
                             let ExprOrSpread { ref expr, .. } = *elem;
                             match &**expr {
                                 Expr::Lit(Lit::Null(..)) => Cow::Borrowed(""),
+                                Expr::Unary(UnaryExpr {
+                                    op: op!("void"),
+                                    arg,
+                                    ..
+                                }) => {
+                                    if arg.may_have_side_effects(ctx) {
+                                        return Value::Unknown;
+                                    }
+                                    Cow::Borrowed("")
+                                }
                                 Expr::Ident(Ident { sym: undefined, .. })
                                     if &**undefined == "undefined" =>
                                 {


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8706/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/8706/config.json
new file mode 100644
index 0000000000..ee65e9fdc6
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8706/config.json
@@ -0,0 +1,3 @@
+{
+    "defaults": true
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8706/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/8706/input.js
new file mode 100644
index 0000000000..97839772a0
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8706/input.js
@@ -0,0 +1,1 @@
+console.log([void 0] + 'swc');
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8706/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8706/output.js
new file mode 100644
index 0000000000..e7d809d714
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8706/output.js
@@ -0,0 +1,1 @@
+console.log("swc");