fix mangle for variable declared within catch block (#1706)

fixes #1704
This commit is contained in:
Alex Lam S.L
2017-03-28 03:26:35 +08:00
committed by GitHub
parent aa3f647656
commit 984a21704e
2 changed files with 182 additions and 2 deletions

View File

@@ -154,6 +154,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
else if (node instanceof AST_SymbolVar
|| node instanceof AST_SymbolConst) {
defun.def_variable(node);
if (defun !== scope) node.mark_enclosed(options);
}
else if (node instanceof AST_SymbolCatch) {
scope.def_variable(node);
@@ -262,9 +263,8 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function(){
}));
});
AST_SymbolRef.DEFMETHOD("reference", function(options) {
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
var def = this.definition();
def.references.push(this);
var s = this.scope;
while (s) {
push_uniq(s.enclosed, def);
@@ -278,6 +278,11 @@ AST_SymbolRef.DEFMETHOD("reference", function(options) {
}
});
AST_SymbolRef.DEFMETHOD("reference", function(options) {
this.definition().references.push(this);
this.mark_enclosed(options);
});
AST_Scope.DEFMETHOD("find_variable", function(name){
if (name instanceof AST_Symbol) name = name.name;
return this.variables.get(name)