1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

another reshuffle ... removed utilities.coffee entirely.

This commit is contained in:
Jeremy Ashkenas 2010-03-30 19:42:09 -04:00
parent 4a8c2e8a13
commit 6d7a04228f
5 changed files with 92 additions and 114 deletions

View file

@ -1,5 +1,5 @@
(function(){
var Scope, utilities;
var Scope;
var __hasProp = Object.prototype.hasOwnProperty;
// The **Scope** class regulates lexical scoping within CoffeeScript. As you
// generate code, you create a tree of scopes in the same shape as the nested
@ -11,7 +11,6 @@
if (!((typeof process !== "undefined" && process !== null))) {
this.exports = this;
}
utilities = (typeof process !== "undefined" && process !== null) ? require('./utilities').utilities : this.utilities;
exports.Scope = (function() {
Scope = function Scope(parent, expressions, method) {
var _a;
@ -81,38 +80,12 @@
};
// Ensure that an assignment is made at the top of this scope
// (or at the top-level scope, if requested).
Scope.prototype.assign = function assign(name, value, top_level) {
if (top_level) {
return Scope.root.assign(name, value);
}
Scope.prototype.assign = function assign(name, value) {
this.variables[name] = {
value: value,
assigned: true
};
return this.variables[name];
};
// Ensure the CoffeeScript utility object is included in the top level
// then return a CallNode curried constructor bound to the utility function
Scope.prototype.utility = function utility(name) {
var _a;
if (this.parent) {
return Scope.root.utility(name);
}
if ((typeof (_a = utilities[name]) !== "undefined" && _a !== null)) {
this.utilities = this.utilities || {};
this.utilities[name] = utilities[name];
}
return "__" + name;
};
// Formats an javascript object containing the utility methods required
// in the scope
Scope.prototype.included_utilities = function included_utilities() {
var _a, _b, key;
_a = []; _b = this.utilities;
for (key in _b) { if (__hasProp.call(_b, key)) {
_a.push("__" + key + " = " + (utilities[key]));
}}
return _a;
return name;
};
// Does this scope reference any variables that need to be declared in the
// given function body?
@ -124,9 +97,9 @@
// Does this scope reference any assignments that need to be declared at the
// top of the given function body?
Scope.prototype.has_assignments = function has_assignments(body) {
return body === this.expressions && (this.utilities || this.any(function(k, val) {
return body === this.expressions && this.any(function(k, val) {
return val.assigned;
}));
});
};
// Return the list of variables first declared in this scope.
Scope.prototype.declared_variables = function declared_variables() {
@ -157,7 +130,7 @@
};
// Compile the JavaScript for all of the variable assignments in this scope.
Scope.prototype.compiled_assignments = function compiled_assignments(tab) {
return this.assigned_variables().concat(this.included_utilities()).join(', ');
return this.assigned_variables().join(', ');
};
return Scope;
}).call(this);