@eslint-react/ast 1.20.1 → 1.20.2-beta.3

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,4 +1,4 @@
1
- import { O } from '@eslint-react/tools';
1
+ import { O } from '@eslint-react/eff';
2
2
  import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
3
3
  import { TSESTree } from '@typescript-eslint/utils';
4
4
  import { SyntaxKind } from 'typescript';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O } from '@eslint-react/tools';
1
+ import { O } from '@eslint-react/eff';
2
2
  import { TSESTree as TSESTree$1, AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
3
3
  import { TSESTree } from '@typescript-eslint/utils';
4
4
  import { SyntaxKind } from 'typescript';
package/dist/index.js CHANGED
@@ -1,25 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var tools = require('@eslint-react/tools');
3
+ var eff = require('@eslint-react/eff');
4
4
  var types = require('@typescript-eslint/types');
5
5
  var utils = require('@typescript-eslint/utils');
6
6
  var tsPattern = require('ts-pattern');
7
7
  var typescriptEstree = require('@typescript-eslint/typescript-estree');
8
+ var types$1 = require('@eslint-react/types');
8
9
  var stringTs = require('string-ts');
9
10
 
10
11
  // src/function-init-path.ts
11
12
  function getFunctionInitPath(node) {
12
13
  const { parent } = node;
13
- if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) return tools.O.some([node]);
14
+ if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) return eff.O.some([node]);
14
15
  if (parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
15
- return tools.O.some([
16
+ return eff.O.some([
16
17
  parent.parent,
17
18
  parent,
18
19
  node
19
20
  ]);
20
21
  }
21
22
  if (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
22
- return tools.O.some([
23
+ return eff.O.some([
23
24
  parent.parent.parent,
24
25
  parent.parent,
25
26
  parent,
@@ -27,7 +28,7 @@ function getFunctionInitPath(node) {
27
28
  ]);
28
29
  }
29
30
  if (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
30
- return tools.O.some([
31
+ return eff.O.some([
31
32
  parent.parent.parent.parent,
32
33
  parent.parent.parent,
33
34
  parent.parent,
@@ -36,7 +37,7 @@ function getFunctionInitPath(node) {
36
37
  ]);
37
38
  }
38
39
  if (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator) {
39
- return tools.O.some([
40
+ return eff.O.some([
40
41
  parent.parent.parent.parent,
41
42
  parent.parent.parent,
42
43
  parent.parent,
@@ -45,7 +46,7 @@ function getFunctionInitPath(node) {
45
46
  ]);
46
47
  }
47
48
  if (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
48
- return tools.O.some([
49
+ return eff.O.some([
49
50
  parent.parent.parent,
50
51
  parent.parent,
51
52
  parent,
@@ -53,21 +54,21 @@ function getFunctionInitPath(node) {
53
54
  ]);
54
55
  }
55
56
  if (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration) {
56
- return tools.O.some([
57
+ return eff.O.some([
57
58
  parent.parent.parent,
58
59
  parent.parent,
59
60
  parent,
60
61
  node
61
62
  ]);
62
63
  }
63
- return tools.O.none();
64
+ return eff.O.none();
64
65
  }
65
66
  function hasCallInFunctionInitPath(callName) {
66
67
  return (initPath) => {
67
- return tools.F.pipe(
68
+ return eff.F.pipe(
68
69
  initPath,
69
- tools.O.filter((p) => p.length > 0),
70
- tools.O.exists((nodes) => {
70
+ eff.O.filter((p) => p.length > 0),
71
+ eff.O.exists((nodes) => {
71
72
  return nodes.some(
72
73
  // TODO: Re-evaluate dot notation callName
73
74
  // callName.includes(".")
@@ -96,11 +97,11 @@ function hasCallInFunctionInitPath(callName) {
96
97
  };
97
98
  }
98
99
  function getClassIdentifier(node) {
99
- if (node.id) return tools.O.fromNullable(node.id);
100
+ if (node.id) return eff.O.fromNullable(node.id);
100
101
  if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
101
- return tools.O.fromNullable(node.parent.id);
102
+ return eff.O.fromNullable(node.parent.id);
102
103
  }
103
- return tools.O.none();
104
+ return eff.O.none();
104
105
  }
105
106
  var is = utils.ASTUtils.isNodeOfType;
106
107
  var isOneOf = utils.ASTUtils.isNodeOfTypes;
@@ -128,14 +129,14 @@ var isLoop = isOneOf([
128
129
  types.AST_NODE_TYPES.ForStatement,
129
130
  types.AST_NODE_TYPES.WhileStatement
130
131
  ]);
131
- var isControlFlow = tools.or(
132
+ var isControlFlow = eff.or(
132
133
  isLoop,
133
134
  isOneOf([
134
135
  types.AST_NODE_TYPES.IfStatement,
135
136
  types.AST_NODE_TYPES.SwitchStatement
136
137
  ])
137
138
  );
138
- var isConditional = tools.or(
139
+ var isConditional = eff.or(
139
140
  isControlFlow,
140
141
  isOneOf([
141
142
  types.AST_NODE_TYPES.LogicalExpression,
@@ -235,33 +236,33 @@ function getFunctionIdentifier(node) {
235
236
  switch (true) {
236
237
  // function MaybeComponent() {}
237
238
  case ("id" in node && !!node.id):
238
- return tools.O.some(node.id);
239
+ return eff.O.some(node.id);
239
240
  // const whatever = function MaybeComponent() {};
240
241
  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
+ return eff.O.some(node.parent.id);
242
243
  // MaybeComponent = () => {};
243
244
  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
+ return eff.O.some(node.parent.left);
245
246
  // {MaybeComponent: () => {}}
246
247
  // {MaybeComponent() {}}
247
248
  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
+ return eff.O.some(node.parent.key);
249
250
  // class {MaybeComponent = () => {}}
250
251
  // class {MaybeComponent() {}}
251
252
  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
+ return eff.O.some(node.parent.key);
253
254
  // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
254
255
  //
255
256
  // const {MaybeComponent = () => {}} = {};
256
257
  // ({MaybeComponent = () => {}} = {});
257
258
  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
+ return eff.O.some(node.parent.left);
259
260
  // const MaybeComponent = (() => {}) as FunctionComponent;
260
261
  // const MaybeComponent = (() => {}) satisfies FunctionComponent;
261
262
  case isOneOf([types.AST_NODE_TYPES.TSAsExpression, types.AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
262
263
  return getFunctionIdentifier(node.parent);
263
264
  }
264
- return tools.O.none();
265
+ return eff.O.none();
265
266
  }
266
267
  function getIdentifiersFromBinaryExpression(side) {
267
268
  if (side.type === types.AST_NODE_TYPES.Identifier) return [side];
@@ -410,20 +411,20 @@ function getNestedIdentifiers(node) {
410
411
  return identifiers;
411
412
  }
412
413
  var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
413
- var traverseUpGuard = tools.F.dual(2, (node, predicate) => {
414
+ var traverseUpGuard = eff.F.dual(2, (node, predicate) => {
414
415
  const { parent } = node;
415
- if (!parent || parent.type === types.AST_NODE_TYPES.Program) return tools.O.none();
416
- return predicate(parent) ? tools.O.some(parent) : traverseUpGuard(parent, predicate);
416
+ if (!parent || parent.type === types.AST_NODE_TYPES.Program) return eff.O.none();
417
+ return predicate(parent) ? eff.O.some(parent) : traverseUpGuard(parent, predicate);
417
418
  });
418
419
 
419
420
  // src/get-nested-return-statements.ts
420
421
  function getNestedReturnStatements(node) {
421
422
  const returnStatements = [];
422
- const functionNode = isFunction(node) ? node : tools.O.getOrNull(traverseUpGuard(node, isFunction));
423
+ const functionNode = isFunction(node) ? node : eff.O.getOrNull(traverseUpGuard(node, isFunction));
423
424
  typescriptEstree.simpleTraverse(node, {
424
425
  enter(node2) {
425
426
  if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) return;
426
- const parentFunction = tools.O.getOrNull(traverseUpGuard(node2, isFunction));
427
+ const parentFunction = eff.O.getOrNull(traverseUpGuard(node2, isFunction));
427
428
  if (parentFunction !== functionNode) return;
428
429
  returnStatements.push(node2);
429
430
  }
@@ -433,11 +434,11 @@ function getNestedReturnStatements(node) {
433
434
  function getTopLevelIdentifier(node) {
434
435
  switch (node.type) {
435
436
  case types.AST_NODE_TYPES.Identifier:
436
- return tools.O.some(node);
437
+ return eff.O.some(node);
437
438
  case types.AST_NODE_TYPES.MemberExpression:
438
439
  return getTopLevelIdentifier(node.object);
439
440
  default:
440
- return tools.O.none();
441
+ return eff.O.none();
441
442
  }
442
443
  }
443
444
  function isEmptyFunction(node) {
@@ -474,7 +475,7 @@ var isFunctionOfObjectMethod = tsPattern.isMatching({
474
475
  }
475
476
  });
476
477
  function isKeyLiteralLike(node, property) {
477
- return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, tools.F.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(tools.F.constFalse);
478
+ return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.F.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.F.constFalse);
478
479
  }
479
480
  function isMapCallLoose(node) {
480
481
  if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
@@ -488,7 +489,7 @@ function isMapCallLoose(node) {
488
489
  function isMultiLine(node) {
489
490
  return node.loc.start.line !== node.loc.end.line;
490
491
  }
491
- var isNodeEqual = tools.F.dual(2, (a, b) => {
492
+ var isNodeEqual = eff.F.dual(2, (a, b) => {
492
493
  if (a.type !== b.type) return false;
493
494
  if (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression) return true;
494
495
  if (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal) return a.value === b.value;
@@ -497,8 +498,8 @@ var isNodeEqual = tools.F.dual(2, (a, b) => {
497
498
  }
498
499
  if (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral) {
499
500
  if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
500
- if (!tools.zip(a.quasis, b.quasis).every(([a2, b2]) => isNodeEqual(a2, b2))) return false;
501
- if (!tools.zip(a.expressions, b.expressions).every(([a2, b2]) => isNodeEqual(a2, b2))) 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;
502
503
  return true;
503
504
  }
504
505
  if (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier) return a.name === b.name;
@@ -514,7 +515,7 @@ function isRegExpLiteral(node) {
514
515
  return node.type === types.AST_NODE_TYPES.Literal && "regex" in node;
515
516
  }
516
517
  function isStringLiteral(node) {
517
- return node.type === types.AST_NODE_TYPES.Literal && tools.isString(node.value);
518
+ return node.type === types.AST_NODE_TYPES.Literal && eff.isString(node.value);
518
519
  }
519
520
  function isThisExpression(node) {
520
521
  if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
@@ -552,10 +553,10 @@ function toReadableNodeType(node) {
552
553
  if (isJSX(node)) return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), " "))}`;
553
554
  return stringTs.toLowerCase(stringTs.delimiterCase(node.type, " "));
554
555
  }
555
- var traverseUp = tools.F.dual(2, (node, predicate) => {
556
+ var traverseUp = eff.F.dual(2, (node, predicate) => {
556
557
  const { parent } = node;
557
- if (!parent || parent.type === types.AST_NODE_TYPES.Program) return tools.O.none();
558
- return predicate(parent) ? tools.O.some(parent) : traverseUp(parent, predicate);
558
+ if (!parent || parent.type === types.AST_NODE_TYPES.Program) return eff.O.none();
559
+ return predicate(parent) ? eff.O.some(parent) : traverseUp(parent, predicate);
559
560
  });
560
561
 
561
562
  exports.getClassIdentifier = getClassIdentifier;
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { or, F, O, zip, isString } from '@eslint-react/tools';
1
+ import { or, F, O, isString } from '@eslint-react/eff';
2
2
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
3
3
  import { ASTUtils } from '@typescript-eslint/utils';
4
4
  import { isMatching, P, match } from 'ts-pattern';
5
5
  import { AST_NODE_TYPES as AST_NODE_TYPES$1, simpleTraverse } from '@typescript-eslint/typescript-estree';
6
+ import { zip } from '@eslint-react/types';
6
7
  import { toLowerCase, delimiterCase, replace } from 'string-ts';
7
8
 
8
9
  // src/function-init-path.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "1.20.1",
3
+ "version": "1.20.2-beta.3",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -41,8 +41,8 @@
41
41
  "birecord": "^0.1.1",
42
42
  "string-ts": "^2.2.0",
43
43
  "ts-pattern": "^5.6.0",
44
- "@eslint-react/tools": "1.20.1",
45
- "@eslint-react/types": "1.20.1"
44
+ "@eslint-react/types": "1.20.2-beta.3",
45
+ "@eslint-react/eff": "1.20.2-beta.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "tsup": "^8.3.5",