-
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.
Parsing support for explicit type arguments in new/call
Summary: This diff adds parsing support for explicit type arguments in new and call expressions, e.g., `f<T>(x)`. This syntax is overlaps with existing syntax in some cases. For example, the program `f<T>(x)` already parses as nested binary expressions `((f<T)>x)`. Flow will only attempt to parse this syntax as explicit type arguments if `should_parse_types` is true -- i.e., if Flow is enabled for the file, either through the `flow` pragma or the `--all` cmdline argument. Due to the ambiguity, parsing this syntax uses backtracking via Try. When we see `f<`, we try to parse the type argument list. If that fails, we rollback and try parsing as a binary expression instead. For optional chaining, the syntax `f?.<T>(x)` is parsed as an optional call with type arguments. Typing support for this syntax will be added in a follow-up. I have marked the places where typing rules should consider type args with a TODO comment. Reviewed By: gabelevi Differential Revision: D7657631 fbshipit-source-id: 34390c43a10c30eeb18285f5282db502335f7419
- Loading branch information
1 parent
c947de2
commit 40fbcdd
Showing
48 changed files
with
1,063 additions
and
71 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
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
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
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
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 @@ | ||
f<T>(e); |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/typeapp_call/disabled_ambiguous_call.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 @@ | ||
{ | ||
"types": false | ||
} |
50 changes: 50 additions & 0 deletions
50
src/parser/test/flow/typeapp_call/disabled_ambiguous_call.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,50 @@ | ||
{ | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"range":[0,8], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"range":[0,8], | ||
"expression":{ | ||
"type":"BinaryExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"range":[0,7], | ||
"operator":">", | ||
"left":{ | ||
"type":"BinaryExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, | ||
"range":[0,3], | ||
"operator":"<", | ||
"left":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":1}}, | ||
"range":[0,1], | ||
"name":"f", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"right":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":2},"end":{"line":1,"column":3}}, | ||
"range":[2,3], | ||
"name":"T", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"right":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":6}}, | ||
"range":[5,6], | ||
"name":"e", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new C<T>(e); |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/typeapp_call/disabled_ambiguous_new.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 @@ | ||
{ | ||
"types": false | ||
} |
56 changes: 56 additions & 0 deletions
56
src/parser/test/flow/typeapp_call/disabled_ambiguous_new.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,56 @@ | ||
{ | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"range":[0,12], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"range":[0,12], | ||
"expression":{ | ||
"type":"BinaryExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"range":[0,11], | ||
"operator":">", | ||
"left":{ | ||
"type":"BinaryExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"range":[0,7], | ||
"operator":"<", | ||
"left":{ | ||
"type":"NewExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, | ||
"range":[0,5], | ||
"callee":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":5}}, | ||
"range":[4,5], | ||
"name":"C", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"arguments":[] | ||
}, | ||
"right":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":7}}, | ||
"range":[6,7], | ||
"name":"T", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"right":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":10}}, | ||
"range":[9,10], | ||
"name":"e", | ||
"typeAnnotation":null, | ||
"optional":false | ||
} | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f<T>(); |
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,49 @@ | ||
{ | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"range":[0,7], | ||
"body":[ | ||
{ | ||
"type":"ExpressionStatement", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":7}}, | ||
"range":[0,7], | ||
"expression":{ | ||
"type":"CallExpression", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"range":[0,6], | ||
"callee":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":1}}, | ||
"range":[0,1], | ||
"name":"f", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeArguments":{ | ||
"type":"TypeParameterInstantiation", | ||
"loc":{"source":null,"start":{"line":1,"column":1},"end":{"line":1,"column":4}}, | ||
"range":[1,4], | ||
"params":[ | ||
{ | ||
"type":"GenericTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":2},"end":{"line":1,"column":3}}, | ||
"range":[2,3], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":2},"end":{"line":1,"column":3}}, | ||
"range":[2,3], | ||
"name":"T", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeParameters":null | ||
} | ||
] | ||
}, | ||
"arguments":[] | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f<T>(x)<U>(y); |
Oops, something went wrong.