[Pkg-javascript-commits] [uglifyjs] 179/491: suppress `collapse_vars` of `this` as call argument (#2204)

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 9306da3c58831fabc93dfae6a7ea4f45d42183d4
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jul 6 01:03:52 2017 +0800

    suppress `collapse_vars` of `this` as call argument (#2204)
    
    fixes #2203
---
 lib/compress.js                | 25 +++++++++++------
 test/compress/collapse_vars.js | 64 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index d9936d2..a2acd53 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -823,16 +823,23 @@ merge(Compressor.prototype, {
                     fn.argnames.forEach(function(sym, i) {
                         var arg = iife.args[i];
                         if (!arg) arg = make_node(AST_Undefined, sym);
-                        else arg.walk(new TreeWalker(function(node) {
-                            if (!arg) return true;
-                            if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
-                                var s = node.definition().scope;
-                                if (s !== scope) while (s = s.parent_scope) {
-                                    if (s === scope) return true;
+                        else {
+                            var tw = new TreeWalker(function(node) {
+                                if (!arg) return true;
+                                if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
+                                    var s = node.definition().scope;
+                                    if (s !== scope) while (s = s.parent_scope) {
+                                        if (s === scope) return true;
+                                    }
+                                    arg = null;
                                 }
-                                arg = null;
-                            }
-                        }));
+                                if (node instanceof AST_This && !tw.find_parent(AST_Scope)) {
+                                    arg = null;
+                                    return true;
+                                }
+                            });
+                            arg.walk(tw);
+                        }
                         if (arg) candidates.push(make_node(AST_VarDef, sym, {
                             name: sym,
                             value: arg
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 24f8ffa..7f3c470 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2256,3 +2256,67 @@ issue_2187_3: {
     }
     expect_stdout: "1"
 }
+
+issue_2203_1: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        a = "FAIL";
+        console.log({
+            a: "PASS",
+            b: function() {
+                return function(c) {
+                    return c.a;
+                }((String, (Object, this)));
+            }
+        }.b());
+    }
+    expect: {
+        a = "FAIL";
+        console.log({
+            a: "PASS",
+            b: function() {
+                return function(c) {
+                    return c.a;
+                }((String, (Object, this)));
+            }
+        }.b());
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2203_2: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        a = "PASS";
+        console.log({
+            a: "FAIL",
+            b: function() {
+                return function(c) {
+                    return c.a;
+                }((String, (Object, function() {
+                    return this;
+                }())));
+            }
+        }.b());
+    }
+    expect: {
+        a = "PASS";
+        console.log({
+            a: "FAIL",
+            b: function() {
+                return function(c) {
+                    return (String, (Object, function() {
+                        return this;
+                    }())).a;
+                }();
+            }
+        }.b());
+    }
+    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