@eslint-react/ast 3.0.0-rc.0 → 3.0.0-rc.2
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 +8 -5
- package/dist/index.js +43 -34
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,9 @@ declare function isDirective(node: TSESTree.Node): node is TSESTreeDirective;
|
|
|
91
91
|
declare function isDirectiveLike(node: TSESTree.Node): node is TSESTreeDirectiveLike;
|
|
92
92
|
//#endregion
|
|
93
93
|
//#region src/directive-kind.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Known directive kinds in React
|
|
96
|
+
*/
|
|
94
97
|
type DirectiveKind = "use client" | "use server" | "use memo" | "use no memo";
|
|
95
98
|
/**
|
|
96
99
|
* Check if a node is a directive kind
|
|
@@ -190,7 +193,7 @@ declare function isDirectiveInFunction(node: TSESTreeFunction, name: string): bo
|
|
|
190
193
|
* where JS gives anonymous function expressions names. We roughly detect the
|
|
191
194
|
* same AST nodes with some exceptions to better fit our use case.
|
|
192
195
|
*/
|
|
193
|
-
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.
|
|
196
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | TSESTree.PrivateIdentifier | null;
|
|
194
197
|
/**
|
|
195
198
|
* Type representing the return type of getFunctionId
|
|
196
199
|
*/
|
|
@@ -314,13 +317,13 @@ declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TS
|
|
|
314
317
|
* @param node The node to check
|
|
315
318
|
* @returns True if the node is a function type
|
|
316
319
|
*/
|
|
317
|
-
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.
|
|
320
|
+
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
|
|
318
321
|
/**
|
|
319
322
|
* Check if a node is a class declaration or expression
|
|
320
323
|
* @param node The node to check
|
|
321
324
|
* @returns True if the node is a class
|
|
322
325
|
*/
|
|
323
|
-
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.
|
|
326
|
+
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassExpression | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName;
|
|
324
327
|
/**
|
|
325
328
|
* Check if a node is a method or property definition
|
|
326
329
|
* @param node The node to check
|
|
@@ -356,7 +359,7 @@ declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) =
|
|
|
356
359
|
* @param node The node to check
|
|
357
360
|
* @returns True if the node is a JSX node
|
|
358
361
|
*/
|
|
359
|
-
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.
|
|
362
|
+
declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
|
|
360
363
|
/**
|
|
361
364
|
* Check if a node is a loop statement
|
|
362
365
|
* @param node The node to check
|
|
@@ -374,7 +377,7 @@ declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is
|
|
|
374
377
|
* @param node The node to check
|
|
375
378
|
* @returns True if the node is conditional
|
|
376
379
|
*/
|
|
377
|
-
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.
|
|
380
|
+
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.LogicalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
|
|
378
381
|
/**
|
|
379
382
|
* Check if a node is a TypeScript type expression
|
|
380
383
|
* @param node The node to check
|
package/dist/index.js
CHANGED
|
@@ -427,8 +427,8 @@ function getNestedIdentifiers(node) {
|
|
|
427
427
|
identifiers.push(...chunk);
|
|
428
428
|
}
|
|
429
429
|
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
430
|
-
|
|
431
|
-
identifiers.push(...
|
|
430
|
+
identifiers.push(...getNestedIdentifiers(node.object));
|
|
431
|
+
if (node.computed) identifiers.push(...getNestedIdentifiers(node.property));
|
|
432
432
|
}
|
|
433
433
|
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
434
434
|
const chunk = getNestedIdentifiers(node.argument);
|
|
@@ -450,6 +450,22 @@ function getNestedIdentifiers(node) {
|
|
|
450
450
|
const chunk = getNestedIdentifiers(node.expression);
|
|
451
451
|
identifiers.push(...chunk);
|
|
452
452
|
}
|
|
453
|
+
if (node.type === AST_NODE_TYPES.ConditionalExpression) {
|
|
454
|
+
identifiers.push(...getNestedIdentifiers(node.test));
|
|
455
|
+
identifiers.push(...getNestedIdentifiers(node.consequent));
|
|
456
|
+
identifiers.push(...getNestedIdentifiers(node.alternate));
|
|
457
|
+
}
|
|
458
|
+
if (node.type === AST_NODE_TYPES.AwaitExpression) identifiers.push(...getNestedIdentifiers(node.argument));
|
|
459
|
+
if (node.type === AST_NODE_TYPES.YieldExpression && node.argument != null) identifiers.push(...getNestedIdentifiers(node.argument));
|
|
460
|
+
if (node.type === AST_NODE_TYPES.UpdateExpression) identifiers.push(...getNestedIdentifiers(node.argument));
|
|
461
|
+
if (node.type === AST_NODE_TYPES.CallExpression || node.type === AST_NODE_TYPES.NewExpression) identifiers.push(...getNestedIdentifiers(node.callee));
|
|
462
|
+
if (node.type === AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
463
|
+
identifiers.push(...getNestedIdentifiers(node.tag));
|
|
464
|
+
identifiers.push(...getNestedIdentifiers(node.quasi));
|
|
465
|
+
}
|
|
466
|
+
if (node.type === AST_NODE_TYPES.ImportExpression) identifiers.push(...getNestedIdentifiers(node.source));
|
|
467
|
+
if (node.type === AST_NODE_TYPES.TSTypeAssertion) identifiers.push(...getNestedIdentifiers(node.expression));
|
|
468
|
+
if (node.type === AST_NODE_TYPES.TSInstantiationExpression) identifiers.push(...getNestedIdentifiers(node.expression));
|
|
453
469
|
return identifiers;
|
|
454
470
|
}
|
|
455
471
|
/**
|
|
@@ -475,84 +491,77 @@ function getNestedReturnStatements(node) {
|
|
|
475
491
|
*/
|
|
476
492
|
function getNestedExpressionsOfType(type) {
|
|
477
493
|
const isNodeOfType = is(type);
|
|
478
|
-
|
|
479
|
-
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
494
|
+
const recurse = (node) => {
|
|
480
495
|
const expressions = [];
|
|
481
496
|
if (isNodeOfType(node)) expressions.push(node);
|
|
482
497
|
if ("arguments" in node) {
|
|
483
|
-
const chunk = node.arguments.flatMap(
|
|
498
|
+
const chunk = node.arguments.flatMap(recurse);
|
|
484
499
|
expressions.push(...chunk);
|
|
485
500
|
}
|
|
486
501
|
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
487
|
-
const chunk =
|
|
502
|
+
const chunk = recurse(node.expression);
|
|
488
503
|
expressions.push(...chunk);
|
|
489
504
|
}
|
|
490
505
|
if ("left" in node) {
|
|
491
|
-
const chunk =
|
|
506
|
+
const chunk = recurse(node.left);
|
|
492
507
|
expressions.push(...chunk);
|
|
493
508
|
}
|
|
494
509
|
if ("right" in node) {
|
|
495
|
-
const chunk =
|
|
510
|
+
const chunk = recurse(node.right);
|
|
496
511
|
expressions.push(...chunk);
|
|
497
512
|
}
|
|
498
513
|
if ("test" in node && node.test != null) {
|
|
499
|
-
const chunk =
|
|
514
|
+
const chunk = recurse(node.test);
|
|
500
515
|
expressions.push(...chunk);
|
|
501
516
|
}
|
|
502
517
|
if ("consequent" in node) {
|
|
503
|
-
const chunk = Array.isArray(node.consequent) ? node.consequent.flatMap(
|
|
518
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.flatMap(recurse) : recurse(node.consequent);
|
|
504
519
|
expressions.push(...chunk);
|
|
505
520
|
}
|
|
506
521
|
if ("alternate" in node && node.alternate != null) {
|
|
507
|
-
const chunk = Array.isArray(node.alternate) ? node.alternate.flatMap(
|
|
522
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.flatMap(recurse) : recurse(node.alternate);
|
|
508
523
|
expressions.push(...chunk);
|
|
509
524
|
}
|
|
510
525
|
if ("elements" in node) {
|
|
511
|
-
const chunk = node.elements.filter((x) => x != null).flatMap(
|
|
526
|
+
const chunk = node.elements.filter((x) => x != null).flatMap(recurse);
|
|
512
527
|
expressions.push(...chunk);
|
|
513
528
|
}
|
|
514
529
|
if ("properties" in node) {
|
|
515
|
-
const chunk = node.properties.flatMap(
|
|
530
|
+
const chunk = node.properties.flatMap(recurse);
|
|
516
531
|
expressions.push(...chunk);
|
|
517
532
|
}
|
|
518
533
|
if ("expressions" in node) {
|
|
519
|
-
const chunk = node.expressions.flatMap(
|
|
534
|
+
const chunk = node.expressions.flatMap(recurse);
|
|
520
535
|
expressions.push(...chunk);
|
|
521
536
|
}
|
|
522
537
|
if (node.type === AST_NODE_TYPES.Property) {
|
|
523
|
-
const chunk =
|
|
538
|
+
const chunk = recurse(node.value);
|
|
524
539
|
expressions.push(...chunk);
|
|
525
540
|
}
|
|
526
541
|
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
527
|
-
const chunk =
|
|
542
|
+
const chunk = recurse(node.argument);
|
|
528
543
|
expressions.push(...chunk);
|
|
529
544
|
}
|
|
530
545
|
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
531
|
-
|
|
532
|
-
expressions.push(...
|
|
546
|
+
expressions.push(...recurse(node.object));
|
|
547
|
+
if (node.computed) expressions.push(...recurse(node.property));
|
|
533
548
|
}
|
|
534
549
|
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
535
|
-
const chunk =
|
|
536
|
-
expressions.push(...chunk);
|
|
537
|
-
}
|
|
538
|
-
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
539
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
550
|
+
const chunk = recurse(node.argument);
|
|
540
551
|
expressions.push(...chunk);
|
|
541
552
|
}
|
|
542
|
-
if (node.type === AST_NODE_TYPES.
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (node.type === AST_NODE_TYPES.
|
|
547
|
-
|
|
548
|
-
expressions.push(...
|
|
549
|
-
}
|
|
550
|
-
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
551
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
552
|
-
expressions.push(...chunk);
|
|
553
|
+
if (node.type === AST_NODE_TYPES.AwaitExpression) expressions.push(...recurse(node.argument));
|
|
554
|
+
if (node.type === AST_NODE_TYPES.YieldExpression && node.argument != null) expressions.push(...recurse(node.argument));
|
|
555
|
+
if (node.type === AST_NODE_TYPES.UpdateExpression) expressions.push(...recurse(node.argument));
|
|
556
|
+
if (node.type === AST_NODE_TYPES.CallExpression || node.type === AST_NODE_TYPES.NewExpression) expressions.push(...recurse(node.callee));
|
|
557
|
+
if (node.type === AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
558
|
+
expressions.push(...recurse(node.tag));
|
|
559
|
+
expressions.push(...recurse(node.quasi));
|
|
553
560
|
}
|
|
561
|
+
if (node.type === AST_NODE_TYPES.ImportExpression) expressions.push(...recurse(node.source));
|
|
554
562
|
return expressions;
|
|
555
563
|
};
|
|
564
|
+
return recurse;
|
|
556
565
|
}
|
|
557
566
|
/**
|
|
558
567
|
* Get all nested new expressions in an expression like node
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.2",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"string-ts": "^2.3.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"tsdown": "^0.21.
|
|
39
|
+
"tsdown": "^0.21.2",
|
|
40
40
|
"@local/configs": "0.0.0",
|
|
41
41
|
"@local/eff": "3.0.0-beta.72"
|
|
42
42
|
},
|
|
@@ -47,6 +47,9 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=22.0.0"
|
|
49
49
|
},
|
|
50
|
+
"inlinedDependencies": {
|
|
51
|
+
"@local/eff": "workspace:*"
|
|
52
|
+
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"build": "tsdown --dts-resolve",
|
|
52
55
|
"lint:publish": "publint",
|