From 2b1e4628e0ee3e73d2e9d00635e51067ec36cd52 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Wed, 12 Sep 2012 13:23:24 +0300 Subject: [PATCH] side effect fixes and small optimization for gzip prefer to always use > and >= operators (idea from Closure) --- lib/compress.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 7faf2df5..06b133f9 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -478,6 +478,7 @@ function Compressor(options, false_by_default) { return this.left.has_side_effects() || this.right.has_side_effects (); }); + def(AST_Assign, function(){ return true }); def(AST_Conditional, function(){ return this.condition.has_side_effects() || this.consequent.has_side_effects() @@ -488,6 +489,7 @@ function Compressor(options, false_by_default) { || this.operator == "++" || this.operator == "--"; }); + def(AST_SymbolRef, function(){ return false }); })(function(node, func){ node.DEFMETHOD("has_side_effects", func); }); @@ -1100,7 +1102,25 @@ function Compressor(options, false_by_default) { } break; } - return this.evaluate(compressor)[0]; + var exp = this.evaluate(compressor); + if (exp.length == 2) { + if (best_of(exp[0], this) !== this) + return exp[0]; + } + var self = this; + if (compressor.option("comparations")) { + var reverse = function(op) { + self.operator = op; + var tmp = self.left; + self.left = self.right; + self.right = tmp; + }; + if (self instanceof AST_Binary) switch (self.operator) { + case "<": reverse(">"); break; + case "<=": reverse(">="); break; + } + } + return self; }); SQUEEZE(AST_Assign, function(self, compressor){ -- 2.34.1