This repository has been archived by the owner. It is now read-only.

Fix flow plugin when flow+arrow+spread used together #10

Merged
merged 1 commit into from Jun 22, 2016

Conversation

Projects
None yet
3 participants
@danez
Copy link
Member

danez commented Mar 20, 2016

Fix for

( ...props: SomeType ) : ?ReturnType => ( 3 );

The fix creates a new method on the parser called parseArrow.
This new function by default only checks if current position matches an
arrow. If it does returns the node otherwise undefined.
The flow plugin can then extend this function and correctly parse the typeAnnotation
and add it to the node.

With this change, in the flow plugin there is no need anymore to extend
parseParenAndDistinguishExpression and the arrow handling in parseParenItem
could also be removed, because it is all handled now in parseArrow.

Some existing tests were failing, because extra->parentesized is now missing,
but this should be correct as it is now inline with the parsing without flow annotations. No extra
is added for arrow function without type annotations.

Also, in the expression-parser this.next() was replaced by a more specific
this.expect(tt.parenL) inside parseParenAndDistinguishExpression.

And I reverted the fix from babel/babel#3305 as it is not necessary anymore.

Fixes babel/T2612

Fix flow plugin when flow+arrow+spread used together
The fix includes creating a new method on the parser called `parseArrow`.
This new function by default only checks if current position matches an
arrow. If it does returns the `node` otherwise `undefined`.
The flow plugin can then extend this function and correctly parse the typeAnnotation
and add it to the node.

With this change, in the flow plugin there is no need anymore to extend
`parseParenAndDistinguishExpression` and the arrow handling in `parseParenItem`
could also be removed, because it is all handled now in `parseArrow`.

Some existing tests were failing, because `extra->parentesized` is now missing,
but this is correct as it is now inline with parsing without flow annotation. No extra
is added for arrow function without type annotations.

In the expression-parser `this.next()` was replaced by a more specific
`this.expect(tt.parenL)`.

@danez danez force-pushed the danez:fix-flow-arrow-spread branch from bc7707c to d15a231 Apr 4, 2016

@hzoo hzoo added the Tag: Bug Fix label May 4, 2016

@kittens kittens merged commit 4d2e1dd into babel:master Jun 22, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@danez danez deleted the danez:fix-flow-arrow-spread branch Jun 22, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.