From 02a84385a02ccf4cf3a1ccca2fc5f6a90fb43487 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Fri, 7 Jun 2013 12:51:23 +0300 Subject: [PATCH] Don't swap binary ops when "use asm" is in effect. Refs #167 --- lib/ast.js | 3 +++ lib/compress.js | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index a1301da8..b8e89f23 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -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]; diff --git a/lib/compress.js b/lib/compress.js index 57554fa5..9eed8280 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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)) { -- 2.34.1