fix join_vars on property accessors (#2895)

fixes #2893
This commit is contained in:
Alex Lam S.L
2018-02-09 01:52:39 +08:00
committed by GitHub
parent 0cfbd79aa1
commit bf1d47180c
2 changed files with 58 additions and 5 deletions

View File

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

View File

@@ -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"
}