Skip to content

Commit 6417c48

Browse files
andrewbranchCopilotRyanCavanaugh
authored
[api] AST predicate APIs (#65590)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
1 parent f4eb8d7 commit 6417c48

4 files changed

Lines changed: 902 additions & 0 deletions

File tree

‎packages/typescript/src/ast/ast.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,39 @@ import { SyntaxKind } from "../../enums/syntaxKind.js";
1010
import type {
1111
AssertionExpression,
1212
BindingElement,
13+
BindingPattern,
14+
CallExpression,
1315
CaseClause,
1416
ComputedPropertyName,
1517
Decorator,
1618
DoStatement,
19+
ElementAccessExpression,
1720
EndOfFile,
1821
EntityName,
1922
EnumMember,
23+
ExportDeclaration,
24+
ExportSpecifier,
2025
Expression,
2126
ExpressionStatement,
2227
ForInStatement,
2328
ForOfStatement,
2429
ForStatement,
2530
Identifier,
2631
IfStatement,
32+
ImportClause,
33+
ImportEqualsDeclaration,
34+
ImportSpecifier,
2735
JSDoc,
2836
JsxAttribute,
2937
JsxExpression,
3038
JsxSpreadAttribute,
3139
KeywordSyntaxKind,
3240
ModifierSyntaxKind,
41+
NamedExports,
42+
NamedImports,
43+
NamespaceExport,
44+
NamespaceImport,
45+
NonNullExpression,
3346
ParameterDeclaration,
3447
PropertyAccessExpression,
3548
PropertyAssignment,
@@ -58,6 +71,59 @@ export { TokenFlags } from "../../enums/tokenFlags.js";
5871
export * from "./ast.generated.ts";
5972
export * as factory from "./factory.generated.ts";
6073

74+
declare const autoAccessorBrand: unique symbol;
75+
export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration {
76+
readonly [autoAccessorBrand]: void;
77+
}
78+
79+
declare const optionalChainBrand: unique symbol;
80+
export interface CallChain extends CallExpression {
81+
readonly [optionalChainBrand]: void;
82+
}
83+
84+
export interface ElementAccessChain extends ElementAccessExpression {
85+
readonly [optionalChainBrand]: void;
86+
}
87+
88+
declare const emptyBindingPatternBrand: unique symbol;
89+
export type EmptyBindingPattern = BindingPattern & { readonly [emptyBindingPatternBrand]: void; };
90+
91+
export interface NonNullChain extends NonNullExpression {
92+
readonly [optionalChainBrand]: void;
93+
}
94+
95+
export interface PropertyAccessChain extends PropertyAccessExpression {
96+
readonly [optionalChainBrand]: void;
97+
}
98+
99+
export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain;
100+
101+
declare const parameterPropertyBrand: unique symbol;
102+
export interface ParameterPropertyDeclaration extends ParameterDeclaration {
103+
readonly [parameterPropertyBrand]: void;
104+
}
105+
106+
export type TypeOnlyImportDeclaration =
107+
| ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }
108+
| ImportEqualsDeclaration & { readonly isTypeOnly: true; }
109+
| NamespaceImport & { readonly parent: ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }
110+
| ImportSpecifier
111+
& (
112+
| { readonly isTypeOnly: true; }
113+
| { readonly parent: NamedImports & { readonly parent: ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }; }
114+
);
115+
116+
export type TypeOnlyExportDeclaration =
117+
| ExportSpecifier
118+
& (
119+
| { readonly isTypeOnly: true; }
120+
| { readonly parent: NamedExports & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true; }; }; }
121+
)
122+
| ExportDeclaration & { readonly isTypeOnly: true; readonly moduleSpecifier: Expression; readonly exportClause?: undefined; }
123+
| NamespaceExport & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true; }; };
124+
125+
export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration;
126+
61127
// ── Core types ──
62128

63129
declare const rootedPathBrand: unique symbol;

0 commit comments

Comments
 (0)