Convert p: function(){} to p(){} in object literals (#2199)
when `compress` option `ecma` is 6 or greater.
This commit is contained in:
@@ -4655,4 +4655,41 @@ merge(Compressor.prototype, {
|
||||
OPT(AST_PrefixedTemplateString, function(self, compressor){
|
||||
return self;
|
||||
});
|
||||
|
||||
OPT(AST_ObjectKeyVal, function(self, compressor){
|
||||
// p:function(){} ---> p(){}
|
||||
// p:function*(){} ---> *p(){}
|
||||
// p:async function(){} ---> async p(){}
|
||||
// p:()=>{} ---> p(){}
|
||||
// p:async()=>{} ---> async p(){}
|
||||
if (compressor.option("ecma") >= 6) {
|
||||
var key = self.key;
|
||||
var value = self.value;
|
||||
var is_arrow_with_block = value instanceof AST_Arrow
|
||||
&& Array.isArray(value.body)
|
||||
&& !contains_this(value);
|
||||
if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) {
|
||||
return make_node(AST_ConciseMethod, self, {
|
||||
async: value.async,
|
||||
is_generator: value.is_generator,
|
||||
key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, {
|
||||
name: key,
|
||||
}),
|
||||
value: make_node(AST_Accessor, value, value),
|
||||
});
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
||||
function contains_this(node) {
|
||||
var result;
|
||||
var tw = new TreeWalker(function(node) {
|
||||
if (node instanceof AST_This) {
|
||||
return result = true;
|
||||
}
|
||||
});
|
||||
node.walk(tw);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user