[Pkg-javascript-commits] [uglifyjs] 152/190: Completely allow evaluating -0

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:22 UTC 2016


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

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit bc49dfd27a800cfa2070464c236a1d56ed30bfca
Author: Richard van Velzen <rvanvelzen at experty.com>
Date:   Wed May 18 18:49:55 2016 +0200

    Completely allow evaluating -0
---
 lib/compress.js           | 20 +++++++++++++-------
 test/compress/evaluate.js | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index e8c42c0..419c6a2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -183,9 +183,18 @@ merge(Compressor.prototype, {
                 value: val
             }).optimize(compressor);
           case "number":
-            return make_node(isNaN(val) ? AST_NaN : AST_Number, orig, {
-                value: val
-            }).optimize(compressor);
+            if (isNaN(val)) {
+                return make_node(AST_NaN, orig);
+            }
+
+            if ((1 / val) < 0) {
+                return make_node(AST_UnaryPrefix, orig, {
+                    operator: "-",
+                    expression: make_node(AST_Number, null, { value: -val })
+                });
+            }
+
+            return make_node(AST_Number, orig, { value: val }).optimize(compressor);
           case "boolean":
             return make_node(val ? AST_True : AST_False, orig).optimize(compressor);
           case "undefined":
@@ -1028,10 +1037,7 @@ merge(Compressor.prototype, {
                 return typeof e;
               case "void": return void ev(e, compressor);
               case "~": return ~ev(e, compressor);
-              case "-":
-                e = -ev(e, compressor);
-                if (e === -0) throw def;
-                return e;
+              case "-": return -ev(e, compressor);
               case "+": return +ev(e, compressor);
             }
             throw def;
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 9aa6b3d..d27582f 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -1,9 +1,39 @@
 negative_zero: {
     options = { evaluate: true }
     input: {
-        assert.sameValue(-"", -0, '-""');
+        console.log(
+            -"",
+            - -"",
+            1 / (-0),
+            1 / (-"")
+        );
     }
     expect: {
-        assert.sameValue(-"", -0, '-""');
+        console.log(
+            -0,
+            0,
+            1 / (-0),
+            1 / (-0)
+        );
+    }
+}
+
+positive_zero: {
+    options = { evaluate: true }
+    input: {
+        console.log(
+            +"",
+            + -"",
+            1 / (+0),
+            1 / (+"")
+        );
+    }
+    expect: {
+        console.log(
+            0,
+            -0,
+            1 / (0),
+            1 / (0)
+        );
     }
 }

-- 
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