@@ -6466,13 +6466,6 @@ merge(Compressor.prototype, {
|
|||||||
}).optimize(compressor);
|
}).optimize(compressor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// 0 - n => -n
|
|
||||||
case "-":
|
|
||||||
if (self.left.value == 0) return make_node(AST_UnaryPrefix, self, {
|
|
||||||
operator: "-",
|
|
||||||
expression: self.right
|
|
||||||
}).optimize(compressor);
|
|
||||||
break;
|
|
||||||
// 1 * n => n
|
// 1 * n => n
|
||||||
case "*":
|
case "*":
|
||||||
if (self.left.value == 1) {
|
if (self.left.value == 1) {
|
||||||
@@ -6483,16 +6476,33 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (self.right instanceof AST_Number && !self.left.is_constant()) switch (self.operator) {
|
||||||
|
// n + 0 => n
|
||||||
|
case "+":
|
||||||
|
if (self.right.value == 0 && (self.left.is_boolean(compressor) || self.left.is_number(compressor))) {
|
||||||
|
return self.left;
|
||||||
|
}
|
||||||
|
break;
|
||||||
// n - 0 => n
|
// n - 0 => n
|
||||||
// n / 1 => n
|
case "-":
|
||||||
if (self.right instanceof AST_Number && !self.left.is_constant() && self.right.value == {
|
if (self.right.value == 0) {
|
||||||
"-": 0,
|
return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, {
|
||||||
"/": 1,
|
|
||||||
}[self.operator]) return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, {
|
|
||||||
operator: "+",
|
operator: "+",
|
||||||
expression: self.left
|
expression: self.left
|
||||||
}).optimize(compressor);
|
}).optimize(compressor);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
// n / 1 => n
|
||||||
|
case "/":
|
||||||
|
if (self.right.value == 1) {
|
||||||
|
return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, {
|
||||||
|
operator: "+",
|
||||||
|
expression: self.left
|
||||||
|
}).optimize(compressor);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (compressor.option("typeofs")) switch (self.operator) {
|
if (compressor.option("typeofs")) switch (self.operator) {
|
||||||
case "&&":
|
case "&&":
|
||||||
mark_locally_defined(self.left, self.right, null, "&&");
|
mark_locally_defined(self.left, self.right, null, "&&");
|
||||||
|
|||||||
@@ -997,7 +997,7 @@ identity_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
0 + a;
|
0 + a;
|
||||||
a + 0;
|
a + 0;
|
||||||
-a;
|
0 - a;
|
||||||
+a;
|
+a;
|
||||||
+a;
|
+a;
|
||||||
+a;
|
+a;
|
||||||
@@ -1023,7 +1023,7 @@ identity_2: {
|
|||||||
expect: {
|
expect: {
|
||||||
+!a;
|
+!a;
|
||||||
+!a;
|
+!a;
|
||||||
-!a;
|
0 - !a;
|
||||||
+!a;
|
+!a;
|
||||||
+!a;
|
+!a;
|
||||||
+!a;
|
+!a;
|
||||||
@@ -1049,7 +1049,7 @@ identity_3: {
|
|||||||
expect: {
|
expect: {
|
||||||
--a;
|
--a;
|
||||||
--a;
|
--a;
|
||||||
- --a;
|
0 - --a;
|
||||||
--a;
|
--a;
|
||||||
--a;
|
--a;
|
||||||
--a;
|
--a;
|
||||||
@@ -1057,3 +1057,42 @@ identity_3: {
|
|||||||
--a;
|
--a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3653: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 + (0 - (console && 0)));
|
||||||
|
console.log(0 - (0 - (console && 0)));
|
||||||
|
console.log(1 * (0 - (console && 0)));
|
||||||
|
console.log(1 / (0 - (console && 0)));
|
||||||
|
console.log((0 - (console && 0)) + 0);
|
||||||
|
console.log((0 - (console && 0)) - 0);
|
||||||
|
console.log((0 - (console && 0)) * 1);
|
||||||
|
console.log((0 - (console && 0)) / 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (0 - (console && 0)));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(1 / (0 - (console && 0)));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"Infinity",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user