From: Alex Lam S.L Date: Sun, 9 Aug 2020 21:48:56 +0000 (+0100) Subject: fix corner case in `collapse_vars` (#4048) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=49670d216bf7eca9218c797d509e149cd8515708;p=UglifyJS.git fix corner case in `collapse_vars` (#4048) fixes #4047 --- diff --git a/lib/compress.js b/lib/compress.js index 9c1fc3a9..6f739368 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1984,9 +1984,12 @@ merge(Compressor.prototype, { if (expr.name instanceof AST_SymbolFunarg) { var index = compressor.self().argnames.indexOf(expr.name); var args = compressor.parent().args; - if (args[index]) args[index] = make_node(AST_Number, args[index], { - value: 0 - }); + if (args[index]) { + args[index] = make_node(AST_Number, args[index], { + value: 0 + }); + expr.name.definition().fixed = false; + } return true; } var end = hit_stack.length - 1; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index ff6b9a29..7fc4b768 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8391,3 +8391,59 @@ issue_4040: { } expect_stdout: "PASS" } + +issue_4047_1: { + options = { + collapse_vars: true, + evaluate: true, + inline: true, + reduce_vars: true, + sequences: true, + toplevel: true, + unused: true, + } + input: { + var b = 1; + console.log(+function(a) { + b = a; + (a >>= 0) && console.log("PASS"); + }(--b + (0 !== typeof A))); + } + expect: { + var b = 1; + var a; + console.log((a = --b + ((a = 0) !== typeof A), +void ((a >>= 0) && console.log("PASS")))); + } + expect_stdout: [ + "PASS", + "NaN", + ] +} + +issue_4047_2: { + options = { + collapse_vars: true, + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + sequences: true, + toplevel: true, + unused: true, + } + input: { + var b = 1; + console.log(+function(a) { + b = a; + (a >>= 0) && console.log("PASS"); + }(--b + (0 !== typeof A))); + } + expect: { + var a; + console.log((a = +(0 !== typeof A), +void ((a >>= 0) && console.log("PASS")))); + } + expect_stdout: [ + "PASS", + "NaN", + ] +}