mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge branch 'catchless' of http://github.com/satyr/coffee-script
This commit is contained in:
commit
8eb283df2c
6 changed files with 91 additions and 81 deletions
|
@ -353,7 +353,9 @@
|
|||
})
|
||||
],
|
||||
Try: [
|
||||
o("TRY Block Catch", function() {
|
||||
o("TRY Block", function() {
|
||||
return new TryNode($2);
|
||||
}), o("TRY Block Catch", function() {
|
||||
return new TryNode($2, $3[0], $3[1]);
|
||||
}), o("TRY Block FINALLY Block", function() {
|
||||
return new TryNode($2, null, null, $4);
|
||||
|
|
|
@ -1478,7 +1478,7 @@
|
|||
o.top = true;
|
||||
attemptPart = this.attempt.compile(o);
|
||||
errorPart = this.error ? (" (" + (this.error.compile(o)) + ") ") : ' ';
|
||||
catchPart = this.recovery ? (" catch" + (errorPart) + "{\n" + (this.recovery.compile(o)) + "\n" + (this.tab) + "}") : '';
|
||||
catchPart = this.recovery ? (" catch" + (errorPart) + "{\n" + (this.recovery.compile(o)) + "\n" + (this.tab) + "}") : (!(this.ensure || this.recovery) ? ' catch (_e) {}' : '');
|
||||
finallyPart = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o)) + ("\n" + (this.tab) + "}");
|
||||
return "" + (this.tab) + "try {\n" + (attemptPart) + "\n" + (this.tab) + "}" + (catchPart) + (finallyPart);
|
||||
};
|
||||
|
|
156
lib/parser.js
156
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -389,6 +389,7 @@ grammar =
|
|||
|
||||
# The variants of *try/catch/finally* exception handling blocks.
|
||||
Try: [
|
||||
o "TRY Block", -> new TryNode $2
|
||||
o "TRY Block Catch", -> new TryNode $2, $3[0], $3[1]
|
||||
o "TRY Block FINALLY Block", -> new TryNode $2, null, null, $4
|
||||
o "TRY Block Catch FINALLY Block", -> new TryNode $2, $3[0], $3[1], $5
|
||||
|
|
|
@ -1288,7 +1288,9 @@ exports.TryNode = class TryNode extends BaseNode
|
|||
o.top = true
|
||||
attemptPart = @attempt.compile(o)
|
||||
errorPart = if @error then " (#{ @error.compile(o) }) " else ' '
|
||||
catchPart = if @recovery then " catch#{errorPart}{\n#{ @recovery.compile(o) }\n#{@tab}}" else ''
|
||||
catchPart = if @recovery
|
||||
" catch#{errorPart}{\n#{ @recovery.compile(o) }\n#{@tab}}"
|
||||
else unless @ensure or @recovery then ' catch (_e) {}' else ''
|
||||
finallyPart = (@ensure or '') and ' finally {\n' + @ensure.compile(merge(o)) + "\n#{@tab}}"
|
||||
"#{@tab}try {\n#{attemptPart}\n#{@tab}}#{catchPart}#{finallyPart}"
|
||||
|
||||
|
|
|
@ -23,8 +23,11 @@ result = try throw 'error' catch err then err.length
|
|||
|
||||
ok result is 5
|
||||
|
||||
try throw 'catch is optional'
|
||||
|
||||
# try/catch with empty clauses still compiles.
|
||||
try
|
||||
|
||||
try
|
||||
# nothing
|
||||
catch err
|
||||
|
@ -39,4 +42,4 @@ try
|
|||
catch err
|
||||
finally
|
||||
|
||||
ok yes
|
||||
ok yes
|
||||
|
|
Loading…
Reference in a new issue