Repository: swc-project/swc (rust)

Issue:
Spreading array into arrow function receives undefined arguments
### Describe the bug

It seems that arrays destructuring optimizations with arrow functions are incorrect.

### Input code

```typescript
function logTheNine() {
  ((theThree, theNine) => {
    console.log(theNine)
  })(...[ 3, 9 ]);
}

logTheNine();
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2018",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": true,
        "hoist_vars": false,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": true,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": false,
        "unsafe_arrows": false,
        "unsafe_comps": false,
        "unsafe_Function": false,
        "unsafe_math": false,
        "unsafe_symbols": false,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true,
        "passes": 2
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


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

https://play.swc.rs/?version=1.4.11&code=H4sIAAAAAAAAA%2BNKK81LLsnMz1PIyU8PyUj1y8xL1dBUqOZSUNDQKMlIDckoSk3VUSiByGgq2NqB5RQUkvPzivNzUvWA2jRgskCJWk0NPT29aAVjHQVLhVhNa65aLi5kk625AHmWkb5yAAAA&config=H4sIAAAAAAAAA32US3LbMAyG9z6FR%2Bsu2iwynRygu56BQ5OgTJcPDQE61mR890CU7LgxpJ2EDz9AAiA%2Bdvt9d0LTve0%2F%2BJN%2FBl0Qyv2fLTgm0he2dGCiRlP8QN2PGz3hhJwOCM10nUlHuvRATYUvP3%2F9XhRdyBnhplhs0SfvxsecJsehAOKDja0cskZIhP%2FrF1by%2BwSo1Ef7IecAOm0QpVH5RNBDkQKbHIIeENRZFyHKdFJdPGYpxQQrgVVDyYPIk%2FXkc%2BKcz9SCtspkCwLyBQz5M0gyzsWyhHw94T4NWzjUvm99%2FqaGsw5Vk5ATLq0lfFoh6jF7JOVqkko4w5UazHAp7neld6oA1ZKedafs00pP%2FgFwBYJGTDqCFLd5OJ6nNbXbVPrkeGRpFDjPt3TLBD0XVXnvhMpOlYFCXupmAVsNTJU10nEWvFI%2B9BYUOMezIoTGd0%2FmKCWlcYDsBMD91U6aqhmo%2Bytc4dOD2MB%2F%2BJYkD9jiETUd1ymO8ZDDRoIIdMx2w4FbQXkdF94Sl2Gd12SBRwOs6FKxgeclwA%2BAsgptXz7NBj8Pjqj6kA%2Fimhh4zlsTXxbb9b6co0791xKY9%2FNucehitrXBZfNPTZ%2F39Wv35XRbzffbdB7%2F3pTTSXbXTzRLP3hFBgAA

### SWC Info output

console.log(void 0);

### Expected behavior

console.log(9);

### Actual behavior

console.log(void 0);

### Version

1.4.11

### Additional context

Original issue: https://github.com/fullcalendar/temporal-polyfill/issues/36

Pull request description:
fix(es/minifier): Abort fn inliner if there's a spread arg
**Description:**


**Related issue:**

 - Closes #8806

Patch:
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs
index 702952b458..6d8200c5d5 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/iife.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/iife.rs
@@ -835,6 +835,10 @@ impl Optimizer<'_> {
             return None;
         }
 
+        if args.iter().any(|arg| arg.spread.is_some()) {
+            return None;
+        }
+
         if self.vars.inline_with_multi_replacer(body) {
             self.changed = true;
         }


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8806/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/8806/config.json
new file mode 100644
index 0000000000..91c951a76c
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8806/config.json
@@ -0,0 +1,48 @@
+{
+    "defaults": true,
+    "arguments": false,
+    "arrows": true,
+    "booleans": true,
+    "booleans_as_integers": false,
+    "collapse_vars": true,
+    "comparisons": true,
+    "computed_props": true,
+    "conditionals": true,
+    "dead_code": true,
+    "directives": true,
+    "drop_console": false,
+    "drop_debugger": true,
+    "evaluate": true,
+    "expression": false,
+    "hoist_funs": false,
+    "hoist_props": true,
+    "hoist_vars": false,
+    "if_return": true,
+    "join_vars": true,
+    "keep_classnames": false,
+    "keep_fargs": true,
+    "keep_fnames": false,
+    "keep_infinity": false,
+    "loops": true,
+    "negate_iife": true,
+    "properties": true,
+    "reduce_funcs": false,
+    "reduce_vars": false,
+    "side_effects": true,
+    "switches": true,
+    "typeofs": true,
+    "unsafe": false,
+    "unsafe_arrows": false,
+    "unsafe_comps": false,
+    "unsafe_Function": false,
+    "unsafe_math": false,
+    "unsafe_symbols": false,
+    "unsafe_methods": false,
+    "unsafe_proto": false,
+    "unsafe_regexp": false,
+    "unsafe_undefined": false,
+    "unused": true,
+    "const_to_let": true,
+    "pristine_globals": true,
+    "passes": 2
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8806/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/8806/input.js
new file mode 100644
index 0000000000..0c78cf9a8e
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8806/input.js
@@ -0,0 +1,8 @@
+
+function logTheNine() {
+    ((theThree, theNine) => {
+        console.log(theNine)
+    })(...[3, 9]);
+}
+
+logTheNine();
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8806/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8806/output.js
new file mode 100644
index 0000000000..40a257d077
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8806/output.js
@@ -0,0 +1,9 @@
+function logTheNine() {
+    ((theThree, theNine)=>{
+        console.log(theNine);
+    })(...[
+        3,
+        9
+    ]);
+}
+logTheNine();