diff --git a/lib/compress.js b/lib/compress.js index 73c9d653cc..b1971f8a0c 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 e3972b8a6b..fe39cdde4d 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" +}