fix corner case in evaluate (#4036)

fixes #4035
This commit is contained in:
Alex Lam S.L
2020-08-04 20:05:10 +08:00
committed by GitHub
parent 9d758a216b
commit a4002ef467
2 changed files with 86 additions and 48 deletions

View File

@@ -7436,6 +7436,7 @@ merge(Compressor.prototype, {
}
break;
}
if (!(parent instanceof AST_UnaryPrefix && parent.operator == "delete")) {
if (self.left instanceof AST_Number && !self.right.is_constant()) switch (self.operator) {
// 0 + n => n
case "+":
@@ -7488,6 +7489,7 @@ merge(Compressor.prototype, {
break;
}
}
}
if (compressor.option("typeofs")) switch (self.operator) {
case "&&":
mark_locally_defined(self.left, self.right, null);

View File

@@ -2833,3 +2833,39 @@ issue_3997: {
}
expect_stdout: "string"
}
issue_4035: {
options = {
evaluate: true,
reduce_vars: true,
}
input: {
var a = 0;
(function() {
var b = --a;
console.log(delete (0 + b));
console.log(delete (1 * b));
console.log(delete (b + 0));
console.log(delete (b - 0));
console.log(delete (b / 1));
})();
}
expect: {
var a = 0;
(function() {
var b = --a;
console.log((0 + b, true));
console.log((1 * b, true));
console.log((0 + b, true));
console.log((b - 0, true));
console.log((b / 1, true));
})();
}
expect_stdout: [
"true",
"true",
"true",
"true",
"true",
]
}