-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow][parser] Fix parsing of parenthesized component types
Summary: Parse parenthesized component types as component types Changelog: [parser] Component type in parentheses can now be correctly parsed. e.g. `type Foo = (component(x: number) renders Bar);` Reviewed By: SamChou19815 Differential Revision: D64196210 fbshipit-source-id: 1abbfca38a2baa45656cd6d80abbbc28508cf941
- Loading branch information
1 parent
2830c6a
commit 13a349f
Showing
5 changed files
with
84 additions
and
0 deletions.
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 @@ | ||
type Foo = (component(x: number) renders Bar); |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/components/component_type_paren.options.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,3 @@ | ||
{ | ||
"components": true | ||
} |
70 changes: 70 additions & 0 deletions
70
src/parser/test/flow/components/component_type_paren.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":46}}, | ||
"range":[0,46], | ||
"body":[ | ||
{ | ||
"type":"TypeAlias", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":46}}, | ||
"range":[0,46], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":8}}, | ||
"range":[5,8], | ||
"name":"Foo", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeParameters":null, | ||
"right":{ | ||
"type":"ComponentTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":44}}, | ||
"range":[12,44], | ||
"params":[ | ||
{ | ||
"type":"ComponentTypeParameter", | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":31}}, | ||
"range":[22,31], | ||
"name":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, | ||
"range":[22,23], | ||
"name":"x", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeAnnotation":{ | ||
"type":"NumberTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":31}}, | ||
"range":[25,31] | ||
}, | ||
"optional":false | ||
} | ||
], | ||
"rest":null, | ||
"rendersType":{ | ||
"type":"TypeOperator", | ||
"loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":44}}, | ||
"range":[33,44], | ||
"operator":"renders", | ||
"typeAnnotation":{ | ||
"type":"GenericTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":44}}, | ||
"range":[41,44], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":44}}, | ||
"range":[41,44], | ||
"name":"Bar", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeParameters":null | ||
} | ||
}, | ||
"typeParameters":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
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,4 @@ | ||
declare component Foo(bar: string) renders 'svg'; | ||
type FooTy = (component(bar: string) renders 'svg'); | ||
|
||
Foo as FooTy; // ok |