@eslint-react/ast 1.42.1 → 1.42.2-beta.0
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 +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +37 -27
- package/dist/index.mjs +36 -27
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
2
1
|
import { _ } from '@eslint-react/eff';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
3
3
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
5
5
|
|
|
6
|
-
declare function getArrayMethodIndexParamPosition(methodName: string): number;
|
|
7
|
-
declare function isArrayMapCall(node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* Find the parent node that satisfies the test function
|
|
11
8
|
* @param node The AST node
|
|
@@ -135,6 +132,8 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
135
132
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
136
133
|
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
137
134
|
|
|
135
|
+
declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
|
|
136
|
+
|
|
138
137
|
/**
|
|
139
138
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
140
139
|
* @param node The AST node to check
|
|
@@ -227,6 +226,10 @@ declare const isLeftHandSideExpressionType: (node: TSESTree$1.Node | null | unde
|
|
|
227
226
|
declare const isTypeExpression: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSAsExpression | TSESTree$1.TSInstantiationExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
228
227
|
declare const isTypeAssertionExpression: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
229
228
|
|
|
229
|
+
declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
230
|
+
|
|
231
|
+
declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
232
|
+
|
|
230
233
|
declare function isEmptyFunction(node: TSESTreeFunction): boolean;
|
|
231
234
|
|
|
232
235
|
/**
|
|
@@ -280,4 +283,4 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
280
283
|
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "string literal" | "number literal" | "bigint literal" | "boolean literal" | "symbol literal" | "undefined literal" | "object literal" | "function literal" | "null literal" | "identifier" | "member expression" | "JSX attribute" | "JSX element" | "JSX fragment" | "JSX identifier" | "JSX text" | "JSX closing element" | "JSX closing fragment" | "JSX empty expression" | "JSX expression container" | "JSX member expression" | "JSX namespaced name" | "JSX opening element" | "JSX opening fragment" | "JSX spread attribute" | "JSX spread child" | "decorator" | "program" | "super" | "accessor property" | "array expression" | "array pattern" | "function expression" | "arrow function expression" | "assignment expression" | "assignment pattern" | "await expression" | "binary expression" | "block statement" | "break statement" | "call expression" | "catch clause" | "chain expression" | "class body" | "class declaration" | "class expression" | "conditional expression" | "continue statement" | "debugger statement" | "while statement" | "do while statement" | "empty statement" | "export all declaration" | "export default declaration" | "export named declaration" | "export specifier" | "expression statement" | "for in statement" | "for of statement" | "for statement" | "function declaration" | "if statement" | "import attribute" | "import declaration" | "import default specifier" | "import expression" | "import namespace specifier" | "import specifier" | "labeled statement" | "logical expression" | "meta property" | "method definition" | "new expression" | "object expression" | "object pattern" | "private identifier" | "property definition" | "rest element" | "return statement" | "sequence expression" | "spread element" | "static block" | "switch case" | "switch statement" | "tagged template expression" | "template element" | "template literal" | "this expression" | "throw statement" | "try statement" | "unary expression" | "update expression" | "variable declaration" | "variable declarator" | "with statement" | "yield expression" | "ts abstract accessor property" | "ts abstract keyword" | "ts abstract method definition" | "ts abstract property definition" | "ts any keyword" | "ts array type" | "ts as expression" | "ts async keyword" | "ts big int keyword" | "ts boolean keyword" | "ts call signature declaration" | "ts class implements" | "ts conditional type" | "ts constructor type" | "ts construct signature declaration" | "ts declare function" | "ts declare keyword" | "ts empty body function expression" | "ts enum body" | "ts enum declaration" | "ts enum member" | "ts export assignment" | "ts export keyword" | "ts external module reference" | "ts function type" | "ts import equals declaration" | "ts import type" | "ts indexed access type" | "ts index signature" | "ts infer type" | "ts instantiation expression" | "ts interface body" | "ts interface declaration" | "ts interface heritage" | "ts intersection type" | "ts intrinsic keyword" | "ts literal type" | "ts mapped type" | "ts method signature" | "ts module block" | "ts module declaration" | "ts named tuple member" | "ts namespace export declaration" | "ts never keyword" | "ts non null expression" | "ts null keyword" | "ts number keyword" | "ts object keyword" | "ts optional type" | "ts parameter property" | "ts private keyword" | "ts property signature" | "ts protected keyword" | "ts public keyword" | "ts qualified name" | "ts readonly keyword" | "ts rest type" | "ts satisfies expression" | "ts static keyword" | "ts string keyword" | "ts symbol keyword" | "ts template literal type" | "ts this type" | "ts tuple type" | "ts type alias declaration" | "ts type annotation" | "ts type assertion" | "ts type literal" | "ts type operator" | "ts type parameter" | "ts type parameter declaration" | "ts type parameter instantiation" | "ts type predicate" | "ts type query" | "ts type reference" | "ts undefined keyword" | "ts union type" | "ts unknown keyword" | "ts void keyword";
|
|
281
284
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
282
285
|
|
|
283
|
-
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode,
|
|
286
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassIdentifier, getEcmaExpression, getFunctionIdentifier, getFunctionInitPath, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
2
1
|
import { _ } from '@eslint-react/eff';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
3
3
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
5
5
|
|
|
6
|
-
declare function getArrayMethodIndexParamPosition(methodName: string): number;
|
|
7
|
-
declare function isArrayMapCall(node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* Find the parent node that satisfies the test function
|
|
11
8
|
* @param node The AST node
|
|
@@ -135,6 +132,8 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
135
132
|
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
136
133
|
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
137
134
|
|
|
135
|
+
declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
|
|
136
|
+
|
|
138
137
|
/**
|
|
139
138
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
140
139
|
* @param node The AST node to check
|
|
@@ -227,6 +226,10 @@ declare const isLeftHandSideExpressionType: (node: TSESTree$1.Node | null | unde
|
|
|
227
226
|
declare const isTypeExpression: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSAsExpression | TSESTree$1.TSInstantiationExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
228
227
|
declare const isTypeAssertionExpression: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
|
|
229
228
|
|
|
229
|
+
declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
230
|
+
|
|
231
|
+
declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
232
|
+
|
|
230
233
|
declare function isEmptyFunction(node: TSESTreeFunction): boolean;
|
|
231
234
|
|
|
232
235
|
/**
|
|
@@ -280,4 +283,4 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
280
283
|
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "string literal" | "number literal" | "bigint literal" | "boolean literal" | "symbol literal" | "undefined literal" | "object literal" | "function literal" | "null literal" | "identifier" | "member expression" | "JSX attribute" | "JSX element" | "JSX fragment" | "JSX identifier" | "JSX text" | "JSX closing element" | "JSX closing fragment" | "JSX empty expression" | "JSX expression container" | "JSX member expression" | "JSX namespaced name" | "JSX opening element" | "JSX opening fragment" | "JSX spread attribute" | "JSX spread child" | "decorator" | "program" | "super" | "accessor property" | "array expression" | "array pattern" | "function expression" | "arrow function expression" | "assignment expression" | "assignment pattern" | "await expression" | "binary expression" | "block statement" | "break statement" | "call expression" | "catch clause" | "chain expression" | "class body" | "class declaration" | "class expression" | "conditional expression" | "continue statement" | "debugger statement" | "while statement" | "do while statement" | "empty statement" | "export all declaration" | "export default declaration" | "export named declaration" | "export specifier" | "expression statement" | "for in statement" | "for of statement" | "for statement" | "function declaration" | "if statement" | "import attribute" | "import declaration" | "import default specifier" | "import expression" | "import namespace specifier" | "import specifier" | "labeled statement" | "logical expression" | "meta property" | "method definition" | "new expression" | "object expression" | "object pattern" | "private identifier" | "property definition" | "rest element" | "return statement" | "sequence expression" | "spread element" | "static block" | "switch case" | "switch statement" | "tagged template expression" | "template element" | "template literal" | "this expression" | "throw statement" | "try statement" | "unary expression" | "update expression" | "variable declaration" | "variable declarator" | "with statement" | "yield expression" | "ts abstract accessor property" | "ts abstract keyword" | "ts abstract method definition" | "ts abstract property definition" | "ts any keyword" | "ts array type" | "ts as expression" | "ts async keyword" | "ts big int keyword" | "ts boolean keyword" | "ts call signature declaration" | "ts class implements" | "ts conditional type" | "ts constructor type" | "ts construct signature declaration" | "ts declare function" | "ts declare keyword" | "ts empty body function expression" | "ts enum body" | "ts enum declaration" | "ts enum member" | "ts export assignment" | "ts export keyword" | "ts external module reference" | "ts function type" | "ts import equals declaration" | "ts import type" | "ts indexed access type" | "ts index signature" | "ts infer type" | "ts instantiation expression" | "ts interface body" | "ts interface declaration" | "ts interface heritage" | "ts intersection type" | "ts intrinsic keyword" | "ts literal type" | "ts mapped type" | "ts method signature" | "ts module block" | "ts module declaration" | "ts named tuple member" | "ts namespace export declaration" | "ts never keyword" | "ts non null expression" | "ts null keyword" | "ts number keyword" | "ts object keyword" | "ts optional type" | "ts parameter property" | "ts private keyword" | "ts property signature" | "ts protected keyword" | "ts public keyword" | "ts qualified name" | "ts readonly keyword" | "ts rest type" | "ts satisfies expression" | "ts static keyword" | "ts string keyword" | "ts symbol keyword" | "ts template literal type" | "ts this type" | "ts tuple type" | "ts type alias declaration" | "ts type annotation" | "ts type assertion" | "ts type literal" | "ts type operator" | "ts type parameter" | "ts type parameter declaration" | "ts type parameter instantiation" | "ts type predicate" | "ts type query" | "ts type reference" | "ts undefined keyword" | "ts union type" | "ts unknown keyword" | "ts void keyword";
|
|
281
284
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
282
285
|
|
|
283
|
-
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode,
|
|
286
|
+
export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassIdentifier, getEcmaExpression, getFunctionIdentifier, getFunctionInitPath, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType };
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var types = require('@typescript-eslint/types');
|
|
4
3
|
var eff = require('@eslint-react/eff');
|
|
4
|
+
var types = require('@typescript-eslint/types');
|
|
5
5
|
var utils = require('@typescript-eslint/utils');
|
|
6
6
|
var typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
7
7
|
var stringTs = require('string-ts');
|
|
8
8
|
|
|
9
|
-
// src/
|
|
10
|
-
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
11
|
-
["every", 1],
|
|
12
|
-
["filter", 1],
|
|
13
|
-
["find", 1],
|
|
14
|
-
["findIndex", 1],
|
|
15
|
-
["findLast", 1],
|
|
16
|
-
["findLastIndex", 1],
|
|
17
|
-
["flatMap", 1],
|
|
18
|
-
["forEach", 1],
|
|
19
|
-
["map", 1],
|
|
20
|
-
["reduce", 2],
|
|
21
|
-
["reduceRight", 2],
|
|
22
|
-
["some", 1]
|
|
23
|
-
]);
|
|
24
|
-
function getArrayMethodIndexParamPosition(methodName) {
|
|
25
|
-
return indexParamPosition.get(methodName) ?? -1;
|
|
26
|
-
}
|
|
27
|
-
function isArrayMapCall(node) {
|
|
28
|
-
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
29
|
-
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
30
|
-
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
|
|
31
|
-
const { name } = node.callee.property;
|
|
32
|
-
return name === "map" || name.endsWith("Map");
|
|
33
|
-
}
|
|
9
|
+
// src/find-parent-node.ts
|
|
34
10
|
function findParentNode(node, test) {
|
|
35
11
|
if (node == null) return eff._;
|
|
36
12
|
let parent = node.parent;
|
|
@@ -78,6 +54,25 @@ function hasCallInFunctionInitPath(callName, initPath) {
|
|
|
78
54
|
}
|
|
79
55
|
});
|
|
80
56
|
}
|
|
57
|
+
|
|
58
|
+
// src/get-array-method-callback-index-param-position.ts
|
|
59
|
+
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
60
|
+
["every", 1],
|
|
61
|
+
["filter", 1],
|
|
62
|
+
["find", 1],
|
|
63
|
+
["findIndex", 1],
|
|
64
|
+
["findLast", 1],
|
|
65
|
+
["findLastIndex", 1],
|
|
66
|
+
["flatMap", 1],
|
|
67
|
+
["forEach", 1],
|
|
68
|
+
["map", 1],
|
|
69
|
+
["reduce", 2],
|
|
70
|
+
["reduceRight", 2],
|
|
71
|
+
["some", 1]
|
|
72
|
+
]);
|
|
73
|
+
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
74
|
+
return indexParamPosition.get(methodName) ?? -1;
|
|
75
|
+
}
|
|
81
76
|
function getClassIdentifier(node) {
|
|
82
77
|
if (node.id != null) return node.id;
|
|
83
78
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
@@ -466,6 +461,20 @@ function getTopLevelIdentifier(node) {
|
|
|
466
461
|
return eff._;
|
|
467
462
|
}
|
|
468
463
|
}
|
|
464
|
+
function isArrayFromCall(node, loose = true) {
|
|
465
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
466
|
+
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
467
|
+
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
|
|
468
|
+
const name = node.callee.property.name;
|
|
469
|
+
return name === "from" || loose && name.startsWith("from");
|
|
470
|
+
}
|
|
471
|
+
function isArrayMapCall(node, loose = true) {
|
|
472
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
473
|
+
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
474
|
+
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
|
|
475
|
+
const name = node.callee.property.name;
|
|
476
|
+
return name === "map" || loose && name.endsWith("Map");
|
|
477
|
+
}
|
|
469
478
|
function isEmptyFunction(node) {
|
|
470
479
|
return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
471
480
|
}
|
|
@@ -586,7 +595,7 @@ function toReadableNodeType(node) {
|
|
|
586
595
|
}
|
|
587
596
|
|
|
588
597
|
exports.findParentNode = findParentNode;
|
|
589
|
-
exports.
|
|
598
|
+
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
|
|
590
599
|
exports.getClassIdentifier = getClassIdentifier;
|
|
591
600
|
exports.getEcmaExpression = getEcmaExpression;
|
|
592
601
|
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
@@ -601,6 +610,7 @@ exports.getPropertyName = getPropertyName;
|
|
|
601
610
|
exports.getTopLevelIdentifier = getTopLevelIdentifier;
|
|
602
611
|
exports.hasCallInFunctionInitPath = hasCallInFunctionInitPath;
|
|
603
612
|
exports.is = is;
|
|
613
|
+
exports.isArrayFromCall = isArrayFromCall;
|
|
604
614
|
exports.isArrayMapCall = isArrayMapCall;
|
|
605
615
|
exports.isArrayTupleType = isArrayTupleType;
|
|
606
616
|
exports.isClass = isClass;
|
package/dist/index.mjs
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
1
|
import { or, dual, _ } from '@eslint-react/eff';
|
|
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';
|
|
5
5
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
9
|
-
["every", 1],
|
|
10
|
-
["filter", 1],
|
|
11
|
-
["find", 1],
|
|
12
|
-
["findIndex", 1],
|
|
13
|
-
["findLast", 1],
|
|
14
|
-
["findLastIndex", 1],
|
|
15
|
-
["flatMap", 1],
|
|
16
|
-
["forEach", 1],
|
|
17
|
-
["map", 1],
|
|
18
|
-
["reduce", 2],
|
|
19
|
-
["reduceRight", 2],
|
|
20
|
-
["some", 1]
|
|
21
|
-
]);
|
|
22
|
-
function getArrayMethodIndexParamPosition(methodName) {
|
|
23
|
-
return indexParamPosition.get(methodName) ?? -1;
|
|
24
|
-
}
|
|
25
|
-
function isArrayMapCall(node) {
|
|
26
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
27
|
-
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
28
|
-
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
29
|
-
const { name } = node.callee.property;
|
|
30
|
-
return name === "map" || name.endsWith("Map");
|
|
31
|
-
}
|
|
7
|
+
// src/find-parent-node.ts
|
|
32
8
|
function findParentNode(node, test) {
|
|
33
9
|
if (node == null) return _;
|
|
34
10
|
let parent = node.parent;
|
|
@@ -76,6 +52,25 @@ function hasCallInFunctionInitPath(callName, initPath) {
|
|
|
76
52
|
}
|
|
77
53
|
});
|
|
78
54
|
}
|
|
55
|
+
|
|
56
|
+
// src/get-array-method-callback-index-param-position.ts
|
|
57
|
+
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
58
|
+
["every", 1],
|
|
59
|
+
["filter", 1],
|
|
60
|
+
["find", 1],
|
|
61
|
+
["findIndex", 1],
|
|
62
|
+
["findLast", 1],
|
|
63
|
+
["findLastIndex", 1],
|
|
64
|
+
["flatMap", 1],
|
|
65
|
+
["forEach", 1],
|
|
66
|
+
["map", 1],
|
|
67
|
+
["reduce", 2],
|
|
68
|
+
["reduceRight", 2],
|
|
69
|
+
["some", 1]
|
|
70
|
+
]);
|
|
71
|
+
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
72
|
+
return indexParamPosition.get(methodName) ?? -1;
|
|
73
|
+
}
|
|
79
74
|
function getClassIdentifier(node) {
|
|
80
75
|
if (node.id != null) return node.id;
|
|
81
76
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -464,6 +459,20 @@ function getTopLevelIdentifier(node) {
|
|
|
464
459
|
return _;
|
|
465
460
|
}
|
|
466
461
|
}
|
|
462
|
+
function isArrayFromCall(node, loose = true) {
|
|
463
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
464
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
465
|
+
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
466
|
+
const name = node.callee.property.name;
|
|
467
|
+
return name === "from" || loose && name.startsWith("from");
|
|
468
|
+
}
|
|
469
|
+
function isArrayMapCall(node, loose = true) {
|
|
470
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
471
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
472
|
+
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
473
|
+
const name = node.callee.property.name;
|
|
474
|
+
return name === "map" || loose && name.endsWith("Map");
|
|
475
|
+
}
|
|
467
476
|
function isEmptyFunction(node) {
|
|
468
477
|
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
469
478
|
}
|
|
@@ -583,4 +592,4 @@ function toReadableNodeType(node) {
|
|
|
583
592
|
return toLowerCase(delimiterCase(node.type, " "));
|
|
584
593
|
}
|
|
585
594
|
|
|
586
|
-
export { findParentNode,
|
|
595
|
+
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassIdentifier, getEcmaExpression, getFunctionIdentifier, getFunctionInitPath, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.2-beta.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^8.29.1",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.7.0",
|
|
43
|
-
"@eslint-react/eff": "1.42.
|
|
43
|
+
"@eslint-react/eff": "1.42.2-beta.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.4.0",
|