From: Alex Lam S.L Date: Fri, 25 Dec 2020 14:50:11 +0000 (+0000) Subject: fix corner case in `reduce_vars` (#4459) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=95aea0e33ce0288d7c31b11b044432f2043cf3d1;p=UglifyJS.git fix corner case in `reduce_vars` (#4459) fixes #4458 --- diff --git a/lib/compress.js b/lib/compress.js index 1dc01f93..e4506f75 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -879,6 +879,13 @@ merge(Compressor.prototype, { pop(tw); return true; }); + def(AST_DefaultValue, function(tw) { + this.name.walk(tw); + push(tw); + this.value.walk(tw); + pop(tw); + return true; + }); def(AST_Defun, reduce_defun); def(AST_Do, function(tw) { var saved_loop = tw.in_loop; diff --git a/test/compress/default-values.js b/test/compress/default-values.js index bda32c1b..eefa6e0e 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -1076,3 +1076,27 @@ issue_4446_2: { expect_stdout: "PASS 42" node_version: ">=6" } + +issue_4458: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = "PASS"; + function f(b = a = "FAIL") { + console.log(a, b); + } + f(42); + } + expect: { + var a = "PASS"; + (function(b = a = "FAIL") { + console.log(a, b); + })(42); + } + expect_stdout: "PASS 42" + node_version: ">=6" +}