handle modifications to `this` correctly (#3036)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 30 Mar 2018 06:07:36 +0000 (15:07 +0900)
committerGitHub <noreply@github.com>
Fri, 30 Mar 2018 06:07:36 +0000 (15:07 +0900)
fixes #3032

lib/compress.js
test/compress/collapse_vars.js

index 03ed9e8..52a23ee 100644 (file)
@@ -1052,6 +1052,7 @@ merge(Compressor.prototype, {
                         && (side_effects || node.expression.may_throw_on_access(compressor))
                     || node instanceof AST_SymbolRef
                         && (symbol_in_lvalues(node) || side_effects && may_modify(node))
+                    || node instanceof AST_This && symbol_in_lvalues(node)
                     || node instanceof AST_VarDef && node.value
                         && (node.name.name in lvalues || side_effects && may_modify(node.name))
                     || (sym = is_lhs(node.left, node))
index 886a756..e97f103 100644 (file)
@@ -5303,3 +5303,27 @@ issue_2974: {
     }
     expect_stdout: "1"
 }
+
+issue_3032: {
+    options = {
+        collapse_vars: true,
+        pure_getters: true,
+    }
+    input: {
+        console.log({
+            f: function() {
+                this.a = 42;
+                return [ this.a, !1 ];
+            }
+        }.f()[0]);
+    }
+    expect: {
+        console.log({
+            f: function() {
+                this.a = 42;
+                return [ this.a, !1 ];
+            }
+        }.f()[0]);
+    }
+    expect_stdout: "42"
+}