From: Richard van Velzen Date: Tue, 29 Oct 2013 20:37:36 +0000 (+0100) Subject: Disallow reversal where lhs has higher or equal precedence X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=785c6064cc4d28f3453e88fba3e085c4e2eaf553;p=UglifyJS.git Disallow reversal where lhs has higher or equal precedence Fixes #267 --- diff --git a/lib/compress.js b/lib/compress.js index 13ae7c70..108a4e9e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1907,7 +1907,11 @@ merge(Compressor.prototype, { // if right is a constant, whatever side effects the // left side might have could not influence the // result. hence, force switch. - reverse(null, true); + + if (!(self.left instanceof AST_Binary + && PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) { + reverse(null, true); + } } if (/^[!=]==?$/.test(self.operator)) { if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) { diff --git a/test/compress/issue-267.js b/test/compress/issue-267.js new file mode 100644 index 00000000..7233d9f1 --- /dev/null +++ b/test/compress/issue-267.js @@ -0,0 +1,11 @@ +issue_267: { + options = { comparisons: true }; + input: { + x = a % b / b * c * 2; + x = a % b * 2 + } + expect: { + x = a % b / b * c * 2; + x = a % b * 2; + } +}