Skip to content

Commit

Permalink
fix corner case in hoist_vars (#5188)
Browse files Browse the repository at this point in the history
fixes #5187
  • Loading branch information
alexlamsl committed Nov 23, 2021
1 parent 69636da commit ea10498
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -9071,10 +9071,13 @@ merge(Compressor.prototype, {
right: value,
});
a.push(assign);
name.fixed = function() {
var fixed = function() {
return assign.right;
};
name.fixed.assigns = [ assign ];
fixed.assigns = [ assign ];
fixed.direct_access = def.direct_access;
fixed.escaped = def.escaped;
name.fixed = fixed;
def.references.forEach(function(ref) {
var assigns = ref.fixed && ref.fixed.assigns;
if (assigns && assigns[0] === defn) assigns[0] = assign;
Expand Down
29 changes: 29 additions & 0 deletions test/compress/hoist_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,32 @@ issue_4898: {
}
expect_stdout: "PASS"
}

issue_5187: {
options = {
hoist_props: true,
hoist_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f() {
var a = 42;
do {
var b = { 0: a++ };
} while (console.log(b[b ^= 0]));
}
f();
}
expect: {
(function() {
var b, a = 42;
do {
b = { 0: a++ };
} while (console.log(b[b ^= 0]));
})();
}
expect_stdout: "42"
}

0 comments on commit ea10498

Please sign in to comment.