[Pkg-javascript-commits] [uglifyjs] 178/228: remove paranthesis for `-(x*y)` (#1732)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 7cb1adf455f8ab440e1971ae41265c1f7f9a806a
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Mar 30 16:09:00 2017 +0800

    remove paranthesis for `-(x*y)` (#1732)
---
 lib/compress.js          |  7 +++++++
 test/compress/numbers.js | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index be76015..ac7ea35 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3034,6 +3034,13 @@ merge(Compressor.prototype, {
                 })).optimize(compressor);
             }
         }
+        if (e instanceof AST_Binary
+            && (self.operator == "+" || self.operator == "-")
+            && (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
+            self.expression = e.left;
+            e.left = self;
+            return e.optimize(compressor);
+        }
         // avoids infinite recursion of numerals
         if (self.operator != "-"
             || !(self.expression instanceof AST_Number
diff --git a/test/compress/numbers.js b/test/compress/numbers.js
index ea439ec..946a7f2 100644
--- a/test/compress/numbers.js
+++ b/test/compress/numbers.js
@@ -168,3 +168,37 @@ issue_1710: {
     }
     expect_stdout: true
 }
+
+unary_binary_parenthesis: {
+    input: {
+        var v = [ 0, 1, NaN, Infinity, null, undefined, true, false, "", "foo", /foo/ ];
+        v.forEach(function(x) {
+            v.forEach(function(y) {
+                console.log(
+                    +(x*y),
+                    +(x/y),
+                    +(x%y),
+                    -(x*y),
+                    -(x/y),
+                    -(x%y)
+                );
+            });
+        });
+    }
+    expect: {
+        var v = [ 0, 1, 0/0, 1/0, null, void 0, true, false, "", "foo", /foo/ ];
+        v.forEach(function(x) {
+            v.forEach(function(y) {
+                console.log(
+                    +x*y,
+                    +x/y,
+                    +x%y,
+                    -x*y,
+                    -x/y,
+                    -x%y
+                );
+            });
+        });
+    }
+    expect_stdout: true
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list