1
0
Fork 0
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:
matehat 2010-03-30 16:48:43 -04:00
parent 27fb3763b4
commit 97096696a2
13 changed files with 146 additions and 158 deletions

View file

@ -1,17 +1,13 @@
(function(){ (function(){
var CoffeeScript, fs, helpers, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks; var CoffeeScript, fs, helpers, no_such_task, oparse, options, optparse, path, print_tasks, switches, tasks;
var Coffeescript = { var __slice = function(array, from, to, exclusive) {
slice: function(array, from, to, exclusive) { return array.slice.apply(array, __range(array, from, to, exclusive));
return array.slice.apply(array, Coffeescript.range(array, from, to, exclusive)); }, __range = function(array, from, to, exclusive) {
}, return [
range: function(array, from, to, exclusive) { (from < 0 ? from + array.length : from || 0),
return [ (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)
(from < 0 ? from + array.length : from || 0), ];
(to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1) }, __hasProp = Object.prototype.hasOwnProperty;
];
},
hasProp: Object.prototype.hasOwnProperty
};
// `cake` is a simplified version of [Make](http://www.gnu.org/software/make/) // `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
// ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake)) // ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake))
// for CoffeeScript. You define tasks with names and descriptions in a Cakefile, // for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
@ -64,7 +60,7 @@
if (!(exists)) { if (!(exists)) {
throw new Error("Cakefile not found in " + (process.cwd())); throw new Error("Cakefile not found in " + (process.cwd()));
} }
args = Coffeescript.slice(process.argv, 2, process.argv.length, true); args = __slice(process.argv, 2, process.argv.length, true);
CoffeeScript.run(fs.readFileSync('Cakefile'), { CoffeeScript.run(fs.readFileSync('Cakefile'), {
source: 'Cakefile' source: 'Cakefile'
}); });
@ -86,7 +82,7 @@
var _a, _b, _c, _d, _e, i, name, spaces, task; var _a, _b, _c, _d, _e, i, name, spaces, task;
puts(''); puts('');
_a = tasks; _a = tasks;
for (name in _a) { if (Coffeescript.hasProp.call(_a, name)) { for (name in _a) { if (__hasProp.call(_a, name)) {
task = _a[name]; task = _a[name];
spaces = 20 - name.length; spaces = 20 - name.length;
spaces = spaces > 0 ? (function() { spaces = spaces > 0 ? (function() {

View file

@ -1,15 +1,12 @@
(function(){ (function(){
var BANNER, CoffeeScript, SWITCHES, compile_options, compile_script, compile_scripts, compile_stdio, fs, lint, option_parser, options, optparse, parse_options, path, print_tokens, sources, usage, version, watch_scripts, write_js; var BANNER, CoffeeScript, SWITCHES, compile_options, compile_script, compile_scripts, compile_stdio, fs, lint, option_parser, options, optparse, parse_options, path, print_tokens, sources, usage, version, watch_scripts, write_js;
var Coffeescript = { var __slice = function(array, from, to, exclusive) {
slice: function(array, from, to, exclusive) { return array.slice.apply(array, __range(array, from, to, exclusive));
return array.slice.apply(array, Coffeescript.range(array, from, to, exclusive)); }, __range = function(array, from, to, exclusive) {
}, return [
range: function(array, from, to, exclusive) { (from < 0 ? from + array.length : from || 0),
return [ (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)
(from < 0 ? from + array.length : from || 0), ];
(to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)
];
}
}; };
// The `coffee` utility. Handles command-line compilation of CoffeeScript // The `coffee` utility. Handles command-line compilation of CoffeeScript
// into various forms: saved into `.js` files or printed to stdout, piped to // into various forms: saved into `.js` files or printed to stdout, piped to
@ -56,8 +53,8 @@
separator = sources.indexOf('--'); separator = sources.indexOf('--');
flags = []; flags = [];
if (separator >= 0) { if (separator >= 0) {
flags = Coffeescript.slice(sources, (separator + 1), sources.length, true); flags = __slice(sources, (separator + 1), sources.length, true);
sources = Coffeescript.slice(sources, 0, separator, true); sources = __slice(sources, 0, separator, true);
} }
process.ARGV = (process.argv = flags); process.ARGV = (process.argv = flags);
if (options.watch) { if (options.watch) {
@ -213,7 +210,7 @@
o = (options = option_parser.parse(process.argv)); o = (options = option_parser.parse(process.argv));
options.run = !(o.compile || o.print || o.lint); options.run = !(o.compile || o.print || o.lint);
options.print = !!(o.print || (o.eval || o.stdio && o.compile)); options.print = !!(o.print || (o.eval || o.stdio && o.compile));
sources = Coffeescript.slice(options.arguments, 2, options.arguments.length, true); sources = __slice(options.arguments, 2, options.arguments.length, true);
return sources; return sources;
}; };
// The compile-time options to pass to the CoffeeScript compiler. // The compile-time options to pass to the CoffeeScript compiler.

View file

@ -1,8 +1,6 @@
(function(){ (function(){
var Parser, _a, _b, _c, _d, _e, _f, _g, _h, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; var Parser, _a, _b, _c, _d, _e, _f, _g, _h, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
var Coffeescript = { var __hasProp = Object.prototype.hasOwnProperty;
hasProp: Object.prototype.hasOwnProperty
};
// The CoffeeScript parser is generated by [Jison](http://github.com/zaach/jison) // The CoffeeScript parser is generated by [Jison](http://github.com/zaach/jison)
// from this grammar file. Jison is a bottom-up parser generator, similar in // from this grammar file. Jison is a bottom-up parser generator, similar in
// style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript. // style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript.
@ -674,7 +672,7 @@
// as "tokens". // as "tokens".
tokens = []; tokens = [];
_a = grammar; _a = grammar;
for (name in _a) { if (Coffeescript.hasProp.call(_a, name)) { for (name in _a) { if (__hasProp.call(_a, name)) {
alternatives = _a[name]; alternatives = _a[name];
grammar[name] = (function() { grammar[name] = (function() {
_b = []; _d = alternatives; _b = []; _d = alternatives;

View file

@ -1,8 +1,6 @@
(function(){ (function(){
var balanced_string, compact, count, del, extend, flatten, helpers, include, merge, starts; var balanced_string, compact, count, del, extend, flatten, helpers, include, merge, starts;
var Coffeescript = { var __hasProp = Object.prototype.hasOwnProperty;
hasProp: Object.prototype.hasOwnProperty
};
// This file contains the common helper functions that we'd like to share among // This file contains the common helper functions that we'd like to share among
// the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten // the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
// arrays, count characters, that sort of thing. // arrays, count characters, that sort of thing.
@ -47,13 +45,13 @@
var _a, _b, fresh, key, val; var _a, _b, fresh, key, val;
fresh = {}; fresh = {};
_a = options; _a = options;
for (key in _a) { if (Coffeescript.hasProp.call(_a, key)) { for (key in _a) { if (__hasProp.call(_a, key)) {
val = _a[key]; val = _a[key];
(fresh[key] = val); (fresh[key] = val);
}} }}
if (overrides) { if (overrides) {
_b = overrides; _b = overrides;
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) { for (key in _b) { if (__hasProp.call(_b, key)) {
val = _b[key]; val = _b[key];
(fresh[key] = val); (fresh[key] = val);
}} }}
@ -65,7 +63,7 @@
helpers.extend = (extend = function extend(object, properties) { helpers.extend = (extend = function extend(object, properties) {
var _a, _b, key, val; var _a, _b, key, val;
_a = []; _b = properties; _a = []; _b = properties;
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) { for (key in _b) { if (__hasProp.call(_b, key)) {
val = _b[key]; val = _b[key];
_a.push((object[key] = val)); _a.push((object[key] = val));
}} }}

View file

@ -1,5 +1,6 @@
(function(){ (function(){
var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, balanced_string, compact, count, helpers, include, starts; var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, _a, _b, _c, _d, balanced_string, compact, count, helpers, include, k, starts, u;
var __arraySlice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt // The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
// matches against the beginning of the source code. When a match is found, // matches against the beginning of the source code. When a match is found,
// a token is produced, we consume the match, and start again. Tokens are in the // a token is produced, we consume the match, and start again. Tokens are in the
@ -236,7 +237,7 @@
// balanced (ie. strings, JS literals). // balanced (ie. strings, JS literals).
Lexer.prototype.balanced_token = function balanced_token() { Lexer.prototype.balanced_token = function balanced_token() {
var delimited; var delimited;
delimited = Array.prototype.slice.call(arguments, 0, arguments.length - 0); delimited = __arraySlice.call(arguments, 0, arguments.length - 0);
return balanced_string(this.chunk, delimited); return balanced_string(this.chunk, delimited);
}; };
// Matches and conumes comments. We pass through comments into JavaScript, // Matches and conumes comments. We pass through comments into JavaScript,
@ -609,7 +610,13 @@
// The list of keywords that are reserved by JavaScript, but not used, or are // The list of keywords that are reserved by JavaScript, but not used, or are
// used by CoffeeScript internally. We throw an error when these are encountered, // used by CoffeeScript internally. We throw an error when these are encountered,
// to avoid having a JavaScript error at runtime. // to avoid having a JavaScript error at runtime.
RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "debugger", "enum", "export", "import", "native", "Coffeescript"]; RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "debugger", "enum", "export", "import", "native"].concat((function() {
_c = []; _d = (u = require('./utilities')).utilities.functions;
for (k in _d) { if (__hasProp.call(_d, k)) {
_c.push(u.utilities.key(k));
}}
return _c;
}).call(this));
// The superset of both JavaScript keywords and reserved words, none of which may // The superset of both JavaScript keywords and reserved words, none of which may
// be used as identifiers or properties. // be used as identifiers or properties.
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);

View file

@ -1,31 +1,26 @@
(function(){ (function(){
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, flatten, helpers, literal, merge, statement; var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, flatten, helpers, literal, merge, statement;
var Coffeescript = { var __extend = function(child, parent) {
extend: function(child, parent) { var ctor = function(){ };
var ctor = function(){ }; ctor.prototype = parent.prototype;
ctor.prototype = parent.prototype; child.__superClass__ = parent.prototype;
child.__superClass__ = parent.prototype; child.prototype = new ctor();
child.prototype = new ctor(); child.prototype.constructor = child;
child.prototype.constructor = child; }, __slice = function(array, from, to, exclusive) {
}, return array.slice.apply(array, __range(array, from, to, exclusive));
slice: function(array, from, to, exclusive) { }, __range = function(array, from, to, exclusive) {
return array.slice.apply(array, Coffeescript.range(array, from, to, exclusive)); return [
}, (from < 0 ? from + array.length : from || 0),
range: function(array, from, to, exclusive) { (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)
return [ ];
(from < 0 ? from + array.length : from || 0), }, __bind = function(func, obj, args) {
(to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1) obj = obj || {};
]; return (typeof args !== 'undefined' && args !== null) ? function() {
}, return func.apply(obj, args.concat(__arraySlice.call(arguments, 0)));
bind: function(func, obj, args) { } : function() {
obj = obj || {}; return func.apply(obj, arguments);
return (typeof args !== 'undefined' && args !== null) ? function() { };
return func.apply(obj, args.concat(Array.prototype.slice.call(arguments, 0))); }, __arraySlice = Array.prototype.slice;
} : function() {
return func.apply(obj, arguments);
};
}
};
// `nodes.coffee` contains all of the node classes for the syntax tree. Most // `nodes.coffee` contains all of the node classes for the syntax tree. Most
// nodes are created as the result of actions in the [grammar](grammar.html), // nodes are created as the result of actions in the [grammar](grammar.html),
// but some are created by other nodes as a method of code generation. To convert // but some are created by other nodes as a method of code generation. To convert
@ -208,7 +203,7 @@
this.children = (this.expressions = compact(flatten(nodes || []))); this.children = (this.expressions = compact(flatten(nodes || [])));
return this; return this;
}; };
Coffeescript.extend(Expressions, BaseNode); __extend(Expressions, BaseNode);
Expressions.prototype.type = 'Expressions'; Expressions.prototype.type = 'Expressions';
// Tack an expression on to the end of this expression list. // Tack an expression on to the end of this expression list.
Expressions.prototype.push = function push(node) { Expressions.prototype.push = function push(node) {
@ -336,7 +331,7 @@
this.value = value; this.value = value;
return this; return this;
}; };
Coffeescript.extend(LiteralNode, BaseNode); __extend(LiteralNode, BaseNode);
LiteralNode.prototype.type = 'Literal'; LiteralNode.prototype.type = 'Literal';
// Break and continue must be treated as pure statements -- they lose their // Break and continue must be treated as pure statements -- they lose their
// meaning when wrapped in a closure. // meaning when wrapped in a closure.
@ -363,7 +358,7 @@
this.children = [(this.expression = expression)]; this.children = [(this.expression = expression)];
return this; return this;
}; };
Coffeescript.extend(ReturnNode, BaseNode); __extend(ReturnNode, BaseNode);
ReturnNode.prototype.type = 'Return'; ReturnNode.prototype.type = 'Return';
ReturnNode.prototype.top_sensitive = function top_sensitive() { ReturnNode.prototype.top_sensitive = function top_sensitive() {
return true; return true;
@ -391,7 +386,7 @@
this.children = flatten([(this.base = base), (this.properties = (properties || []))]); this.children = flatten([(this.base = base), (this.properties = (properties || []))]);
return this; return this;
}; };
Coffeescript.extend(ValueNode, BaseNode); __extend(ValueNode, BaseNode);
ValueNode.prototype.type = 'Value'; ValueNode.prototype.type = 'Value';
ValueNode.prototype.SOAK = " == undefined ? undefined : "; ValueNode.prototype.SOAK = " == undefined ? undefined : ";
// A **ValueNode** has a base and a list of property accesses. // A **ValueNode** has a base and a list of property accesses.
@ -445,7 +440,7 @@
op = del(o, 'operation'); op = del(o, 'operation');
splice = del(o, 'splice'); splice = del(o, 'splice');
replace = del(o, 'replace'); replace = del(o, 'replace');
props = only ? Coffeescript.slice(this.properties, 0, this.properties.length - 1, true) : this.properties; props = only ? __slice(this.properties, 0, this.properties.length - 1, true) : this.properties;
baseline = this.base.compile(o); baseline = this.base.compile(o);
if (this.base instanceof ObjectNode && this.has_properties()) { if (this.base instanceof ObjectNode && this.has_properties()) {
baseline = "(" + baseline + ")"; baseline = "(" + baseline + ")";
@ -498,7 +493,7 @@
this; this;
return this; return this;
}; };
Coffeescript.extend(CommentNode, BaseNode); __extend(CommentNode, BaseNode);
CommentNode.prototype.type = 'Comment'; CommentNode.prototype.type = 'Comment';
CommentNode.prototype.make_return = function make_return() { CommentNode.prototype.make_return = function make_return() {
return this; return this;
@ -518,10 +513,10 @@
this.is_super = variable === 'super'; this.is_super = variable === 'super';
this.variable = this.is_super ? null : variable; this.variable = this.is_super ? null : variable;
this.children = compact(flatten([this.variable, (this.args = (args || []))])); this.children = compact(flatten([this.variable, (this.args = (args || []))]));
this.compile_splat_arguments = Coffeescript.bind(SplatNode.compile_mixed_array, this, [this.args]); this.compile_splat_arguments = __bind(SplatNode.compile_mixed_array, this, [this.args]);
return this; return this;
}; };
Coffeescript.extend(CallNode, BaseNode); __extend(CallNode, BaseNode);
CallNode.prototype.type = 'Call'; CallNode.prototype.type = 'Call';
// Tag this invocation as creating a new instance. // Tag this invocation as creating a new instance.
CallNode.prototype.new_instance = function new_instance() { CallNode.prototype.new_instance = function new_instance() {
@ -588,10 +583,10 @@
exports.CurryNode = (function() { exports.CurryNode = (function() {
CurryNode = function CurryNode(meth, args) { CurryNode = function CurryNode(meth, args) {
this.children = flatten([(this.meth = meth), (this.context = args[0]), (this.args = (args.slice(1) || []))]); this.children = flatten([(this.meth = meth), (this.context = args[0]), (this.args = (args.slice(1) || []))]);
this.compile_splat_arguments = Coffeescript.bind(SplatNode.compile_mixed_array, this, [this.args]); this.compile_splat_arguments = __bind(SplatNode.compile_mixed_array, this, [this.args]);
return this; return this;
}; };
Coffeescript.extend(CurryNode, CallNode); __extend(CurryNode, CallNode);
CurryNode.prototype.type = 'Curry'; CurryNode.prototype.type = 'Curry';
CurryNode.prototype.arguments = function arguments(o) { CurryNode.prototype.arguments = function arguments(o) {
var _a, _b, _c, arg; var _a, _b, _c, arg;
@ -620,7 +615,7 @@
this.children = [(this.child = child), (this.parent = parent)]; this.children = [(this.child = child), (this.parent = parent)];
return this; return this;
}; };
Coffeescript.extend(ExtendsNode, BaseNode); __extend(ExtendsNode, BaseNode);
ExtendsNode.prototype.type = 'Extends'; ExtendsNode.prototype.type = 'Extends';
// Hooks one constructor into another's prototype chain. // Hooks one constructor into another's prototype chain.
ExtendsNode.prototype.compile_node = function compile_node(o) { ExtendsNode.prototype.compile_node = function compile_node(o) {
@ -641,7 +636,7 @@
this; this;
return this; return this;
}; };
Coffeescript.extend(AccessorNode, BaseNode); __extend(AccessorNode, BaseNode);
AccessorNode.prototype.type = 'Accessor'; AccessorNode.prototype.type = 'Accessor';
AccessorNode.prototype.compile_node = function compile_node(o) { AccessorNode.prototype.compile_node = function compile_node(o) {
var proto_part; var proto_part;
@ -658,7 +653,7 @@
this.soak_node = tag === 'soak'; this.soak_node = tag === 'soak';
return this; return this;
}; };
Coffeescript.extend(IndexNode, BaseNode); __extend(IndexNode, BaseNode);
IndexNode.prototype.type = 'Index'; IndexNode.prototype.type = 'Index';
IndexNode.prototype.compile_node = function compile_node(o) { IndexNode.prototype.compile_node = function compile_node(o) {
var idx; var idx;
@ -677,7 +672,7 @@
this.exclusive = !!exclusive; this.exclusive = !!exclusive;
return this; return this;
}; };
Coffeescript.extend(RangeNode, BaseNode); __extend(RangeNode, BaseNode);
RangeNode.prototype.type = 'Range'; RangeNode.prototype.type = 'Range';
// Compiles the range's source variables -- where it starts and where it ends. // Compiles the range's source variables -- where it starts and where it ends.
RangeNode.prototype.compile_variables = function compile_variables(o) { RangeNode.prototype.compile_variables = function compile_variables(o) {
@ -733,7 +728,7 @@
this; this;
return this; return this;
}; };
Coffeescript.extend(SliceNode, BaseNode); __extend(SliceNode, BaseNode);
SliceNode.prototype.type = 'Slice'; SliceNode.prototype.type = 'Slice';
SliceNode.prototype.compile_node = function compile_node(o) { SliceNode.prototype.compile_node = function compile_node(o) {
var from, plus_part, to; var from, plus_part, to;
@ -772,7 +767,7 @@
this.children = (this.objects = (this.properties = props || [])); this.children = (this.objects = (this.properties = props || []));
return this; return this;
}; };
Coffeescript.extend(ObjectNode, BaseNode); __extend(ObjectNode, BaseNode);
ObjectNode.prototype.type = 'Object'; ObjectNode.prototype.type = 'Object';
// All the mucking about with commas is to make sure that CommentNodes and // All the mucking about with commas is to make sure that CommentNodes and
// AssignNodes get interleaved correctly, with no trailing commas or // AssignNodes get interleaved correctly, with no trailing commas or
@ -819,10 +814,10 @@
exports.ArrayNode = (function() { exports.ArrayNode = (function() {
ArrayNode = function ArrayNode(objects) { ArrayNode = function ArrayNode(objects) {
this.children = (this.objects = objects || []); this.children = (this.objects = objects || []);
this.compile_splat_literal = Coffeescript.bind(SplatNode.compile_mixed_array, this, [this.objects]); this.compile_splat_literal = __bind(SplatNode.compile_mixed_array, this, [this.objects]);
return this; return this;
}; };
Coffeescript.extend(ArrayNode, BaseNode); __extend(ArrayNode, BaseNode);
ArrayNode.prototype.type = 'Array'; ArrayNode.prototype.type = 'Array';
ArrayNode.prototype.compile_node = function compile_node(o) { ArrayNode.prototype.compile_node = function compile_node(o) {
var _a, _b, code, ending, i, obj, objects; var _a, _b, code, ending, i, obj, objects;
@ -856,7 +851,7 @@
this.returns = false; this.returns = false;
return this; return this;
}; };
Coffeescript.extend(ClassNode, BaseNode); __extend(ClassNode, BaseNode);
ClassNode.prototype.type = 'Class'; ClassNode.prototype.type = 'Class';
// Initialize a **ClassNode** with its name, an optional superclass, and a // Initialize a **ClassNode** with its name, an optional superclass, and a
// list of prototype property assignments. // list of prototype property assignments.
@ -916,7 +911,7 @@
this.context = context; this.context = context;
return this; return this;
}; };
Coffeescript.extend(AssignNode, BaseNode); __extend(AssignNode, BaseNode);
AssignNode.prototype.type = 'Assign'; AssignNode.prototype.type = 'Assign';
// Matchers for detecting prototype assignments. // Matchers for detecting prototype assignments.
AssignNode.prototype.PROTO_ASSIGN = /^(\S+)\.prototype/; AssignNode.prototype.PROTO_ASSIGN = /^(\S+)\.prototype/;
@ -1034,7 +1029,7 @@
this.bound = tag === 'boundfunc'; this.bound = tag === 'boundfunc';
return this; return this;
}; };
Coffeescript.extend(CodeNode, BaseNode); __extend(CodeNode, BaseNode);
CodeNode.prototype.type = 'Code'; CodeNode.prototype.type = 'Code';
// Compilation creates a new scope unless explicitly asked to share with the // Compilation creates a new scope unless explicitly asked to share with the
// outer scope. Handles splat parameters in the parameter list by peeking at // outer scope. Handles splat parameters in the parameter list by peeking at
@ -1139,7 +1134,7 @@
this.children = [(this.name = name)]; this.children = [(this.name = name)];
return this; return this;
}; };
Coffeescript.extend(SplatNode, BaseNode); __extend(SplatNode, BaseNode);
SplatNode.prototype.type = 'Splat'; SplatNode.prototype.type = 'Splat';
SplatNode.prototype.compile_node = function compile_node(o) { SplatNode.prototype.compile_node = function compile_node(o) {
var _a; var _a;
@ -1162,15 +1157,15 @@
o.scope.assign(trailing.compile(o), "arguments[arguments.length - " + this.trailings.length + " + " + i + "]"); o.scope.assign(trailing.compile(o), "arguments[arguments.length - " + this.trailings.length + " + " + i + "]");
i += 1; i += 1;
} }
return "" + name + " = Array.prototype.slice.call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")"; return "" + name + " = " + (o.scope.utility('arraySlice')) + ".call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")";
}; };
// A compiling a splat as a destructuring assignment means slicing arguments // A compiling a splat as a destructuring assignment means slicing arguments
// from the right-hand-side's corresponding array. // from the right-hand-side's corresponding array.
SplatNode.prototype.compile_value = function compile_value(o, name, index, trailings) { SplatNode.prototype.compile_value = function compile_value(o, name, index, trailings) {
if ((typeof trailings !== "undefined" && trailings !== null)) { if ((typeof trailings !== "undefined" && trailings !== null)) {
return "Array.prototype.slice.call(" + name + ", " + index + ", " + (name) + ".length - " + trailings + ")"; return "" + (o.scope.utility('arraySlice')) + ".call(" + name + ", " + index + ", " + (name) + ".length - " + trailings + ")";
} else { } else {
return "Array.prototype.slice.call(" + name + ", " + index + ")"; return "" + (o.scope.utility('arraySlice')) + ".call(" + name + ", " + index + ")";
} }
}; };
// Utility function that converts arbitrary number of elements, mixed with // Utility function that converts arbitrary number of elements, mixed with
@ -1212,7 +1207,7 @@
this.filter = opts && opts.filter; this.filter = opts && opts.filter;
return this; return this;
}; };
Coffeescript.extend(WhileNode, BaseNode); __extend(WhileNode, BaseNode);
WhileNode.prototype.type = 'While'; WhileNode.prototype.type = 'While';
WhileNode.prototype.add_body = function add_body(body) { WhileNode.prototype.add_body = function add_body(body) {
this.children.push((this.body = body)); this.children.push((this.body = body));
@ -1268,7 +1263,7 @@
this.flip = !!flip; this.flip = !!flip;
return this; return this;
}; };
Coffeescript.extend(OpNode, BaseNode); __extend(OpNode, BaseNode);
OpNode.prototype.type = 'Op'; OpNode.prototype.type = 'Op';
// The map of conversions from CoffeeScript to JavaScript symbols. // The map of conversions from CoffeeScript to JavaScript symbols.
OpNode.prototype.CONVERSIONS = { OpNode.prototype.CONVERSIONS = {
@ -1369,7 +1364,7 @@
this; this;
return this; return this;
}; };
Coffeescript.extend(TryNode, BaseNode); __extend(TryNode, BaseNode);
TryNode.prototype.type = 'Try'; TryNode.prototype.type = 'Try';
TryNode.prototype.make_return = function make_return() { TryNode.prototype.make_return = function make_return() {
if (this.attempt) { if (this.attempt) {
@ -1402,7 +1397,7 @@
this.children = [(this.expression = expression)]; this.children = [(this.expression = expression)];
return this; return this;
}; };
Coffeescript.extend(ThrowNode, BaseNode); __extend(ThrowNode, BaseNode);
ThrowNode.prototype.type = 'Throw'; ThrowNode.prototype.type = 'Throw';
// A **ThrowNode** is already a return, of sorts... // A **ThrowNode** is already a return, of sorts...
ThrowNode.prototype.make_return = function make_return() { ThrowNode.prototype.make_return = function make_return() {
@ -1423,7 +1418,7 @@
this.children = [(this.expression = expression)]; this.children = [(this.expression = expression)];
return this; return this;
}; };
Coffeescript.extend(ExistenceNode, BaseNode); __extend(ExistenceNode, BaseNode);
ExistenceNode.prototype.type = 'Existence'; ExistenceNode.prototype.type = 'Existence';
ExistenceNode.prototype.compile_node = function compile_node(o) { ExistenceNode.prototype.compile_node = function compile_node(o) {
return ExistenceNode.compile_test(o, this.expression); return ExistenceNode.compile_test(o, this.expression);
@ -1458,7 +1453,7 @@
this.children = [(this.expression = expression)]; this.children = [(this.expression = expression)];
return this; return this;
}; };
Coffeescript.extend(ParentheticalNode, BaseNode); __extend(ParentheticalNode, BaseNode);
ParentheticalNode.prototype.type = 'Paren'; ParentheticalNode.prototype.type = 'Paren';
ParentheticalNode.prototype.is_statement = function is_statement() { ParentheticalNode.prototype.is_statement = function is_statement() {
return this.expression.is_statement(); return this.expression.is_statement();
@ -1510,7 +1505,7 @@
this.returns = false; this.returns = false;
return this; return this;
}; };
Coffeescript.extend(ForNode, BaseNode); __extend(ForNode, BaseNode);
ForNode.prototype.type = 'For'; ForNode.prototype.type = 'For';
ForNode.prototype.top_sensitive = function top_sensitive() { ForNode.prototype.top_sensitive = function top_sensitive() {
return true; return true;
@ -1614,7 +1609,7 @@
} }
return this; return this;
}; };
Coffeescript.extend(IfNode, BaseNode); __extend(IfNode, BaseNode);
IfNode.prototype.type = 'If'; IfNode.prototype.type = 'If';
// Add a new *else* clause to this **IfNode**, or push it down to the bottom // Add a new *else* clause to this **IfNode**, or push it down to the bottom
// of the chain recursively. // of the chain recursively.

View file

@ -1,16 +1,13 @@
(function(){ (function(){
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, helpers, include, pair; var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, helpers, include, pair;
var Coffeescript = { var __bind = function(func, obj, args) {
bind: function(func, obj, args) { obj = obj || {};
obj = obj || {}; return (typeof args !== 'undefined' && args !== null) ? function() {
return (typeof args !== 'undefined' && args !== null) ? function() { return func.apply(obj, args.concat(__arraySlice.call(arguments, 0)));
return func.apply(obj, args.concat(Array.prototype.slice.call(arguments, 0))); } : function() {
} : function() { return func.apply(obj, arguments);
return func.apply(obj, arguments); };
}; }, __arraySlice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
},
hasProp: Object.prototype.hasOwnProperty
};
// The CoffeeScript language has a good deal of optional syntax, implicit syntax, // The CoffeeScript language has a good deal of optional syntax, implicit syntax,
// and shorthand syntax. This can greatly complicate a grammar and bloat // and shorthand syntax. This can greatly complicate a grammar and bloat
// the resulting parse table. Instead of making the parser handle it all, we take // the resulting parse table. Instead of making the parser handle it all, we take
@ -67,7 +64,7 @@
// Massage newlines and indentations so that comments don't have to be // Massage newlines and indentations so that comments don't have to be
// correctly indented, or appear on a line of their own. // correctly indented, or appear on a line of their own.
Rewriter.prototype.adjust_comments = function adjust_comments() { Rewriter.prototype.adjust_comments = function adjust_comments() {
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var after; var after;
if (!(token[0] === 'COMMENT')) { if (!(token[0] === 'COMMENT')) {
return 1; return 1;
@ -98,7 +95,7 @@
// Some blocks occur in the middle of expressions -- when we're expecting // Some blocks occur in the middle of expressions -- when we're expecting
// this, remove their trailing newlines. // this, remove their trailing newlines.
Rewriter.prototype.remove_mid_expression_newlines = function remove_mid_expression_newlines() { Rewriter.prototype.remove_mid_expression_newlines = function remove_mid_expression_newlines() {
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
if (!(post && include(EXPRESSION_CLOSE, post[0]) && token[0] === 'TERMINATOR')) { if (!(post && include(EXPRESSION_CLOSE, post[0]) && token[0] === 'TERMINATOR')) {
return 1; return 1;
} }
@ -113,7 +110,7 @@
var brackets, parens; var brackets, parens;
parens = [0]; parens = [0];
brackets = [0]; brackets = [0];
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var _a; var _a;
if ((_a = token[0]) === 'CALL_START') { if ((_a = token[0]) === 'CALL_START') {
parens.push(0); parens.push(0);
@ -149,7 +146,7 @@
stack = [0]; stack = [0];
calls = 0; calls = 0;
parens = 0; parens = 0;
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var _a, _b, _c, idx, last, open, size, stack_pointer, tag, tmp; var _a, _b, _c, idx, last, open, size, stack_pointer, tag, tmp;
tag = token[0]; tag = token[0];
if (tag === 'CALL_START') { if (tag === 'CALL_START') {
@ -200,7 +197,7 @@
// blocks, so it doesn't need to. ')' can close a single-line block, // blocks, so it doesn't need to. ')' can close a single-line block,
// but we need to make sure it's balanced. // but we need to make sure it's balanced.
Rewriter.prototype.add_implicit_indentation = function add_implicit_indentation() { Rewriter.prototype.add_implicit_indentation = function add_implicit_indentation() {
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var idx, insertion, outdent, parens, pre, starter, tok; var idx, insertion, outdent, parens, pre, starter, tok;
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) { if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
return 1; return 1;
@ -240,7 +237,7 @@
var _a, _b, key, levels, line, open, open_line, unclosed, value; var _a, _b, key, levels, line, open, open_line, unclosed, value;
levels = {}; levels = {};
open_line = {}; open_line = {};
this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { this.scan_tokens(__bind(function(prev, token, post, i) {
var _a, _b, _c, _d, close, open, pair; var _a, _b, _c, _d, close, open, pair;
_b = pairs; _b = pairs;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_a = 0, _c = _b.length; _a < _c; _a++) {
@ -266,7 +263,7 @@
}, this)); }, this));
unclosed = (function() { unclosed = (function() {
_a = []; _b = levels; _a = []; _b = levels;
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) { for (key in _b) { if (__hasProp.call(_b, key)) {
value = _b[key]; value = _b[key];
value > 0 ? _a.push(key) : null; value > 0 ? _a.push(key) : null;
}} }}
@ -294,11 +291,11 @@
stack = []; stack = [];
debt = {}; debt = {};
_a = INVERSES; _a = INVERSES;
for (key in _a) { if (Coffeescript.hasProp.call(_a, key)) { for (key in _a) { if (__hasProp.call(_a, key)) {
val = _a[key]; val = _a[key];
(debt[key] = 0); (debt[key] = 0);
}} }}
return this.scan_tokens(Coffeescript.bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var inv, match, mtag, tag; var inv, match, mtag, tag;
tag = token[0]; tag = token[0];
inv = INVERSES[token[0]]; inv = INVERSES[token[0]];

View file

@ -1,8 +1,6 @@
(function(){ (function(){
var Scope, utilities; var Scope, utilities;
var Coffeescript = { var __hasProp = Object.prototype.hasOwnProperty;
hasProp: Object.prototype.hasOwnProperty
};
// The **Scope** class regulates lexical scoping within CoffeeScript. As you // 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 // 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, // function bodies. Each scope knows about the variables declared within it,
@ -50,7 +48,7 @@
Scope.prototype.any = function any(fn) { Scope.prototype.any = function any(fn) {
var _a, k, v; var _a, k, v;
_a = this.variables; _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]; k = _a[v];
if (fn(v, k)) { if (fn(v, k)) {
return true; return true;
@ -110,21 +108,18 @@
!this.utilities[dep] ? this.utility(dep) : null; !this.utilities[dep] ? this.utility(dep) : null;
} }
} }
return "" + (utilities.key) + "." + name; return "" + (utilities.key(name));
}; };
// Formats an javascript object containing the utility methods required // Formats an javascript object containing the utility methods required
// in the scope // in the scope
Scope.prototype.included_utilities = function included_utilities(tab) { 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)) { if ((typeof (_c = this.utilities) !== "undefined" && _c !== null)) {
props = (function() { _a = []; _b = this.utilities;
_a = []; _b = this.utilities; for (key in _b) { if (__hasProp.call(_b, key)) {
for (key in _b) { if (Coffeescript.hasProp.call(_b, key)) { _a.push(utilities.format(key, tab));
_a.push(utilities.format(key, tab)); }}
}} return _a;
return _a;
}).call(this);
return ["" + (utilities.key) + " = {" + (props.join(', ')) + "\n" + tab + "}"];
} else { } else {
return []; return [];
} }
@ -149,7 +144,7 @@
var _a, _b, key, val; var _a, _b, key, val;
return (function() { return (function() {
_a = []; _b = this.variables; _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 = _b[key];
val === 'var' ? _a.push(key) : null; val === 'var' ? _a.push(key) : null;
}} }}
@ -161,7 +156,7 @@
Scope.prototype.assigned_variables = function assigned_variables() { Scope.prototype.assigned_variables = function assigned_variables() {
var _a, _b, key, val; var _a, _b, key, val;
_a = []; _b = this.variables; _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 = _b[key];
val.assigned ? _a.push("" + key + " = " + (val.value)) : null; val.assigned ? _a.push("" + key + " = " + (val.value)) : null;
}} }}

View file

@ -1,26 +1,29 @@
(function(){ (function(){
var KEY, utilities; var utilities;
if (!((typeof process !== "undefined" && process !== null))) { if (!((typeof process !== "undefined" && process !== null))) {
this.exports = this; this.exports = this;
} }
KEY = "Coffeescript";
exports.utilities = (function() { exports.utilities = (function() {
utilities = function utilities() { }; utilities = function utilities() { };
utilities.key = KEY; utilities.key = function key(name) {
return "__" + name;
};
utilities.format = function format(key, tab) { utilities.format = function format(key, tab) {
return "\n " + tab + key + ": " + (utilities.functions[key].replace(/\n/g, "\n" + tab + " ") || 'undefined'); return "" + (utilities.key(key)) + " = " + (utilities.functions[key].replace(/\n/g, "\n" + tab) || 'undefined');
}; };
utilities.dependencies = { utilities.dependencies = {
slice: ['range'], slice: ['range'],
splice: ['range'] splice: ['range'],
bind: ['arraySlice']
}; };
utilities.functions = { utilities.functions = {
extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}", extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}",
bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(Array.prototype.slice.call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}", bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('arraySlice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}",
range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}", range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}",
slice: "function(array, from, to, exclusive) {\n return array.slice.apply(array, " + (KEY) + ".range(array, from, to, exclusive));\n}", slice: "function(array, from, to, exclusive) {\n return array.slice.apply(array, " + (utilities.key('range')) + "(array, from, to, exclusive));\n}",
splice: "function(array, from, to, exclusive, replace) {\n return array.splice.apply(array, [(_a = " + (KEY) + ".range(array, from, to, exclusive))[0], \n _a[1] - _a[0]].concat(replace));\n}", splice: "function(array, from, to, exclusive, replace) {\n return array.splice.apply(array, [(_a = " + (utilities.key('range')) + "(array, from, to, exclusive))[0], \n _a[1] - _a[0]].concat(replace));\n}",
hasProp: "Object.prototype.hasOwnProperty" hasProp: 'Object.prototype.hasOwnProperty',
arraySlice: 'Array.prototype.slice'
}; };
return utilities; return utilities;
}).call(this); }).call(this);

View file

@ -464,7 +464,7 @@ KEYWORDS: JS_KEYWORDS.concat COFFEE_KEYWORDS
RESERVED: [ RESERVED: [
"case", "default", "do", "function", "var", "void", "with" "case", "default", "do", "function", "var", "void", "with"
"const", "let", "debugger", "enum", "export", "import", "native", "const", "let", "debugger", "enum", "export", "import", "native",
"Coffeescript" (u.utilities.key(k) for k of (u: require './utilities').utilities.functions)...
] ]
# The superset of both JavaScript keywords and reserved words, none of which may # The superset of both JavaScript keywords and reserved words, none of which may

View file

@ -843,13 +843,13 @@ exports.SplatNode: class SplatNode extends BaseNode
for trailing in @trailings for trailing in @trailings
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]") o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
i: + 1 i: + 1
"$name = Array.prototype.slice.call(arguments, $@index, arguments.length - ${@trailings.length})" "$name = ${o.scope.utility('arraySlice')}.call(arguments, $@index, arguments.length - ${@trailings.length})"
# A compiling a splat as a destructuring assignment means slicing arguments # A compiling a splat as a destructuring assignment means slicing arguments
# from the right-hand-side's corresponding array. # from the right-hand-side's corresponding array.
compile_value: (o, name, index, trailings) -> compile_value: (o, name, index, trailings) ->
if trailings? then "Array.prototype.slice.call($name, $index, ${name}.length - $trailings)" \ if trailings? then "${o.scope.utility('arraySlice')}.call($name, $index, ${name}.length - $trailings)" \
else "Array.prototype.slice.call($name, $index)" else "${o.scope.utility('arraySlice')}.call($name, $index)"
# Utility function that converts arbitrary number of elements, mixed with # Utility function that converts arbitrary number of elements, mixed with
# splats, to a proper array # splats, to a proper array

View file

@ -70,14 +70,13 @@ exports.Scope: class Scope
@utilities: or {} @utilities: or {}
@utilities[name]: utilities.functions[name] @utilities[name]: utilities.functions[name]
@utility(dep) for dep in (utilities.dependencies[name] or []) when not @utilities[dep] @utility(dep) for dep in (utilities.dependencies[name] or []) when not @utilities[dep]
"${utilities.key}.$name" "${utilities.key(name)}"
# Formats an javascript object containing the utility methods required # Formats an javascript object containing the utility methods required
# in the scope # in the scope
included_utilities: (tab) -> included_utilities: (tab) ->
if @utilities? if @utilities?
props: (utilities.format(key, tab) for key of @utilities) utilities.format(key, tab) for key of @utilities
["${utilities.key} = {${props.join(', ')}\n$tab}"]
else [] else []
# Does this scope reference any variables that need to be declared in the # Does this scope reference any variables that need to be declared in the

View file

@ -1,14 +1,16 @@
this.exports: this unless process? this.exports: this unless process?
KEY: "Coffeescript"
exports.utilities: class utilities exports.utilities: class utilities
@key: KEY @key: (name) ->
"__$name"
@format: (key, tab) -> @format: (key, tab) ->
"\n $tab$key: ${utilities.functions[key].replace(/\n/g, "\n$tab ") or 'undefined'}" "${utilities.key(key)} = ${utilities.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}"
@dependencies: { @dependencies: {
slice: ['range'] slice: ['range']
splice: ['range'] splice: ['range']
bind: ['arraySlice']
} }
@functions: { @functions: {
@ -25,7 +27,7 @@ exports.utilities: class utilities
function(func, obj, args) { function(func, obj, args) {
obj = obj || {}; obj = obj || {};
return (typeof args !== 'undefined' && args !== null) ? function() { return (typeof args !== 'undefined' && args !== null) ? function() {
return func.apply(obj, args.concat(Array.prototype.slice.call(arguments, 0))); return func.apply(obj, args.concat(${utilities.key('arraySlice')}.call(arguments, 0)));
} : function() { } : function() {
return func.apply(obj, arguments); return func.apply(obj, arguments);
}; };
@ -41,14 +43,15 @@ exports.utilities: class utilities
""" """
slice: """ slice: """
function(array, from, to, exclusive) { function(array, from, to, exclusive) {
return array.slice.apply(array, ${KEY}.range(array, from, to, exclusive)); return array.slice.apply(array, ${utilities.key('range')}(array, from, to, exclusive));
} }
""" """
splice: """ splice: """
function(array, from, to, exclusive, replace) { function(array, from, to, exclusive, replace) {
return array.splice.apply(array, [(_a = ${KEY}.range(array, from, to, exclusive))[0], return array.splice.apply(array, [(_a = ${utilities.key('range')}(array, from, to, exclusive))[0],
_a[1] - _a[0]].concat(replace)); _a[1] - _a[0]].concat(replace));
} }
""" """
hasProp: "Object.prototype.hasOwnProperty" hasProp: 'Object.prototype.hasOwnProperty'
arraySlice: 'Array.prototype.slice'
} }