fix(es/generator): Fix code generation for break in nested while (#9684)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/9110
This commit is contained in:
CPunisher 2024-10-29 06:21:11 -07:00 committed by GitHub
parent 7aab945a21
commit 65872afaf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_compat_es2015: patch
---
fix(es/generator): Fix code generation for `break` in nested while

View File

@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"externalHelpers": false,
"target": "es5"
},
"isModule": true
}

View File

@ -0,0 +1,36 @@
function* test() {
while (!False()) {
// execute this line
while (!False()) {
// execute this line
break;
}
// execute this line
if (False()) {
// NOT execute this line
break;
}
// execute this line
yield "correct";
return;
}
// NOT execute this line
yield "wrong";
return;
}
function False() {
return false;
}
const t = test();
expect(t.next()).toEqual({
value: "correct",
done: false,
});
expect(t.next()).toEqual({
value: undefined,
done: true,
});

View File

@ -1659,7 +1659,7 @@ impl Generator {
self.emit_break(loop_label, None);
self.end_loop_block();
} else {
node.visit_mut_children_with(self);
node.visit_mut_with(self);
self.emit_stmt(node.into());
}