Repository: swc-project/swc (rust)

Issue:
swc minify bug
### Describe the bug

swc does not recognize the change in the array in some situation.

### Input code

```typescript
var c = 'push'; // maybe any word

for (var a = 1, b = []; a < 5; a++) {
  b[c]({});
}

b[0][d] = 1;
b[e][f] = b[1][g];
```

### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": {
        
      },
      "mangle": false
    },
    "externalHelpers": false
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}
```

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

https://play.swc.rs/?version=1.11.8&code=H4sIAAAAAAAAAxWLsQqDQBAF%2B%2F2K16koqEWqjV%2BybHF7p6ZJDCcaRPz3rNUwMLOHjIgBxXdbXwWjbfEOh40InwO%2FJSeiackod%2B%2BCd30Dc4iy6xMPR11XOAkwiVqeV8V0EZl0Kknvg11GlekWk15lVv4D3BuDjHcAAAA%3D&config=H4sIAAAAAAAAA1WPPQ7DMAiF957CYu7aDj1Blx4CuaRy5D8BkRJFuXsdx0nTDT7e48F8MQZ6sfAwcylLk5GF%2BOgLkSkqjoUA2YBi2WWF6z7tZR0pD1TJsg1AkT%2Bk1SS3pgafklBhHXqhxoKLrpvOeTaFzCRyYsa0YjlyA8aPP5b9ZdOoxBH9k3wmlpOmKiCk91Ct7WWdMm2X3uEn2u9aX6vEyWs31neXL%2B8BHY89AQAA

### SWC Info output

_No response_

### Expected behavior

terser is ok:

![Image](https://github.com/user-attachments/assets/dbec19c6-fde3-40fc-bdad-956f6d77e798)

### Actual behavior

swc does not recognize the change in the array:

![Image](https://github.com/user-attachments/assets/e86d0159-eb73-452c-9304-5002275ea1fb)

### Version

1.11.8

### Additional context

_No response_

Pull request:
fix(es/minifier): Check array inline for indexed with dynamic key
<!-- 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 #10178

Patch:
diff --git a/.changeset/brave-pugs-agree.md b/.changeset/brave-pugs-agree.md
new file mode 100644
index 0000000000..5c65edd891
--- /dev/null
+++ b/.changeset/brave-pugs-agree.md
@@ -0,0 +1,7 @@
+---
+swc_ecma_minifier: patch
+swc_core: patch
+swc_ecma_usage_analyzer: patch
+---
+
+fix(es/minifier): Check array inline for indexed with dynamic key
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs
index 184e27cb9c..21ae1a9e0c 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs
@@ -102,6 +102,7 @@ impl Optimizer<'_> {
             if usage.declared
                 && !usage.mutated()
                 && usage.accessed_props.is_empty()
+                && !usage.indexed_with_dynamic_key
                 && !usage.is_infected()
                 && is_inline_enabled
                 && !usage.used_as_ref
diff --git a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
index 71efbb6bb1..73ba7829b7 100644
--- a/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
+++ b/crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
@@ -367,6 +367,7 @@ where
                             var.add_accessed_property(prop.value.clone());
                         }
 
+                        Expr::Lit(Lit::Str(_) | Lit::Num(_)) => {}
                         _ => {
                             var.mark_indexed_with_dynamic_key();
                         }
@@ -972,6 +973,8 @@ where
                     Expr::Lit(Lit::Str(s)) if s.value.parse::<f64>().is_err() => {
                         v.add_accessed_property(s.value.clone());
                     }
+
+                    Expr::Lit(Lit::Str(_) | Lit::Num(_)) => {}
                     _ => {
                         v.mark_indexed_with_dynamic_key();
                     }


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/10178/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/10178/input.js
new file mode 100644
index 0000000000..6bf34936b0
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/10178/input.js
@@ -0,0 +1,6 @@
+//// [indexerWithTuple.ts]
+var strNumTuple = ["foo", 10],
+    numTupleTuple = [10, ["bar", 20]],
+    unionTuple1 = [10, "foo"],
+    unionTuple2 = [!0, "foo"];
+strNumTuple[0], strNumTuple["0"];
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/10178/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/10178/output.js
new file mode 100644
index 0000000000..5eae0146e2
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/10178/output.js
@@ -0,0 +1,1 @@
+//// [indexerWithTuple.ts]