mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Added generator for custom free variable types, e.g., '_cache',
'_cache2', and so on.
This commit is contained in:
25
lib/scope.js
25
lib/scope.js
@@ -58,14 +58,25 @@
|
||||
}
|
||||
return !!(this.parent && this.parent.check(name));
|
||||
};
|
||||
Scope.prototype.freeVariable = function() {
|
||||
var ordinal;
|
||||
while (this.check(this.tempVars.general)) {
|
||||
ordinal = 1 + parseInt(this.tempVars.general.substr(1), 36);
|
||||
this.tempVars.general = '_' + ordinal.toString(36).replace(/\d/g, 'a');
|
||||
Scope.prototype.freeVariable = function(type) {
|
||||
var next;
|
||||
if (type) {
|
||||
next = function(prev) {
|
||||
return '_' + type + ((prev && Number(prev.match(/\d+$/) || 1) + 1) || '');
|
||||
};
|
||||
} else {
|
||||
type = 'general';
|
||||
next = function(prev) {
|
||||
var ordinal;
|
||||
ordinal = 1 + parseInt(prev.substr(1), 36);
|
||||
return '_' + ordinal.toString(36).replace(/\d/g, 'a');
|
||||
};
|
||||
}
|
||||
this.variables[this.tempVars.general] = 'var';
|
||||
return this.tempVars.general;
|
||||
while (this.check(this.tempVars[type] || (this.tempVars[type] = next()))) {
|
||||
this.tempVars[type] = next(this.tempVars[type]);
|
||||
}
|
||||
this.variables[this.tempVars[type]] = 'var';
|
||||
return this.tempVars[type];
|
||||
};
|
||||
Scope.prototype.assign = function(name, value) {
|
||||
return (this.variables[name] = {
|
||||
|
||||
Reference in New Issue
Block a user