handle computed properties correctly

This commit is contained in:
alexlamsl
2017-10-29 17:42:25 +08:00
parent 3ae34177a6
commit 0a9cdb6c73
2 changed files with 30 additions and 1 deletions

View File

@@ -4907,7 +4907,12 @@ merge(Compressor.prototype, {
expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) {
var v = prop.value;
return v instanceof AST_Accessor ? make_node(AST_Function, v, v) : v;
if (v instanceof AST_Accessor) v = make_node(AST_Function, v, v);
var k = prop.key;
if (k instanceof AST_Node && !(k instanceof AST_SymbolMethod)) {
return make_sequence(prop, [ k, v ]);
}
return v;
})
}),
property: make_node(AST_Number, this, {

View File

@@ -1258,3 +1258,27 @@ array_hole: {
}
expect_stdout: "2 undefined 3"
}
computed_property: {
options = {
properties: true,
side_effects: true,
}
input: {
console.log({
a: "bar",
[console.log("foo")]: 42,
}.a);
}
expect: {
console.log([
"bar",
console.log("foo")
][0]);
}
expect_stdout: [
"foo",
"bar"
]
node_version: ">=4"
}