From: Alex Lam S.L Date: Wed, 13 May 2020 15:44:54 +0000 (+0100) Subject: fix corner case in `reduce_vars` (#3895) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=fe2f1965d6efcd1807eea087708ffdb9a5798db0;p=UglifyJS.git fix corner case in `reduce_vars` (#3895) fixes #3894 --- diff --git a/lib/compress.js b/lib/compress.js index f7c0af30..8cf7262a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -741,6 +741,11 @@ merge(Compressor.prototype, { if (j < 0) return value; return iife.args[j] || make_node(AST_Undefined, iife); }; + d.fixed.reduce_arg = function() { + var j = fn.argnames.indexOf(arg); + if (j < 0 || j >= iife.args.length) return; + iife.args[j] = make_node(AST_Number, iife.args[j], { value: 0 }); + }; tw.loop_ids[d.id] = tw.in_loop; mark(tw, d, true); } else { @@ -7566,6 +7571,7 @@ merge(Compressor.prototype, { })); } else { value = fixed.optimize(compressor); + if (def.fixed.reduce_arg) def.fixed.reduce_arg(); } def.replaced++; return value; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 262a77f2..08accc45 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7068,3 +7068,30 @@ issue_3880: { } expect_stdout: "PASS" } + +issue_3894: { + options = { + collapse_vars: true, + inline: true, + reduce_vars: true, + unused: true, + } + input: { + function log(msg) { + console.log(msg ? "FAIL" : "PASS"); + } + var a; + (function(b) { + a = 0, + log(b); + })(-0); + } + expect: { + function log(msg) { + console.log(msg ? "FAIL" : "PASS"); + } + var a; + void log(-(a = 0)); + } + expect_stdout: "PASS" +}