mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 11:01:25 -05:00
self-compiler: handles try/catch/finally blocks
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, ValueNode, WhileNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
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 __hasProp = Object.prototype.hasOwnProperty;
|
||||
process.mixin(require('./scope'));
|
||||
// The abstract base class for all CoffeeScript nodes.
|
||||
@@ -1114,4 +1114,24 @@
|
||||
return parts.join('');
|
||||
}
|
||||
}));
|
||||
// A try/catch/finally block.
|
||||
TryNode = (exports.TryNode = inherit(Node, {
|
||||
constructor: function constructor(attempt, error, recovery, ensure) {
|
||||
this.children = [(this.attempt = attempt), (this.recovery = recovery), (this.ensure = ensure)];
|
||||
this.error = error;
|
||||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var catch_part, error_part, finally_part;
|
||||
o.indent = this.idt(1);
|
||||
o.top = true;
|
||||
error_part = this.error ? ' (' + this.error.compile(o) + ') ' : ' ';
|
||||
catch_part = (this.recovery || '') && ' catch' + error_part + '{\n' + this.recovery.compile(o) + '\n' + this.idt() + '}';
|
||||
finally_part = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o, {
|
||||
returns: null
|
||||
})) + '\n' + this.idt() + '}';
|
||||
return this.idt() + 'try {\n' + this.attempt.compile(o) + '\n' + this.idt() + '}' + catch_part + finally_part;
|
||||
}
|
||||
}));
|
||||
statement(TryNode);
|
||||
})();
|
||||
Reference in New Issue
Block a user