improve string concatenation

shuffle associative operations to minimise parentheses and aid other uglification efforts

closes #1454
This commit is contained in:
alexlamsl
2017-02-18 19:07:52 +08:00
parent f584ca8d07
commit 6b3c49e458
3 changed files with 152 additions and 5 deletions

View File

@@ -2751,9 +2751,16 @@ merge(Compressor.prototype, {
}
// x && (y && z) ==> x && y && z
// x || (y || z) ==> x || y || z
// x + ("y" + z) ==> x + "y" + z
// "x" + (y + "z")==> "x" + y + "z"
if (self.right instanceof AST_Binary
&& self.right.operator == self.operator
&& (self.operator == "&&" || self.operator == "||"))
&& (self.operator == "&&"
|| self.operator == "||"
|| (self.operator == "+"
&& (self.right.left.is_string(compressor)
|| (self.left.is_string(compressor)
&& self.right.right.is_string(compressor))))))
{
self.left = make_node(AST_Binary, self.left, {
operator : self.operator,