diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-11-05 16:01:09 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-11-05 16:01:09 +0200 |
commit | fba0c1aafe5e54a982238bd7e54596852617ef6c (patch) | |
tree | 73d3bfac1e8ebffc15d7e89c4f75ffa414ddfd42 | |
parent | 774f2ded9422903f082f0291ec69c7a6e2edfcaf (diff) | |
download | tracifyjs-fba0c1aafe5e54a982238bd7e54596852617ef6c.tar.gz tracifyjs-fba0c1aafe5e54a982238bd7e54596852617ef6c.zip |
minor
-rw-r--r-- | lib/compress.js | 25 |
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; |