[Pkg-javascript-commits] [uglifyjs] 457/491: relax `collapse_vars` on `AST_Exit` (#2855)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:04 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 2a4c68be4f3ed60fa638b66a57e7056f7507da83
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Jan 31 23:49:59 2018 +0800

    relax `collapse_vars` on `AST_Exit` (#2855)
    
    First introduced in #1862 to stop assignments to migrate beyond `return` or `throw`. Since then `collapse_vars` has been improved to handle various side-effect-related corner cases.
---
 lib/compress.js                |  1 -
 test/compress/collapse_vars.js | 83 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index d0ef5f5..db6ee8b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1044,7 +1044,6 @@ merge(Compressor.prototype, {
                 // but are otherwise not safe to scan into or beyond them.
                 var sym;
                 if (node instanceof AST_Call
-                    || node instanceof AST_Exit
                     || node instanceof AST_PropAccess
                         && (side_effects || node.expression.may_throw_on_access(compressor))
                     || node instanceof AST_SymbolRef
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 4172b33..b361781 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -4107,3 +4107,86 @@ unsafe_builtin: {
     }
     expect_stdout: "1 4"
 }
+
+return_1: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var log = console.log;
+        function f(b, c) {
+            var a = c;
+            if (b) return b;
+            log(a);
+        }
+        f(false, 1);
+        f(true, 2);
+    }
+    expect: {
+        var log = console.log;
+        function f(b, c) {
+            if (b) return b;
+            log(c);
+        }
+        f(false, 1);
+        f(true, 2);
+    }
+    expect_stdout: "1"
+}
+
+return_2: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var log = console.log;
+        function f(b, c) {
+            var a = c();
+            if (b) return b;
+            log(a);
+        }
+        f(false, function() { return 1 });
+        f(true, function() { return 2 });
+    }
+    expect: {
+        var log = console.log;
+        function f(b, c) {
+            var a = c();
+            if (b) return b;
+            log(a);
+        }
+        f(false, function() { return 1 });
+        f(true, function() { return 2 });
+    }
+    expect_stdout: "1"
+}
+
+return_3: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var log = console.log;
+        function f(b, c) {
+            var a = b <<= c;
+            if (b) return b;
+            log(a);
+        }
+        f(false, 1);
+        f(true, 2);
+    }
+    expect: {
+        var log = console.log;
+        function f(b, c) {
+            var a = b <<= c;
+            if (b) return b;
+            log(a);
+        }
+        f(false, 1);
+        f(true, 2);
+    }
+    expect_stdout: "0"
+}

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