@eslint-react/ast 2.8.2-next.5 → 2.8.3-beta.7
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 +156 -0
- package/dist/index.js +100 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,18 +3,57 @@ import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
|
3
3
|
import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Represents function expressions and declarations in TSESTree
|
|
8
|
+
*/
|
|
6
9
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
10
|
+
/**
|
|
11
|
+
* Represents all function-related types including TypeScript function types
|
|
12
|
+
*/
|
|
7
13
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Represents class declarations and expressions in TSESTree
|
|
16
|
+
*/
|
|
8
17
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
18
|
+
/**
|
|
19
|
+
* Represents method definitions and property definitions in classes
|
|
20
|
+
*/
|
|
9
21
|
type TSESTreeMethodOrProperty = TSESTree$1.PropertyDefinition | TSESTree$1.MethodDefinition;
|
|
22
|
+
/**
|
|
23
|
+
* Represents loop statements in TSESTree
|
|
24
|
+
*/
|
|
10
25
|
type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
|
|
26
|
+
/**
|
|
27
|
+
* Represents TypeScript array and tuple types
|
|
28
|
+
*/
|
|
11
29
|
type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
30
|
+
/**
|
|
31
|
+
* Represents property-like nodes in TSESTree
|
|
32
|
+
*/
|
|
12
33
|
type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
|
|
34
|
+
/**
|
|
35
|
+
* Represents all JSX-related nodes in TSESTree
|
|
36
|
+
*/
|
|
13
37
|
type TSESTreeJSX = TSESTree$1.JSXAttribute | TSESTree$1.JSXChild | TSESTree$1.JSXClosingElement | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXElement | TSESTree$1.JSXEmptyExpression | TSESTree$1.JSXExpression | TSESTree$1.JSXExpressionContainer | TSESTree$1.JSXFragment | TSESTree$1.JSXIdentifier | TSESTree$1.JSXIdentifierToken | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXSpreadAttribute | TSESTree$1.JSXSpreadChild | TSESTree$1.JSXTagNameExpression | TSESTree$1.JSXText | TSESTree$1.JSXTextToken;
|
|
38
|
+
/**
|
|
39
|
+
* Represents JSX attribute-like nodes (attributes and spread attributes)
|
|
40
|
+
*/
|
|
14
41
|
type TSESTreeJSXAttributeLike = TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute;
|
|
42
|
+
/**
|
|
43
|
+
* Represents destructuring patterns in variable declarations
|
|
44
|
+
*/
|
|
15
45
|
type TSESTreeDestructuringPattern = TSESTree$1.ArrayPattern | TSESTree$1.AssignmentPattern | TSESTree$1.ObjectPattern | TSESTree$1.RestElement;
|
|
46
|
+
/**
|
|
47
|
+
* Represents TypeScript type declaration nodes
|
|
48
|
+
*/
|
|
16
49
|
type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TSTypeAliasDeclaration;
|
|
50
|
+
/**
|
|
51
|
+
* Represents TypeScript type expression nodes (type assertions, non-null expressions, etc.)
|
|
52
|
+
*/
|
|
17
53
|
type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
|
|
54
|
+
/**
|
|
55
|
+
* Represents TypeScript type assertion expressions (excluding instantiation expressions)
|
|
56
|
+
*/
|
|
18
57
|
type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
19
58
|
//#endregion
|
|
20
59
|
//#region src/class-id.d.ts
|
|
@@ -158,6 +197,9 @@ declare function getFunctionDirectives(node: TSESTreeFunction): TSESTree.StringL
|
|
|
158
197
|
* same AST nodes with some exceptions to better fit our use case.
|
|
159
198
|
*/
|
|
160
199
|
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Type representing the return type of getFunctionId
|
|
202
|
+
*/
|
|
161
203
|
type FunctionID = ReturnType<typeof getFunctionId>;
|
|
162
204
|
//#endregion
|
|
163
205
|
//#region src/function-init-path.d.ts
|
|
@@ -208,31 +250,121 @@ declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
|
|
|
208
250
|
declare function isIdentifier(node: TSESTree.Node | null | unit, name?: string): node is TSESTree.Identifier;
|
|
209
251
|
//#endregion
|
|
210
252
|
//#region src/identifier-name.d.ts
|
|
253
|
+
/**
|
|
254
|
+
* Check if a string is a valid JavaScript identifier name
|
|
255
|
+
* @param name The string to check
|
|
256
|
+
* @returns True if the string is a valid identifier name
|
|
257
|
+
*/
|
|
211
258
|
declare function isIdentifierName(name: string): boolean;
|
|
212
259
|
//#endregion
|
|
213
260
|
//#region src/is.d.ts
|
|
261
|
+
/**
|
|
262
|
+
* Type guard to check if a node is of a specific AST node type
|
|
263
|
+
* @param nodeType The AST node type to check against
|
|
264
|
+
* @returns A type guard function that narrows the node type
|
|
265
|
+
*/
|
|
214
266
|
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
215
267
|
type: NodeType;
|
|
216
268
|
}>;
|
|
269
|
+
/**
|
|
270
|
+
* Type guard to check if a node is one of multiple AST node types
|
|
271
|
+
* @param nodeTypes Array of AST node types to check against
|
|
272
|
+
* @returns A type guard function that narrows the node type
|
|
273
|
+
*/
|
|
217
274
|
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
218
275
|
type: NodeTypes[number];
|
|
219
276
|
}>;
|
|
277
|
+
/**
|
|
278
|
+
* Check if a node is a function (arrow, declaration, or expression)
|
|
279
|
+
* @param node The node to check
|
|
280
|
+
* @returns True if the node is a function
|
|
281
|
+
*/
|
|
220
282
|
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
283
|
+
/**
|
|
284
|
+
* Check if a node is a function type (including TypeScript function types)
|
|
285
|
+
* @param node The node to check
|
|
286
|
+
* @returns True if the node is a function type
|
|
287
|
+
*/
|
|
221
288
|
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;
|
|
289
|
+
/**
|
|
290
|
+
* Check if a node is a class declaration or expression
|
|
291
|
+
* @param node The node to check
|
|
292
|
+
* @returns True if the node is a class
|
|
293
|
+
*/
|
|
222
294
|
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
295
|
+
/**
|
|
296
|
+
* Check if a node is a method or property definition
|
|
297
|
+
* @param node The node to check
|
|
298
|
+
* @returns True if the node is a method or property definition
|
|
299
|
+
*/
|
|
223
300
|
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
301
|
+
/**
|
|
302
|
+
* Check if a node is a property-like node (including TypeScript property signatures)
|
|
303
|
+
* @param node The node to check
|
|
304
|
+
* @returns True if the node is a property
|
|
305
|
+
*/
|
|
224
306
|
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
307
|
+
/**
|
|
308
|
+
* Check if a node is a JSX element
|
|
309
|
+
* @param node The node to check
|
|
310
|
+
* @returns True if the node is a JSX element
|
|
311
|
+
*/
|
|
225
312
|
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
313
|
+
/**
|
|
314
|
+
* Check if a node is a JSX fragment
|
|
315
|
+
* @param node The node to check
|
|
316
|
+
* @returns True if the node is a JSX fragment
|
|
317
|
+
*/
|
|
226
318
|
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
319
|
+
/**
|
|
320
|
+
* Check if a node is a JSX tag name expression (identifier, member expression, or namespaced name)
|
|
321
|
+
* @param node The node to check
|
|
322
|
+
* @returns True if the node is a JSX tag name expression
|
|
323
|
+
*/
|
|
227
324
|
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
325
|
+
/**
|
|
326
|
+
* Check if a node is a JSX-related node
|
|
327
|
+
* @param node The node to check
|
|
328
|
+
* @returns True if the node is a JSX node
|
|
329
|
+
*/
|
|
228
330
|
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;
|
|
331
|
+
/**
|
|
332
|
+
* Check if a node is a loop statement
|
|
333
|
+
* @param node The node to check
|
|
334
|
+
* @returns True if the node is a loop
|
|
335
|
+
*/
|
|
229
336
|
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
337
|
+
/**
|
|
338
|
+
* Check if a node is a control flow statement (loop, if, or switch)
|
|
339
|
+
* @param node The node to check
|
|
340
|
+
* @returns True if the node is a control flow statement
|
|
341
|
+
*/
|
|
230
342
|
declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
343
|
+
/**
|
|
344
|
+
* Check if a node is a conditional expression or control flow statement
|
|
345
|
+
* @param node The node to check
|
|
346
|
+
* @returns True if the node is conditional
|
|
347
|
+
*/
|
|
231
348
|
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;
|
|
349
|
+
/**
|
|
350
|
+
* Check if a node is a TypeScript type expression
|
|
351
|
+
* @param node The node to check
|
|
352
|
+
* @returns True if the node is a type expression
|
|
353
|
+
*/
|
|
232
354
|
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
355
|
+
/**
|
|
356
|
+
* Check if a node is a TypeScript type assertion expression
|
|
357
|
+
* @param node The node to check
|
|
358
|
+
* @returns True if the node is a type assertion expression
|
|
359
|
+
*/
|
|
233
360
|
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
234
361
|
//#endregion
|
|
235
362
|
//#region src/literal.d.ts
|
|
363
|
+
/**
|
|
364
|
+
* Check if a node is a literal value
|
|
365
|
+
* @param node The node to check
|
|
366
|
+
* @returns True if the node is a literal
|
|
367
|
+
*/
|
|
236
368
|
declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
|
|
237
369
|
declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
|
|
238
370
|
declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
|
|
@@ -271,16 +403,31 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is
|
|
|
271
403
|
declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
|
|
272
404
|
//#endregion
|
|
273
405
|
//#region src/property-name.d.ts
|
|
406
|
+
/**
|
|
407
|
+
* Get the name of a property from a node
|
|
408
|
+
* Handles identifiers, private identifiers, literals, and template literals
|
|
409
|
+
* @param node The node to get the property name from
|
|
410
|
+
* @returns The property name or unit if not determinable
|
|
411
|
+
*/
|
|
274
412
|
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
275
413
|
//#endregion
|
|
276
414
|
//#region src/selectors.d.ts
|
|
415
|
+
/**
|
|
416
|
+
* Represents an arrow function expression with an implicit return
|
|
417
|
+
*/
|
|
277
418
|
type ImplicitReturnArrowFunctionExpression = TSESTree$1.ArrowFunctionExpression & {
|
|
278
419
|
body: TSESTree$1.Expression;
|
|
279
420
|
};
|
|
421
|
+
/**
|
|
422
|
+
* Represents a variable declarator with object destructuring and an identifier initializer
|
|
423
|
+
*/
|
|
280
424
|
type ObjectDestructuringVariableDeclarator = TSESTree$1.VariableDeclarator & {
|
|
281
425
|
id: TSESTree$1.ObjectPattern;
|
|
282
426
|
init: TSESTree$1.Identifier;
|
|
283
427
|
};
|
|
428
|
+
/**
|
|
429
|
+
* Represents an assignment expression that assigns to a displayName property
|
|
430
|
+
*/
|
|
284
431
|
type DisplayNameAssignmentExpression = TSESTree$1.AssignmentExpression & {
|
|
285
432
|
type: "AssignmentExpression";
|
|
286
433
|
left: TSESTree$1.MemberExpression & {
|
|
@@ -291,8 +438,17 @@ type DisplayNameAssignmentExpression = TSESTree$1.AssignmentExpression & {
|
|
|
291
438
|
operator: "=";
|
|
292
439
|
right: TSESTree$1.Literal;
|
|
293
440
|
};
|
|
441
|
+
/**
|
|
442
|
+
* Selector for arrow function expressions with implicit return
|
|
443
|
+
*/
|
|
294
444
|
declare const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
|
|
445
|
+
/**
|
|
446
|
+
* Selector for variable declarators with object destructuring
|
|
447
|
+
*/
|
|
295
448
|
declare const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR: string;
|
|
449
|
+
/**
|
|
450
|
+
* Selector for assignment expressions that set displayName
|
|
451
|
+
*/
|
|
296
452
|
declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
|
|
297
453
|
//#endregion
|
|
298
454
|
//#region src/traverse.d.ts
|
package/dist/index.js
CHANGED
|
@@ -65,13 +65,33 @@ function isDirectiveKind(kind) {
|
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
67
67
|
//#region src/is.ts
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check if a node is of a specific AST node type
|
|
70
|
+
* @param nodeType The AST node type to check against
|
|
71
|
+
* @returns A type guard function that narrows the node type
|
|
72
|
+
*/
|
|
68
73
|
const is = ASTUtils.isNodeOfType;
|
|
74
|
+
/**
|
|
75
|
+
* Type guard to check if a node is one of multiple AST node types
|
|
76
|
+
* @param nodeTypes Array of AST node types to check against
|
|
77
|
+
* @returns A type guard function that narrows the node type
|
|
78
|
+
*/
|
|
69
79
|
const isOneOf = ASTUtils.isNodeOfTypes;
|
|
80
|
+
/**
|
|
81
|
+
* Check if a node is a function (arrow, declaration, or expression)
|
|
82
|
+
* @param node The node to check
|
|
83
|
+
* @returns True if the node is a function
|
|
84
|
+
*/
|
|
70
85
|
const isFunction = isOneOf([
|
|
71
86
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
72
87
|
AST_NODE_TYPES.FunctionDeclaration,
|
|
73
88
|
AST_NODE_TYPES.FunctionExpression
|
|
74
89
|
]);
|
|
90
|
+
/**
|
|
91
|
+
* Check if a node is a function type (including TypeScript function types)
|
|
92
|
+
* @param node The node to check
|
|
93
|
+
* @returns True if the node is a function type
|
|
94
|
+
*/
|
|
75
95
|
const isFunctionType = isOneOf([
|
|
76
96
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
77
97
|
AST_NODE_TYPES.FunctionDeclaration,
|
|
@@ -83,21 +103,56 @@ const isFunctionType = isOneOf([
|
|
|
83
103
|
AST_NODE_TYPES.TSFunctionType,
|
|
84
104
|
AST_NODE_TYPES.TSMethodSignature
|
|
85
105
|
]);
|
|
106
|
+
/**
|
|
107
|
+
* Check if a node is a class declaration or expression
|
|
108
|
+
* @param node The node to check
|
|
109
|
+
* @returns True if the node is a class
|
|
110
|
+
*/
|
|
86
111
|
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
112
|
+
/**
|
|
113
|
+
* Check if a node is a method or property definition
|
|
114
|
+
* @param node The node to check
|
|
115
|
+
* @returns True if the node is a method or property definition
|
|
116
|
+
*/
|
|
87
117
|
const isMethodOrProperty = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
|
|
118
|
+
/**
|
|
119
|
+
* Check if a node is a property-like node (including TypeScript property signatures)
|
|
120
|
+
* @param node The node to check
|
|
121
|
+
* @returns True if the node is a property
|
|
122
|
+
*/
|
|
88
123
|
const isProperty = isOneOf([
|
|
89
124
|
AST_NODE_TYPES.PropertyDefinition,
|
|
90
125
|
AST_NODE_TYPES.TSIndexSignature,
|
|
91
126
|
AST_NODE_TYPES.TSParameterProperty,
|
|
92
127
|
AST_NODE_TYPES.TSPropertySignature
|
|
93
128
|
]);
|
|
129
|
+
/**
|
|
130
|
+
* Check if a node is a JSX element
|
|
131
|
+
* @param node The node to check
|
|
132
|
+
* @returns True if the node is a JSX element
|
|
133
|
+
*/
|
|
94
134
|
const isJSXElement = is(AST_NODE_TYPES.JSXElement);
|
|
135
|
+
/**
|
|
136
|
+
* Check if a node is a JSX fragment
|
|
137
|
+
* @param node The node to check
|
|
138
|
+
* @returns True if the node is a JSX fragment
|
|
139
|
+
*/
|
|
95
140
|
const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
|
|
141
|
+
/**
|
|
142
|
+
* Check if a node is a JSX tag name expression (identifier, member expression, or namespaced name)
|
|
143
|
+
* @param node The node to check
|
|
144
|
+
* @returns True if the node is a JSX tag name expression
|
|
145
|
+
*/
|
|
96
146
|
const isJSXTagNameExpression = isOneOf([
|
|
97
147
|
AST_NODE_TYPES.JSXIdentifier,
|
|
98
148
|
AST_NODE_TYPES.JSXMemberExpression,
|
|
99
149
|
AST_NODE_TYPES.JSXNamespacedName
|
|
100
150
|
]);
|
|
151
|
+
/**
|
|
152
|
+
* Check if a node is a JSX-related node
|
|
153
|
+
* @param node The node to check
|
|
154
|
+
* @returns True if the node is a JSX node
|
|
155
|
+
*/
|
|
101
156
|
const isJSX = isOneOf([
|
|
102
157
|
AST_NODE_TYPES.JSXAttribute,
|
|
103
158
|
AST_NODE_TYPES.JSXClosingElement,
|
|
@@ -115,6 +170,11 @@ const isJSX = isOneOf([
|
|
|
115
170
|
AST_NODE_TYPES.JSXSpreadChild,
|
|
116
171
|
AST_NODE_TYPES.JSXText
|
|
117
172
|
]);
|
|
173
|
+
/**
|
|
174
|
+
* Check if a node is a loop statement
|
|
175
|
+
* @param node The node to check
|
|
176
|
+
* @returns True if the node is a loop
|
|
177
|
+
*/
|
|
118
178
|
const isLoop = isOneOf([
|
|
119
179
|
AST_NODE_TYPES.DoWhileStatement,
|
|
120
180
|
AST_NODE_TYPES.ForInStatement,
|
|
@@ -122,8 +182,23 @@ const isLoop = isOneOf([
|
|
|
122
182
|
AST_NODE_TYPES.ForStatement,
|
|
123
183
|
AST_NODE_TYPES.WhileStatement
|
|
124
184
|
]);
|
|
185
|
+
/**
|
|
186
|
+
* Check if a node is a control flow statement (loop, if, or switch)
|
|
187
|
+
* @param node The node to check
|
|
188
|
+
* @returns True if the node is a control flow statement
|
|
189
|
+
*/
|
|
125
190
|
const isControlFlow = or(isLoop, isOneOf([AST_NODE_TYPES.IfStatement, AST_NODE_TYPES.SwitchStatement]));
|
|
191
|
+
/**
|
|
192
|
+
* Check if a node is a conditional expression or control flow statement
|
|
193
|
+
* @param node The node to check
|
|
194
|
+
* @returns True if the node is conditional
|
|
195
|
+
*/
|
|
126
196
|
const isConditional = or(isControlFlow, isOneOf([AST_NODE_TYPES.LogicalExpression, AST_NODE_TYPES.ConditionalExpression]));
|
|
197
|
+
/**
|
|
198
|
+
* Check if a node is a TypeScript type expression
|
|
199
|
+
* @param node The node to check
|
|
200
|
+
* @returns True if the node is a type expression
|
|
201
|
+
*/
|
|
127
202
|
const isTypeExpression = isOneOf([
|
|
128
203
|
AST_NODE_TYPES.TSAsExpression,
|
|
129
204
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
@@ -131,6 +206,11 @@ const isTypeExpression = isOneOf([
|
|
|
131
206
|
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
132
207
|
AST_NODE_TYPES.TSInstantiationExpression
|
|
133
208
|
]);
|
|
209
|
+
/**
|
|
210
|
+
* Check if a node is a TypeScript type assertion expression
|
|
211
|
+
* @param node The node to check
|
|
212
|
+
* @returns True if the node is a type assertion expression
|
|
213
|
+
*/
|
|
134
214
|
const isTypeAssertionExpression = isOneOf([
|
|
135
215
|
AST_NODE_TYPES.TSAsExpression,
|
|
136
216
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
@@ -600,6 +680,11 @@ function isIdentifier(node, name) {
|
|
|
600
680
|
|
|
601
681
|
//#endregion
|
|
602
682
|
//#region src/identifier-name.ts
|
|
683
|
+
/**
|
|
684
|
+
* Check if a string is a valid JavaScript identifier name
|
|
685
|
+
* @param name The string to check
|
|
686
|
+
* @returns True if the string is a valid identifier name
|
|
687
|
+
*/
|
|
603
688
|
function isIdentifierName(name) {
|
|
604
689
|
return /^[A-Z$_][\w$]*$/i.test(name);
|
|
605
690
|
}
|
|
@@ -651,6 +736,12 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
651
736
|
|
|
652
737
|
//#endregion
|
|
653
738
|
//#region src/property-name.ts
|
|
739
|
+
/**
|
|
740
|
+
* Get the name of a property from a node
|
|
741
|
+
* Handles identifiers, private identifiers, literals, and template literals
|
|
742
|
+
* @param node The node to get the property name from
|
|
743
|
+
* @returns The property name or unit if not determinable
|
|
744
|
+
*/
|
|
654
745
|
function getPropertyName(node) {
|
|
655
746
|
if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
|
|
656
747
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
@@ -661,12 +752,21 @@ function getPropertyName(node) {
|
|
|
661
752
|
|
|
662
753
|
//#endregion
|
|
663
754
|
//#region src/selectors.ts
|
|
755
|
+
/**
|
|
756
|
+
* Selector for arrow function expressions with implicit return
|
|
757
|
+
*/
|
|
664
758
|
const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
|
|
759
|
+
/**
|
|
760
|
+
* Selector for variable declarators with object destructuring
|
|
761
|
+
*/
|
|
665
762
|
const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
|
|
666
763
|
"VariableDeclarator",
|
|
667
764
|
"[id.type='ObjectPattern']",
|
|
668
765
|
"[init.type='Identifier']"
|
|
669
766
|
].join("");
|
|
767
|
+
/**
|
|
768
|
+
* Selector for assignment expressions that set displayName
|
|
769
|
+
*/
|
|
670
770
|
const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
|
|
671
771
|
"AssignmentExpression",
|
|
672
772
|
"[operator='=']",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.3-beta.7",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@typescript-eslint/typescript-estree": "^8.54.0",
|
|
35
35
|
"@typescript-eslint/utils": "^8.54.0",
|
|
36
36
|
"string-ts": "^2.3.1",
|
|
37
|
-
"@eslint-react/eff": "2.8.
|
|
37
|
+
"@eslint-react/eff": "2.8.3-beta.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsdown": "^0.20.1",
|