@eslint-react/ast 1.24.0-next.1 → 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 CHANGED
@@ -5,30 +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 first parent node that satisfies the test
9
- * @param node The node to start searching
10
- * @param test The test function
11
- * @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
12
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
-
13
+ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (n: TSESTree.Node) => n is A): A | _;
18
14
  /**
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
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
23
19
  */
24
- declare const findParentNodeGuard: {
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
- };
20
+ declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
28
21
 
29
22
  type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
30
23
  type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
31
24
  type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
25
+ type TSESTreeMethodOrProperty = TSESTree$1.PropertyDefinition | TSESTree$1.MethodDefinition;
32
26
  type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
33
27
  type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
34
28
  type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
@@ -135,7 +129,7 @@ readonly [TSESTree.FunctionDeclaration]
135
129
  TSESTreeFunction
136
130
  ];
137
131
  declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
138
- declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
132
+ declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
139
133
 
140
134
  /**
141
135
  * Gets class identifier from ClassDeclaration or ClassExpression
@@ -2349,6 +2343,7 @@ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes
2349
2343
  declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression;
2350
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;
2351
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;
2352
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;
2353
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;
2354
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;
@@ -2436,4 +2431,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
2436
2431
 
2437
2432
  declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
2438
2433
 
2439
- export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode, findParentNodeGuard, 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 };
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,30 +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 first parent node that satisfies the test
9
- * @param node The node to start searching
10
- * @param test The test function
11
- * @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
12
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
-
13
+ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, predicate: (n: TSESTree.Node) => n is A): A | _;
18
14
  /**
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
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
23
19
  */
24
- declare const findParentNodeGuard: {
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
- };
20
+ declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
28
21
 
29
22
  type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
30
23
  type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
31
24
  type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
25
+ type TSESTreeMethodOrProperty = TSESTree$1.PropertyDefinition | TSESTree$1.MethodDefinition;
32
26
  type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TSESTree$1.ForOfStatement | TSESTree$1.ForStatement | TSESTree$1.WhileStatement;
33
27
  type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
34
28
  type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
@@ -135,7 +129,7 @@ readonly [TSESTree.FunctionDeclaration]
135
129
  TSESTreeFunction
136
130
  ];
137
131
  declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
138
- declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
132
+ declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
139
133
 
