diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-09 01:52:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-09 01:52:39 +0800 |
commit | bf1d47180c87462b1605157eb15b31c9db2c1249 (patch) | |
tree | 09b4c30e0ff396446f51e5cc9637ab07e8248a1a | |
parent | 0cfbd79aa123a97c94c1bf5032acf11c15886dad (diff) | |
download | tracifyjs-bf1d47180c87462b1605157eb15b31c9db2c1249.tar.gz tracifyjs-bf1d47180c87462b1605157eb15b31c9db2c1249.zip |
fix `join_vars` on property accessors (#2895)
fixes #2893
-rw-r--r-- | lib/compress.js | 11 | ||||
-rw-r--r-- | test/compress/properties.js | 52 |
2 files changed, 58 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js index dc453f14..e70af436 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1816,11 +1816,12 @@ merge(Compressor.prototype, { } if (prop instanceof AST_Node) break; prop = "" + prop; - if (compressor.has_directive("use strict")) { - if (!all(def.value.properties, function(node) { - return node.key != prop && node.key.name != prop; - })) break; - } + var diff = compressor.has_directive("use strict") ? function(node) { + return node.key != prop && node.key.name != prop; + } : function(node) { + return node.key.name != prop; + }; + if (!all(def.value.properties, diff)) break; def.value.properties.push(make_node(AST_ObjectKeyVal, node, { key: prop, value: node.right diff --git a/test/compress/properties.js b/test/compress/properties.js index dbc7bf2d..419c7f85 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -1588,3 +1588,55 @@ issue_2816: { } expect_stdout: "3 2 4" } + +issue_2893_1: { + options = { + join_vars: true, + } + input: { + var o = { + get a() { + return "PASS"; + }, + }; + o.a = "FAIL"; + console.log(o.a); + } + expect: { + var o = { + get a() { + return "PASS"; + }, + }; + o.a = "FAIL"; + console.log(o.a); + } + expect_stdout: "PASS" +} + +issue_2893_2: { + options = { + join_vars: true, + } + input: { + var o = { + set a(v) { + this.b = v; + }, + b: "FAIL", + }; + o.a = "PASS"; + console.log(o.b); + } + expect: { + var o = { + set a(v) { + this.b = v; + }, + b: "FAIL", + }; + o.a = "PASS"; + console.log(o.b); + } + expect_stdout: "PASS" +} |