mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
added Stan's fix for try/finally without catch
This commit is contained in:
@@ -1195,7 +1195,7 @@ idt += TAB
|
|||||||
o.top = true;
|
o.top = true;
|
||||||
attempt_part = this.attempt.compile(o);
|
attempt_part = this.attempt.compile(o);
|
||||||
error_part = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
error_part = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
||||||
catch_part = '' + ((this.recovery || '') && ' catch') + error_part + "{\n" + (this.recovery.compile(o)) + "\n" + this.tab + "}";
|
catch_part = this.recovery ? " catch" + error_part + "{\n" + (this.recovery.compile(o)) + "\n" + this.tab + "}" : '';
|
||||||
finally_part = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o, {
|
finally_part = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o, {
|
||||||
returns: null
|
returns: null
|
||||||
})) + "\n" + this.tab + "}";
|
})) + "\n" + this.tab + "}";
|
||||||
|
|||||||
@@ -905,7 +905,7 @@ exports.TryNode: class TryNode extends BaseNode
|
|||||||
o.top: true
|
o.top: true
|
||||||
attempt_part: @attempt.compile(o)
|
attempt_part: @attempt.compile(o)
|
||||||
error_part: if @error then " (${ @error.compile(o) }) " else ' '
|
error_part: if @error then " (${ @error.compile(o) }) " else ' '
|
||||||
catch_part: "${ (@recovery or '') and ' catch' }$error_part{\n${ @recovery.compile(o) }\n$@tab}"
|
catch_part: if @recovery then " catch$error_part{\n${ @recovery.compile(o) }\n$@tab}" else ''
|
||||||
finally_part: (@ensure or '') and ' finally {\n' + @ensure.compile(merge(o, {returns: null})) + "\n$@tab}"
|
finally_part: (@ensure or '') and ' finally {\n' + @ensure.compile(merge(o, {returns: null})) + "\n$@tab}"
|
||||||
"${@tab}try {\n$attempt_part\n$@tab}$catch_part$finally_part"
|
"${@tab}try {\n$attempt_part\n$@tab}$catch_part$finally_part"
|
||||||
|
|
||||||
|
|||||||
14
test/test_try_catch.coffee
Normal file
14
test/test_try_catch.coffee
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
result: try
|
||||||
|
10
|
||||||
|
finally
|
||||||
|
15
|
||||||
|
|
||||||
|
ok result is 10
|
||||||
|
|
||||||
|
|
||||||
|
result: try
|
||||||
|
throw 'up'
|
||||||
|
catch err
|
||||||
|
err.length
|
||||||
|
|
||||||
|
ok result is 2
|
||||||
Reference in New Issue
Block a user