Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhancement: add strictparent types for nodes that have well-defined parents #6225

Closed
Labels
ASTPRs and Issues about the AST structureaccepting 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.package: ast-specIssues related to @typescript-eslint/ast-spec
Milestone
@bradzacher

Description

@bradzacher

Right now a node's.parent property is loosely typed asTESTree.Node. This is pretty sucky as it means that users need to either add unnecessary logic or explicit casts to refine types in some cases.

There are a number of nodes wherein we know exactly what the parent node will always be due to the defined structure of the AST.
For example, we know that aVariableDeclarator will always have aVariableDeclaration parent.

We should define some of these simpler relationships in our types to improve the experience of consuming the AST types.

Some cases we can define:

  • AccessorProperty has parentClassBody (feat(ast-spec): add parent property to AccessorProperty node types #9487)
  • CatchClause has parentTryStatement
  • ClassBody has parentClassDeclaration | ClassExpression | TSAbstractClassDeclaration
  • ExportSpecifier has parentExportNamedDeclaration
  • ImportAttribute has parentImportDeclaration | ImportExpression
  • ImportDefaultSpecifier has parentImportDeclaration
  • ImportNamespaceSpecifier has parentImportDeclaration
  • ImportSpecifier has parentExportAllDeclaration | ExportNamedDeclaration | ImportDeclaration
  • JSXAttribute has parentJSXOpeningElement
  • JSXClosingElement has parentJSXElement
  • JSXClosingFragment has parentJSXFragment
  • JSXOpeningElement has parentJSXElement
  • JSXOpeningFragment has parentJSXFragment
  • JSXSpreadAttribute has parentJSXOpeningElement
  • MethodDefinition has parentClassBody
  • Property has parentObjectExpression | ObjectPattern
  • PropertyDefinition has parentClassBody
  • SpreadElement has parentArrayExpression | CallExpression | ObjectExpression
  • StaticBlock has parentClassBody
  • SwitchCase has parentSwitchStatement
  • TemplateElement has parentTemplateLiteral | TSTemplateLiteralType
  • TSAbstractAccessorProperty has parentClassBody
  • TSAbstractMethodDefinition has parentClassBody
  • TSAbstractPropertyDefinition has parentClassBody
  • TSCallSignatureDeclaration has parentTSInterfaceBody | TSTypeLiteral
  • TSConstructSignatureDeclaration has parentTSInterfaceBody | TSTypeLiteral
  • TSClassImplements has parentClassDeclaration | ClassExpression
  • TSEnumMember has parentTSEnumDeclaration
  • TSIndexSignature has parentClassBody | TSInterfaceBody | TSTypeLiteral
  • TSInterfaceBody has parentTSInterfaceDeclaration
  • TSInterfaceHeritage has parentTSInterfaceBody
  • TSMethodSignature has parentTSInterfaceBody | TSTypeLiteral
  • TSModuleBlock has parentTSModuleDeclaration
  • TSParameterProperty has parentFunctionLike
  • TSPropertySignature has parentTSInterfaceBody | TSTypeLiteral
  • TSTypeParameter has parentTSInferType | TSTypeParameterDeclaration | TSMappedType
  • VariableDeclarator has parentVariableDeclaration (feat(typescript-estree): restrict variable declarator definite/init combinations #9228)

Note: the implementor should double check that I've written these correctly by comparing them against the AST types.

The import thing to note is that we shouldn't define all of the relationships that exist - just a subset of them that we can easily statically define and maintain. I'd probably put a rule around ~3 parent types being the maximum.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPRs and Issues about the AST structureaccepting 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.package: ast-specIssues related to @typescript-eslint/ast-spec

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp