diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-03-30 15:07:36 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 15:07:36 +0900 |
commit | 06b9894c1970da69376296f97e853a465587292e (patch) | |
tree | 45682999768e09ea3ed2ea9247cdf1bad4a4aebd | |
parent | 9f9db504d72dad5097217129e6c0849c334a32ca (diff) | |
download | tracifyjs-06b9894c1970da69376296f97e853a465587292e.tar.gz tracifyjs-06b9894c1970da69376296f97e853a465587292e.zip |
handle modifications to `this` correctly (#3036)
fixes #3032
-rw-r--r-- | lib/compress.js | 1 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 03ed9e8a..52a23ee4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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)) diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 886a7564..e97f1031 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -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" +} |