@eslint-react/ast 1.23.3-next.8 → 1.24.0-next.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 +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +79 -71
- package/dist/index.mjs +80 -72
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
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
29
|
/**
|
|
@@ -32,9 +31,9 @@ declare const findParentNodeGuard: {
|
|
|
32
31
|
* @param node The node to start searching
|
|
33
32
|
* @param stopNode The node to stop searching
|
|
34
33
|
* @param predicate The test function
|
|
35
|
-
* @returns The first parent node that satisfies the test
|
|
34
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
36
35
|
*/
|
|
37
|
-
declare function findParentNodeStop(node: TSESTree.Node, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean):
|
|
36
|
+
declare function findParentNodeStop(node: TSESTree.Node | _, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
38
37
|
|
|
39
38
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
40
39
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
@@ -144,15 +143,15 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
143
|
TSESTree.PropertyDefinition,
|
|
145
144
|
TSESTreeFunction
|
|
146
145
|
];
|
|
147
|
-
declare function getFunctionInitPath(node: TSESTreeFunction):
|
|
148
|
-
declare function hasCallInFunctionInitPath(callName: string): (initPath:
|
|
146
|
+
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
+
declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
152
151
|
* @param node The AST node to check
|
|
153
152
|
* @returns class identifier or null
|
|
154
153
|
*/
|
|
155
|
-
declare function getClassIdentifier(node: TSESTreeClass):
|
|
154
|
+
declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
156
155
|
|
|
157
156
|
/**
|
|
158
157
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -162,11 +161,11 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree.Iden
|
|
|
162
161
|
* same AST nodes with some exceptions to better fit our use case.
|
|
163
162
|
*/
|
|
164
163
|
|
|
165
|
-
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction):
|
|
164
|
+
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
166
165
|
|
|
167
|
-
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): TSESTree.Identifier[];
|
|
166
|
+
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): readonly TSESTree.Identifier[];
|
|
168
167
|
|
|
169
|
-
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "
|
|
168
|
+
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
|
|
170
169
|
|
|
171
170
|
/**********************************************
|
|
172
171
|
* DO NOT MODIFY THIS FILE MANUALLY *
|
|
@@ -2348,7 +2347,7 @@ declare const getNestedNewExpressions: (node: Node) => NewExpression[];
|
|
|
2348
2347
|
*/
|
|
2349
2348
|
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
2350
2349
|
|
|
2351
|
-
declare function getTopLevelIdentifier(node: TSESTree.Node):
|
|
2350
|
+
declare function getTopLevelIdentifier(node: TSESTree.Node): TSESTree.Identifier | _;
|
|
2352
2351
|
|
|
2353
2352
|
declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree$1.Node | null | undefined) => node is Extract<TSESTree$1.Node, {
|
|
2354
2353
|
type: NodeType;
|
|
@@ -2360,8 +2359,8 @@ declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is
|
|
|
2360
2359
|
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
2360
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2362
2361
|
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:
|
|
2362
|
+
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;
|
|
2363
|
+
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
2364
|
declare const isArrayTupleType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
2366
2365
|
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
2366
|
declare const isJSXElement: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXElement;
|
|
@@ -2441,7 +2440,7 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
2441
2440
|
* @param node AST node
|
|
2442
2441
|
* @returns Human readable node type
|
|
2443
2442
|
*/
|
|
2444
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "
|
|
2443
|
+
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
2444
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
2446
2445
|
|
|
2447
2446
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
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
29
|
/**
|
|
@@ -32,9 +31,9 @@ declare const findParentNodeGuard: {
|
|
|
32
31
|
* @param node The node to start searching
|
|
33
32
|
* @param stopNode The node to stop searching
|
|
34
33
|
* @param predicate The test function
|
|
35
|
-
* @returns The first parent node that satisfies the test
|
|
34
|
+
* @returns The first parent node that satisfies the test or undefined if not found
|
|
36
35
|
*/
|
|
37
|
-
declare function findParentNodeStop(node: TSESTree.Node, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean):
|
|
36
|
+
declare function findParentNodeStop(node: TSESTree.Node | _, stopNode: TSESTree.Node, predicate: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
|
|
38
37
|
|
|
39
38
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
40
39
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
@@ -144,15 +143,15 @@ readonly [TSESTree.FunctionDeclaration]
|
|
|
144
143
|
TSESTree.PropertyDefinition,
|
|
145
144
|
TSESTreeFunction
|
|
146
145
|
];
|
|
147
|
-
declare function getFunctionInitPath(node: TSESTreeFunction):
|
|
148
|
-
declare function hasCallInFunctionInitPath(callName: string): (initPath:
|
|
146
|
+
declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
|
|
147
|
+
declare function hasCallInFunctionInitPath(callName: string): (initPath: FunctionInitPath) => boolean;
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
152
151
|
* @param node The AST node to check
|
|
153
152
|
* @returns class identifier or null
|
|
154
153
|
*/
|
|
155
|
-
declare function getClassIdentifier(node: TSESTreeClass):
|
|
154
|
+
declare function getClassIdentifier(node: TSESTreeClass): TSESTree.Identifier | _;
|
|
156
155
|
|
|
157
156
|
/**
|
|
158
157
|
* Gets the static name of a function AST node. For function declarations it is
|
|
@@ -162,11 +161,11 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree.Iden
|
|
|
162
161
|
* same AST nodes with some exceptions to better fit our use case.
|
|
163
162
|
*/
|
|
164
163
|
|
|
165
|
-
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction):
|
|
164
|
+
declare function getFunctionIdentifier(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
|
|
166
165
|
|
|
167
|
-
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): TSESTree.Identifier[];
|
|
166
|
+
declare function getIdentifiersFromBinaryExpression(side: TSESTree.BinaryExpression | TSESTree.BinaryExpression["left"] | TSESTree.BinaryExpression["right"]): readonly TSESTree.Identifier[];
|
|
168
167
|
|
|
169
|
-
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "
|
|
168
|
+
declare function getLiteralValueType(input: bigint | boolean | null | number | string | symbol): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
|
|
170
169
|
|
|
171
170
|
/**********************************************
|
|
172
171
|
* DO NOT MODIFY THIS FILE MANUALLY *
|
|
@@ -2348,7 +2347,7 @@ declare const getNestedNewExpressions: (node: Node) => NewExpression[];
|
|
|
2348
2347
|
*/
|
|
2349
2348
|
declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[];
|
|
2350
2349
|
|
|
2351
|
-
declare function getTopLevelIdentifier(node: TSESTree.Node):
|
|
2350
|
+
declare function getTopLevelIdentifier(node: TSESTree.Node): TSESTree.Identifier | _;
|
|
2352
2351
|
|
|
2353
2352
|
declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree$1.Node | null | undefined) => node is Extract<TSESTree$1.Node, {
|
|
2354
2353
|
type: NodeType;
|
|
@@ -2360,8 +2359,8 @@ declare const isFunction: (node: TSESTree$1.Node | null | undefined) => node is
|
|
|
2360
2359
|
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
2360
|
declare const isClass: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.ClassDeclarationWithName | TSESTree$1.ClassDeclarationWithOptionalName | TSESTree$1.ClassExpression;
|
|
2362
2361
|
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:
|
|
2362
|
+
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;
|
|
2363
|
+
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
2364
|
declare const isArrayTupleType: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
|
|
2366
2365
|
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
2366
|
declare const isJSXElement: (node: TSESTree$1.Node | null | undefined) => node is TSESTree$1.JSXElement;
|
|
@@ -2441,7 +2440,7 @@ declare function toReadableNodeName(node: TSESTree.Node, getText: (node: TSESTre
|
|
|
2441
2440
|
* @param node AST node
|
|
2442
2441
|
* @returns Human readable node type
|
|
2443
2442
|
*/
|
|
2444
|
-
declare function toReadableNodeType(node: TSESTree.Node): "property" | "RegExp literal" | "
|
|
2443
|
+
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
2444
|
type ReadableNodeType = ReturnType<typeof toReadableNodeType>;
|
|
2446
2445
|
|
|
2447
2446
|
declare function unwrapTypeExpression(node: TSESTree.Node): TSESTree.Node;
|
package/dist/index.js
CHANGED
|
@@ -3,127 +3,123 @@
|
|
|
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 === eff._) return eff._;
|
|
13
13
|
let parent = node.parent;
|
|
14
|
-
while (parent
|
|
14
|
+
while (parent && 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 === eff._) return eff._;
|
|
23
24
|
let parent = node.parent;
|
|
24
|
-
while (parent
|
|
25
|
+
while (parent) {
|
|
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
33
|
function findParentNodeStop(node, stopNode, predicate) {
|
|
34
|
+
if (node === eff._) return eff._;
|
|
33
35
|
let parent = node.parent;
|
|
34
|
-
while (parent
|
|
36
|
+
while (parent && parent !== stopNode && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
35
37
|
if (predicate(parent)) {
|
|
36
|
-
return
|
|
38
|
+
return parent;
|
|
37
39
|
}
|
|
38
40
|
parent = parent.parent;
|
|
39
41
|
}
|
|
40
|
-
return eff.
|
|
42
|
+
return eff._;
|
|
41
43
|
}
|
|
42
44
|
function getFunctionInitPath(node) {
|
|
43
45
|
const { parent } = node;
|
|
44
46
|
if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
|
|
45
|
-
return
|
|
47
|
+
return [node];
|
|
46
48
|
}
|
|
47
49
|
if (parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
48
|
-
return
|
|
50
|
+
return [
|
|
49
51
|
parent.parent,
|
|
50
52
|
parent,
|
|
51
53
|
node
|
|
52
|
-
]
|
|
54
|
+
];
|
|
53
55
|
}
|
|
54
56
|
if (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
|
|
55
|
-
return
|
|
57
|
+
return [
|
|
56
58
|
parent.parent.parent,
|
|
57
59
|
parent.parent,
|
|
58
60
|
parent,
|
|
59
61
|
node
|
|
60
|
-
]
|
|
62
|
+
];
|
|
61
63
|
}
|
|
62
64
|
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
|
|
65
|
+
return [
|
|
64
66
|
parent.parent.parent.parent,
|
|
65
67
|
parent.parent.parent,
|
|
66
68
|
parent.parent,
|
|
67
69
|
parent,
|
|
68
70
|
node
|
|
69
|
-
]
|
|
71
|
+
];
|
|
70
72
|
}
|
|
71
73
|
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
|
|
74
|
+
return [
|
|
73
75
|
parent.parent.parent.parent,
|
|
74
76
|
parent.parent.parent,
|
|
75
77
|
parent.parent,
|
|
76
78
|
parent,
|
|
77
79
|
node
|
|
78
|
-
]
|
|
80
|
+
];
|
|
79
81
|
}
|
|
80
82
|
if (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
|
|
81
|
-
return
|
|
83
|
+
return [
|
|
82
84
|
parent.parent.parent,
|
|
83
85
|
parent.parent,
|
|
84
86
|
parent,
|
|
85
87
|
node
|
|
86
|
-
]
|
|
88
|
+
];
|
|
87
89
|
}
|
|
88
90
|
if (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
|
|
89
|
-
return
|
|
91
|
+
return [
|
|
90
92
|
parent.parent.parent,
|
|
91
93
|
parent.parent,
|
|
92
94
|
parent,
|
|
93
95
|
node
|
|
94
|
-
]
|
|
96
|
+
];
|
|
95
97
|
}
|
|
96
|
-
return eff.
|
|
98
|
+
return eff._;
|
|
97
99
|
}
|
|
98
100
|
function hasCallInFunctionInitPath(callName) {
|
|
99
101
|
return (initPath) => {
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
})
|
|
116
|
-
);
|
|
102
|
+
return initPath.some((n) => {
|
|
103
|
+
if (n.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
switch (n.callee.type) {
|
|
107
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
108
|
+
return n.callee.name === callName;
|
|
109
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
110
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
111
|
+
default:
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
117
115
|
};
|
|
118
116
|
}
|
|
119
117
|
function getClassIdentifier(node) {
|
|
120
|
-
if (node.id
|
|
121
|
-
return eff.O.fromNullable(node.id);
|
|
122
|
-
}
|
|
118
|
+
if (node.id) return node.id;
|
|
123
119
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
124
|
-
return
|
|
120
|
+
return node.parent.id;
|
|
125
121
|
}
|
|
126
|
-
return eff.
|
|
122
|
+
return eff._;
|
|
127
123
|
}
|
|
128
124
|
var is = utils.ASTUtils.isNodeOfType;
|
|
129
125
|
var isOneOf = utils.ASTUtils.isNodeOfTypes;
|
|
@@ -264,34 +260,34 @@ function getFunctionIdentifier(node) {
|
|
|
264
260
|
switch (true) {
|
|
265
261
|
// function MaybeComponent() {}
|
|
266
262
|
case ("id" in node && node.id != null):
|
|
267
|
-
return
|
|
263
|
+
return node.id;
|
|
268
264
|
// const whatever = function MaybeComponent() {};
|
|
269
265
|
case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
|
|
270
|
-
return
|
|
266
|
+
return node.parent.id;
|
|
271
267
|
// MaybeComponent = () => {};
|
|
272
268
|
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
|
|
269
|
+
return node.parent.left;
|
|
274
270
|
// {MaybeComponent: () => {}}
|
|
275
271
|
// {MaybeComponent() {}}
|
|
276
272
|
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
|
|
273
|
+
return node.parent.key;
|
|
278
274
|
// class {MaybeComponent = () => {}}
|
|
279
275
|
// class {MaybeComponent() {}}
|
|
280
276
|
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
|
|
277
|
+
return node.parent.key;
|
|
282
278
|
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
283
279
|
//
|
|
284
280
|
// const {MaybeComponent = () => {}} = {};
|
|
285
281
|
// ({MaybeComponent = () => {}} = {});
|
|
286
282
|
case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
|
|
287
|
-
return
|
|
283
|
+
return node.parent.left;
|
|
288
284
|
// const MaybeComponent = (() => {})!;
|
|
289
285
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
290
286
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
291
287
|
case isTypeExpression(node.parent):
|
|
292
288
|
return getFunctionIdentifier(node.parent);
|
|
293
289
|
}
|
|
294
|
-
return eff.
|
|
290
|
+
return eff._;
|
|
295
291
|
}
|
|
296
292
|
function getIdentifiersFromBinaryExpression(side) {
|
|
297
293
|
if (side.type === types.AST_NODE_TYPES.Identifier) {
|
|
@@ -305,8 +301,11 @@ function getIdentifiersFromBinaryExpression(side) {
|
|
|
305
301
|
}
|
|
306
302
|
return [];
|
|
307
303
|
}
|
|
304
|
+
|
|
305
|
+
// src/get-literal-value-type.ts
|
|
308
306
|
function getLiteralValueType(input) {
|
|
309
|
-
|
|
307
|
+
if (input === null) return "null";
|
|
308
|
+
return typeof input;
|
|
310
309
|
}
|
|
311
310
|
function getNestedExpressionsOfType(type) {
|
|
312
311
|
const isNodeOfType = utils.ASTUtils.isNodeOfType(type);
|
|
@@ -332,7 +331,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
332
331
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
333
332
|
expressions.push(...chunk);
|
|
334
333
|
}
|
|
335
|
-
if ("test" in node && node.test
|
|
334
|
+
if ("test" in node && node.test) {
|
|
336
335
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
337
336
|
expressions.push(...chunk);
|
|
338
337
|
}
|
|
@@ -340,7 +339,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
340
339
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
341
340
|
expressions.push(...chunk);
|
|
342
341
|
}
|
|
343
|
-
if ("alternate" in node && node.alternate
|
|
342
|
+
if ("alternate" in node && node.alternate) {
|
|
344
343
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
345
344
|
expressions.push(...chunk);
|
|
346
345
|
}
|
|
@@ -460,13 +459,13 @@ function getNestedIdentifiers(node) {
|
|
|
460
459
|
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
461
460
|
function getNestedReturnStatements(node) {
|
|
462
461
|
const returnStatements = [];
|
|
463
|
-
const functionNode = isFunction(node) ? node :
|
|
462
|
+
const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
|
|
464
463
|
typescriptEstree.simpleTraverse(node, {
|
|
465
464
|
enter(node2) {
|
|
466
465
|
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
|
|
467
466
|
return;
|
|
468
467
|
}
|
|
469
|
-
const parentFunction =
|
|
468
|
+
const parentFunction = findParentNodeGuard(node2, isFunction);
|
|
470
469
|
if (parentFunction !== functionNode) {
|
|
471
470
|
return;
|
|
472
471
|
}
|
|
@@ -478,11 +477,11 @@ function getNestedReturnStatements(node) {
|
|
|
478
477
|
function getTopLevelIdentifier(node) {
|
|
479
478
|
switch (node.type) {
|
|
480
479
|
case types.AST_NODE_TYPES.Identifier:
|
|
481
|
-
return
|
|
480
|
+
return node;
|
|
482
481
|
case types.AST_NODE_TYPES.MemberExpression:
|
|
483
482
|
return getTopLevelIdentifier(node.object);
|
|
484
483
|
default:
|
|
485
|
-
return eff.
|
|
484
|
+
return eff._;
|
|
486
485
|
}
|
|
487
486
|
}
|
|
488
487
|
function isEmptyFunction(node) {
|
|
@@ -501,7 +500,7 @@ function isFunctionOfObjectMethod(node) {
|
|
|
501
500
|
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
501
|
}
|
|
503
502
|
function isKeyLiteralLike(node, property) {
|
|
504
|
-
return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, eff.
|
|
503
|
+
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
504
|
}
|
|
506
505
|
function isMapCallLoose(node) {
|
|
507
506
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
@@ -521,7 +520,7 @@ function isMapCallLoose(node) {
|
|
|
521
520
|
function isMultiLine(node) {
|
|
522
521
|
return node.loc.start.line !== node.loc.end.line;
|
|
523
522
|
}
|
|
524
|
-
var isNodeEqual = eff.
|
|
523
|
+
var isNodeEqual = eff.dual(2, (a, b) => {
|
|
525
524
|
switch (true) {
|
|
526
525
|
case a === b:
|
|
527
526
|
return true;
|
|
@@ -531,17 +530,26 @@ var isNodeEqual = eff.F.dual(2, (a, b) => {
|
|
|
531
530
|
return a.value === b.value;
|
|
532
531
|
case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement):
|
|
533
532
|
return a.value.raw === b.value.raw;
|
|
534
|
-
case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral):
|
|
533
|
+
case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral): {
|
|
535
534
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
|
|
536
535
|
return false;
|
|
537
536
|
}
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
let i = a.quasis.length;
|
|
538
|
+
while (i--) {
|
|
539
|
+
if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
540
542
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
+
i = a.expressions.length;
|
|
544
|
+
while (i--) {
|
|
545
|
+
const exprA = a.expressions[i];
|
|
546
|
+
const exprB = b.expressions[i];
|
|
547
|
+
if (!isNodeEqual(exprA, exprB)) {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
543
550
|
}
|
|
544
551
|
return true;
|
|
552
|
+
}
|
|
545
553
|
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier):
|
|
546
554
|
return a.name === b.name;
|
|
547
555
|
case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier):
|
|
@@ -567,7 +575,7 @@ function isRegExpLiteral(node) {
|
|
|
567
575
|
return node.type === types.AST_NODE_TYPES.Literal && "regex" in node;
|
|
568
576
|
}
|
|
569
577
|
function isStringLiteral(node) {
|
|
570
|
-
return node.type === types.AST_NODE_TYPES.Literal &&
|
|
578
|
+
return node.type === types.AST_NODE_TYPES.Literal && typeof node.value === "string";
|
|
571
579
|
}
|
|
572
580
|
function isThisExpression(node) {
|
|
573
581
|
if (isTypeExpression(node)) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,127 +1,123 @@
|
|
|
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 === _) return _;
|
|
11
11
|
let parent = node.parent;
|
|
12
|
-
while (parent
|
|
12
|
+
while (parent && 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 === _) return _;
|
|
21
22
|
let parent = node.parent;
|
|
22
|
-
while (parent
|
|
23
|
+
while (parent) {
|
|
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
31
|
function findParentNodeStop(node, stopNode, predicate) {
|
|
32
|
+
if (node === _) return _;
|
|
31
33
|
let parent = node.parent;
|
|
32
|
-
while (parent
|
|
34
|
+
while (parent && parent !== stopNode && parent.type !== AST_NODE_TYPES.Program) {
|
|
33
35
|
if (predicate(parent)) {
|
|
34
|
-
return
|
|
36
|
+
return parent;
|
|
35
37
|
}
|
|
36
38
|
parent = parent.parent;
|
|
37
39
|
}
|
|
38
|
-
return
|
|
40
|
+
return _;
|
|
39
41
|
}
|
|
40
42
|
function getFunctionInitPath(node) {
|
|
41
43
|
const { parent } = node;
|
|
42
44
|
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
43
|
-
return
|
|
45
|
+
return [node];
|
|
44
46
|
}
|
|
45
47
|
if (parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
46
|
-
return
|
|
48
|
+
return [
|
|
47
49
|
parent.parent,
|
|
48
50
|
parent,
|
|
49
51
|
node
|
|
50
|
-
]
|
|
52
|
+
];
|
|
51
53
|
}
|
|
52
54
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
53
|
-
return
|
|
55
|
+
return [
|
|
54
56
|
parent.parent.parent,
|
|
55
57
|
parent.parent,
|
|
56
58
|
parent,
|
|
57
59
|
node
|
|
58
|
-
]
|
|
60
|
+
];
|
|
59
61
|
}
|
|
60
62
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
61
|
-
return
|
|
63
|
+
return [
|
|
62
64
|
parent.parent.parent.parent,
|
|
63
65
|
parent.parent.parent,
|
|
64
66
|
parent.parent,
|
|
65
67
|
parent,
|
|
66
68
|
node
|
|
67
|
-
]
|
|
69
|
+
];
|
|
68
70
|
}
|
|
69
71
|
if (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
70
|
-
return
|
|
72
|
+
return [
|
|
71
73
|
parent.parent.parent.parent,
|
|
72
74
|
parent.parent.parent,
|
|
73
75
|
parent.parent,
|
|
74
76
|
parent,
|
|
75
77
|
node
|
|
76
|
-
]
|
|
78
|
+
];
|
|
77
79
|
}
|
|
78
80
|
if (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration) {
|
|
79
|
-
return
|
|
81
|
+
return [
|
|
80
82
|
parent.parent.parent,
|
|
81
83
|
parent.parent,
|
|
82
84
|
parent,
|
|
83
85
|
node
|
|
84
|
-
]
|
|
86
|
+
];
|
|
85
87
|
}
|
|
86
88
|
if (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration) {
|
|
87
|
-
return
|
|
89
|
+
return [
|
|
88
90
|
parent.parent.parent,
|
|
89
91
|
parent.parent,
|
|
90
92
|
parent,
|
|
91
93
|
node
|
|
92
|
-
]
|
|
94
|
+
];
|
|
93
95
|
}
|
|
94
|
-
return
|
|
96
|
+
return _;
|
|
95
97
|
}
|
|
96
98
|
function hasCallInFunctionInitPath(callName) {
|
|
97
99
|
return (initPath) => {
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
})
|
|
114
|
-
);
|
|
100
|
+
return initPath.some((n) => {
|
|
101
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
switch (n.callee.type) {
|
|
105
|
+
case AST_NODE_TYPES.Identifier:
|
|
106
|
+
return n.callee.name === callName;
|
|
107
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
108
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
109
|
+
default:
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
115
113
|
};
|
|
116
114
|
}
|
|
117
115
|
function getClassIdentifier(node) {
|
|
118
|
-
if (node.id
|
|
119
|
-
return O.fromNullable(node.id);
|
|
120
|
-
}
|
|
116
|
+
if (node.id) return node.id;
|
|
121
117
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
122
|
-
return
|
|
118
|
+
return node.parent.id;
|
|
123
119
|
}
|
|
124
|
-
return
|
|
120
|
+
return _;
|
|
125
121
|
}
|
|
126
122
|
var is = ASTUtils.isNodeOfType;
|
|
127
123
|
var isOneOf = ASTUtils.isNodeOfTypes;
|
|
@@ -262,34 +258,34 @@ function getFunctionIdentifier(node) {
|
|
|
262
258
|
switch (true) {
|
|
263
259
|
// function MaybeComponent() {}
|
|
264
260
|
case ("id" in node && node.id != null):
|
|
265
|
-
return
|
|
261
|
+
return node.id;
|
|
266
262
|
// const whatever = function MaybeComponent() {};
|
|
267
263
|
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
268
|
-
return
|
|
264
|
+
return node.parent.id;
|
|
269
265
|
// MaybeComponent = () => {};
|
|
270
266
|
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
|
|
267
|
+
return node.parent.left;
|
|
272
268
|
// {MaybeComponent: () => {}}
|
|
273
269
|
// {MaybeComponent() {}}
|
|
274
270
|
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
|
|
271
|
+
return node.parent.key;
|
|
276
272
|
// class {MaybeComponent = () => {}}
|
|
277
273
|
// class {MaybeComponent() {}}
|
|
278
274
|
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
|
|
275
|
+
return node.parent.key;
|
|
280
276
|
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
281
277
|
//
|
|
282
278
|
// const {MaybeComponent = () => {}} = {};
|
|
283
279
|
// ({MaybeComponent = () => {}} = {});
|
|
284
280
|
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
285
|
-
return
|
|
281
|
+
return node.parent.left;
|
|
286
282
|
// const MaybeComponent = (() => {})!;
|
|
287
283
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
288
284
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
289
285
|
case isTypeExpression(node.parent):
|
|
290
286
|
return getFunctionIdentifier(node.parent);
|
|
291
287
|
}
|
|
292
|
-
return
|
|
288
|
+
return _;
|
|
293
289
|
}
|
|
294
290
|
function getIdentifiersFromBinaryExpression(side) {
|
|
295
291
|
if (side.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -303,8 +299,11 @@ function getIdentifiersFromBinaryExpression(side) {
|
|
|
303
299
|
}
|
|
304
300
|
return [];
|
|
305
301
|
}
|
|
302
|
+
|
|
303
|
+
// src/get-literal-value-type.ts
|
|
306
304
|
function getLiteralValueType(input) {
|
|
307
|
-
|
|
305
|
+
if (input === null) return "null";
|
|
306
|
+
return typeof input;
|
|
308
307
|
}
|
|
309
308
|
function getNestedExpressionsOfType(type) {
|
|
310
309
|
const isNodeOfType = ASTUtils.isNodeOfType(type);
|
|
@@ -330,7 +329,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
330
329
|
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
331
330
|
expressions.push(...chunk);
|
|
332
331
|
}
|
|
333
|
-
if ("test" in node && node.test
|
|
332
|
+
if ("test" in node && node.test) {
|
|
334
333
|
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
335
334
|
expressions.push(...chunk);
|
|
336
335
|
}
|
|
@@ -338,7 +337,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
338
337
|
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
339
338
|
expressions.push(...chunk);
|
|
340
339
|
}
|
|
341
|
-
if ("alternate" in node && node.alternate
|
|
340
|
+
if ("alternate" in node && node.alternate) {
|
|
342
341
|
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
343
342
|
expressions.push(...chunk);
|
|
344
343
|
}
|
|
@@ -458,13 +457,13 @@ function getNestedIdentifiers(node) {
|
|
|
458
457
|
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
459
458
|
function getNestedReturnStatements(node) {
|
|
460
459
|
const returnStatements = [];
|
|
461
|
-
const functionNode = isFunction(node) ? node :
|
|
460
|
+
const functionNode = isFunction(node) ? node : findParentNodeGuard(node, isFunction);
|
|
462
461
|
simpleTraverse(node, {
|
|
463
462
|
enter(node2) {
|
|
464
463
|
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
465
464
|
return;
|
|
466
465
|
}
|
|
467
|
-
const parentFunction =
|
|
466
|
+
const parentFunction = findParentNodeGuard(node2, isFunction);
|
|
468
467
|
if (parentFunction !== functionNode) {
|
|
469
468
|
return;
|
|
470
469
|
}
|
|
@@ -476,11 +475,11 @@ function getNestedReturnStatements(node) {
|
|
|
476
475
|
function getTopLevelIdentifier(node) {
|
|
477
476
|
switch (node.type) {
|
|
478
477
|
case AST_NODE_TYPES.Identifier:
|
|
479
|
-
return
|
|
478
|
+
return node;
|
|
480
479
|
case AST_NODE_TYPES.MemberExpression:
|
|
481
480
|
return getTopLevelIdentifier(node.object);
|
|
482
481
|
default:
|
|
483
|
-
return
|
|
482
|
+
return _;
|
|
484
483
|
}
|
|
485
484
|
}
|
|
486
485
|
function isEmptyFunction(node) {
|
|
@@ -499,7 +498,7 @@ function isFunctionOfObjectMethod(node) {
|
|
|
499
498
|
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
499
|
}
|
|
501
500
|
function isKeyLiteralLike(node, property) {
|
|
502
|
-
return match(property).with({ type: AST_NODE_TYPES.Literal },
|
|
501
|
+
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
502
|
}
|
|
504
503
|
function isMapCallLoose(node) {
|
|
505
504
|
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
@@ -519,7 +518,7 @@ function isMapCallLoose(node) {
|
|
|
519
518
|
function isMultiLine(node) {
|
|
520
519
|
return node.loc.start.line !== node.loc.end.line;
|
|
521
520
|
}
|
|
522
|
-
var isNodeEqual =
|
|
521
|
+
var isNodeEqual = dual(2, (a, b) => {
|
|
523
522
|
switch (true) {
|
|
524
523
|
case a === b:
|
|
525
524
|
return true;
|
|
@@ -529,17 +528,26 @@ var isNodeEqual = F.dual(2, (a, b) => {
|
|
|
529
528
|
return a.value === b.value;
|
|
530
529
|
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
|
|
531
530
|
return a.value.raw === b.value.raw;
|
|
532
|
-
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral):
|
|
531
|
+
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
|
|
533
532
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
|
|
534
533
|
return false;
|
|
535
534
|
}
|
|
536
|
-
|
|
537
|
-
|
|
535
|
+
let i = a.quasis.length;
|
|
536
|
+
while (i--) {
|
|
537
|
+
if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
538
540
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
+
i = a.expressions.length;
|
|
542
|
+
while (i--) {
|
|
543
|
+
const exprA = a.expressions[i];
|
|
544
|
+
const exprB = b.expressions[i];
|
|
545
|
+
if (!isNodeEqual(exprA, exprB)) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
541
548
|
}
|
|
542
549
|
return true;
|
|
550
|
+
}
|
|
543
551
|
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
|
|
544
552
|
return a.name === b.name;
|
|
545
553
|
case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
|
|
@@ -565,7 +573,7 @@ function isRegExpLiteral(node) {
|
|
|
565
573
|
return node.type === AST_NODE_TYPES.Literal && "regex" in node;
|
|
566
574
|
}
|
|
567
575
|
function isStringLiteral(node) {
|
|
568
|
-
return node.type === AST_NODE_TYPES.Literal &&
|
|
576
|
+
return node.type === AST_NODE_TYPES.Literal && typeof node.value === "string";
|
|
569
577
|
}
|
|
570
578
|
function isThisExpression(node) {
|
|
571
579
|
if (isTypeExpression(node)) {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0-next.0",
|
|
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-next.0",
|
|
42
|
+
"@eslint-react/types": "1.24.0-next.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|