fix corner case in keep_fnames

happens when inner function:
- just below top level
- not referenced
- `unused` is disabled

closes #1445
This commit is contained in:
alexlamsl
2017-02-18 19:00:54 +08:00
parent 686a496b1c
commit fa668a28b4
2 changed files with 31 additions and 2 deletions

View File

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

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: { level_one: {
options = { options = {
keep_fnames: true keep_fnames: true