Skip to content

Commit

Permalink
fix corner case in reduce_vars (#5325)
Browse files Browse the repository at this point in the history
fixes #5324
  • Loading branch information
alexlamsl committed Jan 29, 2022
1 parent e7d6dd2 commit 0a5a1f3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ Compressor.prototype.compress = function(node) {
right: node.right,
});
};
left.fixed.assigns = !fixed || !fixed.assigns ? [] : fixed.assigns.slice();
left.fixed.assigns = !fixed || !fixed.assigns ? [ ld.orig[0] ] : fixed.assigns.slice();
left.fixed.assigns.push(node);
left.fixed.to_binary = replace_ref(left, fixed);
} else {
Expand Down
32 changes: 28 additions & 4 deletions test/compress/drop-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ issue_3956: {
collapse_vars: true,
evaluate: true,
inline: true,
passes: 2,
passes: 3,
reduce_vars: true,
sequences: true,
side_effects: true,
Expand Down Expand Up @@ -2787,7 +2787,7 @@ issue_3986: {
expect_stdout: "0"
}

issue_4017: {
issue_4017_1: {
options = {
pure_getters: "strict",
reduce_vars: true,
Expand All @@ -2805,7 +2805,31 @@ issue_4017: {
var a = 0;
console.log(function() {
c &= 0;
var c;
var c = a++ + (A = a);
}());
}
expect_stdout: "undefined"
}

issue_4017_2: {
options = {
passes: 2,
pure_getters: "strict",
reduce_vars: true,
unused: true,
}
input: {
var a = 0;
console.log(function f() {
var b = c &= 0;
var c = a++ + (A = a);
var d = c && c[f];
}());
}
expect: {
var a = 0;
console.log(function() {
0;
a++,
A = a;
}());
Expand Down Expand Up @@ -3248,7 +3272,7 @@ issue_4558_1: {
expect: {
var a = 0;
var b = c >>>= a;
var c;
var c = 0;
b && a++,
console.log(a);
}
Expand Down
29 changes: 29 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7832,3 +7832,32 @@ issue_5055_2: {
}
expect_stdout: "PASS"
}

issue_5324: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
A = 0;
do {
var a, b = A;
for (a in b)
var c = b;
} while (function() {
var d;
console.log(d *= A);
}());
}
expect: {
A = 0;
do {
var a, b = A;
for (a in b);
} while (b = void 0, void console.log(b *= A));
}
expect_stdout: "NaN"
}

0 comments on commit 0a5a1f3

Please sign in to comment.