@@ -8823,7 +8823,8 @@ Compressor.prototype.compress = function(node) {
8823
8823
var negated = node.clone();
8824
8824
negated.operator = op == "&&" ? "||" : "&&";
8825
8825
negated.left = left.negate(compressor, first_in_statement);
8826
- if (negated.operator == negated.right.operator) swap_chain(negated);
8826
+ var negated_rhs = negated.right.tail_node();
8827
+ if (negated_rhs instanceof AST_Binary && negated.operator == negated_rhs.operator) swap_chain(negated);
8827
8828
var best = first_in_statement ? best_of_statement : best_of_expression;
8828
8829
return op == "&&" ? best(node, negated) : best(negated, node);
8829
8830
}
@@ -11607,7 +11608,14 @@ Compressor.prototype.compress = function(node) {
11607
11608
}
11608
11609
11609
11610
function swap_chain(self, compressor) {
11610
- var rhs = self.right;
11611
+ var rhs = self.right.tail_node();
11612
+ if (rhs !== self.right) {
11613
+ var exprs = self.right.expressions.slice(0, -1);
11614
+ exprs.push(rhs.left);
11615
+ rhs = rhs.clone();
11616
+ rhs.left = make_sequence(self.right, exprs);
11617
+ self.right = rhs;
11618
+ }
11611
11619
self.left = make_node(AST_Binary, self, {
11612
11620
operator: self.operator,
11613
11621
left: self.left,
@@ -11808,16 +11816,7 @@ Compressor.prototype.compress = function(node) {
11808
11816
// x && (y && z) ---> x && y && z
11809
11817
// w || (x, y || z) ---> w || (x, y) || z
11810
11818
var rhs = self.right.tail_node();
11811
- if (rhs instanceof AST_Binary && self.operator == rhs.operator) {
11812
- if (rhs !== self.right) {
11813
- var exprs = self.right.expressions.slice(0, -1);
11814
- exprs.push(rhs.left);
11815
- rhs = rhs.clone();
11816
- rhs.left = make_sequence(self.right, exprs);
11817
- self.right = rhs;
11818
- }
11819
- swap_chain(self, compressor);
11820
- }
11819
+ if (rhs instanceof AST_Binary && self.operator == rhs.operator) swap_chain(self, compressor);
11821
11820
}
11822
11821
if (compressor.option("strings") && self.operator == "+") {
11823
11822
// "foo" + 42 + "" ---> "foo" + 42
@@ -11843,12 +11842,13 @@ Compressor.prototype.compress = function(node) {
11843
11842
return self.optimize(compressor);
11844
11843
}
11845
11844
// "x" + (y + "z") ---> "x" + y + "z"
11846
- // x + ("y" + z) ---> x + "y" + z
11847
- if (self.right instanceof AST_Binary
11848
- && self.operator == self.right.operator
11849
- && (self.left.is_string(compressor) && self.right.is_string(compressor)
11850
- || self.right.left.is_string(compressor)
11851
- && (self.left.is_constant() || !self.right.right.has_side_effects(compressor)))) {
11845
+ // w + (x, "y" + z) ---> w + (x, "y") + z
11846
+ var rhs = self.right.tail_node();
11847
+ if (rhs instanceof AST_Binary
11848
+ && self.operator == rhs.operator
11849
+ && (self.left.is_string(compressor) && rhs.is_string(compressor)
11850
+ || rhs.left.is_string(compressor)
11851
+ && (self.left.is_constant() || !rhs.right.has_side_effects(compressor)))) {
11852
11852
swap_chain(self, compressor);
11853
11853
}
11854
11854
}
0 commit comments