Skip to content

Commit

Permalink
fix corner case in reduce_vars (#4569)
Browse files Browse the repository at this point in the history
fixes #4568
  • Loading branch information
alexlamsl committed Jan 18, 2021
1 parent e23a10f commit b57bae4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -9733,7 +9733,7 @@ merge(Compressor.prototype, {
single_use = false;
}
if (single_use) fixed.parent_scope = self.scope;
} else if (!fixed || !fixed.is_constant_expression()) {
} else if (!fixed || !fixed.is_constant_expression() || fixed.drop_side_effect_free(compressor)) {
single_use = false;
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/compress/ie8.js
Original file line number Diff line number Diff line change
Expand Up @@ -2900,3 +2900,22 @@ issue_4250: {
}
expect_stdout: "0"
}

issue_4568: {
options = {
ie8: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(typeof f, function(a) {
return a.length;
}([ function f() {} ]));
}
expect: {
console.log(typeof f, function(a) {
return a.length;
}([ function f() {} ]));
}
expect_stdout: "undefined 1"
}
29 changes: 29 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7601,3 +7601,32 @@ issue_4188_2: {
}
expect_stdout: "number undefined"
}

issue_4568: {
options = {
booleans: true,
conditionals: true,
dead_code: true,
evaluate: true,
loops: true,
passes: 2,
reduce_vars: true,
sequences: true,
unused: true,
}
input: {
(function(a) {
a && console.log("FAIL");
if (1)
do {
if (!console.log("PASS")) break;
} while (1);
})(!(0 !== delete NaN));
}
expect: {
(function(a) {
for (a && console.log("FAIL"), 1; console.log("PASS"); ) 1;
})(!(0 !== delete NaN));
}
expect_stdout: "PASS"
}

0 comments on commit b57bae4

Please sign in to comment.