diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-02 21:05:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 04:05:52 +0800 |
commit | 203f4b7ad9994f85472402c5be8474755d1d835d (patch) | |
tree | 42feec498fa8f60915e0d148b385bdfbc4c1f7c4 | |
parent | 4114431eec1f822e75b86753a801b720dbe5ad04 (diff) | |
download | tracifyjs-203f4b7ad9994f85472402c5be8474755d1d835d.tar.gz tracifyjs-203f4b7ad9994f85472402c5be8474755d1d835d.zip |
fix corner case in `hoist_vars` (#4900)
fixes #4898
-rw-r--r-- | lib/compress.js | 14 | ||||
-rw-r--r-- | test/compress/hoist_vars.js | 27 |
2 files changed, 36 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js index 73c9d653..b1971f8a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8438,12 +8438,20 @@ merge(Compressor.prototype, { if (value) { if (value instanceof AST_Sequence) value = value.clone(); var name = make_node(AST_SymbolRef, defn.name, defn.name); - name.fixed = value; - a.push(make_node(AST_Assign, defn, { + var assign = make_node(AST_Assign, defn, { operator: "=", left: name, right: value, - })); + }); + a.push(assign); + name.fixed = function() { + return assign.right; + }; + name.fixed.assigns = [ assign ]; + def.references.forEach(function(ref) { + var assigns = ref.fixed && ref.fixed.assigns; + if (assigns && assigns[0] === defn) assigns[0] = assign; + }); def.references.push(name); } def.eliminated++; diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js index e3972b8a..fe39cdde 100644 --- a/test/compress/hoist_vars.js +++ b/test/compress/hoist_vars.js @@ -232,9 +232,8 @@ issue_4736: { expect: { (function() { (function() { - var b = 1 << 30; 0, - console.log(b); + console.log(1073741824); })(); })(); } @@ -373,3 +372,27 @@ issue_4893_2: { } expect_stdout: "PASS" } + +issue_4898: { + options = { + collapse_vars: true, + evaluate: true, + hoist_vars: true, + loops: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + do { + var b = [ console.log("PASS") ]; + var c = b; + } while (c.p = 0); + } + expect: { + var b; + b = [ console.log("PASS") ]; + b.p = 0; + } + expect_stdout: "PASS" +} |