From 02d966d9140a3fd77e1e40f56a6b008ca5d9c9af Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 8 Sep 2022 03:55:59 +0100 Subject: [PATCH] fix corner case in `hoist_props` (#5654) fixes #5653 --- lib/compress.js | 15 ++++++++++++--- test/compress/arrows.js | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index cbddce318e6..73414a1d057 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8486,9 +8486,18 @@ Compressor.prototype.compress = function(node) { return make_sequence(node, assignments); } if (node instanceof AST_Scope) { - if (node === self) return; - var parent = tt.parent(); - if (parent.TYPE == "Call" && parent.expression === node) return; + var parent; + if (node === self || (parent = tt.parent()).TYPE == "Call" && parent.expression === node) { + if (!(is_arrow(node) && node.value)) return; + var stat = node.first_statement(); + node.body = [ stat ]; + node.value = null; + descend(node, tt); + if (node.body.length == 1 && node.body[0] === stat) { + node.body.length = 0; + node.value = stat.value; + } + } return node; } if (node instanceof AST_VarDef) { diff --git a/test/compress/arrows.js b/test/compress/arrows.js index b8837fb7970..78adb4e29b9 100644 --- a/test/compress/arrows.js +++ b/test/compress/arrows.js @@ -1212,3 +1212,28 @@ issue_5495: { expect_stdout: "undefined" node_version: ">=4" } + +issue_5653: { + options = { + arrows: true, + hoist_props: true, + passes: 2, + reduce_vars: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + console.log((a => { + a = { p: console }; + return a++; + })()); + } + expect: { + console.log((a => { + return console, +{}; + })()); + } + expect_stdout: "NaN" + node_version: ">=4" +}