mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
self-compiler: handles try/catch/finally blocks
This commit is contained in:
@@ -805,7 +805,25 @@ OpNode: exports.OpNode: inherit Node, {
|
||||
|
||||
}
|
||||
|
||||
|
||||
# A try/catch/finally block.
|
||||
TryNode: exports.TryNode: inherit Node, {
|
||||
|
||||
constructor: (attempt, error, recovery, ensure) ->
|
||||
@children: [@attempt: attempt, @recovery: recovery, @ensure: ensure]
|
||||
@error: error
|
||||
this
|
||||
|
||||
compile_node: (o) ->
|
||||
o.indent: @idt(1)
|
||||
o.top: true
|
||||
error_part: if @error then ' (' + @error.compile(o) + ') ' else ' '
|
||||
catch_part: (@recovery or '') and ' catch' + error_part + '{\n' + @recovery.compile(o) + '\n' + @idt() + '}'
|
||||
finally_part: (@ensure or '') and ' finally {\n' + @ensure.compile(merge(o, {returns: null})) + '\n' + @idt() + '}'
|
||||
@idt() + 'try {\n' + @attempt.compile(o) + '\n' + @idt() + '}' + catch_part + finally_part
|
||||
|
||||
}
|
||||
|
||||
statement TryNode
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user