Skip to content

minifier: jump smts inside of switch cases are not collapsed #24672

Description

@armano2

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions