fix mangling collision with keep_fnames

fixes #1423
This commit is contained in:
alexlamsl 2017-01-21 01:30:27 +08:00
parent 48284844a4
commit 9c794844af
2 changed files with 129 additions and 7 deletions

View File

@ -224,7 +224,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|| parent instanceof AST_Assign && parent.left === node) { || parent instanceof AST_Assign && parent.left === node) {
sym.modified = true; sym.modified = true;
} }
node.reference(); node.reference(options);
return true; return true;
} }
}); });
@ -255,13 +255,18 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function(){
this.variables.set(symbol.name, def); this.variables.set(symbol.name, def);
}); });
AST_SymbolRef.DEFMETHOD("reference", function() { AST_SymbolRef.DEFMETHOD("reference", function(options) {
var def = this.definition(); var def = this.definition();
def.references.push(this); def.references.push(this);
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 (s === def.scope) break;
if (options.keep_fnames) {
s.variables.each(function(d) {
push_uniq(def.scope.enclosed, d);
});
}
s = s.parent_scope; s = s.parent_scope;
} }
this.frame = this.scope.nesting - def.scope.nesting; this.frame = this.scope.nesting - def.scope.nesting;
@ -329,11 +334,6 @@ AST_Function.DEFMETHOD("next_mangled", function(options, def){
} }
}); });
AST_Scope.DEFMETHOD("references", function(sym){
if (sym instanceof AST_Symbol) sym = sym.definition();
return this.enclosed.indexOf(sym) < 0 ? null : sym;
});
AST_Symbol.DEFMETHOD("unmangleable", function(options){ AST_Symbol.DEFMETHOD("unmangleable", function(options){
return this.definition().unmangleable(options); return this.definition().unmangleable(options);
}); });

122
test/compress/issue-1423.js Normal file
View File

@ -0,0 +1,122 @@
level_one: {
options = {
keep_fnames: true
}
mangle = {
keep_fnames: true
}
input: {
function f(x) {
return function() {
function n(a) {
return a * a;
}
return x(n);
};
}
}
expect: {
function f(r) {
return function() {
function n(n) {
return n * n;
}
return r(n);
};
}
}
}
level_two: {
options = {
keep_fnames: true
}
mangle = {
keep_fnames: true
}
input: {
function f(x) {
return function() {
function r(a) {
return a * a;
}
return function() {
function n(a) {
return a * a;
}
return x(n);
};
};
}
}
expect: {
function f(t) {
return function() {
function r(n) {
return n * n;
}
return function() {
function n(n) {
return n * n;
}
return t(n);
};
};
}
}
}
level_three: {
options = {
keep_fnames: true
}
mangle = {
keep_fnames: true
}
input: {
function f(x) {
return function() {
function r(a) {
return a * a;
}
return [
function() {
function t(a) {
return a * a;
}
return t;
},
function() {
function n(a) {
return a * a;
}
return x(n);
}
];
};
}
}
expect: {
function f(t) {
return function() {
function r(n) {
return n * n;
}
return [
function() {
function t(n) {
return n * n;
}
return t;
},
function() {
function n(n) {
return n * n;
}
return t(n);
}
];
};
}
}
}