fix(es/compat): Handle nested for loops with break/continue (#4777)

This commit is contained in:
Austaras 2022-05-24 19:32:49 +08:00 committed by GitHub
parent 5ddd2dca6d
commit 4f00914c1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 4 deletions

View File

@ -796,10 +796,6 @@ impl VisitMut for FlowHelper<'_> {
match node { match node {
Stmt::Continue(ContinueStmt { label, .. }) => { Stmt::Continue(ContinueStmt { label, .. }) => {
if self.in_nested_loop {
return;
}
let value = if let Some(label) = label { let value = if let Some(label) = label {
let value: JsWord = format!("continue|{}", label.sym).into(); let value: JsWord = format!("continue|{}", label.sym).into();
self.label self.label

View File

@ -0,0 +1,9 @@
out: for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; ++j) {
if (i < 2) continue out;
[1].forEach((_) => {
console.log(i, j);
});
}
}

View File

@ -0,0 +1,24 @@
var _loop = function(i) {
var _loop1 = function(j) {
if (i < 2) return "continue|out";
[
1
].forEach((_)=>{
console.log(i, j);
});
};
for(var j = 0; j < 4; ++j){
var _ret1 = _loop1(j);
switch(_ret1){
case "continue|out":
return "continue|out";
}
}
};
out: for(var i = 0; i < 4; i++){
var _ret = _loop(i);
switch(_ret){
case "continue|out":
continue out;
}
}