From 69cb459c16b1a264f95681e8414c4d51a3197082 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Sun, 30 Jul 2017 02:10:59 +0800 Subject: [PATCH] fix-ups for #2258 --- lib/propmangle.js | 10 ++------- test/compress/object.js | 8 ++++--- test/compress/properties.js | 42 +++++++++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/propmangle.js b/lib/propmangle.js index aa45e64d..6ca6a491 100644 --- a/lib/propmangle.js +++ b/lib/propmangle.js @@ -93,6 +93,8 @@ function reserve_quoted_keys(ast, reserved) { ast.walk(new TreeWalker(function(node) { if (node instanceof AST_ObjectKeyVal && node.quote) { add(node.key); + } else if (node instanceof AST_ObjectProperty && node.quote) { + add(node.key.name); } else if (node instanceof AST_Sub) { addStrings(node.property, add); } @@ -155,9 +157,6 @@ function mangle_properties(ast, options) { if (node instanceof AST_ObjectKeyVal) { add(node.key); } - 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); @@ -175,11 +174,6 @@ function mangle_properties(ast, options) { if (node instanceof AST_ObjectKeyVal) { 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); diff --git a/test/compress/object.js b/test/compress/object.js index f7ce136a..4ad17324 100644 --- a/test/compress/object.js +++ b/test/compress/object.js @@ -284,9 +284,11 @@ concise_methods_with_various_property_names: { } concise_methods_and_mangle_props: { - mangle_props = { - regex: /_/ - }; + mangle = { + properties: { + regex: /_/, + }, + } input: { function x() { obj = { diff --git a/test/compress/properties.js b/test/compress/properties.js index 88cee79c..8f2a66aa 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -888,9 +888,11 @@ methods_keep_quoted_true: { arrows: true, ecma: 6, } - mangle_props = { - keep_quoted: true, - }; + mangle = { + properties: { + keep_quoted: true, + }, + } input: { class C { "Quoted"(){} Unquoted(){} } f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); @@ -905,9 +907,11 @@ methods_keep_quoted_false: { arrows: true, ecma: 6, } - mangle_props = { - keep_quoted: false, - }; + mangle = { + properties: { + keep_quoted: false, + }, + } input: { class C { "Quoted"(){} Unquoted(){} } f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); @@ -917,6 +921,32 @@ methods_keep_quoted_false: { expect_exact: "class C{o(){}d(){}}f1({o(){},d(){},e:3});f2({o(){}});f3({o(){}});" } +methods_keep_quoted_from_dead_code: { + options = { + arrows: true, + booleans: true, + conditionals: true, + dead_code: true, + ecma: 6, + evaluate: true, + reduce_vars: true, + side_effects: true, + } + mangle = { + properties: { + keep_quoted: true, + }, + } + input: { + class C { Quoted(){} Unquoted(){} } + f1({ Quoted(){}, Unquoted(){}, "Prop": 3 }); + f2({ Quoted: function(){} }); + f3({ Quoted: ()=>{} }); + 0 && obj["Quoted"]; + } + expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});" +} + issue_2256: { options = { side_effects: true,