mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixing scope.coffee -- we can't use a JS object as a hash that has to contain the word 'hasOwnProperty'
This commit is contained in:
21
lib/scope.js
21
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([]);
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
Reference in New Issue
Block a user