diff --git a/lib/compress.js b/lib/compress.js index 29543727..375cc5dd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -11806,8 +11806,18 @@ Compressor.prototype.compress = function(node) { } } // x && (y && z) ---> x && y && z - // x || (y || z) ---> x || y || z - if (self.right instanceof AST_Binary && self.operator == self.right.operator) swap_chain(self, compressor); + // w || (x, y || z) ---> w || (x, y) || z + var rhs = self.right.tail_node(); + if (rhs instanceof AST_Binary && self.operator == rhs.operator) { + if (rhs !== self.right) { + var exprs = self.right.expressions.slice(0, -1); + exprs.push(rhs.left); + rhs = rhs.clone(); + rhs.left = make_sequence(self.right, exprs); + self.right = rhs; + } + swap_chain(self, compressor); + } } if (compressor.option("strings") && self.operator == "+") { // "foo" + 42 + "" ---> "foo" + 42 @@ -13101,7 +13111,7 @@ Compressor.prototype.compress = function(node) { operator: "||", left: booleanize(condition), right: alternative, - }); + }).optimize(compressor); } if (is_false(consequent)) { // c ? false : true ---> !c @@ -13111,20 +13121,20 @@ Compressor.prototype.compress = function(node) { operator: "&&", left: booleanize(condition.negate(compressor)), right: alternative, - }); + }).optimize(compressor); } // c ? x : true ---> !c || x if (is_true(alternative)) return make_node(AST_Binary, self, { operator: "||", left: booleanize(condition.negate(compressor)), right: consequent, - }); + }).optimize(compressor); // c ? x : false ---> !!c && x if (is_false(alternative)) return make_node(AST_Binary, self, { operator: "&&", left: booleanize(condition), right: consequent, - }); + }).optimize(compressor); if (compressor.option("typeofs")) mark_locally_defined(condition, consequent, alternative); return self; diff --git a/test/compress/transform.js b/test/compress/transform.js index a06d08a9..e3621eb2 100644 --- a/test/compress/transform.js +++ b/test/compress/transform.js @@ -127,7 +127,7 @@ if_return: { if (w) { if (y) return; } else if (z) return; - return x != y && (x && w(), y && z()), !0; + return x != y && (x && w(), y) && z(), !0; } } }