implement compress option computed_props (#2361)
transforms `{["computed"]: 1}` into `{computed: 1}`
This commit is contained in:
@@ -53,6 +53,7 @@ function Compressor(options, false_by_default) {
|
||||
cascade : !false_by_default,
|
||||
collapse_vars : !false_by_default,
|
||||
comparisons : !false_by_default,
|
||||
computed_props: !false_by_default,
|
||||
conditionals : !false_by_default,
|
||||
dead_code : !false_by_default,
|
||||
drop_console : false,
|
||||
@@ -4869,6 +4870,18 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
|
||||
OPT(AST_ObjectKeyVal, function(self, compressor){
|
||||
// ["p"]:1 ---> p:1
|
||||
// [42]:1 ---> 42:1
|
||||
if (compressor.option("computed_props")
|
||||
&& self.key instanceof AST_Constant // save a comparison in the typical case
|
||||
&& (
|
||||
// whitelist acceptable props as not all AST_Constants are true constants
|
||||
self.key instanceof AST_String
|
||||
|| self.key instanceof AST_Number
|
||||
)) {
|
||||
self.key = self.key.value;
|
||||
// fallthrough - `return self` not needed as transformed tree in good form
|
||||
}
|
||||
// p:function(){} ---> p(){}
|
||||
// p:function*(){} ---> *p(){}
|
||||
// p:async function(){} ---> async p(){}
|
||||
|
||||
Reference in New Issue
Block a user