From ebe4e1ad28009bdf5b2e936ed8d01d7d20704cc4 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 7 Apr 2021 23:31:15 +0100 Subject: [PATCH] fix corner case in `unused` (#4850) fixes #4849 --- lib/compress.js | 1 + test/compress/exponentiation.js | 4 ++-- test/compress/spreads.js | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 5a9c8b7899..437baabfe5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9393,6 +9393,7 @@ merge(Compressor.prototype, { var seq = lift_sequence_in_expression(self, compressor); if (seq !== self) return seq.optimize(compressor); } + if (compressor.option("unused")) drop_unused_call_args(self, compressor); if (compressor.option("unsafe")) { var exp = self.expression; if (is_undeclared_ref(exp)) { diff --git a/test/compress/exponentiation.js b/test/compress/exponentiation.js index 1a678f520a..e945e13ea5 100644 --- a/test/compress/exponentiation.js +++ b/test/compress/exponentiation.js @@ -99,8 +99,8 @@ issue_4664: { expect: { (function f() { new function(a) { - console.log(typeof f, 2 ** 30, typeof this); - }(0, A = 0); + console.log(typeof f, 1073741824, typeof this); + }(A = 0); })(); } expect_stdout: "function 1073741824 object" diff --git a/test/compress/spreads.js b/test/compress/spreads.js index 02bb3f0ec1..4e5d0d987a 100644 --- a/test/compress/spreads.js +++ b/test/compress/spreads.js @@ -1045,3 +1045,26 @@ issue_4614: { expect_stdout: true node_version: ">=6" } + +issue_4849: { + options = { + reduce_vars: true, + unused: true, + } + input: { + while (function() { + while (!console); + }(new function(a) { + console.log(typeof { ...a }); + }(function() {}))); + } + expect: { + while (function() { + while (!console); + }(function(a) { + console.log(typeof { ...function() {} }); + }())); + } + expect_stdout: "object" + node_version: ">=8" +}