From: Alex Lam S.L Date: Fri, 18 Dec 2020 20:53:53 +0000 (+0000) Subject: fix corner case in `arguments` (#4411) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0f55bd92f18bd27628f1cfd10c9fb5d70f4d4d29;p=UglifyJS.git fix corner case in `arguments` (#4411) fixes #4410 --- diff --git a/lib/compress.js b/lib/compress.js index ab68c45d..f33b97bc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9905,6 +9905,7 @@ merge(Compressor.prototype, { } else if (argname instanceof AST_Destructured) { argname = null; } else if (argname && (compressor.has_directive("use strict") + || fn.name || !(fn_parent instanceof AST_Call && index < fn_parent.args.length) || !all(fn.argnames, function(argname) { return !(argname instanceof AST_Destructured); diff --git a/test/compress/arguments.js b/test/compress/arguments.js index c3ef226e..39628b50 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -871,3 +871,74 @@ issue_4397: { } expect_stdout: "string" } + +issue_4410_1: { + options = { + arguments: true, + conditionals: true, + evaluate: true, + reduce_vars: true, + } + input: { + (function(a) { + console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS"); + })(1); + } + expect: { + (function(a) { + console.log(a === (a = 0) ? "FAIL" : "PASS"); + })(1); + } + expect_stdout: "PASS" +} + +issue_4410_2: { + options = { + arguments: true, + conditionals: true, + evaluate: true, + reduce_vars: true, + } + input: { + (function f(a) { + console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS"); + })(1); + } + expect: { + (function f(a) { + console.log(arguments[0] === (a = 0) ? "FAIL" : "PASS"); + })(1); + } + expect_stdout: "PASS" +} + +issue_4410_3: { + options = { + arguments: true, + } + input: { + var a = 1; + (function f(b) { + a-- && f(); + for (var c = 2; c--;) + switch (arguments[0]) { + case b = 42: + case 42: + console.log("PASS"); + } + })(null); + } + expect: { + var a = 1; + (function f(b) { + a-- && f(); + for (var c = 2; c--;) + switch (arguments[0]) { + case b = 42: + case 42: + console.log("PASS"); + } + })(null); + } + expect_stdout: "PASS" +}