@eslint-react/ast 5.30.0-beta.1 → 5.30.0-beta.11

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +166 -40
  2. package/dist/index.js +292 -99
  3. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -1,29 +1,30 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
- /** Union of function-like node types. */
3
- type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
4
- /** Union of class-like node types. */
5
- type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
6
- /** Union of function-like and class-like node types. */
7
- type TSESTreeFunctionOrClass = TSESTreeFunction | TSESTreeClass;
8
- /** Union of method and property definition node types. */
9
- type TSESTreeMethodOrPropertyDefinition = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
2
+ import { VisitorKeys } from "@typescript-eslint/visitor-keys";
10
3
  /** An expression statement that is a directive (ex: `"use strict"`). */
11
4
  type TSESTreeDirective = TSESTree.ExpressionStatement & {
12
5
  directive: string;
13
6
  expression: TSESTree.StringLiteral;
14
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;
15
16
  /** Union of all JSX-related node types. */
16
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;
17
- /** Union of JSX element-like node types (element or fragment). */
18
- type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
19
18
  /** Union of JSX attribute-like node types (attribute or spread attribute). */
20
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;
21
22
  /** Union of TypeScript type expression node types. */
22
- 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;
23
24
  /** Union of expression node types that wrap another expression (TypeScript type expressions and chain expressions) — the nodes `Extract.unwrap` strips. */
24
- type TSESTreeTypeOrChainExpression = TSESTreeTypeExpression | TSESTree.ChainExpression;
25
+ type TSESTreeTypeOrChainExpression = TSESTree.ChainExpression | TSESTreeTypeExpression;
25
26
  declare namespace check_d_exports {
26
- 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 };
27
28
  }
28
29
  /** Check if a node is of the given type. */
29
30
  declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
@@ -50,18 +51,20 @@ declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSEST
50
51
  declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
51
52
  /** Check if a node is a call expression. */
52
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;
53
56
  /** Check if a node is a member expression. */
54
57
  declare const isMemberExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName;
55
58
  /** Check if a node is an object expression. */
56
59
  declare const isObjectExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ObjectExpression;
57
- /** Check if a node is an expression node. */
58
- 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;
59
60
  /** Check if a node is a loop statement. */
60
61
  declare const isLoopStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
61
62
  /** Check if a node is a return statement. */
62
63
  declare const isReturnStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.ReturnStatement;
63
64
  /** Check if a node is a class declaration or class expression. */
64
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;
65
68
  /** Check if a node is a function declaration, function expression, or arrow function expression. */
66
69
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
67
70
  /** Check if a node is a function declaration, function expression, arrow function expression, class declaration, or class expression. */
@@ -70,26 +73,39 @@ declare const isFunctionOrClass: (node: TSESTree.Node | null | undefined) => nod
70
73
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
71
74
  /** Check if a node is a property or method definition. */
72
75
  declare const isPropertyOrMethod: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
73
- /** Check if a node is a conditional or logical expression, or a control flow statement. */
74
- 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;
75
91
  /** Check if a node is any JSX-related node. */
76
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;
77
93
  /** Check if a node is a JSX element. */
78
94
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
79
- /** Check if a node is a JSX fragment. */
80
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
81
95
  /** Check if a node is a JSX element or JSX fragment. */
82
96
  declare const isJSXElementOrFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
83
97
  /** Check if a node is a JSX expression container. */
84
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;
85
101
  /** Check if a node is a JSX spread attribute. */
86
102
  declare const isJSXSpreadAttribute: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXSpreadAttribute;
87
103
  /** Check if a node can appear as a JSX tag name. */
88
104
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
89
- /** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
90
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
91
105
  /** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
92
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;
93
109
  /** Check if a node is a TypeScript type expression or a chain expression (i.e. a transparent wrapper around an inner expression). */
94
110
  declare const isTypeOrChainExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ChainExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
