handle negated constants correctly in collapse_vars (#2975)

fixes #2974
This commit is contained in:
Alex Lam S.L
2018-03-06 00:45:58 +08:00
committed by GitHub
parent 951d87ca94
commit fe51a91395
2 changed files with 37 additions and 2 deletions

View File

@@ -778,8 +778,7 @@ merge(Compressor.prototype, {
lhs = lhs.fixed_value();
}
if (!lhs) return true;
if (lhs instanceof AST_RegExp) return false;
if (lhs instanceof AST_Constant) return true;
if (lhs.is_constant()) return true;
return is_lhs_read_only(lhs);
}
return false;

View File

@@ -5207,3 +5207,39 @@ collapse_rhs_undefined: {
}
expect_stdout: "true true true"
}
issue_2974: {
options = {
booleans: true,
collapse_vars: true,
evaluate: true,
loops: true,
passes: 2,
pure_getters: "strict",
reduce_vars: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
var c = 0;
(function f(b) {
var a = 2;
do {
b && b[b];
b && (b.null = -4);
c++;
} while (b.null && --a > 0);
})(true);
console.log(c);
}
expect: {
var c = 0;
(function(b) {
var a = 2;
for (; b.null = -4, c++, b.null && --a > 0;);
})(!0),
console.log(c);
}
expect_stdout: "1"
}