@eslint-react/ast 2.14.0-next.0 → 3.0.0-next.0
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 +87 -75
- package/dist/index.js +121 -105
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { unit } from "@eslint-react/eff";
|
|
|
2
2
|
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
3
3
|
import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
4
4
|
|
|
5
|
-
//#region src/types.d.ts
|
|
5
|
+
//#region src/node-types.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Represents function expressions and declarations in TSESTree
|
|
8
8
|
*/
|
|
@@ -77,6 +77,34 @@ 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
|
|
80
108
|
//#region src/directive-is.d.ts
|
|
81
109
|
/**
|
|
82
110
|
* Check if a node is a directive expression statement
|
|
@@ -108,19 +136,6 @@ declare function isDirectiveKind(kind: string): kind is DirectiveKind;
|
|
|
108
136
|
*/
|
|
109
137
|
declare function isDirectiveName(name: string): boolean;
|
|
110
138
|
//#endregion
|
|
111
|
-
//#region src/equal.d.ts
|
|
112
|
-
/**
|
|
113
|
-
* Check if two nodes are equal
|
|
114
|
-
* @param a node to compare
|
|
115
|
-
* @param b node to compare
|
|
116
|
-
* @returns `true` if node equal
|
|
117
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
118
|
-
*/
|
|
119
|
-
declare const isNodeEqual: {
|
|
120
|
-
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
121
|
-
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
122
|
-
};
|
|
123
|
-
//#endregion
|
|
124
139
|
//#region src/expression-base.d.ts
|
|
125
140
|
/**
|
|
126
141
|
* Unwraps any type expressions to get the underlying JavaScript expression node.
|
|
@@ -175,22 +190,6 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
|
|
|
175
190
|
*/
|
|
176
191
|
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
177
192
|
//#endregion
|
|
178
|
-
//#region src/file-directive.d.ts
|
|
179
|
-
/**
|
|
180
|
-
* Get all directive expression statements from the top of a program AST node
|
|
181
|
-
* @param node The program AST node
|
|
182
|
-
* @returns The array of directive string literals (e.g., "use strict")
|
|
183
|
-
*/
|
|
184
|
-
declare function getFileDirectives(node: TSESTree.Program): TSESTreeDirective[];
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/function-directive.d.ts
|
|
187
|
-
/**
|
|
188
|
-
* Get all directive expression statements from the top of a function AST node
|
|
189
|
-
* @param node The function AST node
|
|
190
|
-
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
191
|
-
*/
|
|
192
|
-
declare function getFunctionDirectives(node: TSESTreeFunction): TSESTreeDirective[];
|
|
193
|
-
//#endregion
|
|
194
193
|
//#region src/function-id.d.ts
|
|
195
194
|
/**
|
|
196
195
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -260,7 +259,33 @@ declare function isIdentifier(node: TSESTree.Node | null | unit, name?: string):
|
|
|
260
259
|
*/
|
|
261
260
|
declare function isIdentifierName(name: string): boolean;
|
|
262
261
|
//#endregion
|
|
263
|
-
//#region src/is.d.ts
|
|
262
|
+
//#region src/literal-is.d.ts
|
|
263
|
+
/**
|
|
264
|
+
* Check if a node is a literal value
|
|
265
|
+
* @param node The node to check
|
|
266
|
+
* @returns True if the node is a literal
|
|
267
|
+
*/
|
|
268
|
+
declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
|
|
269
|
+
declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
|
|
270
|
+
declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
|
|
271
|
+
declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
|
|
272
|
+
declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
|
|
273
|
+
declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/node-equal.d.ts
|
|
276
|
+
/**
|
|
277
|
+
* Check if two nodes are equal
|
|
278
|
+
* @param a node to compare
|
|
279
|
+
* @param b node to compare
|
|
280
|
+
* @returns `true` if node equal
|
|
281
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
282
|
+
*/
|
|
283
|
+
declare const isNodeEqual: {
|
|
284
|
+
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
285
|
+
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/node-is.d.ts
|
|
264
289
|
/**
|
|
265
290
|
* Type guard to check if a node is of a specific AST node type
|
|
266
291
|
* @param nodeType The AST node type to check against
|
|
@@ -362,55 +387,17 @@ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node
|
|
|
362
387
|
*/
|
|
363
388
|
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
364
389
|
//#endregion
|
|
365
|
-
//#region src/kind.d.ts
|
|
390
|
+
//#region src/node-kind.d.ts
|
|
366
391
|
declare function getHumanReadableKind(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
367
392
|
//#endregion
|
|
368
|
-
//#region src/line.d.ts
|
|
393
|
+
//#region src/node-line.d.ts
|
|
369
394
|
declare function isMultiLine(node: TSESTree.Node): boolean;
|
|
370
395
|
declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
371
396
|
//#endregion
|
|
372
|
-
//#region src/
|
|
373
|
-
/**
|
|
374
|
-
* Check if a node is a literal value
|
|
375
|
-
* @param node The node to check
|
|
376
|
-
* @returns True if the node is a literal
|
|
377
|
-
*/
|
|
378
|
-
declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
|
|
379
|
-
declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
|
|
380
|
-
declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
|
|
381
|
-
declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
|
|
382
|
-
declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
|
|
383
|
-
declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/name.d.ts
|
|
397
|
+
//#region src/node-name.d.ts
|
|
386
398
|
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
387
399
|
//#endregion
|
|
388
|
-
//#region src/
|
|
389
|
-
/**
|
|
390
|
-
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
391
|
-
* @param node The AST node
|
|
392
|
-
* @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
|
|
393
|
-
*/
|
|
394
|
-
declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
|
|
395
|
-
/**
|
|
396
|
-
* Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
|
|
397
|
-
* @param node The AST node
|
|
398
|
-
* @param operator The operator used in the comparison
|
|
399
|
-
* @param value The string literal value to compare against
|
|
400
|
-
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
|
|
401
|
-
*/
|
|
402
|
-
declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
|
|
403
|
-
//#endregion
|
|
404
|
-
//#region src/property-name.d.ts
|
|
405
|
-
/**
|
|
406
|
-
* Get the name of a property from a node
|
|
407
|
-
* Handles identifiers, private identifiers, literals, and template literals
|
|
408
|
-
* @param node The node to get the property name from
|
|
409
|
-
* @returns The property name or unit if not determinable
|
|
410
|
-
*/
|
|
411
|
-
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
412
|
-
//#endregion
|
|
413
|
-
//#region src/selectors.d.ts
|
|
400
|
+
//#region src/node-selectors.d.ts
|
|
414
401
|
/**
|
|
415
402
|
* Represents an arrow function expression with an implicit return
|
|
416
403
|
*/
|
|
@@ -450,7 +437,7 @@ declare const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR: string;
|
|
|
450
437
|
*/
|
|
451
438
|
declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
|
|
452
439
|
//#endregion
|
|
453
|
-
//#region src/traverse.d.ts
|
|
440
|
+
//#region src/node-traverse.d.ts
|
|
454
441
|
/**
|
|
455
442
|
* Find the parent node that satisfies the test function
|
|
456
443
|
* @param node The AST node
|
|
@@ -466,6 +453,31 @@ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | u
|
|
|
466
453
|
*/
|
|
467
454
|
declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
|
|
468
455
|
//#endregion
|
|
456
|
+
//#region src/process-env-node-env.d.ts
|
|
457
|
+
/**
|
|
458
|
+
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
459
|
+
* @param node The AST node
|
|
460
|
+
* @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
|
|
461
|
+
*/
|
|
462
|
+
declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
|
|
463
|
+
/**
|
|
464
|
+
* Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
|
|
465
|
+
* @param node The AST node
|
|
466
|
+
* @param operator The operator used in the comparison
|
|
467
|
+
* @param value The string literal value to compare against
|
|
468
|
+
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
|
|
469
|
+
*/
|
|
470
|
+
declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/property-name.d.ts
|
|
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
|
|
469
481
|
//#region src/vitest-mock.d.ts
|
|
470
482
|
/**
|
|
471
483
|
* Check if the given node is a `vi.mock`.
|
|
@@ -482,4 +494,4 @@ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.M
|
|
|
482
494
|
*/
|
|
483
495
|
declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
|
|
484
496
|
//#endregion
|
|
485
|
-
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, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, 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 };
|
|
497
|
+
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, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, 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
|
@@ -28,7 +28,7 @@ function isDirectiveName(name) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
//#endregion
|
|
31
|
-
//#region src/literal.ts
|
|
31
|
+
//#region src/literal-is.ts
|
|
32
32
|
function isLiteral(node, type) {
|
|
33
33
|
if (node.type !== AST_NODE_TYPES.Literal) return false;
|
|
34
34
|
if (type == null) return true;
|
|
@@ -60,6 +60,54 @@ 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
|
+
|
|
63
111
|
//#endregion
|
|
64
112
|
//#region src/directive-kind.ts
|
|
65
113
|
/**
|
|
@@ -72,7 +120,7 @@ function isDirectiveKind(kind) {
|
|
|
72
120
|
}
|
|
73
121
|
|
|
74
122
|
//#endregion
|
|
75
|
-
//#region src/is.ts
|
|
123
|
+
//#region src/node-is.ts
|
|
76
124
|
/**
|
|
77
125
|
* Type guard to check if a node is of a specific AST node type
|
|
78
126
|
* @param nodeType The AST node type to check against
|
|
@@ -239,47 +287,6 @@ function getUnderlyingExpression(node) {
|
|
|
239
287
|
return node;
|
|
240
288
|
}
|
|
241
289
|
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/equal.ts
|
|
244
|
-
/**
|
|
245
|
-
* Check if two nodes are equal
|
|
246
|
-
* @param a node to compare
|
|
247
|
-
* @param b node to compare
|
|
248
|
-
* @returns `true` if node equal
|
|
249
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
250
|
-
*/
|
|
251
|
-
const isNodeEqual = dual(2, (a, b) => {
|
|
252
|
-
a = isTypeExpression(a) ? getUnderlyingExpression(a) : a;
|
|
253
|
-
b = isTypeExpression(b) ? getUnderlyingExpression(b) : b;
|
|
254
|
-
switch (true) {
|
|
255
|
-
case a === b: return true;
|
|
256
|
-
case a.type !== b.type: return false;
|
|
257
|
-
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
258
|
-
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
259
|
-
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
260
|
-
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
261
|
-
let i = a.quasis.length;
|
|
262
|
-
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
263
|
-
i = a.expressions.length;
|
|
264
|
-
while (i--) {
|
|
265
|
-
const exprA = a.expressions[i];
|
|
266
|
-
const exprB = b.expressions[i];
|
|
267
|
-
if (!isNodeEqual(exprA, exprB)) return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
272
|
-
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
273
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
274
|
-
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
275
|
-
if (a.name.name !== b.name.name) return false;
|
|
276
|
-
if (a.value == null || b.value == null) return a.value === b.value;
|
|
277
|
-
return isNodeEqual(a.value, b.value);
|
|
278
|
-
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
279
|
-
default: return false;
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
290
|
//#endregion
|
|
284
291
|
//#region src/expression-is.ts
|
|
285
292
|
/**
|
|
@@ -294,7 +301,7 @@ function isThisExpressionLoose(node) {
|
|
|
294
301
|
}
|
|
295
302
|
|
|
296
303
|
//#endregion
|
|
297
|
-
//#region src/traverse.ts
|
|
304
|
+
//#region src/node-traverse.ts
|
|
298
305
|
function findParentNode(node, test) {
|
|
299
306
|
if (node == null) return unit;
|
|
300
307
|
let parent = node.parent;
|
|
@@ -488,39 +495,6 @@ const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExp
|
|
|
488
495
|
*/
|
|
489
496
|
const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
490
497
|
|
|
491
|
-
//#endregion
|
|
492
|
-
//#region src/file-directive.ts
|
|
493
|
-
/**
|
|
494
|
-
* Get all directive expression statements from the top of a program AST node
|
|
495
|
-
* @param node The program AST node
|
|
496
|
-
* @returns The array of directive string literals (e.g., "use strict")
|
|
497
|
-
*/
|
|
498
|
-
function getFileDirectives(node) {
|
|
499
|
-
const directives = [];
|
|
500
|
-
for (const stmt of node.body) {
|
|
501
|
-
if (!isDirective(stmt)) continue;
|
|
502
|
-
directives.push(stmt);
|
|
503
|
-
}
|
|
504
|
-
return directives;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/function-directive.ts
|
|
509
|
-
/**
|
|
510
|
-
* Get all directive expression statements from the top of a function AST node
|
|
511
|
-
* @param node The function AST node
|
|
512
|
-
* @returns The array of directive string literals (e.g., "use memo", "use no memo")
|
|
513
|
-
*/
|
|
514
|
-
function getFunctionDirectives(node) {
|
|
515
|
-
const directives = [];
|
|
516
|
-
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return directives;
|
|
517
|
-
for (const stmt of node.body.body) {
|
|
518
|
-
if (!isDirective(stmt)) continue;
|
|
519
|
-
directives.push(stmt);
|
|
520
|
-
}
|
|
521
|
-
return directives;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
498
|
//#endregion
|
|
525
499
|
//#region src/function-id.ts
|
|
526
500
|
/**
|
|
@@ -538,6 +512,7 @@ function getFunctionId(node) {
|
|
|
538
512
|
case node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed: return node.parent.key;
|
|
539
513
|
case isMethodOrProperty(node.parent) && node.parent.value === node: return node.parent.key;
|
|
540
514
|
case node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node: return node.parent.left;
|
|
515
|
+
case node.parent.type === AST_NODE_TYPES.ConditionalExpression: return getFunctionId(node.parent);
|
|
541
516
|
case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
|
|
542
517
|
}
|
|
543
518
|
return unit;
|
|
@@ -657,7 +632,48 @@ function isIdentifierName(name) {
|
|
|
657
632
|
}
|
|
658
633
|
|
|
659
634
|
//#endregion
|
|
660
|
-
//#region src/
|
|
635
|
+
//#region src/node-equal.ts
|
|
636
|
+
/**
|
|
637
|
+
* Check if two nodes are equal
|
|
638
|
+
* @param a node to compare
|
|
639
|
+
* @param b node to compare
|
|
640
|
+
* @returns `true` if node equal
|
|
641
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
642
|
+
*/
|
|
643
|
+
const isNodeEqual = dual(2, (a, b) => {
|
|
644
|
+
a = isTypeExpression(a) ? getUnderlyingExpression(a) : a;
|
|
645
|
+
b = isTypeExpression(b) ? getUnderlyingExpression(b) : b;
|
|
646
|
+
switch (true) {
|
|
647
|
+
case a === b: return true;
|
|
648
|
+
case a.type !== b.type: return false;
|
|
649
|
+
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
650
|
+
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
651
|
+
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
652
|
+
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
653
|
+
let i = a.quasis.length;
|
|
654
|
+
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
655
|
+
i = a.expressions.length;
|
|
656
|
+
while (i--) {
|
|
657
|
+
const exprA = a.expressions[i];
|
|
658
|
+
const exprB = b.expressions[i];
|
|
659
|
+
if (!isNodeEqual(exprA, exprB)) return false;
|
|
660
|
+
}
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
664
|
+
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
665
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
666
|
+
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
667
|
+
if (a.name.name !== b.name.name) return false;
|
|
668
|
+
if (a.value == null || b.value == null) return a.value === b.value;
|
|
669
|
+
return isNodeEqual(a.value, b.value);
|
|
670
|
+
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
671
|
+
default: return false;
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/node-kind.ts
|
|
661
677
|
function getHumanReadableKind(node, delimiter = " ") {
|
|
662
678
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
663
679
|
if ("regex" in node) return "RegExp literal";
|
|
@@ -669,7 +685,7 @@ function getHumanReadableKind(node, delimiter = " ") {
|
|
|
669
685
|
}
|
|
670
686
|
|
|
671
687
|
//#endregion
|
|
672
|
-
//#region src/line.ts
|
|
688
|
+
//#region src/node-line.ts
|
|
673
689
|
function isMultiLine(node) {
|
|
674
690
|
return node.loc.start.line !== node.loc.end.line;
|
|
675
691
|
}
|
|
@@ -678,7 +694,7 @@ function isLineBreak(node) {
|
|
|
678
694
|
}
|
|
679
695
|
|
|
680
696
|
//#endregion
|
|
681
|
-
//#region src/name.ts
|
|
697
|
+
//#region src/node-name.ts
|
|
682
698
|
function getFullyQualifiedName(node, getText) {
|
|
683
699
|
switch (node.type) {
|
|
684
700
|
case AST_NODE_TYPES.Identifier:
|
|
@@ -693,6 +709,30 @@ function getFullyQualifiedName(node, getText) {
|
|
|
693
709
|
}
|
|
694
710
|
}
|
|
695
711
|
|
|
712
|
+
//#endregion
|
|
713
|
+
//#region src/node-selectors.ts
|
|
714
|
+
/**
|
|
715
|
+
* Selector for arrow function expressions with implicit return
|
|
716
|
+
*/
|
|
717
|
+
const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
|
|
718
|
+
/**
|
|
719
|
+
* Selector for variable declarators with object destructuring
|
|
720
|
+
*/
|
|
721
|
+
const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
|
|
722
|
+
"VariableDeclarator",
|
|
723
|
+
"[id.type='ObjectPattern']",
|
|
724
|
+
"[init.type='Identifier']"
|
|
725
|
+
].join("");
|
|
726
|
+
/**
|
|
727
|
+
* Selector for assignment expressions that set displayName
|
|
728
|
+
*/
|
|
729
|
+
const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
|
|
730
|
+
"AssignmentExpression",
|
|
731
|
+
"[operator='=']",
|
|
732
|
+
"[left.type='MemberExpression']",
|
|
733
|
+
"[left.property.name='displayName']"
|
|
734
|
+
].join("");
|
|
735
|
+
|
|
696
736
|
//#endregion
|
|
697
737
|
//#region src/process-env-node-env.ts
|
|
698
738
|
/**
|
|
@@ -735,30 +775,6 @@ function getPropertyName(node) {
|
|
|
735
775
|
return unit;
|
|
736
776
|
}
|
|
737
777
|
|
|
738
|
-
//#endregion
|
|
739
|
-
//#region src/selectors.ts
|
|
740
|
-
/**
|
|
741
|
-
* Selector for arrow function expressions with implicit return
|
|
742
|
-
*/
|
|
743
|
-
const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
|
|
744
|
-
/**
|
|
745
|
-
* Selector for variable declarators with object destructuring
|
|
746
|
-
*/
|
|
747
|
-
const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
|
|
748
|
-
"VariableDeclarator",
|
|
749
|
-
"[id.type='ObjectPattern']",
|
|
750
|
-
"[init.type='Identifier']"
|
|
751
|
-
].join("");
|
|
752
|
-
/**
|
|
753
|
-
* Selector for assignment expressions that set displayName
|
|
754
|
-
*/
|
|
755
|
-
const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
|
|
756
|
-
"AssignmentExpression",
|
|
757
|
-
"[operator='=']",
|
|
758
|
-
"[left.type='MemberExpression']",
|
|
759
|
-
"[left.property.name='displayName']"
|
|
760
|
-
].join("");
|
|
761
|
-
|
|
762
778
|
//#endregion
|
|
763
779
|
//#region src/vitest-mock.ts
|
|
764
780
|
/**
|
|
@@ -781,4 +797,4 @@ function isViMockCallback(node) {
|
|
|
781
797
|
}
|
|
782
798
|
|
|
783
799
|
//#endregion
|
|
784
|
-
export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isClass, isConditional, isControlFlow, isDirective, 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 };
|
|
800
|
+
export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParentNode, getClassId, getFileDirectives, getFullyQualifiedName, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHumanReadableKind, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, 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
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"./package.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@typescript-eslint/types": "^8.
|
|
34
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
35
|
-
"@typescript-eslint/utils": "^8.
|
|
33
|
+
"@typescript-eslint/types": "^8.56.0",
|
|
34
|
+
"@typescript-eslint/typescript-estree": "^8.56.0",
|
|
35
|
+
"@typescript-eslint/utils": "^8.56.0",
|
|
36
36
|
"string-ts": "^2.3.1",
|
|
37
|
-
"@eslint-react/eff": "
|
|
37
|
+
"@eslint-react/eff": "3.0.0-next.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsdown": "^0.20.3",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typescript": ">=4.8.4 <6.0.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=22.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsdown --dts-resolve",
|