@eslint-react/ast 1.22.2-next.6 → 1.22.2-next.7

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 CHANGED
@@ -1,7 +1,8 @@
1
1
  import { O } from '@eslint-react/eff';
2
- import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
2
+ import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$2 } from '@typescript-eslint/types';
3
3
  import { TSESTree } from '@typescript-eslint/utils';
4
4
  import { SyntaxKind } from 'typescript';
5
+ import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
5
6
  import * as effect_Predicate from 'effect/Predicate';
6
7
 
7
8
  type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
@@ -2285,6 +2286,16 @@ declare interface YieldExpression extends BaseNode {
2285
2286
  */
2286
2287
  declare const getNestedCallExpressions: (node: Node) => CallExpression[];
2287
2288
 
2289
+ /**
2290
+ * Get all nested expressions of type T in an expression like node
2291
+ * @param type The type of the expression to retrieve within the node
2292
+ * @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
2293
+ * node, and it will return an array of all nested expressions of type T.
2294
+ */
2295
+ declare function getNestedExpressionsOfType<T extends AST_NODE_TYPES$1>(type: T): (node: TSESTree$1.Node) => Extract<TSESTree$1.Node, {
2296
+ type: T;
2297
+ }>[];
2298
+
2288
2299
  /**
2289
2300
  * Get all nested identifiers in a expression like node
2290
2301
  * @param node The node to get the nested identifiers from
@@ -2308,10 +2319,10 @@ declare function getNestedReturnStatements(node: TSESTree$1.Node): readonly TSES
2308
2319
 
2309
2320
  declare function getTopLevelIdentifier(node: TSESTree$1.Node): O.Option<TSESTree$1.Identifier>;
2310
2321
 
2311
- declare const is: <NodeType extends AST_NODE_TYPES$1>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2322
+ declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2312
2323
  type: NodeType;
2313
2324
  }>;
2314
- declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$1[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2325
+ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2315
2326
  type: NodeTypes[number];
2316
2327
  }>;
2317
2328
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
@@ -2330,6 +2341,7 @@ declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) =
2330
2341
  declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
2331
2342
  declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.ClassExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.ArrayPattern | TSESTree.ObjectPattern | TSESTree.CallExpression | TSESTree.ObjectExpression | TSESTree.ArrayExpression | TSESTree.Identifier | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
2332
2343
  declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.ClassExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.ArrayPattern | TSESTree.ObjectPattern | TSESTree.CallExpression | TSESTree.ObjectExpression | TSESTree.ArrayExpression | TSESTree.Identifier | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
2344
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
2333
2345
 
2334
2346
  declare function isEmptyFunction(node: TSESTreeFunction): boolean;
2335
2347
 
@@ -2424,4 +2436,15 @@ declare const traverseUpGuard: {
2424
2436
  <T extends TSESTree$1.Node>(predicate: (node: TSESTree$1.Node) => node is T): (node: TSESTree$1.Node) => O.Option<T>;
2425
2437
  };
2426
2438
 
2427
- export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard };
2439
+ /**
2440
+ * Traverses up the AST tree until the predicate returns `true` or the stop node is reached
2441
+ * @param node The AST node to start traversing from
2442
+ * @param stopNode The AST node to stop traversing at
2443
+ * @param predicate The predicate to check each node
2444
+ * @returns The first node that matches the predicate or `null` if no node matches
2445
+ */
2446
+ declare function traverseUpStop(node: TSESTree$1.Node, stopNode: TSESTree$1.Node, predicate: (node: TSESTree$1.Node) => boolean): O.Option<TSESTree$1.Node>;
2447
+
2448
+ declare function unwrapTypeExpression(node: TSESTree$1.Node): TSESTree$1.Node;
2449
+
2450
+ export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard, traverseUpStop, unwrapTypeExpression };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { O } from '@eslint-react/eff';
2
- import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
2
+ import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$2 } from '@typescript-eslint/types';
3
3
  import { TSESTree } from '@typescript-eslint/utils';
4
4
  import { SyntaxKind } from 'typescript';
5
+ import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/typescript-estree';
5
6
  import * as effect_Predicate from 'effect/Predicate';
6
7
 
7
8
  type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
