@eslint-react/ast 5.2.1-next.3 → 5.2.2-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.
@@ -0,0 +1,18 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!no_symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll as t };
package/dist/index.d.ts CHANGED
@@ -1,205 +1,77 @@
1
- import { TSESTree } from "@typescript-eslint/types";
1
+ import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
2
 
3
- //#region src/expression-is.d.ts
4
- /**
5
- * Check if the given expression is a 'this' expression
6
- * Unwraps any type expressions before checking
7
- *
8
- * @param node The expression node to check
9
- * @returns True if the expression is a 'this' expression, false otherwise
10
- */
11
- declare function isThisExpressionLoose(node: TSESTree.Expression): boolean;
12
- //#endregion
13
- //#region src/file.d.ts
14
- /**
15
- * Check if a directive with the given name exists in the file directives
16
- * @param node The program AST node
17
- * @param name The directive name to check (ex: "use strict", "use memo", "use no memo")
18
- * @returns True if the directive exists, false otherwise
19
- */
20
- declare function isFileHasDirective(node: TSESTree.Program, name: string): boolean;
21
- //#endregion
22
- //#region src/identifier-is.d.ts
23
- /**
24
- * Check if the given node is an identifier
25
- * @param node The node to check
26
- * @param name The name to check
27
- * @returns True if the node is an identifier, false otherwise
28
- */
29
- declare function isIdentifier(node: TSESTree.Node | null, name?: string): node is TSESTree.Identifier;
30
- //#endregion
31
- //#region src/identifier-traverse.d.ts
32
- /**
33
- * Get the root identifier of a (possibly nested) member expression.
34
- * For `a.b.c`, returns the `a` Identifier node.
35
- * @param node The expression to analyze
36
- * @returns The root Identifier node, or null if it cannot be determined (ex: non-identifier root)
37
- */
38
- declare function getRootIdentifier(node: TSESTree.Expression | TSESTree.PrivateIdentifier): TSESTree.Identifier | null;
39
- //#endregion
40
- //#region src/literal-is.d.ts
41
- /**
42
- * Check if a node is a literal value
43
- * @param node The node to check
44
- * @returns True if the node is a literal
45
- */
46
- declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
47
- declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
48
- declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
49
- declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
50
- declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
51
- declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
52
- //#endregion
53
- //#region src/node-equality.d.ts
54
- /**
55
- * Check if two nodes are equal
56
- * @param a node to compare
57
- * @param b node to compare
58
- * @returns `true` if node equal
59
- * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
60
- */
61
- declare const isNodeEqual: {
62
- (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
63
- (a: TSESTree.Node, b: TSESTree.Node): boolean;
64
- };
65
- //#endregion
66
- //#region src/node-types.d.ts
67
- /**
68
- * Represents function expressions and declarations in TSESTree
69
- */
70
- type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
71
- /**
72
- * Represents class declarations and expressions in TSESTree
73
- */
74
- type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
75
- /**
76
- * Represents method definitions and property definitions in classes
77
- */
78
- type TSESTreeMethodOrProperty = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
79
- /**
80
- * Represents all JSX-related nodes in TSESTree
81
- * Note: This type is for type-level operations. The isJSX() runtime guard in node-is.ts
82
- * has a slightly different set of nodes as it includes JSXExpressionContainer which is
83
- * commonly needed for runtime checks but not included in this type union.
84
- */
85
- type TSESTreeJSX = TSESTree.JSXAttribute | TSESTree.JSXChild | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXEmptyExpression | TSESTree.JSXIdentifierToken | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXTagNameExpression | TSESTree.JSXTextToken;
86
- type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
87
- /**
88
- * Represents JSX attribute-like nodes (attributes and spread attributes)
89
- */
90
- type TSESTreeJSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
91
- /**
92
- * Represents a directive expression statement in TSESTree (ex: "use strict";)
93
- */
94
- type TSESTreeDirective = TSESTree.ExpressionStatement & {
3
+ //#region src/types.d.ts
4
+ type Node = TSESTree.Node;
5
+ type Program = TSESTree.Program;
6
+ type Expression = TSESTree.Expression;
7
+ type Statement = TSESTree.Statement;
8
+ type Identifier = TSESTree.Identifier;
9
+ type FunctionExpression = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
10
+ type ClassExpression = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
11
+ type MethodOrPropertyDefinition = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
12
+ type JSXNode = TSESTree.JSXAttribute | TSESTree.JSXChild | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXEmptyExpression | TSESTree.JSXIdentifierToken | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXTagNameExpression | TSESTree.JSXTextToken;
13
+ type JSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
14
+ type JSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
15
+ type Directive = TSESTree.ExpressionStatement & {
95
16
  directive: string;
96
17
  expression: TSESTree.StringLiteral;
97
18
  };
98
- type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
99
- //#endregion
100
- //#region src/node-is.d.ts
101
- /**
102
- * Type guard to check if a node is of a specific AST node type
103
- * @param nodeType The AST node type to check against
104
- * @returns A type guard function that narrows the node type
105
- */
106
- declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
19
+ type TypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
20
+ declare namespace check_d_exports {
21
+ export { directive, identifier, is, isClass, isFunction, isJSX, isJSXElement, isJSXFragment, isJSXLike, isJSXTagNameExpression, isMethodOrProperty, isOneOf, isProperty, isTypeAssertionExpression, isTypeExpression, literal, thisExpression };
22
+ }
23
+ declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
107
24
  type: NodeType;
108
25
  }>;
109
- /**
110
- * Type guard to check if a node is one of multiple AST node types
111
- * @param nodeTypes Array of AST node types to check against
112
- * @returns A type guard function that narrows the node type
113
- */
114
- declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
26
+ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
115
27
  type: NodeTypes[number];
116
28
  }>;
