Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: add strict parent types for nodes that have well-defined parents #10682

Closed
@ronami

Description

@ronami

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

types

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

This PR is a very similar proposal to the one in #6225 and suggests having stricter parent types for some AST nodes:

  • ExportDefaultDeclaration has parent TSESTree.BlockStatement | TSESTree.Program | TSESTree.TSModuleBlock
  • ExportNamedDeclaration has parent TSESTree.BlockStatement | TSESTree.Program | TSESTree.TSModuleBlock
  • FunctionDeclaration with name has parent TSESTree.BlockStatement | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.Program.
  • FunctionDeclaration without name has parent TSESTree.ExportDefaultDeclaration (reference).

This is a follow-up to the discussion in #10422 (comment).


Some thoughts/notes:

  • I've looked into @babel/parser, @swc/types, and @oxc-project/types (also the more technical 1, 2), but I didn't find anything that makes me confident this is valid in every case. I verified that @typescript-eslint itself is type-checked successfully with these assumptions.
  • TypeScript itself doesn't have a specific parent for FunctionDeclaration (it falls back to the generic ts.Node), although they do have stricter parent types for some other nodes.
  • To my understanding, TypeScript's AST doesn't have an actual AST node for ExportDefaultDeclaration or ExportNamedDeclaration, as they're expressed as modifiers.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions