@eslint-react/ast 5.2.3-next.2 → 5.2.4-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.ts +11 -11
- package/dist/index.js +46 -47
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTre
|
|
|
41
41
|
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
42
42
|
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
|
|
43
43
|
declare namespace compare_d_exports {
|
|
44
|
-
export {
|
|
44
|
+
export { isEqual };
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Check if two nodes are equal
|
|
@@ -50,24 +50,24 @@ declare namespace compare_d_exports {
|
|
|
50
50
|
* @returns `true` if node equal
|
|
51
51
|
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
52
52
|
*/
|
|
53
|
-
declare const
|
|
53
|
+
declare const isEqual: {
|
|
54
54
|
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
|
|
55
55
|
(a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
56
56
|
};
|
|
57
57
|
declare namespace extract_d_exports {
|
|
58
|
-
export {
|
|
58
|
+
export { getFullyQualifiedName, getHumanReadableKind, getPropertyName, getRootIdentifier, unwrap };
|
|
59
59
|
}
|
|
60
|
-
declare function
|
|
61
|
-
declare function
|
|
62
|
-
declare function
|
|
63
|
-
declare function
|
|
64
|
-
declare function
|
|
60
|
+
declare function unwrap(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
|
|
61
|
+
declare function getRootIdentifier(node: TSESTree.Expression | TSESTree.PrivateIdentifier): TSESTree.Identifier | null;
|
|
62
|
+
declare function getPropertyName(node: TSESTree.Node): string | null;
|
|
63
|
+
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
|
|
64
|
+
declare function getHumanReadableKind(node: TSESTree.Node): "regexp literal" | "null literal" | "string literal" | "number literal" | "bigint literal" | "boolean literal" | "symbol literal" | "undefined literal" | "object literal" | "function literal" | "decorator" | "identifier" | "program" | "property" | "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" | "jsx attribute" | "jsx closing element" | "jsx closing fragment" | "jsx element" | "jsx empty expression" | "jsx expression container" | "jsx fragment" | "jsx identifier" | "member expression" | "jsx member expression" | "jsx namespaced name" | "jsx opening element" | "jsx opening fragment" | "jsx spread attribute" | "jsx spread child" | "jsx text" | "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";
|
|
65
65
|
declare namespace traverse_d_exports {
|
|
66
|
-
export {
|
|
66
|
+
export { findParent };
|
|
67
67
|
}
|
|
68
68
|
type Predicate<T extends TSESTree.Node> = (node: TSESTree.Node) => node is T;
|
|
69
69
|
type NodePredicate = (node: TSESTree.Node) => boolean;
|
|
70
|
-
declare function findParent<T extends TSESTree.Node>(
|
|
71
|
-
declare function findParent(
|
|
70
|
+
declare function findParent<T extends TSESTree.Node>(node: TSESTree.Node | null, test: Predicate<T>): T | null;
|
|
71
|
+
declare function findParent(node: TSESTree.Node | null, test: NodePredicate): TSESTree.Node | null;
|
|
72
72
|
//#endregion
|
|
73
73
|
export { check_d_exports as Check, compare_d_exports as Compare, extract_d_exports as Extract, TSESTreeClass, TSESTreeDirective, TSESTreeFunction, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeJSXElementLike, TSESTreeMethodOrPropertyDefinition, TSESTreeTypeExpression, traverse_d_exports as Traverse, is, isOneOf };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-BYypO7fO.js";
|
|
2
2
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
3
|
import { ASTUtils } from "@typescript-eslint/utils";
|
|
4
|
-
import { delimiterCase,
|
|
4
|
+
import { delimiterCase, toLowerCase } from "string-ts";
|
|
5
5
|
|
|
6
6
|
//#region src/check.ts
|
|
7
7
|
var check_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -217,55 +217,54 @@ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
|
217
217
|
//#endregion
|
|
218
218
|
//#region src/extract.ts
|
|
219
219
|
var extract_exports = /* @__PURE__ */ __exportAll({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
220
|
+
getFullyQualifiedName: () => getFullyQualifiedName,
|
|
221
|
+
getHumanReadableKind: () => getHumanReadableKind,
|
|
222
|
+
getPropertyName: () => getPropertyName,
|
|
223
|
+
getRootIdentifier: () => getRootIdentifier,
|
|
224
|
+
unwrap: () => unwrap
|
|
225
225
|
});
|
|
226
|
-
function
|
|
227
|
-
if (isTypeExpression(
|
|
228
|
-
return
|
|
226
|
+
function unwrap(node) {
|
|
227
|
+
if (isTypeExpression(node)) return unwrap(node.expression);
|
|
228
|
+
return node;
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
230
|
+
function getRootIdentifier(node) {
|
|
231
|
+
const expr = unwrap(node);
|
|
232
|
+
if (expr.type === AST_NODE_TYPES.Identifier) return expr;
|
|
233
|
+
if (expr.type === AST_NODE_TYPES.MemberExpression) return getRootIdentifier(expr.object);
|
|
234
234
|
return null;
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
if (isTypeExpression(
|
|
238
|
-
if (
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
236
|
+
function getPropertyName(node) {
|
|
237
|
+
if (isTypeExpression(node)) return getPropertyName(unwrap(node));
|
|
238
|
+
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
239
|
+
if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
|
|
240
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw ?? null;
|
|
241
241
|
return null;
|
|
242
242
|
}
|
|
243
|
-
function
|
|
244
|
-
switch (
|
|
243
|
+
function getFullyQualifiedName(node, getText) {
|
|
244
|
+
switch (node.type) {
|
|
245
245
|
case AST_NODE_TYPES.Identifier:
|
|
246
246
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
247
|
-
case AST_NODE_TYPES.PrivateIdentifier: return
|
|
247
|
+
case AST_NODE_TYPES.PrivateIdentifier: return node.name;
|
|
248
248
|
case AST_NODE_TYPES.MemberExpression:
|
|
249
|
-
case AST_NODE_TYPES.JSXMemberExpression: return `${
|
|
250
|
-
case AST_NODE_TYPES.JSXNamespacedName: return `${
|
|
251
|
-
case AST_NODE_TYPES.JSXText: return
|
|
252
|
-
case AST_NODE_TYPES.Literal: return
|
|
253
|
-
default: return
|
|
249
|
+
case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(node.object, getText)}.${getFullyQualifiedName(node.property, getText)}`;
|
|
250
|
+
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
251
|
+
case AST_NODE_TYPES.JSXText: return node.value;
|
|
252
|
+
case AST_NODE_TYPES.Literal: return node.raw;
|
|
253
|
+
default: return getText(node);
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
function
|
|
257
|
-
if (
|
|
258
|
-
if ("regex" in
|
|
259
|
-
if (
|
|
260
|
-
return `${typeof
|
|
256
|
+
function getHumanReadableKind(node) {
|
|
257
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
258
|
+
if ("regex" in node) return "regexp literal";
|
|
259
|
+
if (node.value === null) return "null literal";
|
|
260
|
+
return `${typeof node.value} literal`;
|
|
261
261
|
}
|
|
262
|
-
|
|
263
|
-
return toLowerCase(delimiterCase(of.type, delimiter));
|
|
262
|
+
return toLowerCase(delimiterCase(node.type, " "));
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
//#endregion
|
|
267
266
|
//#region src/compare.ts
|
|
268
|
-
var compare_exports = /* @__PURE__ */ __exportAll({
|
|
267
|
+
var compare_exports = /* @__PURE__ */ __exportAll({ isEqual: () => isEqual });
|
|
269
268
|
/**
|
|
270
269
|
* Check if two nodes are equal
|
|
271
270
|
* @param a node to compare
|
|
@@ -273,9 +272,9 @@ var compare_exports = /* @__PURE__ */ __exportAll({ areEqual: () => areEqual });
|
|
|
273
272
|
* @returns `true` if node equal
|
|
274
273
|
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
275
274
|
*/
|
|
276
|
-
const
|
|
277
|
-
a = isTypeExpression(a) ?
|
|
278
|
-
b = isTypeExpression(b) ?
|
|
275
|
+
const isEqual = dual(2, (a, b) => {
|
|
276
|
+
a = isTypeExpression(a) ? unwrap(a) : a;
|
|
277
|
+
b = isTypeExpression(b) ? unwrap(b) : b;
|
|
279
278
|
switch (true) {
|
|
280
279
|
case a === b: return true;
|
|
281
280
|
case a.type !== b.type: return false;
|
|
@@ -289,20 +288,20 @@ const areEqual = dual(2, (a, b) => {
|
|
|
289
288
|
while (i--) {
|
|
290
289
|
const exprA = a.expressions[i];
|
|
291
290
|
const exprB = b.expressions[i];
|
|
292
|
-
if (!
|
|
291
|
+
if (!isEqual(exprA, exprB)) return false;
|
|
293
292
|
}
|
|
294
293
|
return true;
|
|
295
294
|
}
|
|
296
295
|
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
297
296
|
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
298
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return
|
|
297
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isEqual(a.property, b.property) && isEqual(a.object, b.object);
|
|
299
298
|
case a.type === AST_NODE_TYPES.JSXIdentifier && b.type === AST_NODE_TYPES.JSXIdentifier: return a.name === b.name;
|
|
300
|
-
case a.type === AST_NODE_TYPES.JSXNamespacedName && b.type === AST_NODE_TYPES.JSXNamespacedName: return
|
|
301
|
-
case a.type === AST_NODE_TYPES.JSXMemberExpression && b.type === AST_NODE_TYPES.JSXMemberExpression: return
|
|
299
|
+
case a.type === AST_NODE_TYPES.JSXNamespacedName && b.type === AST_NODE_TYPES.JSXNamespacedName: return isEqual(a.namespace, b.namespace) && isEqual(a.name, b.name);
|
|
300
|
+
case a.type === AST_NODE_TYPES.JSXMemberExpression && b.type === AST_NODE_TYPES.JSXMemberExpression: return isEqual(a.object, b.object) && isEqual(a.property, b.property);
|
|
302
301
|
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
303
|
-
if (!
|
|
302
|
+
if (!isEqual(a.name, b.name)) return false;
|
|
304
303
|
if (a.value == null || b.value == null) return a.value === b.value;
|
|
305
|
-
return
|
|
304
|
+
return isEqual(a.value, b.value);
|
|
306
305
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
307
306
|
default: return false;
|
|
308
307
|
}
|
|
@@ -311,12 +310,12 @@ const areEqual = dual(2, (a, b) => {
|
|
|
311
310
|
//#endregion
|
|
312
311
|
//#region src/traverse.ts
|
|
313
312
|
var traverse_exports = /* @__PURE__ */ __exportAll({ findParent: () => findParent });
|
|
314
|
-
function findParent(
|
|
315
|
-
if (
|
|
316
|
-
let parent =
|
|
313
|
+
function findParent(node, test) {
|
|
314
|
+
if (node == null) return null;
|
|
315
|
+
let parent = node.parent;
|
|
317
316
|
while (parent?.type !== AST_NODE_TYPES.Program) {
|
|
318
317
|
if (parent == null) return null;
|
|
319
|
-
if (
|
|
318
|
+
if (test(parent)) return parent;
|
|
320
319
|
parent = parent.parent;
|
|
321
320
|
}
|
|
322
321
|
return null;
|