[Pkg-javascript-commits] [uglifyjs] 397/491: improve `if_return` (#2727)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:56 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 b82feb9302adddb1763e9915b0daf9ff35ab2af2
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Jan 5 20:24:30 2018 +0800

    improve `if_return` (#2727)
---
 lib/compress.js            |  5 +++--
 test/compress/if_return.js | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index e824d6f..7f33b53 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1436,8 +1436,9 @@ merge(Compressor.prototype, {
                     }
                     //---
                     // if (foo()) return x; [ return ; ] ==> return foo() ? x : undefined;
-                    if (multiple_if_returns && in_lambda && value && !stat.alternative
-                        && (!next || next instanceof AST_Return)) {
+                    if (value && !stat.alternative
+                        && (!next && in_lambda && multiple_if_returns
+                            || next instanceof AST_Return)) {
                         CHANGED = true;
                         stat = stat.clone();
                         stat.alternative = next || make_node(AST_Return, stat, {
diff --git a/test/compress/if_return.js b/test/compress/if_return.js
index a0dfdc9..981b437 100644
--- a/test/compress/if_return.js
+++ b/test/compress/if_return.js
@@ -372,3 +372,27 @@ if_var_return: {
         }
     }
 }
+
+if_if_return_return: {
+    options = {
+        conditionals: true,
+        if_return: true,
+    }
+    input: {
+        function f(a, b) {
+            if (a) {
+                if (b)
+                    return b;
+                return;
+            }
+            g();
+        }
+    }
+    expect: {
+        function f(a, b) {
+            if (a)
+                return b || void 0;
+            g();
+        }
+    }
+}

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