[Pkg-javascript-commits] [uglifyjs] 175/190: Fix conditional expressions of form (x ? -1 : -1)

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:24 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 ace8aaa0f4ad6ecae77e760473353f07b384880e
Author: kzc <zaxxon2011 at gmail.com>
Date:   Tue Jun 21 14:52:13 2016 -0400

    Fix conditional expressions of form (x ? -1 : -1)
    
    Fixes #1154, #1153
---
 lib/compress.js               |  2 +-
 test/compress/conditionals.js | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index db6a26d..4152bd0 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2746,7 +2746,7 @@ merge(Compressor.prototype, {
         if (consequent.is_constant(compressor)
             && alternative.is_constant(compressor)
             && consequent.equivalent_to(alternative)) {
-            var consequent_value = consequent.constant_value();
+            var consequent_value = consequent.constant_value(compressor);
             if (self.condition.has_side_effects(compressor)) {
                 return AST_Seq.from_array([self.condition, make_node_from_constant(compressor, consequent_value, self)]);
             } else {
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index f5eeb6f..35cb26f 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -868,3 +868,41 @@ trivial_boolean_ternary_expressions : {
         f(!(x >= y));
     }
 }
+
+issue_1154: {
+    options = {
+        conditionals: true,
+        evaluate    : true,
+        booleans    : true,
+    };
+    input: {
+        function f1(x) { return x ? -1 : -1; }
+        function f2(x) { return x ? +2 : +2; }
+        function f3(x) { return x ? ~3 : ~3; }
+        function f4(x) { return x ? !4 : !4; }
+        function f5(x) { return x ? void 5 : void 5; }
+        function f6(x) { return x ? typeof 6 : typeof 6; }
+
+        function g1() { return g() ? -1 : -1; }
+        function g2() { return g() ? +2 : +2; }
+        function g3() { return g() ? ~3 : ~3; }
+        function g4() { return g() ? !4 : !4; }
+        function g5() { return g() ? void 5 : void 5; }
+        function g6() { return g() ? typeof 6 : typeof 6; }
+    }
+    expect: {
+        function f1(x) { return -1; }
+        function f2(x) { return 2; }
+        function f3(x) { return -4; }
+        function f4(x) { return !1; }
+        function f5(x) { return; }
+        function f6(x) { return "number"; }
+
+        function g1() { return g(), -1; }
+        function g2() { return g(), 2; }
+        function g3() { return g(), -4; }
+        function g4() { return g(), !1; }
+        function g5() { return g(), void 0; }
+        function g6() { return g(), "number"; }
+    }
+}

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