Don't swap binary ops when "use asm" is in effect.
authorMihai Bazon <mihai@bazon.net>
Fri, 7 Jun 2013 09:51:23 +0000 (12:51 +0300)
committerMihai Bazon <mihai@bazon.net>
Fri, 7 Jun 2013 09:52:09 +0000 (12:52 +0300)
Refs #167

lib/ast.js
lib/compress.js

index a1301da..b8e89f2 100644 (file)
@@ -945,6 +945,9 @@ TreeWalker.prototype = {
             if (x instanceof type) return x;
         }
     },
+    has_directive: function(type) {
+        return this.find_parent(AST_Scope).has_directive(type);
+    },
     in_boolean_context: function() {
         var stack = this.stack;
         var i = stack.length, self = stack[--i];
index 57554fa..9eed828 100644 (file)
@@ -1765,14 +1765,15 @@ merge(Compressor.prototype, {
     var commutativeOperators = makePredicate("== === != !== * & | ^");
 
     OPT(AST_Binary, function(self, compressor){
-        function reverse(op, force) {
-            if (force || !(self.left.has_side_effects() || self.right.has_side_effects())) {
-                if (op) self.operator = op;
-                var tmp = self.left;
-                self.left = self.right;
-                self.right = tmp;
-            }
-        };
+        var reverse = compressor.has_directive("use asm") ? noop
+            : function(op, force) {
+                if (force || !(self.left.has_side_effects() || self.right.has_side_effects())) {
+                    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)) {