[Pkg-javascript-commits] [uglifyjs] 123/491: fix `AST_Function` scope invariance (#2052)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:28 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 540220b91bb02d50d04422dc782a5fe1905dd27a
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Jun 4 19:27:43 2017 +0800

    fix `AST_Function` scope invariance (#2052)
    
    improve function name hack in `run_code()`
---
 lib/compress.js              |  2 +-
 test/compress/drop-unused.js | 12 ++++++------
 test/compress/reduce_vars.js | 39 ++++++++++++++++++++++++++++++++++-----
 test/sandbox.js              |  4 +++-
 4 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 71cffce..effa6b1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2957,7 +2957,7 @@ merge(Compressor.prototype, {
                     && !(def.scope.uses_arguments
                         && def.orig[0] instanceof AST_SymbolFunarg)
                     && !def.scope.uses_eval
-                    && compressor.find_parent(AST_Scope) === def.scope) {
+                    && compressor.find_parent(AST_Scope) === exp.parent_scope) {
                     self.expression = exp;
                 }
             }
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 2ef6f79..af792bf 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -751,12 +751,12 @@ issue_1583: {
     expect: {
         function m(t) {
             (function(e) {
-                t = (function() {
-                    return (function(a) {
-                        return a;
-                    })(function(a) {});
-                })();
-            })();
+                t = e();
+            })(function() {
+                return (function(a) {
+                    return a;
+                })(function(a) {});
+            });
         }
     }
 }
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 2a44492..078de82 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1311,19 +1311,48 @@ iife_func_side_effects: {
         unused: true,
     }
     input: {
+        function x() {
+            console.log("x");
+        }
+        function y() {
+            console.log("y");
+        }
+        function z() {
+            console.log("z");
+        }
         (function(a, b, c) {
-            return b();
+            function y() {
+                console.log("FAIL");
+            }
+            return y + b();
         })(x(), function() {
             return y();
         }, z());
     }
     expect: {
+        function x() {
+            console.log("x");
+        }
+        function y() {
+            console.log("y");
+        }
+        function z() {
+            console.log("z");
+        }
         (function(a, b, c) {
-            return function() {
-                return y();
-            }();
-        })(x(), 0, z());
+            function y() {
+                console.log("FAIL");
+            }
+            return y + b();
+        })(x(), function() {
+            return y();
+        }, z());
     }
+    expect_stdout: [
+        "x",
+        "z",
+        "y",
+    ]
 }
 
 issue_1595_1: {
diff --git a/test/sandbox.js b/test/sandbox.js
index 974f521..ca1781c 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -26,16 +26,18 @@ var FUNC_TOSTRING = [
     "        var i = this.name;",
     '        if (typeof i != "number") {',
     "            i = ++id;",
+].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
     '            Object.defineProperty(this, "name", {',
     "                get: function() {",
     "                    return i;",
     "                }",
     "            });",
+] : [], [
     "        }",
     '        return "[Function: " + i + "]";',
     "    }",
     "}();",
-].join("\n");
+]).join("\n");
 exports.run_code = function(code) {
     var stdout = "";
     var original_write = process.stdout.write;

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