@eslint-react/ast 1.24.0-next.1 → 1.24.0-next.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 CHANGED
@@ -5,26 +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 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;
@@ -135,7 +128,7 @@ readonly [TSESTree.FunctionDeclaration]
135
128
  TSESTreeFunction
136
129
  ];
137
130
  declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
138
- declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
131
+ declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
139
132
 
140
133
  /**
141
134
  * Gets class identifier from ClassDeclaration or ClassExpression
@@ -2436,4 +2429,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
2436
2429
 
2437
2430
  declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
2438
2431
 
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 };
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,26 +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 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;
@@ -135,7 +128,7 @@ readonly [TSESTree.FunctionDeclaration]
135
128
  TSESTreeFunction
136
129
  ];
137
130
  declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
138
- declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
131
+ declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
139
132
 
140
133
  /**
141
134
  * Gets class identifier from ClassDeclaration or ClassExpression
@@ -2436,4 +2429,4 @@ type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
2436
2429
 
2437
2430
  declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
2438
2431
 
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 };
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,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;
@@ -448,13 +435,13 @@ function getNestedIdentifiers(node) {
448
435
  var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
449
436
  function getNestedReturnStatements(node) {
450
437
  const returnStatements = [];
451
- const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
438
+ const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
452
439
  typescriptEstree.simpleTraverse(node, {
453
440
  enter(node2) {
454
441
  if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
455
442
  return;
456
443
  }
457
- const parentFunction = findParentNodeGuard(node2, isFunction);
444
+ const parentFunction = findParentNode(node2, isFunction);
458
445
  if (parentFunction !== functionNode) {
459
446
  return;
460
447
  }
@@ -616,7 +603,6 @@ function unwrapTypeExpression(node) {
616
603
  }
617
604
 
618
605
  exports.findParentNode = findParentNode;
619
- exports.findParentNodeGuard = findParentNodeGuard;
620
606
  exports.getClassIdentifier = getClassIdentifier;
621
607
  exports.getFunctionIdentifier = getFunctionIdentifier;
622
608
  exports.getFunctionInitPath = getFunctionInitPath;
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;
@@ -446,13 +433,13 @@ function getNestedIdentifiers(node) {
446
433
  var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
447
434
  function getNestedReturnStatements(node) {
448
435
  const returnStatements = [];
449
- const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
436
+ const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
450
437
  simpleTraverse(node, {
451
438
  enter(node2) {
452
439
  if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
453
440
  return;
454
441
  }
455
- const parentFunction = findParentNodeGuard(node2, isFunction);
442
+ const parentFunction = findParentNode(node2, isFunction);
456
443
  if (parentFunction !== functionNode) {
457
444
  return;
458
445
  }
@@ -613,4 +600,4 @@ function unwrapTypeExpression(node) {
613
600
  return node;
614
601
  }
615
602
 
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 };
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-next.1",
3
+ "version": "1.24.0-next.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/eff": "1.24.0-next.1",
42
- "@eslint-react/types": "1.24.0-next.1"
41
+ "@eslint-react/eff": "1.24.0-next.3",
42
+ "@eslint-react/types": "1.24.0-next.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.3.5",