From d600c78d7b3da5c9a72ba1a0c37e6bc84e011ca3 Mon Sep 17 00:00:00 2001 From: kzc Date: Fri, 28 Jul 2017 07:42:12 -0400 Subject: [PATCH] have `keep_quoted` respect quoted method names (#2258) fixes #2257 --- lib/compress.js | 4 +++- lib/propmangle.js | 16 ++++++++-------- test/compress/properties.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index a6aef068..db26dfd7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4824,7 +4824,8 @@ merge(Compressor.prototype, { arrow.is_generator = self.is_generator; return make_node(AST_ObjectKeyVal, self, { key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key, - value: arrow + value: arrow, + quote: self.quote, }); } return self; @@ -4850,6 +4851,7 @@ merge(Compressor.prototype, { name: key, }), value: make_node(AST_Accessor, value, value), + quote: self.quote, }); } } diff --git a/lib/propmangle.js b/lib/propmangle.js index fd88eb5b..3c848c62 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -129,6 +129,9 @@ function mangle_properties(ast, options) { if (node instanceof AST_ObjectKeyVal) { add(node.key, keep_quoted && node.quote); } + else if (node instanceof AST_ConciseMethod && node.key && node.key.name) { + add(node.key.name, keep_quoted && node.quote); + } else if (node instanceof AST_ObjectProperty) { // setter or getter, since KeyVal is handled above add(node.key.name); @@ -139,9 +142,6 @@ function mangle_properties(ast, options) { else if (node instanceof AST_Sub) { addStrings(node.property, keep_quoted); } - else if (node instanceof AST_ConciseMethod) { - add(node.name.name); - } })); // step 2: transform the tree, renaming properties @@ -150,6 +150,11 @@ function mangle_properties(ast, options) { if (!(keep_quoted && node.quote)) node.key = mangle(node.key); } + else if (node instanceof AST_ConciseMethod && node.name && node.key.name) { + if (!(keep_quoted && node.quote) && should_mangle(node.key.name)) { + node.key.name = mangle(node.key.name); + } + } else if (node instanceof AST_ObjectProperty) { // setter or getter node.key.name = mangle(node.key.name); @@ -161,11 +166,6 @@ function mangle_properties(ast, options) { if (!keep_quoted) node.property = mangleStrings(node.property); } - else if (node instanceof AST_ConciseMethod) { - if (should_mangle(node.name.name)) { - node.name.name = mangle(node.name.name); - } - } // else if (node instanceof AST_String) { // if (should_mangle(node.value)) { // AST_Node.warn( diff --git a/test/compress/properties.js b/test/compress/properties.js index 214135a2..07cf7883 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -870,3 +870,37 @@ issue_2208_9: { expect_stdout: "42" node_version: ">=4" } + +methods_keep_quoted_true: { + options = { + arrows: true, + ecma: 6, + } + mangle_props = { + keep_quoted: true, + }; + input: { + class C { "Quoted"(){} Unquoted(){} } + f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); + f2({ "Quoted": function(){} }); + f3({ "Quoted": ()=>{} }); + } + expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});" +} + +methods_keep_quoted_false: { + options = { + arrows: true, + ecma: 6, + } + mangle_props = { + keep_quoted: false, + }; + input: { + class C { "Quoted"(){} Unquoted(){} } + f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); + f2({ "Quoted": function(){} }); + f3({ "Quoted": ()=>{} }); + } + expect_exact: "class C{o(){}d(){}}f1({o(){},d(){},e:3});f2({o(){}});f3({o(){}});" +}