mirror of
https://github.com/swc-project/swc.git
synced 2024-11-22 06:46:41 +03:00
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:
parent
7aab945a21
commit
65872afaf1
6
.changeset/quick-actors-do.md
Normal file
6
.changeset/quick-actors-do.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_compat_es2015: patch
|
||||
---
|
||||
|
||||
fix(es/generator): Fix code generation for `break` in nested while
|
10
crates/swc/tests/exec/issues-9xxx/9110/.swcrc
Normal file
10
crates/swc/tests/exec/issues-9xxx/9110/.swcrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"externalHelpers": false,
|
||||
"target": "es5"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
36
crates/swc/tests/exec/issues-9xxx/9110/1/exec.js
Normal file
36
crates/swc/tests/exec/issues-9xxx/9110/1/exec.js
Normal 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,
|
||||
});
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user