Skip to content

Commit d038b54

Browse files
committed
fix(minifier): remove continue in the end of for-in / for-of
1 parent 358f2fc commit d038b54

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/oxc_minifier/src/peephole/minimize_statements.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ impl<'a> PeepholeOptimizations {
7171
// "while (x) { y(); continue; }" => "while (x) { y(); }"
7272
Statement::ContinueStatement(s) if s.label.is_none() => {
7373
let mut changed = false;
74-
if let Some(Ancestor::ForStatementBody(_)) = ctx.ancestors().nth(1) {
74+
if let Some(
75+
Ancestor::ForStatementBody(_)
76+
| Ancestor::ForInStatementBody(_)
77+
| Ancestor::ForOfStatementBody(_),
78+
) = ctx.ancestors().nth(1)
79+
{
7580
stmts.pop();
7681
changed = true;
7782
}
@@ -1815,5 +1820,9 @@ mod test {
18151820
test("for( a of b ){ if(c) { continue; } d() }", "for ( a of b ) c || d();");
18161821
test("for( a in b ){ if(c) { continue; } d() }", "for ( a in b ) c || d();");
18171822
test("for( ; ; ){ if(c) { continue; } d() }", "for ( ; ; ) c || d();");
1823+
1824+
test("for( a of b ){ c(); continue; }", "for ( a of b ) c();");
1825+
test("for( a in b ){ c(); continue; }", "for ( a in b ) c();");
1826+
test("for( ; ; ){ c(); continue; }", "for ( ; ; ) c();");
18181827
}
18191828
}

0 commit comments

Comments
 (0)