While investigating removal of breaks from switch cases i noticed that jump symbols inside of switch cases are not being collapsed
switch (a) {
case 1:
if (a) { break; }
else { break; }
}
// result
switch (a) {
case 1:
if (a) break;
break;
}
this works for return stmts or break's in loops
example of working code
switch (a) {
case 1:
if (a) { return; }
else { return; }
}
// result
switch (a) {
case 1: a; return;
}
if (a) {
return;
} else {
return
}
// result
a; return;
// there are 2 optimizations that take place here, first, else is dropped and after that first `if break` is inlined into `test` of loop
while (a) {
if (a) {
break;
} else {
break
}
}
// result
for (; a && !a;) break;
related code:
While investigating removal of breaks from switch cases i noticed that jump symbols inside of switch cases are not being collapsed
this works for return stmts or break's in loops
example of working code
related code:
oxc/crates/oxc_minifier/src/peephole/minimize_statements.rs
Line 828 in 0ed53f1