Fixes name collision issue, which is not directly related to this patch
but has an additional case in debug mode. Added regression test.
This commit is contained in:
Ashley (Scirra) 2016-10-06 17:41:11 +01:00
parent 7de8ffe77b
commit 10cee1144b
2 changed files with 42 additions and 3 deletions

View File

@ -214,15 +214,18 @@ function mangle_properties(ast, options) {
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
var debug_mangled = "_$" + name + "$" + debug_cache_name + "_";
if (can_mangle(debug_mangled))
if (can_mangle(debug_mangled) && !(ignore_quoted && debug_mangled in ignored))
mangled = debug_mangled;
}
// either debug mode is off, or it is on and can_mangle returned false
// 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));
} while (!can_mangle(mangled) || (ignore_quoted && mangled in ignored));
}
cache.props.set(name, mangled);

View File

@ -0,0 +1,36 @@
issue_1321_no_debug: {
mangle_props = {
ignore_quoted: true
}
input: {
var x = {};
x.foo = 1;
x["a"] = 2 * x.foo;
console.log(x.foo, x["a"]);
}
expect: {
var x = {};
x.b = 1;
x["a"] = 2 * x.b;
console.log(x.b, x["a"]);
}
}
issue_1321_debug: {
mangle_props = {
ignore_quoted: true,
debug: ""
}
input: {
var x = {};
x.foo = 1;
x["_$foo$_"] = 2 * x.foo;
console.log(x.foo, x["_$foo$_"]);
}
expect: {
var x = {};
x.a = 1;
x["_$foo$_"] = 2 * x.a;
console.log(x.a, x["_$foo$_"]);
}
}