@eslint-react/ast 1.23.3-next.8 → 1.24.0-beta.1
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 +18 -28
- package/dist/index.d.ts +18 -28
- package/dist/index.js +71 -75
- package/dist/index.mjs +73 -76
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,41 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ } from '@eslint-react/eff';
|
|
2
2
|
import { TSESTree, AST_NODE_TYPES as AST_NODE_TYPES$2 } from '@typescript-eslint/types';
|
|
3
3
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
4
|
import { SyntaxKind } from 'typescript';
|
|
5
5
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
|
|
6
|
-
import * as effect_Predicate from 'effect/Predicate';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Find the first parent node that satisfies the test
|
|
10
9
|
* @param node The node to start searching
|
|
11
10
|
* @param test The test function
|
|
12
|
-
* @returns The first parent node that satisfies the test
|
|
11
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
13
12
|
*/
|
|
14
13
|
declare const findParentNode: {
|
|
15
|
-
(node: TSESTree.Node, test: (node: TSESTree.Node) => boolean):
|
|
16
|
-
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) =>
|
|
14
|
+
(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
15
|
+
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) => TSESTree.Node | _;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Find the first parent node that satisfies the test
|
|
21
20
|
* @param node The node to start searching
|
|
22
21
|
* @param predicate The type guard function
|
|
23
|
-
* @returns The first parent node that satisfies the test
|
|
22
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
24
23
|
*/
|
|
25
24
|
declare const findParentNodeGuard: {
|
|
26
|
-
<T extends TSESTree.Node>(node: TSESTree.Node, predicate: (node: TSESTree.Node) => node is T):
|
|
27
|
-
<T extends TSESTree.Node>(predicate: (node: TSESTree.Node) => node is T): (node: TSESTree.Node) =>
|
|
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 | _;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
/**
|
|
31
|
-
* Find the first parent node that satisfies the test and stops at the stop node
|
|
32
|
-
* @param node The node to start searching
|
|
33
|
-
* @param stopNode The node to stop searching
|
|
34
|
-
* @param predicate The test function
|
|
35
|
-
* @returns The first parent node that satisfies the test
|
|
36
|
-
*/
|
|
37
|
-
declare function findParentNodeStop(node: TSESTree.Node, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean): O.Option<TSESTree.Node>;
|
|
38
|
-
|
|
39
29
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
40
30
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
41
31
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
@@ -144,15 +134,15 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
134
|
TSESTree.PropertyDefinition,
|
|
145
135
|
TSESTreeFunction
|
|
146
136
|
];
|
|
147
|
-
declare function getFunctionInitPath(node: TSESTreeFunction):
|
|
148
|
-
declare function hasCallInFunctionInitPath(callName: string): (initPath:
|
|
137
|
+
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
138
|
+
declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
|
|
149
139
|
|
|
150
140
|
/**
|
|
151
141
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
152
142
|
* @param node The AST node to check
|
|
153
143
|
* @returns class identifier or null
|
|
154
144
|
*/
|
|
155
|
-
declare function getClassIdentifier(node: TSESTreeClass):
|
|
145
|
+
declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
156
146
|
|
|
157
147
|
/**
|
|
158
148
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -162,11 +152,11 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree.Iden
|
|
|
162
152
|
* same AST nodes with some exceptions to better fit our use case.
|
|
163
153
|
*/
|
|
164
154
|
|
|
165
|
-
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction):
|
|
155
|
+
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
166
156
|
|
|
167
|
-
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): TSESTree.Identifier[];
|
|
157
|
+
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): readonly TSESTree.Identifier[];
|
|
168
158
|
|
|
169
|
-
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "
|
|
159
|
+
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
|
|
170
160
|
|
|
171
161
|
/**********************************************
|
|
172
162
|
* DO NOT MODIFY THIS FILE MANUALLY *
|
|
@@ -2348,7 +2338,7 @@ declare const getNestedNewExpressions: (node: Node) => NewExpression[];
|
|
|
2348
2338
|
*/
|
|
2349
2339
|
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
2350
2340
|
|
|
2351
|
-
declare function getTopLevelIdentifier(node: TSESTree.Node):
|
|
2341
|
+
declare function getTopLevelIdentifier(node: TSESTree.Node): TSESTree.Identifier | _;
|
|
2352
2342
|
|
|
2353
2343
|
declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree$1.Node | null | undefined) => node is Extract<TSESTree$1.Node, {
|
|
2354
2344
|
type: NodeType;
|
|
@@ -2360,8 +2350,8 @@ declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is
|
|
|
2360
2350
|
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;
|
|
2361
2351
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2362
2352
|
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;
|
|
2363
|
-
declare const isControlFlow:
|
|
2364
|
-
declare const isConditional:
|
|
2353
|
+
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
|
+
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;
|
|
2365
2355
|
declare const isArrayTupleType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
2366
2356
|
declare const isProperty: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.PropertyDefinitionComputedName | TSESTree$1.PropertyDefinitionNonComputedName | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignatureComputedName | TSESTree$1.TSPropertySignatureNonComputedName;
|
|
2367
2357
|
declare const isJSXElement: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXElement;
|
|
@@ -2441,9 +2431,9 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
2441
2431
|
* @param node AST node
|
|
2442
2432
|
* @returns Human readable node type
|
|
2443
2433
|
*/
|
|
2444
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "
|
|
2434
|
+
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";
|
|
2445
2435
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
2446
2436
|
|
|
2447
2437
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2448
2438
|
|
|
2449
|
-
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,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ } from '@eslint-react/eff';
|
|
2
2
|
import { TSESTree, AST_NODE_TYPES as AST_NODE_TYPES$2 } from '@typescript-eslint/types';
|
|
3
3
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
4
4
|
import { SyntaxKind } from 'typescript';
|
|
5
5
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
|
|
6
|
-
import * as effect_Predicate from 'effect/Predicate';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Find the first parent node that satisfies the test
|
|
10
9
|
* @param node The node to start searching
|
|
11
10
|
* @param test The test function
|
|
12
|
-
* @returns The first parent node that satisfies the test
|
|
11
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
13
12
|
*/
|
|
14
13
|
declare const findParentNode: {
|
|
15
|
-
(node: TSESTree.Node, test: (node: TSESTree.Node) => boolean):
|
|
16
|
-
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) =>
|
|
14
|
+
(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
15
|
+
(test: (node: TSESTree.Node) => boolean): (node: TSESTree.Node) => TSESTree.Node | _;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Find the first parent node that satisfies the test
|
|
21
20
|
* @param node The node to start searching
|
|
22
21
|
* @param predicate The type guard function
|
|
23
|
-
* @returns The first parent node that satisfies the test
|
|
22
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
24
23
|
*/
|
|
25
24
|
declare const findParentNodeGuard: {
|
|
26
|
-
<T extends TSESTree.Node>(node: TSESTree.Node, predicate: (node: TSESTree.Node) => node is T):
|
|
27
|
-
<T extends TSESTree.Node>(predicate: (node: TSESTree.Node) => node is T): (node: TSESTree.Node) =>
|
|
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 | _;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
/**
|
|
31
|
-
* Find the first parent node that satisfies the test and stops at the stop node
|
|
32
|
-
* @param node The node to start searching
|
|
33
|
-
* @param stopNode The node to stop searching
|
|
34
|
-
* @param predicate The test function
|
|
35
|
-
* @returns The first parent node that satisfies the test
|
|
36
|
-
*/
|
|
37
|
-
declare function findParentNodeStop(node: TSESTree.Node, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean): O.Option<TSESTree.Node>;
|
|
38
|
-
|
|
39
29
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
40
30
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
41
31
|
type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
|
|
@@ -144,15 +134,15 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
134
|
TSESTree.PropertyDefinition,
|
|
145
135
|
TSESTreeFunction
|
|
146
136
|
];
|
|
147
|
-
declare function getFunctionInitPath(node: TSESTreeFunction):
|
|
148
|
-
declare function hasCallInFunctionInitPath(callName: string): (initPath:
|
|
137
|
+
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
138
|
+
declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
|
|
149
139
|
|
|
150
140
|
/**
|
|
151
141
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
152
142
|
* @param node The AST node to check
|
|
153
143
|
* @returns class identifier or null
|
|
154
144
|
*/
|
|
155
|
-
declare function getClassIdentifier(node: TSESTreeClass):
|
|
145
|
+
declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
156
146
|
|
|
157
147
|
/**
|
|
158
148
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -162,11 +152,11 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree.Iden
|
|
|
162
152
|
* same AST nodes with some exceptions to better fit our use case.
|
|
163
153
|
*/
|
|
164
154
|
|
|
165
|
-
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction):
|
|
155
|
+
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
166
156
|
|
|
167
|
-
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): TSESTree.Identifier[];
|
|
157
|
+
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): readonly TSESTree.Identifier[];
|
|
168
158
|
|
|
169
|
-
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "
|
|
159
|
+
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
|
|
170
160
|
|
|
171
161
|
/**********************************************
|
|
172
162
|
* DO NOT MODIFY THIS FILE MANUALLY *
|
|
@@ -2348,7 +2338,7 @@ declare const getNestedNewExpressions: (node: Node) => NewExpression[];
|
|
|
2348
2338
|
*/
|
|
2349
2339
|
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
2350
2340
|
|
|
2351
|
-
declare function getTopLevelIdentifier(node: TSESTree.Node):
|
|
2341
|
+
declare function getTopLevelIdentifier(node: TSESTree.Node): TSESTree.Identifier | _;
|
|
2352
2342
|
|
|
2353
2343
|
declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree$1.Node | null | undefined) => node is Extract<TSESTree$1.Node, {
|
|
2354
2344
|
type: NodeType;
|
|
@@ -2360,8 +2350,8 @@ declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is
|
|
|
2360
2350
|
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;
|
|
2361
2351
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2362
2352
|
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;
|
|
2363
|
-
declare const isControlFlow:
|
|
2364
|
-
declare const isConditional:
|
|
2353
|
+
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
|
+
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;
|
|
2365
2355
|
declare const isArrayTupleType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
2366
2356
|
declare const isProperty: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.PropertyDefinitionComputedName | TSESTree$1.PropertyDefinitionNonComputedName | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignatureComputedName | TSESTree$1.TSPropertySignatureNonComputedName;
|
|
2367
2357
|
declare const isJSXElement: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXElement;
|
|
@@ -2441,9 +2431,9 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
2441
2431
|
* @param node AST node
|
|
2442
2432
|
* @returns Human readable node type
|
|
2443
2433
|
*/
|
|
2444
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "
|
|
2434
|
+
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";
|
|
2445
2435
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
2446
2436
|
|
|
2447
2437
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
|
2448
2438
|
|
|
2449
|
-
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,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -3,127 +3,112 @@
|
|
|
3
3
|
var eff = require('@eslint-react/eff');
|
|
4
4
|
var types = require('@typescript-eslint/types');
|
|
5
5
|
var utils = require('@typescript-eslint/utils');
|
|
6
|
-
var tsPattern = require('ts-pattern');
|
|
7
6
|
var typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
8
|
-
var
|
|
7
|
+
var tsPattern = require('ts-pattern');
|
|
9
8
|
var stringTs = require('string-ts');
|
|
10
9
|
|
|
11
10
|
// src/find-parent-node.ts
|
|
12
|
-
var findParentNode = eff.
|
|
11
|
+
var findParentNode = eff.dual(2, (node, test) => {
|
|
12
|
+
if (node == null) return eff._;
|
|
13
13
|
let parent = node.parent;
|
|
14
14
|
while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
15
15
|
if (test(parent)) {
|
|
16
|
-
return
|
|
16
|
+
return parent;
|
|
17
17
|
}
|
|
18
18
|
parent = parent.parent;
|
|
19
19
|
}
|
|
20
|
-
return eff.
|
|
20
|
+
return eff._;
|
|
21
21
|
});
|
|
22
|
-
var findParentNodeGuard = eff.
|
|
22
|
+
var findParentNodeGuard = eff.dual(2, (node, predicate) => {
|
|
23
|
+
if (node == null) return eff._;
|
|
23
24
|
let parent = node.parent;
|
|
24
25
|
while (parent != null) {
|
|
25
26
|
if (predicate(parent)) {
|
|
26
|
-
return
|
|
27
|
+
return parent;
|
|
27
28
|
}
|
|
28
29
|
parent = parent.parent;
|
|
29
30
|
}
|
|
30
|
-
return eff.
|
|
31
|
+
return eff._;
|
|
31
32
|
});
|
|
32
|
-
function findParentNodeStop(node, stopNode, predicate) {
|
|
33
|
-
let parent = node.parent;
|
|
34
|
-
while (parent != null && parent !== stopNode && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
35
|
-
if (predicate(parent)) {
|
|
36
|
-
return eff.O.some(parent);
|
|
37
|
-
}
|
|
38
|
-
parent = parent.parent;
|
|
39
|
-
}
|
|
40
|
-
return eff.O.none();
|
|
41
|
-
}
|
|
42
33
|
function getFunctionInitPath(node) {
|
|
43
34
|
const { parent } = node;
|
|
44
35
|
if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
|
|
45
|
-
return
|
|
36
|
+
return [node];
|
|
46
37
|
}
|
|
47
38
|
if (parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
48
|
-
return
|
|
39
|
+
return [
|
|
49
40
|
parent.parent,
|
|
50
41
|
parent,
|
|
51
42
|
node
|
|
52
|
-
]
|
|
43
|
+
];
|
|
53
44
|
}
|
|
54
45
|
if (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
55
|
-
return
|
|
46
|
+
return [
|
|
56
47
|
parent.parent.parent,
|
|
57
48
|
parent.parent,
|
|
58
49
|
parent,
|
|
59
50
|
node
|
|
60
|
-
]
|
|
51
|
+
];
|
|
61
52
|
}
|
|
62
53
|
if (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
63
|
-
return
|
|
54
|
+
return [
|
|
64
55
|
parent.parent.parent.parent,
|
|
65
56
|
parent.parent.parent,
|
|
66
57
|
parent.parent,
|
|
67
58
|
parent,
|
|
68
59
|
node
|
|
69
|
-
]
|
|
60
|
+
];
|
|
70
61
|
}
|
|
71
62
|
if (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
72
|
-
return
|
|
63
|
+
return [
|
|
73
64
|
parent.parent.parent.parent,
|
|
74
65
|
parent.parent.parent,
|
|
75
66
|
parent.parent,
|
|
76
67
|
parent,
|
|
77
68
|
node
|
|
78
|
-
]
|
|
69
|
+
];
|
|
79
70
|
}
|
|
80
71
|
if (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
|
|
81
|
-
return
|
|
72
|
+
return [
|
|
82
73
|
parent.parent.parent,
|
|
83
74
|
parent.parent,
|
|
84
75
|
parent,
|
|
85
76
|
node
|
|
86
|
-
]
|
|
77
|
+
];
|
|
87
78
|
}
|
|
88
79
|
if (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
|
|
89
|
-
return
|
|
80
|
+
return [
|
|
90
81
|
parent.parent.parent,
|
|
91
82
|
parent.parent,
|
|
92
83
|
parent,
|
|
93
84
|
node
|
|
94
|
-
]
|
|
85
|
+
];
|
|
95
86
|
}
|
|
96
|
-
return eff.
|
|
87
|
+
return eff._;
|
|
97
88
|
}
|
|
98
89
|
function hasCallInFunctionInitPath(callName) {
|
|
99
90
|
return (initPath) => {
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
})
|
|
116
|
-
);
|
|
91
|
+
return initPath.some((n) => {
|
|
92
|
+
if (n.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
93
|
+
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
|
+
});
|
|
117
104
|
};
|
|
118
105
|
}
|
|
119
106
|
function getClassIdentifier(node) {
|
|
120
|
-
if (node.id != null)
|
|
121
|
-
return eff.O.fromNullable(node.id);
|
|
122
|
-
}
|
|
107
|
+
if (node.id != null) return node.id;
|
|
123
108
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
124
|
-
return
|
|
109
|
+
return node.parent.id;
|
|
125
110
|
}
|
|
126
|
-
return eff.
|
|
111
|
+
return eff._;
|
|
127
112
|
}
|
|
128
113
|
var is = utils.ASTUtils.isNodeOfType;
|
|
129
114
|
var isOneOf = utils.ASTUtils.isNodeOfTypes;
|
|
@@ -264,34 +249,34 @@ function getFunctionIdentifier(node) {
|
|
|
264
249
|
switch (true) {
|
|
265
250
|
// function MaybeComponent() {}
|
|
266
251
|
case ("id" in node && node.id != null):
|
|
267
|
-
return
|
|
252
|
+
return node.id;
|
|
268
253
|
// const whatever = function MaybeComponent() {};
|
|
269
254
|
case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
|
|
270
|
-
return
|
|
255
|
+
return node.parent.id;
|
|
271
256
|
// MaybeComponent = () => {};
|
|
272
257
|
case (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
|
|
273
|
-
return
|
|
258
|
+
return node.parent.left;
|
|
274
259
|
// {MaybeComponent: () => {}}
|
|
275
260
|
// {MaybeComponent() {}}
|
|
276
261
|
case (node.parent.type === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
|
|
277
|
-
return
|
|
262
|
+
return node.parent.key;
|
|
278
263
|
// class {MaybeComponent = () => {}}
|
|
279
264
|
// class {MaybeComponent() {}}
|
|
280
265
|
case (isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
|
|
281
|
-
return
|
|
266
|
+
return node.parent.key;
|
|
282
267
|
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
283
268
|
//
|
|
284
269
|
// const {MaybeComponent = () => {}} = {};
|
|
285
270
|
// ({MaybeComponent = () => {}} = {});
|
|
286
271
|
case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
|
|
287
|
-
return
|
|
272
|
+
return node.parent.left;
|
|
288
273
|
// const MaybeComponent = (() => {})!;
|
|
289
274
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
290
275
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
291
276
|
case isTypeExpression(node.parent):
|
|
292
277
|
return getFunctionIdentifier(node.parent);
|
|
293
278
|
}
|
|
294
|
-
return eff.
|
|
279
|
+
return eff._;
|
|
295
280
|
}
|
|
296
281
|
function getIdentifiersFromBinaryExpression(side) {
|
|
297
282
|
if (side.type === types.AST_NODE_TYPES.Identifier) {
|
|
@@ -305,8 +290,11 @@ function getIdentifiersFromBinaryExpression(side) {
|
|
|
305
290
|
}
|
|
306
291
|
return [];
|
|
307
292
|
}
|
|
293
|
+
|
|
294
|
+
// src/get-literal-value-type.ts
|
|
308
295
|
function getLiteralValueType(input) {
|
|
309
|
-
|
|
296
|
+
if (input === null) return "null";
|
|
297
|
+
return typeof input;
|
|
310
298
|
}
|
|
311
299
|
function getNestedExpressionsOfType(type) {
|
|
312
300
|
const isNodeOfType = utils.ASTUtils.isNodeOfType(type);
|
|
@@ -460,13 +448,13 @@ function getNestedIdentifiers(node) {
|
|
|
460
448
|
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
461
449
|
function getNestedReturnStatements(node) {
|
|
462
450
|
const returnStatements = [];
|
|
463
|
-
const functionNode = isFunction(node) ? node :
|
|
451
|
+
const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
|
|
464
452
|
typescriptEstree.simpleTraverse(node, {
|
|
465
453
|
enter(node2) {
|
|
466
454
|
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
467
455
|
return;
|
|
468
456
|
}
|
|
469
|
-
const parentFunction =
|
|
457
|
+
const parentFunction = findParentNodeGuard(node2, isFunction);
|
|
470
458
|
if (parentFunction !== functionNode) {
|
|
471
459
|
return;
|
|
472
460
|
}
|
|
@@ -478,11 +466,11 @@ function getNestedReturnStatements(node) {
|
|
|
478
466
|
function getTopLevelIdentifier(node) {
|
|
479
467
|
switch (node.type) {
|
|
480
468
|
case types.AST_NODE_TYPES.Identifier:
|
|
481
|
-
return
|
|
469
|
+
return node;
|
|
482
470
|
case types.AST_NODE_TYPES.MemberExpression:
|
|
483
471
|
return getTopLevelIdentifier(node.object);
|
|
484
472
|
default:
|
|
485
|
-
return eff.
|
|
473
|
+
return eff._;
|
|
486
474
|
}
|
|
487
475
|
}
|
|
488
476
|
function isEmptyFunction(node) {
|
|
@@ -501,7 +489,7 @@ function isFunctionOfObjectMethod(node) {
|
|
|
501
489
|
return (node.type === types.AST_NODE_TYPES.FunctionExpression || node.type === types.AST_NODE_TYPES.ArrowFunctionExpression) && node.parent.type === types.AST_NODE_TYPES.Property && node.parent.parent.type === types.AST_NODE_TYPES.ObjectExpression;
|
|
502
490
|
}
|
|
503
491
|
function isKeyLiteralLike(node, property) {
|
|
504
|
-
return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, eff.
|
|
492
|
+
return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, eff.returnTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.returnTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.returnFalse);
|
|
505
493
|
}
|
|
506
494
|
function isMapCallLoose(node) {
|
|
507
495
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
@@ -521,7 +509,7 @@ function isMapCallLoose(node) {
|
|
|
521
509
|
function isMultiLine(node) {
|
|
522
510
|
return node.loc.start.line !== node.loc.end.line;
|
|
523
511
|
}
|
|
524
|
-
var isNodeEqual = eff.
|
|
512
|
+
var isNodeEqual = eff.dual(2, (a, b) => {
|
|
525
513
|
switch (true) {
|
|
526
514
|
case a === b:
|
|
527
515
|
return true;
|
|
@@ -531,17 +519,26 @@ var isNodeEqual = eff.F.dual(2, (a, b) => {
|
|
|
531
519
|
return a.value === b.value;
|
|
532
520
|
case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement):
|
|
533
521
|
return a.value.raw === b.value.raw;
|
|
534
|
-
case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral):
|
|
522
|
+
case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral): {
|
|
535
523
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
|
|
536
524
|
return false;
|
|
537
525
|
}
|
|
538
|
-
|
|
539
|
-
|
|
526
|
+
let i = a.quasis.length;
|
|
527
|
+
while (i--) {
|
|
528
|
+
if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
540
531
|
}
|
|
541
|
-
|
|
542
|
-
|
|
532
|
+
i = a.expressions.length;
|
|
533
|
+
while (i--) {
|
|
534
|
+
const exprA = a.expressions[i];
|
|
535
|
+
const exprB = b.expressions[i];
|
|
536
|
+
if (!isNodeEqual(exprA, exprB)) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
543
539
|
}
|
|
544
540
|
return true;
|
|
541
|
+
}
|
|
545
542
|
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier):
|
|
546
543
|
return a.name === b.name;
|
|
547
544
|
case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier):
|
|
@@ -567,7 +564,7 @@ function isRegExpLiteral(node) {
|
|
|
567
564
|
return node.type === types.AST_NODE_TYPES.Literal && "regex" in node;
|
|
568
565
|
}
|
|
569
566
|
function isStringLiteral(node) {
|
|
570
|
-
return node.type === types.AST_NODE_TYPES.Literal &&
|
|
567
|
+
return node.type === types.AST_NODE_TYPES.Literal && typeof node.value === "string";
|
|
571
568
|
}
|
|
572
569
|
function isThisExpression(node) {
|
|
573
570
|
if (isTypeExpression(node)) {
|
|
@@ -620,7 +617,6 @@ function unwrapTypeExpression(node) {
|
|
|
620
617
|
|
|
621
618
|
exports.findParentNode = findParentNode;
|
|
622
619
|
exports.findParentNodeGuard = findParentNodeGuard;
|
|
623
|
-
exports.findParentNodeStop = findParentNodeStop;
|
|
624
620
|
exports.getClassIdentifier = getClassIdentifier;
|
|
625
621
|
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
626
622
|
exports.getFunctionInitPath = getFunctionInitPath;
|
package/dist/index.mjs
CHANGED
|
@@ -1,127 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dual, _, or, 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
|
-
import { match, P } from 'ts-pattern';
|
|
5
4
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1, simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
6
|
-
import {
|
|
5
|
+
import { match } from 'ts-pattern';
|
|
7
6
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
8
7
|
|
|
9
8
|
// src/find-parent-node.ts
|
|
10
|
-
var findParentNode =
|
|
9
|
+
var findParentNode = dual(2, (node, test) => {
|
|
10
|
+
if (node == null) return _;
|
|
11
11
|
let parent = node.parent;
|
|
12
12
|
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
|
|
13
13
|
if (test(parent)) {
|
|
14
|
-
return
|
|
14
|
+
return parent;
|
|
15
15
|
}
|
|
16
16
|
parent = parent.parent;
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return _;
|
|
19
19
|
});
|
|
20
|
-
var findParentNodeGuard =
|
|
20
|
+
var findParentNodeGuard = dual(2, (node, predicate) => {
|
|
21
|
+
if (node == null) return _;
|
|
21
22
|
let parent = node.parent;
|
|
22
23
|
while (parent != null) {
|
|
23
24
|
if (predicate(parent)) {
|
|
24
|
-
return
|
|
25
|
+
return parent;
|
|
25
26
|
}
|
|
26
27
|
parent = parent.parent;
|
|
27
28
|
}
|
|
28
|
-
return
|
|
29
|
+
return _;
|
|
29
30
|
});
|
|
30
|
-
function findParentNodeStop(node, stopNode, predicate) {
|
|
31
|
-
let parent = node.parent;
|
|
32
|
-
while (parent != null && parent !== stopNode && parent.type !== AST_NODE_TYPES.Program) {
|
|
33
|
-
if (predicate(parent)) {
|
|
34
|
-
return O.some(parent);
|
|
35
|
-
}
|
|
36
|
-
parent = parent.parent;
|
|
37
|
-
}
|
|
38
|
-
return O.none();
|
|
39
|
-
}
|
|
40
31
|
function getFunctionInitPath(node) {
|
|
41
32
|
const { parent } = node;
|
|
42
33
|
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
43
|
-
return
|
|
34
|
+
return [node];
|
|
44
35
|
}
|
|
45
36
|
if (parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
46
|
-
return
|
|
37
|
+
return [
|
|
47
38
|
parent.parent,
|
|
48
39
|
parent,
|
|
49
40
|
node
|
|
50
|
-
]
|
|
41
|
+
];
|
|
51
42
|
}
|
|
52
43
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
53
|
-
return
|
|
44
|
+
return [
|
|
54
45
|
parent.parent.parent,
|
|
55
46
|
parent.parent,
|
|
56
47
|
parent,
|
|
57
48
|
node
|
|
58
|
-
]
|
|
49
|
+
];
|
|
59
50
|
}
|
|
60
51
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
61
|
-
return
|
|
52
|
+
return [
|
|
62
53
|
parent.parent.parent.parent,
|
|
63
54
|
parent.parent.parent,
|
|
64
55
|
parent.parent,
|
|
65
56
|
parent,
|
|
66
57
|
node
|
|
67
|
-
]
|
|
58
|
+
];
|
|
68
59
|
}
|
|
69
60
|
if (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
70
|
-
return
|
|
61
|
+
return [
|
|
71
62
|
parent.parent.parent.parent,
|
|
72
63
|
parent.parent.parent,
|
|
73
64
|
parent.parent,
|
|
74
65
|
parent,
|
|
75
66
|
node
|
|
76
|
-
]
|
|
67
|
+
];
|
|
77
68
|
}
|
|
78
69
|
if (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration) {
|
|
79
|
-
return
|
|
70
|
+
return [
|
|
80
71
|
parent.parent.parent,
|
|
81
72
|
parent.parent,
|
|
82
73
|
parent,
|
|
83
74
|
node
|
|
84
|
-
]
|
|
75
|
+
];
|
|
85
76
|
}
|
|
86
77
|
if (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration) {
|
|
87
|
-
return
|
|
78
|
+
return [
|
|
88
79
|
parent.parent.parent,
|
|
89
80
|
parent.parent,
|
|
90
81
|
parent,
|
|
91
82
|
node
|
|
92
|
-
]
|
|
83
|
+
];
|
|
93
84
|
}
|
|
94
|
-
return
|
|
85
|
+
return _;
|
|
95
86
|
}
|
|
96
87
|
function hasCallInFunctionInitPath(callName) {
|
|
97
88
|
return (initPath) => {
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
})
|
|
114
|
-
);
|
|
89
|
+
return initPath.some((n) => {
|
|
90
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
91
|
+
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
|
+
});
|
|
115
102
|
};
|
|
116
103
|
}
|
|
117
104
|
function getClassIdentifier(node) {
|
|
118
|
-
if (node.id != null)
|
|
119
|
-
return O.fromNullable(node.id);
|
|
120
|
-
}
|
|
105
|
+
if (node.id != null) return node.id;
|
|
121
106
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
122
|
-
return
|
|
107
|
+
return node.parent.id;
|
|
123
108
|
}
|
|
124
|
-
return
|
|
109
|
+
return _;
|
|
125
110
|
}
|
|
126
111
|
var is = ASTUtils.isNodeOfType;
|
|
127
112
|
var isOneOf = ASTUtils.isNodeOfTypes;
|
|
@@ -262,34 +247,34 @@ function getFunctionIdentifier(node) {
|
|
|
262
247
|
switch (true) {
|
|
263
248
|
// function MaybeComponent() {}
|
|
264
249
|
case ("id" in node && node.id != null):
|
|
265
|
-
return
|
|
250
|
+
return node.id;
|
|
266
251
|
// const whatever = function MaybeComponent() {};
|
|
267
252
|
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
268
|
-
return
|
|
253
|
+
return node.parent.id;
|
|
269
254
|
// MaybeComponent = () => {};
|
|
270
255
|
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
271
|
-
return
|
|
256
|
+
return node.parent.left;
|
|
272
257
|
// {MaybeComponent: () => {}}
|
|
273
258
|
// {MaybeComponent() {}}
|
|
274
259
|
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
275
|
-
return
|
|
260
|
+
return node.parent.key;
|
|
276
261
|
// class {MaybeComponent = () => {}}
|
|
277
262
|
// class {MaybeComponent() {}}
|
|
278
263
|
case (isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
279
|
-
return
|
|
264
|
+
return node.parent.key;
|
|
280
265
|
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
281
266
|
//
|
|
282
267
|
// const {MaybeComponent = () => {}} = {};
|
|
283
268
|
// ({MaybeComponent = () => {}} = {});
|
|
284
269
|
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
285
|
-
return
|
|
270
|
+
return node.parent.left;
|
|
286
271
|
// const MaybeComponent = (() => {})!;
|
|
287
272
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
288
273
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
289
274
|
case isTypeExpression(node.parent):
|
|
290
275
|
return getFunctionIdentifier(node.parent);
|
|
291
276
|
}
|
|
292
|
-
return
|
|
277
|
+
return _;
|
|
293
278
|
}
|
|
294
279
|
function getIdentifiersFromBinaryExpression(side) {
|
|
295
280
|
if (side.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -303,8 +288,11 @@ function getIdentifiersFromBinaryExpression(side) {
|
|
|
303
288
|
}
|
|
304
289
|
return [];
|
|
305
290
|
}
|
|
291
|
+
|
|
292
|
+
// src/get-literal-value-type.ts
|
|
306
293
|
function getLiteralValueType(input) {
|
|
307
|
-
|
|
294
|
+
if (input === null) return "null";
|
|
295
|
+
return typeof input;
|
|
308
296
|
}
|
|
309
297
|
function getNestedExpressionsOfType(type) {
|
|
310
298
|
const isNodeOfType = ASTUtils.isNodeOfType(type);
|
|
@@ -458,13 +446,13 @@ function getNestedIdentifiers(node) {
|
|
|
458
446
|
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
459
447
|
function getNestedReturnStatements(node) {
|
|
460
448
|
const returnStatements = [];
|
|
461
|
-
const functionNode = isFunction(node) ? node :
|
|
449
|
+
const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
|
|
462
450
|
simpleTraverse(node, {
|
|
463
451
|
enter(node2) {
|
|
464
452
|
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
465
453
|
return;
|
|
466
454
|
}
|
|
467
|
-
const parentFunction =
|
|
455
|
+
const parentFunction = findParentNodeGuard(node2, isFunction);
|
|
468
456
|
if (parentFunction !== functionNode) {
|
|
469
457
|
return;
|
|
470
458
|
}
|
|
@@ -476,11 +464,11 @@ function getNestedReturnStatements(node) {
|
|
|
476
464
|
function getTopLevelIdentifier(node) {
|
|
477
465
|
switch (node.type) {
|
|
478
466
|
case AST_NODE_TYPES.Identifier:
|
|
479
|
-
return
|
|
467
|
+
return node;
|
|
480
468
|
case AST_NODE_TYPES.MemberExpression:
|
|
481
469
|
return getTopLevelIdentifier(node.object);
|
|
482
470
|
default:
|
|
483
|
-
return
|
|
471
|
+
return _;
|
|
484
472
|
}
|
|
485
473
|
}
|
|
486
474
|
function isEmptyFunction(node) {
|
|
@@ -499,7 +487,7 @@ function isFunctionOfObjectMethod(node) {
|
|
|
499
487
|
return (node.type === AST_NODE_TYPES.FunctionExpression || node.type === AST_NODE_TYPES.ArrowFunctionExpression) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression;
|
|
500
488
|
}
|
|
501
489
|
function isKeyLiteralLike(node, property) {
|
|
502
|
-
return match(property).with({ type: AST_NODE_TYPES.Literal },
|
|
490
|
+
return match(property).with({ type: AST_NODE_TYPES.Literal }, returnTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, returnTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(returnFalse);
|
|
503
491
|
}
|
|
504
492
|
function isMapCallLoose(node) {
|
|
505
493
|
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
@@ -519,7 +507,7 @@ function isMapCallLoose(node) {
|
|
|
519
507
|
function isMultiLine(node) {
|
|
520
508
|
return node.loc.start.line !== node.loc.end.line;
|
|
521
509
|
}
|
|
522
|
-
var isNodeEqual =
|
|
510
|
+
var isNodeEqual = dual(2, (a, b) => {
|
|
523
511
|
switch (true) {
|
|
524
512
|
case a === b:
|
|
525
513
|
return true;
|
|
@@ -529,17 +517,26 @@ var isNodeEqual = F.dual(2, (a, b) => {
|
|
|
529
517
|
return a.value === b.value;
|
|
530
518
|
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
|
|
531
519
|
return a.value.raw === b.value.raw;
|
|
532
|
-
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral):
|
|
520
|
+
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
|
|
533
521
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
|
|
534
522
|
return false;
|
|
535
523
|
}
|
|
536
|
-
|
|
537
|
-
|
|
524
|
+
let i = a.quasis.length;
|
|
525
|
+
while (i--) {
|
|
526
|
+
if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
538
529
|
}
|
|
539
|
-
|
|
540
|
-
|
|
530
|
+
i = a.expressions.length;
|
|
531
|
+
while (i--) {
|
|
532
|
+
const exprA = a.expressions[i];
|
|
533
|
+
const exprB = b.expressions[i];
|
|
534
|
+
if (!isNodeEqual(exprA, exprB)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
541
537
|
}
|
|
542
538
|
return true;
|
|
539
|
+
}
|
|
543
540
|
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
|
|
544
541
|
return a.name === b.name;
|
|
545
542
|
case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
|
|
@@ -565,7 +562,7 @@ function isRegExpLiteral(node) {
|
|
|
565
562
|
return node.type === AST_NODE_TYPES.Literal && "regex" in node;
|
|
566
563
|
}
|
|
567
564
|
function isStringLiteral(node) {
|
|
568
|
-
return node.type === AST_NODE_TYPES.Literal &&
|
|
565
|
+
return node.type === AST_NODE_TYPES.Literal && typeof node.value === "string";
|
|
569
566
|
}
|
|
570
567
|
function isThisExpression(node) {
|
|
571
568
|
if (isTypeExpression(node)) {
|
|
@@ -616,4 +613,4 @@ function unwrapTypeExpression(node) {
|
|
|
616
613
|
return node;
|
|
617
614
|
}
|
|
618
615
|
|
|
619
|
-
export { findParentNode, findParentNodeGuard,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0-beta.1",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/Rel1cx/eslint-react/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/Rel1cx/eslint-react.git",
|
|
12
12
|
"directory": "packages/utilities/ast"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
@@ -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.
|
|
42
|
-
"@eslint-react/types": "1.
|
|
41
|
+
"@eslint-react/eff": "1.24.0-beta.1",
|
|
42
|
+
"@eslint-react/types": "1.24.0-beta.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|