This commit is contained in:
alexlamsl
2017-07-30 02:10:59 +08:00
parent 1eae8f2dcc
commit 69cb459c16
3 changed files with 43 additions and 17 deletions

View File

@@ -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);

View File

@@ -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 = {

View File

@@ -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,