From fba0c1aafe5e54a982238bd7e54596852617ef6c Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Mon, 5 Nov 2012 16:01:09 +0200 Subject: [PATCH] minor --- lib/compress.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 5cbb31c9..a7a6172b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1477,7 +1477,21 @@ merge(Compressor.prototype, { return this; }); + var commutativeOperators = makePredicate("== === != !== * & | ^"); + OPT(AST_Binary, function(self, compressor){ + function reverse(op) { + if (op) self.operator = op; + var tmp = self.left; + self.left = self.right; + self.right = tmp; + }; + if (commutativeOperators(self.operator)) { + if (self.right instanceof AST_Constant + && !(self.left instanceof AST_Constant)) { + reverse(); + } + } self = self.lift_sequences(compressor); if (compressor.option("comparisons")) switch (self.operator) { case "===": @@ -1489,11 +1503,6 @@ merge(Compressor.prototype, { // XXX: intentionally falling down to the next case case "==": case "!=": - if (self.right instanceof AST_Constant && !(self.left instanceof AST_Constant)) { - var tmp = self.left; - self.left = self.right; - self.right = tmp; - } if (self.left instanceof AST_String && self.left.value == "undefined" && self.right instanceof AST_UnaryPrefix @@ -1560,12 +1569,6 @@ merge(Compressor.prototype, { }); self = best_of(self, negated); } - var reverse = function(op) { - self.operator = op; - var tmp = self.left; - self.left = self.right; - self.right = tmp; - }; switch (self.operator) { case "<": reverse(">"); break; case "<=": reverse(">="); break; -- 2.34.1