diff --git a/crates/swc_ecma_minifier/src/compress/pure/properties.rs b/crates/swc_ecma_minifier/src/compress/pure/properties.rs index 2a7bad6b5637..2388f6debfe5 100644 --- a/crates/swc_ecma_minifier/src/compress/pure/properties.rs +++ b/crates/swc_ecma_minifier/src/compress/pure/properties.rs @@ -95,7 +95,7 @@ impl Pure<'_> { return; } - if !s.value.starts_with('0') || s.value.len() <= 1 { + if (!s.value.starts_with('0') && !s.value.starts_with('+')) || s.value.len() <= 1 { if let Ok(v) = s.value.parse::() { self.changed = true; report_change!("misc: Optimizing numeric property name"); diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 5508fa9fc641..a00ad7941c36 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -10374,3 +10374,23 @@ fn issue_6463_1() { "###, ); } + +#[test] +fn issue_6528() { + run_default_exec_test( + r###" + const foo = { + "+1": 1, + "2": 2, + "-3": 3, + } + + console.log(foo[1]); + console.log(foo["+1"]); + console.log(foo["2"]); + console.log(foo[2]); + console.log(foo[-3]); + console.log(foo["-3"]); + "###, + ) +}