Skip to content

Commit c2fe4bf

Browse files
authored
fix(es/minifier): Check array inline for indexed with dynamic key (#10184)
**Related issue:** - Closes #10178
1 parent 56d065e commit c2fe4bf

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

Diff for: .changeset/brave-pugs-agree.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
swc_ecma_minifier: patch
3+
swc_core: patch
4+
swc_ecma_usage_analyzer: patch
5+
---
6+
7+
fix(es/minifier): Check array inline for indexed with dynamic key

Diff for: crates/swc_ecma_minifier/src/compress/optimize/inline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl Optimizer<'_> {
102102
if usage.declared
103103
&& !usage.mutated()
104104
&& usage.accessed_props.is_empty()
105+
&& !usage.indexed_with_dynamic_key
105106
&& !usage.is_infected()
106107
&& is_inline_enabled
107108
&& !usage.used_as_ref
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [indexerWithTuple.ts]
2+
var strNumTuple = ["foo", 10],
3+
numTupleTuple = [10, ["bar", 20]],
4+
unionTuple1 = [10, "foo"],
5+
unionTuple2 = [!0, "foo"];
6+
strNumTuple[0], strNumTuple["0"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//// [indexerWithTuple.ts]

Diff for: crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ where
367367
var.add_accessed_property(prop.value.clone());
368368
}
369369

370+
Expr::Lit(Lit::Str(_) | Lit::Num(_)) => {}
370371
_ => {
371372
var.mark_indexed_with_dynamic_key();
372373
}
@@ -972,6 +973,8 @@ where
972973
Expr::Lit(Lit::Str(s)) if s.value.parse::<f64>().is_err() => {
973974
v.add_accessed_property(s.value.clone());
974975
}
976+
977+
Expr::Lit(Lit::Str(_) | Lit::Num(_)) => {}
975978
_ => {
976979
v.mark_indexed_with_dynamic_key();
977980
}

0 commit comments

Comments
 (0)