UNPKG

12.5 kBTypeScriptView Raw
1import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
2import * as ts from 'typescript';
3import { TSNode } from './ts-nodes';
4export interface EstreeToTsNodeTypes {
5 [AST_NODE_TYPES.ArrayExpression]: ts.ArrayLiteralExpression;
6 [AST_NODE_TYPES.ArrayPattern]: ts.ArrayLiteralExpression | ts.ArrayBindingPattern;
7 [AST_NODE_TYPES.ArrowFunctionExpression]: ts.ArrowFunction;
8 [AST_NODE_TYPES.AssignmentExpression]: ts.BinaryExpression;
9 [AST_NODE_TYPES.AssignmentPattern]: ts.ShorthandPropertyAssignment | ts.BindingElement | ts.BinaryExpression | ts.ParameterDeclaration;
10 [AST_NODE_TYPES.AwaitExpression]: ts.AwaitExpression;
11 [AST_NODE_TYPES.BinaryExpression]: ts.BinaryExpression;
12 [AST_NODE_TYPES.BlockStatement]: ts.Block;
13 [AST_NODE_TYPES.BreakStatement]: ts.BreakStatement;
14 [AST_NODE_TYPES.CallExpression]: ts.CallExpression;
15 [AST_NODE_TYPES.CatchClause]: ts.CatchClause;
16 [AST_NODE_TYPES.ChainExpression]: ts.CallExpression | ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.NonNullExpression;
17 [AST_NODE_TYPES.ClassBody]: ts.ClassDeclaration | ts.ClassExpression;
18 [AST_NODE_TYPES.ClassDeclaration]: ts.ClassDeclaration;
19 [AST_NODE_TYPES.ClassExpression]: ts.ClassExpression;
20 [AST_NODE_TYPES.ClassProperty]: ts.PropertyDeclaration;
21 [AST_NODE_TYPES.ConditionalExpression]: ts.ConditionalExpression;
22 [AST_NODE_TYPES.ContinueStatement]: ts.ContinueStatement;
23 [AST_NODE_TYPES.DebuggerStatement]: ts.DebuggerStatement;
24 [AST_NODE_TYPES.Decorator]: ts.Decorator;
25 [AST_NODE_TYPES.DoWhileStatement]: ts.DoStatement;
26 [AST_NODE_TYPES.EmptyStatement]: ts.EmptyStatement;
27 [AST_NODE_TYPES.ExportAllDeclaration]: ts.ExportDeclaration;
28 [AST_NODE_TYPES.ExportDefaultDeclaration]: ts.ExportAssignment | ts.FunctionDeclaration | ts.VariableStatement | ts.ClassDeclaration | ts.ClassExpression | ts.TypeAliasDeclaration | ts.InterfaceDeclaration | ts.EnumDeclaration | ts.ModuleDeclaration;
29 [AST_NODE_TYPES.ExportNamedDeclaration]: ts.ExportDeclaration | ts.FunctionDeclaration | ts.VariableStatement | ts.ClassDeclaration | ts.ClassExpression | ts.TypeAliasDeclaration | ts.InterfaceDeclaration | ts.EnumDeclaration | ts.ModuleDeclaration;
30 [AST_NODE_TYPES.ExportSpecifier]: ts.ExportSpecifier;
31 [AST_NODE_TYPES.ExpressionStatement]: ts.ExpressionStatement;
32 [AST_NODE_TYPES.ForInStatement]: ts.ForInStatement;
33 [AST_NODE_TYPES.ForOfStatement]: ts.ForOfStatement;
34 [AST_NODE_TYPES.ForStatement]: ts.ForStatement;
35 [AST_NODE_TYPES.FunctionDeclaration]: ts.FunctionDeclaration;
36 [AST_NODE_TYPES.FunctionExpression]: ts.FunctionExpression | ts.ConstructorDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.MethodDeclaration;
37 [AST_NODE_TYPES.Identifier]: ts.Identifier | ts.ConstructorDeclaration | ts.Token<ts.SyntaxKind.NewKeyword | ts.SyntaxKind.ImportKeyword>;
38 [AST_NODE_TYPES.IfStatement]: ts.IfStatement;
39 [AST_NODE_TYPES.ImportDeclaration]: ts.ImportDeclaration;
40 [AST_NODE_TYPES.ImportDefaultSpecifier]: ts.ImportClause;
41 [AST_NODE_TYPES.ImportExpression]: ts.CallExpression;
42 [AST_NODE_TYPES.ImportNamespaceSpecifier]: ts.NamespaceImport;
43 [AST_NODE_TYPES.ImportSpecifier]: ts.ImportSpecifier;
44 [AST_NODE_TYPES.JSXAttribute]: ts.JsxAttribute;
45 [AST_NODE_TYPES.JSXClosingElement]: ts.JsxClosingElement;
46 [AST_NODE_TYPES.JSXClosingFragment]: ts.JsxClosingFragment;
47 [AST_NODE_TYPES.JSXElement]: ts.JsxElement | ts.JsxSelfClosingElement;
48 [AST_NODE_TYPES.JSXEmptyExpression]: ts.JsxExpression;
49 [AST_NODE_TYPES.JSXExpressionContainer]: ts.JsxExpression;
50 [AST_NODE_TYPES.JSXFragment]: ts.JsxFragment;
51 [AST_NODE_TYPES.JSXIdentifier]: ts.Identifier | ts.ThisExpression;
52 [AST_NODE_TYPES.JSXOpeningElement]: ts.JsxOpeningElement | ts.JsxSelfClosingElement;
53 [AST_NODE_TYPES.JSXOpeningFragment]: ts.JsxOpeningFragment;
54 [AST_NODE_TYPES.JSXSpreadAttribute]: ts.JsxSpreadAttribute;
55 [AST_NODE_TYPES.JSXSpreadChild]: ts.JsxExpression;
56 [AST_NODE_TYPES.JSXMemberExpression]: ts.PropertyAccessExpression;
57 [AST_NODE_TYPES.JSXNamespacedName]: ts.Identifier | ts.ThisExpression;
58 [AST_NODE_TYPES.JSXText]: ts.JsxText;
59 [AST_NODE_TYPES.LabeledStatement]: ts.LabeledStatement;
60 [AST_NODE_TYPES.Literal]: ts.StringLiteral | ts.NumericLiteral | ts.RegularExpressionLiteral | ts.JsxText | ts.NullLiteral | ts.BooleanLiteral | ts.BigIntLiteral;
61 [AST_NODE_TYPES.LogicalExpression]: ts.BinaryExpression;
62 [AST_NODE_TYPES.MemberExpression]: ts.PropertyAccessExpression | ts.ElementAccessExpression;
63 [AST_NODE_TYPES.MetaProperty]: ts.MetaProperty;
64 [AST_NODE_TYPES.MethodDefinition]: ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.MethodDeclaration | ts.ConstructorDeclaration;
65 [AST_NODE_TYPES.NewExpression]: ts.NewExpression;
66 [AST_NODE_TYPES.ObjectExpression]: ts.ObjectLiteralExpression;
67 [AST_NODE_TYPES.ObjectPattern]: ts.ObjectLiteralExpression | ts.ObjectBindingPattern;
68 [AST_NODE_TYPES.Program]: ts.SourceFile;
69 [AST_NODE_TYPES.Property]: ts.PropertyAssignment | ts.ShorthandPropertyAssignment | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.MethodDeclaration | ts.BindingElement;
70 [AST_NODE_TYPES.RestElement]: ts.BindingElement | ts.SpreadAssignment | ts.SpreadElement | ts.ParameterDeclaration;
71 [AST_NODE_TYPES.ReturnStatement]: ts.ReturnStatement;
72 [AST_NODE_TYPES.SequenceExpression]: ts.BinaryExpression;
73 [AST_NODE_TYPES.SpreadElement]: ts.SpreadElement | ts.SpreadAssignment;
74 [AST_NODE_TYPES.Super]: ts.SuperExpression;
75 [AST_NODE_TYPES.SwitchCase]: ts.CaseClause | ts.DefaultClause;
76 [AST_NODE_TYPES.SwitchStatement]: ts.SwitchStatement;
77 [AST_NODE_TYPES.TaggedTemplateExpression]: ts.TaggedTemplateExpression;
78 [AST_NODE_TYPES.TemplateElement]: ts.NoSubstitutionTemplateLiteral | ts.TemplateHead | ts.TemplateMiddle | ts.TemplateTail;
79 [AST_NODE_TYPES.TemplateLiteral]: ts.NoSubstitutionTemplateLiteral | ts.TemplateExpression;
80 [AST_NODE_TYPES.ThisExpression]: ts.ThisExpression | ts.KeywordTypeNode;
81 [AST_NODE_TYPES.ThrowStatement]: ts.ThrowStatement;
82 [AST_NODE_TYPES.TryStatement]: ts.TryStatement;
83 [AST_NODE_TYPES.TSAbstractClassProperty]: ts.PropertyDeclaration;
84 [AST_NODE_TYPES.TSAbstractMethodDefinition]: ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.MethodDeclaration | ts.ConstructorDeclaration;
85 [AST_NODE_TYPES.TSArrayType]: ts.ArrayTypeNode;
86 [AST_NODE_TYPES.TSAsExpression]: ts.AsExpression;
87 [AST_NODE_TYPES.TSCallSignatureDeclaration]: ts.CallSignatureDeclaration;
88 [AST_NODE_TYPES.TSClassImplements]: ts.ExpressionWithTypeArguments;
89 [AST_NODE_TYPES.TSConditionalType]: ts.ConditionalTypeNode;
90 [AST_NODE_TYPES.TSConstructorType]: ts.ConstructorTypeNode;
91 [AST_NODE_TYPES.TSConstructSignatureDeclaration]: ts.ConstructSignatureDeclaration;
92 [AST_NODE_TYPES.TSDeclareFunction]: ts.FunctionDeclaration;
93 [AST_NODE_TYPES.TSEnumDeclaration]: ts.EnumDeclaration;
94 [AST_NODE_TYPES.TSEnumMember]: ts.EnumMember;
95 [AST_NODE_TYPES.TSExportAssignment]: ts.ExportAssignment;
96 [AST_NODE_TYPES.TSExternalModuleReference]: ts.ExternalModuleReference;
97 [AST_NODE_TYPES.TSFunctionType]: ts.FunctionTypeNode;
98 [AST_NODE_TYPES.TSImportEqualsDeclaration]: ts.ImportEqualsDeclaration;
99 [AST_NODE_TYPES.TSImportType]: ts.ImportTypeNode;
100 [AST_NODE_TYPES.TSIndexedAccessType]: ts.IndexedAccessTypeNode;
101 [AST_NODE_TYPES.TSIndexSignature]: ts.IndexSignatureDeclaration;
102 [AST_NODE_TYPES.TSInferType]: ts.InferTypeNode;
103 [AST_NODE_TYPES.TSInterfaceDeclaration]: ts.InterfaceDeclaration;
104 [AST_NODE_TYPES.TSInterfaceBody]: ts.InterfaceDeclaration;
105 [AST_NODE_TYPES.TSInterfaceHeritage]: ts.ExpressionWithTypeArguments;
106 [AST_NODE_TYPES.TSIntersectionType]: ts.IntersectionTypeNode;
107 [AST_NODE_TYPES.TSLiteralType]: ts.LiteralTypeNode;
108 [AST_NODE_TYPES.TSMappedType]: ts.MappedTypeNode;
109 [AST_NODE_TYPES.TSMethodSignature]: ts.MethodSignature | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration;
110 [AST_NODE_TYPES.TSModuleBlock]: ts.ModuleBlock;
111 [AST_NODE_TYPES.TSModuleDeclaration]: ts.ModuleDeclaration;
112 [AST_NODE_TYPES.TSNamedTupleMember]: ts.NamedTupleMember;
113 [AST_NODE_TYPES.TSNamespaceExportDeclaration]: ts.NamespaceExportDeclaration;
114 [AST_NODE_TYPES.TSNonNullExpression]: ts.NonNullExpression;
115 [AST_NODE_TYPES.TSOptionalType]: ts.OptionalTypeNode;
116 [AST_NODE_TYPES.TSParameterProperty]: ts.ParameterDeclaration;
117 [AST_NODE_TYPES.TSParenthesizedType]: ts.ParenthesizedTypeNode;
118 [AST_NODE_TYPES.TSPropertySignature]: ts.PropertySignature;
119 [AST_NODE_TYPES.TSQualifiedName]: ts.QualifiedName;
120 [AST_NODE_TYPES.TSRestType]: ts.RestTypeNode | ts.NamedTupleMember;
121 [AST_NODE_TYPES.TSThisType]: ts.ThisTypeNode;
122 [AST_NODE_TYPES.TSTupleType]: ts.TupleTypeNode;
123 [AST_NODE_TYPES.TSTemplateLiteralType]: ts.TemplateLiteralTypeNode;
124 [AST_NODE_TYPES.TSTypeAliasDeclaration]: ts.TypeAliasDeclaration;
125 [AST_NODE_TYPES.TSTypeAnnotation]: undefined;
126 [AST_NODE_TYPES.TSTypeAssertion]: ts.TypeAssertion;
127 [AST_NODE_TYPES.TSTypeLiteral]: ts.TypeLiteralNode;
128 [AST_NODE_TYPES.TSTypeOperator]: ts.TypeOperatorNode;
129 [AST_NODE_TYPES.TSTypeParameter]: ts.TypeParameterDeclaration;
130 [AST_NODE_TYPES.TSTypeParameterDeclaration]: undefined;
131 [AST_NODE_TYPES.TSTypeParameterInstantiation]: ts.TaggedTemplateExpression | ts.ImportTypeNode | ts.ExpressionWithTypeArguments | ts.TypeReferenceNode | ts.JsxOpeningElement | ts.JsxSelfClosingElement | ts.NewExpression | ts.CallExpression;
132 [AST_NODE_TYPES.TSTypePredicate]: ts.TypePredicateNode;
133 [AST_NODE_TYPES.TSTypeQuery]: ts.TypeQueryNode;
134 [AST_NODE_TYPES.TSTypeReference]: ts.TypeReferenceNode;
135 [AST_NODE_TYPES.TSUnionType]: ts.UnionTypeNode;
136 [AST_NODE_TYPES.UpdateExpression]: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression;
137 [AST_NODE_TYPES.UnaryExpression]: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression | ts.DeleteExpression | ts.VoidExpression | ts.TypeOfExpression;
138 [AST_NODE_TYPES.VariableDeclaration]: ts.VariableDeclarationList | ts.VariableStatement;
139 [AST_NODE_TYPES.VariableDeclarator]: ts.VariableDeclaration;
140 [AST_NODE_TYPES.WhileStatement]: ts.WhileStatement;
141 [AST_NODE_TYPES.WithStatement]: ts.WithStatement;
142 [AST_NODE_TYPES.YieldExpression]: ts.YieldExpression;
143 [AST_NODE_TYPES.TSEmptyBodyFunctionExpression]: ts.FunctionExpression | ts.ConstructorDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.MethodDeclaration;
144 [AST_NODE_TYPES.TSAbstractKeyword]: ts.Token<ts.SyntaxKind.AbstractKeyword>;
145 [AST_NODE_TYPES.TSNullKeyword]: ts.NullLiteral | ts.KeywordTypeNode;
146 [AST_NODE_TYPES.TSAnyKeyword]: ts.KeywordTypeNode;
147 [AST_NODE_TYPES.TSBigIntKeyword]: ts.KeywordTypeNode;
148 [AST_NODE_TYPES.TSBooleanKeyword]: ts.KeywordTypeNode;
149 [AST_NODE_TYPES.TSIntrinsicKeyword]: ts.KeywordTypeNode;
150 [AST_NODE_TYPES.TSNeverKeyword]: ts.KeywordTypeNode;
151 [AST_NODE_TYPES.TSNumberKeyword]: ts.KeywordTypeNode;
152 [AST_NODE_TYPES.TSObjectKeyword]: ts.KeywordTypeNode;
153 [AST_NODE_TYPES.TSStringKeyword]: ts.KeywordTypeNode;
154 [AST_NODE_TYPES.TSSymbolKeyword]: ts.KeywordTypeNode;
155 [AST_NODE_TYPES.TSUnknownKeyword]: ts.KeywordTypeNode;
156 [AST_NODE_TYPES.TSVoidKeyword]: ts.KeywordTypeNode;
157 [AST_NODE_TYPES.TSUndefinedKeyword]: ts.KeywordTypeNode;
158 [AST_NODE_TYPES.TSAsyncKeyword]: ts.Token<ts.SyntaxKind.AsyncKeyword>;
159 [AST_NODE_TYPES.TSDeclareKeyword]: ts.Token<ts.SyntaxKind.DeclareKeyword>;
160 [AST_NODE_TYPES.TSExportKeyword]: ts.Token<ts.SyntaxKind.ExportKeyword>;
161 [AST_NODE_TYPES.TSStaticKeyword]: ts.Token<ts.SyntaxKind.StaticKeyword>;
162 [AST_NODE_TYPES.TSPublicKeyword]: ts.Token<ts.SyntaxKind.PublicKeyword>;
163 [AST_NODE_TYPES.TSPrivateKeyword]: ts.Token<ts.SyntaxKind.PrivateKeyword>;
164 [AST_NODE_TYPES.TSProtectedKeyword]: ts.Token<ts.SyntaxKind.ProtectedKeyword>;
165 [AST_NODE_TYPES.TSReadonlyKeyword]: ts.Token<ts.SyntaxKind.ReadonlyKeyword>;
166}
167/**
168 * Maps TSESTree AST Node type to the expected TypeScript AST Node type(s).
169 * This mapping is based on the internal logic of the parser.
170 */
171export declare type TSESTreeToTSNode<T extends TSESTree.Node = TSESTree.Node> = Extract<TSNode | ts.Token<ts.SyntaxKind.NewKeyword | ts.SyntaxKind.ImportKeyword>, EstreeToTsNodeTypes[T['type']]>;
172//# sourceMappingURL=estree-to-ts-node-types.d.ts.map
\No newline at end of file