@@ -2285,6 +2286,16 @@ declare interface YieldExpression extends BaseNode {
2285
2286
  */
2286
2287
  declare const getNestedCallExpressions: (node: Node) => CallExpression[];
2287
2288
 
2289
+ /**
2290
+ * Get all nested expressions of type T in an expression like node
2291
+ * @param type The type of the expression to retrieve within the node
2292
+ * @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
2293
+ * node, and it will return an array of all nested expressions of type T.
2294
+ */
2295
+ declare function getNestedExpressionsOfType<T extends AST_NODE_TYPES$1>(type: T): (node: TSESTree$1.Node) => Extract<TSESTree$1.Node, {
2296
+ type: T;
2297
+ }>[];
2298
+
2288
2299
  /**
2289
2300
  * Get all nested identifiers in a expression like node
2290
2301
  * @param node The node to get the nested identifiers from
@@ -2308,10 +2319,10 @@ declare function getNestedReturnStatements(node: TSESTree$1.Node): readonly TSES
2308
2319
 
2309
2320
  declare function getTopLevelIdentifier(node: TSESTree$1.Node): O.Option<TSESTree$1.Identifier>;
2310
2321
 
2311
- declare const is: <NodeType extends AST_NODE_TYPES$1>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2322
+ declare const is: <NodeType extends AST_NODE_TYPES$2>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2312
2323
  type: NodeType;
2313
2324
  }>;
2314
- declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$1[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2325
+ declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES$2[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
2315
2326
  type: NodeTypes[number];
2316
2327
  }>;
2317
2328
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
@@ -2330,6 +2341,7 @@ declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) =
2330
2341
  declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
2331
2342
  declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.ClassExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.ArrayPattern | TSESTree.ObjectPattern | TSESTree.CallExpression | TSESTree.ObjectExpression | TSESTree.ArrayExpression | TSESTree.Identifier | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
2332
2343
  declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.ClassExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.ArrayPattern | TSESTree.ObjectPattern | TSESTree.CallExpression | TSESTree.ObjectExpression | TSESTree.ArrayExpression | TSESTree.Identifier | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
2344
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
2333
2345
 
2334
2346
  declare function isEmptyFunction(node: TSESTreeFunction): boolean;
2335
2347
 
@@ -2424,4 +2436,15 @@ declare const traverseUpGuard: {
2424
2436
  <T extends TSESTree$1.Node>(predicate: (node: TSESTree$1.Node) => node is T): (node: TSESTree$1.Node) => O.Option<T>;
2425
2437
  };
2426
2438
 
2427
- export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard };
2439
+ /**
2440
+ * Traverses up the AST tree until the predicate returns `true` or the stop node is reached
2441
+ * @param node The AST node to start traversing from
2442
+ * @param stopNode The AST node to stop traversing at
2443
+ * @param predicate The predicate to check each node
2444
+ * @returns The first node that matches the predicate or `null` if no node matches
2445
+ */
2446
+ declare function traverseUpStop(node: TSESTree$1.Node, stopNode: TSESTree$1.Node, predicate: (node: TSESTree$1.Node) => boolean): O.Option<TSESTree$1.Node>;
2447
+
2448
+ declare function unwrapTypeExpression(node: TSESTree$1.Node): TSESTree$1.Node;
2449
+
2450
+ export { type FunctionInitPath, type ReadableNodeType, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeProperty, type TSESTreeTypeDeclaration, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard, traverseUpStop, unwrapTypeExpression };
package/dist/index.js CHANGED
@@ -230,6 +230,12 @@ var isLeftHandSideExpressionType = isOneOf([
230
230
  types.AST_NODE_TYPES.TSNonNullExpression,
231
231
  types.AST_NODE_TYPES.TSTypeAssertion
232
232
  ]);
233
+ var isTypeExpression = isOneOf([
234
+ types.AST_NODE_TYPES.TSAsExpression,
235
+ types.AST_NODE_TYPES.TSTypeAssertion,
236
+ types.AST_NODE_TYPES.TSNonNullExpression,
237
+ types.AST_NODE_TYPES.TSSatisfiesExpression
238
+ ]);
233
239
 
234
240
  // src/get-function-identifier.ts
235
241
  function getFunctionIdentifier(node) {
@@ -257,9 +263,10 @@ function getFunctionIdentifier(node) {
257
263
  // ({MaybeComponent = () => {}} = {});
258
264
  case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
259
265
  return eff.O.some(node.parent.left);
266
+ // const MaybeComponent = (() => {})!;
260
267
  // const MaybeComponent = (() => {}) as FunctionComponent;
261
268
  // const MaybeComponent = (() => {}) satisfies FunctionComponent;
262
- case isOneOf([types.AST_NODE_TYPES.TSAsExpression, types.AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
269
+ case isTypeExpression(node.parent):
263
270
  return getFunctionIdentifier(node.parent);
264
271
  }
265
272
  return eff.O.none();
@@ -349,6 +356,14 @@ function getNestedExpressionsOfType(type) {
349
356
  const chunk = boundGetNestedExpressionsOfType(node.expression);
350
357
  expressions.push(...chunk);
351
358
  }
359
+ if (node.type === typescriptEstree.AST_NODE_TYPES.TSAsExpression) {
360
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
361
+ expressions.push(...chunk);
362
+ }
363
+ if (node.type === typescriptEstree.AST_NODE_TYPES.TSSatisfiesExpression) {
364
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
365
+ expressions.push(...chunk);
366
+ }
352
367
  return expressions;
353
368
  };
354
369
  }
@@ -408,6 +423,14 @@ function getNestedIdentifiers(node) {
408
423
  const chunk = getNestedIdentifiers(node.expression);
409
424
  identifiers.push(...chunk);
410
425
  }
426
+ if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
427
+ const chunk = getNestedIdentifiers(node.expression);
428
+ identifiers.push(...chunk);
429
+ }
430
+ if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
431
+ const chunk = getNestedIdentifiers(node.expression);
432
+ identifiers.push(...chunk);
433
+ }
411
434
  return identifiers;
