From 785c6064cc4d28f3453e88fba3e085c4e2eaf553 Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Tue, 29 Oct 2013 21:37:36 +0100 Subject: [PATCH] Disallow reversal where lhs has higher or equal precedence Fixes #267 --- lib/compress.js | 6 +++++- test/compress/issue-267.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/compress/issue-267.js 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; + } +} -- 2.34.1