[Pkg-javascript-commits] [uglifyjs] 92/228: fix function name eliminiation (#1576)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:20 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 c7cdcf06a65b70b557894c1680fc099d3c7aca6a
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Mar 8 12:39:57 2017 +0800

    fix function name eliminiation (#1576)
    
    Function expression can be assigned to a variable and be given a name. Ensure function name is the reduced variable before clearing it out.
    
    fixes #1573
    fixes #1575
---
 lib/compress.js              |  3 ++-
 test/compress/reduce_vars.js | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 85b457e..f423fdd 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2611,7 +2611,8 @@ merge(Compressor.prototype, {
                 if (compressor.option("unused")
                     && def.references.length == 1
                     && compressor.find_parent(AST_Scope) === def.scope) {
-                    if (!compressor.option("keep_fnames")) {
+                    if (!compressor.option("keep_fnames")
+                        && exp.name && exp.name.definition() === def) {
                         exp.name = null;
                     }
                     self.expression = exp;
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 53e2815..10dc9d9 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1122,3 +1122,25 @@ defun_label: {
         }();
     }
 }
+
+double_reference: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            var g = function g() {
+                g();
+            };
+            g();
+        }
+    }
+    expect: {
+        function f() {
+            (function g() {
+                g();
+            })();
+        }
+    }
+}

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