mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 11:01:25 -05:00
self-compiler handles throws, the existential operator, and parentheticals.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function(){
|
||||
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, Expressions, ExtendsNode, IDENTIFIER, IndexNode, LiteralNode, Node, ObjectNode, OpNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, TryNode, ValueNode, WhileNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, IDENTIFIER, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
process.mixin(require('./scope'));
|
||||
// The abstract base class for all CoffeeScript nodes.
|
||||
@@ -1134,4 +1134,53 @@
|
||||
}
|
||||
}));
|
||||
statement(TryNode);
|
||||
// Throw an exception.
|
||||
ThrowNode = (exports.ThrowNode = inherit(Node, {
|
||||
constructor: function constructor(expression) {
|
||||
this.children = [(this.expression = expression)];
|
||||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
return this.idt() + 'throw ' + this.expression.compile(o) + ';';
|
||||
}
|
||||
}));
|
||||
statement(ThrowNode, true);
|
||||
// Check an expression for existence (meaning not null or undefined).
|
||||
ExistenceNode = (exports.ExistenceNode = inherit(Node, {
|
||||
constructor: function constructor(expression) {
|
||||
this.children = [(this.expression = expression)];
|
||||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
return ExistenceNode.compile_test(o, this.expression);
|
||||
}
|
||||
}));
|
||||
ExistenceNode.compile_test = function compile_test(o, variable) {
|
||||
var __a, __b, first, second;
|
||||
__a = [variable, variable];
|
||||
first = __a[0];
|
||||
second = __a[1];
|
||||
if (variable instanceof CallNode) {
|
||||
__b = variable.compile_reference(o);
|
||||
first = __b[0];
|
||||
second = __b[1];
|
||||
}
|
||||
return '(typeof ' + first.compile(o) + ' !== "undefined" && ' + second.compile(o) + ' !== null)';
|
||||
};
|
||||
// An extra set of parentheses, specified explicitly in the source.
|
||||
ParentheticalNode = (exports.ParentheticalNode = inherit(Node, {
|
||||
constructor: function constructor(expressions) {
|
||||
this.children = [(this.expressions = expressions)];
|
||||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var code, l;
|
||||
code = this.expressions.compile(o);
|
||||
l = code.length;
|
||||
if (code.substr(l - 1, 1) === ';') {
|
||||
code = code.substr(o, l - 1);
|
||||
}
|
||||
return '(' + code + ')';
|
||||
}
|
||||
}));
|
||||
})();
|
||||
Reference in New Issue
Block a user