mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
Implementing sethaurus' suggestion for better temp variable names -- getting rid of the numbers.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
this.expressions = expressions;
|
||||
this.method = method;
|
||||
this.variables = {};
|
||||
this.temp_variable = this.parent ? this.parent.temp_variable : 1;
|
||||
this.temp_var = this.parent ? this.parent.temp_var : '_a';
|
||||
return this;
|
||||
});
|
||||
// Look up a variable in lexical scope, or declare it if not found.
|
||||
@@ -47,13 +47,13 @@
|
||||
};
|
||||
// Find an available, short, name for a compiler-generated variable.
|
||||
Scope.prototype.free_variable = function free_variable() {
|
||||
var id;
|
||||
id = '_' + this.temp_variable;
|
||||
while (this.check(id)) {
|
||||
id = '_' + (this.temp_variable += 1);
|
||||
var ordinal;
|
||||
while (this.check(this.temp_var)) {
|
||||
ordinal = 1 + parseInt(this.temp_var.substr(1), 36);
|
||||
this.temp_var = '_' + ordinal.toString(36).replace(/\d/g, 'a');
|
||||
}
|
||||
this.variables[id] = 'var';
|
||||
return id;
|
||||
this.variables[this.temp_var] = 'var';
|
||||
return this.temp_var;
|
||||
};
|
||||
// Ensure that an assignment is made at the top of scope (or top-level
|
||||
// scope, if requested).
|
||||
@@ -78,45 +78,45 @@
|
||||
};
|
||||
// Return the list of variables first declared in current scope.
|
||||
Scope.prototype.declared_variables = function declared_variables() {
|
||||
var _1, _2, key, val;
|
||||
var _a, _b, key, val;
|
||||
return ((function() {
|
||||
_1 = []; _2 = this.variables;
|
||||
for (key in _2) if (__hasProp.call(_2, key)) {
|
||||
val = _2[key];
|
||||
_a = []; _b = this.variables;
|
||||
for (key in _b) if (__hasProp.call(_b, key)) {
|
||||
val = _b[key];
|
||||
if (val === 'var') {
|
||||
_1.push(key);
|
||||
_a.push(key);
|
||||
}
|
||||
}
|
||||
return _1;
|
||||
return _a;
|
||||
}).call(this)).sort();
|
||||
};
|
||||
// Return the list of variables that are supposed to be assigned at the top
|
||||
// of scope.
|
||||
Scope.prototype.assigned_variables = function assigned_variables() {
|
||||
var _1, _2, key, val;
|
||||
var _a, _b, key, val;
|
||||
return ((function() {
|
||||
_1 = []; _2 = this.variables;
|
||||
for (key in _2) if (__hasProp.call(_2, key)) {
|
||||
val = _2[key];
|
||||
_a = []; _b = this.variables;
|
||||
for (key in _b) if (__hasProp.call(_b, key)) {
|
||||
val = _b[key];
|
||||
if (val.assigned) {
|
||||
_1.push([key, val.value]);
|
||||
_a.push([key, val.value]);
|
||||
}
|
||||
}
|
||||
return _1;
|
||||
return _a;
|
||||
}).call(this)).sort();
|
||||
};
|
||||
Scope.prototype.compiled_declarations = function compiled_declarations() {
|
||||
return this.declared_variables().join(', ');
|
||||
};
|
||||
Scope.prototype.compiled_assignments = function compiled_assignments() {
|
||||
var _1, _2, _3, t;
|
||||
var _a, _b, _c, t;
|
||||
return ((function() {
|
||||
_1 = []; _2 = this.assigned_variables();
|
||||
for (_3 = 0; _3 < _2.length; _3++) {
|
||||
t = _2[_3];
|
||||
_1.push(t[0] + ' = ' + t[1]);
|
||||
_a = []; _b = this.assigned_variables();
|
||||
for (_c = 0; _c < _b.length; _c++) {
|
||||
t = _b[_c];
|
||||
_a.push(t[0] + ' = ' + t[1]);
|
||||
}
|
||||
return _1;
|
||||
return _a;
|
||||
}).call(this)).join(', ');
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user