[Pkg-javascript-commits] [uglifyjs] 182/491: handle duplicate argument names in `collapse_vars` (#2215)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:33 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 71ee91e716a7fb0f1ef8a4a80a627e10944ef062
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Jul 8 04:42:35 2017 +0800

    handle duplicate argument names in `collapse_vars` (#2215)
---
 lib/compress.js                | 10 +++++++---
 test/compress/collapse_vars.js | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index e634924..74fb62e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -820,7 +820,11 @@ merge(Compressor.prototype, {
                     && !fn.uses_eval
                     && (iife = compressor.parent()) instanceof AST_Call
                     && iife.expression === fn) {
-                    fn.argnames.forEach(function(sym, i) {
+                    var names = Object.create(null);
+                    for (var i = fn.argnames.length; --i >= 0;) {
+                        var sym = fn.argnames[i];
+                        if (sym.name in names) continue;
+                        names[sym.name] = true;
                         var arg = iife.args[i];
                         if (!arg) arg = make_node(AST_Undefined, sym);
                         else {
@@ -840,11 +844,11 @@ merge(Compressor.prototype, {
                             });
                             arg.walk(tw);
                         }
-                        if (arg) candidates.push(make_node(AST_VarDef, sym, {
+                        if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
                             name: sym,
                             value: arg
                         }));
-                    });
+                    }
                 }
             }
 
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 7f3c470..10c403f 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2320,3 +2320,25 @@ issue_2203_2: {
     }
     expect_stdout: "PASS"
 }
+
+duplicate_argname: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        function f() { return "PASS"; }
+        console.log(function(a, a) {
+            f++;
+            return a;
+        }("FAIL", f()));
+    }
+    expect: {
+        function f() { return "PASS"; }
+        console.log(function(a, a) {
+            f++;
+            return a;
+        }("FAIL", f()));
+    }
+    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