@eslint-react/ast 3.0.0-rc.0 → 3.0.0-rc.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 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
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
- const chunk = getNestedIdentifiers(node.object);
431
- identifiers.push(...chunk);
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
- return (node) => {
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(getNestedExpressionsOfType(type));
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 = boundGetNestedExpressionsOfType(node.expression);
502
+ const chunk = recurse(node.expression);
488
503
  expressions.push(...chunk);
489
504
  }
490
505
  if ("left" in node) {
491
- const chunk = boundGetNestedExpressionsOfType(node.left);
506
+ const chunk = recurse(node.left);
492
507
  expressions.push(...chunk);
493
508
  }
494
509
  if ("right" in node) {
495
- const chunk = boundGetNestedExpressionsOfType(node.right);
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 = boundGetNestedExpressionsOfType(node.test);
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(boundGetNestedExpressionsOfType) : boundGetNestedExpressionsOfType(node.consequent);
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(boundGetNestedExpressionsOfType) : boundGetNestedExpressionsOfType(node.alternate);
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(getNestedExpressionsOfType(type));
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(boundGetNestedExpressionsOfType);
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(boundGetNestedExpressionsOfType);
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 = boundGetNestedExpressionsOfType(node.value);
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 = boundGetNestedExpressionsOfType(node.argument);
542
+ const chunk = recurse(node.argument);
528
543
  expressions.push(...chunk);
529
544
  }
530
545
  if (node.type === AST_NODE_TYPES.MemberExpression) {
531
- const chunk = boundGetNestedExpressionsOfType(node.object);
532
- expressions.push(...chunk);
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 = boundGetNestedExpressionsOfType(node.argument);
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.TSNonNullExpression) {
543
- const chunk = boundGetNestedExpressionsOfType(node.expression);
544
- expressions.push(...chunk);
545
- }
546
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
547
- const chunk = boundGetNestedExpressionsOfType(node.expression);
548
- expressions.push(...chunk);
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.0",
3
+ "version": "3.0.0-rc.1",
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.0",
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",