mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Put back every utility functions on the global scope, automatically prefixed with __
and set them dynamically as reserved on the lexer.
This commit is contained in:
parent
27fb3763b4
commit
97096696a2
13 changed files with 146 additions and 158 deletions
27
lib/scope.js
27
lib/scope.js
|
@ -1,8 +1,6 @@
|
|||
(function(){
|
||||
var Scope, utilities;
|
||||
var Coffeescript = {
|
||||
hasProp: Object.prototype.hasOwnProperty
|
||||
};
|
||||
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
|
||||
// function bodies. Each scope knows about the variables declared within it,
|
||||
|
@ -50,7 +48,7 @@
|
|||
Scope.prototype.any = function any(fn) {
|
||||
var _a, k, v;
|
||||
_a = this.variables;
|
||||
for (v in _a) { if (Coffeescript.hasProp.call(_a, v)) {
|
||||
for (v in _a) { if (__hasProp.call(_a, v)) {
|
||||
k = _a[v];
|
||||
if (fn(v, k)) {
|
||||
return true;
|
||||
|
@ -110,21 +108,18 @@
|
|||
!this.utilities[dep] ? this.utility(dep) : null;
|
||||
}
|
||||
}
|
||||
return "" + (utilities.key) + "." + name;
|
||||
return "" + (utilities.key(name));
|
||||
};
|
||||
// Formats an javascript object containing the utility methods required
|
||||
// in the scope
|
||||
Scope.prototype.included_utilities = function included_utilities(tab) {
|
||||
var _a, _b, _c, key, props;
|
||||
var _a, _b, _c, key;
|
||||
if ((typeof (_c = this.utilities) !== "undefined" && _c !== null)) {
|
||||
props = (function() {
|
||||
_a = []; _b = this.utilities;
|
||||
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) {
|
||||
_a.push(utilities.format(key, tab));
|
||||
}}
|
||||
return _a;
|
||||
}).call(this);
|
||||
return ["" + (utilities.key) + " = {" + (props.join(', ')) + "\n" + tab + "}"];
|
||||
_a = []; _b = this.utilities;
|
||||
for (key in _b) { if (__hasProp.call(_b, key)) {
|
||||
_a.push(utilities.format(key, tab));
|
||||
}}
|
||||
return _a;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
@ -149,7 +144,7 @@
|
|||
var _a, _b, key, val;
|
||||
return (function() {
|
||||
_a = []; _b = this.variables;
|
||||
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) {
|
||||
for (key in _b) { if (__hasProp.call(_b, key)) {
|
||||
val = _b[key];
|
||||
val === 'var' ? _a.push(key) : null;
|
||||
}}
|
||||
|
@ -161,7 +156,7 @@
|
|||
Scope.prototype.assigned_variables = function assigned_variables() {
|
||||
var _a, _b, key, val;
|
||||
_a = []; _b = this.variables;
|
||||
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) {
|
||||
for (key in _b) { if (__hasProp.call(_b, key)) {
|
||||
val = _b[key];
|
||||
val.assigned ? _a.push("" + key + " = " + (val.value)) : null;
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue