[Pkg-javascript-commits] [uglifyjs] 106/190: collapse_vars: fix if/else and ternary operator side effects

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:17 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 929de2b0de0429bb076f73ebcbb19df53e4d1704
Author: kzc <zaxxon2011 at gmail.com>
Date:   Thu Jan 28 12:17:06 2016 -0500

    collapse_vars: fix if/else and ternary operator side effects
---
 lib/compress.js                |  2 ++
 test/compress/collapse_vars.js | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index 6cd5571..68471a5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -321,6 +321,8 @@ merge(Compressor.prototype, {
                                 || node instanceof AST_Try
                                 || node instanceof AST_With
                                 || node instanceof AST_IterationStatement
+                                || (parent instanceof AST_If          && node !== parent.condition)
+                                || (parent instanceof AST_Conditional && node !== parent.condition)
                                 || (parent instanceof AST_Binary
                                     && (parent.operator == "&&" || parent.operator == "||")
                                     && node === parent.right)
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 39fee59..934a5c7 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1103,3 +1103,53 @@ collapse_vars_short_circuit: {
     }
 }
 
+collapse_vars_short_circuited_conditions: {
+    options = {
+        collapse_vars: true,
+        sequences:     false,
+        dead_code:     true,
+        conditionals:  false,
+        comparisons:   false,
+        evaluate:      true,
+        booleans:      true,
+        loops:         true,
+        unused:        true,
+        hoist_funs:    true,
+        keep_fargs:    true,
+        if_return:     false,
+        join_vars:     true,
+        cascade:       true,
+        side_effects:  true,
+    }
+    input: {
+        function c1(x) { var a = foo(), b = bar(), c = baz(); return a ? b : c; }
+        function c2(x) { var a = foo(), b = bar(), c = baz(); return a ? c : b; }
+        function c3(x) { var a = foo(), b = bar(), c = baz(); return b ? a : c; }
+        function c4(x) { var a = foo(), b = bar(), c = baz(); return b ? c : a; }
+        function c5(x) { var a = foo(), b = bar(), c = baz(); return c ? a : b; }
+        function c6(x) { var a = foo(), b = bar(), c = baz(); return c ? b : a; }
+
+        function i1(x) { var a = foo(), b = bar(), c = baz(); if (a) return b; else return c; }
+        function i2(x) { var a = foo(), b = bar(), c = baz(); if (a) return c; else return b; }
+        function i3(x) { var a = foo(), b = bar(), c = baz(); if (b) return a; else return c; }
+        function i4(x) { var a = foo(), b = bar(), c = baz(); if (b) return c; else return a; }
+        function i5(x) { var a = foo(), b = bar(), c = baz(); if (c) return a; else return b; }
+        function i6(x) { var a = foo(), b = bar(), c = baz(); if (c) return b; else return a; }
+    }
+    expect: {
+        function c1(x) { var a = foo(), b = bar(), c = baz(); return a ? b : c; }
+        function c2(x) { var a = foo(), b = bar(), c = baz(); return a ? c : b; }
+        function c3(x) { var a = foo(), b = bar(), c = baz(); return b ? a : c; }
+        function c4(x) { var a = foo(), b = bar(), c = baz(); return b ? c : a; }
+        function c5(x) { var a = foo(), b = bar(); return baz() ? a : b; }
+        function c6(x) { var a = foo(), b = bar(); return baz() ? b : a; }
+
+        function i1(x) { var a = foo(), b = bar(), c = baz(); if (a) return b; else return c; }
+        function i2(x) { var a = foo(), b = bar(), c = baz(); if (a) return c; else return b; }
+        function i3(x) { var a = foo(), b = bar(), c = baz(); if (b) return a; else return c; }
+        function i4(x) { var a = foo(), b = bar(), c = baz(); if (b) return c; else return a; }
+        function i5(x) { var a = foo(), b = bar(); if (baz()) return a; else return b; }
+        function i6(x) { var a = foo(), b = bar(); if (baz()) return b; else return a; }
+    }
+}
+

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