@@ -8823,7 +8823,8 @@ Compressor.prototype.compress = function(node) {
88238823 var negated = node.clone();
88248824 negated.operator = op == "&&" ? "||" : "&&";
88258825 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);
88278828 var best = first_in_statement ? best_of_statement : best_of_expression;
88288829 return op == "&&" ? best(node, negated) : best(negated, node);
88298830 }
@@ -11607,7 +11608,14 @@ Compressor.prototype.compress = function(node) {
1160711608 }
1160811609
1160911610 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+ }
1161111619 self.left = make_node(AST_Binary, self, {
1161211620 operator: self.operator,
1161311621 left: self.left,
@@ -11808,16 +11816,7 @@ Compressor.prototype.compress = function(node) {
1180811816 // x && (y && z) ---> x && y && z
1180911817 // w || (x, y || z) ---> w || (x, y) || z
1181011818 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);
1182111820 }
1182211821 if (compressor.option("strings") && self.operator == "+") {
1182311822 // "foo" + 42 + "" ---> "foo" + 42
@@ -11843,12 +11842,13 @@ Compressor.prototype.compress = function(node) {
1184311842 return self.optimize(compressor);
1184411843 }
1184511844 // "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)))) {
1185211852 swap_chain(self, compressor);
1185311853 }
1185411854 }
0 commit comments