[Pkg-javascript-commits] [uglifyjs] 315/491: fix escape analysis for `AST_Throw` (#2564)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:48 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 74a2f53683e2b8788eadc10762583491e3dbc7ea
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Dec 8 02:54:37 2017 +0800

    fix escape analysis for `AST_Throw` (#2564)
---
 lib/compress.js              |   2 +-
 test/compress/reduce_vars.js | 163 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 164 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index c80192d..7f1b46e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -652,7 +652,7 @@ merge(Compressor.prototype, {
             }
             if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
                 || parent instanceof AST_Call && node !== parent.expression
-                || parent instanceof AST_Return && node === parent.value && node.scope !== d.scope
+                || parent instanceof AST_Exit && node === parent.value && node.scope !== d.scope
                 || parent instanceof AST_VarDef && node === parent.value) {
                 d.escaped = true;
                 return;
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 9a66d1c..df2eb71 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -4621,3 +4621,166 @@ issue_2560_2: {
     }
     expect_stdout: "PASS"
 }
+
+issue_2560_3: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function main() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("FAIL");
+            else
+                console.log("PASS");
+        }
+        function baz() {
+            try {
+                throw foo;
+            } catch (bar) {
+                return bar;
+            }
+        }
+        function foo() {}
+        main();
+    }
+    expect: {
+        function baz() {
+            try {
+                throw foo;
+            } catch (bar) {
+                return bar;
+            }
+        }
+        function foo() {}
+        (function() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("FAIL");
+            else
+                console.log("PASS");
+        })();
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2560_4: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function main() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        }
+        function baz(s) {
+            function foo() {}
+            function bar() {}
+            return s ? foo : bar;
+        }
+        main();
+    }
+    expect: {
+        function baz(s) {
+            return s ? function() {} : function() {};
+        }
+        (function() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        })();
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2560_5: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function main() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        }
+        function baz() {
+            function foo() {}
+            function bar() {}
+            return foo, bar;
+        }
+        main();
+    }
+    expect: {
+        function baz() {
+            return function() {}, function() {};
+        }
+        (function() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        })();
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2560_6: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        function main() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        }
+        function baz() {
+            function foo() {}
+            try {
+                throw foo;
+            } catch (bar) {
+                return bar;
+            }
+        }
+        main();
+    }
+    expect: {
+        function baz() {
+            try {
+                throw function() {};
+            } catch (bar) {
+                return bar;
+            }
+        }
+        (function() {
+            var thing = baz();
+            if (thing !== (thing = baz()))
+                console.log("PASS");
+            else
+                console.log("FAIL");
+        })();
+    }
+    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