Skip to content
This repository was archived by the owner on May 19, 2018. It is now read-only.
/ babylon Public archive

Add optionality to catch bindings#634

Merged
hzoo merged 4 commits intobabel:masterfrom
MarckK:optional-catch-binding
Jul 21, 2017
Merged

Add optionality to catch bindings#634
hzoo merged 4 commits intobabel:masterfrom
MarckK:optional-catch-binding

Conversation

@MarckK
Copy link
Copy Markdown
Member

@MarckK MarckK commented Jul 16, 2017

Q A
Bug fix? no
Breaking change? no
New feature? yes
Deprecations?
Spec compliancy?
Tests added/pass? yes
Fixed tickets
License MIT

This implements the optional catch binding proposal (babel/proposals #7).

@bakkot
Copy link
Copy Markdown
Contributor

bakkot commented Jul 16, 2017

  1. I think you want to update the AST specification too.

  2. Maybe add a test for try + catch + finally, e.g. try {} catch {} finally {}.

Otherwise looks good to me!

Copy link
Copy Markdown
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakkot's request, too. Nearly there.

clause.param = this.parseBindingAtom();
this.checkLVal(clause.param, true, Object.create(null), "catch clause");
this.expect(tt.parenR);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's set clause.param = null in an else case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. 👍

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jul 19, 2017

https://github.com/babel/babylon/blob/master/CONTRIBUTING.md#creating-a-new-plugin-spec-new

Yeah I would:

  • add an entry to the readme,
  • update ast/spec

this.checkLVal(clause.param, true, Object.create(null), "catch clause");
this.expect(tt.parenR);
}
clause.param = null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to add this to else otherwise it would set it to null in all cases? And then rerun the tests fixtures

Copy link
Copy Markdown
Member Author

@MarckK MarckK Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. This is causing a failure in one of my tests. I'll have to look at more.

Copy link
Copy Markdown
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

this.checkLVal(clause.param, true, Object.create(null), "catch clause");
this.expect(tt.parenR);

if (this.match(tt.parenL) || !this.hasPlugin("optionalCatchBinding")) {
Copy link
Copy Markdown
Member

@hzoo hzoo Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering whether the this.match check is necessary?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok never mind, talked to Kara and it makes sense. This is for the case you have the plugin on, but you choose to still use the binding itself.

@hzoo hzoo merged commit c88af90 into babel:master Jul 21, 2017
@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jul 21, 2017

Nice work! 😄 First parser PR in the bag

@MarckK MarckK deleted the optional-catch-binding branch July 22, 2017 13:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants