If name_cache is specified, do rename cached properties
authorMihai Bazon <mihai.bazon@gmail.com>
Wed, 22 Apr 2015 14:34:49 +0000 (17:34 +0300)
committerMihai Bazon <mihai.bazon@gmail.com>
Wed, 22 Apr 2015 14:34:49 +0000 (17:34 +0300)
(even if --mangle-props is not there)

bin/uglifyjs
lib/propmangle.js

index df7b783..67db297 100755 (executable)
@@ -372,12 +372,13 @@ async.eachLimit(files, 1, function (file, cb) {
         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 cache = readNameCache("props");
         TOPLEVEL = UglifyJS.mangle_properties(TOPLEVEL, {
-            reserved: reserved,
-            cache: cache
+            reserved   : reserved,
+            cache      : cache,
+            only_cache : !ARGS.mangle_props
         });
         writeNameCache("props", cache);
     })();
index 46fb752..8f291d6 100644 (file)
@@ -63,7 +63,8 @@ function find_builtins() {
 function mangle_properties(ast, options) {
     options = defaults(options, {
         reserved : null,
-        cache : null
+        cache : null,
+        only_cache : false
     });
 
     var reserved = options.reserved;
@@ -139,6 +140,9 @@ function mangle_properties(ast, options) {
     // only function declarations after this line
 
     function can_mangle(name) {
+        if (options.only_cache) {
+            return cache.props.has(name);
+        }
         if (reserved.indexOf(name) >= 0) return false;
         if (/^[0-9.]+$/.test(name)) return false;
         return true;