@eslint-react/ast 3.0.0-next.6 → 3.0.0-next.60
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 +71 -51
- package/dist/index.js +109 -70
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignat
|
|
|
34
34
|
/**
|
|
35
35
|
* Represents all JSX-related nodes in TSESTree
|
|
36
36
|
*/
|
|
37
|
-
type TSESTreeJSX = TSESTree$1.JSXAttribute | TSESTree$1.JSXChild | TSESTree$1.JSXClosingElement | TSESTree$1.JSXClosingFragment | TSESTree$1.
|
|
37
|
+
type TSESTreeJSX = TSESTree$1.JSXAttribute | TSESTree$1.JSXChild | TSESTree$1.JSXClosingElement | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXEmptyExpression | TSESTree$1.JSXIdentifierToken | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXSpreadAttribute | TSESTree$1.JSXTagNameExpression | TSESTree$1.JSXTextToken;
|
|
38
38
|
/**
|
|
39
39
|
* Represents JSX attribute-like nodes (attributes and spread attributes)
|
|
40
40
|
*/
|
|
@@ -77,34 +77,6 @@ type TSESTreeDirectiveLike = TSESTree$1.ExpressionStatement & {
|
|
|
77
77
|
*/
|
|
78
78
|
declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | unit;
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region src/directive-helper.d.ts
|
|
81
|
-
/**
|
|
82
|
-
* Get all directive expression statements from the top of a program AST node
|
|
83
|
-
* @param node The program AST node
|
|
84
|
-
* @returns The array of directive string literals (e.g., "use strict")
|
|
85
|
-
*/
|
|
86
|
-
declare function getFileDirectives(node: TSESTree.Program): TSESTreeDirective[];
|
|
87
|
-
/**
|
|
88
|
-
* Get all directive expression statements from the top of a function AST node
|
|
89
|
-
* @param node The function AST node
|
|
90
|
-
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
91
|
-
*/
|
|
92
|
-
declare function getFunctionDirectives(node: TSESTreeFunction): TSESTreeDirective[];
|
|
93
|
-
/**
|
|
94
|
-
* Check if a directive with the given name exists in the file or function directives
|
|
95
|
-
* @param node The program or function AST node
|
|
96
|
-
* @param name The directive name to check (e.g., "use strict", "use memo", "use no memo")
|
|
97
|
-
* @returns True if the directive exists, false otherwise
|
|
98
|
-
*/
|
|
99
|
-
declare function isDirectiveInFile(node: TSESTree.Program, name: string): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Check if a directive with the given name exists in the function directives
|
|
102
|
-
* @param node The function AST node
|
|
103
|
-
* @param name The directive name to check (e.g., "use memo", "use no memo")
|
|
104
|
-
* @returns True if the directive exists, false otherwise
|
|
105
|
-
*/
|
|
106
|
-
declare function isDirectiveInFunction(node: TSESTreeFunction, name: string): boolean;
|
|
107
|
-
//#endregion
|
|
108
80
|
//#region src/directive-is.d.ts
|
|
109
81
|
/**
|
|
110
82
|
* Check if a node is a directive expression statement
|
|
@@ -136,15 +108,6 @@ declare function isDirectiveKind(kind: string): kind is DirectiveKind;
|
|
|
136
108
|
*/
|
|
137
109
|
declare function isDirectiveName(name: string): boolean;
|
|
138
110
|
//#endregion
|
|
139
|
-
//#region src/expression-base.d.ts
|
|
140
|
-
/**
|
|
141
|
-
* Unwraps any type expressions to get the underlying JavaScript expression node.
|
|
142
|
-
* Recursively processes nodes until a non-type expression is found.
|
|
143
|
-
* @param node The AST node to unwrap
|
|
144
|
-
* @returns The underlying JavaScript expression node
|
|
145
|
-
*/
|
|
146
|
-
declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
147
|
-
//#endregion
|
|
148
111
|
//#region src/expression-is.d.ts
|
|
149
112
|
/**
|
|
150
113
|
* Check if the given expression is a 'this' expression
|
|
@@ -190,6 +153,36 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
|
|
|
190
153
|
*/
|
|
191
154
|
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
192
155
|
//#endregion
|
|
156
|
+
//#region src/file-directive.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Get all directive expression statements from the top of a program AST node
|
|
159
|
+
* @param node The program AST node
|
|
160
|
+
* @returns The array of directive string literals (e.g., "use strict")
|
|
161
|
+
*/
|
|
162
|
+
declare function getFileDirectives(node: TSESTree.Program): TSESTreeDirective[];
|
|
163
|
+
/**
|
|
164
|
+
* Check if a directive with the given name exists in the file or function directives
|
|
165
|
+
* @param node The program or function AST node
|
|
166
|
+
* @param name The directive name to check (e.g., "use strict", "use memo", "use no memo")
|
|
167
|
+
* @returns True if the directive exists, false otherwise
|
|
168
|
+
*/
|
|
169
|
+
declare function isDirectiveInFile(node: TSESTree.Program, name: string): boolean;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/function-directive.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* Get all directive expression statements from the top of a function AST node
|
|
174
|
+
* @param node The function AST node
|
|
175
|
+
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
176
|
+
*/
|
|
177
|
+
declare function getFunctionDirectives(node: TSESTreeFunction): TSESTreeDirective[];
|
|
178
|
+
/**
|
|
179
|
+
* Check if a directive with the given name exists in the function directives
|
|
180
|
+
* @param node The function AST node
|
|
181
|
+
* @param name The directive name to check (e.g., "use memo", "use no memo")
|
|
182
|
+
* @returns True if the directive exists, false otherwise
|
|
183
|
+
*/
|
|
184
|
+
declare function isDirectiveInFunction(node: TSESTreeFunction, name: string): boolean;
|
|
185
|
+
//#endregion
|
|
193
186
|
//#region src/function-id.d.ts
|
|
194
187
|
/**
|
|
195
188
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -259,6 +252,15 @@ declare function isIdentifier(node: TSESTree.Node | null | unit, name?: string):
|
|
|
259
252
|
*/
|
|
260
253
|
declare function isIdentifierName(name: string): boolean;
|
|
261
254
|
//#endregion
|
|
255
|
+
//#region src/identifier-traverse.d.ts
|
|
256
|
+
/**
|
|
257
|
+
* Get the root identifier of a (possibly nested) member expression.
|
|
258
|
+
* For `a.b.c`, returns the `a` Identifier node.
|
|
259
|
+
* @param node The expression to analyze
|
|
260
|
+
* @returns The root Identifier node, or null if it cannot be determined (e.g. non-identifier root)
|
|
261
|
+
*/
|
|
262
|
+
declare function getRootIdentifier(node: TSESTree.Expression | TSESTree.PrivateIdentifier): TSESTree.Identifier | null;
|
|
263
|
+
//#endregion
|
|
262
264
|
//#region src/literal-is.d.ts
|
|
263
265
|
/**
|
|
264
266
|
* Check if a node is a literal value
|
|
@@ -272,7 +274,7 @@ declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTre
|
|
|
272
274
|
declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
|
|
273
275
|
declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
|
|
274
276
|
//#endregion
|
|
275
|
-
//#region src/node-
|
|
277
|
+
//#region src/node-equality.d.ts
|
|
276
278
|
/**
|
|
277
279
|
* Check if two nodes are equal
|
|
278
280
|
* @param a node to compare
|
|
@@ -453,7 +455,16 @@ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | u
|
|
|
453
455
|
*/
|
|
454
456
|
declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
|
|
455
457
|
//#endregion
|
|
456
|
-
//#region src/
|
|
458
|
+
//#region src/node-unwrap.d.ts
|
|
459
|
+
/**
|
|
460
|
+
* Unwraps any type expressions to get the underlying JavaScript expression node.
|
|
461
|
+
* Recursively processes nodes until a non-type expression is found.
|
|
462
|
+
* @param node The AST node to unwrap
|
|
463
|
+
* @returns The underlying JavaScript expression node
|
|
464
|
+
*/
|
|
465
|
+
declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/pattern-process-env-node-env.d.ts
|
|
457
468
|
/**
|
|
458
469
|
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
459
470
|
* @param node The AST node
|
|
@@ -469,16 +480,7 @@ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is
|
|
|
469
480
|
*/
|
|
470
481
|
declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
|
|
471
482
|
//#endregion
|
|
472
|
-
//#region src/
|
|
473
|
-
/**
|
|
474
|
-
* Get the name of a property from a node
|
|
475
|
-
* Handles identifiers, private identifiers, literals, and template literals
|
|
476
|
-
* @param node The node to get the property name from
|
|
477
|
-
* @returns The property name or unit if not determinable
|
|
478
|
-
*/
|
|
479
|
-
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
480
|
-
//#endregion
|
|
481
|
-
//#region src/vitest-mock.d.ts
|
|
483
|
+
//#region src/pattern-vitest-mock.d.ts
|
|
482
484
|
/**
|
|
483
485
|
* Check if the given node is a `vi.mock`.
|
|
484
486
|
* @param node The node to check
|
|
@@ -494,4 +496,22 @@ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.M
|
|
|
494
496
|
*/
|
|
495
497
|
declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
|
|
496
498
|
//#endregion
|
|
497
|
-
|
|
499
|
+
//#region src/property-name.d.ts
|
|
500
|
+
/**
|
|
501
|
+
* Get the name of a property from a node
|
|
502
|
+
* Handles identifiers, private identifiers, literals, and template literals
|
|
503
|
+
* @param node The node to get the property name from
|
|
504
|
+
* @returns The property name or unit if not determinable
|
|
505
|
+
*/
|
|
506
|
+
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/property-traverse.d.ts
|
|
509
|
+
/**
|
|
510
|
+
* Recursively traverses an object expression's properties to find a property with the specified name
|
|
511
|
+
* @param properties The properties of the object expression to traverse
|
|
512
|
+
* @param name The name of the property to find
|
|
513
|
+
* @returns The matching property node, or undefined if not found
|
|
514
|
+
*/
|
|
515
|
+
declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | unit;
|
|
516
|
+
//#endregion
|
|
517
|
+
export { DirectiveKind, DisplayNameAssignmentExpression, FunctionID, FunctionInitPath, ImplicitReturnArrowFunctionExpression, ObjectDestructuringVariableDeclarator, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeDirective, TSESTreeDirectiveLike, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, findProperty, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getRootIdentifier, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, isDirectiveInFile, isDirectiveInFunction, isDirectiveKind, isDirectiveLike, isDirectiveName, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifier, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dual, or, unit } from "@eslint-react/eff";
|
|
2
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
2
|
+
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
3
3
|
import { ASTUtils } from "@typescript-eslint/utils";
|
|
4
4
|
import { simpleTraverse } from "@typescript-eslint/typescript-estree";
|
|
5
5
|
import { delimiterCase, replace, toLowerCase } from "string-ts";
|
|
@@ -60,54 +60,6 @@ function isDirectiveLike(node) {
|
|
|
60
60
|
return node.type === AST_NODE_TYPES.ExpressionStatement && isLiteral(node.expression, "string") && isDirectiveName(node.expression.value);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/directive-helper.ts
|
|
65
|
-
/**
|
|
66
|
-
* Get all directive expression statements from the top of a program AST node
|
|
67
|
-
* @param node The program AST node
|
|
68
|
-
* @returns The array of directive string literals (e.g., "use strict")
|
|
69
|
-
*/
|
|
70
|
-
function getFileDirectives(node) {
|
|
71
|
-
const directives = [];
|
|
72
|
-
for (const stmt of node.body) {
|
|
73
|
-
if (!isDirective(stmt)) continue;
|
|
74
|
-
directives.push(stmt);
|
|
75
|
-
}
|
|
76
|
-
return directives;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get all directive expression statements from the top of a function AST node
|
|
80
|
-
* @param node The function AST node
|
|
81
|
-
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
82
|
-
*/
|
|
83
|
-
function getFunctionDirectives(node) {
|
|
84
|
-
const directives = [];
|
|
85
|
-
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return directives;
|
|
86
|
-
for (const stmt of node.body.body) {
|
|
87
|
-
if (!isDirective(stmt)) continue;
|
|
88
|
-
directives.push(stmt);
|
|
89
|
-
}
|
|
90
|
-
return directives;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Check if a directive with the given name exists in the file or function directives
|
|
94
|
-
* @param node The program or function AST node
|
|
95
|
-
* @param name The directive name to check (e.g., "use strict", "use memo", "use no memo")
|
|
96
|
-
* @returns True if the directive exists, false otherwise
|
|
97
|
-
*/
|
|
98
|
-
function isDirectiveInFile(node, name) {
|
|
99
|
-
return getFileDirectives(node).some((d) => d.directive === name);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Check if a directive with the given name exists in the function directives
|
|
103
|
-
* @param node The function AST node
|
|
104
|
-
* @param name The directive name to check (e.g., "use memo", "use no memo")
|
|
105
|
-
* @returns True if the directive exists, false otherwise
|
|
106
|
-
*/
|
|
107
|
-
function isDirectiveInFunction(node, name) {
|
|
108
|
-
return getFunctionDirectives(node).some((d) => d.directive === name);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
63
|
//#endregion
|
|
112
64
|
//#region src/directive-kind.ts
|
|
113
65
|
/**
|
|
@@ -275,7 +227,7 @@ const isTypeAssertionExpression = isOneOf([
|
|
|
275
227
|
]);
|
|
276
228
|
|
|
277
229
|
//#endregion
|
|
278
|
-
//#region src/
|
|
230
|
+
//#region src/node-unwrap.ts
|
|
279
231
|
/**
|
|
280
232
|
* Unwraps any type expressions to get the underlying JavaScript expression node.
|
|
281
233
|
* Recursively processes nodes until a non-type expression is found.
|
|
@@ -495,6 +447,57 @@ const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExp
|
|
|
495
447
|
*/
|
|
496
448
|
const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
497
449
|
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/file-directive.ts
|
|
452
|
+
/**
|
|
453
|
+
* Get all directive expression statements from the top of a program AST node
|
|
454
|
+
* @param node The program AST node
|
|
455
|
+
* @returns The array of directive string literals (e.g., "use strict")
|
|
456
|
+
*/
|
|
457
|
+
function getFileDirectives(node) {
|
|
458
|
+
const directives = [];
|
|
459
|
+
for (const stmt of node.body) {
|
|
460
|
+
if (!isDirective(stmt)) continue;
|
|
461
|
+
directives.push(stmt);
|
|
462
|
+
}
|
|
463
|
+
return directives;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Check if a directive with the given name exists in the file or function directives
|
|
467
|
+
* @param node The program or function AST node
|
|
468
|
+
* @param name The directive name to check (e.g., "use strict", "use memo", "use no memo")
|
|
469
|
+
* @returns True if the directive exists, false otherwise
|
|
470
|
+
*/
|
|
471
|
+
function isDirectiveInFile(node, name) {
|
|
472
|
+
return getFileDirectives(node).some((d) => d.directive === name);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/function-directive.ts
|
|
477
|
+
/**
|
|
478
|
+
* Get all directive expression statements from the top of a function AST node
|
|
479
|
+
* @param node The function AST node
|
|
480
|
+
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
481
|
+
*/
|
|
482
|
+
function getFunctionDirectives(node) {
|
|
483
|
+
const directives = [];
|
|
484
|
+
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return directives;
|
|
485
|
+
for (const stmt of node.body.body) {
|
|
486
|
+
if (!isDirective(stmt)) continue;
|
|
487
|
+
directives.push(stmt);
|
|
488
|
+
}
|
|
489
|
+
return directives;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Check if a directive with the given name exists in the function directives
|
|
493
|
+
* @param node The function AST node
|
|
494
|
+
* @param name The directive name to check (e.g., "use memo", "use no memo")
|
|
495
|
+
* @returns True if the directive exists, false otherwise
|
|
496
|
+
*/
|
|
497
|
+
function isDirectiveInFunction(node, name) {
|
|
498
|
+
return getFunctionDirectives(node).some((d) => d.directive === name);
|
|
499
|
+
}
|
|
500
|
+
|
|
498
501
|
//#endregion
|
|
499
502
|
//#region src/function-id.ts
|
|
500
503
|
/**
|
|
@@ -632,7 +635,24 @@ function isIdentifierName(name) {
|
|
|
632
635
|
}
|
|
633
636
|
|
|
634
637
|
//#endregion
|
|
635
|
-
//#region src/
|
|
638
|
+
//#region src/identifier-traverse.ts
|
|
639
|
+
/**
|
|
640
|
+
* Get the root identifier of a (possibly nested) member expression.
|
|
641
|
+
* For `a.b.c`, returns the `a` Identifier node.
|
|
642
|
+
* @param node The expression to analyze
|
|
643
|
+
* @returns The root Identifier node, or null if it cannot be determined (e.g. non-identifier root)
|
|
644
|
+
*/
|
|
645
|
+
function getRootIdentifier(node) {
|
|
646
|
+
const expr = getUnderlyingExpression(node);
|
|
647
|
+
switch (expr.type) {
|
|
648
|
+
case AST_NODE_TYPES.Identifier: return expr;
|
|
649
|
+
case AST_NODE_TYPES.MemberExpression: return getRootIdentifier(expr.object);
|
|
650
|
+
default: return null;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
//#endregion
|
|
655
|
+
//#region src/node-equality.ts
|
|
636
656
|
/**
|
|
637
657
|
* Check if two nodes are equal
|
|
638
658
|
* @param a node to compare
|
|
@@ -734,7 +754,7 @@ const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
|
|
|
734
754
|
].join("");
|
|
735
755
|
|
|
736
756
|
//#endregion
|
|
737
|
-
//#region src/process-env-node-env.ts
|
|
757
|
+
//#region src/pattern-process-env-node-env.ts
|
|
738
758
|
/**
|
|
739
759
|
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
740
760
|
* @param node The AST node
|
|
@@ -760,23 +780,7 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
760
780
|
}
|
|
761
781
|
|
|
762
782
|
//#endregion
|
|
763
|
-
//#region src/
|
|
764
|
-
/**
|
|
765
|
-
* Get the name of a property from a node
|
|
766
|
-
* Handles identifiers, private identifiers, literals, and template literals
|
|
767
|
-
* @param node The node to get the property name from
|
|
768
|
-
* @returns The property name or unit if not determinable
|
|
769
|
-
*/
|
|
770
|
-
function getPropertyName(node) {
|
|
771
|
-
if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
|
|
772
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
773
|
-
if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
|
|
774
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
|
|
775
|
-
return unit;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
//#endregion
|
|
779
|
-
//#region src/vitest-mock.ts
|
|
783
|
+
//#region src/pattern-vitest-mock.ts
|
|
780
784
|
/**
|
|
781
785
|
* Check if the given node is a `vi.mock`.
|
|
782
786
|
* @param node The node to check
|
|
@@ -797,4 +801,39 @@ function isViMockCallback(node) {
|
|
|
797
801
|
}
|
|
798
802
|
|
|
799
803
|
//#endregion
|
|
800
|
-
|
|
804
|
+
//#region src/property-name.ts
|
|
805
|
+
/**
|
|
806
|
+
* Get the name of a property from a node
|
|
807
|
+
* Handles identifiers, private identifiers, literals, and template literals
|
|
808
|
+
* @param node The node to get the property name from
|
|
809
|
+
* @returns The property name or unit if not determinable
|
|
810
|
+
*/
|
|
811
|
+
function getPropertyName(node) {
|
|
812
|
+
if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
|
|
813
|
+
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
814
|
+
if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
|
|
815
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
|
|
816
|
+
return unit;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/property-traverse.ts
|
|
821
|
+
/**
|
|
822
|
+
* Recursively traverses an object expression's properties to find a property with the specified name
|
|
823
|
+
* @param properties The properties of the object expression to traverse
|
|
824
|
+
* @param name The name of the property to find
|
|
825
|
+
* @returns The matching property node, or undefined if not found
|
|
826
|
+
*/
|
|
827
|
+
function findProperty(properties, name) {
|
|
828
|
+
for (const prop of properties) {
|
|
829
|
+
if (prop.type === AST_NODE_TYPES.Property && getPropertyName(prop.key) === name) return prop;
|
|
830
|
+
if (prop.type === AST_NODE_TYPES.SpreadElement && prop.argument.type === AST_NODE_TYPES.ObjectExpression) {
|
|
831
|
+
const found = findProperty(prop.argument.properties, name);
|
|
832
|
+
if (found != null) return found;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return unit;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
//#endregion
|
|
839
|
+
export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, findProperty, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getRootIdentifier, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, isDirectiveInFile, isDirectiveInFunction, isDirectiveKind, isDirectiveLike, isDirectiveName, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isIdentifier, isIdentifierName, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.60",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@typescript-eslint/typescript-estree": "canary",
|
|
35
35
|
"@typescript-eslint/utils": "canary",
|
|
36
36
|
"string-ts": "^2.3.1",
|
|
37
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
37
|
+
"@eslint-react/eff": "3.0.0-next.60"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"tsdown": "^0.
|
|
40
|
+
"tsdown": "^0.21.0-beta.2",
|
|
41
41
|
"@local/configs": "0.0.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown --dts-resolve",
|
|
52
52
|
"lint:publish": "publint",
|
|
53
|
-
"lint:ts": "
|
|
53
|
+
"lint:ts": "tsl"
|
|
54
54
|
}
|
|
55
55
|
}
|