412
435
  }
413
436
  var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
@@ -490,26 +513,36 @@ function isMultiLine(node) {
490
513
  return node.loc.start.line !== node.loc.end.line;
491
514
  }
492
515
  var isNodeEqual = eff.F.dual(2, (a, b) => {
493
- if (a.type !== b.type) return false;
494
- if (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression) return true;
495
- if (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal) return a.value === b.value;
496
- if (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement) {
497
- return a.value.raw === b.value.raw;
498
- }
499
- if (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral) {
500
- if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
501
- if (!types$1.zip(a.quasis, b.quasis).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
502
- if (!types$1.zip(a.expressions, b.expressions).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
503
- return true;
504
- }
505
- if (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier) return a.name === b.name;
506
- if (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier) {
507
- return a.name === b.name;
508
- }
509
- if (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression) {
510
- return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
511
- }
512
- return false;
516
+ switch (true) {
517
+ case a === b:
518
+ return true;
519
+ case a.type !== b.type:
520
+ return false;
521
+ case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal):
522
+ return a.value === b.value;
523
+ case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement):
524
+ return a.value.raw === b.value.raw;
525
+ case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral):
526
+ if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
527
+ if (!types$1.zip(a.quasis, b.quasis).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
528
+ if (!types$1.zip(a.expressions, b.expressions).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
529
+ return true;
530
+ case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier):
531
+ return a.name === b.name;
532
+ case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier):
533
+ return a.name === b.name;
534
+ case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression):
535
+ return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
536
+ case (a.type === types.AST_NODE_TYPES.JSXAttribute && b.type === types.AST_NODE_TYPES.JSXAttribute): {
537
+ if (a.name.name !== b.name.name) return false;
538
+ if (a.value === null || b.value === null) return a.value === b.value;
539
+ return isNodeEqual(a.value, b.value);
540
+ }
541
+ case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression):
542
+ return true;
543
+ default:
544
+ return false;
545
+ }
513
546
  });
