Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras committed Apr 20, 2022
1 parent 9e077ac commit d4d11d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/swc_ecma_minifier/src/compress/optimize/switches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ where
.map(|(idx, case)| {
case.test
.as_deref()
.map(|test| test.may_have_side_effects())
.map(|test| is_primitive(test).is_none())
.unwrap_or(false)
|| !(case.cons.is_empty() || case.cons.terminates() || idx == cases.len() - 1)
})
Expand All @@ -239,6 +239,7 @@ where
let mut i = 0;
let len = cases.len();

// may some smarter person find a better solution
while i < len {
if cases[i].cons.is_empty() {
i += 1;
Expand All @@ -264,8 +265,12 @@ where
if found {
self.changed = true;
report_change!("switches: Merging cases with same cons");
let mut len = 1;
while len < j && cases[j - len].cons.is_empty() {
len += 1;
}
cases[j].cons = cases[i].cons.take();
cases[(i + 1)..=j].rotate_right(1);
cases[(i + 1)..=j].rotate_right(len);
i += 1;
}
}
Expand Down

0 comments on commit d4d11d3

Please sign in to comment.