diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-25 14:50:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 22:50:11 +0800 |
commit | 95aea0e33ce0288d7c31b11b044432f2043cf3d1 (patch) | |
tree | e178048a72cef9e15236f53c7791288d263a0e2e | |
parent | a1b2735dd8f7f89b7dd57ee7098f1720df28838f (diff) | |
download | tracifyjs-95aea0e33ce0288d7c31b11b044432f2043cf3d1.tar.gz tracifyjs-95aea0e33ce0288d7c31b11b044432f2043cf3d1.zip |
fix corner case in `reduce_vars` (#4459)
fixes #4458
-rw-r--r-- | lib/compress.js | 7 | ||||
-rw-r--r-- | test/compress/default-values.js | 24 |
2 files changed, 31 insertions, 0 deletions
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" +} |