Add optionality to catch bindings (#634)
* Add optionality to catch bindings (plus tests) * Update ast/spec, README, set param to null if no param with plugin optionalCatchBinding * Fix: wrap param = null in else case * Fix tests for optional catch binding; add tests which include finally clause
This commit is contained in:
@@ -491,12 +491,14 @@ export default class StatementParser extends ExpressionParser {
|
||||
if (this.match(tt._catch)) {
|
||||
const clause = this.startNode();
|
||||
this.next();
|
||||
|
||||
this.expect(tt.parenL);
|
||||
clause.param = this.parseBindingAtom();
|
||||
this.checkLVal(clause.param, true, Object.create(null), "catch clause");
|
||||
this.expect(tt.parenR);
|
||||
|
||||
if (this.match(tt.parenL) || !this.hasPlugin("optionalCatchBinding")) {
|
||||
this.expect(tt.parenL);
|
||||
clause.param = this.parseBindingAtom();
|
||||
this.checkLVal(clause.param, true, Object.create(null), "catch clause");
|
||||
this.expect(tt.parenR);
|
||||
} else {
|
||||
clause.param = null;
|
||||
}
|
||||
clause.body = this.parseBlock();
|
||||
node.handler = this.finishNode(clause, "CatchClause");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user