Repository: swc-project/swc (rust)

Issue:
compress.arguments = true brokes arr["a space b"]
### Describe the bug

When `compress.arguments` is `true` it brokes index accesses when index is string and matches `/^[a-z]/i`. Only `example1` will fail.

### Input code

```typescript
export const example1 = (param) =>
  param => param["There is something wrong!"];

export const example2 = (param) =>
  param => param["123 is fine"];

export const example3 = (param) =>
  param => param["! That is fine !"];

export const example4 = (param) =>
  param => param[" space in start works fine"];

export const example5 = (param) =>
  param => param[123];
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": true,
        "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
      },
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.37&code=H4sIAAAAAAAAA4XPvQ6CQBAE4P6eYqDSEtDK4FPQEYsNWbmL3k%2F2LoHH95TQSa6bZr7M8Bq8JEzexQReyYY3N%2BhxCiRkz%2BjvCvjlHLcw1oNmYZiI6C0nbdyMRbybq%2FpxU4r%2FkG2JbNruCz6N40OkKyEVBk1pd3A851KSEANN%2BaJDTJTbi5dXYd21YOaHufoBjMAqg3ABAAA%3D&config=H4sIAAAAAAAAA22TQZLjIAxF7%2BJ1FlNZ9KIPMLs%2BA6WAcOjByIVEOq5U7j7CsXGc9M56%2FhLiS9y6b7bd560bITPm%2BsVTErh2nx3aAdjmMEp3UJkiD5HxfugEco9SJXz8czzq70jEuAgO3RBS8FMtZmkYMzLXb00qAybRQHJRGeRMPy06EUWE9BYbYBOSYI%2BZ2wmWYoSR0Vwgt4x6GOTAlHaoCDozZhqfaHJBAiUttjKH4Iwlhw2EjFbCBTeJ1lBJYm2sdTJDh6fS99W%2FhxIvEAtIq4XX2QU9seWdKbAYXxK%2FoF2nD%2FS45KIK3mSUktOq%2BaaQdj78Q9Q%2BIzAnGHDLnLnXMeyV%2FhdVSF5nKFOjOuCtq4S9Xs6E4NsNa9eYJWxuZXTFYr2h3YovcHchDg4Neq9ut2T%2BCWLPWzGZRiTfQnUN%2FDaDR2jWfdrTugJv8K92Jc%2FjWPgAcn5lPA0nim8lBpQzuTesRgi9wqzbex1faUkO1WZ0Tz8K17CtqQ5fyMT62FafdSE0x%2FSRTm199U0OkPq2lvcKyJUKbrN582P96O7b41zXib8W4VzoP9zQhRURBAAA

### Expected behavior

```
export const example1 = (param)=>(param)=>param.["There is something wrong!"[;
export const example2 = (param)=>(param)=>param["123 is fine"];
export const example3 = (param)=>(param)=>param["! That is fine !"];
export const example4 = (param)=>(param)=>param[" space in start works fine"];
export const example5 = (param)=>(param)=>param[123];
```

### Actual behavior

```
export const example1 = (param)=>(param)=>param.There is something wrong!;
export const example2 = (param)=>(param)=>param["123 is fine"];
export const example3 = (param)=>(param)=>param["! That is fine !"];
export const example4 = (param)=>(param)=>param[" space in start works fine"];
export const example5 = (param)=>(param)=>param[123];
```

### Version

1.3.37

### Additional context

_No response_

Pull request description:
fix(es/minifier): Disable computed access optimization for invalid pr…
…op identifiers

<!-- 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):**
- fix #7009 


Patch:
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs b/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs
index 984169b0bf..535a0e63b0 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/arguments.rs
@@ -3,7 +3,7 @@ use std::iter::repeat_with;
 use swc_atoms::js_word;
 use swc_common::{util::take::Take, DUMMY_SP};
 use swc_ecma_ast::*;
-use swc_ecma_utils::{find_pat_ids, private_ident};
+use swc_ecma_utils::{find_pat_ids, is_valid_prop_ident, private_ident};
 use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
 
 use super::Optimizer;
@@ -29,6 +29,10 @@ where
                             return;
                         }
 
+                        if !is_valid_prop_ident(&s.value) {
+                            return;
+                        }
+
                         self.changed = true;
                         report_change!("arguments: Optimizing computed access to arguments");
                         *prop = MemberProp::Ident(Ident {
@@ -47,6 +51,10 @@ where
                             return;
                         }
 
+                        if !is_valid_prop_ident(&s.value) {
+                            return;
+                        }
+
                         self.changed = true;
                         report_change!("arguments: Optimizing computed access to arguments");
                         *prop = SuperProp::Ident(Ident {


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/7009/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/7009/config.json
new file mode 100644
index 0000000000..de86de31d9
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/7009/config.json
@@ -0,0 +1,46 @@
+{
+    "arguments": true,
+    "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
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/7009/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/7009/input.js
new file mode 100644
index 0000000000..b0fb1f2f7b
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/7009/input.js
@@ -0,0 +1,20 @@
+export const example1 = (param) =>
+  param => param["There is something wrong!"];
+
+export const example2 = (param) =>
+  param => param["123 is fine"];
+
+export const example3 = (param) =>
+  param => param["! That is fine !"];
+
+export const example4 = (param) =>
+  param => param[" space in start works fine"];
+
+export const example5 = (param) =>
+  param => param[123];
+
+export class Foo extends Bar {
+  foo() {
+    super["a space b"]();
+  }
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/7009/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/7009/output.js
new file mode 100644
index 0000000000..9b317fe56b
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/7009/output.js
@@ -0,0 +1,10 @@
+export const example1 = (param)=>(param)=>param["There is something wrong!"];
+export const example2 = (param)=>(param)=>param["123 is fine"];
+export const example3 = (param)=>(param)=>param["! That is fine !"];
+export const example4 = (param)=>(param)=>param[" space in start works fine"];
+export const example5 = (param)=>(param)=>param[123];
+export class Foo extends Bar {
+    foo() {
+        super["a space b"]();
+    }
+}