aboutsummaryrefslogtreecommitdiff
path: root/lib/propmangle.js
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen@experty.com>2015-07-31 15:56:33 +0200
committerRichard van Velzen <rvanvelzen@experty.com>2015-08-05 21:18:39 +0200
commit759b3f7d6df1cecaefd987218373ce3db3646845 (patch)
tree7bf50a6e91e53879df8f5949ff497f733045a7b0 /lib/propmangle.js
parent958b6c2e57ea64cf876c3f884db2a76f11f7074f (diff)
downloadtracifyjs-759b3f7d6df1cecaefd987218373ce3db3646845.tar.gz
tracifyjs-759b3f7d6df1cecaefd987218373ce3db3646845.zip
Fix mangling of property names which overwrite unmangleable properties
Fixes #747.
Diffstat (limited to 'lib/propmangle.js')
-rw-r--r--lib/propmangle.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/propmangle.js b/lib/propmangle.js
index 086709e6..840bda91 100644
--- a/lib/propmangle.js
+++ b/lib/propmangle.js
@@ -83,6 +83,7 @@ function mangle_properties(ast, options) {
var regex = options.regex;
var names_to_mangle = [];
+ var unmangleable = [];
// step 1: find candidates to mangle
ast.walk(new TreeWalker(function(node){
@@ -108,20 +109,14 @@ function mangle_properties(ast, options) {
// step 2: transform the tree, renaming properties
return ast.transform(new TreeTransformer(function(node){
if (node instanceof AST_ObjectKeyVal) {
- if (should_mangle(node.key)) {
- node.key = mangle(node.key);
- }
+ node.key = mangle(node.key);
}
else if (node instanceof AST_ObjectProperty) {
// setter or getter
- if (should_mangle(node.key.name)) {
- node.key.name = mangle(node.key.name);
- }
+ node.key.name = mangle(node.key.name);
}
else if (node instanceof AST_Dot) {
- if (should_mangle(node.property)) {
- node.property = mangle(node.property);
- }
+ node.property = mangle(node.property);
}
else if (node instanceof AST_Sub) {
node.property = mangleStrings(node.property);
@@ -143,6 +138,7 @@ function mangle_properties(ast, options) {
// only function declarations after this line
function can_mangle(name) {
+ if (unmangleable.indexOf(name) >= 0) return false;
if (reserved.indexOf(name) >= 0) return false;
if (options.only_cache) {
return cache.props.has(name);
@@ -161,9 +157,17 @@ function mangle_properties(ast, options) {
function add(name) {
if (can_mangle(name))
push_uniq(names_to_mangle, name);
+
+ if (!should_mangle(name)) {
+ push_uniq(unmangleable, name);
+ }
}
function mangle(name) {
+ if (!should_mangle(name)) {
+ return name;
+ }
+
var mangled = cache.props.get(name);
if (!mangled) {
do {
@@ -206,9 +210,7 @@ function mangle_properties(ast, options) {
node.cdr = mangleStrings(node.cdr);
}
else if (node instanceof AST_String) {
- if (should_mangle(node.value)) {
- node.value = mangle(node.value);
- }
+ node.value = mangle(node.value);
}
else if (node instanceof AST_Conditional) {
node.consequent = mangleStrings(node.consequent);