Skip to content

Commit 65872af

Browse files
authoredOct 29, 2024··
fix(es/generator): Fix code generation for break in nested while (#9684)
**Related issue:** - Closes #9110
1 parent 7aab945 commit 65872af

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed
 

‎.changeset/quick-actors-do.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_compat_es2015: patch
4+
---
5+
6+
fix(es/generator): Fix code generation for `break` in nested while
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "ecmascript"
5+
},
6+
"externalHelpers": false,
7+
"target": "es5"
8+
},
9+
"isModule": true
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function* test() {
2+
while (!False()) {
3+
// execute this line
4+
while (!False()) {
5+
// execute this line
6+
break;
7+
}
8+
// execute this line
9+
if (False()) {
10+
// NOT execute this line
11+
break;
12+
}
13+
14+
// execute this line
15+
yield "correct";
16+
return;
17+
}
18+
19+
// NOT execute this line
20+
yield "wrong";
21+
return;
22+
}
23+
24+
function False() {
25+
return false;
26+
}
27+
28+
const t = test();
29+
expect(t.next()).toEqual({
30+
value: "correct",
31+
done: false,
32+
});
33+
expect(t.next()).toEqual({
34+
value: undefined,
35+
done: true,
36+
});

‎crates/swc_ecma_compat_es2015/src/generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ impl Generator {
16591659
self.emit_break(loop_label, None);
16601660
self.end_loop_block();
16611661
} else {
1662-
node.visit_mut_children_with(self);
1662+
node.visit_mut_with(self);
16631663

16641664
self.emit_stmt(node.into());
16651665
}

0 commit comments

Comments
 (0)
Please sign in to comment.