[Pkg-javascript-commits] [uglifyjs] 05/06: Fix compression of conditionals

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


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

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

commit 18c63ff3d806439bfb4df613156563ec050e12e9
Author: Mihai Bazon <mihai.bazon at gmail.com>
Date:   Mon Apr 13 17:29:48 2015 +0300

    Fix compression of conditionals
    
    Don't move the condition on the right side of an assignment when
    the left side may have side effects.
    
    Fix #677
---
 lib/compress.js               |  1 +
 test/compress/conditionals.js | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 41e4f17..fa89c32 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2343,6 +2343,7 @@ merge(Compressor.prototype, {
             && alternative instanceof AST_Assign
             && consequent.operator == alternative.operator
             && consequent.left.equivalent_to(alternative.left)
+            && !consequent.left.has_side_effects(compressor)
            ) {
             /*
              * Stuff like this:
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index e5a3922..299097b 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -86,7 +86,9 @@ ifs_4: {
             x(foo)[10].bar.baz = something_else();
     }
     expect: {
-        x(foo)[10].bar.baz = (foo && bar) ? something() : something_else();
+        foo && bar
+            ? x(foo)[10].bar.baz = something()
+            : x(foo)[10].bar.baz = something_else();
     }
 }
 
@@ -133,6 +135,7 @@ ifs_6: {
         comparisons: true
     };
     input: {
+        var x;
         if (!foo && !bar && !baz && !boo) {
             x = 10;
         } else {
@@ -140,6 +143,7 @@ ifs_6: {
         }
     }
     expect: {
+        var x;
         x = foo || bar || baz || boo ? 20 : 10;
     }
 }
@@ -165,6 +169,7 @@ cond_2: {
         conditionals: true
     };
     input: {
+        var x;
         if (some_condition()) {
             x = new FooBar(1);
         } else {
@@ -172,6 +177,7 @@ cond_2: {
         }
     }
     expect: {
+        var x;
         x = new FooBar(some_condition() ? 1 : 2);
     }
 }
@@ -303,6 +309,7 @@ cond_7_1: {
         evaluate    : true
     };
     input: {
+        var x;
         // access to global should be assumed to have side effects
         if (y) {
             x = 1+1;
@@ -311,6 +318,7 @@ cond_7_1: {
         }
     }
     expect: {
+        var x;
         x = (y, 2);
     }
 }
@@ -321,6 +329,7 @@ cond_8: {
         evaluate    : true
     };
     input: {
+        var a;
         // compress these
         a = condition ? true : false;
 
@@ -355,6 +364,7 @@ cond_8: {
 
     }
     expect: {
+        var a;
         a = !!condition;
         a = !condition;
         a = !!condition();
@@ -367,4 +377,4 @@ cond_8: {
         a = condition ? 0 : true;
         a = condition ? 1 : 0;
     }
-}
\ No newline at end of file
+}

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