[Pkg-javascript-commits] [uglifyjs] 04/05: Fix compressing conditionals

Jonas Smedegaard dr at jones.dk
Tue May 19 00:02:52 UTC 2015


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

js pushed a commit to tag v2.4.22
in repository uglifyjs.

commit a5b60217cede3f214153e62087d32274aa0859e5
Author: Mihai Bazon <mihai.bazon at gmail.com>
Date:   Mon May 18 13:56:04 2015 +0300

    Fix compressing conditionals
    
    Only transform foo() ? EXP(x) : EXP(y) into EXP(foo() ? x : y) if EXP has no
    side effects.
    
    Fix #710
---
 lib/compress.js               |  1 +
 test/compress/conditionals.js | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 944db1d..530e7c2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2356,6 +2356,7 @@ merge(Compressor.prototype, {
         if (consequent instanceof AST_Call
             && alternative.TYPE === consequent.TYPE
             && consequent.args.length == alternative.args.length
+            && !consequent.expression.has_side_effects(compressor)
             && consequent.expression.equivalent_to(alternative.expression)) {
             if (consequent.args.length == 0) {
                 return make_node(AST_Seq, self, {
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 299097b..1b96181 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -153,6 +153,7 @@ cond_1: {
         conditionals: true
     };
     input: {
+        var do_something; // if undeclared it's assumed to have side-effects
         if (some_condition()) {
             do_something(x);
         } else {
@@ -160,6 +161,7 @@ cond_1: {
         }
     }
     expect: {
+        var do_something;
         do_something(some_condition() ? x : y);
     }
 }
@@ -169,7 +171,7 @@ cond_2: {
         conditionals: true
     };
     input: {
-        var x;
+        var x, FooBar;
         if (some_condition()) {
             x = new FooBar(1);
         } else {
@@ -177,7 +179,7 @@ cond_2: {
         }
     }
     expect: {
-        var x;
+        var x, FooBar;
         x = new FooBar(some_condition() ? 1 : 2);
     }
 }
@@ -187,6 +189,7 @@ cond_3: {
         conditionals: true
     };
     input: {
+        var FooBar;
         if (some_condition()) {
             new FooBar(1);
         } else {
@@ -194,6 +197,7 @@ cond_3: {
         }
     }
     expect: {
+        var FooBar;
         some_condition() ? new FooBar(1) : FooBar(2);
     }
 }
@@ -203,6 +207,7 @@ cond_4: {
         conditionals: true
     };
     input: {
+        var do_something;
         if (some_condition()) {
             do_something();
         } else {
@@ -210,6 +215,7 @@ cond_4: {
         }
     }
     expect: {
+        var do_something;
         some_condition(), do_something();
     }
 }

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