diff options
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/scope.js b/lib/scope.js index bceec289..79b2475d 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -43,9 +43,10 @@ "use strict"; -function SymbolDef(scope, orig) { +function SymbolDef(scope, orig, init) { this.name = orig.name; this.orig = [ orig ]; + this.init = init; this.eliminated = 0; this.scope = scope; this.references = []; @@ -158,10 +159,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ // scope when we encounter the AST_Defun node (which is // instanceof AST_Scope) but we get to the symbol a bit // later. - (node.scope = defun.parent_scope).def_function(node); + (node.scope = defun.parent_scope).def_function(node, defun); } else if (node instanceof AST_SymbolVar) { - defun.def_variable(node); + defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined); if (defun !== scope) { node.mark_enclosed(options); var def = scope.find_variable(node); @@ -306,21 +307,21 @@ AST_Scope.DEFMETHOD("find_variable", function(name){ || (this.parent_scope && this.parent_scope.find_variable(name)); }); -AST_Scope.DEFMETHOD("def_function", function(symbol){ - var def = this.def_variable(symbol); +AST_Scope.DEFMETHOD("def_function", function(symbol, init){ + var def = this.def_variable(symbol, init); + if (!def.init) def.init = init; this.functions.set(symbol.name, def); return def; }); -AST_Scope.DEFMETHOD("def_variable", function(symbol){ - var def; - if (!this.variables.has(symbol.name)) { - def = new SymbolDef(this, symbol); +AST_Scope.DEFMETHOD("def_variable", function(symbol, init){ + var def = this.variables.get(symbol.name); + if (def) { + def.orig.push(symbol); + } else { + def = new SymbolDef(this, symbol, init); this.variables.set(symbol.name, def); def.global = !this.parent_scope; - } else { - def = this.variables.get(symbol.name); - def.orig.push(symbol); } return symbol.thedef = def; }); |