@@ -4828,7 +4828,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (is_lhs(self, compressor.parent())) return self;
|
||||
if (compressor.option("properties") && key !== prop) {
|
||||
var node = self.flatten_object(property);
|
||||
var node = self.flatten_object(property, compressor);
|
||||
if (node) {
|
||||
expr = self.expression = node.expression;
|
||||
prop = self.property = node.property;
|
||||
@@ -4888,22 +4888,26 @@ merge(Compressor.prototype, {
|
||||
return result;
|
||||
});
|
||||
|
||||
AST_PropAccess.DEFMETHOD("flatten_object", function(key) {
|
||||
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
||||
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6;
|
||||
var expr = this.expression;
|
||||
if (expr instanceof AST_Object) {
|
||||
var props = expr.properties;
|
||||
for (var i = props.length; --i >= 0;) {
|
||||
var prop = props[i];
|
||||
if ("" + prop.key == key) {
|
||||
if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) {
|
||||
if (!all(props, function(prop) {
|
||||
return prop instanceof AST_ObjectKeyVal;
|
||||
return prop instanceof AST_ObjectKeyVal
|
||||
|| arrows && prop instanceof AST_ConciseMethod && !prop.is_generator;
|
||||
})) break;
|
||||
var value = prop.value;
|
||||
if (value instanceof AST_Function && value.contains_this()) break;
|
||||
if ((value instanceof AST_Accessor || value instanceof AST_Function)
|
||||
&& value.contains_this()) break;
|
||||
return make_node(AST_Sub, this, {
|
||||
expression: make_node(AST_Array, expr, {
|
||||
elements: props.map(function(prop) {
|
||||
return prop.value;
|
||||
var v = prop.value;
|
||||
return v instanceof AST_Accessor ? make_node(AST_Function, v, v) : v;
|
||||
})
|
||||
}),
|
||||
property: make_node(AST_Number, this, {
|
||||
@@ -4944,7 +4948,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (is_lhs(self, compressor.parent())) return self;
|
||||
if (compressor.option("properties")) {
|
||||
var node = self.flatten_object(self.property);
|
||||
var node = self.flatten_object(self.property, compressor);
|
||||
if (node) return node.optimize(compressor);
|
||||
}
|
||||
var ev = self.evaluate(compressor);
|
||||
|
||||
@@ -1291,7 +1291,6 @@ issue_2063: {
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
var a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -902,10 +902,10 @@ issue_2349b: {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 3,
|
||||
properties: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unsafe_arrows: true,
|
||||
unused: true,
|
||||
}
|
||||
|
||||
@@ -797,8 +797,8 @@ issue_2208_5: {
|
||||
issue_2208_6: {
|
||||
options = {
|
||||
inline: true,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
console.log({
|
||||
@@ -814,9 +814,11 @@ issue_2208_6: {
|
||||
|
||||
issue_2208_7: {
|
||||
options = {
|
||||
ecma: 6,
|
||||
inline: true,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unsafe_arrows: true,
|
||||
}
|
||||
input: {
|
||||
console.log({
|
||||
@@ -834,9 +836,11 @@ issue_2208_7: {
|
||||
|
||||
issue_2208_8: {
|
||||
options = {
|
||||
ecma: 6,
|
||||
inline: true,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unsafe_arrows: true,
|
||||
}
|
||||
input: {
|
||||
console.log({
|
||||
@@ -856,17 +860,17 @@ issue_2208_8: {
|
||||
return x();
|
||||
}
|
||||
}.p());
|
||||
console.log(async function() {
|
||||
console.log((async () => {
|
||||
return await x();
|
||||
}());
|
||||
})());
|
||||
}
|
||||
}
|
||||
|
||||
issue_2208_9: {
|
||||
options = {
|
||||
inline: true,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
a = 42;
|
||||
|
||||
@@ -442,7 +442,7 @@ simple_string: {
|
||||
console.log({[`foo`]: 1}[`foo`], `hi` == "hi", `world`);
|
||||
}
|
||||
expect: {
|
||||
console.log({foo: 1}.foo, true, "world");
|
||||
console.log([ 1 ][0], true, "world");
|
||||
}
|
||||
expect_stdout: "1 true 'world'"
|
||||
node_version: ">=4"
|
||||
|
||||
Reference in New Issue
Block a user