117
- /**
118
- * Check if a node is a function (arrow, declaration, or expression)
119
- * @param node The node to check
120
- * @returns True if the node is a function
121
- */
29
+ declare function identifier(node: TSESTree.Node | null, named?: string): node is TSESTree.Identifier;
30
+ declare function literal(node: TSESTree.Node): node is TSESTree.Literal;
31
+ declare function literal(node: TSESTree.Node, ofKind: "boolean"): node is TSESTree.BooleanLiteral;
32
+ declare function literal(node: TSESTree.Node, ofKind: "null"): node is TSESTree.NullLiteral;
33
+ declare function literal(node: TSESTree.Node, ofKind: "number"): node is TSESTree.NumberLiteral;
34
+ declare function literal(node: TSESTree.Node, ofKind: "regexp"): node is TSESTree.RegExpLiteral;
35
+ declare function literal(node: TSESTree.Node, ofKind: "string"): node is TSESTree.StringLiteral;
36
+ declare function thisExpression(expression: TSESTree.Expression): boolean;
122
37
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
123
- /**
124
- * Check if a node is a class declaration or expression
125
- * @param node The node to check
126
- * @returns True if the node is a class
127
- */
128
38
  declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
129
- /**
130
- * Check if a node is a method or property definition
131
- * @param node The node to check
132
- * @returns True if the node is a method or property definition
133
- */
134
39
  declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
135
- /**
136
- * Check if a node is a property-like node (including TypeScript property signatures)
137
- * @param node The node to check
138
- * @returns True if the node is a property
139
- */
140
40
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
141
- /**
142
- * Check if a node is a JSX element
143
- * @param node The node to check
144
- * @returns True if the node is a JSX element
145
- */
146
41
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
147
- /**
148
- * Check if a node is a JSX element or JSX fragment
149
- */
150
- declare const isJSXElementLike: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
151
- /**
152
- * Check if a node is a JSX tag name expression (identifier, member expression, or namespaced name)
153
- * @param node The node to check
154
- * @returns True if the node is a JSX tag name expression
155
- */
42
+ declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
43
+ declare const isJSXLike: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
156
44
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
157
- /**
158
- * Check if a node is a JSX-related node
159
- * Note: This runtime guard includes JSXExpressionContainer which is commonly needed
160
- * for AST traversals but not included in the TSESTreeJSX type union.
161
- * @param node The node to check
162
- * @returns True if the node is a JSX node
163
- * @see TSESTreeJSX
164
- */
165
45
  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;
166
- /**
167
- * Check if a node is a TypeScript type expression
168
- * @param node The node to check
169
- * @returns True if the node is a type expression
170
- */
171
46
  declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
172
- /**
173
- * Check if a node is a TypeScript type assertion expression
174
- * @param node The node to check
175
- * @returns True if the node is a type assertion expression
176
- */
177
47
  declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
