@eslint-react/var 2.0.0-next.43 → 2.0.0-next.45

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
@@ -1,6 +1,6 @@
1
1
  import { Scope, Variable } from '@typescript-eslint/scope-manager';
2
2
  import { TSESTree } from '@typescript-eslint/types';
3
- import { _ } from '@eslint-react/eff';
3
+ import { unit } from '@eslint-react/eff';
4
4
 
5
5
  /**
6
6
  * Get all variables from the given scope up to the global scope
@@ -9,10 +9,10 @@ import { _ } from '@eslint-react/eff';
9
9
  */
10
10
  declare function getVariables(initialScope: Scope): Variable[];
11
11
  declare const findVariable: {
12
- (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
13
- (nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
12
+ (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | unit) => Variable | unit;
13
+ (nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope): Variable | unit;
14
14
  };
15
- declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
15
+ declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | unit;
16
16
 
17
17
  declare const ConstructionDetectionHint: {
18
18
  None: bigint;
@@ -53,27 +53,27 @@ type Construction = {
53
53
  * @param hint Optional hint to control the detection behavior.
54
54
  * @returns The construction type of the node, or `_` if not found.
55
55
  */
56
- declare function getConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): Construction | _;
56
+ declare function getConstruction(node: TSESTree.Node | unit, initialScope: Scope, hint?: bigint): Construction | unit;
57
57
 
58
- declare function getVariableDeclaratorId(node: TSESTree.Node | _, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | _;
58
+ declare function getVariableDeclaratorId(node: TSESTree.Node | unit, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | unit;
59
59
 
60
- declare function getVariableInitNode(variable: Variable | _, at: number): _ | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
60
+ declare function getVariableInitNode(variable: Variable | unit, at: number): unit | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
61
61
 
62
62
  declare function getChidScopes(scope: Scope): readonly Scope[];
63
63
 
64
64
  type LazyValue = {
65
65
  kind: "lazy";
66
66
  node: TSESTree.Node;
67
- initialScope: Scope | _;
67
+ initialScope: Scope | unit;
68
68
  } | {
69
69
  kind: "none";
70
70
  node: TSESTree.Node;
71
- initialScope: Scope | _;
71
+ initialScope: Scope | unit;
72
72
  } | {
73
73
  kind: "some";
74
74
  node: TSESTree.Node;
75
75
  value: unknown;
76
- initialScope: Scope | _;
76
+ initialScope: Scope | unit;
77
77
  };
78
78
  declare function toStaticValue(lazyValue: LazyValue): {
79
79
  readonly kind: "none";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dual, _ } from '@eslint-react/eff';
1
+ import { dual, unit } from '@eslint-react/eff';
2
2
  import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
3
3
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
4
4
  import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
@@ -7,9 +7,9 @@ import * as AST from '@eslint-react/ast';
7
7
 
8
8
  // src/var-collect.ts
9
9
  function getVariableInitNode(variable, at) {
10
- if (variable == null) return _;
10
+ if (variable == null) return unit;
11
11
  const def = variable.defs.at(at);
12
- if (def == null) return _;
12
+ if (def == null) return unit;
13
13
  switch (true) {
14
14
  case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
15
15
  return def.node;
@@ -18,7 +18,7 @@ function getVariableInitNode(variable, at) {
18
18
  case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
19
19
  return def.node.init;
20
20
  default:
21
- return _;
21
+ return unit;
22
22
  }
23
23
  }
24
24
 
@@ -33,8 +33,8 @@ function getVariables(initialScope) {
33
33
  return variables.reverse();
34
34
  }
35
35
  var findVariable2 = dual(2, (nameOrNode, initialScope) => {
36
- if (nameOrNode == null) return _;
37
- return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
36
+ if (nameOrNode == null) return unit;
37
+ return ASTUtils.findVariable(initialScope, nameOrNode) ?? unit;
38
38
  });
39
39
  function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
40
40
  return properties.findLast((prop) => {
@@ -78,7 +78,7 @@ var ConstructionDetectionHint = {
78
78
  StrictCallExpression: 1n << 0n
79
79
  };
80
80
  function getConstruction(node, initialScope, hint = ConstructionDetectionHint.None) {
81
- if (node == null) return _;
81
+ if (node == null) return unit;
82
82
  switch (node.type) {
83
83
  case AST_NODE_TYPES.JSXElement:
84
84
  case AST_NODE_TYPES.JSXFragment:
@@ -98,30 +98,30 @@ function getConstruction(node, initialScope, hint = ConstructionDetectionHint.No
98
98
  if (hint & ConstructionDetectionHint.StrictCallExpression) {
99
99
  return { kind: "CallExpression", node };
100
100
  }
101
- return _;
101
+ return unit;
102
102
  }
103
103
  case AST_NODE_TYPES.MemberExpression: {
104
- if (!("object" in node)) return _;
104
+ if (!("object" in node)) return unit;
105
105
  return getConstruction(node.object, initialScope, hint);
106
106
  }
107
107
  case AST_NODE_TYPES.AssignmentExpression:
108
108
  case AST_NODE_TYPES.AssignmentPattern: {
109
- if (!("right" in node)) return _;
109
+ if (!("right" in node)) return unit;
110
110
  return getConstruction(node.right, initialScope, hint);
111
111
  }
112
112
  case AST_NODE_TYPES.LogicalExpression: {
113
113
  const lvc = getConstruction(node.left, initialScope, hint);
114
- if (lvc == null) return _;
114
+ if (lvc == null) return unit;
115
115
  return getConstruction(node.right, initialScope, hint);
116
116
  }
117
117
  case AST_NODE_TYPES.ConditionalExpression: {
118
118
  const cvc = getConstruction(node.consequent, initialScope, hint);
119
- if (cvc == null) return _;
119
+ if (cvc == null) return unit;
120
120
  return getConstruction(node.alternate, initialScope, hint);
121
121
  }
122
122
  case AST_NODE_TYPES.Identifier: {
123
123
  if (!("name" in node) || typeof node.name !== "string") {
124
- return _;
124
+ return unit;
125
125
  }
126
126
  const variable = initialScope.set.get(node.name);
127
127
  const variableNode = getVariableInitNode(variable, -1);
@@ -131,25 +131,25 @@ function getConstruction(node, initialScope, hint = ConstructionDetectionHint.No
131
131
  if ("regex" in node) {
132
132
  return { kind: "RegExpLiteral", node };
133
133
  }
134
- return _;
134
+ return unit;
135
135
  }
136
136
  default: {
137
137
  if (!("expression" in node) || typeof node.expression !== "object") {
138
- return _;
138
+ return unit;
139
139
  }
140
140
  return getConstruction(node.expression, initialScope, hint);
141
141
  }
142
142
  }
143
143
  }
144
144
  function getVariableDeclaratorId(node, prev) {
145
- if (node == null) return _;
145
+ if (node == null) return unit;
146
146
  switch (true) {
147
147
  case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
148
148
  return node.id;
149
149
  case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
150
150
  return node.left;
151
151
  case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
152
- return _;
152
+ return unit;
153
153
  default:
154
154
  return getVariableDeclaratorId(node.parent, node);
155
155
  }
@@ -245,12 +245,12 @@ function isNodeValueEqual(a, b, initialScopes) {
245
245
  }
246
246
  }
247
247
  function getVariableInitNodeLoose(variable, at) {
248
- if (variable == null) return _;
248
+ if (variable == null) return unit;
249
249
  const node = getVariableInitNode(variable, at);
250
250
  if (node != null) return node;
251
251
  const def = variable.defs.at(at);
252
252
  if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node;
253
- return _;
253
+ return unit;
254
254
  }
255
255
 
256
256
  export { ConstructionDetectionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getConstruction, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "2.0.0-next.43",
3
+ "version": "2.0.0-next.45",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -32,8 +32,8 @@
32
32
  "@typescript-eslint/utils": "^8.34.0",
33
33
  "string-ts": "^2.2.1",
34
34
  "ts-pattern": "^5.7.1",
35
- "@eslint-react/ast": "2.0.0-next.43",
36
- "@eslint-react/eff": "2.0.0-next.43"
35
+ "@eslint-react/ast": "2.0.0-next.45",
36
+ "@eslint-react/eff": "2.0.0-next.45"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^8.5.0",