diff --git a/crates/swc_ecma_minifier/src/compress/optimize/switches.rs b/crates/swc_ecma_minifier/src/compress/optimize/switches.rs index f3730f2e84de..0e5791f89467 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/switches.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/switches.rs @@ -44,7 +44,12 @@ impl Optimizer<'_> { for (idx, case) in stmt.cases.iter_mut().enumerate() { if let Some(test) = case.test.as_ref() { if let Some(e) = is_primitive(&self.expr_ctx, tail_expr(test)) { - if e.eq_ignore_span(tail) { + if match (e, tail) { + (Expr::Lit(Lit::Num(e)), Expr::Lit(Lit::Num(tail))) => { + e.value == tail.value + } + _ => e.eq_ignore_span(tail), + } { cases.push(case.take()); exact = Some(idx); diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/9176/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/9176/input.js new file mode 100644 index 000000000000..5516a3c5436c --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/9176/input.js @@ -0,0 +1,10 @@ +"use strict"; +const k = (function () { + switch (-0) { + case 0: + console.log("hi"); + break; + default: + throw 0; + } +})(); diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/9176/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/9176/output.js new file mode 100644 index 000000000000..5724c24c8e53 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/9176/output.js @@ -0,0 +1,2 @@ +"use strict"; +console.log("hi");