fix corner case in keep_fnames

happens when inner function:
- just below top level
- not referenced
- `unused` is disabled
This commit is contained in:
alexlamsl 2017-01-28 02:49:22 +08:00
parent 7f8d72d9d3
commit 49a36f194e
2 changed files with 31 additions and 2 deletions

View File

@ -270,12 +270,12 @@ AST_SymbolRef.DEFMETHOD("reference", function(options) {
var s = this.scope;
while (s) {
push_uniq(s.enclosed, def);
if (s === def.scope) break;
if (options.keep_fnames) {
s.variables.each(function(d) {
s.functions.each(function(d) {
push_uniq(def.scope.enclosed, d);
});
}
if (s === def.scope) break;
s = s.parent_scope;
}
this.frame = this.scope.nesting - def.scope.nesting;

View File

@ -1,3 +1,32 @@
level_zero: {
options = {
keep_fnames: true
}
mangle = {
keep_fnames: true
}
input: {
function f(x) {
function n(a) {
return a * a;
}
return function() {
return x;
};
}
}
expect: {
function f(r) {
function n(n) {
return n * n;
}
return function() {
return r;
};
}
}
}
level_one: {
options = {
keep_fnames: true