diff --git a/lib/scope.js b/lib/scope.js index 2822fe29..a6bce387 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -13,7 +13,6 @@ type: 'arguments' } ]; - this.positions = {}; if (this.parent) { this.garbage = this.parent.garbage; } else { @@ -26,15 +25,19 @@ })(); Scope.root = null; Scope.prototype.add = function(name, type) { - if (this.positions.hasOwnProperty(name)) { - this.variables[this.positions[name]].type = type; - } else { - this.positions[name] = this.variables.push({ - name: name, - type: type - }) - 1; + var _len, _ref2, i, variable; + _ref2 = this.variables; + for (i = 0, _len = _ref2.length; i < _len; i++) { + variable = _ref2[i]; + if (variable.name === name) { + this.variables[i].type = type; + return; + } } - return this; + return this.variables.push({ + name: name, + type: type + }); }; Scope.prototype.startLevel = function() { this.garbage.push([]); diff --git a/src/scope.coffee b/src/scope.coffee index 3955fae3..b0e63e3d 100644 --- a/src/scope.coffee +++ b/src/scope.coffee @@ -19,7 +19,6 @@ exports.Scope = class Scope # it wraps. constructor: (@parent, @expressions, @method) -> @variables = [{name: 'arguments', type: 'arguments'}] - @positions = {} if @parent @garbage = @parent.garbage else @@ -28,11 +27,11 @@ exports.Scope = class Scope # Adds a new variable or overrides an existing one. add: (name, type) -> - if @positions.hasOwnProperty name - @variables[@positions[name]].type = type - else - @positions[name] = @variables.push({name, type}) - 1 - this + for variable, i in @variables + if variable.name is name + @variables[i].type = type + return + @variables.push {name, type} # Create a new garbage level startLevel: ->