@eslint-react/ast 5.30.0-beta.4 → 5.30.0-beta.6

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 CHANGED
@@ -1,30 +1,30 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
2
  import { VisitorKeys } from "@typescript-eslint/visitor-keys";
3
- /** Union of function-like node types. */
4
- type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
5
- /** Union of class-like node types. */
6
- type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
7
- /** Union of function-like and class-like node types. */
8
- type TSESTreeFunctionOrClass = TSESTreeFunction | TSESTreeClass;
9
- /** Union of method and property definition node types. */
10
- type TSESTreeMethodOrPropertyDefinition = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
11
3
  /** An expression statement that is a directive (ex: `"use strict"`). */
12
4
  type TSESTreeDirective = TSESTree.ExpressionStatement & {
13
5
  directive: string;
14
6
  expression: TSESTree.StringLiteral;
15
7
  };
8
+ /** Union of class-like node types. */
9
+ type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
10
+ /** Union of function-like node types. */
11
+ type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
12
+ /** Union of function-like and class-like node types. */
13
+ type TSESTreeFunctionOrClass = TSESTreeClass | TSESTreeFunction;
14
+ /** Union of method and property definition node types. */
15
+ type TSESTreeMethodOrPropertyDefinition = TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
16
16
  /** Union of all JSX-related node types. */
17
17
  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;
18
- /** Union of JSX element-like node types (element or fragment). */
19
- type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
20
18
  /** Union of JSX attribute-like node types (attribute or spread attribute). */
21
19
  type TSESTreeJSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
20
+ /** Union of JSX element-like node types (element or fragment). */
21
+ type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
22
22
  /** Union of TypeScript type expression node types. */
23
- type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
23
+ type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
24
24
  /** Union of expression node types that wrap another expression (TypeScript type expressions and chain expressions) — the nodes `Extract.unwrap` strips. */
