aboutsummaryrefslogtreecommitdiff
path: root/lib/propmangle.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-05 05:08:09 +0800
committerGitHub <noreply@github.com>2018-01-05 05:08:09 +0800
commitafbcebddf63c7ffa5b0df9b3712ee3b560918f1e (patch)
tree8348f45f70f00abdb764c328899cd849ee870d23 /lib/propmangle.js
parent484e484571448595389e4c6fd9559e47c5591f7a (diff)
downloadtracifyjs-afbcebddf63c7ffa5b0df9b3712ee3b560918f1e.tar.gz
tracifyjs-afbcebddf63c7ffa5b0df9b3712ee3b560918f1e.zip
fix `mangle` name collision across files (#2722)
Diffstat (limited to 'lib/propmangle.js')
-rw-r--r--lib/propmangle.js25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/propmangle.js b/lib/propmangle.js
index c2f27c42..ffc8faf8 100644
--- a/lib/propmangle.js
+++ b/lib/propmangle.js
@@ -110,12 +110,15 @@ function mangle_properties(ast, options) {
if (!Array.isArray(reserved)) reserved = [];
if (!options.builtins) find_builtins(reserved);
- var cache = options.cache;
- if (cache == null) {
- cache = {
- cname: -1,
- props: new Dictionary()
- };
+ var cname = -1;
+ var cache;
+ if (options.cache) {
+ cache = options.cache.props;
+ cache.each(function(mangled_name) {
+ push_uniq(reserved, mangled_name);
+ });
+ } else {
+ cache = new Dictionary();
}
var regex = options.regex;
@@ -172,7 +175,7 @@ function mangle_properties(ast, options) {
if (unmangleable.indexOf(name) >= 0) return false;
if (reserved.indexOf(name) >= 0) return false;
if (options.only_cache) {
- return cache.props.has(name);
+ return cache.has(name);
}
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
return true;
@@ -181,7 +184,7 @@ function mangle_properties(ast, options) {
function should_mangle(name) {
if (regex && !regex.test(name)) return false;
if (reserved.indexOf(name) >= 0) return false;
- return cache.props.has(name)
+ return cache.has(name)
|| names_to_mangle.indexOf(name) >= 0;
}
@@ -199,7 +202,7 @@ function mangle_properties(ast, options) {
return name;
}
- var mangled = cache.props.get(name);
+ var mangled = cache.get(name);
if (!mangled) {
if (debug) {
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
@@ -213,11 +216,11 @@ function mangle_properties(ast, options) {
// either debug mode is off, or it is on and we could not use the mangled name
if (!mangled) {
do {
- mangled = base54(++cache.cname);
+ mangled = base54(++cname);
} while (!can_mangle(mangled));
}
- cache.props.set(name, mangled);
+ cache.set(name, mangled);
}
return mangled;
}