95
111
  declare namespace compare_d_exports {
@@ -106,8 +122,59 @@ declare const isEqual: {
106
122
  (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
107
123
  (a: TSESTree.Node, b: TSESTree.Node): boolean;
108
124
  };
125
+ declare namespace collect_d_exports {
126
+ export { getCallExpressions, getIdentifiers, getNewExpressions, getReturnExpressions, getReturnStatements };
127
+ }
128
+ /**
129
+ * Get all identifiers referenced within an expression-like node, in source order.
130
+ *
131
+ * The property name of a non-computed member access is not a reference, so `obj.prop` collects
132
+ * only `obj`. Non-computed object property keys are not visited either. Nested function and class
133
+ * bodies are ignored, and statement roots contribute only their expression-bearing parts.
134
+ * @param node The expression-like node to collect identifiers from.
135
+ * @returns All identifiers referenced by the node.
136
+ */
137
+ declare function getIdentifiers(node: TSESTree.Node): readonly TSESTree.Identifier[];
138
+ /**
139
+ * Get all nested `new` expressions within an expression-like node, in source order.
140
+ *
141
+ * Function and class bodies are not traversed; statement roots contribute only their
142
+ * expression-bearing parts.
143
+ * @param node The expression-like node to collect `new` expressions from.
144
+ * @returns All nested `new` expressions.
145
+ */
146
+ declare const getNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
147
+ /**
148
+ * Get all nested call expressions within an expression-like node, in source order.
149
+ *
150
+ * Function and class bodies are not traversed; statement roots contribute only their
151
+ * expression-bearing parts.
152
+ * @param node The expression-like node to collect call expressions from.
153
+ * @returns All nested call expressions.
154
+ */
155
+ declare const getCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
156
+ /**
157
+ * Get all return statements in the subtree of `node` that belong to its function.
158
+ *
159
+ * Return statements nested inside another function are excluded. When `node` is a function, its
160
+ * own returns are collected; otherwise returns in its subtree are collected as long as they are
161
+ * not nested inside a function. The search never expands beyond the subtree of `node`.
162
+ * @param node The node whose subtree is searched.
163
+ * @returns The return statements in the subtree, in source order.
164
+ */
165
+ declare function getReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
166
+ /**
167
+ * Get all expressions returned by a function, in source order.
168
+ *
169
+ * The implicit return value of an expression-bodied arrow function (ex: `() => value`) is
170
+ * included, while bare `return;` statements without an argument are skipped. Return statements
171
+ * inside nested functions are excluded.
172
+ * @param node The function to collect return expressions from.
173
+ * @returns All expressions returned by the function.
174
+ */
175
+ declare function getReturnExpressions(node: TSESTreeFunction): readonly TSESTree.Expression[];
109
176
  declare namespace extract_d_exports {
110
- export { findProperty, getAssignmentTargets, getCalleeName, getFullyQualifiedName, getMemberChain, getPropertyName, unwrap };
177
+ export { findProperty, getAssignmentTargets, getCalleeName, getFullyQualifiedName, getJSXName, getMemberChain, getPropertyName, unwrap };
111
178
  }
112
179
  /**
113
180
  * Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
@@ -117,12 +184,18 @@ declare namespace extract_d_exports {
117
184
  declare function unwrap(node: TSESTreeTypeOrChainExpression): Exclude<TSESTree.Expression, TSESTreeTypeOrChainExpression>;
118
185
  declare function unwrap<T extends TSESTree.Node>(node: T): Exclude<T, TSESTreeTypeOrChainExpression>;
119
186
  /**
120
- * Find a property by name in a list of object literal properties, recursing into spread object expressions.
121
- * @param properties The object literal properties to search.
122
- * @param name The property name to look for.
123
- * @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"`).
124
190
  */
125
- 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;
126
199
  /**
127
200
  * Get the name of the callee of a call expression.
128
201
  * @param node The call expression to inspect.
@@ -136,6 +209,20 @@ declare function getCalleeName(node: TSESTree.CallExpression): string | null;
136
209
  * @returns The base node followed by each member property in access order.
137
210
  */
138
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)[];
212
+ /**
213
+ * Get the static name of an object property's key.
214
+ * @param property The property to inspect.
215
+ * @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
216
+ * @returns The property name, or `null` when it cannot be statically determined.
217
+ */
218
+ declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
219
+ /**
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.
224
+ */
225
+ declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
139
226
  /**
140
227
  * Collect every write target of an assignment or loop target, expanding
141
228
  * destructuring patterns such as `[local, globalValue] = source` or
@@ -145,27 +232,63 @@ declare function getMemberChain(node: TSESTree.Expression | TSESTree.PrivateIden
145
232
  * @returns The identifier and member expression targets being written.
146
233
  */
147
234
  declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
235
+ declare namespace analyze_d_exports {
236
+ export { isTerminatingStatement, isUnconditionallyTerminating };
237
+ }
148
238
  /**
149
- * Get the static name of an object property's key.
150
- * @param property The property to inspect.
151
- * @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
152
- * @returns The property name, or `null` when it cannot be statically determined.
239
+ * Check if a statement terminates the control flow of its block.
240
+ *
241
+ * A statement terminates when it cannot complete normally: a `return`, `throw`,
242
+ * `break`, or `continue`, a block containing such a statement, an `if` whose
243
+ * branches both terminate, or a `try` whose paths all terminate. `switch`
244
+ * statements are not analyzed, so a `switch` whose entry paths all terminate is
245
+ * not treated as terminating.
246
+ * @param node The node to check.
247
+ * @returns `true` if the statement terminates the control flow.
153
248
  */
154
- declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
249
+ declare function isTerminatingStatement(node: TSESTree.Node): boolean;
155
250
  /**
156
- * Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
157
- * @param node The node to inspect.
158
- * @param getText A function returning the source text of a node.
159
- * @returns The fully qualified name.
251
+ * Check if every path through a statement exits the current function with a
252
+ * `return` or `throw`. Unlike {@link isTerminatingStatement}, `break` and
253
+ * `continue` are not considered terminating.
254
+ * @param node The node to check.
255
+ * @returns `true` if the statement unconditionally terminates.
160
256
  */
161
- declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
257
+ declare function isUnconditionallyTerminating(node: TSESTree.Node): boolean;
162
258
  declare namespace traverse_d_exports {
163
- export { findEnclosingTryBlock, findParent, hasEnclosingTryBlock, hasParent };
259
+ export { SimpleTraverseOptions, findEnclosingTryBlock, findParent, hasEnclosingTryBlock, hasParent, simpleTraverse };
164
260
  }
165
- type Predicate<T extends TSESTree.Node> = (node: TSESTree.Node) => node is T;
166
261
  type NodePredicate = (node: TSESTree.Node) => boolean;
262
+ type Predicate<T extends TSESTree.Node> = (node: TSESTree.Node) => node is T;
263
+ /** Options for `simpleTraverse`. */
264
+ type SimpleTraverseOptions = {
265
+ /** Called for each visited node before its children are visited. */
266
+ enter?: (node: TSESTree.Node, parent: TSESTree.Node | undefined) => void;
267
+ /** Called for each visited node after its children are visited. */
268
+ leave?: (node: TSESTree.Node, parent: TSESTree.Node | undefined) => void;
269
+ /** Attach parent pointers to every visited node. */
270
+ setParentPointers?: boolean;
271
+ /** Visitor keys to use instead of the default ESTree keys (ex: to prune subtrees). */
272
+ visitorKeys?: VisitorKeys;
273
+ };
274
+ /**
275
+ * Walk the AST from `root`, calling `enter` before and `leave` after a node's children.
276
+ *
277
+ * This is a lightweight local equivalent of `simpleTraverse` from
278
+ * `@typescript-eslint/typescript-estree`: it only depends on the visitor keys, so importing it does
279
+ * not load the TypeScript compiler. Parent pointers are not attached unless `setParentPointers` is
280
+ * enabled; the parent of each node is passed to `enter` and `leave` instead. Node types missing
281
+ * from the visitor keys are not descended into, which allows pruning subtrees (ex: function or
282
+ * class bodies) with a custom map.
283
+ * @param root The root node to traverse.
284
+ * @param options Traversal options.
285
+ */
286
+ declare function simpleTraverse(root: TSESTree.Node, options?: SimpleTraverseOptions): void;
167
287
  /**
168
288
  * Walk up the AST from `node` to find the nearest ancestor matching a predicate.
289
+ *
290
+ * This function relies on the `parent` pointers attached by the parser or by
291
+ * `simpleTraverse` with `setParentPointers` enabled.
169
292
  * @param node The starting node for the upward search.
170
293
  * @param test The predicate a candidate ancestor must satisfy.
171
294
  * @param stop An optional predicate that aborts the search when it returns `true`.
@@ -184,6 +307,9 @@ declare function hasParent<T extends TSESTree.Node>(node: TSESTree.Node | null,
184
307
  declare function hasParent(node: TSESTree.Node | null, test: NodePredicate, stop?: NodePredicate): boolean;
185
308
  /**
186
309
  * Find the nearest `TryStatement` whose `try` block (not `catch`/`finally`) encloses the given node.
310
+ *
311
+ * This function relies on the `parent` pointers attached by the parser or by
312
+ * `simpleTraverse` with `setParentPointers` enabled.
187
313
  * @param node The node to check.
188
314
  * @returns The enclosing `TryStatement`, or `null` when none is found.
189
315
  */
@@ -194,4 +320,4 @@ declare function findEnclosingTryBlock(node: TSESTree.Node): TSESTree.TryStateme
194
320
  * @returns `true` when an enclosing `try` block exists.
195
321
  */
196
322
  declare function hasEnclosingTryBlock(node: TSESTree.Node): boolean;
197
- export { check_d_exports as Check, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
323
+ export { analyze_d_exports as Analyze, check_d_exports as Check, collect_d_exports as Collect, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
2
2
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
3
3
  import * as ASTUtils from "@typescript-eslint/utils/ast-utils";
4
+ import { visitorKeys } from "@typescript-eslint/visitor-keys";
4
5
  // src/check.ts
5
6
  var check_exports = /* @__PURE__ */ __exportAll({
6
7
  is: () => is,
8
+ isArrayPatternElementDefault: () => isArrayPatternElementDefault,
7
9
  isCallExpression: () => isCallExpression,
8
10
  isClass: () => isClass,
9
11
  isConditional: () => isConditional,
@@ -22,6 +24,7 @@ var check_exports = /* @__PURE__ */ __exportAll({
22
24
  isLoopStatement: () => isLoopStatement,
23
25
  isMemberExpression: () => isMemberExpression,
24
26
  isObjectExpression: () => isObjectExpression,
27
+ isObjectPatternElementDefault: () => isObjectPatternElementDefault,
25
28
  isOneOf: () => isOneOf,
26
29
  isProperty: () => isProperty,
27
30
  isPropertyOrMethod: () => isPropertyOrMethod,
@@ -39,54 +42,65 @@ function isDirective(node, name) {
39
42
  return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
40
43
  }
41
44
  const isCallExpression = is(AST_NODE_TYPES.CallExpression);
42
- const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
43
- const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
44
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,
45
52
  AST_NODE_TYPES.ArrayExpression,
46
- AST_NODE_TYPES.ArrayPattern,
53
+ AST_NODE_TYPES.TaggedTemplateExpression,
54
+ AST_NODE_TYPES.BinaryExpression,
47
55
  AST_NODE_TYPES.ArrowFunctionExpression,
56
+ AST_NODE_TYPES.LogicalExpression,
57
+ AST_NODE_TYPES.UnaryExpression,
48
58
  AST_NODE_TYPES.AssignmentExpression,
49
- AST_NODE_TYPES.AwaitExpression,
50
- AST_NODE_TYPES.BinaryExpression,
51
- AST_NODE_TYPES.CallExpression,
59
+ AST_NODE_TYPES.FunctionExpression,
52
60
  AST_NODE_TYPES.ChainExpression,
53
- AST_NODE_TYPES.ClassExpression,
61
+ AST_NODE_TYPES.TSNonNullExpression,
62
+ AST_NODE_TYPES.NewExpression,
63
+ AST_NODE_TYPES.ObjectPattern,
64
+ AST_NODE_TYPES.TSAsExpression,
54
65
  AST_NODE_TYPES.ConditionalExpression,
55
- AST_NODE_TYPES.FunctionExpression,
56
- AST_NODE_TYPES.Identifier,
57
- AST_NODE_TYPES.ImportExpression,
66
+ AST_NODE_TYPES.ThisExpression,
67
+ AST_NODE_TYPES.YieldExpression,
68
+ AST_NODE_TYPES.TSSatisfiesExpression,
58
69
  AST_NODE_TYPES.JSXElement,
59
- AST_NODE_TYPES.JSXFragment,
60
- AST_NODE_TYPES.Literal,
61
- AST_NODE_TYPES.LogicalExpression,
62
- AST_NODE_TYPES.MemberExpression,
70
+ AST_NODE_TYPES.ArrayPattern,
71
+ AST_NODE_TYPES.UpdateExpression,
72
+ AST_NODE_TYPES.AwaitExpression,
63
73
  AST_NODE_TYPES.MetaProperty,
64
- AST_NODE_TYPES.NewExpression,
65
- AST_NODE_TYPES.ObjectExpression,
66
- AST_NODE_TYPES.ObjectPattern,
74
+ AST_NODE_TYPES.ImportExpression,
75
+ AST_NODE_TYPES.ClassExpression,
76
+ AST_NODE_TYPES.JSXFragment,
67
77
  AST_NODE_TYPES.SequenceExpression,
68
78
  AST_NODE_TYPES.Super,
69
- AST_NODE_TYPES.TSAsExpression,
70
79
  AST_NODE_TYPES.TSInstantiationExpression,
71
- AST_NODE_TYPES.TSNonNullExpression,
72
- AST_NODE_TYPES.TSSatisfiesExpression,
73
- AST_NODE_TYPES.TSTypeAssertion,
74
- AST_NODE_TYPES.TaggedTemplateExpression,
75
- AST_NODE_TYPES.TemplateLiteral,
76
- AST_NODE_TYPES.ThisExpression,
77
- AST_NODE_TYPES.UnaryExpression,
78
- AST_NODE_TYPES.UpdateExpression,
79
- AST_NODE_TYPES.YieldExpression
80
+ AST_NODE_TYPES.TSTypeAssertion
80
81
  ]);
82
+ const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
83
+ const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
81
84
  const isLoopStatement = isOneOf([
82
- AST_NODE_TYPES.DoWhileStatement,
83
- AST_NODE_TYPES.ForInStatement,
84
85
  AST_NODE_TYPES.ForOfStatement,
86
+ AST_NODE_TYPES.WhileStatement,
85
87
  AST_NODE_TYPES.ForStatement,
86
- AST_NODE_TYPES.WhileStatement
88
+ AST_NODE_TYPES.ForInStatement,
89
+ AST_NODE_TYPES.DoWhileStatement
87
90
  ]);
88
91
  const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
89
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
+ ]);
90
104
  const isFunction$1 = isOneOf([
91
105
  AST_NODE_TYPES.ArrowFunctionExpression,
92
106
  AST_NODE_TYPES.FunctionDeclaration,
@@ -100,70 +114,65 @@ const isFunctionOrClass = isOneOf([
100
114
  AST_NODE_TYPES.ClassExpression
101
115
  ]);
102
116
  const isProperty = isOneOf([
117
+ AST_NODE_TYPES.TSPropertySignature,
103
118
  AST_NODE_TYPES.PropertyDefinition,
104
119
  AST_NODE_TYPES.TSIndexSignature,
105
- AST_NODE_TYPES.TSParameterProperty,
106
- AST_NODE_TYPES.TSPropertySignature
107
- ]);
108
- const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
109
- const isConditional = isOneOf([
110
- AST_NODE_TYPES.DoWhileStatement,
111
- AST_NODE_TYPES.ForInStatement,
112
- AST_NODE_TYPES.ForOfStatement,
113
- AST_NODE_TYPES.ForStatement,
114
- AST_NODE_TYPES.WhileStatement,
115
- AST_NODE_TYPES.IfStatement,
116
- AST_NODE_TYPES.SwitchStatement,
117
- AST_NODE_TYPES.LogicalExpression,
118
- AST_NODE_TYPES.ConditionalExpression
120
+ AST_NODE_TYPES.TSParameterProperty
119
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
+ }
120
129
  const isJSX = isOneOf([
130
+ AST_NODE_TYPES.JSXIdentifier,
131
+ AST_NODE_TYPES.JSXText,
121
132
  AST_NODE_TYPES.JSXAttribute,
133
+ AST_NODE_TYPES.JSXElement,
134
+ AST_NODE_TYPES.JSXOpeningElement,
122
135
  AST_NODE_TYPES.JSXClosingElement,
136
+ AST_NODE_TYPES.JSXExpressionContainer,
137
+ AST_NODE_TYPES.JSXMemberExpression,
138
+ AST_NODE_TYPES.JSXSpreadAttribute,
123
139
  AST_NODE_TYPES.JSXClosingFragment,
124
- AST_NODE_TYPES.JSXElement,
125
140
  AST_NODE_TYPES.JSXEmptyExpression,
126
- AST_NODE_TYPES.JSXExpressionContainer,
127
141
  AST_NODE_TYPES.JSXFragment,
128
- AST_NODE_TYPES.JSXIdentifier,
129
- AST_NODE_TYPES.JSXMemberExpression,
130
142
  AST_NODE_TYPES.JSXNamespacedName,
131
- AST_NODE_TYPES.JSXOpeningElement,
132
143
  AST_NODE_TYPES.JSXOpeningFragment,
133
- AST_NODE_TYPES.JSXSpreadAttribute,
134
- AST_NODE_TYPES.JSXSpreadChild,
135
- AST_NODE_TYPES.JSXText
144
+ AST_NODE_TYPES.JSXSpreadChild
136
145
  ]);
137
146
  const isJSXElement = is(AST_NODE_TYPES.JSXElement);
138
- const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
139
147
  const isJSXElementOrFragment = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
140
148
  const isJSXExpressionContainer = is(AST_NODE_TYPES.JSXExpressionContainer);
149
+ const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
141
150
  const isJSXSpreadAttribute = is(AST_NODE_TYPES.JSXSpreadAttribute);
142
151
  const isJSXTagNameExpression = isOneOf([
143
152
  AST_NODE_TYPES.JSXIdentifier,
144
153
  AST_NODE_TYPES.JSXMemberExpression,
145
154
  AST_NODE_TYPES.JSXNamespacedName
146
155
  ]);
147
- const isTypeExpression = isOneOf([
148
- AST_NODE_TYPES.TSAsExpression,
149
- AST_NODE_TYPES.TSTypeAssertion,
156
+ const isTypeAssertionExpression = isOneOf([
150
157
  AST_NODE_TYPES.TSNonNullExpression,
158
+ AST_NODE_TYPES.TSAsExpression,
151
159
  AST_NODE_TYPES.TSSatisfiesExpression,
152
- AST_NODE_TYPES.TSInstantiationExpression
160
+ AST_NODE_TYPES.TSTypeAssertion
153
161
  ]);
154
- const isTypeAssertionExpression = isOneOf([
155
- AST_NODE_TYPES.TSAsExpression,
156
- AST_NODE_TYPES.TSTypeAssertion,
162
+ const isTypeExpression = isOneOf([
157
163
  AST_NODE_TYPES.TSNonNullExpression,
158
- AST_NODE_TYPES.TSSatisfiesExpression
164
+ AST_NODE_TYPES.TSAsExpression,
165
+ AST_NODE_TYPES.TSSatisfiesExpression,
166
+ AST_NODE_TYPES.TSInstantiationExpression,
167
+ AST_NODE_TYPES.TSTypeAssertion
159
168
  ]);
160
169
  const isTypeOrChainExpression = isOneOf([
161
- AST_NODE_TYPES.TSAsExpression,
162
- AST_NODE_TYPES.TSTypeAssertion,
170
+ AST_NODE_TYPES.ChainExpression,
163
171
  AST_NODE_TYPES.TSNonNullExpression,
172
+ AST_NODE_TYPES.TSAsExpression,
164
173
  AST_NODE_TYPES.TSSatisfiesExpression,
165
174
  AST_NODE_TYPES.TSInstantiationExpression,
166
- AST_NODE_TYPES.ChainExpression
175
+ AST_NODE_TYPES.TSTypeAssertion
167
176
  ]);
168
177
  // ../../.pkgs/eff/dist/index.js
169
178
  const pipeArguments = (self, args) => {
@@ -265,6 +274,7 @@ var extract_exports = /* @__PURE__ */ __exportAll({
265
274
  getAssignmentTargets: () => getAssignmentTargets,
266
275
  getCalleeName: () => getCalleeName,
267
276
  getFullyQualifiedName: () => getFullyQualifiedName,
277
+ getJSXName: () => getJSXName,
268
278
  getMemberChain: () => getMemberChain,
269
279
  getPropertyName: () => getPropertyName,
270
280
  unwrap: () => unwrap
@@ -273,15 +283,28 @@ function unwrap(node) {
273
283
  if (isTypeOrChainExpression(node)) return unwrap(node.expression);
274
284
  return node;
275
285
  }
276
- function findProperty(properties, name) {
277
- for (const property of properties) {
278
- if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
279
- if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
280
- const found = findProperty(property.argument.properties, name);
281
- if (found != null) return found;
282
- }
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);
283
307
  }
284
- return null;
285
308
  }
286
309
  function getCalleeName(node) {
287
310
  const callee = unwrap(node.callee);
@@ -300,6 +323,24 @@ function getMemberChain(node) {
300
323
  members.unshift(current);
301
324
  return members;
302
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
+ }
303
344
  function getAssignmentTargets(node) {
304
345
  const target = unwrap(node);
305
346
  switch (target.type) {
@@ -315,30 +356,6 @@ function getAssignmentTargets(node) {
315
356
  default: return [];
316
357
  }
317
358
  }
318
- function getPropertyName(property, effort = "min") {
319
- const key = unwrap(property.key);
320
- if (isIdentifier(key) && !property.computed) return key.name;
321
- if (effort === "min") return null;
322
- if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
323
- if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
324
- return null;
325
- }
326
- function getFullyQualifiedName(node, getText) {
327
- const expr = unwrap(node);
328
- switch (expr.type) {
329
- case AST_NODE_TYPES.Identifier:
330
- case AST_NODE_TYPES.JSXIdentifier:
331
- case AST_NODE_TYPES.PrivateIdentifier: return expr.name;
332
- case AST_NODE_TYPES.MemberExpression:
333
- if (expr.computed) return getText(expr);
334
- return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
335
- case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
336
- case AST_NODE_TYPES.JSXNamespacedName: return `${expr.namespace.name}:${expr.name.name}`;
337
- case AST_NODE_TYPES.JSXText: return expr.value;
338
- case AST_NODE_TYPES.Literal: return expr.raw;
339
- default: return getText(expr);
340
- }
341
- }
342
359
  // src/compare.ts
343
360
  var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
344
361
  const isEqual = dual(2, (a, b) => {
@@ -364,7 +381,7 @@ const isEqual = dual(2, (a, b) => {
364
381
  }
365
382
  case isIdentifier(a) && isIdentifier(b): return a.name === b.name;
366
383
  case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
367
- case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isEqual(a.property, b.property) && isEqual(a.object, b.object);
384
+ case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return a.computed === b.computed && a.optional === b.optional && isEqual(a.property, b.property) && isEqual(a.object, b.object);
368
385
  case a.type === AST_NODE_TYPES.CallExpression && b.type === AST_NODE_TYPES.CallExpression: {
369
386
  if (a.optional !== b.optional) return false;
370
387
  if (a.arguments.length !== b.arguments.length) return false;
@@ -394,8 +411,30 @@ var traverse_exports = /* @__PURE__ */ __exportAll({
394
411
  findEnclosingTryBlock: () => findEnclosingTryBlock,
395
412
  findParent: () => findParent,
396
413
  hasEnclosingTryBlock: () => hasEnclosingTryBlock,
397
- hasParent: () => hasParent
414
+ hasParent: () => hasParent,
415
+ simpleTraverse: () => simpleTraverse
398
416
  });
417
+ function isNode(value) {
418
+ return typeof value === "object" && value != null && "type" in value && typeof value.type === "string";
419
+ }
420
+ function simpleTraverse(root, options = {}) {
421
+ const { enter, leave, setParentPointers = false, visitorKeys: visitorKeys$1 = visitorKeys } = options;
422
+ const visit = (node, parent) => {
423
+ if (!isNode(node)) return;
424
+ if (setParentPointers) {
425
+ if (parent == null) delete node.parent;
426
+ else node.parent = parent;
427
+ }
428
+ enter?.(node, parent);
429
+ for (const key of visitorKeys$1[node.type] ?? []) {
430
+ const child = node[key];
431
+ if (Array.isArray(child)) for (const item of child) visit(item, node);
432
+ else visit(child, node);
433
+ }
434
+ leave?.(node, parent);
435
+ };
436
+ visit(root, void 0);
437
+ }
399
438
  function findParent(node, test, stop) {
400
439
  if (node == null) return null;
401
440
  let current = node.parent;
@@ -419,4 +458,158 @@ function findEnclosingTryBlock(node) {
419
458
  function hasEnclosingTryBlock(node) {
420
459
  return findEnclosingTryBlock(node) != null;
421
460
  }
422
- export { check_exports as Check, compare_exports as Compare, extract_exports as Extract, traverse_exports as Traverse };
461
+ // src/collect.ts
462
+ var collect_exports = /* @__PURE__ */ __exportAll({
463
+ getCallExpressions: () => getCallExpressions,
464
+ getIdentifiers: () => getIdentifiers,
465
+ getNewExpressions: () => getNewExpressions,
466
+ getReturnExpressions: () => getReturnExpressions,
467
+ getReturnStatements: () => getReturnStatements
468
+ });
469
+ const EXPRESSION_VISITOR_KEYS = {
470
+ [AST_NODE_TYPES.ArrayExpression]: ["elements"],
471
+ [AST_NODE_TYPES.ArrayPattern]: ["elements"],
472
+ [AST_NODE_TYPES.AssignmentExpression]: ["left", "right"],
473
+ [AST_NODE_TYPES.AssignmentPattern]: ["left", "right"],
474
+ [AST_NODE_TYPES.AwaitExpression]: ["argument"],
475
+ [AST_NODE_TYPES.BinaryExpression]: ["left", "right"],
476
+ [AST_NODE_TYPES.CallExpression]: ["callee", "arguments"],
477
+ [AST_NODE_TYPES.ChainExpression]: ["expression"],
478
+ [AST_NODE_TYPES.ConditionalExpression]: [
479
+ "test",
480
+ "consequent",
481
+ "alternate"
482
+ ],
483
+ [AST_NODE_TYPES.Decorator]: ["expression"],
484
+ [AST_NODE_TYPES.DoWhileStatement]: ["test"],
485
+ [AST_NODE_TYPES.ExpressionStatement]: ["expression"],
486
+ [AST_NODE_TYPES.ForInStatement]: ["left", "right"],
487
+ [AST_NODE_TYPES.ForOfStatement]: ["left", "right"],
488
+ [AST_NODE_TYPES.ForStatement]: ["test"],
489
+ [AST_NODE_TYPES.IfStatement]: ["test"],
490
+ [AST_NODE_TYPES.ImportExpression]: ["source", "options"],
491
+ [AST_NODE_TYPES.JSXAttribute]: ["name", "value"],
492
+ [AST_NODE_TYPES.JSXElement]: [
493
+ "openingElement",
494
+ "children",
495
+ "closingElement"
496
+ ],
497
+ [AST_NODE_TYPES.JSXExpressionContainer]: ["expression"],
498
+ [AST_NODE_TYPES.JSXFragment]: [
499
+ "openingFragment",
500
+ "children",
501
+ "closingFragment"
502
+ ],
503
+ [AST_NODE_TYPES.JSXOpeningElement]: [
504
+ "name",
505
+ "typeArguments",
506
+ "attributes"
507
+ ],
508
+ [AST_NODE_TYPES.JSXSpreadAttribute]: ["argument"],
509
+ [AST_NODE_TYPES.JSXSpreadChild]: ["expression"],
510
+ [AST_NODE_TYPES.LogicalExpression]: ["left", "right"],
511
+ [AST_NODE_TYPES.MemberExpression]: ["object", "property"],
512
+ [AST_NODE_TYPES.NewExpression]: ["callee", "arguments"],
513
+ [AST_NODE_TYPES.ObjectExpression]: ["properties"],
514
+ [AST_NODE_TYPES.ObjectPattern]: ["properties"],
515
+ [AST_NODE_TYPES.Property]: ["key", "value"],
516
+ [AST_NODE_TYPES.RestElement]: ["argument"],
517
+ [AST_NODE_TYPES.SequenceExpression]: ["expressions"],
518
+ [AST_NODE_TYPES.SpreadElement]: ["argument"],
519
+ [AST_NODE_TYPES.SwitchCase]: ["test"],
520
+ [AST_NODE_TYPES.TaggedTemplateExpression]: ["tag", "quasi"],
521
+ [AST_NODE_TYPES.TemplateLiteral]: ["expressions"],
522
+ [AST_NODE_TYPES.TSAsExpression]: ["expression"],
523
+ [AST_NODE_TYPES.TSClassImplements]: ["expression"],
524
+ [AST_NODE_TYPES.TSExportAssignment]: ["expression"],
525
+ [AST_NODE_TYPES.TSExternalModuleReference]: ["expression"],
526
+ [AST_NODE_TYPES.TSInstantiationExpression]: ["expression"],
527
+ [AST_NODE_TYPES.TSInterfaceHeritage]: ["expression"],
528
+ [AST_NODE_TYPES.TSNonNullExpression]: ["expression"],
529
+ [AST_NODE_TYPES.TSSatisfiesExpression]: ["expression"],
530
+ [AST_NODE_TYPES.TSTypeAssertion]: ["expression"],
531
+ [AST_NODE_TYPES.UnaryExpression]: ["argument"],
532
+ [AST_NODE_TYPES.UpdateExpression]: ["argument"],
533
+ [AST_NODE_TYPES.WhileStatement]: ["test"],
534
+ [AST_NODE_TYPES.YieldExpression]: ["argument"]
535
+ };
536
+ const RETURN_VISITOR_KEYS = {
537
+ ...visitorKeys,
538
+ [AST_NODE_TYPES.ClassDeclaration]: [],
539
+ [AST_NODE_TYPES.ClassExpression]: []
540
+ };
541
+ function collectNodes(node, isNode) {
542
+ const nodes = [];
543
+ simpleTraverse(node, {
544
+ enter(node, parent) {
545
+ const parentNode = parent ?? node.parent;
546
+ if (parentNode?.type === AST_NODE_TYPES.MemberExpression && !parentNode.computed && parentNode.property === node) return;
547
+ if (parentNode?.type === AST_NODE_TYPES.Property && !parentNode.computed && parentNode.key === node) return;
548
+ if (isNode(node)) nodes.push(node);
549
+ },
550
+ visitorKeys: EXPRESSION_VISITOR_KEYS
551
+ });
552
+ return nodes;
553
+ }
554
+ function getIdentifiers(node) {
555
+ return collectNodes(node, isIdentifier);
556
+ }
557
+ function getExpressionsOfType(type) {
558
+ const isNodeOfType = is(type);
559
+ return (node) => collectNodes(node, isNodeOfType);
560
+ }
561
+ const getNewExpressions = getExpressionsOfType(AST_NODE_TYPES.NewExpression);
562
+ const getCallExpressions = getExpressionsOfType(AST_NODE_TYPES.CallExpression);
563
+ function getReturnStatements(node) {
564
+ const stmts = [];
565
+ const boundaryDepth = isFunction$1(node) ? 1 : 0;
566
+ let depth = 0;
567
+ simpleTraverse(node, {
568
+ enter(child) {
569
+ if (isFunction$1(child)) depth++;
570
+ if (child.type === AST_NODE_TYPES.ReturnStatement && depth === boundaryDepth) stmts.push(child);
571
+ },
572
+ leave(child) {
573
+ if (isFunction$1(child)) depth--;
574
+ },
575
+ visitorKeys: RETURN_VISITOR_KEYS
576
+ });
577
+ return stmts;
578
+ }
579
+ function getReturnExpressions(node) {
580
+ if (node.body.type !== AST_NODE_TYPES.BlockStatement) return [node.body];
581
+ return getReturnStatements(node).flatMap((stmt) => stmt.argument == null ? [] : [stmt.argument]);
582
+ }
583
+ // src/analyze.ts
584
+ var analyze_exports = /* @__PURE__ */ __exportAll({
585
+ isTerminatingStatement: () => isTerminatingStatement,
586
+ isUnconditionallyTerminating: () => isUnconditionallyTerminating
587
+ });
588
+ function isTerminatingStatement(node) {
589
+ switch (node.type) {
590
+ case AST_NODE_TYPES.ReturnStatement:
591
+ case AST_NODE_TYPES.ThrowStatement:
592
+ case AST_NODE_TYPES.BreakStatement:
593
+ case AST_NODE_TYPES.ContinueStatement: return true;
594
+ case AST_NODE_TYPES.BlockStatement: return node.body.some(isTerminatingStatement);
595
+ case AST_NODE_TYPES.IfStatement: return node.alternate != null && isTerminatingStatement(node.consequent) && isTerminatingStatement(node.alternate);
596
+ case AST_NODE_TYPES.TryStatement:
597
+ if (node.finalizer != null && isTerminatingStatement(node.finalizer)) return true;
598
+ if (node.handler == null) return isTerminatingStatement(node.block);
599
+ return isTerminatingStatement(node.block) && isTerminatingStatement(node.handler.body);
600
+ default: return false;
601
+ }
602
+ }
603
+ function isUnconditionallyTerminating(node) {
604
+ switch (node.type) {
605
+ case AST_NODE_TYPES.ReturnStatement:
606
+ case AST_NODE_TYPES.ThrowStatement: return true;
607
+ case AST_NODE_TYPES.BlockStatement: {
608
+ const last = node.body.at(-1);
609
+ return last != null && isUnconditionallyTerminating(last);
610
+ }
611
+ case AST_NODE_TYPES.IfStatement: return node.alternate != null && isUnconditionallyTerminating(node.consequent) && isUnconditionallyTerminating(node.alternate);
612
+ default: return false;
613
+ }
614
+ }
615
+ export { analyze_exports as Analyze, check_exports as Check, collect_exports as Collect, 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.30.0-beta.1",
3
+ "version": "5.30.0-beta.11",
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/typescript-estree": "^8.72.0",
34
- "@typescript-eslint/utils": "^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",