From e88527c84fa5a29c3dee39b087c33f214a7da4bd Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 2 Dec 2022 09:57:38 +0800 Subject: [PATCH] fix corner case in `if_return` fixes #5754 --- lib/compress.js | 5 ++++- test/compress/yields.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index b73c3d6643b..2b9aa1ce8ee 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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; diff --git a/test/compress/yields.js b/test/compress/yields.js index b0721b6d6ec..0736adaa0d2 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -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" +}