If name_cache is specified, do rename cached properties

(even if --mangle-props is not there)
This commit is contained in:
Mihai Bazon
2015-04-22 17:34:49 +03:00
parent 3b14582d6b
commit 7b22f2031f
2 changed files with 9 additions and 4 deletions

View File

@@ -372,12 +372,13 @@ async.eachLimit(files, 1, function (file, cb) {
TOPLEVEL = TOPLEVEL.wrap_enclose(arg_parameter_list); TOPLEVEL = TOPLEVEL.wrap_enclose(arg_parameter_list);
} }
if (ARGS.mangle_props) (function(){ if (ARGS.mangle_props || ARGS.name_cache) (function(){
var reserved = RESERVED ? RESERVED.props : null; var reserved = RESERVED ? RESERVED.props : null;
var cache = readNameCache("props"); var cache = readNameCache("props");
TOPLEVEL = UglifyJS.mangle_properties(TOPLEVEL, { TOPLEVEL = UglifyJS.mangle_properties(TOPLEVEL, {
reserved: reserved, reserved : reserved,
cache: cache cache : cache,
only_cache : !ARGS.mangle_props
}); });
writeNameCache("props", cache); writeNameCache("props", cache);
})(); })();

View File

@@ -63,7 +63,8 @@ function find_builtins() {
function mangle_properties(ast, options) { function mangle_properties(ast, options) {
options = defaults(options, { options = defaults(options, {
reserved : null, reserved : null,
cache : null cache : null,
only_cache : false
}); });
var reserved = options.reserved; var reserved = options.reserved;
@@ -139,6 +140,9 @@ function mangle_properties(ast, options) {
// only function declarations after this line // only function declarations after this line
function can_mangle(name) { function can_mangle(name) {
if (options.only_cache) {
return cache.props.has(name);
}
if (reserved.indexOf(name) >= 0) return false; if (reserved.indexOf(name) >= 0) return false;
if (/^[0-9.]+$/.test(name)) return false; if (/^[0-9.]+$/.test(name)) return false;
return true; return true;