/
visitor-keys.ts
148 lines (138 loc) · 5.16 KB
/
visitor-keys.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
import * as eslintVisitorKeys from 'eslint-visitor-keys';
interface VisitorKeys {
readonly [type: string]: readonly string[] | undefined;
}
type GetNodeTypeKeys<T extends AST_NODE_TYPES> = Exclude<
keyof Extract<TSESTree.Node, { type: T }>,
'type' | 'loc' | 'range' | 'parent'
>;
// strictly type the arrays of keys provided to make sure we keep this config in sync with the type defs
type AdditionalKeys = {
readonly [T in AST_NODE_TYPES]?: readonly GetNodeTypeKeys<T>[];
};
const additionalKeys: AdditionalKeys = {
// ES2020
ImportExpression: ['source'],
// Additional Properties.
ArrayPattern: ['decorators', 'elements', 'typeAnnotation'],
ArrowFunctionExpression: ['typeParameters', 'params', 'returnType', 'body'],
AssignmentPattern: ['decorators', 'left', 'right', 'typeAnnotation'],
CallExpression: ['callee', 'typeParameters', 'arguments'],
ClassDeclaration: [
'decorators',
'id',
'typeParameters',
'superClass',
'superTypeParameters',
'implements',
'body',
],
ClassExpression: [
'decorators',
'id',
'typeParameters',
'superClass',
'superTypeParameters',
'implements',
'body',
],
FunctionDeclaration: ['id', 'typeParameters', 'params', 'returnType', 'body'],
FunctionExpression: ['id', 'typeParameters', 'params', 'returnType', 'body'],
Identifier: ['decorators', 'typeAnnotation'],
MethodDefinition: ['decorators', 'key', 'value'],
NewExpression: ['callee', 'typeParameters', 'arguments'],
ObjectPattern: ['decorators', 'properties', 'typeAnnotation'],
RestElement: ['decorators', 'argument', 'typeAnnotation'],
TaggedTemplateExpression: ['tag', 'typeParameters', 'quasi'],
// JSX
JSXOpeningElement: ['name', 'typeParameters', 'attributes'],
JSXClosingFragment: [],
JSXOpeningFragment: [],
JSXSpreadChild: ['expression'],
// Additional Nodes.
ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
Decorator: ['expression'],
// TS-prefixed nodes
TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'],
TSAbstractKeyword: [],
TSAbstractMethodDefinition: ['key', 'value'],
TSAnyKeyword: [],
TSArrayType: ['elementType'],
TSAsExpression: ['expression', 'typeAnnotation'],
TSAsyncKeyword: [],
TSBigIntKeyword: [],
TSBooleanKeyword: [],
TSCallSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
TSClassImplements: ['expression', 'typeParameters'],
TSConditionalType: ['checkType', 'extendsType', 'trueType', 'falseType'],
TSConstructorType: ['typeParameters', 'params', 'returnType'],
TSConstructSignatureDeclaration: ['typeParameters', 'params', 'returnType'],
TSDeclareFunction: ['id', 'typeParameters', 'params', 'returnType', 'body'],
TSDeclareKeyword: [],
TSEmptyBodyFunctionExpression: [
'id',
'typeParameters',
'params',
'returnType',
],
TSEnumDeclaration: ['id', 'members'],
TSEnumMember: ['id', 'initializer'],
TSExportAssignment: ['expression'],
TSExportKeyword: [],
TSExternalModuleReference: ['expression'],
TSFunctionType: ['typeParameters', 'params', 'returnType'],
TSImportEqualsDeclaration: ['id', 'moduleReference'],
TSImportType: ['parameter', 'qualifier', 'typeParameters'],
TSIndexedAccessType: ['indexType', 'objectType'],
TSIndexSignature: ['parameters', 'typeAnnotation'],
TSInferType: ['typeParameter'],
TSInterfaceBody: ['body'],
TSInterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'],
TSInterfaceHeritage: ['expression', 'typeParameters'],
TSIntersectionType: ['types'],
TSLiteralType: ['literal'],
TSMappedType: ['typeParameter', 'typeAnnotation'],
TSMethodSignature: ['typeParameters', 'key', 'params', 'returnType'],
TSModuleBlock: ['body'],
TSModuleDeclaration: ['id', 'body'],
TSNamedTupleMember: ['elementType'],
TSNamespaceExportDeclaration: ['id'],
TSNeverKeyword: [],
TSNonNullExpression: ['expression'],
TSNullKeyword: [],
TSNumberKeyword: [],
TSObjectKeyword: [],
TSOptionalType: ['typeAnnotation'],
TSParameterProperty: ['decorators', 'parameter'],
TSParenthesizedType: ['typeAnnotation'],
TSPrivateKeyword: [],
TSPropertySignature: ['typeAnnotation', 'key', 'initializer'],
TSProtectedKeyword: [],
TSPublicKeyword: [],
TSQualifiedName: ['left', 'right'],
TSReadonlyKeyword: [],
TSRestType: ['typeAnnotation'],
TSStaticKeyword: [],
TSStringKeyword: [],
TSSymbolKeyword: [],
TSThisType: [],
TSTupleType: ['elementTypes'],
TSTypeAliasDeclaration: ['id', 'typeParameters', 'typeAnnotation'],
TSTypeAnnotation: ['typeAnnotation'],
TSTypeAssertion: ['typeAnnotation', 'expression'],
TSTypeLiteral: ['members'],
TSTypeOperator: ['typeAnnotation'],
TSTypeParameter: ['name', 'constraint', 'default'],
TSTypeParameterDeclaration: ['params'],
TSTypeParameterInstantiation: ['params'],
TSTypePredicate: ['typeAnnotation', 'parameterName'],
TSTypeQuery: ['exprName'],
TSTypeReference: ['typeName', 'typeParameters'],
TSUndefinedKeyword: [],
TSUnionType: ['types'],
TSUnknownKeyword: [],
TSVoidKeyword: [],
} as const;
const visitorKeys: VisitorKeys = eslintVisitorKeys.unionWith(additionalKeys);
export { visitorKeys, VisitorKeys };