aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js25
1 files 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;