mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 09:52:57 +03:00
fix(es/transforms/optimization): Fix dead_branch_remover
(#2373)
swc_ecma_transforms_optimization: - `dead_branch_remover`: Fix handling of `switch(boolean)`.
This commit is contained in:
parent
b0ee9543d4
commit
1f99c3a44c
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2851,7 +2851,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_optimization"
|
||||
version = "0.49.0"
|
||||
version = "0.49.1"
|
||||
dependencies = [
|
||||
"dashmap",
|
||||
"indexmap",
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_optimization"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.49.0"
|
||||
version = "0.49.1"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
@ -602,6 +602,10 @@ impl VisitMut for Remover {
|
||||
&Expr::Lit(Lit::Num(Number { value: test, .. })),
|
||||
&Expr::Lit(Lit::Num(Number { value: d, .. })),
|
||||
) => (test - d).abs() < 1e-10,
|
||||
(
|
||||
&Expr::Lit(Lit::Bool(Bool { value: test, .. })),
|
||||
&Expr::Lit(Lit::Bool(Bool { value: d, .. })),
|
||||
) => test == d,
|
||||
(&Expr::Lit(Lit::Null(..)), &Expr::Lit(Lit::Null(..))) => true,
|
||||
(&Expr::Ident(ref test), &Expr::Ident(ref d)) => {
|
||||
test.sym == d.sym && test.span.ctxt() == d.span.ctxt()
|
||||
|
@ -540,6 +540,11 @@ fn test_optimize_switch_4() {
|
||||
"switch (1) {\ncase 1:\n foo();\n break;\ncase 2:\n bar();\n break;\n}",
|
||||
"foo();",
|
||||
);
|
||||
test(
|
||||
"switch (true) {\ncase true:\n foo();\n break;\ncase false:\n bar();\n break;
|
||||
default: foobar(); break; \n}",
|
||||
"foo();",
|
||||
);
|
||||
test(
|
||||
"switch (1) {\ncase 1.1:\n foo();\n break;\ncase 2:\n bar();\n break;\n}",
|
||||
"",
|
||||
|
Loading…
Reference in New Issue
Block a user