The moment of truth: CoffeeScript has now compiled itself ten times over.

This commit is contained in:
Jeremy Ashkenas 2010-02-13 01:13:08 -05:00
parent 126f6c2d88
commit b965fcf32d
6 changed files with 24 additions and 35 deletions

View File

@ -27,8 +27,7 @@
exports.compile = function compile(script, source) {
var options;
source = source || 'error';
options = {
};
options = {};
if (this.options.no_wrap) {
options.no_wrap = true;
}
@ -94,8 +93,7 @@
// Use OptionParser for all the options.
exports.parse_options = function parse_options() {
var oparser, opts, paths;
opts = (this.options = {
});
opts = (this.options = {});
oparser = (this.option_parser = new optparse.OptionParser(SWITCHES));
oparser.add = oparser['on'];
oparser.add('interactive', function() {

View File

@ -519,8 +519,7 @@
};
// Helpers ==============================================================
// Make the Jison parser.
bnf = {
};
bnf = {};
tokens = [];
__a = grammar;
for (name in __a) {

View File

@ -5,7 +5,7 @@
// Some helper functions
// Tabs are two spaces for pretty printing.
TAB = ' ';
TRAILING_WHITESPACE = /\s+$/g;
TRAILING_WHITESPACE = /\s+$/gm;
// Keep the identifier regex in sync with the Lexer.
IDENTIFIER = /^[a-zA-Z$_](\w|\$)*$/;
// Flatten nested arrays recursively.
@ -46,8 +46,7 @@
}
return __a;
} else {
output = {
};
output = {};
__d = input;
for (key in __d) {
val = __d[key];
@ -61,8 +60,7 @@
// Merge objects.
merge = function merge(src, dest) {
var __a, __b, fresh, key, val;
fresh = {
};
fresh = {};
__a = src;
for (key in __a) {
val = __a[key];
@ -144,8 +142,7 @@
// already been asked to return the result.
Node.prototype.compile = function compile(o) {
var closure, top;
this.options = dup(o || {
});
this.options = dup(o || {});
this.indent = o.indent;
top = this.top_sensitive() ? this.options.top : del(this.options, 'top');
closure = this.is_statement() && !this.is_statement_only() && !top && !this.options.returns && !(this instanceof CommentNode) && !this.contains(function(node) {
@ -245,8 +242,7 @@
return node === this.expressions[l - last_index];
},
compile: function compile(o) {
o = o || {
};
o = o || {};
return o.scope ? Node.prototype.compile.call(this, o) : this.compile_root(o);
},
// Compile each expression in the Expressions body.
@ -525,11 +521,11 @@
},
// Hooking one constructor into another's prototype chain.
compile_node: function compile_node(o) {
var child, constructor, parent;
constructor = o.scope.free_variable();
var child, construct, parent;
construct = o.scope.free_variable();
child = this.child.compile(o);
parent = this.parent.compile(o);
return this.idt() + constructor + ' = function(){};\n' + this.idt() + constructor + '.prototype = ' + parent + ".prototype;\n" + this.idt() + child + '.__superClass__ = ' + parent + ".prototype;\n" + this.idt() + child + '.prototype = new ' + constructor + "();\n" + this.idt() + child + '.prototype.constructor = ' + child + ';';
return this.idt() + construct + ' = function(){};\n' + this.idt() + construct + '.prototype = ' + parent + ".prototype;\n" + this.idt() + child + '.__superClass__ = ' + parent + ".prototype;\n" + this.idt() + child + '.prototype = new ' + construct + "();\n" + this.idt() + child + '.prototype.constructor = ' + child + ';';
}
}));
statement(ExtendsNode);
@ -1215,8 +1211,7 @@
this.body = body && body.unwrap();
this.else_body = else_body && else_body.unwrap();
this.children = compact([this.condition, this.body, this.else_body]);
this.tags = tags || {
};
this.tags = tags || {};
if (this.condition instanceof Array) {
this.multiple = true;
}

View File

@ -32,8 +32,7 @@
IMPLICIT_END = ['IF', 'UNLESS', 'FOR', 'WHILE', 'TERMINATOR', 'OUTDENT'];
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', '@', '->', '=>', '[', '(', '{'];
// The inverse mappings of token pairs we're trying to fix up.
INVERSES = {
};
INVERSES = {};
__g = BALANCED_PAIRS;
for (__h = 0; __h < __g.length; __h++) {
pair = __g[__h];
@ -266,8 +265,7 @@
// the course of the token stream.
re.prototype.ensure_balance = function ensure_balance(pairs) {
var __i, __j, key, levels, unclosed, value;
levels = {
};
levels = {};
this.scan_tokens((function(__this) {
var __func = function(prev, token, post, i) {
var __i, __j, __k, close, open;
@ -322,11 +320,11 @@
// it with the inverse of what we've just popped.
// 3. Keep track of "debt" for tokens that we fake, to make sure we end
// up balanced in the end.
//
re.prototype.rewrite_closing_parens = function rewrite_closing_parens() {
var __i, debt, key, stack, val;
stack = [];
debt = {
};
debt = {};
__i = INVERSES;
for (key in __i) {
val = __i[key];

View File

@ -12,8 +12,7 @@
this.parent = parent;
this.expressions = expressions;
this.method = method;
this.variables = {
};
this.variables = {};
this.temp_variable = this.parent ? this.parent.temp_variable : '__a';
return this;
});

View File

@ -4,7 +4,7 @@ process.mixin require './scope'
# Tabs are two spaces for pretty printing.
TAB: ' '
TRAILING_WHITESPACE: /\s+$/g
TRAILING_WHITESPACE: /\s+$/gm
# Keep the identifier regex in sync with the Lexer.
IDENTIFIER: /^[a-zA-Z$_](\w|\$)*$/
@ -382,13 +382,13 @@ ExtendsNode: exports.ExtendsNode: inherit Node, {
# Hooking one constructor into another's prototype chain.
compile_node: (o) ->
constructor: o.scope.free_variable()
child: @child.compile(o)
parent: @parent.compile(o)
@idt() + constructor + ' = function(){};\n' + @idt() +
constructor + '.prototype = ' + parent + ".prototype;\n" + @idt() +
construct: o.scope.free_variable()
child: @child.compile(o)
parent: @parent.compile(o)
@idt() + construct + ' = function(){};\n' + @idt() +
construct + '.prototype = ' + parent + ".prototype;\n" + @idt() +
child + '.__superClass__ = ' + parent + ".prototype;\n" + @idt() +
child + '.prototype = new ' + constructor + "();\n" + @idt() +
child + '.prototype = new ' + construct + "();\n" + @idt() +
child + '.prototype.constructor = ' + child + ';'
}