[Pkg-javascript-commits] [uglifyjs] 164/228: drop anonymous function name when overshadowed by other declarations (#1712)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:27 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit fb177a6312ccd90918c9f8f0f867c2fddd85a2c8
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Mar 28 17:02:20 2017 +0800

    drop anonymous function name when overshadowed by other declarations (#1712)
    
    fixes #1709
---
 lib/compress.js              | 10 +++++++---
 test/compress/drop-unused.js | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index e2fde88..e4863d9 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1850,9 +1850,13 @@ merge(Compressor.prototype, {
                 function before(node, descend, in_list) {
                     if (node instanceof AST_Function
                         && node.name
-                        && !compressor.option("keep_fnames")
-                        && !(node.name.definition().id in in_use_ids)) {
-                        node.name = null;
+                        && !compressor.option("keep_fnames")) {
+                        var def = node.name.definition();
+                        // any declarations with same name will overshadow
+                        // name of this anonymous function and can therefore
+                        // never be used anywhere
+                        if (!(def.id in in_use_ids) || def.orig.length > 1)
+                            node.name = null;
                     }
                     if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
                         var trim = !compressor.option("keep_fargs");
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index fabf8d9..10ca549 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -805,3 +805,42 @@ issue_1656: {
     }
     expect_exact: "for (;;) ;"
 }
+
+issue_1709: {
+    options = {
+        unused: true,
+    }
+    input: {
+        console.log(
+            function x() {
+                var x = 1;
+                return x;
+            }(),
+            function y() {
+                const y = 2;
+                return y;
+            }(),
+            function z() {
+                function z() {}
+                return z;
+            }()
+        );
+    }
+    expect: {
+        console.log(
+            function() {
+                var x = 1;
+                return x;
+            }(),
+            function() {
+                const y = 2;
+                return y;
+            }(),
+            function() {
+                function z() {}
+                return z;
+            }()
+        );
+    }
+    expect_stdout: true
+}

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