@eslint-react/ast 2.3.13-beta.2 → 2.3.13-beta.4
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.ts +48 -48
- package/dist/index.js +79 -77
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -9,53 +9,6 @@ declare function getArrayMethodCallbackIndexParamPosition(methodName: string): n
|
|
|
9
9
|
declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
10
10
|
declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
|
|
11
11
|
//#endregion
|
|
12
|
-
//#region src/node-equal.d.ts
|
|
13
|
-
/**
|
|
14
|
-
* Determines whether node equals to another node
|
|
15
|
-
* @param a node to compare
|
|
16
|
-
* @param b node to compare
|
|
17
|
-
* @returns `true` if node equal
|
|
18
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
19
|
-
*/
|
|
20
|
-
declare const isNodeEqual: {
|
|
21
|
-
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
22
|
-
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/node-format.d.ts
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
30
|
-
/**
|
|
31
|
-
* Incomplete but sufficient stringification of AST nodes for common use cases
|
|
32
|
-
*
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/node-is.d.ts
|
|
38
|
-
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
39
|
-
type: NodeType;
|
|
40
|
-
}>;
|
|
41
|
-
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
42
|
-
type: NodeTypes[number];
|
|
43
|
-
}>;
|
|
44
|
-
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
45
|
-
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
46
|
-
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
47
|
-
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
48
|
-
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
49
|
-
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
50
|
-
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
51
|
-
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
52
|
-
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
|
|
53
|
-
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
54
|
-
declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
55
|
-
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
56
|
-
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
57
|
-
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
58
|
-
//#endregion
|
|
59
12
|
//#region src/node-types.d.ts
|
|
60
13
|
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
|
|
61
14
|
type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
|
|
@@ -189,6 +142,53 @@ declare function isMultiLine(node: TSESTree.Node): boolean;
|
|
|
189
142
|
*/
|
|
190
143
|
declare function isLineBreak(node: TSESTree.Node): boolean;
|
|
191
144
|
//#endregion
|
|
145
|
+
//#region src/node-equal.d.ts
|
|
146
|
+
/**
|
|
147
|
+
* Determines whether node equals to another node
|
|
148
|
+
* @param a node to compare
|
|
149
|
+
* @param b node to compare
|
|
150
|
+
* @returns `true` if node equal
|
|
151
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
152
|
+
*/
|
|
153
|
+
declare const isNodeEqual: {
|
|
154
|
+
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
155
|
+
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/node-format.d.ts
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
|
|
163
|
+
/**
|
|
164
|
+
* Incomplete but sufficient stringification of AST nodes for common use cases
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/node-is.d.ts
|
|
171
|
+
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
172
|
+
type: NodeType;
|
|
173
|
+
}>;
|
|
174
|
+
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
175
|
+
type: NodeTypes[number];
|
|
176
|
+
}>;
|
|
177
|
+
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
178
|
+
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
179
|
+
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
180
|
+
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
|
|
181
|
+
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
|
182
|
+
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
|
|
183
|
+
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
|
|
184
|
+
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
|
|
185
|
+
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
|
|
186
|
+
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
|
|
187
|
+
declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
188
|
+
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
189
|
+
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
190
|
+
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
191
|
+
//#endregion
|
|
192
192
|
//#region src/node-selectors.d.ts
|
|
193
193
|
type ImplicitReturnArrowFunctionExpression = TSESTree$1.ArrowFunctionExpression & {
|
|
194
194
|
body: TSESTree$1.Expression;
|
|
@@ -233,7 +233,7 @@ declare function isThenCall(node: TSESTree.CallExpression): boolean;
|
|
|
233
233
|
//#region src/property-name.d.ts
|
|
234
234
|
declare function getPropertyName(node: TSESTree.Node): string | unit;
|
|
235
235
|
//#endregion
|
|
236
|
-
//#region src/traverse
|
|
236
|
+
//#region src/traverse.d.ts
|
|
237
237
|
/**
|
|
238
238
|
* Find the parent node that satisfies the test function
|
|
239
239
|
* @param node The AST node
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
2
2
|
import { dual, or, unit } from "@eslint-react/eff";
|
|
3
|
-
import { delimiterCase, replace, toLowerCase } from "string-ts";
|
|
4
3
|
import { ASTUtils } from "@typescript-eslint/utils";
|
|
5
4
|
import { simpleTraverse } from "@typescript-eslint/typescript-estree";
|
|
5
|
+
import { delimiterCase, replace, toLowerCase } from "string-ts";
|
|
6
6
|
|
|
7
7
|
//#region src/array-index.ts
|
|
8
8
|
const indexParamPosition = new Map([
|
|
@@ -48,45 +48,6 @@ function getClassId(node) {
|
|
|
48
48
|
return unit;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/node-equal.ts
|
|
53
|
-
/**
|
|
54
|
-
* Determines whether node equals to another node
|
|
55
|
-
* @param a node to compare
|
|
56
|
-
* @param b node to compare
|
|
57
|
-
* @returns `true` if node equal
|
|
58
|
-
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
59
|
-
*/
|
|
60
|
-
const isNodeEqual = dual(2, (a, b) => {
|
|
61
|
-
switch (true) {
|
|
62
|
-
case a === b: return true;
|
|
63
|
-
case a.type !== b.type: return false;
|
|
64
|
-
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
65
|
-
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
66
|
-
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
67
|
-
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
68
|
-
let i = a.quasis.length;
|
|
69
|
-
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
70
|
-
i = a.expressions.length;
|
|
71
|
-
while (i--) {
|
|
72
|
-
const exprA = a.expressions[i];
|
|
73
|
-
const exprB = b.expressions[i];
|
|
74
|
-
if (!isNodeEqual(exprA, exprB)) return false;
|
|
75
|
-
}
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
79
|
-
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
80
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
81
|
-
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
82
|
-
if (a.name.name !== b.name.name) return false;
|
|
83
|
-
if (a.value == null || b.value == null) return a.value === b.value;
|
|
84
|
-
return isNodeEqual(a.value, b.value);
|
|
85
|
-
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
86
|
-
default: return false;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
51
|
//#endregion
|
|
91
52
|
//#region src/node-is.ts
|
|
92
53
|
const is = ASTUtils.isNodeOfType;
|
|
@@ -162,42 +123,6 @@ const isTypeAssertionExpression = isOneOf([
|
|
|
162
123
|
AST_NODE_TYPES.TSSatisfiesExpression
|
|
163
124
|
]);
|
|
164
125
|
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region src/node-format.ts
|
|
167
|
-
function getLiteralValueType(input) {
|
|
168
|
-
if (input === null) return "null";
|
|
169
|
-
return typeof input;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
function toDelimiterFormat(node, delimiter = " ") {
|
|
175
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
176
|
-
if ("regex" in node) return "RegExp literal";
|
|
177
|
-
return `${getLiteralValueType(node.value)} literal`;
|
|
178
|
-
}
|
|
179
|
-
if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
180
|
-
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Incomplete but sufficient stringification of AST nodes for common use cases
|
|
184
|
-
*
|
|
185
|
-
* @internal
|
|
186
|
-
*/
|
|
187
|
-
function toStringFormat(node, getText) {
|
|
188
|
-
switch (node.type) {
|
|
189
|
-
case AST_NODE_TYPES.Identifier:
|
|
190
|
-
case AST_NODE_TYPES.JSXIdentifier:
|
|
191
|
-
case AST_NODE_TYPES.PrivateIdentifier: return node.name;
|
|
192
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
193
|
-
case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
|
|
194
|
-
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
195
|
-
case AST_NODE_TYPES.JSXText: return node.value;
|
|
196
|
-
case AST_NODE_TYPES.Literal: return node.raw;
|
|
197
|
-
default: return getText(node);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
126
|
//#endregion
|
|
202
127
|
//#region src/expression-base.ts
|
|
203
128
|
/**
|
|
@@ -226,7 +151,7 @@ function isThisExpression(node) {
|
|
|
226
151
|
}
|
|
227
152
|
|
|
228
153
|
//#endregion
|
|
229
|
-
//#region src/traverse
|
|
154
|
+
//#region src/traverse.ts
|
|
230
155
|
function findParentNode(node, test) {
|
|
231
156
|
if (node == null) return unit;
|
|
232
157
|
let parent = node.parent;
|
|
@@ -555,6 +480,83 @@ function isLineBreak(node) {
|
|
|
555
480
|
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
556
481
|
}
|
|
557
482
|
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/node-equal.ts
|
|
485
|
+
/**
|
|
486
|
+
* Determines whether node equals to another node
|
|
487
|
+
* @param a node to compare
|
|
488
|
+
* @param b node to compare
|
|
489
|
+
* @returns `true` if node equal
|
|
490
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
491
|
+
*/
|
|
492
|
+
const isNodeEqual = dual(2, (a, b) => {
|
|
493
|
+
a = isTypeExpression(a) ? getUnderlyingExpression(a) : a;
|
|
494
|
+
b = isTypeExpression(b) ? getUnderlyingExpression(b) : b;
|
|
495
|
+
switch (true) {
|
|
496
|
+
case a === b: return true;
|
|
497
|
+
case a.type !== b.type: return false;
|
|
498
|
+
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
499
|
+
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
500
|
+
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
501
|
+
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
502
|
+
let i = a.quasis.length;
|
|
503
|
+
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
504
|
+
i = a.expressions.length;
|
|
505
|
+
while (i--) {
|
|
506
|
+
const exprA = a.expressions[i];
|
|
507
|
+
const exprB = b.expressions[i];
|
|
508
|
+
if (!isNodeEqual(exprA, exprB)) return false;
|
|
509
|
+
}
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
513
|
+
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
514
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
515
|
+
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
516
|
+
if (a.name.name !== b.name.name) return false;
|
|
517
|
+
if (a.value == null || b.value == null) return a.value === b.value;
|
|
518
|
+
return isNodeEqual(a.value, b.value);
|
|
519
|
+
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
520
|
+
default: return false;
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/node-format.ts
|
|
526
|
+
function getLiteralValueType(input) {
|
|
527
|
+
if (input === null) return "null";
|
|
528
|
+
return typeof input;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* @internal
|
|
532
|
+
*/
|
|
533
|
+
function toDelimiterFormat(node, delimiter = " ") {
|
|
534
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
535
|
+
if ("regex" in node) return "RegExp literal";
|
|
536
|
+
return `${getLiteralValueType(node.value)} literal`;
|
|
537
|
+
}
|
|
538
|
+
if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
539
|
+
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Incomplete but sufficient stringification of AST nodes for common use cases
|
|
543
|
+
*
|
|
544
|
+
* @internal
|
|
545
|
+
*/
|
|
546
|
+
function toStringFormat(node, getText) {
|
|
547
|
+
switch (node.type) {
|
|
548
|
+
case AST_NODE_TYPES.Identifier:
|
|
549
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
550
|
+
case AST_NODE_TYPES.PrivateIdentifier: return node.name;
|
|
551
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
552
|
+
case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
|
|
553
|
+
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
554
|
+
case AST_NODE_TYPES.JSXText: return node.value;
|
|
555
|
+
case AST_NODE_TYPES.Literal: return node.raw;
|
|
556
|
+
default: return getText(node);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
558
560
|
//#endregion
|
|
559
561
|
//#region src/node-selectors.ts
|
|
560
562
|
const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "2.3.13-beta.
|
|
3
|
+
"version": "2.3.13-beta.4",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@typescript-eslint/typescript-estree": "^8.48.1",
|
|
35
35
|
"@typescript-eslint/utils": "^8.48.1",
|
|
36
36
|
"string-ts": "^2.3.1",
|
|
37
|
-
"@eslint-react/eff": "2.3.13-beta.
|
|
37
|
+
"@eslint-react/eff": "2.3.13-beta.4"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"eslint": "^8.57.0 || ^9.0.0",
|