From 5411360829a59fb9b38e5ac360620124a53a31be Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 13 Oct 2022 22:34:55 +0100 Subject: [PATCH] fix corner case in `if_return` (#5711) fixes #5710 --- lib/compress.js | 2 +- test/compress/yields.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 903558585e..3099fcde52 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3536,7 +3536,7 @@ Compressor.prototype.compress = function(node) { var declare_only, jump, merge_jump; var in_iife = in_lambda && parent && parent.TYPE == "Call" && parent.expression === self; var chain_if_returns = in_lambda && compressor.option("conditionals") && compressor.option("sequences"); - var drop_return_void = !(in_try && in_try.bfinally && in_async_generator(in_lambda)); + var drop_return_void = !(in_try && in_try.bfinally && in_async_generator(scope)); var multiple_if_returns = has_multiple_if_returns(statements); for (var i = statements.length; --i >= 0;) { var stat = statements[i]; diff --git a/test/compress/yields.js b/test/compress/yields.js index c49f7f3980..835eff1c6f 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -2039,3 +2039,40 @@ issue_5707: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5710: { + options = { + conditionals: true, + if_return: true, + } + input: { + (async function*() { + try { + switch (42) { + case 42: + { + if (console.log("PASS")) + return; + return null; + } + break; + } + } finally {} + })().next(); + } + expect: { + (async function*() { + try { + switch (42) { + case 42: + if (console.log("PASS")) + return; + return null; + break; + } + } finally {} + })().next(); + } + expect_stdout: "PASS" + node_version: ">=10" +}