Skip to content

Commit 404794f

Browse files
authoredDec 2, 2022
fix corner case in if_return (#5755)
fixes #5754
1 parent 650e63c commit 404794f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
 

‎lib/compress.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,10 @@ Compressor.prototype.compress = function(node) {
37593759
if (!in_lambda) return false;
37603760
if (!(ab instanceof AST_Return)) return false;
37613761
var value = ab.value;
3762-
if (value && !is_undefined(value.tail_node())) return false;
3762+
if (value) {
3763+
if (!drop_return_void) return false;
3764+
if (!is_undefined(value.tail_node())) return false;
3765+
}
37633766
if (!(self instanceof AST_SwitchBranch)) return true;
37643767
if (!jump) return false;
37653768
if (jump instanceof AST_Exit && jump.value) return false;

‎test/compress/yields.js

+38
Original file line numberDiff line numberDiff line change
@@ -2169,3 +2169,41 @@ issue_5749_2: {
21692169
expect_stdout: "PASS"
21702170
node_version: ">=4"
21712171
}
2172+
2173+
issue_5754: {
2174+
options = {
2175+
if_return: true,
2176+
}
2177+
input: {
2178+
async function* f(a, b) {
2179+
try {
2180+
if (a)
2181+
return void 0;
2182+
} finally {
2183+
console.log(b);
2184+
}
2185+
}
2186+
f(42, "foo").next();
2187+
f(null, "bar").next();
2188+
console.log("baz");
2189+
}
2190+
expect: {
2191+
async function* f(a, b) {
2192+
try {
2193+
if (a)
2194+
return void 0;
2195+
} finally {
2196+
console.log(b);
2197+
}
2198+
}
2199+
f(42, "foo").next();
2200+
f(null, "bar").next();
2201+
console.log("baz");
2202+
}
2203+
expect_stdout: [
2204+
"bar",
2205+
"baz",
2206+
"foo",
2207+
]
2208+
node_version: ">=10"
2209+
}

0 commit comments

Comments
 (0)
Please sign in to comment.