[Pkg-javascript-commits] [uglifyjs] 10/491: fix `reduce_vars` on conditionals (#1822)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:17 UTC 2018


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

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit d1aa09c5c7af14bf5f17cc7ea2ab5d6be20e3220
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Apr 18 01:44:23 2017 +0800

    fix `reduce_vars` on conditionals (#1822)
---
 lib/compress.js              | 10 ++++++++++
 test/compress/reduce_vars.js | 23 +++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/lib/compress.js b/lib/compress.js
index f49dd60..0dfe2a3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -348,6 +348,16 @@ merge(Compressor.prototype, {
                     pop();
                     return true;
                 }
+                if (node instanceof AST_Conditional) {
+                    node.condition.walk(tw);
+                    push();
+                    node.consequent.walk(tw);
+                    pop();
+                    push();
+                    node.alternative.walk(tw);
+                    pop();
+                    return true;
+                }
                 if (node instanceof AST_If) {
                     node.condition.walk(tw);
                     push();
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 94d37cb..ad2c90b 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -2240,3 +2240,26 @@ boolean_binary_assign: {
     }
     expect_stdout: "undefined"
 }
+
+cond_assign: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        !function() {
+            var a;
+            void 0 ? (a = 1) : 0;
+            console.log(a);
+        }();
+    }
+    expect: {
+        !function() {
+            var a;
+            void 0 ? (a = 1) : 0;
+            console.log(a);
+        }();
+    }
+    expect_stdout: "undefined"
+}

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