140
134
  /**
141
135
  * Gets class identifier from ClassDeclaration or ClassExpression
@@ -2349,6 +2343,7 @@ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes
2349
2343
  declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclarationWithName | TSESTree$1.FunctionDeclarationWithOptionalName | TSESTree$1.FunctionExpression;
2350
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;
2351
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;
2352
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;
2353
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;
2354
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;
@@ -2436,4 +2431,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
2436
2431
 
2437
2432
  declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
2438
2433
 
2439
- export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, findParentNode, findParentNodeGuard, 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 };
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,7 +8,7 @@ var tsPattern = require('ts-pattern');
8
8
  var stringTs = require('string-ts');
9
9
 
10
10
  // src/find-parent-node.ts
11
- var findParentNode = eff.dual(2, (node, test) => {
11
+ function findParentNode(node, test) {
12
12
  if (node == null) return eff._;
13
13
  let parent = node.parent;
14
14
  while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
@@ -18,18 +18,7 @@ var findParentNode = eff.dual(2, (node, test) => {
18
18
  parent = parent.parent;
19
19
  }
20
20
  return eff._;
21
- });
22
- var findParentNodeGuard = eff.dual(2, (node, predicate) => {
23
- if (node == null) return eff._;
24
- let parent = node.parent;
25
- while (parent != null) {
26
- if (predicate(parent)) {
27
- return parent;
28
- }
29
- parent = parent.parent;
30
- }
31
- return eff._;
32
- });
21
+ }
33
22
  function getFunctionInitPath(node) {
34
23
  const { parent } = node;
35
24
  if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
@@ -86,22 +75,20 @@ function getFunctionInitPath(node) {
86
75
  }
87
76
  return eff._;
88
77
  }
89
- function hasCallInFunctionInitPath(callName) {
90
- return (initPath) => {
91
- return initPath.some((n) => {
92
- if (n.type !== types.AST_NODE_TYPES.CallExpression) {
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:
93
89
  return false;
94
- }
95
- switch (n.callee.type) {
96
- case types.AST_NODE_TYPES.Identifier:
97
- return n.callee.name === callName;
98
- case types.AST_NODE_TYPES.MemberExpression:
99
- return "name" in n.callee.property && n.callee.property.name === callName;
100
- default:
101
- return false;
102
- }
103
- });
104
- };
90
+ }
91
+ });
105
92
  }
106
93
  function getClassIdentifier(node) {
107
94
  if (node.id != null) return node.id;
@@ -129,6 +116,10 @@ var isFunctionType = isOneOf([
129
116
  types.AST_NODE_TYPES.TSMethodSignature
130
117
  ]);
131
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
+ ]);
132
123
  var isLoop = isOneOf([
133
124
  types.AST_NODE_TYPES.DoWhileStatement,
134
125
  types.AST_NODE_TYPES.ForInStatement,
@@ -448,13 +439,13 @@ function getNestedIdentifiers(node) {
448
439
  var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
449
440
  function getNestedReturnStatements(node) {
450
441
  const returnStatements = [];
451
- const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
442
+ const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
452
443
  typescriptEstree.simpleTraverse(node, {
453
444
  enter(node2) {
454
445
  if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
455
446
  return;
456
447
  }
457
- const parentFunction = findParentNodeGuard(node2, isFunction);
448
+ const parentFunction = findParentNode(node2, isFunction);
458
449
  if (parentFunction !== functionNode) {
459
450
  return;
460
451
  }
@@ -616,7 +607,6 @@ function unwrapTypeExpression(node) {
616
607
  }
617
608
 
618
609
  exports.findParentNode = findParentNode;
619
- exports.findParentNodeGuard = findParentNodeGuard;
620
610
  exports.getClassIdentifier = getClassIdentifier;
621
611
  exports.getFunctionIdentifier = getFunctionIdentifier;
622
612
  exports.getFunctionInitPath = getFunctionInitPath;
@@ -651,6 +641,7 @@ exports.isLeftHandSideExpression = isLeftHandSideExpression;
651
641
  exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType;
652
642
  exports.isLoop = isLoop;
653
643
  exports.isMapCallLoose = isMapCallLoose;
644
+ exports.isMethodOrProperty = isMethodOrProperty;
654
645
  exports.isMultiLine = isMultiLine;
655
646
  exports.isNodeEqual = isNodeEqual;
656
647
  exports.isOneOf = isOneOf;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { dual, _, or, returnTrue, returnFalse } from '@eslint-react/eff';
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,7 +6,7 @@ import { match } from 'ts-pattern';
6
6
  import { toLowerCase, delimiterCase, replace } from 'string-ts';
7
7
 
8
8
  // src/find-parent-node.ts
9
- var findParentNode = dual(2, (node, test) => {
9
+ function findParentNode(node, test) {
10
10
  if (node == null) return _;
11
11
  let parent = node.parent;
12
12
  while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
@@ -16,18 +16,7 @@ var findParentNode = dual(2, (node, test) => {
16
16
  parent = parent.parent;
17
17
  }
18
18
  return _;
19
- });
20
- var findParentNodeGuard = dual(2, (node, predicate) => {
21
- if (node == null) return _;
22
- let parent = node.parent;
23
- while (parent != null) {
24
- if (predicate(parent)) {
25
- return parent;
26
- }
27
- parent = parent.parent;
28
- }
29
- return _;
30
- });
19
+ }
31
20
  function getFunctionInitPath(node) {
32
21
  const { parent } = node;
33
22
  if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
@@ -84,22 +73,20 @@ function getFunctionInitPath(node) {
84
73
  }
85
74
  return _;
86
75
  }
87
- function hasCallInFunctionInitPath(callName) {
88
- return (initPath) => {
89
- return initPath.some((n) => {
90
- if (n.type !== AST_NODE_TYPES.CallExpression) {
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:
91
87
  return false;
92
- }
93
- switch (n.callee.type) {
94
- case AST_NODE_TYPES.Identifier:
95
- return n.callee.name === callName;
96
- case AST_NODE_TYPES.MemberExpression:
97
- return "name" in n.callee.property && n.callee.property.name === callName;
98
- default:
99
- return false;
100
- }
101
- });
102
- };
88
+ }
89
+ });
103
90
  }
104
91
  function getClassIdentifier(node) {
105
92
  if (node.id != null) return node.id;
@@ -127,6 +114,10 @@ var isFunctionType = isOneOf([
127
114
  AST_NODE_TYPES.TSMethodSignature
128
115
  ]);
129
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
+ ]);
130
121
  var isLoop = isOneOf([
131
122
  AST_NODE_TYPES.DoWhileStatement,
132
123
  AST_NODE_TYPES.ForInStatement,
@@ -446,13 +437,13 @@ function getNestedIdentifiers(node) {
446
437
  var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
447
438
  function getNestedReturnStatements(node) {
448
439
  const returnStatements = [];
449
- const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
440
+ const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
450
441
  simpleTraverse(node, {
451
442
  enter(node2) {
452
443
  if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
453
444
  return;
454
445
  }
455
- const parentFunction = findParentNodeGuard(node2, isFunction);
446
+ const parentFunction = findParentNode(node2, isFunction);
456
447
  if (parentFunction !== functionNode) {
457
448
  return;
458
449
  }
@@ -613,4 +604,4 @@ function unwrapTypeExpression(node) {
613
604
  return node;
614
605
  }
615
606
 
616
- export { findParentNode, findParentNodeGuard, 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 };
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.1",
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.19.1",
37
- "@typescript-eslint/typescript-estree": "^8.19.1",
38
- "@typescript-eslint/utils": "^8.19.1",
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.1",
42
- "@eslint-react/types": "1.24.0-next.1"
41
+ "@eslint-react/eff": "1.24.0-next.11"
43
42
  },
44
43
  "devDependencies": {
45
44
  "tsup": "^8.3.5",