Using a typeof check in scope.
This commit is contained in:
parent
99c06b5cda
commit
2ddae698bb
15
lib/scope.js
15
lib/scope.js
|
@ -13,6 +13,7 @@
|
||||||
type: 'arguments'
|
type: 'arguments'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
this.positions = {};
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.garbage = this.parent.garbage;
|
this.garbage = this.parent.garbage;
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,19 +26,11 @@
|
||||||
})();
|
})();
|
||||||
Scope.root = null;
|
Scope.root = null;
|
||||||
Scope.prototype.add = function(name, type) {
|
Scope.prototype.add = function(name, type) {
|
||||||
var _len, _ref2, i, variable;
|
var pos;
|
||||||
_ref2 = this.variables;
|
return typeof (pos = this.positions[name]) === 'number' ? this.variables[pos].type = type : this.positions[name] = this.variables.push({
|
||||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
|
||||||
variable = _ref2[i];
|
|
||||||
if (variable.name === name) {
|
|
||||||
this.variables[i].type = type;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.variables.push({
|
|
||||||
name: name,
|
name: name,
|
||||||
type: type
|
type: type
|
||||||
});
|
}) - 1;
|
||||||
};
|
};
|
||||||
Scope.prototype.startLevel = function() {
|
Scope.prototype.startLevel = function() {
|
||||||
this.garbage.push([]);
|
this.garbage.push([]);
|
||||||
|
|
|
@ -19,6 +19,7 @@ exports.Scope = class Scope
|
||||||
# it wraps.
|
# it wraps.
|
||||||
constructor: (@parent, @expressions, @method) ->
|
constructor: (@parent, @expressions, @method) ->
|
||||||
@variables = [{name: 'arguments', type: 'arguments'}]
|
@variables = [{name: 'arguments', type: 'arguments'}]
|
||||||
|
@positions = {}
|
||||||
if @parent
|
if @parent
|
||||||
@garbage = @parent.garbage
|
@garbage = @parent.garbage
|
||||||
else
|
else
|
||||||
|
@ -27,11 +28,10 @@ exports.Scope = class Scope
|
||||||
|
|
||||||
# Adds a new variable or overrides an existing one.
|
# Adds a new variable or overrides an existing one.
|
||||||
add: (name, type) ->
|
add: (name, type) ->
|
||||||
for variable, i in @variables
|
if typeof (pos = @positions[name]) is 'number'
|
||||||
if variable.name is name
|
@variables[pos].type = type
|
||||||
@variables[i].type = type
|
else
|
||||||
return
|
@positions[name] = @variables.push({name, type}) - 1
|
||||||
@variables.push {name, type}
|
|
||||||
|
|
||||||
# Create a new garbage level
|
# Create a new garbage level
|
||||||
startLevel: ->
|
startLevel: ->
|
||||||
|
|
Loading…
Reference in New Issue