Skip to content

Commit f81fa6e

Browse files
authoredJul 11, 2024··
fix(es/minifier): Fix case matching (#9208)
**Description:** Caused by #7112 Since swc minifier evaluates expressions in a separate pass, I make a temporary patch here. **Related issue:** - Closes #9176
1 parent bcfc650 commit f81fa6e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎crates/swc_ecma_minifier/src/compress/optimize/switches.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ impl Optimizer<'_> {
4444
for (idx, case) in stmt.cases.iter_mut().enumerate() {
4545
if let Some(test) = case.test.as_ref() {
4646
if let Some(e) = is_primitive(&self.expr_ctx, tail_expr(test)) {
47-
if e.eq_ignore_span(tail) {
47+
if match (e, tail) {
48+
(Expr::Lit(Lit::Num(e)), Expr::Lit(Lit::Num(tail))) => {
49+
e.value == tail.value
50+
}
51+
_ => e.eq_ignore_span(tail),
52+
} {
4853
cases.push(case.take());
4954

5055
exact = Some(idx);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
const k = (function () {
3+
switch (-0) {
4+
case 0:
5+
console.log("hi");
6+
break;
7+
default:
8+
throw 0;
9+
}
10+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
console.log("hi");

0 commit comments

Comments
 (0)
Please sign in to comment.