[Pkg-javascript-commits] [uglifyjs] 376/491: fix `dead_code` on escaped `return` assignment (#2693)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:54 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 ed7a0a454e9c06c592a0dd40ea740faadc0bb4c0
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Dec 30 15:20:25 2017 +0800

    fix `dead_code` on escaped `return` assignment (#2693)
    
    fixes #2692
---
 lib/compress.js            |  8 ++++----
 test/compress/dead-code.js | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 318246c..b94e584 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4838,7 +4838,7 @@ merge(Compressor.prototype, {
         return self;
     });
 
-    function is_reachable(node, defs) {
+    function is_reachable(self, defs) {
         var reachable = false;
         var find_ref = new TreeWalker(function(node) {
             if (reachable) return true;
@@ -4848,7 +4848,7 @@ merge(Compressor.prototype, {
         });
         var scan_scope = new TreeWalker(function(node) {
             if (reachable) return true;
-            if (node instanceof AST_Scope) {
+            if (node instanceof AST_Scope && node !== self) {
                 var parent = scan_scope.parent();
                 if (!(parent instanceof AST_Call && parent.expression === node)) {
                     node.walk(find_ref);
@@ -4856,7 +4856,7 @@ merge(Compressor.prototype, {
                 return true;
             }
         });
-        node.walk(scan_scope);
+        self.walk(scan_scope);
         return reachable;
     }
 
@@ -4873,7 +4873,7 @@ merge(Compressor.prototype, {
                 parent = compressor.parent(level++);
                 if (parent instanceof AST_Exit) {
                     if (in_try(level, parent instanceof AST_Throw)) break;
-                    if (is_reachable(self, [ def ])) break;
+                    if (is_reachable(def.scope, [ def ])) break;
                     if (self.operator == "=") return self.right;
                     return make_node(AST_Binary, self, {
                         operator: self.operator.slice(0, -1),
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 7ea380d..68ee4b1 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -855,3 +855,29 @@ issue_2666: {
     }
     expect_stdout: "object"
 }
+
+issue_2692: {
+    options = {
+        dead_code: true,
+        reduce_vars: false,
+    }
+    input: {
+        function f(a) {
+            return a = g;
+            function g() {
+                return a;
+            }
+        }
+        console.log(typeof f()());
+    }
+    expect: {
+        function f(a) {
+            return a = g;
+            function g() {
+                return a;
+            }
+        }
+        console.log(typeof f()());
+    }
+    expect_stdout: "function"
+}

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