aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-18 01:44:23 +0800
committerGitHub <noreply@github.com>2017-04-18 01:44:23 +0800
commitd1aa09c5c7af14bf5f17cc7ea2ab5d6be20e3220 (patch)
tree3a7b07667a8edb552bfd2e4c7ec08b276365c396
parent6d5f341999da7dfad708979151932fd9d8242ebd (diff)
downloadtracifyjs-d1aa09c5c7af14bf5f17cc7ea2ab5d6be20e3220.tar.gz
tracifyjs-d1aa09c5c7af14bf5f17cc7ea2ab5d6be20e3220.zip
fix `reduce_vars` on conditionals (#1822)
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/reduce_vars.js23
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f49dd60e..0dfe2a3c 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 94d37cb7..ad2c90bc 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"
+}