Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript nested type identifiers #4

Open
begleynk opened this issue Jan 14, 2024 · 0 comments
Open

Support TypeScript nested type identifiers #4

begleynk opened this issue Jan 14, 2024 · 0 comments
Labels
TypeScript Relates to the TypeScript parser

Comments

@begleynk
Copy link
Member

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.

@begleynk begleynk added the TypeScript Relates to the TypeScript parser label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TypeScript Relates to the TypeScript parser
Projects
None yet
Development

No branches or pull requests

1 participant