From ba3313b083cb6f0ce70d8b2cd66d398c0f8453b6 Mon Sep 17 00:00:00 2001 From: Yongwook Choi Date: Tue, 29 Nov 2022 00:13:52 +0900 Subject: [PATCH] fix --- .../src/compress/pure/properties.rs | 2 +- crates/swc_ecma_minifier/tests/exec.rs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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"]); + "###, + ) +}