From 77c4103f509a0277e5331c4dad97d2f1e1d24c59 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 30 Oct 2024 14:00:00 +0200 Subject: [PATCH] fix corner case in `inline` fixes #5956 --- lib/compress.js | 10 +++-- test/compress/awaits.js | 85 +++++++++++++++++++++++++++++++++++++++++ test/compress/yields.js | 43 +++++++++++++++++++++ 3 files changed, 135 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 9cf80de5d0..075e168d27 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -14330,18 +14330,22 @@ Compressor.prototype.compress = function(node) { if (node instanceof AST_Return) return abort = true; if (node instanceof AST_Scope) return true; }); - stat.walk(new TreeWalker(function(node) { + var tw = new TreeWalker(function(node) { if (abort) return true; if (node instanceof AST_Try) { if (!node.bfinally) return; if (all(node.body, function(stat) { stat.walk(find_return); return !abort; - }) && node.bcatch) node.bcatch.walk(find_return); + })) { + if (node.bcatch) node.bcatch.walk(find_return); + node.bfinally.walk(tw); + } return true; } if (node instanceof AST_Scope) return true; - })); + }); + stat.walk(tw); return !abort; }; } diff --git a/test/compress/awaits.js b/test/compress/awaits.js index aafddaece8..05c5d2bc08 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -3729,3 +3729,88 @@ issue_5791: { ] node_version: ">=8" } + +issue_5842: { + options = { + awaits: true, + inline: true, + } + input: { + var a = "FAIL"; + (async function() { + await function() { + try { + try { + return console; + } finally { + a = "PASS"; + } + } catch (e) {} + FAIL; + }(); + })(); + console.log(a); + } + expect: { + var a = "FAIL"; + (async function() { + await function() { + try { + try { + return console; + } finally { + a = "PASS"; + } + } catch (e) {} + FAIL; + }(); + })(); + console.log(a); + } + expect_stdout: "PASS" + node_version: ">=8" +} + +issue_5956: { + options = { + awaits: true, + inline: true, + } + input: { + (async function() { + await function() { + try { + FAIL; + } finally { + try { + return 42; + } finally { + console.log("foo"); + } + } + }(); + })(); + console.log("bar"); + } + expect: { + (async function() { + await function() { + try { + FAIL; + } finally { + try { + return 42; + } finally { + console.log("foo"); + } + } + }(); + })(); + console.log("bar"); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=8" +} diff --git a/test/compress/yields.js b/test/compress/yields.js index eebdf4b8cb..88fee90bb3 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -2302,3 +2302,46 @@ issue_5842: { expect_stdout: "PASS" node_version: ">=10" } + +issue_5956: { + options = { + inline: true, + } + input: { + (async function*() { + (function() { + try { + FAIL; + } finally { + try { + return console; + } finally { + console.log("foo"); + } + } + })(); + })().next(); + console.log("bar"); + } + expect: { + (async function*() { + (function() { + try { + FAIL; + } finally { + try { + return console; + } finally { + console.log("foo"); + } + } + })(); + })().next(); + console.log("bar"); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=10" +}