@eslint-react/ast 1.24.0-next.0 → 1.24.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -28
- package/dist/index.d.ts +14 -28
- package/dist/index.js +26 -47
- package/dist/index.mjs +27 -47
- package/package.json +5 -6
package/dist/index.d.mts
CHANGED
|
@@ -5,39 +5,24 @@ import { SyntaxKind } from 'typescript';
|
|
|
5
5
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Find the
|
|
9
|
-
* @param node The node
|
|
10
|
-
* @param
|
|
11
|
-
* @returns The
|
|
12
|
-
*/
|
|
13
|
-
declare const findParentNode: {
|
|
14
|
-
(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
15
|
-
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) => TSESTree.Node | _;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Find the first parent node that satisfies the test
|
|
20
|
-
* @param node The node to start searching
|
|
21
|
-
* @param predicate The type guard function
|
|
22
|
-
* @returns The first parent node that satisfies the test or undefined if not found
|
|
8
|
+
* Find the parent node that satisfies the predicate function
|
|
9
|
+
* @param node The AST node
|
|
10
|
+
* @param predicate The predicate function
|
|
11
|
+
* @returns The parent node that satisfies the predicate or `undefined` if not found
|
|
23
12
|
*/
|
|
24
|
-
declare
|
|
25
|
-
<T extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (node: TSESTree.Node) => node is T): T | _;
|
|
26
|
-
<T extends TSESTree.Node>(predicate: (node: TSESTree.Node) => node is T): (node: TSESTree.Node | _) => T | _;
|
|
27
|
-
};
|
|
28
|
-
|
|
13
|
+
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (n: TSESTree.Node) => n is A): A | _;
|
|
29
14
|
/**
|
|
30
|
-
* Find the
|
|
31
|
-
* @param node The node
|
|
32
|
-
* @param
|
|
33
|
-
* @
|
|
34
|
-
* @returns The first parent node that satisfies the test or undefined if not found
|
|
15
|
+
* Find the parent node that satisfies the test function
|
|
16
|
+
* @param node The AST node
|
|
17
|
+
* @param test The test function
|
|
18
|
+
* @returns The parent node that satisfies the test or `undefined` if not found
|
|
35
19
|
*/
|
|
36
|
-
declare function
|
|
20
|
+
declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
37
21
|
|
|
38
22
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
39
23
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
40
24
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
25
|
+
type TSESTreeMethodOrProperty = TSESTree$1.PropertyDefinition | TSESTree$1.MethodDefinition;
|
|
41
26
|
type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
|
|
42
27
|
type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
43
28
|
type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
|
|
@@ -144,7 +129,7 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
129
|
TSESTreeFunction
|
|
145
130
|
];
|
|
146
131
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
-
declare function hasCallInFunctionInitPath(callName: string
|
|
132
|
+
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
148
133
|
|
|
149
134
|
/**
|
|
150
135
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
@@ -2358,6 +2343,7 @@ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes
|
|
|
2358
2343
|
declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression;
|
|
2359
2344
|
declare const isFunctionType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression | TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunctionNoDeclare | TSESTree$1.TSDeclareFunctionWithDeclare | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignatureComputedName | TSESTree$1.TSMethodSignatureNonComputedName;
|
|
2360
2345
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2346
|
+
declare const isMethodOrProperty: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.MethodDefinitionComputedName | TSESTree$1.MethodDefinitionNonComputedName | TSESTree$1.PropertyDefinitionComputedName | TSESTree$1.PropertyDefinitionNonComputedName;
|
|
2361
2347
|
declare const isLoop: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
|
|
2362
2348
|
declare const isControlFlow: (data: TSESTree$1.Node | null | undefined) => data is TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.IfStatement | TSESTree$1.SwitchStatement | TSESTree$1.WhileStatement;
|
|
2363
2349
|
declare const isConditional: (data: TSESTree$1.Node | null | undefined) => data is TSESTree$1.ConditionalExpression | TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.IfStatement | TSESTree$1.LogicalExpression | TSESTree$1.SwitchStatement | TSESTree$1.WhileStatement;
|
|
@@ -2445,4 +2431,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
2445
2431
|
|
|
2446
2432
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2447
2433
|
|
|
2448
|
-
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode,
|
|
2434
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, unwrapTypeExpression };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,39 +5,24 @@ import { SyntaxKind } from 'typescript';
|
|
|
5
5
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Find the
|
|
9
|
-
* @param node The node
|
|
10
|
-
* @param
|
|
11
|
-
* @returns The
|
|
12
|
-
*/
|
|
13
|
-
declare const findParentNode: {
|
|
14
|
-
(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
15
|
-
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) => TSESTree.Node | _;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Find the first parent node that satisfies the test
|
|
20
|
-
* @param node The node to start searching
|
|
21
|
-
* @param predicate The type guard function
|
|
22
|
-
* @returns The first parent node that satisfies the test or undefined if not found
|
|
8
|
+
* Find the parent node that satisfies the predicate function
|
|
9
|
+
* @param node The AST node
|
|
10
|
+
* @param predicate The predicate function
|
|
11
|
+
* @returns The parent node that satisfies the predicate or `undefined` if not found
|
|
23
12
|
*/
|
|
24
|
-
declare
|
|
25
|
-
<T extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (node: TSESTree.Node) => node is T): T | _;
|
|
26
|
-
<T extends TSESTree.Node>(predicate: (node: TSESTree.Node) => node is T): (node: TSESTree.Node | _) => T | _;
|
|
27
|
-
};
|
|
28
|
-
|
|
13
|
+
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (n: TSESTree.Node) => n is A): A | _;
|
|
29
14
|
/**
|
|
30
|
-
* Find the
|
|
31
|
-
* @param node The node
|
|
32
|
-
* @param
|
|
33
|
-
* @
|
|
34
|
-
* @returns The first parent node that satisfies the test or undefined if not found
|
|
15
|
+
* Find the parent node that satisfies the test function
|
|
16
|
+
* @param node The AST node
|
|
17
|
+
* @param test The test function
|
|
18
|
+
* @returns The parent node that satisfies the test or `undefined` if not found
|
|
35
19
|
*/
|
|
36
|
-
declare function
|
|
20
|
+
declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
37
21
|
|
|
38
22
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
39
23
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
40
24
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
25
|
+
type TSESTreeMethodOrProperty = TSESTree$1.PropertyDefinition | TSESTree$1.MethodDefinition;
|
|
41
26
|
type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
|
|
42
27
|
type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
43
28
|
type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
|
|
@@ -144,7 +129,7 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
129
|
TSESTreeFunction
|
|
145
130
|
];
|
|
146
131
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
-
declare function hasCallInFunctionInitPath(callName: string
|
|
132
|
+
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
148
133
|
|
|
149
134
|
/**
|
|
150
135
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
@@ -2358,6 +2343,7 @@ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes
|
|
|
2358
2343
|
declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression;
|
|
2359
2344
|
declare const isFunctionType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression | TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunctionNoDeclare | TSESTree$1.TSDeclareFunctionWithDeclare | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignatureComputedName | TSESTree$1.TSMethodSignatureNonComputedName;
|
|
2360
2345
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2346
|
+
declare const isMethodOrProperty: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.MethodDefinitionComputedName | TSESTree$1.MethodDefinitionNonComputedName | TSESTree$1.PropertyDefinitionComputedName | TSESTree$1.PropertyDefinitionNonComputedName;
|
|
2361
2347
|
declare const isLoop: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
|
|
2362
2348
|
declare const isControlFlow: (data: TSESTree$1.Node | null | undefined) => data is TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.IfStatement | TSESTree$1.SwitchStatement | TSESTree$1.WhileStatement;
|
|
2363
2349
|
declare const isConditional: (data: TSESTree$1.Node | null | undefined) => data is TSESTree$1.ConditionalExpression | TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.IfStatement | TSESTree$1.LogicalExpression | TSESTree$1.SwitchStatement | TSESTree$1.WhileStatement;
|
|
@@ -2445,4 +2431,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
2445
2431
|
|
|
2446
2432
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2447
2433
|
|
|
2448
|
-
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode,
|
|
2434
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, unwrapTypeExpression };
|
package/dist/index.js
CHANGED
|
@@ -8,38 +8,16 @@ var tsPattern = require('ts-pattern');
|
|
|
8
8
|
var stringTs = require('string-ts');
|
|
9
9
|
|
|
10
10
|
// src/find-parent-node.ts
|
|
11
|
-
|
|
12
|
-
if (node
|
|
11
|
+
function findParentNode(node, test) {
|
|
12
|
+
if (node == null) return eff._;
|
|
13
13
|
let parent = node.parent;
|
|
14
|
-
while (parent && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
14
|
+
while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
15
15
|
if (test(parent)) {
|
|
16
16
|
return parent;
|
|
17
17
|
}
|
|
18
18
|
parent = parent.parent;
|
|
19
19
|
}
|
|
20
20
|
return eff._;
|
|
21
|
-
});
|
|
22
|
-
var findParentNodeGuard = eff.dual(2, (node, predicate) => {
|
|
23
|
-
if (node === eff._) return eff._;
|
|
24
|
-
let parent = node.parent;
|
|
25
|
-
while (parent) {
|
|
26
|
-
if (predicate(parent)) {
|
|
27
|
-
return parent;
|
|
28
|
-
}
|
|
29
|
-
parent = parent.parent;
|
|
30
|
-
}
|
|
31
|
-
return eff._;
|
|
32
|
-
});
|
|
33
|
-
function findParentNodeStop(node, stopNode, predicate) {
|
|
34
|
-
if (node === eff._) return eff._;
|
|
35
|
-
let parent = node.parent;
|
|
36
|
-
while (parent && parent !== stopNode && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
37
|
-
if (predicate(parent)) {
|
|
38
|
-
return parent;
|
|
39
|
-
}
|
|
40
|
-
parent = parent.parent;
|
|
41
|
-
}
|
|
42
|
-
return eff._;
|
|
43
21
|
}
|
|
44
22
|
function getFunctionInitPath(node) {
|
|
45
23
|
const { parent } = node;
|
|
@@ -97,25 +75,23 @@ function getFunctionInitPath(node) {
|
|
|
97
75
|
}
|
|
98
76
|
return eff._;
|
|
99
77
|
}
|
|
100
|
-
function hasCallInFunctionInitPath(callName) {
|
|
101
|
-
return (
|
|
102
|
-
|
|
103
|
-
|
|
78
|
+
function hasCallInFunctionInitPath(callName, initPath) {
|
|
79
|
+
return initPath.some((n) => {
|
|
80
|
+
if (n.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
switch (n.callee.type) {
|
|
84
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
85
|
+
return n.callee.name === callName;
|
|
86
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
87
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
88
|
+
default:
|
|
104
89
|
return false;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
case types.AST_NODE_TYPES.Identifier:
|
|
108
|
-
return n.callee.name === callName;
|
|
109
|
-
case types.AST_NODE_TYPES.MemberExpression:
|
|
110
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
111
|
-
default:
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
90
|
+
}
|
|
91
|
+
});
|
|
116
92
|
}
|
|
117
93
|
function getClassIdentifier(node) {
|
|
118
|
-
if (node.id) return node.id;
|
|
94
|
+
if (node.id != null) return node.id;
|
|
119
95
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
120
96
|
return node.parent.id;
|
|
121
97
|
}
|
|
@@ -140,6 +116,10 @@ var isFunctionType = isOneOf([
|
|
|
140
116
|
types.AST_NODE_TYPES.TSMethodSignature
|
|
141
117
|
]);
|
|
142
118
|
var isClass = isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression]);
|
|
119
|
+
var isMethodOrProperty = isOneOf([
|
|
120
|
+
types.AST_NODE_TYPES.PropertyDefinition,
|
|
121
|
+
types.AST_NODE_TYPES.MethodDefinition
|
|
122
|
+
]);
|
|
143
123
|
var isLoop = isOneOf([
|
|
144
124
|
types.AST_NODE_TYPES.DoWhileStatement,
|
|
145
125
|
types.AST_NODE_TYPES.ForInStatement,
|
|
@@ -331,7 +311,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
331
311
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
332
312
|
expressions.push(...chunk);
|
|
333
313
|
}
|
|
334
|
-
if ("test" in node && node.test) {
|
|
314
|
+
if ("test" in node && node.test != null) {
|
|
335
315
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
336
316
|
expressions.push(...chunk);
|
|
337
317
|
}
|
|
@@ -339,7 +319,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
339
319
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
340
320
|
expressions.push(...chunk);
|
|
341
321
|
}
|
|
342
|
-
if ("alternate" in node && node.alternate) {
|
|
322
|
+
if ("alternate" in node && node.alternate != null) {
|
|
343
323
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
344
324
|
expressions.push(...chunk);
|
|
345
325
|
}
|
|
@@ -459,13 +439,13 @@ function getNestedIdentifiers(node) {
|
|
|
459
439
|
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
460
440
|
function getNestedReturnStatements(node) {
|
|
461
441
|
const returnStatements = [];
|
|
462
|
-
const functionNode = isFunction(node) ? node :
|
|
442
|
+
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
463
443
|
typescriptEstree.simpleTraverse(node, {
|
|
464
444
|
enter(node2) {
|
|
465
445
|
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
466
446
|
return;
|
|
467
447
|
}
|
|
468
|
-
const parentFunction =
|
|
448
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
469
449
|
if (parentFunction !== functionNode) {
|
|
470
450
|
return;
|
|
471
451
|
}
|
|
@@ -627,8 +607,6 @@ function unwrapTypeExpression(node) {
|
|
|
627
607
|
}
|
|
628
608
|
|
|
629
609
|
exports.findParentNode = findParentNode;
|
|
630
|
-
exports.findParentNodeGuard = findParentNodeGuard;
|
|
631
|
-
exports.findParentNodeStop = findParentNodeStop;
|
|
632
610
|
exports.getClassIdentifier = getClassIdentifier;
|
|
633
611
|
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
634
612
|
exports.getFunctionInitPath = getFunctionInitPath;
|
|
@@ -663,6 +641,7 @@ exports.isLeftHandSideExpression = isLeftHandSideExpression;
|
|
|
663
641
|
exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType;
|
|
664
642
|
exports.isLoop = isLoop;
|
|
665
643
|
exports.isMapCallLoose = isMapCallLoose;
|
|
644
|
+
exports.isMethodOrProperty = isMethodOrProperty;
|
|
666
645
|
exports.isMultiLine = isMultiLine;
|
|
667
646
|
exports.isNodeEqual = isNodeEqual;
|
|
668
647
|
exports.isOneOf = isOneOf;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dual, _,
|
|
1
|
+
import { or, dual, _, returnTrue, returnFalse } from '@eslint-react/eff';
|
|
2
2
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
3
3
|
import { ASTUtils } from '@typescript-eslint/utils';
|
|
4
4
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1, simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
@@ -6,38 +6,16 @@ import { match } from 'ts-pattern';
|
|
|
6
6
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
7
7
|
|
|
8
8
|
// src/find-parent-node.ts
|
|
9
|
-
|
|
10
|
-
if (node
|
|
9
|
+
function findParentNode(node, test) {
|
|
10
|
+
if (node == null) return _;
|
|
11
11
|
let parent = node.parent;
|
|
12
|
-
while (parent && parent.type !== AST_NODE_TYPES.Program) {
|
|
12
|
+
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
|
|
13
13
|
if (test(parent)) {
|
|
14
14
|
return parent;
|
|
15
15
|
}
|
|
16
16
|
parent = parent.parent;
|
|
17
17
|
}
|
|
18
18
|
return _;
|
|
19
|
-
});
|
|
20
|
-
var findParentNodeGuard = dual(2, (node, predicate) => {
|
|
21
|
-
if (node === _) return _;
|
|
22
|
-
let parent = node.parent;
|
|
23
|
-
while (parent) {
|
|
24
|
-
if (predicate(parent)) {
|
|
25
|
-
return parent;
|
|
26
|
-
}
|
|
27
|
-
parent = parent.parent;
|
|
28
|
-
}
|
|
29
|
-
return _;
|
|
30
|
-
});
|
|
31
|
-
function findParentNodeStop(node, stopNode, predicate) {
|
|
32
|
-
if (node === _) return _;
|
|
33
|
-
let parent = node.parent;
|
|
34
|
-
while (parent && parent !== stopNode && parent.type !== AST_NODE_TYPES.Program) {
|
|
35
|
-
if (predicate(parent)) {
|
|
36
|
-
return parent;
|
|
37
|
-
}
|
|
38
|
-
parent = parent.parent;
|
|
39
|
-
}
|
|
40
|
-
return _;
|
|
41
19
|
}
|
|
42
20
|
function getFunctionInitPath(node) {
|
|
43
21
|
const { parent } = node;
|
|
@@ -95,25 +73,23 @@ function getFunctionInitPath(node) {
|
|
|
95
73
|
}
|
|
96
74
|
return _;
|
|
97
75
|
}
|
|
98
|
-
function hasCallInFunctionInitPath(callName) {
|
|
99
|
-
return (
|
|
100
|
-
|
|
101
|
-
|
|
76
|
+
function hasCallInFunctionInitPath(callName, initPath) {
|
|
77
|
+
return initPath.some((n) => {
|
|
78
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
switch (n.callee.type) {
|
|
82
|
+
case AST_NODE_TYPES.Identifier:
|
|
83
|
+
return n.callee.name === callName;
|
|
84
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
85
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
86
|
+
default:
|
|
102
87
|
return false;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
case AST_NODE_TYPES.Identifier:
|
|
106
|
-
return n.callee.name === callName;
|
|
107
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
108
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
109
|
-
default:
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
114
90
|
}
|
|
115
91
|
function getClassIdentifier(node) {
|
|
116
|
-
if (node.id) return node.id;
|
|
92
|
+
if (node.id != null) return node.id;
|
|
117
93
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
118
94
|
return node.parent.id;
|
|
119
95
|
}
|
|
@@ -138,6 +114,10 @@ var isFunctionType = isOneOf([
|
|
|
138
114
|
AST_NODE_TYPES.TSMethodSignature
|
|
139
115
|
]);
|
|
140
116
|
var isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
117
|
+
var isMethodOrProperty = isOneOf([
|
|
118
|
+
AST_NODE_TYPES.PropertyDefinition,
|
|
119
|
+
AST_NODE_TYPES.MethodDefinition
|
|
120
|
+
]);
|
|
141
121
|
var isLoop = isOneOf([
|
|
142
122
|
AST_NODE_TYPES.DoWhileStatement,
|
|
143
123
|
AST_NODE_TYPES.ForInStatement,
|
|
@@ -329,7 +309,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
329
309
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
330
310
|
expressions.push(...chunk);
|
|
331
311
|
}
|
|
332
|
-
if ("test" in node && node.test) {
|
|
312
|
+
if ("test" in node && node.test != null) {
|
|
333
313
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
334
314
|
expressions.push(...chunk);
|
|
335
315
|
}
|
|
@@ -337,7 +317,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
337
317
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
338
318
|
expressions.push(...chunk);
|
|
339
319
|
}
|
|
340
|
-
if ("alternate" in node && node.alternate) {
|
|
320
|
+
if ("alternate" in node && node.alternate != null) {
|
|
341
321
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
342
322
|
expressions.push(...chunk);
|
|
343
323
|
}
|
|
@@ -457,13 +437,13 @@ function getNestedIdentifiers(node) {
|
|
|
457
437
|
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
458
438
|
function getNestedReturnStatements(node) {
|
|
459
439
|
const returnStatements = [];
|
|
460
|
-
const functionNode = isFunction(node) ? node :
|
|
440
|
+
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
461
441
|
simpleTraverse(node, {
|
|
462
442
|
enter(node2) {
|
|
463
443
|
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
464
444
|
return;
|
|
465
445
|
}
|
|
466
|
-
const parentFunction =
|
|
446
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
467
447
|
if (parentFunction !== functionNode) {
|
|
468
448
|
return;
|
|
469
449
|
}
|
|
@@ -624,4 +604,4 @@ function unwrapTypeExpression(node) {
|
|
|
624
604
|
return node;
|
|
625
605
|
}
|
|
626
606
|
|
|
627
|
-
export { findParentNode,
|
|
607
|
+
export { findParentNode, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, unwrapTypeExpression };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.11",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
"./package.json"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/types": "^8.
|
|
37
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
38
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
37
|
+
"@typescript-eslint/typescript-estree": "^8.20.0",
|
|
38
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
39
39
|
"string-ts": "^2.2.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/eff": "1.24.0-next.
|
|
42
|
-
"@eslint-react/types": "1.24.0-next.0"
|
|
41
|
+
"@eslint-react/eff": "1.24.0-next.11"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"tsup": "^8.3.5",
|