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:
MarckK
2017-07-21 15:18:57 +01:00
committed by Henry Zhu
parent 77bdb9ae3e
commit c88af90c0a
23 changed files with 788 additions and 7 deletions

View File

@@ -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");
}