aboutsummaryrefslogtreecommitdiff
path: root/lib/propmangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/propmangle.js')
-rw-r--r--lib/propmangle.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/propmangle.js b/lib/propmangle.js
index 3923baa6..f2777475 100644
--- a/lib/propmangle.js
+++ b/lib/propmangle.js
@@ -66,7 +66,8 @@ function mangle_properties(ast, options) {
cache : null,
only_cache : false,
regex : null,
- ignore_quoted : false
+ ignore_quoted : false,
+ debug : false
});
var reserved = options.reserved;
@@ -84,6 +85,15 @@ function mangle_properties(ast, options) {
var regex = options.regex;
var ignore_quoted = options.ignore_quoted;
+ // note debug is either false (disabled), or a string of the debug suffix to use (enabled).
+ // note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
+ // the same as passing an empty string.
+ var debug = (options.debug !== false);
+ var debug_name_suffix;
+ if (debug) {
+ debug_name_suffix = (options.debug === true ? "" : options.debug);
+ }
+
var names_to_mangle = [];
var unmangleable = [];
var ignored = {};
@@ -177,9 +187,25 @@ function mangle_properties(ast, options) {
var mangled = cache.props.get(name);
if (!mangled) {
- do {
- mangled = base54(++cache.cname);
- } while (!can_mangle(mangled));
+ if (debug) {
+ // debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
+ var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
+
+ if (can_mangle(debug_mangled) && !(ignore_quoted && debug_mangled in ignored)) {
+ mangled = debug_mangled;
+ }
+ }
+
+ // either debug mode is off, or it is on and we could not use the mangled name
+ if (!mangled) {
+ // note can_mangle() does not check if the name collides with the 'ignored' set
+ // (filled with quoted properties when ignore_quoted set). Make sure we add this
+ // check so we don't collide with a quoted name.
+ do {
+ mangled = base54(++cache.cname);
+ } while (!can_mangle(mangled) || (ignore_quoted && mangled in ignored));
+ }
+
cache.props.set(name, mangled);
}
return mangled;