@eslint-react/ast 1.48.2-beta.0 → 1.48.2-beta.2
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.mts +31 -39
- package/dist/index.d.ts +31 -39
- package/dist/index.js +115 -117
- package/dist/index.mjs +113 -115
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -25,7 +25,7 @@ type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TS
|
|
|
25
25
|
* @param node The AST node to check
|
|
26
26
|
* @returns class identifier or null
|
|
27
27
|
*/
|
|
28
|
-
declare function
|
|
28
|
+
declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Recursively get the inner expression until it's not a TypeExpression
|
|
@@ -34,27 +34,6 @@ declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier |
|
|
|
34
34
|
*/
|
|
35
35
|
declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
36
36
|
declare function isThisExpression(node: TSESTree.Expression): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Get all nested expressions of type T in an expression like node
|
|
39
|
-
* @param type The type of the expression to retrieve within the node
|
|
40
|
-
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
41
|
-
* node, and it will return an array of all nested expressions of type T.
|
|
42
|
-
*/
|
|
43
|
-
declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
|
|
44
|
-
type: TNodeType;
|
|
45
|
-
}>[];
|
|
46
|
-
/**
|
|
47
|
-
* Get all nested new expressions in an expression like node
|
|
48
|
-
* @param node The node to get the nested new expressions from
|
|
49
|
-
* @returns All nested new expressions
|
|
50
|
-
*/
|
|
51
|
-
declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
|
|
52
|
-
/**
|
|
53
|
-
* Get all nested call expressions in a expression like node
|
|
54
|
-
* @param node The node to get the nested call expressions from
|
|
55
|
-
* @returns All nested call expressions
|
|
56
|
-
*/
|
|
57
|
-
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
58
37
|
|
|
59
38
|
/**
|
|
60
39
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -64,7 +43,7 @@ declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallEx
|
|
|
64
43
|
* same AST nodes with some exceptions to better fit our use case.
|
|
65
44
|
*/
|
|
66
45
|
|
|
67
|
-
declare function
|
|
46
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
68
47
|
|
|
69
48
|
type FunctionInitPath =
|
|
70
49
|
/**
|
|
@@ -190,6 +169,33 @@ declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.N
|
|
|
190
169
|
* @returns All nested identifiers
|
|
191
170
|
*/
|
|
192
171
|
declare function getNestedIdentifiers(node: TSESTree.Node): readonly TSESTree.Identifier[];
|
|
172
|
+
/**
|
|
173
|
+
* Gets the nested return statements in the node that are within the same function
|
|
174
|
+
* @param node The AST node
|
|
175
|
+
* @returns The nested return statements in the node
|
|
176
|
+
*/
|
|
177
|
+
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
178
|
+
/**
|
|
179
|
+
* Get all nested expressions of type T in an expression like node
|
|
180
|
+
* @param type The type of the expression to retrieve within the node
|
|
181
|
+
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
182
|
+
* node, and it will return an array of all nested expressions of type T.
|
|
183
|
+
*/
|
|
184
|
+
declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
|
|
185
|
+
type: TNodeType;
|
|
186
|
+
}>[];
|
|
187
|
+
/**
|
|
188
|
+
* Get all nested new expressions in an expression like node
|
|
189
|
+
* @param node The node to get the nested new expressions from
|
|
190
|
+
* @returns All nested new expressions
|
|
191
|
+
*/
|
|
192
|
+
declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
|
|
193
|
+
/**
|
|
194
|
+
* Get all nested call expressions in a expression like node
|
|
195
|
+
* @param node The node to get the nested call expressions from
|
|
196
|
+
* @returns All nested call expressions
|
|
197
|
+
*/
|
|
198
|
+
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
193
199
|
|
|
194
200
|
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
195
201
|
type: NodeType;
|
|
@@ -266,21 +272,7 @@ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | _, oper
|
|
|
266
272
|
|
|
267
273
|
declare function getPropertyName(node: TSESTree.Node): string | _;
|
|
268
274
|
|
|
269
|
-
|
|
270
|
-
* Gets the nested return statements in the node that are within the same function
|
|
271
|
-
* @param node The AST node
|
|
272
|
-
* @returns The nested return statements in the node
|
|
273
|
-
*/
|
|
274
|
-
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Returns human readable node type for given AST node
|
|
278
|
-
* @param node AST node
|
|
279
|
-
* @returns Human readable node type
|
|
280
|
-
*/
|
|
281
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "string literal" | "number literal" | "bigint literal" | "boolean literal" | "symbol literal" | "undefined literal" | "object literal" | "function literal" | "null literal" | "identifier" | "member expression" | "JSX attribute" | "JSX element" | "JSX fragment" | "JSX identifier" | "JSX text" | "JSX closing element" | "JSX closing fragment" | "JSX empty expression" | "JSX expression container" | "JSX member expression" | "JSX namespaced name" | "JSX opening element" | "JSX opening fragment" | "JSX spread attribute" | "JSX spread child" | "decorator" | "program" | "super" | "accessor property" | "array expression" | "array pattern" | "function expression" | "arrow function expression" | "assignment expression" | "assignment pattern" | "await expression" | "binary expression" | "block statement" | "break statement" | "call expression" | "catch clause" | "chain expression" | "class body" | "class declaration" | "class expression" | "conditional expression" | "continue statement" | "debugger statement" | "while statement" | "do while statement" | "empty statement" | "export all declaration" | "export default declaration" | "export named declaration" | "export specifier" | "expression statement" | "for in statement" | "for of statement" | "for statement" | "function declaration" | "if statement" | "import attribute" | "import declaration" | "import default specifier" | "import expression" | "import namespace specifier" | "import specifier" | "labeled statement" | "logical expression" | "meta property" | "method definition" | "new expression" | "object expression" | "object pattern" | "private identifier" | "property definition" | "rest element" | "return statement" | "sequence expression" | "spread element" | "static block" | "switch case" | "switch statement" | "tagged template expression" | "template element" | "template literal" | "this expression" | "throw statement" | "try statement" | "unary expression" | "update expression" | "variable declaration" | "variable declarator" | "with statement" | "yield expression" | "ts abstract accessor property" | "ts abstract keyword" | "ts abstract method definition" | "ts abstract property definition" | "ts any keyword" | "ts array type" | "ts as expression" | "ts async keyword" | "ts big int keyword" | "ts boolean keyword" | "ts call signature declaration" | "ts class implements" | "ts conditional type" | "ts constructor type" | "ts construct signature declaration" | "ts declare function" | "ts declare keyword" | "ts empty body function expression" | "ts enum body" | "ts enum declaration" | "ts enum member" | "ts export assignment" | "ts export keyword" | "ts external module reference" | "ts function type" | "ts import equals declaration" | "ts import type" | "ts indexed access type" | "ts index signature" | "ts infer type" | "ts instantiation expression" | "ts interface body" | "ts interface declaration" | "ts interface heritage" | "ts intersection type" | "ts intrinsic keyword" | "ts literal type" | "ts mapped type" | "ts method signature" | "ts module block" | "ts module declaration" | "ts named tuple member" | "ts namespace export declaration" | "ts never keyword" | "ts non null expression" | "ts null keyword" | "ts number keyword" | "ts object keyword" | "ts optional type" | "ts parameter property" | "ts private keyword" | "ts property signature" | "ts protected keyword" | "ts public keyword" | "ts qualified name" | "ts readonly keyword" | "ts rest type" | "ts satisfies expression" | "ts static keyword" | "ts string keyword" | "ts symbol keyword" | "ts template literal type" | "ts this type" | "ts tuple type" | "ts type alias declaration" | "ts type annotation" | "ts type assertion" | "ts type literal" | "ts type operator" | "ts type parameter" | "ts type parameter declaration" | "ts type parameter instantiation" | "ts type predicate" | "ts type query" | "ts type reference" | "ts undefined keyword" | "ts union type" | "ts unknown keyword" | "ts void keyword";
|
|
282
|
-
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
283
|
-
|
|
275
|
+
declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
284
276
|
/**
|
|
285
277
|
* Returns human readable node name for given AST node
|
|
286
278
|
* @param node AST node
|
|
@@ -289,4 +281,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
289
281
|
*/
|
|
290
282
|
declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
291
283
|
|
|
292
|
-
export { type FunctionInitPath, type
|
|
284
|
+
export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TS
|
|
|
25
25
|
* @param node The AST node to check
|
|
26
26
|
* @returns class identifier or null
|
|
27
27
|
*/
|
|
28
|
-
declare function
|
|
28
|
+
declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Recursively get the inner expression until it's not a TypeExpression
|
|
@@ -34,27 +34,6 @@ declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier |
|
|
|
34
34
|
*/
|
|
35
35
|
declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
36
36
|
declare function isThisExpression(node: TSESTree.Expression): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Get all nested expressions of type T in an expression like node
|
|
39
|
-
* @param type The type of the expression to retrieve within the node
|
|
40
|
-
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
41
|
-
* node, and it will return an array of all nested expressions of type T.
|
|
42
|
-
*/
|
|
43
|
-
declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
|
|
44
|
-
type: TNodeType;
|
|
45
|
-
}>[];
|
|
46
|
-
/**
|
|
47
|
-
* Get all nested new expressions in an expression like node
|
|
48
|
-
* @param node The node to get the nested new expressions from
|
|
49
|
-
* @returns All nested new expressions
|
|
50
|
-
*/
|
|
51
|
-
declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
|
|
52
|
-
/**
|
|
53
|
-
* Get all nested call expressions in a expression like node
|
|
54
|
-
* @param node The node to get the nested call expressions from
|
|
55
|
-
* @returns All nested call expressions
|
|
56
|
-
*/
|
|
57
|
-
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
58
37
|
|
|
59
38
|
/**
|
|
60
39
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -64,7 +43,7 @@ declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallEx
|
|
|
64
43
|
* same AST nodes with some exceptions to better fit our use case.
|
|
65
44
|
*/
|
|
66
45
|
|
|
67
|
-
declare function
|
|
46
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
68
47
|
|
|
69
48
|
type FunctionInitPath =
|
|
70
49
|
/**
|
|
@@ -190,6 +169,33 @@ declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.N
|
|
|
190
169
|
* @returns All nested identifiers
|
|
191
170
|
*/
|
|
192
171
|
declare function getNestedIdentifiers(node: TSESTree.Node): readonly TSESTree.Identifier[];
|
|
172
|
+
/**
|
|
173
|
+
* Gets the nested return statements in the node that are within the same function
|
|
174
|
+
* @param node The AST node
|
|
175
|
+
* @returns The nested return statements in the node
|
|
176
|
+
*/
|
|
177
|
+
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
178
|
+
/**
|
|
179
|
+
* Get all nested expressions of type T in an expression like node
|
|
180
|
+
* @param type The type of the expression to retrieve within the node
|
|
181
|
+
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
182
|
+
* node, and it will return an array of all nested expressions of type T.
|
|
183
|
+
*/
|
|
184
|
+
declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
|
|
185
|
+
type: TNodeType;
|
|
186
|
+
}>[];
|
|
187
|
+
/**
|
|
188
|
+
* Get all nested new expressions in an expression like node
|
|
189
|
+
* @param node The node to get the nested new expressions from
|
|
190
|
+
* @returns All nested new expressions
|
|
191
|
+
*/
|
|
192
|
+
declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpression[];
|
|
193
|
+
/**
|
|
194
|
+
* Get all nested call expressions in a expression like node
|
|
195
|
+
* @param node The node to get the nested call expressions from
|
|
196
|
+
* @returns All nested call expressions
|
|
197
|
+
*/
|
|
198
|
+
declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
|
|
193
199
|
|
|
194
200
|
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
195
201
|
type: NodeType;
|
|
@@ -266,21 +272,7 @@ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | _, oper
|
|
|
266
272
|
|
|
267
273
|
declare function getPropertyName(node: TSESTree.Node): string | _;
|
|
268
274
|
|
|
269
|
-
|
|
270
|
-
* Gets the nested return statements in the node that are within the same function
|
|
271
|
-
* @param node The AST node
|
|
272
|
-
* @returns The nested return statements in the node
|
|
273
|
-
*/
|
|
274
|
-
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Returns human readable node type for given AST node
|
|
278
|
-
* @param node AST node
|
|
279
|
-
* @returns Human readable node type
|
|
280
|
-
*/
|
|
281
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "string literal" | "number literal" | "bigint literal" | "boolean literal" | "symbol literal" | "undefined literal" | "object literal" | "function literal" | "null literal" | "identifier" | "member expression" | "JSX attribute" | "JSX element" | "JSX fragment" | "JSX identifier" | "JSX text" | "JSX closing element" | "JSX closing fragment" | "JSX empty expression" | "JSX expression container" | "JSX member expression" | "JSX namespaced name" | "JSX opening element" | "JSX opening fragment" | "JSX spread attribute" | "JSX spread child" | "decorator" | "program" | "super" | "accessor property" | "array expression" | "array pattern" | "function expression" | "arrow function expression" | "assignment expression" | "assignment pattern" | "await expression" | "binary expression" | "block statement" | "break statement" | "call expression" | "catch clause" | "chain expression" | "class body" | "class declaration" | "class expression" | "conditional expression" | "continue statement" | "debugger statement" | "while statement" | "do while statement" | "empty statement" | "export all declaration" | "export default declaration" | "export named declaration" | "export specifier" | "expression statement" | "for in statement" | "for of statement" | "for statement" | "function declaration" | "if statement" | "import attribute" | "import declaration" | "import default specifier" | "import expression" | "import namespace specifier" | "import specifier" | "labeled statement" | "logical expression" | "meta property" | "method definition" | "new expression" | "object expression" | "object pattern" | "private identifier" | "property definition" | "rest element" | "return statement" | "sequence expression" | "spread element" | "static block" | "switch case" | "switch statement" | "tagged template expression" | "template element" | "template literal" | "this expression" | "throw statement" | "try statement" | "unary expression" | "update expression" | "variable declaration" | "variable declarator" | "with statement" | "yield expression" | "ts abstract accessor property" | "ts abstract keyword" | "ts abstract method definition" | "ts abstract property definition" | "ts any keyword" | "ts array type" | "ts as expression" | "ts async keyword" | "ts big int keyword" | "ts boolean keyword" | "ts call signature declaration" | "ts class implements" | "ts conditional type" | "ts constructor type" | "ts construct signature declaration" | "ts declare function" | "ts declare keyword" | "ts empty body function expression" | "ts enum body" | "ts enum declaration" | "ts enum member" | "ts export assignment" | "ts export keyword" | "ts external module reference" | "ts function type" | "ts import equals declaration" | "ts import type" | "ts indexed access type" | "ts index signature" | "ts infer type" | "ts instantiation expression" | "ts interface body" | "ts interface declaration" | "ts interface heritage" | "ts intersection type" | "ts intrinsic keyword" | "ts literal type" | "ts mapped type" | "ts method signature" | "ts module block" | "ts module declaration" | "ts named tuple member" | "ts namespace export declaration" | "ts never keyword" | "ts non null expression" | "ts null keyword" | "ts number keyword" | "ts object keyword" | "ts optional type" | "ts parameter property" | "ts private keyword" | "ts property signature" | "ts protected keyword" | "ts public keyword" | "ts qualified name" | "ts readonly keyword" | "ts rest type" | "ts satisfies expression" | "ts static keyword" | "ts string keyword" | "ts symbol keyword" | "ts template literal type" | "ts this type" | "ts tuple type" | "ts type alias declaration" | "ts type annotation" | "ts type assertion" | "ts type literal" | "ts type operator" | "ts type parameter" | "ts type parameter declaration" | "ts type parameter instantiation" | "ts type predicate" | "ts type query" | "ts type reference" | "ts undefined keyword" | "ts union type" | "ts unknown keyword" | "ts void keyword";
|
|
282
|
-
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
283
|
-
|
|
275
|
+
declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
284
276
|
/**
|
|
285
277
|
* Returns human readable node name for given AST node
|
|
286
278
|
* @param node AST node
|
|
@@ -289,4 +281,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
289
281
|
*/
|
|
290
282
|
declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
291
283
|
|
|
292
|
-
export { type FunctionInitPath, type
|
|
284
|
+
export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ var indexParamPosition = /* @__PURE__ */ new Map([
|
|
|
40
40
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
41
41
|
return indexParamPosition.get(methodName) ?? -1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function getClassId(node) {
|
|
44
44
|
if (node.id != null) return node.id;
|
|
45
45
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
46
46
|
return node.parent.id;
|
|
@@ -201,92 +201,7 @@ function getJSExpression(node) {
|
|
|
201
201
|
function isThisExpression(node) {
|
|
202
202
|
return getJSExpression(node).type === types.AST_NODE_TYPES.ThisExpression;
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
const isNodeOfType = is(type);
|
|
206
|
-
return function(node) {
|
|
207
|
-
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
208
|
-
const expressions = [];
|
|
209
|
-
if (isNodeOfType(node)) {
|
|
210
|
-
expressions.push(node);
|
|
211
|
-
}
|
|
212
|
-
if ("arguments" in node) {
|
|
213
|
-
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
214
|
-
expressions.push(...chunk);
|
|
215
|
-
}
|
|
216
|
-
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
217
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
218
|
-
expressions.push(...chunk);
|
|
219
|
-
}
|
|
220
|
-
if ("left" in node) {
|
|
221
|
-
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
222
|
-
expressions.push(...chunk);
|
|
223
|
-
}
|
|
224
|
-
if ("right" in node) {
|
|
225
|
-
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
226
|
-
expressions.push(...chunk);
|
|
227
|
-
}
|
|
228
|
-
if ("test" in node && node.test != null) {
|
|
229
|
-
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
230
|
-
expressions.push(...chunk);
|
|
231
|
-
}
|
|
232
|
-
if ("consequent" in node) {
|
|
233
|
-
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
234
|
-
expressions.push(...chunk);
|
|
235
|
-
}
|
|
236
|
-
if ("alternate" in node && node.alternate != null) {
|
|
237
|
-
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
238
|
-
expressions.push(...chunk);
|
|
239
|
-
}
|
|
240
|
-
if ("elements" in node) {
|
|
241
|
-
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
242
|
-
expressions.push(...chunk);
|
|
243
|
-
}
|
|
244
|
-
if ("properties" in node) {
|
|
245
|
-
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
246
|
-
expressions.push(...chunk);
|
|
247
|
-
}
|
|
248
|
-
if ("expressions" in node) {
|
|
249
|
-
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
250
|
-
expressions.push(...chunk);
|
|
251
|
-
}
|
|
252
|
-
if (node.type === types.AST_NODE_TYPES.Property) {
|
|
253
|
-
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
254
|
-
expressions.push(...chunk);
|
|
255
|
-
}
|
|
256
|
-
if (node.type === types.AST_NODE_TYPES.SpreadElement) {
|
|
257
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
258
|
-
expressions.push(...chunk);
|
|
259
|
-
}
|
|
260
|
-
if (node.type === types.AST_NODE_TYPES.MemberExpression) {
|
|
261
|
-
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
262
|
-
expressions.push(...chunk);
|
|
263
|
-
}
|
|
264
|
-
if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
|
|
265
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
266
|
-
expressions.push(...chunk);
|
|
267
|
-
}
|
|
268
|
-
if (node.type === types.AST_NODE_TYPES.ChainExpression) {
|
|
269
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
270
|
-
expressions.push(...chunk);
|
|
271
|
-
}
|
|
272
|
-
if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
|
|
273
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
274
|
-
expressions.push(...chunk);
|
|
275
|
-
}
|
|
276
|
-
if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
|
|
277
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
278
|
-
expressions.push(...chunk);
|
|
279
|
-
}
|
|
280
|
-
if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
281
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
282
|
-
expressions.push(...chunk);
|
|
283
|
-
}
|
|
284
|
-
return expressions;
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression);
|
|
288
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression);
|
|
289
|
-
function getFunctionIdentifier(node) {
|
|
204
|
+
function getFunctionId(node) {
|
|
290
205
|
switch (true) {
|
|
291
206
|
// function MaybeComponent() {}
|
|
292
207
|
case ("id" in node && node.id != null):
|
|
@@ -315,7 +230,7 @@ function getFunctionIdentifier(node) {
|
|
|
315
230
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
316
231
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
317
232
|
case isTypeAssertionExpression(node.parent):
|
|
318
|
-
return
|
|
233
|
+
return getFunctionId(node.parent);
|
|
319
234
|
}
|
|
320
235
|
return eff._;
|
|
321
236
|
}
|
|
@@ -432,6 +347,108 @@ function getNestedIdentifiers(node) {
|
|
|
432
347
|
}
|
|
433
348
|
return identifiers;
|
|
434
349
|
}
|
|
350
|
+
function getNestedReturnStatements(node) {
|
|
351
|
+
const statements = [];
|
|
352
|
+
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
353
|
+
typescriptEstree.simpleTraverse(node, {
|
|
354
|
+
enter(node2) {
|
|
355
|
+
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
359
|
+
if (parentFunction !== boundaryNode) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
statements.push(node2);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return statements;
|
|
366
|
+
}
|
|
367
|
+
function getNestedExpressionsOfType(type) {
|
|
368
|
+
const isNodeOfType = is(type);
|
|
369
|
+
return function(node) {
|
|
370
|
+
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
371
|
+
const expressions = [];
|
|
372
|
+
if (isNodeOfType(node)) {
|
|
373
|
+
expressions.push(node);
|
|
374
|
+
}
|
|
375
|
+
if ("arguments" in node) {
|
|
376
|
+
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
377
|
+
expressions.push(...chunk);
|
|
378
|
+
}
|
|
379
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
380
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
381
|
+
expressions.push(...chunk);
|
|
382
|
+
}
|
|
383
|
+
if ("left" in node) {
|
|
384
|
+
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
385
|
+
expressions.push(...chunk);
|
|
386
|
+
}
|
|
387
|
+
if ("right" in node) {
|
|
388
|
+
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
389
|
+
expressions.push(...chunk);
|
|
390
|
+
}
|
|
391
|
+
if ("test" in node && node.test != null) {
|
|
392
|
+
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
393
|
+
expressions.push(...chunk);
|
|
394
|
+
}
|
|
395
|
+
if ("consequent" in node) {
|
|
396
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
397
|
+
expressions.push(...chunk);
|
|
398
|
+
}
|
|
399
|
+
if ("alternate" in node && node.alternate != null) {
|
|
400
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
401
|
+
expressions.push(...chunk);
|
|
402
|
+
}
|
|
403
|
+
if ("elements" in node) {
|
|
404
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
405
|
+
expressions.push(...chunk);
|
|
406
|
+
}
|
|
407
|
+
if ("properties" in node) {
|
|
408
|
+
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
409
|
+
expressions.push(...chunk);
|
|
410
|
+
}
|
|
411
|
+
if ("expressions" in node) {
|
|
412
|
+
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
413
|
+
expressions.push(...chunk);
|
|
414
|
+
}
|
|
415
|
+
if (node.type === types.AST_NODE_TYPES.Property) {
|
|
416
|
+
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
417
|
+
expressions.push(...chunk);
|
|
418
|
+
}
|
|
419
|
+
if (node.type === types.AST_NODE_TYPES.SpreadElement) {
|
|
420
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
421
|
+
expressions.push(...chunk);
|
|
422
|
+
}
|
|
423
|
+
if (node.type === types.AST_NODE_TYPES.MemberExpression) {
|
|
424
|
+
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
425
|
+
expressions.push(...chunk);
|
|
426
|
+
}
|
|
427
|
+
if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
|
|
428
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
429
|
+
expressions.push(...chunk);
|
|
430
|
+
}
|
|
431
|
+
if (node.type === types.AST_NODE_TYPES.ChainExpression) {
|
|
432
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
433
|
+
expressions.push(...chunk);
|
|
434
|
+
}
|
|
435
|
+
if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
|
|
436
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
437
|
+
expressions.push(...chunk);
|
|
438
|
+
}
|
|
439
|
+
if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
|
|
440
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
441
|
+
expressions.push(...chunk);
|
|
442
|
+
}
|
|
443
|
+
if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
444
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
445
|
+
expressions.push(...chunk);
|
|
446
|
+
}
|
|
447
|
+
return expressions;
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression);
|
|
451
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression);
|
|
435
452
|
function isMultiLine(node) {
|
|
436
453
|
return node.loc.start.line !== node.loc.end.line;
|
|
437
454
|
}
|
|
@@ -535,28 +552,11 @@ function getPropertyName(node) {
|
|
|
535
552
|
}
|
|
536
553
|
return eff._;
|
|
537
554
|
}
|
|
538
|
-
function getNestedReturnStatements(node) {
|
|
539
|
-
const statements = [];
|
|
540
|
-
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
541
|
-
typescriptEstree.simpleTraverse(node, {
|
|
542
|
-
enter(node2) {
|
|
543
|
-
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
const parentFunction = findParentNode(node2, isFunction);
|
|
547
|
-
if (parentFunction !== boundaryNode) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
statements.push(node2);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
return statements;
|
|
554
|
-
}
|
|
555
555
|
function getLiteralValueType(input) {
|
|
556
556
|
if (input === null) return "null";
|
|
557
557
|
return typeof input;
|
|
558
558
|
}
|
|
559
|
-
function
|
|
559
|
+
function toDelimiterCaseType(node, delimiter = " ") {
|
|
560
560
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
561
561
|
if ("regex" in node) {
|
|
562
562
|
return "RegExp literal";
|
|
@@ -564,19 +564,17 @@ function toReadableNodeType(node) {
|
|
|
564
564
|
return `${getLiteralValueType(node.value)} literal`;
|
|
565
565
|
}
|
|
566
566
|
if (isJSX(node)) {
|
|
567
|
-
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""),
|
|
567
|
+
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`;
|
|
568
568
|
}
|
|
569
|
-
return stringTs.toLowerCase(stringTs.delimiterCase(node.type,
|
|
569
|
+
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter));
|
|
570
570
|
}
|
|
571
571
|
function toString(node, getText) {
|
|
572
572
|
switch (node.type) {
|
|
573
|
-
case types.AST_NODE_TYPES.CallExpression:
|
|
574
|
-
return toString(node.callee, getText);
|
|
575
573
|
case types.AST_NODE_TYPES.Identifier:
|
|
574
|
+
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
576
575
|
case types.AST_NODE_TYPES.PrivateIdentifier:
|
|
577
576
|
return node.name;
|
|
578
|
-
case types.AST_NODE_TYPES.
|
|
579
|
-
return `<${node.name}>`;
|
|
577
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
580
578
|
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
581
579
|
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
582
580
|
case types.AST_NODE_TYPES.JSXNamespacedName:
|
|
@@ -585,8 +583,8 @@ function toString(node, getText) {
|
|
|
585
583
|
return node.value;
|
|
586
584
|
case types.AST_NODE_TYPES.Literal:
|
|
587
585
|
return node.raw;
|
|
588
|
-
case types.AST_NODE_TYPES.
|
|
589
|
-
return
|
|
586
|
+
case types.AST_NODE_TYPES.CallExpression:
|
|
587
|
+
return toString(node.callee, getText);
|
|
590
588
|
default:
|
|
591
589
|
return getText(node);
|
|
592
590
|
}
|
|
@@ -594,8 +592,8 @@ function toString(node, getText) {
|
|
|
594
592
|
|
|
595
593
|
exports.findParentNode = findParentNode;
|
|
596
594
|
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
|
|
597
|
-
exports.
|
|
598
|
-
exports.
|
|
595
|
+
exports.getClassId = getClassId;
|
|
596
|
+
exports.getFunctionId = getFunctionId;
|
|
599
597
|
exports.getFunctionInitPath = getFunctionInitPath;
|
|
600
598
|
exports.getJSExpression = getJSExpression;
|
|
601
599
|
exports.getNestedCallExpressions = getNestedCallExpressions;
|
|
@@ -636,5 +634,5 @@ exports.isThisExpression = isThisExpression;
|
|
|
636
634
|
exports.isTypeAssertionExpression = isTypeAssertionExpression;
|
|
637
635
|
exports.isTypeDeclaration = isTypeDeclaration;
|
|
638
636
|
exports.isTypeExpression = isTypeExpression;
|
|
639
|
-
exports.
|
|
637
|
+
exports.toDelimiterCaseType = toDelimiterCaseType;
|
|
640
638
|
exports.toString = toString;
|
package/dist/index.mjs
CHANGED
|
@@ -38,7 +38,7 @@ var indexParamPosition = /* @__PURE__ */ new Map([
|
|
|
38
38
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
39
39
|
return indexParamPosition.get(methodName) ?? -1;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function getClassId(node) {
|
|
42
42
|
if (node.id != null) return node.id;
|
|
43
43
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
44
44
|
return node.parent.id;
|
|
@@ -199,92 +199,7 @@ function getJSExpression(node) {
|
|
|
199
199
|
function isThisExpression(node) {
|
|
200
200
|
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
const isNodeOfType = is(type);
|
|
204
|
-
return function(node) {
|
|
205
|
-
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
206
|
-
const expressions = [];
|
|
207
|
-
if (isNodeOfType(node)) {
|
|
208
|
-
expressions.push(node);
|
|
209
|
-
}
|
|
210
|
-
if ("arguments" in node) {
|
|
211
|
-
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
212
|
-
expressions.push(...chunk);
|
|
213
|
-
}
|
|
214
|
-
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
215
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
216
|
-
expressions.push(...chunk);
|
|
217
|
-
}
|
|
218
|
-
if ("left" in node) {
|
|
219
|
-
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
220
|
-
expressions.push(...chunk);
|
|
221
|
-
}
|
|
222
|
-
if ("right" in node) {
|
|
223
|
-
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
224
|
-
expressions.push(...chunk);
|
|
225
|
-
}
|
|
226
|
-
if ("test" in node && node.test != null) {
|
|
227
|
-
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
228
|
-
expressions.push(...chunk);
|
|
229
|
-
}
|
|
230
|
-
if ("consequent" in node) {
|
|
231
|
-
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
232
|
-
expressions.push(...chunk);
|
|
233
|
-
}
|
|
234
|
-
if ("alternate" in node && node.alternate != null) {
|
|
235
|
-
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
236
|
-
expressions.push(...chunk);
|
|
237
|
-
}
|
|
238
|
-
if ("elements" in node) {
|
|
239
|
-
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
240
|
-
expressions.push(...chunk);
|
|
241
|
-
}
|
|
242
|
-
if ("properties" in node) {
|
|
243
|
-
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
244
|
-
expressions.push(...chunk);
|
|
245
|
-
}
|
|
246
|
-
if ("expressions" in node) {
|
|
247
|
-
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
248
|
-
expressions.push(...chunk);
|
|
249
|
-
}
|
|
250
|
-
if (node.type === AST_NODE_TYPES.Property) {
|
|
251
|
-
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
252
|
-
expressions.push(...chunk);
|
|
253
|
-
}
|
|
254
|
-
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
255
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
256
|
-
expressions.push(...chunk);
|
|
257
|
-
}
|
|
258
|
-
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
259
|
-
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
260
|
-
expressions.push(...chunk);
|
|
261
|
-
}
|
|
262
|
-
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
263
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
264
|
-
expressions.push(...chunk);
|
|
265
|
-
}
|
|
266
|
-
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
267
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
268
|
-
expressions.push(...chunk);
|
|
269
|
-
}
|
|
270
|
-
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
271
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
272
|
-
expressions.push(...chunk);
|
|
273
|
-
}
|
|
274
|
-
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
275
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
276
|
-
expressions.push(...chunk);
|
|
277
|
-
}
|
|
278
|
-
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
279
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
280
|
-
expressions.push(...chunk);
|
|
281
|
-
}
|
|
282
|
-
return expressions;
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
286
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
287
|
-
function getFunctionIdentifier(node) {
|
|
202
|
+
function getFunctionId(node) {
|
|
288
203
|
switch (true) {
|
|
289
204
|
// function MaybeComponent() {}
|
|
290
205
|
case ("id" in node && node.id != null):
|
|
@@ -313,7 +228,7 @@ function getFunctionIdentifier(node) {
|
|
|
313
228
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
314
229
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
315
230
|
case isTypeAssertionExpression(node.parent):
|
|
316
|
-
return
|
|
231
|
+
return getFunctionId(node.parent);
|
|
317
232
|
}
|
|
318
233
|
return _;
|
|
319
234
|
}
|
|
@@ -430,6 +345,108 @@ function getNestedIdentifiers(node) {
|
|
|
430
345
|
}
|
|
431
346
|
return identifiers;
|
|
432
347
|
}
|
|
348
|
+
function getNestedReturnStatements(node) {
|
|
349
|
+
const statements = [];
|
|
350
|
+
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
351
|
+
simpleTraverse(node, {
|
|
352
|
+
enter(node2) {
|
|
353
|
+
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
357
|
+
if (parentFunction !== boundaryNode) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
statements.push(node2);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return statements;
|
|
364
|
+
}
|
|
365
|
+
function getNestedExpressionsOfType(type) {
|
|
366
|
+
const isNodeOfType = is(type);
|
|
367
|
+
return function(node) {
|
|
368
|
+
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
369
|
+
const expressions = [];
|
|
370
|
+
if (isNodeOfType(node)) {
|
|
371
|
+
expressions.push(node);
|
|
372
|
+
}
|
|
373
|
+
if ("arguments" in node) {
|
|
374
|
+
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
375
|
+
expressions.push(...chunk);
|
|
376
|
+
}
|
|
377
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
378
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
379
|
+
expressions.push(...chunk);
|
|
380
|
+
}
|
|
381
|
+
if ("left" in node) {
|
|
382
|
+
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
383
|
+
expressions.push(...chunk);
|
|
384
|
+
}
|
|
385
|
+
if ("right" in node) {
|
|
386
|
+
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
387
|
+
expressions.push(...chunk);
|
|
388
|
+
}
|
|
389
|
+
if ("test" in node && node.test != null) {
|
|
390
|
+
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
391
|
+
expressions.push(...chunk);
|
|
392
|
+
}
|
|
393
|
+
if ("consequent" in node) {
|
|
394
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
395
|
+
expressions.push(...chunk);
|
|
396
|
+
}
|
|
397
|
+
if ("alternate" in node && node.alternate != null) {
|
|
398
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
399
|
+
expressions.push(...chunk);
|
|
400
|
+
}
|
|
401
|
+
if ("elements" in node) {
|
|
402
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
403
|
+
expressions.push(...chunk);
|
|
404
|
+
}
|
|
405
|
+
if ("properties" in node) {
|
|
406
|
+
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
407
|
+
expressions.push(...chunk);
|
|
408
|
+
}
|
|
409
|
+
if ("expressions" in node) {
|
|
410
|
+
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
411
|
+
expressions.push(...chunk);
|
|
412
|
+
}
|
|
413
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
414
|
+
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
415
|
+
expressions.push(...chunk);
|
|
416
|
+
}
|
|
417
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
418
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
419
|
+
expressions.push(...chunk);
|
|
420
|
+
}
|
|
421
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
422
|
+
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
423
|
+
expressions.push(...chunk);
|
|
424
|
+
}
|
|
425
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
426
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
427
|
+
expressions.push(...chunk);
|
|
428
|
+
}
|
|
429
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
430
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
431
|
+
expressions.push(...chunk);
|
|
432
|
+
}
|
|
433
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
434
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
435
|
+
expressions.push(...chunk);
|
|
436
|
+
}
|
|
437
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
438
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
439
|
+
expressions.push(...chunk);
|
|
440
|
+
}
|
|
441
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
442
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
443
|
+
expressions.push(...chunk);
|
|
444
|
+
}
|
|
445
|
+
return expressions;
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
449
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
433
450
|
function isMultiLine(node) {
|
|
434
451
|
return node.loc.start.line !== node.loc.end.line;
|
|
435
452
|
}
|
|
@@ -533,28 +550,11 @@ function getPropertyName(node) {
|
|
|
533
550
|
}
|
|
534
551
|
return _;
|
|
535
552
|
}
|
|
536
|
-
function getNestedReturnStatements(node) {
|
|
537
|
-
const statements = [];
|
|
538
|
-
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
539
|
-
simpleTraverse(node, {
|
|
540
|
-
enter(node2) {
|
|
541
|
-
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
const parentFunction = findParentNode(node2, isFunction);
|
|
545
|
-
if (parentFunction !== boundaryNode) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
statements.push(node2);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
return statements;
|
|
552
|
-
}
|
|
553
553
|
function getLiteralValueType(input) {
|
|
554
554
|
if (input === null) return "null";
|
|
555
555
|
return typeof input;
|
|
556
556
|
}
|
|
557
|
-
function
|
|
557
|
+
function toDelimiterCaseType(node, delimiter = " ") {
|
|
558
558
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
559
559
|
if ("regex" in node) {
|
|
560
560
|
return "RegExp literal";
|
|
@@ -562,19 +562,17 @@ function toReadableNodeType(node) {
|
|
|
562
562
|
return `${getLiteralValueType(node.value)} literal`;
|
|
563
563
|
}
|
|
564
564
|
if (isJSX(node)) {
|
|
565
|
-
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""),
|
|
565
|
+
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
566
566
|
}
|
|
567
|
-
return toLowerCase(delimiterCase(node.type,
|
|
567
|
+
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
568
568
|
}
|
|
569
569
|
function toString(node, getText) {
|
|
570
570
|
switch (node.type) {
|
|
571
|
-
case AST_NODE_TYPES.CallExpression:
|
|
572
|
-
return toString(node.callee, getText);
|
|
573
571
|
case AST_NODE_TYPES.Identifier:
|
|
572
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
574
573
|
case AST_NODE_TYPES.PrivateIdentifier:
|
|
575
574
|
return node.name;
|
|
576
|
-
case AST_NODE_TYPES.
|
|
577
|
-
return `<${node.name}>`;
|
|
575
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
578
576
|
case AST_NODE_TYPES.JSXMemberExpression:
|
|
579
577
|
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
580
578
|
case AST_NODE_TYPES.JSXNamespacedName:
|
|
@@ -583,11 +581,11 @@ function toString(node, getText) {
|
|
|
583
581
|
return node.value;
|
|
584
582
|
case AST_NODE_TYPES.Literal:
|
|
585
583
|
return node.raw;
|
|
586
|
-
case AST_NODE_TYPES.
|
|
587
|
-
return
|
|
584
|
+
case AST_NODE_TYPES.CallExpression:
|
|
585
|
+
return toString(node.callee, getText);
|
|
588
586
|
default:
|
|
589
587
|
return getText(node);
|
|
590
588
|
}
|
|
591
589
|
}
|
|
592
590
|
|
|
593
|
-
export { findParentNode, getArrayMethodCallbackIndexParamPosition,
|
|
591
|
+
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.48.2-beta.
|
|
3
|
+
"version": "1.48.2-beta.2",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^8.30.1",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.7.0",
|
|
43
|
-
"@eslint-react/eff": "1.48.2-beta.
|
|
43
|
+
"@eslint-react/eff": "1.48.2-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.4.0",
|