aboutsummaryrefslogtreecommitdiff
path: root/lib/propmangle.js
diff options
context:
space:
mode:
authorShrey Banga <shrey@quip.com>2016-05-05 13:44:59 -0700
committerRichard van Velzen <rvanvelzen1@gmail.com>2016-06-19 21:13:31 +0200
commite645ba84cfc950183a222c2cce2ea6b94fe51226 (patch)
tree9ca5d7b1d55c36adb14f0468d4442f2a3a0aeb2d /lib/propmangle.js
parent6c99816855b650c6804a67f4891c339a3e8970f4 (diff)
downloadtracifyjs-e645ba84cfc950183a222c2cce2ea6b94fe51226.tar.gz
tracifyjs-e645ba84cfc950183a222c2cce2ea6b94fe51226.zip
Respect quote style in object literals
The option added in fbbaa42ee55a7f753f7cab9b1a905ccf73cf26d5 wasn't being respected inside object literals, so quoted property names would still be stripped out with this option. This is mostly a corner-case, but useful when the output is passed to something like the Closure compiler, where quoted property names can be used to prevent mangling.
Diffstat (limited to 'lib/propmangle.js')
-rw-r--r--lib/propmangle.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/propmangle.js b/lib/propmangle.js
index 840bda91..08043d73 100644
--- a/lib/propmangle.js
+++ b/lib/propmangle.js
@@ -65,7 +65,8 @@ function mangle_properties(ast, options) {
reserved : null,
cache : null,
only_cache : false,
- regex : null
+ regex : null,
+ ignore_quoted : false
});
var reserved = options.reserved;
@@ -81,6 +82,7 @@ function mangle_properties(ast, options) {
}
var regex = options.regex;
+ var ignore_quoted = options.ignore_quoted;
var names_to_mangle = [];
var unmangleable = [];
@@ -88,7 +90,8 @@ function mangle_properties(ast, options) {
// step 1: find candidates to mangle
ast.walk(new TreeWalker(function(node){
if (node instanceof AST_ObjectKeyVal) {
- add(node.key);
+ if (!(ignore_quoted && node.quote))
+ add(node.key);
}
else if (node instanceof AST_ObjectProperty) {
// setter or getter, since KeyVal is handled above
@@ -101,7 +104,8 @@ function mangle_properties(ast, options) {
}
else if (node instanceof AST_Sub) {
if (this.parent() instanceof AST_Assign) {
- addStrings(node.property);
+ if (!ignore_quoted)
+ addStrings(node.property);
}
}
}));
@@ -109,7 +113,8 @@ function mangle_properties(ast, options) {
// step 2: transform the tree, renaming properties
return ast.transform(new TreeTransformer(function(node){
if (node instanceof AST_ObjectKeyVal) {
- node.key = mangle(node.key);
+ if (!(ignore_quoted && node.quote))
+ node.key = mangle(node.key);
}
else if (node instanceof AST_ObjectProperty) {
// setter or getter
@@ -119,7 +124,8 @@ function mangle_properties(ast, options) {
node.property = mangle(node.property);
}
else if (node instanceof AST_Sub) {
- node.property = mangleStrings(node.property);
+ if (!ignore_quoted)
+ node.property = mangleStrings(node.property);
}
// else if (node instanceof AST_String) {
// if (should_mangle(node.value)) {