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 corner case in if_return #5755

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3759,7 +3759,10 @@ Compressor.prototype.compress = function(node) {
if (!in_lambda) return false;
if (!(ab instanceof AST_Return)) return false;
var value = ab.value;
if (value && !is_undefined(value.tail_node())) return false;
if (value) {
if (!drop_return_void) return false;
if (!is_undefined(value.tail_node())) return false;
}
if (!(self instanceof AST_SwitchBranch)) return true;
if (!jump) return false;
if (jump instanceof AST_Exit && jump.value) return false;
Expand Down
38 changes: 38 additions & 0 deletions test/compress/yields.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,3 +2169,41 @@ issue_5749_2: {
expect_stdout: "PASS"
node_version: ">=4"
}

issue_5754: {
options = {
if_return: true,
}
input: {
async function* f(a, b) {
try {
if (a)
return void 0;
} finally {
console.log(b);
}
}
f(42, "foo").next();
f(null, "bar").next();
console.log("baz");
}
expect: {
async function* f(a, b) {
try {
if (a)
return void 0;
} finally {
console.log(b);
}
}
f(42, "foo").next();
f(null, "bar").next();
console.log("baz");
}
expect_stdout: [
"bar",
"baz",
"foo",
]
node_version: ">=10"
}