mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
feat(es/transforms/optimization): simplify: Preserve do-while loops with conditional stoppers (#1618)
This commit is contained in:
parent
a24266d986
commit
f943021de0
@ -851,6 +851,10 @@ impl Fold for Remover {
|
||||
}
|
||||
|
||||
Stmt::DoWhile(s) => {
|
||||
if has_conditional_stopper(&[Stmt::DoWhile(s.clone())]) {
|
||||
return Stmt::DoWhile(s);
|
||||
}
|
||||
|
||||
if let Known(v) = s.test.as_pure_bool() {
|
||||
if v {
|
||||
// `for(;;);` is shorter than `do ; while(true);`
|
||||
|
@ -307,6 +307,12 @@ fn test_fold_useless_do_extra() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_fold_do_with_conditional_stopper() {
|
||||
test_same("do { if (Date.now() > 0) break; } while (0);");
|
||||
test_same("do { if (Date.now() > 0) continue; } while (0);");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fold_empty_do() {
|
||||
test("do { } while(true);", "for (;;);");
|
||||
|
Loading…
Reference in New Issue
Block a user