@eslint-react/ast 1.15.0 → 1.15.1-beta.14
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 +136 -128
- package/dist/index.d.ts +136 -128
- package/dist/index.js +34 -21
- package/dist/index.mjs +34 -21
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -232,21 +232,34 @@ var isLeftHandSideExpressionType = isOneOf([
|
|
|
232
232
|
|
|
233
233
|
// src/get-function-identifier.ts
|
|
234
234
|
function getFunctionIdentifier(node) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
235
|
+
switch (true) {
|
|
236
|
+
// function MaybeComponent() {}
|
|
237
|
+
case ("id" in node && !!node.id):
|
|
238
|
+
return tools.O.some(node.id);
|
|
239
|
+
// const whatever = function MaybeComponent() {};
|
|
240
|
+
case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
|
|
241
|
+
return tools.O.some(node.parent.id);
|
|
242
|
+
// MaybeComponent = () => {};
|
|
243
|
+
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):
|
|
244
|
+
return tools.O.some(node.parent.left);
|
|
245
|
+
// {MaybeComponent: () => {}}
|
|
246
|
+
// {MaybeComponent() {}}
|
|
247
|
+
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):
|
|
248
|
+
return tools.O.some(node.parent.key);
|
|
249
|
+
// class {MaybeComponent = () => {}}
|
|
250
|
+
// class {MaybeComponent() {}}
|
|
251
|
+
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):
|
|
252
|
+
return tools.O.some(node.parent.key);
|
|
253
|
+
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
254
|
+
//
|
|
255
|
+
// const {MaybeComponent = () => {}} = {};
|
|
256
|
+
// ({MaybeComponent = () => {}} = {});
|
|
257
|
+
case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
|
|
258
|
+
return tools.O.some(node.parent.left);
|
|
259
|
+
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
260
|
+
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
261
|
+
case isOneOf([types.AST_NODE_TYPES.TSAsExpression, types.AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
|
|
262
|
+
return getFunctionIdentifier(node.parent);
|
|
250
263
|
}
|
|
251
264
|
return tools.O.none();
|
|
252
265
|
}
|
|
@@ -511,14 +524,10 @@ function isThisExpression(node) {
|
|
|
511
524
|
}
|
|
512
525
|
function toReadableNodeName(node, getText) {
|
|
513
526
|
switch (node.type) {
|
|
514
|
-
case types.AST_NODE_TYPES.Literal:
|
|
515
|
-
return node.raw;
|
|
516
|
-
case types.AST_NODE_TYPES.Identifier:
|
|
517
|
-
return node.name;
|
|
518
|
-
case types.AST_NODE_TYPES.MemberExpression:
|
|
519
|
-
return `${toReadableNodeName(node.object, getText)}.${toReadableNodeName(node.property, getText)}`;
|
|
520
527
|
case types.AST_NODE_TYPES.CallExpression:
|
|
521
528
|
return toReadableNodeName(node.callee, getText);
|
|
529
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
530
|
+
return node.name;
|
|
522
531
|
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
523
532
|
return `<${node.name}>`;
|
|
524
533
|
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
@@ -527,6 +536,10 @@ function toReadableNodeName(node, getText) {
|
|
|
527
536
|
return `${node.namespace.name}:${node.name.name}`;
|
|
528
537
|
case types.AST_NODE_TYPES.JSXText:
|
|
529
538
|
return node.value;
|
|
539
|
+
case types.AST_NODE_TYPES.Literal:
|
|
540
|
+
return node.raw;
|
|
541
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
542
|
+
return `${toReadableNodeName(node.object, getText)}.${toReadableNodeName(node.property, getText)}`;
|
|
530
543
|
default:
|
|
531
544
|
return getText(node);
|
|
532
545
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -230,21 +230,34 @@ var isLeftHandSideExpressionType = isOneOf([
|
|
|
230
230
|
|
|
231
231
|
// src/get-function-identifier.ts
|
|
232
232
|
function getFunctionIdentifier(node) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
233
|
+
switch (true) {
|
|
234
|
+
// function MaybeComponent() {}
|
|
235
|
+
case ("id" in node && !!node.id):
|
|
236
|
+
return O.some(node.id);
|
|
237
|
+
// const whatever = function MaybeComponent() {};
|
|
238
|
+
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
239
|
+
return O.some(node.parent.id);
|
|
240
|
+
// MaybeComponent = () => {};
|
|
241
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
242
|
+
return O.some(node.parent.left);
|
|
243
|
+
// {MaybeComponent: () => {}}
|
|
244
|
+
// {MaybeComponent() {}}
|
|
245
|
+
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
246
|
+
return O.some(node.parent.key);
|
|
247
|
+
// class {MaybeComponent = () => {}}
|
|
248
|
+
// class {MaybeComponent() {}}
|
|
249
|
+
case (isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
250
|
+
return O.some(node.parent.key);
|
|
251
|
+
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
252
|
+
//
|
|
253
|
+
// const {MaybeComponent = () => {}} = {};
|
|
254
|
+
// ({MaybeComponent = () => {}} = {});
|
|
255
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
256
|
+
return O.some(node.parent.left);
|
|
257
|
+
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
258
|
+
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
259
|
+
case isOneOf([AST_NODE_TYPES.TSAsExpression, AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
|
|
260
|
+
return getFunctionIdentifier(node.parent);
|
|
248
261
|
}
|
|
249
262
|
return O.none();
|
|
250
263
|
}
|
|
@@ -509,14 +522,10 @@ function isThisExpression(node) {
|
|
|
509
522
|
}
|
|
510
523
|
function toReadableNodeName(node, getText) {
|
|
511
524
|
switch (node.type) {
|
|
512
|
-
case AST_NODE_TYPES.Literal:
|
|
513
|
-
return node.raw;
|
|
514
|
-
case AST_NODE_TYPES.Identifier:
|
|
515
|
-
return node.name;
|
|
516
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
517
|
-
return `${toReadableNodeName(node.object, getText)}.${toReadableNodeName(node.property, getText)}`;
|
|
518
525
|
case AST_NODE_TYPES.CallExpression:
|
|
519
526
|
return toReadableNodeName(node.callee, getText);
|
|
527
|
+
case AST_NODE_TYPES.Identifier:
|
|
528
|
+
return node.name;
|
|
520
529
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
521
530
|
return `<${node.name}>`;
|
|
522
531
|
case AST_NODE_TYPES.JSXMemberExpression:
|
|
@@ -525,6 +534,10 @@ function toReadableNodeName(node, getText) {
|
|
|
525
534
|
return `${node.namespace.name}:${node.name.name}`;
|
|
526
535
|
case AST_NODE_TYPES.JSXText:
|
|
527
536
|
return node.value;
|
|
537
|
+
case AST_NODE_TYPES.Literal:
|
|
538
|
+
return node.raw;
|
|
539
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
540
|
+
return `${toReadableNodeName(node.object, getText)}.${toReadableNodeName(node.property, getText)}`;
|
|
528
541
|
default:
|
|
529
542
|
return getText(node);
|
|
530
543
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.1-beta.14",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"./package.json"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@typescript-eslint/types": "^8.
|
|
39
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
40
|
-
"@typescript-eslint/utils": "^8.
|
|
38
|
+
"@typescript-eslint/types": "^8.11.0",
|
|
39
|
+
"@typescript-eslint/typescript-estree": "^8.11.0",
|
|
40
|
+
"@typescript-eslint/utils": "^8.11.0",
|
|
41
41
|
"birecord": "^0.1.1",
|
|
42
42
|
"string-ts": "^2.2.0",
|
|
43
|
-
"ts-pattern": "^5.
|
|
44
|
-
"@eslint-react/tools": "1.15.
|
|
45
|
-
"@eslint-react/types": "1.15.
|
|
43
|
+
"ts-pattern": "^5.5.0",
|
|
44
|
+
"@eslint-react/tools": "1.15.1-beta.14",
|
|
45
|
+
"@eslint-react/types": "1.15.1-beta.14"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"tsup": "^8.3.0"
|