From 3a865629ceb6fccb6ee2e05497c61a91fee1c27e Mon Sep 17 00:00:00 2001 From: kzc Date: Sun, 15 Oct 2017 13:31:50 -0400 Subject: [PATCH] move computed_props to top of OPT(AST_ObjectKeyVal) with fallthrough --- lib/compress.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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; }); })();