diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-04-18 11:08:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 18:08:05 +0800 |
commit | b38838c6bf064bfe54f0419a5eb7cd4298bfc3a3 (patch) | |
tree | a3fae247735cfa405a218f8b08564fae910bfbdd | |
parent | 708973e51d418230918a2d0c2fcafb79d1e1c250 (diff) | |
download | tracifyjs-b38838c6bf064bfe54f0419a5eb7cd4298bfc3a3.tar.gz tracifyjs-b38838c6bf064bfe54f0419a5eb7cd4298bfc3a3.zip |
fix corner case in `join_vars` (#3796)
fixes #3795
-rw-r--r-- | lib/compress.js | 3 | ||||
-rw-r--r-- | test/compress/join_vars.js | 33 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index d07c2412..d6f6a710 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2371,8 +2371,9 @@ merge(Compressor.prototype, { var lhs = expr.left; if (!(lhs instanceof AST_SymbolRef)) break; if (is_undeclared_ref(lhs)) break; + if (lhs.scope !== scope) break; var def = lhs.definition(); - if (def.scope !== lhs.scope) break; + if (def.scope !== scope) break; if (def.orig.length > def.eliminated + 1) break; if (def.orig[0].TYPE != "SymbolVar") break; var name = make_node(AST_SymbolVar, lhs, lhs); diff --git a/test/compress/join_vars.js b/test/compress/join_vars.js index 9901c486..4e8d3b51 100644 --- a/test/compress/join_vars.js +++ b/test/compress/join_vars.js @@ -782,3 +782,36 @@ issue_3791_2: { } expect_stdout: "function" } + +issue_3795: { + options = { + collapse_vars: true, + conditionals: true, + dead_code: true, + evaluate: true, + join_vars: true, + loops: true, + passes: 2, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = "FAIL"; + function f(b) { + for (var i = 1; b && i; --i) return 0; + a = "PASS"; + } + var c = f(a = ""); + console.log(a); + } + expect: { + var a = "FAIL"; + (function(b) { + a = ""; + a = "PASS"; + })(); + console.log(a); + } + expect_stdout: "PASS" +} |