From: Alex Lam S.L Date: Sat, 19 Dec 2020 21:47:15 +0000 (+0000) Subject: fix corner case in `evaluate` & `reduce_vars` (#4423) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8ce3c7d70fb476a65dc23f27bb5444ee89e59652;p=UglifyJS.git fix corner case in `evaluate` & `reduce_vars` (#4423) fixes #4422 --- diff --git a/lib/compress.js b/lib/compress.js index d99310ed..7c1c3b42 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -595,7 +595,14 @@ merge(Compressor.prototype, { var expr = node.expression; if (!(expr instanceof AST_SymbolRef)) return; var def = expr.definition(); - if (is_arguments(def) && node.property instanceof AST_Number) def.reassigned = true; + if (!is_arguments(def)) return; + var key = node.property; + if (key.is_constant()) key = key.value; + if (!(key instanceof AST_Node) && !/^[1-9]*[0-9]$/.test(key)) return; + def.reassigned = true; + (key instanceof AST_Node ? def.scope.argnames : [ def.scope.argnames[key] ]).forEach(function(argname) { + if (argname instanceof AST_SymbolFunarg) argname.definition().fixed = false; + }); } function scan_declaration(tw, lhs, fixed, visit) { diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 8ef1a466..7466d63b 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -3094,3 +3094,26 @@ issue_4393: { } expect_stdout: "PASS" } + +issue_4422: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + console.log(function f(a) { + a = "FAIL 1"; + arguments[0] = "PASS"; + return a; + }("FAIL 2")); + } + expect: { + console.log(function(a) { + a = "FAIL 1"; + arguments[0] = "PASS"; + return a; + }("FAIL 2")); + } + expect_stdout: "PASS" +}