@eslint-react/ast 2.0.0-next.6 → 2.0.0-next.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +141 -219
- package/dist/index.js +531 -554
- package/package.json +8 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
2
|
+
import { unit } from "@eslint-react/eff";
|
|
3
|
+
import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
4
4
|
|
|
5
|
+
//#region src/array-index.d.ts
|
|
6
|
+
declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/array-method.d.ts
|
|
5
9
|
declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
6
10
|
declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/node-equal.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* Determines whether node equals to another node
|
|
15
|
+
* @param a node to compare
|
|
16
|
+
* @param b node to compare
|
|
17
|
+
* @returns `true` if node equal
|
|
18
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
19
|
+
*/
|
|
20
|
+
declare const isNodeEqual: {
|
|
21
|
+
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
22
|
+
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/node-format.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/node-is.d.ts
|
|
36
|
+
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
37
|
+
type: NodeType;
|
|
38
|
+
}>;
|
|
39
|
+
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
40
|
+
type: NodeTypes[number];
|
|
41
|
+
}>;
|
|
42
|
+
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
43
|
+
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
44
|
+
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
45
|
+
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
46
|
+
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
47
|
+
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
48
|
+
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
49
|
+
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
50
|
+
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
|
|
51
|
+
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
52
|
+
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
53
|
+
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/node-types.d.ts
|
|
10
56
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
11
57
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
12
58
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
@@ -19,151 +65,31 @@ type TSESTreeDestructuringPattern = TSESTree$1.ArrayPattern | TSESTree$1.Assignm
|
|
|
19
65
|
type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TSTypeAliasDeclaration;
|
|
20
66
|
type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
|
|
21
67
|
type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
33
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/class-id.d.ts
|
|
70
|
+
declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/expression-base.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Unwraps any type expressions to get the underlying JavaScript expression node.
|
|
75
|
+
* Recursively processes nodes until a non-type expression is found.
|
|
76
|
+
*
|
|
77
|
+
* @param node - The AST node to unwrap
|
|
78
|
+
* @returns The underlying JavaScript expression node
|
|
79
|
+
*/
|
|
80
|
+
declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/expression-is.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the given expression is a 'this' expression.
|
|
85
|
+
* Unwraps any type expressions before checking.
|
|
86
|
+
*
|
|
87
|
+
* @param node - The expression node to check
|
|
88
|
+
* @returns true if the expression is a ThisExpression, false otherwise
|
|
34
89
|
*/
|
|
35
|
-
declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
36
90
|
declare function isThisExpression(node: TSESTree.Expression): boolean;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Gets the static name of a function AST node. For function declarations it is
|
|
40
|
-
* easy. For anonymous function expressions it is much harder. If you search for
|
|
41
|
-
* `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
|
|
42
|
-
* where JS gives anonymous function expressions names. We roughly detect the
|
|
43
|
-
* same AST nodes with some exceptions to better fit our use case.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
47
|
-
|
|
48
|
-
type FunctionInitPath =
|
|
49
|
-
/**
|
|
50
|
-
* function Comp() { return <div />; }
|
|
51
|
-
*/
|
|
52
|
-
readonly [TSESTree.FunctionDeclaration]
|
|
53
|
-
/**
|
|
54
|
-
* const Comp = () => <div />;
|
|
55
|
-
* const Comp = function () { return <div />; };
|
|
56
|
-
*/
|
|
57
|
-
| readonly [
|
|
58
|
-
TSESTree.VariableDeclaration,
|
|
59
|
-
TSESTree.VariableDeclarator,
|
|
60
|
-
TSESTreeFunction
|
|
61
|
-
]
|
|
62
|
-
/**
|
|
63
|
-
* const Comp = React.memo(() => <div />);
|
|
64
|
-
* const Comp = React.forwardRef(() => <div />);
|
|
65
|
-
*/
|
|
66
|
-
| readonly [
|
|
67
|
-
TSESTree.VariableDeclaration,
|
|
68
|
-
TSESTree.VariableDeclarator,
|
|
69
|
-
TSESTree.CallExpression,
|
|
70
|
-
TSESTreeFunction
|
|
71
|
-
]
|
|
72
|
-
/**
|
|
73
|
-
* const Comp = React.memo(React.forwardRef(() => <div />));
|
|
74
|
-
*/
|
|
75
|
-
| readonly [
|
|
76
|
-
TSESTree.VariableDeclaration,
|
|
77
|
-
TSESTree.VariableDeclarator,
|
|
78
|
-
TSESTree.CallExpression,
|
|
79
|
-
TSESTree.CallExpression,
|
|
80
|
-
TSESTreeFunction
|
|
81
|
-
]
|
|
82
|
-
/**
|
|
83
|
-
* const Comps = {
|
|
84
|
-
* TopNav() { return <div />; },
|
|
85
|
-
* SidPanel: () => <div />,
|
|
86
|
-
* }
|
|
87
|
-
*/
|
|
88
|
-
| readonly [
|
|
89
|
-
TSESTree.VariableDeclaration,
|
|
90
|
-
TSESTree.VariableDeclarator,
|
|
91
|
-
TSESTree.ObjectExpression,
|
|
92
|
-
TSESTree.Property,
|
|
93
|
-
TSESTreeFunction
|
|
94
|
-
]
|
|
95
|
-
/**
|
|
96
|
-
* const Comps = {
|
|
97
|
-
* TopNav: React.memo(() => <div />),
|
|
98
|
-
* SidPanel: React.forwardRef(() => <div />),
|
|
99
|
-
* }
|
|
100
|
-
*/
|
|
101
|
-
| readonly [
|
|
102
|
-
TSESTree.VariableDeclaration,
|
|
103
|
-
TSESTree.VariableDeclarator,
|
|
104
|
-
TSESTree.ObjectExpression,
|
|
105
|
-
TSESTree.Property,
|
|
106
|
-
TSESTree.CallExpression,
|
|
107
|
-
TSESTreeFunction
|
|
108
|
-
]
|
|
109
|
-
/**
|
|
110
|
-
* const Comps = {
|
|
111
|
-
* TopNav: React.memo(React.forwardRef(() => <div />)),
|
|
112
|
-
* SidPanel: React.forwardRef(React.memo(() => <div />)),
|
|
113
|
-
* }
|
|
114
|
-
*/
|
|
115
|
-
| readonly [
|
|
116
|
-
TSESTree.VariableDeclaration,
|
|
117
|
-
TSESTree.VariableDeclarator,
|
|
118
|
-
TSESTree.ObjectExpression,
|
|
119
|
-
TSESTree.Property,
|
|
120
|
-
TSESTree.CallExpression,
|
|
121
|
-
TSESTree.CallExpression,
|
|
122
|
-
TSESTreeFunction
|
|
123
|
-
]
|
|
124
|
-
/**
|
|
125
|
-
* class Comp {
|
|
126
|
-
* TopNav() { return <div />; }
|
|
127
|
-
* }
|
|
128
|
-
*/
|
|
129
|
-
| readonly [
|
|
130
|
-
TSESTree.ClassDeclaration,
|
|
131
|
-
TSESTree.ClassBody,
|
|
132
|
-
TSESTree.MethodDefinition,
|
|
133
|
-
TSESTreeFunction
|
|
134
|
-
]
|
|
135
|
-
/**
|
|
136
|
-
* class Comp {
|
|
137
|
-
* TopNav = () => <div />;
|
|
138
|
-
* }
|
|
139
|
-
*/
|
|
140
|
-
| readonly [
|
|
141
|
-
TSESTree.ClassDeclaration,
|
|
142
|
-
TSESTree.ClassBody,
|
|
143
|
-
TSESTree.PropertyDefinition,
|
|
144
|
-
TSESTreeFunction
|
|
145
|
-
];
|
|
146
|
-
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
-
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
148
|
-
|
|
149
|
-
declare function isEmptyFunction(node: TSESTreeFunction): boolean;
|
|
150
|
-
declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Find the parent node that satisfies the test function
|
|
154
|
-
* @param node The AST node
|
|
155
|
-
* @param test The test function
|
|
156
|
-
* @returns The parent node that satisfies the test function or `_` if not found
|
|
157
|
-
*/
|
|
158
|
-
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, test: (n: TSESTree.Node) => n is A): A | _;
|
|
159
|
-
/**
|
|
160
|
-
* Find the parent node that satisfies the test function or `_` if not found
|
|
161
|
-
* @param node The AST node
|
|
162
|
-
* @param test The test function
|
|
163
|
-
* @returns The parent node that satisfies the test function
|
|
164
|
-
*/
|
|
165
|
-
declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
166
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/expression-nested.d.ts
|
|
167
93
|
/**
|
|
168
94
|
* Get all nested identifiers in a expression like node
|
|
169
95
|
* @param node The node to get the nested identifiers from
|
|
@@ -183,7 +109,7 @@ declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTr
|
|
|
183
109
|
* node, and it will return an array of all nested expressions of type T.
|
|
184
110
|
*/
|
|
185
111
|
declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
|
|
186
|
-
|
|
112
|
+
type: TNodeType;
|
|
187
113
|
}>[];
|
|
188
114
|
/**
|
|
189
115
|
* Get all nested new expressions in an expression like node
|
|
@@ -197,91 +123,87 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
|
|
|
197
123
|
* @returns All nested call expressions
|
|
198
124
|
*/
|
|
199
125
|
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type: NodeType;
|
|
203
|
-
}>;
|
|
204
|
-
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
205
|
-
type: NodeTypes[number];
|
|
206
|
-
}>;
|
|
207
|
-
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
208
|
-
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
209
|
-
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
210
|
-
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
211
|
-
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
212
|
-
declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
213
|
-
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
214
|
-
declare const isArrayTupleType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSArrayType | TSESTree.TSTupleType;
|
|
215
|
-
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
216
|
-
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
217
|
-
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
218
|
-
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
219
|
-
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
|
|
220
|
-
declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayPattern | TSESTree.AssignmentPattern | TSESTree.ObjectPattern | TSESTree.RestElement;
|
|
221
|
-
declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
|
|
222
|
-
declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
|
|
223
|
-
declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
|
|
224
|
-
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
225
|
-
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
226
|
-
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/function-id.d.ts
|
|
227
128
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
129
|
+
* Gets the static name of a function AST node. For function declarations it is
|
|
130
|
+
* easy. For anonymous function expressions it is much harder. If you search for
|
|
131
|
+
* `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
|
|
132
|
+
* where JS gives anonymous function expressions names. We roughly detect the
|
|
133
|
+
* same AST nodes with some exceptions to better fit our use case.
|
|
231
134
|
*/
|
|
232
|
-
declare function
|
|
135
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/function-init-path.d.ts
|
|
233
138
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* @returns boolean
|
|
139
|
+
* Represents various AST paths for React component function declarations.
|
|
140
|
+
* Each tuple type represents a specific component definition pattern.
|
|
237
141
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
142
|
+
type FunctionInitPath = readonly [TSESTree.FunctionDeclaration] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
|
|
143
|
+
/**
|
|
144
|
+
* Identifies the initialization path of a function node in the AST.
|
|
145
|
+
* Determines what kind of component declaration pattern the function belongs to.
|
|
146
|
+
*
|
|
147
|
+
* @param node - The function node to analyze
|
|
148
|
+
* @returns The function initialization path or unit if not identifiable
|
|
149
|
+
*/
|
|
150
|
+
declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
|
|
151
|
+
/**
|
|
152
|
+
* Checks if a specific function call exists in the function initialization path.
|
|
153
|
+
* Useful for detecting HOCs like React.memo, React.forwardRef, etc.
|
|
154
|
+
*
|
|
155
|
+
* @param callName - The name of the call to check for (e.g., "memo", "forwardRef")
|
|
156
|
+
* @param initPath - The function initialization path to search in
|
|
157
|
+
* @returns True if the call exists in the path, false otherwise
|
|
158
|
+
*/
|
|
159
|
+
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/function-is.d.ts
|
|
162
|
+
declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
|
|
163
|
+
declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/literal.d.ts
|
|
240
166
|
declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
|
|
241
167
|
declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
|
|
242
168
|
declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
|
|
243
169
|
declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
|
|
244
170
|
declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
|
|
245
171
|
declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
|
|
246
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/misc.d.ts
|
|
247
174
|
/**
|
|
248
|
-
*
|
|
249
|
-
* @param
|
|
250
|
-
* @
|
|
251
|
-
* @returns `true` if node equal
|
|
252
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
175
|
+
* Check if a node is multiline
|
|
176
|
+
* @param node The AST node to check
|
|
177
|
+
* @returns `true` if the node is multiline
|
|
253
178
|
*/
|
|
254
|
-
declare
|
|
255
|
-
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
256
|
-
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
257
|
-
};
|
|
258
|
-
|
|
179
|
+
declare function isMultiLine(node: TSESTree.Node): boolean;
|
|
259
180
|
/**
|
|
260
|
-
* Check if
|
|
261
|
-
* @param node The AST node
|
|
262
|
-
* @returns
|
|
181
|
+
* Check if a node is a line break
|
|
182
|
+
* @param node The AST node to check
|
|
183
|
+
* @returns boolean
|
|
263
184
|
*/
|
|
264
|
-
declare function
|
|
185
|
+
declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/promise-then.d.ts
|
|
188
|
+
declare function isThenCall(node: TSESTree.CallExpression): boolean;
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/property-name.d.ts
|
|
191
|
+
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/traverse-up.d.ts
|
|
265
194
|
/**
|
|
266
|
-
*
|
|
195
|
+
* Find the parent node that satisfies the test function
|
|
267
196
|
* @param node The AST node
|
|
268
|
-
* @param
|
|
269
|
-
* @
|
|
270
|
-
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
|
|
197
|
+
* @param test The test function
|
|
198
|
+
* @returns The parent node that satisfies the test function or `_` if not found
|
|
271
199
|
*/
|
|
272
|
-
declare function
|
|
273
|
-
|
|
274
|
-
declare function getPropertyName(node: TSESTree.Node): string | _;
|
|
275
|
-
|
|
276
|
-
declare function isThenCall(node: TSESTree.CallExpression): boolean;
|
|
277
|
-
|
|
278
|
-
declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
200
|
+
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
|
|
279
201
|
/**
|
|
280
|
-
*
|
|
281
|
-
* @param node AST node
|
|
282
|
-
* @param
|
|
283
|
-
* @returns
|
|
202
|
+
* Find the parent node that satisfies the test function or `_` if not found
|
|
203
|
+
* @param node The AST node
|
|
204
|
+
* @param test The test function
|
|
205
|
+
* @returns The parent node that satisfies the test function
|
|
284
206
|
*/
|
|
285
|
-
declare function
|
|
286
|
-
|
|
287
|
-
export {
|
|
207
|
+
declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
|
|
208
|
+
//#endregion
|
|
209
|
+
export { FunctionInitPath, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
|