48
+ declare function directive(node: TSESTree.Node): node is Directive;
49
+ declare namespace compare_d_exports {
50
+ export { areEqual };
51
+ }
178
52
  /**
179
- * Check if a node is a directive expression statement
180
- * @param node The node to check
181
- * @returns True if the node is a directive, false otherwise
182
- */
183
- declare function isDirective(node: TSESTree.Node): node is TSESTreeDirective;
184
- //#endregion
185
- //#region src/node-kind.d.ts
186
- declare function getHumanReadableKind(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
187
- //#endregion
188
- //#region src/node-name.d.ts
189
- declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
190
- //#endregion
191
- //#region src/node-selectors.d.ts
192
- /**
193
- * Represents a variable declarator with object destructuring and an identifier initializer
53
+ * Check if two nodes are equal
54
+ * @param a node to compare
55
+ * @param b node to compare
56
+ * @returns `true` if node equal
57
+ * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
194
58
  */
195
- type ObjectDestructuringVariableDeclarator = TSESTree.VariableDeclarator & {
196
- id: TSESTree.ObjectPattern;
197
- init: TSESTree.Identifier;
59
+ declare const areEqual: {
60
+ (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
61
+ (a: TSESTree.Node, b: TSESTree.Node): boolean;
198
62
  };
199
- /**
200
- * Represents an assignment expression that assigns to a displayName property
201
- */
202
- type DisplayNameAssignmentExpression = TSESTree.AssignmentExpression & {
63
+ declare namespace extract_d_exports {
64
+ export { fullyQualifiedName, humanReadableKind, propertyName, rootIdentifier, unwrapped };
65
+ }
66
+ declare function unwrapped(from: TSESTree.Node): Exclude<TSESTree.Node, TypeExpression>;
67
+ declare function rootIdentifier(from: TSESTree.Expression | TSESTree.PrivateIdentifier): TSESTree.Identifier | null;
68
+ declare function propertyName(from: TSESTree.Node): string | null;
69
+ declare function fullyQualifiedName(from: TSESTree.Node, using: (node: TSESTree.Node) => string): string;
70
+ declare function humanReadableKind(of: TSESTree.Node, delimiter?: string): string;
71
+ declare namespace select_d_exports {
72
+ export { DisplayNameAssignment, displayNameAssignment };
73
+ }
74
+ type DisplayNameAssignment = TSESTree.AssignmentExpression & {
203
75
  left: TSESTree.MemberExpression & {
204
76
  property: TSESTree.Identifier & {
205
77
  name: "displayName";
@@ -208,58 +80,14 @@ type DisplayNameAssignmentExpression = TSESTree.AssignmentExpression & {
208
80
  operator: "=";
209
81
  right: TSESTree.Literal;
210
82
  };
211
- /**
212
- * Selector for variable declarators with object destructuring
213
- */
214
- declare const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR: string;
215
- /**
216
- * Selector for assignment expressions that set displayName
217
- */
218
- declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
219
- //#endregion
220
- //#region src/node-traverse.d.ts
221
- /**
222
- * Find the parent node that satisfies the test function
223
- * @param node The AST node
224
- * @param test The test function
225
- * @returns The parent node that satisfies the test function or `null` if not found
226
- */
227
- declare function findParent<A extends TSESTree.Node>(node: TSESTree.Node | null, test: (n: TSESTree.Node) => n is A): A | null;
228
- /**
229
- * Find the parent node that satisfies the test function or `null` if not found
230
- * @param node The AST node
231
- * @param test The test function
232
- * @returns The parent node that satisfies the test function
233
- */
234
- declare function findParent(node: TSESTree.Node | null, test: (node: TSESTree.Node) => boolean): TSESTree.Node | null;
235
- //#endregion
236
- //#region src/node-unwrap.d.ts
237
- /**
238
- * Unwraps any type expressions to get the underlying JavaScript expression node.
239
- * Recursively processes nodes until a non-type expression is found.
240
- * @param node The AST node to unwrap
241
- * @returns The underlying JavaScript expression node
242
- */
243
- declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
244
- //#endregion
245
- //#region src/property-name.d.ts
246
- /**
247
- * Get the name of a property from a node
248
- * Handles identifiers, private identifiers, literals, and template literals
249
- * @param node The node to get the property name from
250
- * @returns The property name or null if not determinable
251
- */
252
- declare function getPropertyName(node: TSESTree.Node): string | null;
253
- //#endregion
254
- //#region src/property-traverse.d.ts
255
- /**
256
- * Recursively traverses an object expression's properties to find a property with the specified name
257
- * Note: This only handles inline object literals in spread elements. Properties from variables
258
- * (e.g., `{...props}` where props is a variable) are not resolved.
259
- * @param properties The properties of the object expression to traverse
260
- * @param name The name of the property to find
261
- * @returns The matching property node, or null if not found
262
- */
263
- declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
83
+ declare const displayNameAssignment: string;
84
+ declare namespace traverse_d_exports {
85
+ export { NodePredicate, Predicate, findParent, findProperty };
86
+ }
87
+ type Predicate<T extends TSESTree.Node> = (node: TSESTree.Node) => node is T;
88
+ type NodePredicate = (node: TSESTree.Node) => boolean;
89
+ declare function findParent<T extends TSESTree.Node>(of: TSESTree.Node | null, where: Predicate<T>): T | null;
90
+ declare function findParent(of: TSESTree.Node | null, where: NodePredicate): TSESTree.Node | null;
91
+ declare function findProperty(in_: TSESTree.ObjectLiteralElement[], named: string): TSESTree.Property | null;
264
92
  //#endregion
265
- export { DisplayNameAssignmentExpression, ObjectDestructuringVariableDeclarator, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, TSESTreeClass, TSESTreeDirective, TSESTreeFunction, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeJSXElementLike, TSESTreeMethodOrProperty, TSESTreeTypeExpression, findParent, findProperty, getFullyQualifiedName, getHumanReadableKind, getPropertyName, getRootIdentifier, getUnderlyingExpression, is, isClass, isDirective, isFileHasDirective, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementLike, isJSXTagNameExpression, isLiteral, isMethodOrProperty, isNodeEqual, isOneOf, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression };
93
+ export { check_d_exports as Check, ClassExpression, compare_d_exports as Compare, Directive, Expression, extract_d_exports as Extract, FunctionExpression, Identifier, JSXAttributeLike, JSXElementLike, JSXNode, MethodOrPropertyDefinition, Node, Program, select_d_exports as Select, Statement, traverse_d_exports as Traverse, TypeExpression, is, isOneOf };
package/dist/index.js CHANGED
@@ -1,81 +1,69 @@
1
- import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
2
3
  import { ASTUtils } from "@typescript-eslint/utils";
3
4
  import { delimiterCase, replace, toLowerCase } from "string-ts";
4
5
 
5
- //#region src/node-is.ts
6
- /**
7
- * Type guard to check if a node is of a specific AST node type
8
- * @param nodeType The AST node type to check against
9
- * @returns A type guard function that narrows the node type
10
- */
6
+ //#region src/check.ts
7
+ var check_exports = /* @__PURE__ */ __exportAll({
8
+ directive: () => directive,
9
+ identifier: () => identifier,
10
+ is: () => is,
11
+ isClass: () => isClass,
12
+ isFunction: () => isFunction,
13
+ isJSX: () => isJSX,
14
+ isJSXElement: () => isJSXElement,
15
+ isJSXFragment: () => isJSXFragment,
16
+ isJSXLike: () => isJSXLike,
17
+ isJSXTagNameExpression: () => isJSXTagNameExpression,
18
+ isMethodOrProperty: () => isMethodOrProperty,
19
+ isOneOf: () => isOneOf,
20
+ isProperty: () => isProperty,
21
+ isTypeAssertionExpression: () => isTypeAssertionExpression,
22
+ isTypeExpression: () => isTypeExpression,
23
+ literal: () => literal,
24
+ thisExpression: () => thisExpression
25
+ });
11
26
  const is = ASTUtils.isNodeOfType;
12
- /**
13
- * Type guard to check if a node is one of multiple AST node types
14
- * @param nodeTypes Array of AST node types to check against
15
- * @returns A type guard function that narrows the node type
16
- */
17
27
  const isOneOf = ASTUtils.isNodeOfTypes;
18
- /**
19
- * Check if a node is a function (arrow, declaration, or expression)
20
- * @param node The node to check
21
- * @returns True if the node is a function
22
- */
28
+ function identifier(node, named) {
29
+ return node?.type === AST_NODE_TYPES.Identifier && (named == null || node.name === named);
30
+ }
31
+ function literal(node, ofKind) {
32
+ if (node.type !== AST_NODE_TYPES.Literal) return false;
33
+ if (ofKind == null) return true;
34
+ switch (ofKind) {
35
+ case "boolean": return typeof node.value === "boolean";
36
+ case "null": return node.value === null;
37
+ case "number": return typeof node.value === "number";
38
+ case "regexp": return "regex" in node;
39
+ case "string": return typeof node.value === "string";
40
+ default: return false;
41
+ }
42
+ }
43
+ function thisExpression(expression) {
44
+ return expression.type === AST_NODE_TYPES.ThisExpression;
45
+ }
23
46
  const isFunction = isOneOf([
24
47
  AST_NODE_TYPES.ArrowFunctionExpression,
25
48
  AST_NODE_TYPES.FunctionDeclaration,
26
49
  AST_NODE_TYPES.FunctionExpression
27
50
  ]);
28
- /**
29
- * Check if a node is a class declaration or expression
30
- * @param node The node to check
31
- * @returns True if the node is a class
32
- */
33
51
  const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
34
- /**
35
- * Check if a node is a method or property definition
36
- * @param node The node to check
37
- * @returns True if the node is a method or property definition
38
- */
39
52
  const isMethodOrProperty = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
40
- /**
41
- * Check if a node is a property-like node (including TypeScript property signatures)
42
- * @param node The node to check
43
- * @returns True if the node is a property
44
- */
45
53
  const isProperty = isOneOf([
46
54
  AST_NODE_TYPES.PropertyDefinition,
47
55
  AST_NODE_TYPES.TSIndexSignature,
48
56
  AST_NODE_TYPES.TSParameterProperty,
49
57
  AST_NODE_TYPES.TSPropertySignature
50
58
  ]);
51
- /**
52
- * Check if a node is a JSX element
53
- * @param node The node to check
54
- * @returns True if the node is a JSX element
55
- */
56
59
  const isJSXElement = is(AST_NODE_TYPES.JSXElement);
57
- /**
58
- * Check if a node is a JSX element or JSX fragment
59
- */
60
- const isJSXElementLike = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
61
- /**
62
- * Check if a node is a JSX tag name expression (identifier, member expression, or namespaced name)
63
- * @param node The node to check
64
- * @returns True if the node is a JSX tag name expression
65
- */
60
+ const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
61
+ const isJSXLike = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
66
62
  const isJSXTagNameExpression = isOneOf([
67
63
  AST_NODE_TYPES.JSXIdentifier,
68
64
  AST_NODE_TYPES.JSXMemberExpression,
69
65
  AST_NODE_TYPES.JSXNamespacedName
70
66
  ]);
71
- /**
72
- * Check if a node is a JSX-related node
73
- * Note: This runtime guard includes JSXExpressionContainer which is commonly needed
74
- * for AST traversals but not included in the TSESTreeJSX type union.
75
- * @param node The node to check
76
- * @returns True if the node is a JSX node
77
- * @see TSESTreeJSX
78
- */
79
67
  const isJSX = isOneOf([
80
68
  AST_NODE_TYPES.JSXAttribute,
81
69
  AST_NODE_TYPES.JSXClosingElement,
@@ -93,11 +81,6 @@ const isJSX = isOneOf([
93
81
  AST_NODE_TYPES.JSXSpreadChild,
94
82
  AST_NODE_TYPES.JSXText
95
83
  ]);
96
- /**
97
- * Check if a node is a TypeScript type expression
98
- * @param node The node to check
99
- * @returns True if the node is a type expression
100
- */
101
84
  const isTypeExpression = isOneOf([
102
85
  AST_NODE_TYPES.TSAsExpression,
103
86
  AST_NODE_TYPES.TSTypeAssertion,
@@ -105,108 +88,16 @@ const isTypeExpression = isOneOf([
105
88
  AST_NODE_TYPES.TSSatisfiesExpression,
106
89
  AST_NODE_TYPES.TSInstantiationExpression
107
90
  ]);
108
- /**
109
- * Check if a node is a TypeScript type assertion expression
110
- * @param node The node to check
111
- * @returns True if the node is a type assertion expression
112
- */
113
91
  const isTypeAssertionExpression = isOneOf([
114
92
  AST_NODE_TYPES.TSAsExpression,
115
93
  AST_NODE_TYPES.TSTypeAssertion,
116
94
  AST_NODE_TYPES.TSNonNullExpression,
117
95
  AST_NODE_TYPES.TSSatisfiesExpression
118
96
  ]);
119
- /**
120
- * Check if a node is a directive expression statement
121
- * @param node The node to check
122
- * @returns True if the node is a directive, false otherwise
123
- */
124
- function isDirective(node) {
97
+ function directive(node) {
125
98
  return node.type === AST_NODE_TYPES.ExpressionStatement && node.directive != null;
126
99
  }
127
100
 
128
- //#endregion
129
- //#region src/node-unwrap.ts
130
- /**
131
- * Unwraps any type expressions to get the underlying JavaScript expression node.
132
- * Recursively processes nodes until a non-type expression is found.
133
- * @param node The AST node to unwrap
134
- * @returns The underlying JavaScript expression node
135
- */
136
- function getUnderlyingExpression(node) {
137
- if (isTypeExpression(node)) return getUnderlyingExpression(node.expression);
138
- return node;
139
- }
140
-
141
- //#endregion
142
- //#region src/expression-is.ts
143
- /**
144
- * Check if the given expression is a 'this' expression
145
- * Unwraps any type expressions before checking
146
- *
147
- * @param node The expression node to check
148
- * @returns True if the expression is a 'this' expression, false otherwise
149
- */
150
- function isThisExpressionLoose(node) {
151
- return getUnderlyingExpression(node).type === AST_NODE_TYPES.ThisExpression;
152
- }
153
-
154
- //#endregion
155
- //#region src/file.ts
156
- /**
157
- * Check if a directive with the given name exists in the file directives
158
- * @param node The program AST node
159
- * @param name The directive name to check (ex: "use strict", "use memo", "use no memo")
160
- * @returns True if the directive exists, false otherwise
161
- */
162
- function isFileHasDirective(node, name) {
163
- for (const stmt of node.body) if (isDirective(stmt) && stmt.directive === name) return true;
164
- return false;
165
- }
166
-
167
- //#endregion
168
- //#region src/identifier-is.ts
169
- /**
170
- * Check if the given node is an identifier
171
- * @param node The node to check
172
- * @param name The name to check
173
- * @returns True if the node is an identifier, false otherwise
174
- */
175
- function isIdentifier(node, name) {
176
- return node != null && node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
177
- }
178
-
179
- //#endregion
180
- //#region src/identifier-traverse.ts
181
- /**
182
- * Get the root identifier of a (possibly nested) member expression.
183
- * For `a.b.c`, returns the `a` Identifier node.
184
- * @param node The expression to analyze
185
- * @returns The root Identifier node, or null if it cannot be determined (ex: non-identifier root)
186
- */
187
- function getRootIdentifier(node) {
188
- const expr = getUnderlyingExpression(node);
189
- switch (expr.type) {
190
- case AST_NODE_TYPES.Identifier: return expr;
191
- case AST_NODE_TYPES.MemberExpression: return getRootIdentifier(expr.object);
192
- default: return null;
193
- }
194
- }
195
-
196
- //#endregion
197
- //#region src/literal-is.ts
198
- function isLiteral(node, type) {
199
- if (node.type !== AST_NODE_TYPES.Literal) return false;
200
- if (type == null) return true;
201
- switch (type) {
202
- case "boolean": return typeof node.value === "boolean";
203
- case "null": return node.value === null;
204
- case "number": return typeof node.value === "number";
205
- case "regexp": return "regex" in node;
206
- case "string": return typeof node.value === "string";
207
- }
208
- }
209
-
210
101
  //#endregion
211
102
  //#region ../../.pkgs/eff/dist/index.js
212
103
  /**
@@ -326,7 +217,57 @@ const dual = function(arity, body) {
326
217
  const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
327
218
 
328
219
  //#endregion
329
- //#region src/node-equality.ts
220
+ //#region src/extract.ts
221
+ var extract_exports = /* @__PURE__ */ __exportAll({
222
+ fullyQualifiedName: () => fullyQualifiedName,
223
+ humanReadableKind: () => humanReadableKind,
224
+ propertyName: () => propertyName,
225
+ rootIdentifier: () => rootIdentifier,
226
+ unwrapped: () => unwrapped
227
+ });
228
+ function unwrapped(from) {
229
+ if (isTypeExpression(from)) return unwrapped(from.expression);
230
+ return from;
231
+ }
232
+ function rootIdentifier(from) {
233
+ const node = unwrapped(from);
234
+ if (node.type === AST_NODE_TYPES.Identifier) return node;
235
+ if (node.type === AST_NODE_TYPES.MemberExpression) return rootIdentifier(node.object);
236
+ return null;
237
+ }
238
+ function propertyName(from) {
239
+ if (isTypeExpression(from)) return propertyName(unwrapped(from));
240
+ if (from.type === AST_NODE_TYPES.Identifier || from.type === AST_NODE_TYPES.PrivateIdentifier) return from.name;
241
+ if (from.type === AST_NODE_TYPES.Literal) return String(from.value);
242
+ if (from.type === AST_NODE_TYPES.TemplateLiteral && from.expressions.length === 0) return from.quasis[0]?.value.cooked ?? from.quasis[0]?.value.raw ?? null;
243
+ return null;
244
+ }
245
+ function fullyQualifiedName(from, using) {
246
+ switch (from.type) {
247
+ case AST_NODE_TYPES.Identifier:
248
+ case AST_NODE_TYPES.JSXIdentifier:
249
+ case AST_NODE_TYPES.PrivateIdentifier: return from.name;
250
+ case AST_NODE_TYPES.MemberExpression:
251
+ case AST_NODE_TYPES.JSXMemberExpression: return `${fullyQualifiedName(from.object, using)}.${fullyQualifiedName(from.property, using)}`;
252
+ case AST_NODE_TYPES.JSXNamespacedName: return `${from.namespace.name}:${from.name.name}`;
253
+ case AST_NODE_TYPES.JSXText: return from.value;
254
+ case AST_NODE_TYPES.Literal: return from.raw;
255
+ default: return using(from);
256
+ }
257
+ }
258
+ function humanReadableKind(of, delimiter = " ") {
259
+ if (of.type === AST_NODE_TYPES.Literal) {
260
+ if ("regex" in of) return "RegExp literal";
261
+ if (of.value === null) return "null literal";
262
+ return `${typeof of.value} literal`;
263
+ }
264
+ if (isJSX(of)) return `JSX ${toLowerCase(delimiterCase(replace(of.type, "JSX", ""), delimiter))}`;
265
+ return toLowerCase(delimiterCase(of.type, delimiter));
266
+ }
267
+
268
+ //#endregion
269
+ //#region src/compare.ts
270
+ var compare_exports = /* @__PURE__ */ __exportAll({ areEqual: () => areEqual });
330
271
  /**
331
272
  * Check if two nodes are equal
332
273
  * @param a node to compare
@@ -334,9 +275,9 @@ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
334
275
  * @returns `true` if node equal
335
276
  * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
336
277
  */
337
- const isNodeEqual = dual(2, (a, b) => {
338
- a = isTypeExpression(a) ? getUnderlyingExpression(a) : a;
339
- b = isTypeExpression(b) ? getUnderlyingExpression(b) : b;
278
+ const areEqual = dual(2, (a, b) => {
279
+ a = isTypeExpression(a) ? unwrapped(a) : a;
280
+ b = isTypeExpression(b) ? unwrapped(b) : b;
340
281
  switch (true) {
341
282
  case a === b: return true;
342
283
  case a.type !== b.type: return false;
@@ -350,67 +291,29 @@ const isNodeEqual = dual(2, (a, b) => {
350
291
  while (i--) {
351
292
  const exprA = a.expressions[i];
352
293
  const exprB = b.expressions[i];
353
- if (!isNodeEqual(exprA, exprB)) return false;
294
+ if (!areEqual(exprA, exprB)) return false;
354
295
  }
355
296
  return true;
356
297
  }
357
298
  case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
358
299
  case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
359
- case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
300
+ case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return areEqual(a.property, b.property) && areEqual(a.object, b.object);
360
301
  case a.type === AST_NODE_TYPES.JSXIdentifier && b.type === AST_NODE_TYPES.JSXIdentifier: return a.name === b.name;
361
- case a.type === AST_NODE_TYPES.JSXNamespacedName && b.type === AST_NODE_TYPES.JSXNamespacedName: return isNodeEqual(a.namespace, b.namespace) && isNodeEqual(a.name, b.name);
362
- case a.type === AST_NODE_TYPES.JSXMemberExpression && b.type === AST_NODE_TYPES.JSXMemberExpression: return isNodeEqual(a.object, b.object) && isNodeEqual(a.property, b.property);
302
+ case a.type === AST_NODE_TYPES.JSXNamespacedName && b.type === AST_NODE_TYPES.JSXNamespacedName: return areEqual(a.namespace, b.namespace) && areEqual(a.name, b.name);
303
+ case a.type === AST_NODE_TYPES.JSXMemberExpression && b.type === AST_NODE_TYPES.JSXMemberExpression: return areEqual(a.object, b.object) && areEqual(a.property, b.property);
363
304
  case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
364
- if (!isNodeEqual(a.name, b.name)) return false;
305
+ if (!areEqual(a.name, b.name)) return false;
365
306
  if (a.value == null || b.value == null) return a.value === b.value;
366
- return isNodeEqual(a.value, b.value);
307
+ return areEqual(a.value, b.value);
367
308
  case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
368
309
  default: return false;
369
310
  }
370
311
  });
371
312
 
372
313
  //#endregion
373
- //#region src/node-kind.ts
374
- function getHumanReadableKind(node, delimiter = " ") {
375
- if (node.type === AST_NODE_TYPES.Literal) {
376
- if ("regex" in node) return "RegExp literal";
377
- if (node.value === null) return "null literal";
378
- return `${typeof node.value} literal`;
379
- }
380
- if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
381
- return toLowerCase(delimiterCase(node.type, delimiter));
382
- }
383
-
384
- //#endregion
385
- //#region src/node-name.ts
386
- function getFullyQualifiedName(node, getText) {
387
- switch (node.type) {
388
- case AST_NODE_TYPES.Identifier:
389
- case AST_NODE_TYPES.JSXIdentifier:
390
- case AST_NODE_TYPES.PrivateIdentifier: return node.name;
391
- case AST_NODE_TYPES.MemberExpression:
392
- case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(node.object, getText)}.${getFullyQualifiedName(node.property, getText)}`;
393
- case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
394
- case AST_NODE_TYPES.JSXText: return node.value;
395
- case AST_NODE_TYPES.Literal: return node.raw;
396
- default: return getText(node);
397
- }
398
- }
399
-
400
- //#endregion
401
- //#region src/node-selectors.ts
402
- /**
403
- * Selector for variable declarators with object destructuring
404
- */
405
- const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
406
- "VariableDeclarator",
407
- "[id.type='ObjectPattern']",
408
- "[init.type='Identifier']"
409
- ].join("");
410
- /**
411
- * Selector for assignment expressions that set displayName
412
- */
413
- const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
314
+ //#region src/select.ts
315
+ var select_exports = /* @__PURE__ */ __exportAll({ displayNameAssignment: () => displayNameAssignment });
316
+ const displayNameAssignment = [
414
317
  "AssignmentExpression",
415
318
  "[operator='=']",
416
319
  "[left.type='MemberExpression']",
@@ -418,48 +321,26 @@ const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION = [
418
321
  ].join("");
419
322
 
420
323
  //#endregion
421
- //#region src/node-traverse.ts
422
- function findParent(node, test) {
423
- if (node == null) return null;
424
- let parent = node.parent;
425
- while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
426
- if (test(parent)) return parent;
324
+ //#region src/traverse.ts
325
+ var traverse_exports = /* @__PURE__ */ __exportAll({
326
+ findParent: () => findParent,
327
+ findProperty: () => findProperty
328
+ });
329
+ function findParent(of, where) {
330
+ if (of == null) return null;
331
+ let parent = of.parent;
332
+ while (parent?.type !== AST_NODE_TYPES.Program) {
333
+ if (parent == null) return null;
334
+ if (where(parent)) return parent;
427
335
  parent = parent.parent;
428
336
  }
429
337
  return null;
430
338
  }
431
-
432
- //#endregion
433
- //#region src/property-name.ts
434
- /**
435
- * Get the name of a property from a node
436
- * Handles identifiers, private identifiers, literals, and template literals
437
- * @param node The node to get the property name from
438
- * @returns The property name or null if not determinable
439
- */
440
- function getPropertyName(node) {
441
- if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
442
- if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
443
- if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
444
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw ?? null;
445
- return null;
446
- }
447
-
448
- //#endregion
449
- //#region src/property-traverse.ts
450
- /**
451
- * Recursively traverses an object expression's properties to find a property with the specified name
452
- * Note: This only handles inline object literals in spread elements. Properties from variables
453
- * (e.g., `{...props}` where props is a variable) are not resolved.
454
- * @param properties The properties of the object expression to traverse
455
- * @param name The name of the property to find
456
- * @returns The matching property node, or null if not found
457
- */
458
- function findProperty(properties, name) {
459
- for (const prop of properties) {
460
- if (prop.type === AST_NODE_TYPES.Property && getPropertyName(prop.key) === name) return prop;
461
- if (prop.type === AST_NODE_TYPES.SpreadElement && prop.argument.type === AST_NODE_TYPES.ObjectExpression) {
462
- const found = findProperty(prop.argument.properties, name);
339
+ function findProperty(in_, named) {
340
+ for (const property of in_) {
341
+ if (property.type === AST_NODE_TYPES.Property && propertyName(property.key) === named) return property;
342
+ if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
343
+ const found = findProperty(property.argument.properties, named);
463
344
  if (found != null) return found;
464
345
  }
465
346
  }
@@ -467,4 +348,4 @@ function findProperty(properties, name) {
467
348
  }
468
349
 
469
350
  //#endregion
470
- export { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, findParent, findProperty, getFullyQualifiedName, getHumanReadableKind, getPropertyName, getRootIdentifier, getUnderlyingExpression, is, isClass, isDirective, isFileHasDirective, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementLike, isJSXTagNameExpression, isLiteral, isMethodOrProperty, isNodeEqual, isOneOf, isProperty, isThisExpressionLoose, isTypeAssertionExpression, isTypeExpression };
351
+ export { check_exports as Check, compare_exports as Compare, extract_exports as Extract, select_exports as Select, traverse_exports as Traverse, is, isOneOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.2.1-next.3",
3
+ "version": "5.2.2-next.0",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -52,6 +52,7 @@
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsdown --dts-resolve",
55
+ "build:docs": "typedoc",
55
56
  "lint:publish": "publint",
56
57
  "lint:ts": "tsl"
57
58
  }