Skip to content

[api] AST predicate APIs - #65590

Open
Andrew Branch (andrewbranch) wants to merge 34 commits into
microsoft:mainfrom
andrewbranch:ast-predicate-apis
Open

Andrew Branch (andrewbranch) wants to merge 34 commits into
microsoft:mainfrom
andrewbranch:ast-predicate-apis

Conversation

@andrewbranch

@andrewbranch Andrew Branch (andrewbranch) commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

These aren't auto-generated because they check multiple kinds for which there's no union type alias, or check additional properties or subtree structure.

  • isAutoAccessorPropertyDeclaration
  • isCallChain
  • isClassElement
  • isClassOrTypeElement
  • isConstTypeReference
  • isDeclarationStatement
  • isElementAccessChain
  • isEmptyBindingElement
  • isEmptyBindingPattern
  • isExternalModuleNameRelative
  • isFunctionLike
  • isFunctionOrConstructorTypeNode
  • isImportOrExportSpecifier
  • isIterationStatement
  • isJsxCallLike
  • isNonNullChain
  • isNullishCoalesce
  • isObjectLiteralElement
  • isOptionalChain
  • isParameterPropertyDeclaration
  • isPartOfTypeNode
  • isPartOfTypeOnlyImportOrExportDeclaration
  • isPropertyAccessChain
  • isPropertyAccessOrQualifiedName
  • isRestParameter
  • isStringLiteralOrJsxExpression
  • isStringTextContainingNode
  • isTypeElement
  • isTypeOnlyExportDeclaration
  • isTypeOnlyImportDeclaration
  • isTypeOnlyImportOrExportDeclaration

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The AST predicates omit JSDoc-specific declaration kinds and mishandle nameless array-binding elements, causing valid declarations to be filtered out and hole-only patterns to be misclassified.

2 open issues
What changed in this PR

Expands the TypeScript AST API with predicates for node classification, optional chains, binding patterns, and type-only declarations.

Changes:

  • Adds AST predicates and a relative module-name helper.
  • Introduces supporting types for narrowed predicate results.
  • Adds runtime and type-narrowing tests, including parsed-source coverage.
File Description
packages/​typescript/​test/​astPredicates.test.ts Tests predicate behavior and type narrowing.
packages/​typescript/​src/​ast/​utils.ts Adds relative module-name detection.
packages/​typescript/​src/​ast/​is.ts Implements the new AST predicates.
packages/​typescript/​src/​ast/​ast.ts Defines supporting branded types and type-only declaration unions.

Review effort: Balanced

Comment thread packages/typescript/src/ast/is.ts Resolved
Comment thread packages/typescript/src/ast/is.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the AST predicate and supporting type additions.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants