[Pkg-javascript-commits] [uglifyjs] 338/491: fix `dead_code` on nested `try` (#2599)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:50 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 7d6907cb99bac1e835febe30494ebca4c1a671d3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Dec 15 19:41:28 2017 +0800

    fix `dead_code` on nested `try` (#2599)
    
    fixes #2597
---
 lib/compress.js            | 13 ++++++-------
 test/compress/dead-code.js | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 0162fa4..a8bcf54 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4751,11 +4751,7 @@ merge(Compressor.prototype, {
                 node = parent;
                 parent = compressor.parent(level++);
                 if (parent instanceof AST_Exit) {
-                    var try_node = find_try(level);
-                    if (try_node) {
-                        if (try_node.bfinally) break;
-                        if (parent instanceof AST_Throw && try_node.bcatch) break;
-                    }
+                    if (in_try(level, parent instanceof AST_Throw)) break;
                     if (self.operator == "=") return self.right;
                     return make_node(AST_Binary, self, {
                         operator: self.operator.slice(0, -1),
@@ -4787,11 +4783,14 @@ merge(Compressor.prototype, {
         }
         return self;
 
-        function find_try(level) {
+        function in_try(level, no_catch) {
             var scope = self.left.definition().scope;
             var parent;
             while ((parent = compressor.parent(level++)) !== scope) {
-                if (parent instanceof AST_Try) return parent;
+                if (parent instanceof AST_Try) {
+                    if (parent.bfinally) return true;
+                    if (no_catch && parent.bcatch) return true;
+                }
             }
         }
     });
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 2d2f9d9..591dd3a 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -789,3 +789,42 @@ throw_assignment: {
         "caught -9",
     ]
 }
+
+issue_2597: {
+    options = {
+        dead_code: true,
+    }
+    input: {
+        function f(b) {
+            try {
+                try {
+                    throw "foo";
+                } catch (e) {
+                    return b = true;
+                }
+            } finally {
+                b && (a = "PASS");
+            }
+        }
+        var a = "FAIL";
+        f();
+        console.log(a);
+    }
+    expect: {
+        function f(b) {
+            try {
+                try {
+                    throw "foo";
+                } catch (e) {
+                    return b = true;
+                }
+            } finally {
+                b && (a = "PASS");
+            }
+        }
+        var a = "FAIL";
+        f();
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}

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