@@ -5930,7 +5930,8 @@ merge(Compressor.prototype, {
|
||||
// a - -b => a + b
|
||||
if (self.right instanceof AST_UnaryPrefix
|
||||
&& self.right.operator == "-"
|
||||
&& self.left.is_number(compressor)) {
|
||||
&& self.left.is_number(compressor)
|
||||
&& self.right.expression.is_number(compressor)) {
|
||||
self = make_node(AST_Binary, self, {
|
||||
operator: "+",
|
||||
left: self.left,
|
||||
@@ -5979,6 +5980,7 @@ merge(Compressor.prototype, {
|
||||
// a + (b + c) => (a + b) + c
|
||||
if (self.right instanceof AST_Binary
|
||||
&& self.right.operator != "%"
|
||||
&& self.right.is_number(compressor)
|
||||
&& PRECEDENCE[self.right.operator] == PRECEDENCE[self.operator]) {
|
||||
self = make_node(AST_Binary, self, {
|
||||
operator: align(self.operator, self.right.operator),
|
||||
@@ -5991,6 +5993,14 @@ merge(Compressor.prototype, {
|
||||
}),
|
||||
right: self.right.right
|
||||
});
|
||||
if (self.operator == "+"
|
||||
&& !self.right.is_boolean(compressor)
|
||||
&& !self.right.is_number(compressor)) {
|
||||
self.right = make_node(AST_UnaryPrefix, self.right, {
|
||||
operator: "+",
|
||||
expression: self.right
|
||||
});
|
||||
}
|
||||
}
|
||||
// (2 * n) * 3 => 6 * n
|
||||
// (n + 2) + 3 => n + 5
|
||||
@@ -5998,7 +6008,8 @@ merge(Compressor.prototype, {
|
||||
&& self.left instanceof AST_Binary
|
||||
&& self.left.operator != "%"
|
||||
&& PRECEDENCE[self.left.operator] == PRECEDENCE[self.operator]) {
|
||||
if (self.left.left instanceof AST_Constant) {
|
||||
if (self.left.left instanceof AST_Constant
|
||||
&& (self.left.operator != "+" || self.left.right.is_number(compressor))) {
|
||||
self = make_node(AST_Binary, self, {
|
||||
operator: self.left.operator,
|
||||
left: make_node(AST_Binary, self.left, {
|
||||
@@ -6010,7 +6021,8 @@ merge(Compressor.prototype, {
|
||||
}),
|
||||
right: self.left.right
|
||||
});
|
||||
} else if (self.left.right instanceof AST_Constant) {
|
||||
} else if (self.left.right instanceof AST_Constant
|
||||
&& (self.left.operator != "+" || self.left.left.is_number(compressor))) {
|
||||
self = make_node(AST_Binary, self, {
|
||||
operator: self.left.operator,
|
||||
left: self.left.left,
|
||||
|
||||
Reference in New Issue
Block a user