@eslint-react/ast 5.17.3 → 5.18.1
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 +89 -8
- package/dist/index.js +82 -8
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,87 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
|
+
/** Union of function-like node types. */
|
|
3
4
|
type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
|
|
5
|
+
/** Union of class-like node types. */
|
|
4
6
|
type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
|
|
7
|
+
/** Union of method and property definition node types. */
|
|
5
8
|
type TSESTreeMethodOrPropertyDefinition = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
|
|
9
|
+
/** Union of all JSX-related node types. */
|
|
6
10
|
type TSESTreeJSX = 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;
|
|
11
|
+
/** Union of JSX element-like node types (element or fragment). */
|
|
7
12
|
type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
13
|
+
/** Union of JSX attribute-like node types (attribute or spread attribute). */
|
|
8
14
|
type TSESTreeJSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
|
|
15
|
+
/** An expression statement that is a directive (ex: `"use strict"`). */
|
|
9
16
|
type TSESTreeDirective = TSESTree.ExpressionStatement & {
|
|
10
17
|
directive: string;
|
|
11
18
|
expression: TSESTree.StringLiteral;
|
|
12
19
|
};
|
|
20
|
+
/** Union of TypeScript type expression node types. */
|
|
13
21
|
type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
|
|
14
22
|
declare namespace check_d_exports {
|
|
15
23
|
export { is, isClass, isConditional, isDirective, isExpression, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXFragment, isJSXTagNameExpression, isOneOf, isProperty, isPropertyOrMethod, isTypeAssertionExpression, isTypeExpression };
|
|
16
24
|
}
|
|
25
|
+
/** Check if a node is of the given type. */
|
|
17
26
|
declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
18
27
|
type: NodeType;
|
|
19
28
|
}>;
|
|
29
|
+
/** Check if a node is one of the given types. */
|
|
20
30
|
declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
21
31
|
type: NodeTypes[number];
|
|
22
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a node is a directive statement (ex: `"use client"`), optionally matching a specific directive name.
|
|
35
|
+
* @param node The node to check.
|
|
36
|
+
* @param name The directive name to match. When omitted, any directive matches.
|
|
37
|
+
* @returns `true` if the node is a matching directive statement.
|
|
38
|
+
*/
|
|
23
39
|
declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a node is an identifier, optionally matching a specific name.
|
|
42
|
+
* @param node The node to check.
|
|
43
|
+
* @param name The identifier name to match. When omitted, any identifier matches.
|
|
44
|
+
* @returns `true` if the node is a matching identifier.
|
|
45
|
+
*/
|
|
24
46
|
declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSESTree.Identifier;
|
|
47
|
+
/** Check if a node is a class declaration or class expression. */
|
|
25
48
|
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
49
|
+
/** Check if a node is a function declaration, function expression, or arrow function expression. */
|
|
26
50
|
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
51
|
+
/** Check if a node is a property-like node (property definition, index signature, parameter property, or property signature). */
|
|
27
52
|
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
53
|
+
/** Check if a node is a property or method definition. */
|
|
28
54
|
declare const isPropertyOrMethod: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
55
|
+
/** Check if a node is a JSX element. */
|
|
29
56
|
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
57
|
+
/** Check if a node is a JSX fragment. */
|
|
30
58
|
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
59
|
+
/** Check if a node is a JSX element or JSX fragment. */
|
|
31
60
|
declare const isJSXElementOrFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
61
|
+
/** Check if a node can appear as a JSX tag name. */
|
|
32
62
|
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
63
|
+
/** Check if a node is any JSX-related node. */
|
|
33
64
|
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;
|
|
65
|
+
/** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
|
|
34
66
|
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
67
|
+
/** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
|
|
35
68
|
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
69
|
+
/** Check if a node is an expression node. */
|
|
36
70
|
declare const isExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | 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.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.YieldNoStarExpression | TSESTree.YieldStarExpression;
|
|
37
71
|
/**
|
|
38
|
-
* Check if a node is a conditional expression or control flow statement
|
|
39
|
-
* @param node The node to check
|
|
40
|
-
* @returns
|
|
72
|
+
* Check if a node is a conditional expression or a control flow statement.
|
|
73
|
+
* @param node The node to check.
|
|
74
|
+
* @returns `true` if the node is conditional.
|
|
41
75
|
*/
|
|
42
76
|
declare const isConditional: (node: TSESTree.Node | null | undefined) => node is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
43
77
|
declare namespace compare_d_exports {
|
|
44
78
|
export { isEqual };
|
|
45
79
|
}
|
|
46
80
|
/**
|
|
47
|
-
* Check if two nodes are equal.
|
|
48
|
-
* @param a node to compare.
|
|
49
|
-
* @param b node to compare.
|
|
50
|
-
* @returns `true` if
|
|
81
|
+
* Check if two nodes are structurally equal.
|
|
82
|
+
* @param a The first node to compare.
|
|
83
|
+
* @param b The second node to compare.
|
|
84
|
+
* @returns `true` if the nodes are equal.
|
|
51
85
|
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
52
86
|
*/
|
|
53
87
|
declare const isEqual: {
|
|
@@ -57,18 +91,65 @@ declare const isEqual: {
|
|
|
57
91
|
declare namespace extract_d_exports {
|
|
58
92
|
export { findProperty, getCalleeName, getFullyQualifiedName, getIdentifierAt, getPropertyName, unwrap };
|
|
59
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
|
|
96
|
+
* @param node The node to unwrap.
|
|
97
|
+
* @returns The innermost non-type-expression node.
|
|
98
|
+
*/
|
|
60
99
|
declare function unwrap(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
100
|
+
/**
|
|
101
|
+
* Find a property by name in a list of object literal properties, recursing into spread object expressions.
|
|
102
|
+
* @param properties The object literal properties to search.
|
|
103
|
+
* @param name The property name to look for.
|
|
104
|
+
* @returns The matching `Property` node, or `null` when not found.
|
|
105
|
+
*/
|
|
61
106
|
declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
|
|
107
|
+
/**
|
|
108
|
+
* Get the name of the callee of a call expression.
|
|
109
|
+
* @param node The call expression to inspect.
|
|
110
|
+
* @returns The callee name (ex: `"useState"`), or `null` when it cannot be statically determined.
|
|
111
|
+
*/
|
|
62
112
|
declare function getCalleeName(node: TSESTree.CallExpression): string | null;
|
|
113
|
+
/**
|
|
114
|
+
* Get the static name of an object property's key.
|
|
115
|
+
* @param property The property to inspect.
|
|
116
|
+
* @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
|
|
117
|
+
* @returns The property name, or `null` when it cannot be statically determined.
|
|
118
|
+
*/
|
|
63
119
|
declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
|
|
122
|
+
* @param node The node to inspect.
|
|
123
|
+
* @param getText A function returning the source text of a node.
|
|
124
|
+
* @returns The fully qualified name.
|
|
125
|
+
*/
|
|
64
126
|
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Get the identifier at a given position in a member expression chain (ex: position `0` in `a.b.c` is `a`).
|
|
129
|
+
* @param node The expression to walk.
|
|
130
|
+
* @param position The position of the identifier to return.
|
|
131
|
+
* @returns The identifier at the given position, or `null` when there is none.
|
|
132
|
+
*/
|
|
65
133
|
declare function getIdentifierAt(node: TSESTree.Expression | TSESTree.PrivateIdentifier, position: number): TSESTree.Identifier | null;
|
|
66
134
|
declare namespace traverse_d_exports {
|
|
67
|
-
export { findParent };
|
|
135
|
+
export { findEnclosingTryBlock, findParent };
|
|
68
136
|
}
|
|
69
137
|
type Predicate<T extends TSESTree.Node> = (node: TSESTree.Node) => node is T;
|
|
70
138
|
type NodePredicate = (node: TSESTree.Node) => boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Walk up the AST from `node` to find the nearest ancestor matching a predicate.
|
|
141
|
+
* @param node The starting node for the upward search.
|
|
142
|
+
* @param test The predicate a candidate ancestor must satisfy.
|
|
143
|
+
* @param stop An optional predicate that aborts the search when it returns `true`.
|
|
144
|
+
* @returns The first matching ancestor, or `null` when none is found.
|
|
145
|
+
*/
|
|
71
146
|
declare function findParent<T extends TSESTree.Node>(node: TSESTree.Node | null, test: Predicate<T>, stop?: NodePredicate): T | null;
|
|
72
147
|
declare function findParent(node: TSESTree.Node | null, test: NodePredicate, stop?: NodePredicate): TSESTree.Node | null;
|
|
148
|
+
/**
|
|
149
|
+
* Finds the nearest TryStatement whose `try` block (not catch/finally) encloses the given node.
|
|
150
|
+
* @param node The node to check.
|
|
151
|
+
* @returns The enclosing TryStatement, or null if none is found.
|
|
152
|
+
*/
|
|
153
|
+
declare function findEnclosingTryBlock(node: TSESTree.Node): TSESTree.TryStatement | null;
|
|
73
154
|
//#endregion
|
|
74
155
|
export { check_d_exports as Check, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, traverse_d_exports as Traverse };
|
package/dist/index.js
CHANGED
|
@@ -22,35 +22,58 @@ var check_exports = /* @__PURE__ */ __exportAll({
|
|
|
22
22
|
isTypeAssertionExpression: () => isTypeAssertionExpression,
|
|
23
23
|
isTypeExpression: () => isTypeExpression
|
|
24
24
|
});
|
|
25
|
+
/** Check if a node is of the given type. */
|
|
25
26
|
const is = ASTUtils.isNodeOfType;
|
|
27
|
+
/** Check if a node is one of the given types. */
|
|
26
28
|
const isOneOf = ASTUtils.isNodeOfTypes;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a node is a directive statement (ex: `"use client"`), optionally matching a specific directive name.
|
|
31
|
+
* @param node The node to check.
|
|
32
|
+
* @param name The directive name to match. When omitted, any directive matches.
|
|
33
|
+
* @returns `true` if the node is a matching directive statement.
|
|
34
|
+
*/
|
|
27
35
|
function isDirective(node, name) {
|
|
28
36
|
return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
|
|
29
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a node is an identifier, optionally matching a specific name.
|
|
40
|
+
* @param node The node to check.
|
|
41
|
+
* @param name The identifier name to match. When omitted, any identifier matches.
|
|
42
|
+
* @returns `true` if the node is a matching identifier.
|
|
43
|
+
*/
|
|
30
44
|
function isIdentifier(node, name) {
|
|
31
45
|
return node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
|
|
32
46
|
}
|
|
47
|
+
/** Check if a node is a class declaration or class expression. */
|
|
33
48
|
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
49
|
+
/** Check if a node is a function declaration, function expression, or arrow function expression. */
|
|
34
50
|
const isFunction = isOneOf([
|
|
35
51
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
36
52
|
AST_NODE_TYPES.FunctionDeclaration,
|
|
37
53
|
AST_NODE_TYPES.FunctionExpression
|
|
38
54
|
]);
|
|
55
|
+
/** Check if a node is a property-like node (property definition, index signature, parameter property, or property signature). */
|
|
39
56
|
const isProperty = isOneOf([
|
|
40
57
|
AST_NODE_TYPES.PropertyDefinition,
|
|
41
58
|
AST_NODE_TYPES.TSIndexSignature,
|
|
42
59
|
AST_NODE_TYPES.TSParameterProperty,
|
|
43
60
|
AST_NODE_TYPES.TSPropertySignature
|
|
44
61
|
]);
|
|
62
|
+
/** Check if a node is a property or method definition. */
|
|
45
63
|
const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
|
|
64
|
+
/** Check if a node is a JSX element. */
|
|
46
65
|
const isJSXElement = is(AST_NODE_TYPES.JSXElement);
|
|
66
|
+
/** Check if a node is a JSX fragment. */
|
|
47
67
|
const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
|
|
68
|
+
/** Check if a node is a JSX element or JSX fragment. */
|
|
48
69
|
const isJSXElementOrFragment = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
|
|
70
|
+
/** Check if a node can appear as a JSX tag name. */
|
|
49
71
|
const isJSXTagNameExpression = isOneOf([
|
|
50
72
|
AST_NODE_TYPES.JSXIdentifier,
|
|
51
73
|
AST_NODE_TYPES.JSXMemberExpression,
|
|
52
74
|
AST_NODE_TYPES.JSXNamespacedName
|
|
53
75
|
]);
|
|
76
|
+
/** Check if a node is any JSX-related node. */
|
|
54
77
|
const isJSX = isOneOf([
|
|
55
78
|
AST_NODE_TYPES.JSXAttribute,
|
|
56
79
|
AST_NODE_TYPES.JSXClosingElement,
|
|
@@ -68,6 +91,7 @@ const isJSX = isOneOf([
|
|
|
68
91
|
AST_NODE_TYPES.JSXSpreadChild,
|
|
69
92
|
AST_NODE_TYPES.JSXText
|
|
70
93
|
]);
|
|
94
|
+
/** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
|
|
71
95
|
const isTypeExpression = isOneOf([
|
|
72
96
|
AST_NODE_TYPES.TSAsExpression,
|
|
73
97
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
@@ -75,12 +99,14 @@ const isTypeExpression = isOneOf([
|
|
|
75
99
|
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
76
100
|
AST_NODE_TYPES.TSInstantiationExpression
|
|
77
101
|
]);
|
|
102
|
+
/** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
|
|
78
103
|
const isTypeAssertionExpression = isOneOf([
|
|
79
104
|
AST_NODE_TYPES.TSAsExpression,
|
|
80
105
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
81
106
|
AST_NODE_TYPES.TSNonNullExpression,
|
|
82
107
|
AST_NODE_TYPES.TSSatisfiesExpression
|
|
83
108
|
]);
|
|
109
|
+
/** Check if a node is an expression node. */
|
|
84
110
|
const isExpression = isOneOf([
|
|
85
111
|
AST_NODE_TYPES.ArrayExpression,
|
|
86
112
|
AST_NODE_TYPES.ArrayPattern,
|
|
@@ -119,9 +145,9 @@ const isExpression = isOneOf([
|
|
|
119
145
|
AST_NODE_TYPES.YieldExpression
|
|
120
146
|
]);
|
|
121
147
|
/**
|
|
122
|
-
* Check if a node is a conditional expression or control flow statement
|
|
123
|
-
* @param node The node to check
|
|
124
|
-
* @returns
|
|
148
|
+
* Check if a node is a conditional expression or a control flow statement.
|
|
149
|
+
* @param node The node to check.
|
|
150
|
+
* @returns `true` if the node is conditional.
|
|
125
151
|
*/
|
|
126
152
|
const isConditional = isOneOf([
|
|
127
153
|
AST_NODE_TYPES.DoWhileStatement,
|
|
@@ -619,10 +645,21 @@ var extract_exports = /* @__PURE__ */ __exportAll({
|
|
|
619
645
|
getPropertyName: () => getPropertyName,
|
|
620
646
|
unwrap: () => unwrap
|
|
621
647
|
});
|
|
648
|
+
/**
|
|
649
|
+
* Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
|
|
650
|
+
* @param node The node to unwrap.
|
|
651
|
+
* @returns The innermost non-type-expression node.
|
|
652
|
+
*/
|
|
622
653
|
function unwrap(node) {
|
|
623
654
|
if (isTypeExpression(node) || node.type === AST_NODE_TYPES.ChainExpression) return unwrap(node.expression);
|
|
624
655
|
return node;
|
|
625
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* Find a property by name in a list of object literal properties, recursing into spread object expressions.
|
|
659
|
+
* @param properties The object literal properties to search.
|
|
660
|
+
* @param name The property name to look for.
|
|
661
|
+
* @returns The matching `Property` node, or `null` when not found.
|
|
662
|
+
*/
|
|
626
663
|
function findProperty(properties, name) {
|
|
627
664
|
for (const property of properties) {
|
|
628
665
|
if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
|
|
@@ -633,12 +670,23 @@ function findProperty(properties, name) {
|
|
|
633
670
|
}
|
|
634
671
|
return null;
|
|
635
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Get the name of the callee of a call expression.
|
|
675
|
+
* @param node The call expression to inspect.
|
|
676
|
+
* @returns The callee name (ex: `"useState"`), or `null` when it cannot be statically determined.
|
|
677
|
+
*/
|
|
636
678
|
function getCalleeName(node) {
|
|
637
679
|
const callee = unwrap(node.callee);
|
|
638
680
|
if (callee.type === AST_NODE_TYPES.Identifier) return callee.name;
|
|
639
681
|
if (callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES.Identifier) return callee.property.name;
|
|
640
682
|
return null;
|
|
641
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* Get the static name of an object property's key.
|
|
686
|
+
* @param property The property to inspect.
|
|
687
|
+
* @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
|
|
688
|
+
* @returns The property name, or `null` when it cannot be statically determined.
|
|
689
|
+
*/
|
|
642
690
|
function getPropertyName(property, effort = "min") {
|
|
643
691
|
const key = unwrap(property.key);
|
|
644
692
|
if (key.type === AST_NODE_TYPES.Identifier && !property.computed) return key.name;
|
|
@@ -647,6 +695,12 @@ function getPropertyName(property, effort = "min") {
|
|
|
647
695
|
if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
|
|
648
696
|
return null;
|
|
649
697
|
}
|
|
698
|
+
/**
|
|
699
|
+
* Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
|
|
700
|
+
* @param node The node to inspect.
|
|
701
|
+
* @param getText A function returning the source text of a node.
|
|
702
|
+
* @returns The fully qualified name.
|
|
703
|
+
*/
|
|
650
704
|
function getFullyQualifiedName(node, getText) {
|
|
651
705
|
const expr = unwrap(node);
|
|
652
706
|
switch (expr.type) {
|
|
@@ -663,6 +717,12 @@ function getFullyQualifiedName(node, getText) {
|
|
|
663
717
|
default: return getText(expr);
|
|
664
718
|
}
|
|
665
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* Get the identifier at a given position in a member expression chain (ex: position `0` in `a.b.c` is `a`).
|
|
722
|
+
* @param node The expression to walk.
|
|
723
|
+
* @param position The position of the identifier to return.
|
|
724
|
+
* @returns The identifier at the given position, or `null` when there is none.
|
|
725
|
+
*/
|
|
666
726
|
function getIdentifierAt(node, position) {
|
|
667
727
|
const identifiers = [];
|
|
668
728
|
let current = unwrap(node);
|
|
@@ -679,10 +739,10 @@ function getIdentifierAt(node, position) {
|
|
|
679
739
|
//#region src/compare.ts
|
|
680
740
|
var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
|
|
681
741
|
/**
|
|
682
|
-
* Check if two nodes are equal.
|
|
683
|
-
* @param a node to compare.
|
|
684
|
-
* @param b node to compare.
|
|
685
|
-
* @returns `true` if
|
|
742
|
+
* Check if two nodes are structurally equal.
|
|
743
|
+
* @param a The first node to compare.
|
|
744
|
+
* @param b The second node to compare.
|
|
745
|
+
* @returns `true` if the nodes are equal.
|
|
686
746
|
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
687
747
|
*/
|
|
688
748
|
const isEqual = dual(2, (a, b) => {
|
|
@@ -736,7 +796,10 @@ const isEqual = dual(2, (a, b) => {
|
|
|
736
796
|
|
|
737
797
|
//#endregion
|
|
738
798
|
//#region src/traverse.ts
|
|
739
|
-
var traverse_exports = /* @__PURE__ */ __exportAll({
|
|
799
|
+
var traverse_exports = /* @__PURE__ */ __exportAll({
|
|
800
|
+
findEnclosingTryBlock: () => findEnclosingTryBlock,
|
|
801
|
+
findParent: () => findParent
|
|
802
|
+
});
|
|
740
803
|
function findParent(node, test, stop) {
|
|
741
804
|
if (node == null) return null;
|
|
742
805
|
let current = node.parent;
|
|
@@ -748,6 +811,17 @@ function findParent(node, test, stop) {
|
|
|
748
811
|
}
|
|
749
812
|
return null;
|
|
750
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* Finds the nearest TryStatement whose `try` block (not catch/finally) encloses the given node.
|
|
816
|
+
* @param node The node to check.
|
|
817
|
+
* @returns The enclosing TryStatement, or null if none is found.
|
|
818
|
+
*/
|
|
819
|
+
function findEnclosingTryBlock(node) {
|
|
820
|
+
const parent = node.parent;
|
|
821
|
+
if (parent == null || parent.type === AST_NODE_TYPES.Program) return null;
|
|
822
|
+
if (parent.type === AST_NODE_TYPES.TryStatement && node === parent.block) return parent;
|
|
823
|
+
return findEnclosingTryBlock(parent);
|
|
824
|
+
}
|
|
751
825
|
|
|
752
826
|
//#endregion
|
|
753
827
|
export { check_exports as Check, compare_exports as Compare, extract_exports as Extract, traverse_exports as Traverse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.1",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@typescript-eslint/types": "^8.
|
|
33
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
34
|
-
"@typescript-eslint/utils": "^8.
|
|
32
|
+
"@typescript-eslint/types": "^8.65.0",
|
|
33
|
+
"@typescript-eslint/typescript-estree": "^8.65.0",
|
|
34
|
+
"@typescript-eslint/utils": "^8.65.0",
|
|
35
35
|
"string-ts": "^2.3.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@typescript-eslint/parser": "^8.
|
|
39
|
-
"eslint": "^10.
|
|
40
|
-
"tsdown": "^0.22.
|
|
38
|
+
"@typescript-eslint/parser": "^8.65.0",
|
|
39
|
+
"eslint": "^10.8.0",
|
|
40
|
+
"tsdown": "^0.22.14",
|
|
41
41
|
"typescript": "6.0.3",
|
|
42
42
|
"vitest": "^4.1.10",
|
|
43
|
-
"@local/configs": "0.0.0",
|
|
44
43
|
"@local/eff": "0.0.0",
|
|
45
|
-
"@local/testkit": "0.0.0"
|
|
44
|
+
"@local/testkit": "0.0.0",
|
|
45
|
+
"@local/configs": "0.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"eslint": "*",
|