move computed_props to top of OPT(AST_ObjectKeyVal) with fallthrough

This commit is contained in:
kzc 2017-10-15 13:31:50 -04:00
parent efe01cb8b8
commit 3a865629ce

View File

@ -4870,6 +4870,18 @@ merge(Compressor.prototype, {
}); });
OPT(AST_ObjectKeyVal, function(self, compressor){ 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 AST_Constants are not all constant
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:function*(){} ---> *p(){} // p:function*(){} ---> *p(){}
// p:async function(){} ---> async p(){} // p:async function(){} ---> async p(){}
@ -4896,18 +4908,6 @@ merge(Compressor.prototype, {
}); });
} }
} }
// ["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 AST_Constants are not all constant
self.key instanceof AST_String
|| self.key instanceof AST_Number
)) {
self.key = self.key.value;
return self;
}
return self; return self;
}); });
})(); })();