@eslint-react/ast 5.30.0-beta.2 → 5.30.0-beta.20
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 +123 -79
- package/dist/index.js +139 -129
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
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
|
+
/**
|
|
15
|
+
* Union of `MethodDefinition` and `PropertyDefinition` node types.
|
|
16
|
+
*
|
|
17
|
+
* Abstract and accessor member definitions are not included.
|
|
18
|
+
*/
|
|
19
|
+
type TSESTreeMethodOrPropertyDefinition = TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
16
20
|
/** Union of all JSX-related node types. */
|
|
17
21
|
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
22
|
/** Union of JSX attribute-like node types (attribute or spread attribute). */
|
|
21
23
|
type TSESTreeJSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
|
|
24
|
+
/** Union of JSX element-like node types (element or fragment). */
|
|
25
|
+
type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
22
26
|
/** Union of TypeScript type expression node types. */
|
|
23
|
-
type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.
|
|
27
|
+
type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
24
28
|
/** Union of expression node types that wrap another expression (TypeScript type expressions and chain expressions) — the nodes `Extract.unwrap` strips. */
|
|
25
|
-
type TSESTreeTypeOrChainExpression =
|
|
29
|
+
type TSESTreeTypeOrChainExpression = TSESTree.ChainExpression | TSESTreeTypeExpression;
|
|
26
30
|
declare namespace check_d_exports {
|
|
27
|
-
export { is, isCallExpression, isClass,
|
|
31
|
+
export { is, isArrayPatternElementDefault, isCallExpression, isClass, isConditionalOrLoop, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isObjectPatternElementDefault, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
|
|
28
32
|
}
|
|
29
33
|
/** Check if a node is of the given type. */
|
|
30
34
|
declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
@@ -42,55 +46,80 @@ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes:
|
|
|
42
46
|
*/
|
|
43
47
|
declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSESTree.Identifier;
|
|
44
48
|
/**
|
|
45
|
-
* Check if a node is an expression statement
|
|
46
|
-
*
|
|
49
|
+
* Check if a node is a directive (an expression statement in a directive prologue,
|
|
50
|
+
* ex: `"use client"`), optionally matching a specific name.
|
|
47
51
|
* @param node The node to check.
|
|
48
|
-
* @param name The directive name to match. When omitted, any
|
|
49
|
-
* @returns `true` if the node is
|
|
52
|
+
* @param name The directive name to match. When omitted, any directive matches.
|
|
53
|
+
* @returns `true` if the node is a directive and, when `name` is given, has that name.
|
|
50
54
|
*/
|
|
51
55
|
declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
|
|
52
56
|
/** Check if a node is a call expression. */
|
|
53
57
|
declare const isCallExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.CallExpression;
|
|
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;
|
|
54
60
|
/** Check if a node is a member expression. */
|
|
55
61
|
declare const isMemberExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName;
|
|
56
62
|
/** Check if a node is an object expression. */
|
|
57
63
|
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
64
|
/** Check if a node is a loop statement. */
|
|
61
65
|
declare const isLoopStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
62
66
|
/** Check if a node is a return statement. */
|
|
63
67
|
declare const isReturnStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.ReturnStatement;
|
|
64
68
|
/** Check if a node is a class declaration or class expression. */
|
|
65
69
|
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
70
|
+
/** Check if a node is a conditional or logical expression, a conditional statement, or a loop statement. */
|
|
71
|
+
declare const isConditionalOrLoop: (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
72
|
/** Check if a node is a function declaration, function expression, or arrow function expression. */
|
|
67
73
|
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
68
74
|
/** Check if a node is a function declaration, function expression, arrow function expression, class declaration, or class expression. */
|
|
69
75
|
declare const isFunctionOrClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
70
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Check if a node is a `TSPropertySignature`, `PropertyDefinition`, `TSIndexSignature`, or `TSParameterProperty`.
|
|
78
|
+
*
|
|
79
|
+
* Abstract and accessor property definitions (`TSAbstractPropertyDefinition`, `AccessorProperty`,
|
|
80
|
+
* `TSAbstractAccessorProperty`) are not included.
|
|
81
|
+
*/
|
|
71
82
|
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
72
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Check if a node is a `MethodDefinition` or `PropertyDefinition`.
|
|
85
|
+
*
|
|
86
|
+
* Abstract and accessor member definitions (`TSAbstractMethodDefinition`, `TSAbstractPropertyDefinition`,
|
|
87
|
+
* `AccessorProperty`, `TSAbstractAccessorProperty`) are not included.
|
|
88
|
+
*/
|
|
73
89
|
declare const isPropertyOrMethod: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
74
|
-
/**
|
|
75
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Check if a node is the default value of an array pattern element, i.e. an
|
|
92
|
+
* `AssignmentPattern` directly nested in an `ArrayPattern` (ex: `const [a = 1] = arr`).
|
|
93
|
+
* @param node The node to check.
|
|
94
|
+
* @returns `true` if the node is an array pattern element default.
|
|
95
|
+
*/
|
|
96
|
+
declare function isArrayPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a node is the default value of an object pattern property, i.e. an
|
|
99
|
+
* `AssignmentPattern` used as the `value` of a `Property` inside an `ObjectPattern`
|
|
100
|
+
* (ex: `const { a = 1 } = obj`).
|
|
101
|
+
* @param node The node to check.
|
|
102
|
+
* @returns `true` if the node is an object pattern element default.
|
|
103
|
+
*/
|
|
104
|
+
declare function isObjectPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
|
|
76
105
|
/** Check if a node is any JSX-related node. */
|
|
77
106
|
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
107
|
/** Check if a node is a JSX element. */
|
|
79
108
|
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
109
|
/** Check if a node is a JSX element or JSX fragment. */
|
|
83
110
|
declare const isJSXElementOrFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
84
111
|
/** Check if a node is a JSX expression container. */
|
|
85
112
|
declare const isJSXExpressionContainer: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXExpressionContainer;
|
|
113
|
+
/** Check if a node is a JSX fragment. */
|
|
114
|
+
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
86
115
|
/** Check if a node is a JSX spread attribute. */
|
|
87
116
|
declare const isJSXSpreadAttribute: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXSpreadAttribute;
|
|
88
117
|
/** Check if a node can appear as a JSX tag name. */
|
|
89
118
|
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
119
|
/** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
|
|
93
120
|
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
121
|
+
/** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
|
|
122
|
+
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
94
123
|
/** Check if a node is a TypeScript type expression or a chain expression (i.e. a transparent wrapper around an inner expression). */
|
|
95
124
|
declare const isTypeOrChainExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ChainExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
96
125
|
declare namespace compare_d_exports {
|
|
@@ -98,6 +127,13 @@ declare namespace compare_d_exports {
|
|
|
98
127
|
}
|
|
99
128
|
/**
|
|
100
129
|
* Check if two nodes are structurally equal.
|
|
130
|
+
*
|
|
131
|
+
* - Supports identifiers, private identifiers, literals, template literals/elements, member/call/chain expressions, JSX identifiers/namespaced names/member expressions/attributes, and `this`.
|
|
132
|
+
* - Node types outside that list (including functions and classes) are equal only when they are the same node.
|
|
133
|
+
* - Compares chain expressions through their inner expression, so optional segments remain significant (`a?.b` equals `a?.b` but not `a.b`).
|
|
134
|
+
* - Compares literals by value and regex literals by `pattern` and `flags`.
|
|
135
|
+
* - Ignores source locations (`loc`, `range`) and `parent` pointers.
|
|
136
|
+
* - Ignores type-level syntax: type annotations and type arguments are not compared, and type expressions are unwrapped, so `foo as string` equals `foo`.
|
|
101
137
|
* @param a The first node to compare.
|
|
102
138
|
* @param b The second node to compare.
|
|
103
139
|
* @returns `true` if the nodes are equal.
|
|
@@ -111,31 +147,34 @@ declare namespace collect_d_exports {
|
|
|
111
147
|
export { getCallExpressions, getIdentifiers, getNewExpressions, getReturnExpressions, getReturnStatements };
|
|
112
148
|
}
|
|
113
149
|
/**
|
|
114
|
-
* Get all identifiers
|
|
150
|
+
* Get all identifiers occurring within a node, in source order.
|
|
115
151
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
152
|
+
* This is a syntactic walk, not a scope-aware reference search: identifiers in patterns are
|
|
153
|
+
* collected too when the pattern is traversed (ex: `a` in `[a] = value`). The root is collected
|
|
154
|
+
* when it is an identifier. The property name of a non-computed member access is not a reference,
|
|
155
|
+
* so `obj.prop` collects only `obj`; non-computed object property keys are skipped as well.
|
|
156
|
+
* Function and class nodes are not traversed, and statement roots contribute only their listed
|
|
157
|
+
* expression-bearing keys.
|
|
158
|
+
* @param node The node to collect identifiers from.
|
|
159
|
+
* @returns All identifiers occurring in the node.
|
|
121
160
|
*/
|
|
122
161
|
declare function getIdentifiers(node: TSESTree.Node): readonly TSESTree.Identifier[];
|
|
123
162
|
/**
|
|
124
|
-
* Get all
|
|
163
|
+
* Get all `new` expressions within a node, in source order.
|
|
125
164
|
*
|
|
126
|
-
* Function and class
|
|
127
|
-
* expression-bearing
|
|
128
|
-
* @param node The
|
|
129
|
-
* @returns All
|
|
165
|
+
* The root is included when it is a `new` expression. Function and class nodes are not traversed,
|
|
166
|
+
* and statement roots contribute only their listed expression-bearing keys.
|
|
167
|
+
* @param node The node to collect `new` expressions from.
|
|
168
|
+
* @returns All matching `new` expressions.
|
|
130
169
|
*/
|
|
131
170
|
declare const getNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
|
|
132
171
|
/**
|
|
133
|
-
* Get all
|
|
172
|
+
* Get all call expressions within a node, in source order.
|
|
134
173
|
*
|
|
135
|
-
* Function and class
|
|
136
|
-
* expression-bearing
|
|
137
|
-
* @param node The
|
|
138
|
-
* @returns All
|
|
174
|
+
* The root is included when it is a call expression. Function and class nodes are not traversed,
|
|
175
|
+
* and statement roots contribute only their listed expression-bearing keys.
|
|
176
|
+
* @param node The node to collect call expressions from.
|
|
177
|
+
* @returns All matching call expressions.
|
|
139
178
|
*/
|
|
140
179
|
declare const getCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
141
180
|
/**
|
|
@@ -159,58 +198,63 @@ declare function getReturnStatements(node: TSESTree.Node): readonly TSESTree.Ret
|
|
|
159
198
|
*/
|
|
160
199
|
declare function getReturnExpressions(node: TSESTreeFunction): readonly TSESTree.Expression[];
|
|
161
200
|
declare namespace extract_d_exports {
|
|
162
|
-
export {
|
|
201
|
+
export { getCalleeName, getFullyQualifiedName, getJSXName, unwrap };
|
|
163
202
|
}
|
|
164
203
|
/**
|
|
165
204
|
* Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
|
|
166
205
|
* @param node The node to unwrap.
|
|
167
|
-
* @returns The innermost non-
|
|
206
|
+
* @returns The innermost non-wrapper node (`ChainExpression` and type expressions are stripped) — a reference into the original tree, never a copy.
|
|
168
207
|
*/
|
|
169
208
|
declare function unwrap(node: TSESTreeTypeOrChainExpression): Exclude<TSESTree.Expression, TSESTreeTypeOrChainExpression>;
|
|
170
209
|
declare function unwrap<T extends TSESTree.Node>(node: T): Exclude<T, TSESTreeTypeOrChainExpression>;
|
|
171
210
|
/**
|
|
172
|
-
*
|
|
173
|
-
* @param
|
|
174
|
-
* @
|
|
175
|
-
* @returns The matching `Property` node, or `null` when not found.
|
|
211
|
+
* Get the flattened name of a JSX identifier, namespaced name, or member expression.
|
|
212
|
+
* @param node The JSX name node.
|
|
213
|
+
* @returns The flattened JSX name (ex: `"Foo.Bar"`, `"xml:space"`).
|
|
176
214
|
*/
|
|
177
|
-
declare function
|
|
215
|
+
declare function getJSXName(node: TSESTree.JSXIdentifier | TSESTree.JSXNamespacedName | TSESTree.JSXMemberExpression): string;
|
|
216
|
+
/**
|
|
217
|
+
* Get the fully qualified name of a node (ex: `React.useState`), falling back to source text when needed.
|
|
218
|
+
* @param node The node to inspect.
|
|
219
|
+
* @param getText A function returning the source text of a node.
|
|
220
|
+
* @returns The fully qualified name.
|
|
221
|
+
*/
|
|
222
|
+
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
178
223
|
/**
|
|
179
224
|
* Get the name of the callee of a call expression.
|
|
180
225
|
* @param node The call expression to inspect.
|
|
181
|
-
* @returns The callee name (ex: `"useState"`), or `null`
|
|
226
|
+
* @returns The callee name (ex: `"useState"`), or `null` for computed member expressions and other unsupported callee forms.
|
|
182
227
|
*/
|
|
183
228
|
declare function getCalleeName(node: TSESTree.CallExpression): string | null;
|
|
229
|
+
declare namespace analyze_d_exports {
|
|
230
|
+
export { isTerminatingStatement, isUnconditionallyTerminating };
|
|
231
|
+
}
|
|
184
232
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
-
/**
|
|
201
|
-
* Get the static name of an object property's key.
|
|
202
|
-
* @param property The property to inspect.
|
|
203
|
-
* @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
|
|
204
|
-
* @returns The property name, or `null` when it cannot be statically determined.
|
|
233
|
+
* Check if a statement terminates the control flow of its block.
|
|
234
|
+
*
|
|
235
|
+
* - Treats `return`, `throw`, `break`, and `continue` as terminating.
|
|
236
|
+
* - Treats a block as terminating when any direct statement terminates (uses `some`), so unreachable trailing code does not matter.
|
|
237
|
+
* - Treats an `if` as terminating only when it has an `else` and both branches terminate.
|
|
238
|
+
* - Treats a `try` as terminating when its finalizer terminates, or when its try block terminates and, if present, its catch body terminates.
|
|
239
|
+
* - Does not analyze `switch` statements, loops, or labeled statements, so an all-terminating `switch` or an infinite loop is not recognized.
|
|
240
|
+
* - Is purely syntactic: conditions are not evaluated and no reachability analysis is performed.
|
|
241
|
+
* @param node The node to check.
|
|
242
|
+
* @returns `true` if the statement terminates the control flow.
|
|
205
243
|
*/
|
|
206
|
-
declare function
|
|
244
|
+
declare function isTerminatingStatement(node: TSESTree.Node): boolean;
|
|
207
245
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
246
|
+
* Check if every path through a statement exits the current function with a `return` or `throw`.
|
|
247
|
+
*
|
|
248
|
+
* - Treats only `return` and `throw` as terminating; unlike {@link isTerminatingStatement}, `break` and `continue` are not.
|
|
249
|
+
* - Inspects only the last statement of a block: `{ foo(); return; }` terminates, while `{ return; foo(); }` does not; earlier `break`/`continue` paths are not modeled.
|
|
250
|
+
* - Treats an `if` as terminating only when it has an `else` and both branches terminate.
|
|
251
|
+
* - Treats a `try` as terminating when its finalizer terminates, or when its try block terminates and, if present, its catch body terminates.
|
|
252
|
+
* - Does not analyze `switch` statements, loops, or labeled statements, so `while (true) {}` is not recognized.
|
|
253
|
+
* - Is purely syntactic: conditions are not evaluated and no reachability analysis is performed.
|
|
254
|
+
* @param node The node to check.
|
|
255
|
+
* @returns `true` if the statement unconditionally terminates.
|
|
212
256
|
*/
|
|
213
|
-
declare function
|
|
257
|
+
declare function isUnconditionallyTerminating(node: TSESTree.Node): boolean;
|
|
214
258
|
declare namespace traverse_d_exports {
|
|
215
259
|
export { SimpleTraverseOptions, findEnclosingTryBlock, findParent, hasEnclosingTryBlock, hasParent, simpleTraverse };
|
|
216
260
|
}
|
|
@@ -222,7 +266,7 @@ type SimpleTraverseOptions = {
|
|
|
222
266
|
enter?: (node: TSESTree.Node, parent: TSESTree.Node | undefined) => void;
|
|
223
267
|
/** Called for each visited node after its children are visited. */
|
|
224
268
|
leave?: (node: TSESTree.Node, parent: TSESTree.Node | undefined) => void;
|
|
225
|
-
/** Attach parent pointers to every visited node. */
|
|
269
|
+
/** Attach parent pointers to every visited node; the root's parent is removed. */
|
|
226
270
|
setParentPointers?: boolean;
|
|
227
271
|
/** Visitor keys to use instead of the default ESTree keys (ex: to prune subtrees). */
|
|
228
272
|
visitorKeys?: VisitorKeys;
|
|
@@ -276,4 +320,4 @@ declare function findEnclosingTryBlock(node: TSESTree.Node): TSESTree.TryStateme
|
|
|
276
320
|
* @returns `true` when an enclosing `try` block exists.
|
|
277
321
|
*/
|
|
278
322
|
declare function hasEnclosingTryBlock(node: TSESTree.Node): boolean;
|
|
279
|
-
export { 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 };
|
|
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
|
@@ -5,9 +5,10 @@ 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
|
+
isConditionalOrLoop: () => isConditionalOrLoop,
|
|
11
12
|
isDirective: () => isDirective,
|
|
12
13
|
isExpression: () => isExpression,
|
|
13
14
|
isFunction: () => isFunction$1,
|
|
@@ -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,
|
|
@@ -37,57 +39,68 @@ function isIdentifier(node, name) {
|
|
|
37
39
|
return node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
|
|
38
40
|
}
|
|
39
41
|
function isDirective(node, name) {
|
|
40
|
-
return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
|
|
42
|
+
return node.type === AST_NODE_TYPES.ExpressionStatement && node.directive != null && (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.
|
|
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.
|
|
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.
|
|
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.
|
|
57
|
-
AST_NODE_TYPES.
|
|
58
|
-
AST_NODE_TYPES.
|
|
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.
|
|
61
|
-
AST_NODE_TYPES.
|
|
62
|
-
AST_NODE_TYPES.
|
|
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.
|
|
66
|
-
AST_NODE_TYPES.
|
|
67
|
-
AST_NODE_TYPES.
|
|
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.
|
|
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.
|
|
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 isConditionalOrLoop = 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.
|
|
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
|
|
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.
|
|
160
|
+
AST_NODE_TYPES.TSTypeAssertion
|
|
154
161
|
]);
|
|
155
|
-
const
|
|
156
|
-
AST_NODE_TYPES.TSAsExpression,
|
|
157
|
-
AST_NODE_TYPES.TSTypeAssertion,
|
|
162
|
+
const isTypeExpression = isOneOf([
|
|
158
163
|
AST_NODE_TYPES.TSNonNullExpression,
|
|
159
|
-
AST_NODE_TYPES.
|
|
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.
|
|
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.
|
|
175
|
+
AST_NODE_TYPES.TSTypeAssertion
|
|
168
176
|
]);
|
|
169
177
|
// ../../.pkgs/eff/dist/index.js
|
|
170
178
|
const pipeArguments = (self, args) => {
|
|
@@ -236,9 +244,6 @@ dual(2, (a, b) => (data) => a(data) === b(data));
|
|
|
236
244
|
dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
237
245
|
dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
238
246
|
dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
239
|
-
function isString(input) {
|
|
240
|
-
return typeof input === "string";
|
|
241
|
-
}
|
|
242
247
|
function isFunction(input) {
|
|
243
248
|
return typeof input === "function";
|
|
244
249
|
}
|
|
@@ -262,84 +267,44 @@ dual(2, (self, predicate) => {
|
|
|
262
267
|
});
|
|
263
268
|
// src/extract.ts
|
|
264
269
|
var extract_exports = /* @__PURE__ */ __exportAll({
|
|
265
|
-
findProperty: () => findProperty,
|
|
266
|
-
getAssignmentTargets: () => getAssignmentTargets,
|
|
267
270
|
getCalleeName: () => getCalleeName,
|
|
268
271
|
getFullyQualifiedName: () => getFullyQualifiedName,
|
|
269
|
-
|
|
270
|
-
getPropertyName: () => getPropertyName,
|
|
272
|
+
getJSXName: () => getJSXName,
|
|
271
273
|
unwrap: () => unwrap
|
|
272
274
|
});
|
|
273
275
|
function unwrap(node) {
|
|
274
276
|
if (isTypeOrChainExpression(node)) return unwrap(node.expression);
|
|
275
277
|
return node;
|
|
276
278
|
}
|
|
277
|
-
function
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (found != null) return found;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
function getCalleeName(node) {
|
|
288
|
-
const callee = unwrap(node.callee);
|
|
289
|
-
if (isIdentifier(callee)) return callee.name;
|
|
290
|
-
if (callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifier(callee.property)) return callee.property.name;
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
function getMemberChain(node) {
|
|
294
|
-
const members = [];
|
|
295
|
-
let current = unwrap(node);
|
|
296
|
-
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
297
|
-
const property = unwrap(current.property);
|
|
298
|
-
members.unshift(property);
|
|
299
|
-
current = unwrap(current.object);
|
|
279
|
+
function getJSXName(node) {
|
|
280
|
+
switch (node.type) {
|
|
281
|
+
case AST_NODE_TYPES.JSXIdentifier: return node.name;
|
|
282
|
+
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
283
|
+
case AST_NODE_TYPES.JSXMemberExpression: return `${getJSXName(node.object)}.${getJSXName(node.property)}`;
|
|
300
284
|
}
|
|
301
|
-
members.unshift(current);
|
|
302
|
-
return members;
|
|
303
|
-
}
|
|
304
|
-
function getAssignmentTargets(node) {
|
|
305
|
-
const target = unwrap(node);
|
|
306
|
-
switch (target.type) {
|
|
307
|
-
case AST_NODE_TYPES.Identifier:
|
|
308
|
-
case AST_NODE_TYPES.MemberExpression: return [target];
|
|
309
|
-
case AST_NODE_TYPES.ArrayPattern: return target.elements.flatMap((element) => element == null ? [] : getAssignmentTargets(element));
|
|
310
|
-
case AST_NODE_TYPES.AssignmentPattern: return getAssignmentTargets(target.left);
|
|
311
|
-
case AST_NODE_TYPES.ObjectPattern: return target.properties.flatMap((property) => {
|
|
312
|
-
if (property.type === AST_NODE_TYPES.RestElement) return getAssignmentTargets(property.argument);
|
|
313
|
-
return getAssignmentTargets(property.value);
|
|
314
|
-
});
|
|
315
|
-
case AST_NODE_TYPES.RestElement: return getAssignmentTargets(target.argument);
|
|
316
|
-
default: return [];
|
|
317
|
-
}
|
|
318
|
-
}
|
|
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
285
|
}
|
|
327
286
|
function getFullyQualifiedName(node, getText) {
|
|
328
287
|
const expr = unwrap(node);
|
|
329
288
|
switch (expr.type) {
|
|
330
|
-
case AST_NODE_TYPES.Identifier:
|
|
289
|
+
case AST_NODE_TYPES.Identifier: return expr.name;
|
|
290
|
+
case AST_NODE_TYPES.PrivateIdentifier: return `#${expr.name}`;
|
|
331
291
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
332
|
-
case AST_NODE_TYPES.
|
|
292
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
293
|
+
case AST_NODE_TYPES.JSXNamespacedName: return getJSXName(expr);
|
|
333
294
|
case AST_NODE_TYPES.MemberExpression:
|
|
334
295
|
if (expr.computed) return getText(expr);
|
|
335
296
|
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
297
|
case AST_NODE_TYPES.JSXText: return expr.value;
|
|
339
298
|
case AST_NODE_TYPES.Literal: return expr.raw;
|
|
340
299
|
default: return getText(expr);
|
|
341
300
|
}
|
|
342
301
|
}
|
|
302
|
+
function getCalleeName(node) {
|
|
303
|
+
const callee = unwrap(node.callee);
|
|
304
|
+
if (isIdentifier(callee)) return callee.name;
|
|
305
|
+
if (callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && isIdentifier(callee.property)) return callee.property.name;
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
343
308
|
// src/compare.ts
|
|
344
309
|
var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
|
|
345
310
|
const isEqual = dual(2, (a, b) => {
|
|
@@ -348,7 +313,9 @@ const isEqual = dual(2, (a, b) => {
|
|
|
348
313
|
switch (true) {
|
|
349
314
|
case a === b: return true;
|
|
350
315
|
case a.type !== b.type: return false;
|
|
351
|
-
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal:
|
|
316
|
+
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal:
|
|
317
|
+
if ("regex" in a || "regex" in b) return "regex" in a && "regex" in b && a.regex.pattern === b.regex.pattern && a.regex.flags === b.regex.flags;
|
|
318
|
+
return a.value === b.value;
|
|
352
319
|
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
353
320
|
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
354
321
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
@@ -365,7 +332,8 @@ const isEqual = dual(2, (a, b) => {
|
|
|
365
332
|
}
|
|
366
333
|
case isIdentifier(a) && isIdentifier(b): return a.name === b.name;
|
|
367
334
|
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
368
|
-
case a.type === AST_NODE_TYPES.
|
|
335
|
+
case a.type === AST_NODE_TYPES.ChainExpression && b.type === AST_NODE_TYPES.ChainExpression: return isEqual(a.expression, b.expression);
|
|
336
|
+
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);
|
|
369
337
|
case a.type === AST_NODE_TYPES.CallExpression && b.type === AST_NODE_TYPES.CallExpression: {
|
|
370
338
|
if (a.optional !== b.optional) return false;
|
|
371
339
|
if (a.arguments.length !== b.arguments.length) return false;
|
|
@@ -469,7 +437,11 @@ const EXPRESSION_VISITOR_KEYS = {
|
|
|
469
437
|
[AST_NODE_TYPES.ExpressionStatement]: ["expression"],
|
|
470
438
|
[AST_NODE_TYPES.ForInStatement]: ["left", "right"],
|
|
471
439
|
[AST_NODE_TYPES.ForOfStatement]: ["left", "right"],
|
|
472
|
-
[AST_NODE_TYPES.ForStatement]: [
|
|
440
|
+
[AST_NODE_TYPES.ForStatement]: [
|
|
441
|
+
"init",
|
|
442
|
+
"test",
|
|
443
|
+
"update"
|
|
444
|
+
],
|
|
473
445
|
[AST_NODE_TYPES.IfStatement]: ["test"],
|
|
474
446
|
[AST_NODE_TYPES.ImportExpression]: ["source", "options"],
|
|
475
447
|
[AST_NODE_TYPES.JSXAttribute]: ["name", "value"],
|
|
@@ -514,6 +486,8 @@ const EXPRESSION_VISITOR_KEYS = {
|
|
|
514
486
|
[AST_NODE_TYPES.TSTypeAssertion]: ["expression"],
|
|
515
487
|
[AST_NODE_TYPES.UnaryExpression]: ["argument"],
|
|
516
488
|
[AST_NODE_TYPES.UpdateExpression]: ["argument"],
|
|
489
|
+
[AST_NODE_TYPES.VariableDeclaration]: ["declarations"],
|
|
490
|
+
[AST_NODE_TYPES.VariableDeclarator]: ["init"],
|
|
517
491
|
[AST_NODE_TYPES.WhileStatement]: ["test"],
|
|
518
492
|
[AST_NODE_TYPES.YieldExpression]: ["argument"]
|
|
519
493
|
};
|
|
@@ -564,4 +538,40 @@ function getReturnExpressions(node) {
|
|
|
564
538
|
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return [node.body];
|
|
565
539
|
return getReturnStatements(node).flatMap((stmt) => stmt.argument == null ? [] : [stmt.argument]);
|
|
566
540
|
}
|
|
567
|
-
|
|
541
|
+
// src/analyze.ts
|
|
542
|
+
var analyze_exports = /* @__PURE__ */ __exportAll({
|
|
543
|
+
isTerminatingStatement: () => isTerminatingStatement,
|
|
544
|
+
isUnconditionallyTerminating: () => isUnconditionallyTerminating
|
|
545
|
+
});
|
|
546
|
+
function isTerminatingStatement(node) {
|
|
547
|
+
switch (node.type) {
|
|
548
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
549
|
+
case AST_NODE_TYPES.ThrowStatement:
|
|
550
|
+
case AST_NODE_TYPES.BreakStatement:
|
|
551
|
+
case AST_NODE_TYPES.ContinueStatement: return true;
|
|
552
|
+
case AST_NODE_TYPES.BlockStatement: return node.body.some(isTerminatingStatement);
|
|
553
|
+
case AST_NODE_TYPES.IfStatement: return node.alternate != null && isTerminatingStatement(node.consequent) && isTerminatingStatement(node.alternate);
|
|
554
|
+
case AST_NODE_TYPES.TryStatement:
|
|
555
|
+
if (node.finalizer != null && isTerminatingStatement(node.finalizer)) return true;
|
|
556
|
+
if (node.handler == null) return isTerminatingStatement(node.block);
|
|
557
|
+
return isTerminatingStatement(node.block) && isTerminatingStatement(node.handler.body);
|
|
558
|
+
default: return false;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function isUnconditionallyTerminating(node) {
|
|
562
|
+
switch (node.type) {
|
|
563
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
564
|
+
case AST_NODE_TYPES.ThrowStatement: return true;
|
|
565
|
+
case AST_NODE_TYPES.BlockStatement: {
|
|
566
|
+
const last = node.body.at(-1);
|
|
567
|
+
return last != null && isUnconditionallyTerminating(last);
|
|
568
|
+
}
|
|
569
|
+
case AST_NODE_TYPES.IfStatement: return node.alternate != null && isUnconditionallyTerminating(node.consequent) && isUnconditionallyTerminating(node.alternate);
|
|
570
|
+
case AST_NODE_TYPES.TryStatement:
|
|
571
|
+
if (node.finalizer != null && isUnconditionallyTerminating(node.finalizer)) return true;
|
|
572
|
+
if (node.handler == null) return isUnconditionallyTerminating(node.block);
|
|
573
|
+
return isUnconditionallyTerminating(node.block) && isUnconditionallyTerminating(node.handler.body);
|
|
574
|
+
default: return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
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.
|
|
3
|
+
"version": "5.30.0-beta.20",
|
|
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.
|
|
33
|
-
"@typescript-eslint/utils": "^8.72.
|
|
34
|
-
"@typescript-eslint/visitor-keys": "^8.72.
|
|
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",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@local/testkit": "0.0.0",
|
|
40
40
|
"@tsconfig/node20": "^20.1.10",
|
|
41
41
|
"@types/node": "^20.19.43",
|
|
42
|
-
"eslint": "^10.
|
|
43
|
-
"tsdown": "^0.23.
|
|
42
|
+
"eslint": "^10.14.0",
|
|
43
|
+
"tsdown": "^0.23.4",
|
|
44
44
|
"typescript": "6.0.3",
|
|
45
45
|
"vitest": "^5.0.5"
|
|
46
46
|
},
|