[Pkg-javascript-commits] [uglifyjs] 146/491: suppress `inline` of `this` (#2103)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:30 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 b85a358deb70615596bf5ffc668e2ac282453f88
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jun 15 12:14:16 2017 +0800

    suppress `inline` of `this` (#2103)
    
    fixes #2101
---
 lib/compress.js            |  7 ++++++-
 test/compress/functions.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 4d76878..f598934 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3209,10 +3209,15 @@ merge(Compressor.prototype, {
                         if (!value) return make_node(AST_Undefined, self);
                         value.walk(new TreeWalker(function(node) {
                             if (value === self) return true;
-                            if (node instanceof AST_SymbolRef && exp.variables.has(node.name)) {
+                            if (node instanceof AST_SymbolRef && matches(node.scope.find_variable(node))
+                                || node instanceof AST_This && matches(node)) {
                                 value = self;
                                 return true;
                             }
+
+                            function matches(ref) {
+                                return ref && ref.scope.parent_scope === fn.parent_scope;
+                            }
                         }));
                         if (value !== self) value = best_of(compressor, value, self);
                     } else {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 909a57d..c2794f2 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -365,3 +365,52 @@ issue_2097: {
     }
     expect_stdout: "1"
 }
+
+issue_2101: {
+    options = {
+        inline: true,
+    }
+    input: {
+        a = {};
+        console.log(function() {
+            return function() {
+                return this.a;
+            }();
+        }() === function() {
+            return a;
+        }());
+    }
+    expect: {
+        a = {};
+        console.log(function() {
+            return this.a;
+        }() === a);
+    }
+    expect_stdout: "true"
+}
+
+inner_ref: {
+    options = {
+        inline: true,
+        unused: true,
+    }
+    input: {
+        console.log(function(a) {
+            return function() {
+                return a;
+            }();
+        }(1), function(a) {
+            return function(a) {
+                return a;
+            }();
+        }(2));
+    }
+    expect: {
+        console.log(function(a) {
+            return a;
+        }(1), function(a) {
+            return a;
+        }());
+    }
+    expect_stdout: "1 undefined"
+}

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