@eslint-react/ast 1.24.0-beta.0 → 1.24.0-beta.3
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 +12 -28
- package/dist/index.d.ts +12 -28
- package/dist/index.js +21 -47
- package/dist/index.mjs +23 -47
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -5,35 +5,19 @@ 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;
|
|
@@ -144,7 +128,7 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
128
|
TSESTreeFunction
|
|
145
129
|
];
|
|
146
130
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
-
declare function hasCallInFunctionInitPath(callName: string
|
|
131
|
+
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
148
132
|
|
|
149
133
|
/**
|
|
150
134
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
@@ -2445,4 +2429,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
2445
2429
|
|
|
2446
2430
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2447
2431
|
|
|
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,
|
|
2432
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, 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, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, unwrapTypeExpression };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,35 +5,19 @@ 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;
|
|
@@ -144,7 +128,7 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
128
|
TSESTreeFunction
|
|
145
129
|
];
|
|
146
130
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
-
declare function hasCallInFunctionInitPath(callName: string
|
|
131
|
+
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
148
132
|
|
|
149
133
|
/**
|
|
150
134
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
@@ -2445,4 +2429,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
|
2445
2429
|
|
|
2446
2430
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2447
2431
|
|
|
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,
|
|
2432
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, 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, 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
|
}
|
|
@@ -331,7 +307,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
331
307
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
332
308
|
expressions.push(...chunk);
|
|
333
309
|
}
|
|
334
|
-
if ("test" in node && node.test) {
|
|
310
|
+
if ("test" in node && node.test != null) {
|
|
335
311
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
336
312
|
expressions.push(...chunk);
|
|
337
313
|
}
|
|
@@ -339,7 +315,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
339
315
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
340
316
|
expressions.push(...chunk);
|
|
341
317
|
}
|
|
342
|
-
if ("alternate" in node && node.alternate) {
|
|
318
|
+
if ("alternate" in node && node.alternate != null) {
|
|
343
319
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
344
320
|
expressions.push(...chunk);
|
|
345
321
|
}
|
|
@@ -459,13 +435,13 @@ function getNestedIdentifiers(node) {
|
|
|
459
435
|
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
460
436
|
function getNestedReturnStatements(node) {
|
|
461
437
|
const returnStatements = [];
|
|
462
|
-
const functionNode = isFunction(node) ? node :
|
|
438
|
+
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
463
439
|
typescriptEstree.simpleTraverse(node, {
|
|
464
440
|
enter(node2) {
|
|
465
441
|
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
466
442
|
return;
|
|
467
443
|
}
|
|
468
|
-
const parentFunction =
|
|
444
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
469
445
|
if (parentFunction !== functionNode) {
|
|
470
446
|
return;
|
|
471
447
|
}
|
|
@@ -627,8 +603,6 @@ function unwrapTypeExpression(node) {
|
|
|
627
603
|
}
|
|
628
604
|
|
|
629
605
|
exports.findParentNode = findParentNode;
|
|
630
|
-
exports.findParentNodeGuard = findParentNodeGuard;
|
|
631
|
-
exports.findParentNodeStop = findParentNodeStop;
|
|
632
606
|
exports.getClassIdentifier = getClassIdentifier;
|
|
633
607
|
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
634
608
|
exports.getFunctionInitPath = getFunctionInitPath;
|
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
|
}
|
|
@@ -329,7 +305,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
329
305
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
330
306
|
expressions.push(...chunk);
|
|
331
307
|
}
|
|
332
|
-
if ("test" in node && node.test) {
|
|
308
|
+
if ("test" in node && node.test != null) {
|
|
333
309
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
334
310
|
expressions.push(...chunk);
|
|
335
311
|
}
|
|
@@ -337,7 +313,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
337
313
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
338
314
|
expressions.push(...chunk);
|
|
339
315
|
}
|
|
340
|
-
if ("alternate" in node && node.alternate) {
|
|
316
|
+
if ("alternate" in node && node.alternate != null) {
|
|
341
317
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
342
318
|
expressions.push(...chunk);
|
|
343
319
|
}
|
|
@@ -457,13 +433,13 @@ function getNestedIdentifiers(node) {
|
|
|
457
433
|
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
458
434
|
function getNestedReturnStatements(node) {
|
|
459
435
|
const returnStatements = [];
|
|
460
|
-
const functionNode = isFunction(node) ? node :
|
|
436
|
+
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
461
437
|
simpleTraverse(node, {
|
|
462
438
|
enter(node2) {
|
|
463
439
|
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
464
440
|
return;
|
|
465
441
|
}
|
|
466
|
-
const parentFunction =
|
|
442
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
467
443
|
if (parentFunction !== functionNode) {
|
|
468
444
|
return;
|
|
469
445
|
}
|
|
@@ -624,4 +600,4 @@ function unwrapTypeExpression(node) {
|
|
|
624
600
|
return node;
|
|
625
601
|
}
|
|
626
602
|
|
|
627
|
-
export { findParentNode,
|
|
603
|
+
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, 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-beta.
|
|
3
|
+
"version": "1.24.0-beta.3",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@typescript-eslint/utils": "^8.19.1",
|
|
39
39
|
"string-ts": "^2.2.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/
|
|
42
|
-
"@eslint-react/
|
|
41
|
+
"@eslint-react/types": "1.24.0-beta.3",
|
|
42
|
+
"@eslint-react/eff": "1.24.0-beta.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|