dossier
dossier copied to clipboard
Support TypeScript nested type identifiers
This type signature is not parsed correctly, because we can't parse nested types.
function verifyToken(token: string): string | jwt.JwtPayload {}
--------------
^
|
This is the issue
This gets parsed as follows by tree-sitter (Paste into here: https://tree-sitter.github.io/tree-sitter/playground):
[program](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 0]
[function_declaration](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 63]
name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 9] - [0, 20]
parameters: [formal_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [0, 20] - [0, 35]
[required_parameter](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 34]
pattern: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 26]
type: [type_annotation](https://tree-sitter.github.io/tree-sitter/playground#) [0, 26] - [0, 34]
[predefined_type](https://tree-sitter.github.io/tree-sitter/playground#) [0, 28] - [0, 34]
return_type: [type_annotation](https://tree-sitter.github.io/tree-sitter/playground#) [0, 35] - [0, 60]
[union_type](https://tree-sitter.github.io/tree-sitter/playground#) [0, 37] - [0, 60]
[predefined_type](https://tree-sitter.github.io/tree-sitter/playground#) [0, 37] - [0, 43]
[nested_type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 46] - [0, 60]
module: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 46] - [0, 49]
name: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 50] - [0, 60]
body: [statement_block](https://tree-sitter.github.io/tree-sitter/playground#) [0, 61] - [0, 63]
Note the nested_type_identifier
section near the end.
The fix
This should be quite easy to add to https://github.com/Doctave/dossier/blob/main/dossier-ts/src/types.rs.
Then we need to ensure that we can resolve these types to their implementations. That may require a bit more thinking.