#2900 -- parameter-less catch clause.
Plus some minor cleanup after f8c6b494aa
This commit is contained in:
parent
740a7bcb45
commit
cf07fcb4b1
|
@ -350,6 +350,8 @@
|
|||
return [$2, $3];
|
||||
}), o('CATCH Object Block', function() {
|
||||
return [LOC(2)(new Value($2)), $3];
|
||||
}), o('CATCH Block', function() {
|
||||
return [null, $2];
|
||||
})
|
||||
],
|
||||
Throw: [
|
||||
|
|
|
@ -2460,10 +2460,10 @@
|
|||
};
|
||||
|
||||
Try.prototype.compileNode = function(o) {
|
||||
var catchPart, ensurePart, placeholder, tryPart, _ref4;
|
||||
var catchPart, ensurePart, placeholder, tryPart;
|
||||
o.indent += TAB;
|
||||
tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);
|
||||
catchPart = this.recovery ? (placeholder = new Literal('_error'), this.recovery.unshift(new Assign(this.errorVariable, placeholder)), this.errorVariable = placeholder, (_ref4 = this.errorVariable.value, __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) ? this.errorVariable.error("catch variable may not be \"" + this.errorVariable.value + "\"") : void 0, [].concat(this.makeCode(" catch ("), this.errorVariable.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];
|
||||
catchPart = this.recovery ? (placeholder = new Literal('_error'), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];
|
||||
ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];
|
||||
return [].concat(this.makeCode("" + this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);
|
||||
};
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -365,7 +365,7 @@
|
|||
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
|
||||
};
|
||||
return this.scanTokens(function(token, i, tokens) {
|
||||
var tag, _ref, _ref1;
|
||||
var j, tag, _i, _ref, _ref1;
|
||||
tag = token[0];
|
||||
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
|
||||
tokens.splice(i, 1);
|
||||
|
@ -375,9 +375,14 @@
|
|||
tokens.splice.apply(tokens, [i, 0].concat(__slice.call(this.indentation())));
|
||||
return 2;
|
||||
}
|
||||
if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'OUTDENT' || _ref === 'TERMINATOR' || _ref === 'FINALLY')) {
|
||||
tokens.splice.apply(tokens, [i + 2, 0].concat(__slice.call(this.indentation())));
|
||||
return 4;
|
||||
if (tag === 'CATCH') {
|
||||
for (j = _i = 1; _i <= 2; j = ++_i) {
|
||||
if (!((_ref = this.tag(i + j)) === 'OUTDENT' || _ref === 'TERMINATOR' || _ref === 'FINALLY')) {
|
||||
continue;
|
||||
}
|
||||
tokens.splice.apply(tokens, [i + j, 0].concat(__slice.call(this.indentation())));
|
||||
return 2 + j;
|
||||
}
|
||||
}
|
||||
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
|
||||
starter = tag;
|
||||
|
|
|
@ -401,6 +401,7 @@ grammar =
|
|||
Catch: [
|
||||
o 'CATCH Identifier Block', -> [$2, $3]
|
||||
o 'CATCH Object Block', -> [LOC(2)(new Value($2)), $3]
|
||||
o 'CATCH Block', -> [null, $2]
|
||||
]
|
||||
|
||||
# Throw an exception object.
|
||||
|
|
|
@ -1733,11 +1733,8 @@ exports.Try = class Try extends Base
|
|||
|
||||
catchPart = if @recovery
|
||||
placeholder = new Literal '_error'
|
||||
@recovery.unshift new Assign @errorVariable, placeholder
|
||||
@errorVariable = placeholder
|
||||
if @errorVariable.value in STRICT_PROSCRIBED
|
||||
@errorVariable.error "catch variable may not be \"#{@errorVariable.value}\""
|
||||
[].concat @makeCode(" catch ("), @errorVariable.compileToFragments(o), @makeCode(") {\n"),
|
||||
@recovery.unshift new Assign @errorVariable, placeholder if @errorVariable
|
||||
[].concat @makeCode(" catch ("), placeholder.compileToFragments(o), @makeCode(") {\n"),
|
||||
@recovery.compileToFragments(o, LEVEL_TOP), @makeCode("\n#{@tab}}")
|
||||
else unless @ensure or @recovery
|
||||
[@makeCode(' catch (_error) {}')]
|
||||
|
|
|
@ -375,9 +375,10 @@ class exports.Rewriter
|
|||
if tag is 'ELSE' and @tag(i - 1) isnt 'OUTDENT'
|
||||
tokens.splice i, 0, @indentation()...
|
||||
return 2
|
||||
if tag is 'CATCH' and @tag(i + 2) in ['OUTDENT', 'TERMINATOR', 'FINALLY']
|
||||
tokens.splice i + 2, 0, @indentation()...
|
||||
return 4
|
||||
if tag is 'CATCH'
|
||||
for j in [1..2] when @tag(i + j) in ['OUTDENT', 'TERMINATOR', 'FINALLY']
|
||||
tokens.splice i + j, 0, @indentation()...
|
||||
return 2 + j
|
||||
if tag in SINGLE_LINERS and @tag(i + 1) isnt 'INDENT' and
|
||||
not (tag is 'ELSE' and @tag(i + 1) is 'IF')
|
||||
starter = tag
|
||||
|
|
|
@ -129,3 +129,14 @@ test "Try catch finally as implicit arguments", ->
|
|||
bar = yes
|
||||
catch e
|
||||
eq bar, yes
|
||||
|
||||
# Catch Should Not Require Param: #2900
|
||||
test "parameter-less catch clause", ->
|
||||
try
|
||||
throw new Error 'failed'
|
||||
catch
|
||||
ok true
|
||||
|
||||
try throw new Error 'failed' catch finally ok true
|
||||
|
||||
ok try throw new Error 'failed' catch then true
|
||||
|
|
Loading…
Reference in New Issue