From f2d0aee656b1bc2a41faf1886cca8a277a0ce01f Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 10 Mar 2010 16:27:30 -0500 Subject: [PATCH] added Stan's fix for try/finally without catch --- lib/nodes.js | 2 +- src/nodes.coffee | 2 +- test/test_try_catch.coffee | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/test_try_catch.coffee diff --git a/lib/nodes.js b/lib/nodes.js index b812b85b..bf984ff8 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1195,7 +1195,7 @@ idt += TAB o.top = true; attempt_part = this.attempt.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, { returns: null })) + "\n" + this.tab + "}"; diff --git a/src/nodes.coffee b/src/nodes.coffee index d0d6b1a1..db9b55c1 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -905,7 +905,7 @@ exports.TryNode: class TryNode extends BaseNode o.top: true attempt_part: @attempt.compile(o) 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}" "${@tab}try {\n$attempt_part\n$@tab}$catch_part$finally_part" diff --git a/test/test_try_catch.coffee b/test/test_try_catch.coffee new file mode 100644 index 00000000..ccc2e4a7 --- /dev/null +++ b/test/test_try_catch.coffee @@ -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 \ No newline at end of file