[Pkg-javascript-commits] [uglifyjs] 230/491: account for side-effects from `AST_This` in `collapse_vars` (#2365)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:39 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 fe647b083e0def2bf6445534c7017baed09541a9
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Oct 17 01:18:55 2017 +0800

    account for side-effects from `AST_This` in `collapse_vars` (#2365)
---
 lib/compress.js                |  6 +++--
 test/compress/collapse_vars.js | 52 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index c3876f9..5e391ab 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -950,9 +950,11 @@ merge(Compressor.prototype, {
                         scope = save_scope;
                         return true;
                     }
-                    if (node instanceof AST_SymbolRef || node instanceof AST_PropAccess) {
+                    if (node instanceof AST_PropAccess
+                        || node instanceof AST_SymbolRef
+                        || node instanceof AST_This) {
                         var sym = get_symbol(node);
-                        if (sym instanceof AST_SymbolRef) {
+                        if (sym instanceof AST_SymbolRef || node instanceof AST_This) {
                             lvalues[sym.name] = lvalues[sym.name] || is_lhs(node, tw.parent());
                         }
                     }
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 7d66f7c..ec94e9f 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2600,3 +2600,55 @@ prop_side_effects_2: {
         "2",
     ]
 }
+
+issue_2364: {
+    options = {
+        collapse_vars: true,
+        pure_getters: true,
+    }
+    input: {
+        console.log(function(a) {
+            var b = a.f;
+            a.f++;
+            return b;
+        }({ f: 1 }));
+        console.log(function() {
+            var a = { f: 1 }, b = a.f;
+            a.f++;
+            return b;
+        }());
+        console.log({
+            f: 1,
+            g: function() {
+                var b = this.f;
+                this.f++;
+                return b;
+            }
+        }.g());
+    }
+    expect: {
+        console.log(function(a) {
+            var b = a.f;
+            a.f++;
+            return b;
+        }({ f: 1 }));
+        console.log(function() {
+            var a = { f: 1 }, b = a.f;
+            a.f++;
+            return b;
+        }());
+        console.log({
+            f: 1,
+            g: function() {
+                var b = this.f;
+                this.f++;
+                return b;
+            }
+        }.g());
+    }
+    expect_stdout: [
+        "1",
+        "1",
+        "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