514
547
  function isRegExpLiteral(node) {
515
548
  return node.type === types.AST_NODE_TYPES.Literal && "regex" in node;
@@ -518,7 +551,7 @@ function isStringLiteral(node) {
518
551
  return node.type === types.AST_NODE_TYPES.Literal && eff.isString(node.value);
519
552
  }
520
553
  function isThisExpression(node) {
521
- if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
554
+ if (isTypeExpression(node)) {
522
555
  return isThisExpression(node.expression);
523
556
  }
524
557
  return node.type === types.AST_NODE_TYPES.ThisExpression;
@@ -558,6 +591,17 @@ var traverseUp = eff.F.dual(2, (node, predicate) => {
558
591
  if (!parent || parent.type === types.AST_NODE_TYPES.Program) return eff.O.none();
559
592
  return predicate(parent) ? eff.O.some(parent) : traverseUp(parent, predicate);
560
593
  });
594
+ function traverseUpStop(node, stopNode, predicate) {
595
+ const { parent } = node;
596
+ if (!parent || parent === stopNode || parent.type === types.AST_NODE_TYPES.Program) return eff.O.none();
597
+ return predicate(parent) ? eff.O.some(parent) : traverseUpStop(parent, stopNode, predicate);
598
+ }
599
+
600
+ // src/unwrap-type-expression.ts
601
+ function unwrapTypeExpression(node) {
602
+ if (isTypeExpression(node)) return unwrapTypeExpression(node.expression);
603
+ return node;
604
+ }
561
605
 
562
606
  exports.getClassIdentifier = getClassIdentifier;
563
607
  exports.getFunctionIdentifier = getFunctionIdentifier;
@@ -565,6 +609,7 @@ exports.getFunctionInitPath = getFunctionInitPath;
565
609
  exports.getIdentifiersFromBinaryExpression = getIdentifiersFromBinaryExpression;
566
610
  exports.getLiteralValueType = getLiteralValueType;
567
611
  exports.getNestedCallExpressions = getNestedCallExpressions;
612
+ exports.getNestedExpressionsOfType = getNestedExpressionsOfType;
568
613
  exports.getNestedIdentifiers = getNestedIdentifiers;
569
614
  exports.getNestedNewExpressions = getNestedNewExpressions;
570
615
  exports.getNestedReturnStatements = getNestedReturnStatements;
@@ -600,7 +645,10 @@ exports.isRegExpLiteral = isRegExpLiteral;
600
645
  exports.isStringLiteral = isStringLiteral;
601
646
  exports.isThisExpression = isThisExpression;
602
647
  exports.isTypeDeclaration = isTypeDeclaration;
648
+ exports.isTypeExpression = isTypeExpression;
603
649
  exports.toReadableNodeName = toReadableNodeName;
604
650
  exports.toReadableNodeType = toReadableNodeType;
605
651
  exports.traverseUp = traverseUp;
606
652
  exports.traverseUpGuard = traverseUpGuard;
653
+ exports.traverseUpStop = traverseUpStop;
654
+ exports.unwrapTypeExpression = unwrapTypeExpression;
package/dist/index.mjs CHANGED
@@ -228,6 +228,12 @@ var isLeftHandSideExpressionType = isOneOf([
228
228
  AST_NODE_TYPES.TSNonNullExpression,
229
229
  AST_NODE_TYPES.TSTypeAssertion
230
230
  ]);
231
+ var isTypeExpression = isOneOf([
232
+ AST_NODE_TYPES.TSAsExpression,
233
+ AST_NODE_TYPES.TSTypeAssertion,
234
+ AST_NODE_TYPES.TSNonNullExpression,
235
+ AST_NODE_TYPES.TSSatisfiesExpression
236
+ ]);
231
237
 
232
238
  // src/get-function-identifier.ts
233
239
  function getFunctionIdentifier(node) {
@@ -255,9 +261,10 @@ function getFunctionIdentifier(node) {
255
261
  // ({MaybeComponent = () => {}} = {});
256
262
  case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
257
263
  return O.some(node.parent.left);
264
+ // const MaybeComponent = (() => {})!;
258
265
  // const MaybeComponent = (() => {}) as FunctionComponent;
259
266
  // const MaybeComponent = (() => {}) satisfies FunctionComponent;
260
- case isOneOf([AST_NODE_TYPES.TSAsExpression, AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
267
+ case isTypeExpression(node.parent):
261
268
  return getFunctionIdentifier(node.parent);
262
269
  }
263
270
  return O.none();
@@ -347,6 +354,14 @@ function getNestedExpressionsOfType(type) {
347
354
  const chunk = boundGetNestedExpressionsOfType(node.expression);
348
355
  expressions.push(...chunk);
349
356
  }
357
+ if (node.type === AST_NODE_TYPES$1.TSAsExpression) {
358
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
359
+ expressions.push(...chunk);
360
+ }
361
+ if (node.type === AST_NODE_TYPES$1.TSSatisfiesExpression) {
362
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
363
+ expressions.push(...chunk);
364
+ }
350
365
  return expressions;
351
366
  };
352
367
  }
@@ -406,6 +421,14 @@ function getNestedIdentifiers(node) {
406
421
  const chunk = getNestedIdentifiers(node.expression);
407
422
  identifiers.push(...chunk);
408
423
  }
424
+ if (node.type === AST_NODE_TYPES.TSAsExpression) {
425
+ const chunk = getNestedIdentifiers(node.expression);
426
+ identifiers.push(...chunk);
427
+ }
428
+ if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
429
+ const chunk = getNestedIdentifiers(node.expression);
430
+ identifiers.push(...chunk);
431
+ }
409
432
  return identifiers;
410
433
  }
411
434
  var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
@@ -488,26 +511,36 @@ function isMultiLine(node) {
488
511
  return node.loc.start.line !== node.loc.end.line;
489
512
  }
490
513
  var isNodeEqual = F.dual(2, (a, b) => {
491
- if (a.type !== b.type) return false;
492
- if (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression) return true;
493
- if (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal) return a.value === b.value;
494
- if (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement) {
495
- return a.value.raw === b.value.raw;
496
- }
497
- if (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral) {
498
- if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
499
- if (!zip(a.quasis, b.quasis).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
500
- if (!zip(a.expressions, b.expressions).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
501
- return true;
502
- }
503
- if (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier) return a.name === b.name;
504
- if (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier) {
505
- return a.name === b.name;
506
- }
507
- if (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression) {
508
- return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
509
- }
510
- return false;
514
+ switch (true) {
515
+ case a === b:
516
+ return true;
517
+ case a.type !== b.type:
518
+ return false;
519
+ case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal):
520
+ return a.value === b.value;
521
+ case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
522
+ return a.value.raw === b.value.raw;
523
+ case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral):
524
+ if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
525
+ if (!zip(a.quasis, b.quasis).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
526
+ if (!zip(a.expressions, b.expressions).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
527
+ return true;
528
+ case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
529
+ return a.name === b.name;
530
+ case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
531
+ return a.name === b.name;
532
+ case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
533
+ return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
534
+ case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): {
535
+ if (a.name.name !== b.name.name) return false;
536
+ if (a.value === null || b.value === null) return a.value === b.value;
537
+ return isNodeEqual(a.value, b.value);
538
+ }
539
+ case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
540
+ return true;
541
+ default:
542
+ return false;
543
+ }
511
544
  });
512
545
  function isRegExpLiteral(node) {
513
546
  return node.type === AST_NODE_TYPES.Literal && "regex" in node;
@@ -516,7 +549,7 @@ function isStringLiteral(node) {
516
549
  return node.type === AST_NODE_TYPES.Literal && isString(node.value);
517
550
  }
518
551
  function isThisExpression(node) {
519
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
552
+ if (isTypeExpression(node)) {
520
553
  return isThisExpression(node.expression);
521
554
  }
522
555
  return node.type === AST_NODE_TYPES.ThisExpression;
@@ -556,5 +589,16 @@ var traverseUp = F.dual(2, (node, predicate) => {
556
589
  if (!parent || parent.type === AST_NODE_TYPES.Program) return O.none();
557
590
  return predicate(parent) ? O.some(parent) : traverseUp(parent, predicate);
558
591
  });
592
+ function traverseUpStop(node, stopNode, predicate) {
593
+ const { parent } = node;
594
+ if (!parent || parent === stopNode || parent.type === AST_NODE_TYPES.Program) return O.none();
595
+ return predicate(parent) ? O.some(parent) : traverseUpStop(parent, stopNode, predicate);
596
+ }
597
+
598
+ // src/unwrap-type-expression.ts
599
+ function unwrapTypeExpression(node) {
600
+ if (isTypeExpression(node)) return unwrapTypeExpression(node.expression);
601
+ return node;
602
+ }
559
603
 
560
- export { getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard };
604
+ export { getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getIdentifiersFromBinaryExpression, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionOfClassMethod, isFunctionOfClassProperty, isFunctionOfImmediatelyInvoked, isFunctionOfObjectMethod, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMultiLine, isNodeEqual, isOneOf, isProperty, isRegExpLiteral, isStringLiteral, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, traverseUp, traverseUpGuard, traverseUpStop, unwrapTypeExpression };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "1.22.2-next.6",
3
+ "version": "1.22.2-next.7",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/rEl1cx/eslint-react",
6
6
  "bugs": {
@@ -38,8 +38,8 @@
38
38
  "@typescript-eslint/utils": "^8.18.2",
39
39
  "string-ts": "^2.2.0",
40
40
  "ts-pattern": "^5.6.0",
41
- "@eslint-react/types": "1.22.2-next.6",
42
- "@eslint-react/eff": "1.22.2-next.6"
41
+ "@eslint-react/eff": "1.22.2-next.7",
42
+ "@eslint-react/types": "1.22.2-next.7"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.3.5",