aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen1@gmail.com>2013-10-29 21:37:36 +0100
committerRichard van Velzen <rvanvelzen1@gmail.com>2013-10-29 21:37:36 +0100
commit785c6064cc4d28f3453e88fba3e085c4e2eaf553 (patch)
treee0394286a3f669d9d099e1f281a0b92d3d3c5ef9
parentb214d3786fdb569b9ba5b885f0653927960d450f (diff)
downloadtracifyjs-785c6064cc4d28f3453e88fba3e085c4e2eaf553.tar.gz
tracifyjs-785c6064cc4d28f3453e88fba3e085c4e2eaf553.zip
Disallow reversal where lhs has higher or equal precedence
Fixes #267
-rw-r--r--lib/compress.js6
-rw-r--r--test/compress/issue-267.js11
2 files changed, 16 insertions, 1 deletions
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;
+ }
+}