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