-
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] add support for const type parameter
Summary: Adds support for parsing a `const` modifier in type parameters: ``` function foo<const T>(x: T): void {} ``` Typing won't be supported for now; any instance of `const` type param is an unsupported-syntax error. `const` won't be a valid name for a type parameter anymore, so the following will now be parsing errors: ``` function foo<const>(): void {}; type T<const> = {}; class C<const> {}; ``` Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D66669559 fbshipit-source-id: 17e33fb421f4e626c66c0db679b7816305c23bd5
- Loading branch information
1 parent
638aa1c
commit f0cfd43
Showing
31 changed files
with
971 additions
and
10 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
1 change: 1 addition & 0 deletions
1
src/parser/test/flow/types/mapped_types/invalid_const_tparam.js
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 @@ | ||
let x: {[const key in keyof O]?: T}; |
193 changes: 193 additions & 0 deletions
193
src/parser/test/flow/types/mapped_types/invalid_const_tparam.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,193 @@ | ||
{ | ||
"errors":[ | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, | ||
"message":"Unexpected token `const`, expected a type" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, | ||
"message":"Unexpected token `const`, expected the token `]`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":18}}, | ||
"message":"Unexpected identifier, expected the token `:`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, | ||
"message":"Unexpected token `keyof`, expected the token `,`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, | ||
"message":"Unexpected identifier, expected the token `:`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, | ||
"message":"Unexpected identifier, expected the token `,`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":30}}, | ||
"message":"Unexpected token `]`, expected the token `:`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":30}}, | ||
"message":"Unexpected token `]`, expected the token `,`" | ||
}, | ||
{ | ||
"loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":30}}, | ||
"message":"Unexpected token `]`, expected an identifier" | ||
} | ||
], | ||
"type":"Program", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":36}}, | ||
"range":[0,36], | ||
"body":[ | ||
{ | ||
"type":"VariableDeclaration", | ||
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":36}}, | ||
"range":[0,36], | ||
"declarations":[ | ||
{ | ||
"type":"VariableDeclarator", | ||
"loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":35}}, | ||
"range":[4,35], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":35}}, | ||
"range":[4,35], | ||
"name":"x", | ||
"typeAnnotation":{ | ||
"type":"TypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":35}}, | ||
"range":[5,35], | ||
"typeAnnotation":{ | ||
"type":"ObjectTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":7},"end":{"line":1,"column":35}}, | ||
"range":[7,35], | ||
"inexact":false, | ||
"exact":false, | ||
"properties":[ | ||
{ | ||
"type":"ObjectTypeProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, | ||
"range":[22,27], | ||
"key":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, | ||
"range":[22,27], | ||
"name":"keyof", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"value":{ | ||
"type":"AnyTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, | ||
"range":[22,27] | ||
}, | ||
"method":false, | ||
"optional":false, | ||
"static":false, | ||
"proto":false, | ||
"variance":null, | ||
"kind":"init" | ||
}, | ||
{ | ||
"type":"ObjectTypeProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, | ||
"range":[28,29], | ||
"key":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, | ||
"range":[28,29], | ||
"name":"O", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"value":{ | ||
"type":"AnyTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, | ||
"range":[28,29] | ||
}, | ||
"method":false, | ||
"optional":false, | ||
"static":false, | ||
"proto":false, | ||
"variance":null, | ||
"kind":"init" | ||
}, | ||
{ | ||
"type":"ObjectTypeProperty", | ||
"loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":34}}, | ||
"range":[29,34], | ||
"key":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":30}}, | ||
"range":[29,30], | ||
"name":"", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"value":{ | ||
"type":"GenericTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":34}}, | ||
"range":[33,34], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":34}}, | ||
"range":[33,34], | ||
"name":"T", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeParameters":null | ||
}, | ||
"method":false, | ||
"optional":true, | ||
"static":false, | ||
"proto":false, | ||
"variance":null, | ||
"kind":"init" | ||
} | ||
], | ||
"indexers":[ | ||
{ | ||
"type":"ObjectTypeIndexer", | ||
"loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":1,"column":21}}, | ||
"range":[8,21], | ||
"id":null, | ||
"key":{ | ||
"type":"AnyTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":14}}, | ||
"range":[9,14] | ||
}, | ||
"value":{ | ||
"type":"GenericTypeAnnotation", | ||
"loc":{"source":null,"start":{"line":1,"column":19},"end":{"line":1,"column":21}}, | ||
"range":[19,21], | ||
"id":{ | ||
"type":"Identifier", | ||
"loc":{"source":null,"start":{"line":1,"column":19},"end":{"line":1,"column":21}}, | ||
"range":[19,21], | ||
"name":"in", | ||
"typeAnnotation":null, | ||
"optional":false | ||
}, | ||
"typeParameters":null | ||
}, | ||
"static":false, | ||
"variance":null | ||
} | ||
], | ||
"callProperties":[], | ||
"internalSlots":[] | ||
} | ||
}, | ||
"optional":false | ||
}, | ||
"init":null | ||
} | ||
], | ||
"kind":"let" | ||
} | ||
], | ||
"comments":[] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/parser/test/flow/types/type_params/function_const_params.js
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,6 @@ | ||
function f1<const X>(): void {} | ||
function f2<const X, Y>(): void {} | ||
function f3<X, const Y>(): void {} | ||
function f4<const Y = T>(): void {} | ||
function f5<const Y : T>(): void {} | ||
function f6 < /* comment 1 */ const /* comment 2 */ Y /* comment 3 */ : /* comment 4 */ T /* comment 5 */ >(): void {} |
3 changes: 3 additions & 0 deletions
3
src/parser/test/flow/types/type_params/function_const_params.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 @@ | ||
{ | ||
"intern_comments": true | ||
} |
Oops, something went wrong.