diff --git a/lib/compress.js b/lib/compress.js index d88db1ba..ae0742a2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4870,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 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: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; }); })();