25
- type TSESTreeTypeOrChainExpression = TSESTreeTypeExpression | TSESTree.ChainExpression;
25
+ type TSESTreeTypeOrChainExpression = TSESTree.ChainExpression | TSESTreeTypeExpression;
26
26
  declare namespace check_d_exports {
27
- export { is, isCallExpression, isClass, isConditional, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
27
+ export { is, isArrayPatternElementDefault, isCallExpression, isClass, isConditional, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isObjectPatternElementDefault, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
28
28
  }
29
29
  /** Check if a node is of the given type. */
30
30
  declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
@@ -51,18 +51,20 @@ declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSEST
51
51
  declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
52
52
  /** Check if a node is a call expression. */
53
53
  declare const isCallExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.CallExpression;
54
+ /** Check if a node is an expression node. */
55
+ 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;
54
56
  /** Check if a node is a member expression. */
55
57
  declare const isMemberExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName;
56
58
  /** Check if a node is an object expression. */
57
59
  declare const isObjectExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ObjectExpression;
58
- /** Check if a node is an expression node. */
59
- 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;
60
60
  /** Check if a node is a loop statement. */
61
61
  declare const isLoopStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
62
62
  /** Check if a node is a return statement. */
63
63
  declare const isReturnStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.ReturnStatement;
64
64
  /** Check if a node is a class declaration or class expression. */
65
65
  declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
66
+ /** Check if a node is a conditional or logical expression, or a control flow statement. */
67
+ 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;
66
68
  /** Check if a node is a function declaration, function expression, or arrow function expression. */
67
69
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
68
70
  /** Check if a node is a function declaration, function expression, arrow function expression, class declaration, or class expression. */
@@ -71,26 +73,39 @@ declare const isFunctionOrClass: (node: TSESTree.Node | null | undefined) => nod
71
73
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
72
74
  /** Check if a node is a property or method definition. */
73
75
  declare const isPropertyOrMethod: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
74
- /** Check if a node is a conditional or logical expression, or a control flow statement. */
75
- 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;
76
+ /**
77
+ * Check if a node is the default value of an array pattern element, i.e. an
78
+ * `AssignmentPattern` directly nested in an `ArrayPattern` (ex: `const [a = 1] = arr`).
79
+ * @param node The node to check.
80
+ * @returns `true` if the node is an array pattern element default.
81
+ */
82
+ declare function isArrayPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
83
+ /**
84
+ * Check if a node is the default value of an object pattern property, i.e. an
85
+ * `AssignmentPattern` used as the `value` of a `Property` inside an `ObjectPattern`
86
+ * (ex: `const { a = 1 } = obj`).
87
+ * @param node The node to check.
88
+ * @returns `true` if the node is an object pattern element default.
89
+ */
90
+ declare function isObjectPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
76
91
  /** Check if a node is any JSX-related node. */
77
92
  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;
78
93
  /** Check if a node is a JSX element. */
79
94
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
80
- /** Check if a node is a JSX fragment. */
81
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
82
95
  /** Check if a node is a JSX element or JSX fragment. */
83
96
  declare const isJSXElementOrFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
84
97
  /** Check if a node is a JSX expression container. */
85
98
  declare const isJSXExpressionContainer: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXExpressionContainer;
99
+ /** Check if a node is a JSX fragment. */
100
+ declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
86
101
  /** Check if a node is a JSX spread attribute. */
87
102
  declare const isJSXSpreadAttribute: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXSpreadAttribute;
88
103
  /** Check if a node can appear as a JSX tag name. */
89
104
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
90
- /** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
91
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
92
105
  /** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
93
106
  declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
107
+ /** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
108
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
94
109
  /** Check if a node is a TypeScript type expression or a chain expression (i.e. a transparent wrapper around an inner expression). */
95
110
  declare const isTypeOrChainExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ChainExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
96
111
  declare namespace compare_d_exports {
@@ -159,7 +174,7 @@ declare function getReturnStatements(node: TSESTree.Node): readonly TSESTree.Ret
159
174
  */
160
175
  declare function getReturnExpressions(node: TSESTreeFunction): readonly TSESTree.Expression[];
161
176
  declare namespace extract_d_exports {
162
- export { findProperty, getAssignmentTargets, getCalleeName, getFullyQualifiedName, getMemberChain, getPropertyName, unwrap };
177
+ export { findProperty, getAssignmentTargets, getCalleeName, getFullyQualifiedName, getJSXName, getMemberChain, getPropertyName, unwrap };
163
178
  }
164
179
  /**
165
180
  * Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
@@ -169,12 +184,18 @@ declare namespace extract_d_exports {
169
184
  declare function unwrap(node: TSESTreeTypeOrChainExpression): Exclude<TSESTree.Expression, TSESTreeTypeOrChainExpression>;
170
185
  declare function unwrap<T extends TSESTree.Node>(node: T): Exclude<T, TSESTreeTypeOrChainExpression>;
171
186
  /**
172
- * Find a property by name in a list of object literal properties, recursing into spread object expressions.
173
- * @param properties The object literal properties to search.
174
- * @param name The property name to look for.
175
- * @returns The matching `Property` node, or `null` when not found.
187
+ * Get the flattened name of a JSX identifier, namespaced name, or member expression.
188
+ * @param node The JSX name node.
189
+ * @returns The flattened JSX name (ex: `"Foo.Bar"`, `"xml:space"`).
176
190
  */
177
- declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
191
+ declare function getJSXName(node: TSESTree.JSXIdentifier | TSESTree.JSXNamespacedName | TSESTree.JSXMemberExpression): string;
192
+ /**
193
+ * Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
194
+ * @param node The node to inspect.
195
+ * @param getText A function returning the source text of a node.
196
+ * @returns The fully qualified name.
197
+ */
198
+ declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
178
199
  /**
179
200
  * Get the name of the callee of a call expression.
180
201
  * @param node The call expression to inspect.
@@ -188,15 +209,6 @@ declare function getCalleeName(node: TSESTree.CallExpression): string | null;
188
209
  * @returns The base node followed by each member property in access order.
189
210
  */
190
211
  declare function getMemberChain(node: TSESTree.Expression | TSESTree.PrivateIdentifier): (TSESTree.AccessorProperty | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AssignmentPattern | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.BlockStatement | TSESTree.BreakStatement | TSESTree.CallExpression | TSESTree.CatchClause | TSESTree.ClassBody | TSESTree.ClassDeclaration | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.ContinueStatement | TSESTree.DebuggerStatement | TSESTree.Decorator | TSESTree.DoWhileStatement | TSESTree.EmptyStatement | TSESTree.ExportAllDeclaration | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ExportSpecifier | TSESTree.ExpressionStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.IfStatement | TSESTree.ImportAttribute | TSESTree.ImportDeclaration | TSESTree.ImportDefaultSpecifier | TSESTree.ImportExpression | TSESTree.ImportNamespaceSpecifier | TSESTree.ImportSpecifier | 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 | TSESTree.LabeledStatement | TSESTree.Literal | TSESTree.LogicalExpression | TSESTree.MemberExpression | TSESTree.MetaProperty | TSESTree.MethodDefinition | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.Program | TSESTree.Property | TSESTree.PropertyDefinition | TSESTree.RestElement | TSESTree.ReturnStatement | TSESTree.SequenceExpression | TSESTree.SpreadElement | TSESTree.StaticBlock | TSESTree.Super | TSESTree.SwitchCase | TSESTree.SwitchStatement | TSESTree.TaggedTemplateExpression | TSESTree.TemplateElement | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.ThrowStatement | TSESTree.TryStatement | TSESTree.TSAbstractAccessorProperty | TSESTree.TSAbstractKeyword | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.TSAnyKeyword | TSESTree.TSArrayType | TSESTree.TSAsyncKeyword | TSESTree.TSBigIntKeyword | TSESTree.TSBooleanKeyword | TSESTree.TSCallSignatureDeclaration | TSESTree.TSClassImplements | TSESTree.TSConditionalType | TSESTree.TSConstructorType | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunction | TSESTree.TSDeclareKeyword | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSEnumBody | TSESTree.TSEnumDeclaration | TSESTree.TSEnumMember | TSESTree.TSExportAssignment | TSESTree.TSExportKeyword | TSESTree.TSExternalModuleReference | TSESTree.TSFunctionType | TSESTree.TSImportEqualsDeclaration | TSESTree.TSImportType | TSESTree.TSIndexedAccessType | TSESTree.TSIndexSignature | TSESTree.TSInferType | TSESTree.TSInterfaceBody | TSESTree.TSInterfaceDeclaration | TSESTree.TSInterfaceHeritage | TSESTree.TSIntersectionType | TSESTree.TSIntrinsicKeyword | TSESTree.TSLiteralType | TSESTree.TSMappedType | TSESTree.TSMethodSignature | TSESTree.TSModuleBlock | TSESTree.TSModuleDeclaration | TSESTree.TSNamedTupleMember | TSESTree.TSNamespaceExportDeclaration | TSESTree.TSNeverKeyword | TSESTree.TSNullKeyword | TSESTree.TSNumberKeyword | TSESTree.TSObjectKeyword | TSESTree.TSOptionalType | TSESTree.TSParameterProperty | TSESTree.TSPrivateKeyword | TSESTree.TSPropertySignature | TSESTree.TSProtectedKeyword | TSESTree.TSPublicKeyword | TSESTree.TSQualifiedName | TSESTree.TSReadonlyKeyword | TSESTree.TSRestType | TSESTree.TSStaticKeyword | TSESTree.TSStringKeyword | TSESTree.TSSymbolKeyword | TSESTree.TSTemplateLiteralType | TSESTree.TSThisType | TSESTree.TSTupleType | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAnnotation | TSESTree.TSTypeLiteral | TSESTree.TSTypeOperator | TSESTree.TSTypeParameter | TSESTree.TSTypeParameterDeclaration | TSESTree.TSTypeParameterInstantiation | TSESTree.TSTypePredicate | TSESTree.TSTypeQuery | TSESTree.TSTypeReference | TSESTree.TSUndefinedKeyword | TSESTree.TSUnionType | TSESTree.TSUnknownKeyword | TSESTree.TSVoidKeyword | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.VariableDeclaration | TSESTree.VariableDeclarator | TSESTree.WhileStatement | TSESTree.WithStatement | TSESTree.YieldExpression)[];
191
- /**
192
- * Collect every write target of an assignment or loop target, expanding
193
- * destructuring patterns such as `[local, globalValue] = source` or
194
- * `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
195
- * their left side is.
196
- * @param node The assignment left side or for-in/of loop target to inspect.
197
- * @returns The identifier and member expression targets being written.
198
- */
199
- declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
200
212
  /**
201
213
  * Get the static name of an object property's key.
202
214
  * @param property The property to inspect.
@@ -205,12 +217,21 @@ declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier
205
217
  */
206
218
  declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
207
219
  /**
208
- * Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
209
- * @param node The node to inspect.
210
- * @param getText A function returning the source text of a node.
211
- * @returns The fully qualified name.
220
+ * Find a property by name in a list of object literal properties, recursing into spread object expressions.
221
+ * @param properties The object literal properties to search.
222
+ * @param name The property name to look for.
223
+ * @returns The matching `Property` node, or `null` when not found.
212
224
  */
213
- declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
225
+ declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
226
+ /**
227
+ * Collect every write target of an assignment or loop target, expanding
228
+ * destructuring patterns such as `[local, globalValue] = source` or
229
+ * `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
230
+ * their left side is.
231
+ * @param node The assignment left side or for-in/of loop target to inspect.
232
+ * @returns The identifier and member expression targets being written.
233
+ */
234
+ declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
214
235
  declare namespace analyze_d_exports {
215
236
  export { isTerminatingStatement, isUnconditionallyTerminating };
216
237
  }
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { visitorKeys } from "@typescript-eslint/visitor-keys";
5
5
  // src/check.ts
6
6
  var check_exports = /* @__PURE__ */ __exportAll({
7
7
  is: () => is,
8
+ isArrayPatternElementDefault: () => isArrayPatternElementDefault,
8
9
  isCallExpression: () => isCallExpression,
9
10
  isClass: () => isClass,
10
11
  isConditional: () => isConditional,
@@ -23,6 +24,7 @@ var check_exports = /* @__PURE__ */ __exportAll({
23
24
  isLoopStatement: () => isLoopStatement,
24
25
  isMemberExpression: () => isMemberExpression,
25
26
  isObjectExpression: () => isObjectExpression,
27
+ isObjectPatternElementDefault: () => isObjectPatternElementDefault,
26
28
  isOneOf: () => isOneOf,
27
29
  isProperty: () => isProperty,
28
30
  isPropertyOrMethod: () => isPropertyOrMethod,
@@ -40,54 +42,65 @@ function isDirective(node, name) {
40
42
  return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
41
43
  }
42
44
  const isCallExpression = is(AST_NODE_TYPES.CallExpression);
43
- const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
44
- const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
45
45
  const isExpression = isOneOf([
46
+ AST_NODE_TYPES.Identifier,
47
+ AST_NODE_TYPES.Literal,
48
+ AST_NODE_TYPES.CallExpression,
49
+ AST_NODE_TYPES.MemberExpression,
50
+ AST_NODE_TYPES.ObjectExpression,
51
+ AST_NODE_TYPES.TemplateLiteral,
46
52
  AST_NODE_TYPES.ArrayExpression,
47
- AST_NODE_TYPES.ArrayPattern,
53
+ AST_NODE_TYPES.TaggedTemplateExpression,
54
+ AST_NODE_TYPES.BinaryExpression,
48
55
  AST_NODE_TYPES.ArrowFunctionExpression,
56
+ AST_NODE_TYPES.LogicalExpression,
57
+ AST_NODE_TYPES.UnaryExpression,
49
58
  AST_NODE_TYPES.AssignmentExpression,
50
- AST_NODE_TYPES.AwaitExpression,
51
- AST_NODE_TYPES.BinaryExpression,
52
- AST_NODE_TYPES.CallExpression,
59
+ AST_NODE_TYPES.FunctionExpression,
53
60
  AST_NODE_TYPES.ChainExpression,
54
- AST_NODE_TYPES.ClassExpression,
61
+ AST_NODE_TYPES.TSNonNullExpression,
62
+ AST_NODE_TYPES.NewExpression,
63
+ AST_NODE_TYPES.ObjectPattern,
64
+ AST_NODE_TYPES.TSAsExpression,
55
65
  AST_NODE_TYPES.ConditionalExpression,
56
- AST_NODE_TYPES.FunctionExpression,
57
- AST_NODE_TYPES.Identifier,
58
- AST_NODE_TYPES.ImportExpression,
66
+ AST_NODE_TYPES.ThisExpression,
67
+ AST_NODE_TYPES.YieldExpression,
68
+ AST_NODE_TYPES.TSSatisfiesExpression,
59
69
  AST_NODE_TYPES.JSXElement,
60
- AST_NODE_TYPES.JSXFragment,
61
- AST_NODE_TYPES.Literal,
62
- AST_NODE_TYPES.LogicalExpression,
63
- AST_NODE_TYPES.MemberExpression,
70
+ AST_NODE_TYPES.ArrayPattern,
71
+ AST_NODE_TYPES.UpdateExpression,
72
+ AST_NODE_TYPES.AwaitExpression,
64
73
  AST_NODE_TYPES.MetaProperty,
65
- AST_NODE_TYPES.NewExpression,
66
- AST_NODE_TYPES.ObjectExpression,
67
- AST_NODE_TYPES.ObjectPattern,
74
+ AST_NODE_TYPES.ImportExpression,
75
+ AST_NODE_TYPES.ClassExpression,
76
+ AST_NODE_TYPES.JSXFragment,
68
77
  AST_NODE_TYPES.SequenceExpression,
69
78
  AST_NODE_TYPES.Super,
70
- AST_NODE_TYPES.TSAsExpression,
71
79
  AST_NODE_TYPES.TSInstantiationExpression,
72
- AST_NODE_TYPES.TSNonNullExpression,
73
- AST_NODE_TYPES.TSSatisfiesExpression,
74
- AST_NODE_TYPES.TSTypeAssertion,
75
- AST_NODE_TYPES.TaggedTemplateExpression,
76
- AST_NODE_TYPES.TemplateLiteral,
77
- AST_NODE_TYPES.ThisExpression,
78
- AST_NODE_TYPES.UnaryExpression,
79
- AST_NODE_TYPES.UpdateExpression,
80
- AST_NODE_TYPES.YieldExpression
80
+ AST_NODE_TYPES.TSTypeAssertion
81
81
  ]);
82
+ const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
83
+ const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
82
84
  const isLoopStatement = isOneOf([
83
- AST_NODE_TYPES.DoWhileStatement,
84
- AST_NODE_TYPES.ForInStatement,
85
85
  AST_NODE_TYPES.ForOfStatement,
86
+ AST_NODE_TYPES.WhileStatement,
86
87
  AST_NODE_TYPES.ForStatement,
87
- AST_NODE_TYPES.WhileStatement
88
+ AST_NODE_TYPES.ForInStatement,
89
+ AST_NODE_TYPES.DoWhileStatement
88
90
  ]);
89
91
  const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
90
92
  const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
93
+ const isConditional = isOneOf([
94
+ AST_NODE_TYPES.IfStatement,
95
+ AST_NODE_TYPES.LogicalExpression,
96
+ AST_NODE_TYPES.ConditionalExpression,
97
+ AST_NODE_TYPES.ForOfStatement,
98
+ AST_NODE_TYPES.SwitchStatement,
99
+ AST_NODE_TYPES.WhileStatement,
100
+ AST_NODE_TYPES.ForStatement,
101
+ AST_NODE_TYPES.ForInStatement,
102
+ AST_NODE_TYPES.DoWhileStatement
103
+ ]);
91
104
  const isFunction$1 = isOneOf([
92
105
  AST_NODE_TYPES.ArrowFunctionExpression,
93
106
  AST_NODE_TYPES.FunctionDeclaration,
@@ -101,70 +114,65 @@ const isFunctionOrClass = isOneOf([
101
114
  AST_NODE_TYPES.ClassExpression
102
115
  ]);
103
116
  const isProperty = isOneOf([
117
+ AST_NODE_TYPES.TSPropertySignature,
104
118
  AST_NODE_TYPES.PropertyDefinition,
105
119
  AST_NODE_TYPES.TSIndexSignature,
106
- AST_NODE_TYPES.TSParameterProperty,
107
- AST_NODE_TYPES.TSPropertySignature
108
- ]);
109
- const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
110
- const isConditional = isOneOf([
111
- AST_NODE_TYPES.DoWhileStatement,
112
- AST_NODE_TYPES.ForInStatement,
113
- AST_NODE_TYPES.ForOfStatement,
114
- AST_NODE_TYPES.ForStatement,
115
- AST_NODE_TYPES.WhileStatement,
116
- AST_NODE_TYPES.IfStatement,
117
- AST_NODE_TYPES.SwitchStatement,
118
- AST_NODE_TYPES.LogicalExpression,
119
- AST_NODE_TYPES.ConditionalExpression
120
+ AST_NODE_TYPES.TSParameterProperty
120
121
  ]);
122
+ const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition]);
123
+ function isArrayPatternElementDefault(node) {
124
+ return node.type === AST_NODE_TYPES.AssignmentPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern;
125
+ }
126
+ function isObjectPatternElementDefault(node) {
127
+ return node.type === AST_NODE_TYPES.AssignmentPattern && node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && node.parent.parent.type === AST_NODE_TYPES.ObjectPattern;
128
+ }
121
129
  const isJSX = isOneOf([
130
+ AST_NODE_TYPES.JSXIdentifier,
131
+ AST_NODE_TYPES.JSXText,
122
132
  AST_NODE_TYPES.JSXAttribute,
133
+ AST_NODE_TYPES.JSXElement,
134
+ AST_NODE_TYPES.JSXOpeningElement,
123
135
  AST_NODE_TYPES.JSXClosingElement,
136
+ AST_NODE_TYPES.JSXExpressionContainer,
137
+ AST_NODE_TYPES.JSXMemberExpression,
138
+ AST_NODE_TYPES.JSXSpreadAttribute,
124
139
  AST_NODE_TYPES.JSXClosingFragment,
125
- AST_NODE_TYPES.JSXElement,
126
140
  AST_NODE_TYPES.JSXEmptyExpression,
127
- AST_NODE_TYPES.JSXExpressionContainer,
128
141
  AST_NODE_TYPES.JSXFragment,
129
- AST_NODE_TYPES.JSXIdentifier,
130
- AST_NODE_TYPES.JSXMemberExpression,
131
142
  AST_NODE_TYPES.JSXNamespacedName,
132
- AST_NODE_TYPES.JSXOpeningElement,
133
143
  AST_NODE_TYPES.JSXOpeningFragment,
134
- AST_NODE_TYPES.JSXSpreadAttribute,
135
- AST_NODE_TYPES.JSXSpreadChild,
136
- AST_NODE_TYPES.JSXText
144
+ AST_NODE_TYPES.JSXSpreadChild
137
145
  ]);
138
146
  const isJSXElement = is(AST_NODE_TYPES.JSXElement);
139
- const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
140
147
  const isJSXElementOrFragment = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
141
148
  const isJSXExpressionContainer = is(AST_NODE_TYPES.JSXExpressionContainer);
149
+ const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
142
150
  const isJSXSpreadAttribute = is(AST_NODE_TYPES.JSXSpreadAttribute);
143
151
  const isJSXTagNameExpression = isOneOf([
144
152
  AST_NODE_TYPES.JSXIdentifier,
145
153
  AST_NODE_TYPES.JSXMemberExpression,
146
154
  AST_NODE_TYPES.JSXNamespacedName
147
155
  ]);
148
- const isTypeExpression = isOneOf([
149
- AST_NODE_TYPES.TSAsExpression,
150
- AST_NODE_TYPES.TSTypeAssertion,
156
+ const isTypeAssertionExpression = isOneOf([
151
157
  AST_NODE_TYPES.TSNonNullExpression,
158
+ AST_NODE_TYPES.TSAsExpression,
152
159
  AST_NODE_TYPES.TSSatisfiesExpression,
153
- AST_NODE_TYPES.TSInstantiationExpression
160
+ AST_NODE_TYPES.TSTypeAssertion
154
161
  ]);
155
- const isTypeAssertionExpression = isOneOf([
156
- AST_NODE_TYPES.TSAsExpression,
157
- AST_NODE_TYPES.TSTypeAssertion,
162
+ const isTypeExpression = isOneOf([
158
163
  AST_NODE_TYPES.TSNonNullExpression,
159
- AST_NODE_TYPES.TSSatisfiesExpression
164
+ AST_NODE_TYPES.TSAsExpression,
165
+ AST_NODE_TYPES.TSSatisfiesExpression,
166
+ AST_NODE_TYPES.TSInstantiationExpression,
167
+ AST_NODE_TYPES.TSTypeAssertion
160
168
  ]);
161
169
  const isTypeOrChainExpression = isOneOf([
162
- AST_NODE_TYPES.TSAsExpression,
163
- AST_NODE_TYPES.TSTypeAssertion,
170
+ AST_NODE_TYPES.ChainExpression,
164
171
  AST_NODE_TYPES.TSNonNullExpression,
172
+ AST_NODE_TYPES.TSAsExpression,
165
173
  AST_NODE_TYPES.TSSatisfiesExpression,
166
174
  AST_NODE_TYPES.TSInstantiationExpression,
167
- AST_NODE_TYPES.ChainExpression
175
+ AST_NODE_TYPES.TSTypeAssertion
168
176
  ]);
169
177
  // ../../.pkgs/eff/dist/index.js
170
178
  const pipeArguments = (self, args) => {
@@ -266,6 +274,7 @@ var extract_exports = /* @__PURE__ */ __exportAll({
266
274
  getAssignmentTargets: () => getAssignmentTargets,
267
275
  getCalleeName: () => getCalleeName,
268
276
  getFullyQualifiedName: () => getFullyQualifiedName,
277
+ getJSXName: () => getJSXName,
269
278
  getMemberChain: () => getMemberChain,
270
279
  getPropertyName: () => getPropertyName,
271
280
  unwrap: () => unwrap
@@ -274,15 +283,28 @@ function unwrap(node) {
274
283
  if (isTypeOrChainExpression(node)) return unwrap(node.expression);
275
284
  return node;
276
285
  }
277
- function findProperty(properties, name) {
278
- for (const property of properties) {
279
- if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
280
- if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
281
- const found = findProperty(property.argument.properties, name);
282
- if (found != null) return found;
283
- }
286
+ function getJSXName(node) {
287
+ switch (node.type) {
288
+ case AST_NODE_TYPES.JSXIdentifier: return node.name;
289
+ case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
290
+ case AST_NODE_TYPES.JSXMemberExpression: return `${getJSXName(node.object)}.${getJSXName(node.property)}`;
291
+ }
292
+ }
293
+ function getFullyQualifiedName(node, getText) {
294
+ const expr = unwrap(node);
295
+ switch (expr.type) {
296
+ case AST_NODE_TYPES.Identifier:
297
+ case AST_NODE_TYPES.PrivateIdentifier: return expr.name;
298
+ case AST_NODE_TYPES.JSXIdentifier:
299
+ case AST_NODE_TYPES.JSXMemberExpression:
300
+ case AST_NODE_TYPES.JSXNamespacedName: return getJSXName(expr);
301
+ case AST_NODE_TYPES.MemberExpression:
302
+ if (expr.computed) return getText(expr);
303
+ return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
304
+ case AST_NODE_TYPES.JSXText: return expr.value;
305
+ case AST_NODE_TYPES.Literal: return expr.raw;
306
+ default: return getText(expr);
284
307
  }
285
- return null;
286
308
  }
287
309
  function getCalleeName(node) {
288
310
  const callee = unwrap(node.callee);
@@ -301,6 +323,24 @@ function getMemberChain(node) {
301
323
  members.unshift(current);
302
324
  return members;
303
325
  }
326
+ function getPropertyName(property, effort = "min") {
327
+ const key = unwrap(property.key);
328
+ if (isIdentifier(key) && !property.computed) return key.name;
329
+ if (effort === "min") return null;
330
+ if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
331
+ if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
332
+ return null;
333
+ }
334
+ function findProperty(properties, name) {
335
+ for (const property of properties) {
336
+ if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
337
+ if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
338
+ const found = findProperty(property.argument.properties, name);
339
+ if (found != null) return found;
340
+ }
341
+ }
342
+ return null;
343
+ }
304
344
  function getAssignmentTargets(node) {
305
345
  const target = unwrap(node);
306
346
  switch (target.type) {
@@ -316,30 +356,6 @@ function getAssignmentTargets(node) {
316
356
  default: return [];
317
357
  }
318
358
  }
319
- function getPropertyName(property, effort = "min") {
320
- const key = unwrap(property.key);
321
- if (isIdentifier(key) && !property.computed) return key.name;
322
- if (effort === "min") return null;
323
- if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
324
- if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
325
- return null;
326
- }
327
- function getFullyQualifiedName(node, getText) {
328
- const expr = unwrap(node);
329
- switch (expr.type) {
330
- case AST_NODE_TYPES.Identifier:
331
- case AST_NODE_TYPES.JSXIdentifier:
332
- case AST_NODE_TYPES.PrivateIdentifier: return expr.name;
333
- case AST_NODE_TYPES.MemberExpression:
334
- if (expr.computed) return getText(expr);
335
- return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
336
- case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
337
- case AST_NODE_TYPES.JSXNamespacedName: return `${expr.namespace.name}:${expr.name.name}`;
338
- case AST_NODE_TYPES.JSXText: return expr.value;
339
- case AST_NODE_TYPES.Literal: return expr.raw;
340
- default: return getText(expr);
341
- }
342
- }
343
359
  // src/compare.ts
344
360
  var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
345
361
  const isEqual = dual(2, (a, b) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.30.0-beta.4",
3
+ "version": "5.30.0-beta.6",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -29,9 +29,9 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@typescript-eslint/types": "^8.72.0",
33
- "@typescript-eslint/utils": "^8.72.0",
34
- "@typescript-eslint/visitor-keys": "^8.72.0"
32
+ "@typescript-eslint/types": "^8.72.1",
33
+ "@typescript-eslint/utils": "^8.72.1",
34
+ "@typescript-eslint/visitor-keys": "^8.72.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@local/configs": "0.0.0",