Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allow function types inside tuples inside arrow return types
Summary:
To avoid ambiguity, Flow disallows using a function type in the return type, like
const f = (): boolean => string => { return (b: boolean): string => "hello"; }
unless you wrap it in parens
const f = (): (boolean => string) => { return (b: boolean): string => "hello"; }
We forgot to allow it inside tuples too, like
const f = (): [boolean => string] => { return [(b: boolean): string => "hello"]; }
Reviewed By: dsainati1
Differential Revision: D15150181
fbshipit-source-id: dbc9292ac0935ea79373437501b22373e538979a- Loading branch information
1 parent
52bbf66
commit 65e6d1d
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| (): [number => void] => {} |
70 changes: 70 additions & 0 deletions
70
src/parser/test/flow/arrow_function/tuple_return_type.tree.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| { | ||
| "type":"Program", | ||
| "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
| "range":[0,26], | ||
| "body":[ | ||
| { | ||
| "type":"ExpressionStatement", | ||
| "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
| "range":[0,26], | ||
| "expression":{ | ||
| "type":"ArrowFunctionExpression", | ||
| "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}}, | ||
| "range":[0,26], | ||
| "id":null, | ||
| "params":[], | ||
| "body":{ | ||
| "type":"BlockStatement", | ||
| "loc":{"source":null,"start":{"line":1,"column":24},"end":{"line":1,"column":26}}, | ||
| "range":[24,26], | ||
| "body":[] | ||
| }, | ||
| "async":false, | ||
| "generator":false, | ||
| "predicate":null, | ||
| "expression":false, | ||
| "returnType":{ | ||
| "type":"TypeAnnotation", | ||
| "loc":{"source":null,"start":{"line":1,"column":2},"end":{"line":1,"column":20}}, | ||
| "range":[2,20], | ||
| "typeAnnotation":{ | ||
| "type":"TupleTypeAnnotation", | ||
| "loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":20}}, | ||
| "range":[4,20], | ||
| "types":[ | ||
| { | ||
| "type":"FunctionTypeAnnotation", | ||
| "loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":19}}, | ||
| "range":[5,19], | ||
| "params":[ | ||
| { | ||
| "type":"FunctionTypeParam", | ||
| "loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":11}}, | ||
| "range":[5,11], | ||
| "name":null, | ||
| "typeAnnotation":{ | ||
| "type":"NumberTypeAnnotation", | ||
| "loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":11}}, | ||
| "range":[5,11] | ||
| }, | ||
| "optional":false | ||
| } | ||
| ], | ||
| "returnType":{ | ||
| "type":"VoidTypeAnnotation", | ||
| "loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":19}}, | ||
| "range":[15,19] | ||
| }, | ||
| "rest":null, | ||
| "typeParameters":null | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "typeParameters":null | ||
| }, | ||
| "directive":null | ||
| } | ||
| ], | ||
| "comments":[] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65e6d1dThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