diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-06-09 12:07:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 19:07:20 +0800 |
commit | ed7c82fa5eeffba48513f017ec8115e88b9638ac (patch) | |
tree | 40b60b135061c0bc5a3599d56f7e74bf56f31cde | |
parent | 3b273cecac77b672fd5f9a1d02cebc042b4b73ce (diff) | |
download | tracifyjs-ed7c82fa5eeffba48513f017ec8115e88b9638ac.tar.gz tracifyjs-ed7c82fa5eeffba48513f017ec8115e88b9638ac.zip |
fix corner case in `collapse_vars` (#3978)
fixes #3976
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 907c9e75..cfbafbe4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1468,7 +1468,7 @@ merge(Compressor.prototype, { if (node instanceof AST_Call) { var fn = node.expression; if (fn instanceof AST_SymbolRef) { - if (fn.definition().recursive_refs > 0) return true; + if (recursive_ref(compressor, fn.definition())) return true; fn = fn.fixed_value(); } if (!(fn instanceof AST_Lambda)) return true; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 71c3a147..dcc95b23 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8242,3 +8242,41 @@ issue_3971: { } expect_stdout: "1" } + +issue_3976: { + options = { + collapse_vars: true, + conditionals: true, + evaluate: true, + inline: true, + reduce_vars: true, + unused: true, + } + input: { + function f() { + console.log("FAIL"); + } + (function(a) { + function g() { + if ((a = 0) || f(0)) { + f(); + } else { + f(); + } + if (h(a = 0)); + } + function h() { + g(); + } + })(); + console.log("PASS"); + } + expect: { + function f() { + console.log("FAIL"); + } + void 0; + console.log("PASS"); + } + expect_stdout: "PASS" +} |