[Pkg-javascript-commits] [uglifyjs] 157/491: fix `reduce_vars` on `this` (#2145)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:31 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 3d5bc081851897648ccc71009a2138240fe41fa0
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Jun 23 04:44:57 2017 +0800

    fix `reduce_vars` on `this` (#2145)
    
    fixes #2140
---
 lib/compress.js              | 10 +++++-----
 test/compress/reduce_vars.js | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index aa7affc..c332282 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -279,11 +279,11 @@ merge(Compressor.prototype, {
         var reduce_vars = rescan && compressor.option("reduce_vars");
         var safe_ids = Object.create(null);
         var suppressor = new TreeWalker(function(node) {
-            if (node instanceof AST_Symbol) {
-                var d = node.definition();
-                if (node instanceof AST_SymbolRef) d.references.push(node);
-                d.fixed = false;
-            }
+            if (!(node instanceof AST_Symbol)) return;
+            var d = node.definition();
+            if (!d) return;
+            if (node instanceof AST_SymbolRef) d.references.push(node);
+            d.fixed = false;
         });
         var tw = new TreeWalker(function(node, descend) {
             node._squeezed = false;
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index cef2983..5906a97 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -2575,3 +2575,28 @@ accessor: {
     }
     expect_stdout: "1 1"
 }
+
+for_in_prop: {
+    options = {
+        reduce_vars: true,
+    }
+    input: {
+        var a = {
+            foo: function() {
+                for (this.b in [1, 2]);
+            }
+        };
+        a.foo();
+        console.log(a.b);
+    }
+    expect: {
+        var a = {
+            foo: function() {
+                for (this.b in [1, 2]);
+            }
+        };
+        a.foo();
+        console.log(a.b);
+    }
+    expect_stdout: "1"
+}

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