Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/swc/tests/exec/issues-9xxx/9110/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"externalHelpers": false,
"target": "es5"
},
"isModule": true
}
36 changes: 36 additions & 0 deletions crates/swc/tests/exec/issues-9xxx/9110/1/exec.js
Original file line number Diff line number Diff line change
@@ -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,
});
2 changes: 1 addition & 1 deletion crates/swc_ecma_compat_es2015/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Loading