From 86406e71ec93f3f0c44b5d47b261177fbfe43047 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 19 Dec 2021 18:25:38 +0000 Subject: [PATCH] fix corner case in `unused` (#5225) fixes #5224 --- lib/compress.js | 14 ++++++++---- test/compress/drop-unused.js | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index cf8c7eb5..949abac5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8076,7 +8076,11 @@ Compressor.prototype.compress = function(node) { exprs = trim(exprs, compressor, first_in_statement, array_spread); return exprs && make_sequence(self, exprs.map(convert_spread)); } - if (!fn.contains_this()) self = make_node(AST_Call, self, self); + if (!fn.contains_this()) { + self = make_node(AST_Call, self, self); + self.expression = self.expression.clone(); + self.args = self.args.slice(); + } } } self.call_only = true; @@ -9565,7 +9569,7 @@ Compressor.prototype.compress = function(node) { expression: exp.expression, property: "call", }), - args: args + args: args, }).optimize(compressor); } break; @@ -9579,11 +9583,11 @@ Compressor.prototype.compress = function(node) { self.args[0], make_node(AST_Call, self, { expression: exp.expression, - args: self.args.slice(1) - }) + args: self.args.slice(1), + }), ]) : make_node(AST_Call, self, { expression: exp.expression, - args: [] + args: [], })).optimize(compressor); } break; diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index be28ebe7..2c4b7350 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -3516,3 +3516,47 @@ issue_5079: { } expect_stdout: "PASS" } + +issue_5224: { + options = { + evaluate: true, + keep_fargs: false, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f() { + try { + var b = function() { + var a = "FAIL 1"; + null && a; + a = console.log(a); + }(new function(c, d) { + console.log(d); + a; + }("FAIL 2", Infinity)); + } finally { + return f; + } + } + f(); + } + expect: { + (function f() { + try { + (function() { + var a = "FAIL 1"; + null; + a = console.log(a); + })(function() { + console.log(1 / 0); + a; + }()); + } finally { + return f; + } + })(); + } + expect_stdout: "Infinity" +} -- 2.34.1