mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Fixes #1467. Catch now introduces its parameter to scope.
This commit is contained in:
committed by
Michael Ficarra
parent
73af3b17b1
commit
0f18dff464
@@ -1822,7 +1822,7 @@
|
|||||||
var catchPart, errorPart;
|
var catchPart, errorPart;
|
||||||
o.indent += TAB;
|
o.indent += TAB;
|
||||||
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
||||||
catchPart = this.recovery ? " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
|
catchPart = this.recovery ? (o.scope.add(this.error.value, 'param'), " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
|
||||||
return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '');
|
return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '');
|
||||||
};
|
};
|
||||||
return Try;
|
return Try;
|
||||||
|
|||||||
@@ -1402,6 +1402,7 @@ exports.Try = class Try extends Base
|
|||||||
o.indent += TAB
|
o.indent += TAB
|
||||||
errorPart = if @error then " (#{ @error.compile o }) " else ' '
|
errorPart = if @error then " (#{ @error.compile o }) " else ' '
|
||||||
catchPart = if @recovery
|
catchPart = if @recovery
|
||||||
|
o.scope.add @error.value, 'param'
|
||||||
" catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
|
" catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
|
||||||
else unless @ensure or @recovery
|
else unless @ensure or @recovery
|
||||||
' catch (_e) {}'
|
' catch (_e) {}'
|
||||||
|
|||||||
@@ -26,3 +26,9 @@ test "siblings of variadic arguments shouldn't break out.", ->
|
|||||||
oops = (x,args...) ->
|
oops = (x,args...) ->
|
||||||
oops(20, 1,2,3)
|
oops(20, 1,2,3)
|
||||||
eq x, 10
|
eq x, 10
|
||||||
|
|
||||||
|
test "catch statements should introduce their argument to scope", ->
|
||||||
|
try throw ''
|
||||||
|
catch e
|
||||||
|
do -> e = 5
|
||||||
|
eq 5, e
|
||||||
|
|||||||
Reference in New Issue
Block a user