@eslint-react/var 1.17.4-next.1 → 1.17.4-next.11

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
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
452
452
 
453
453
  declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
454
454
 
455
+ declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
456
+
455
457
  declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
456
458
 
457
459
  /**
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
491
493
  * @param initialScopes initial scopes of the two nodes
492
494
  * @returns `true` if node value equal
493
495
  */
494
- declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [Scope, Scope]): boolean;
496
+ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
497
+ aScope: Scope,
498
+ bScope: Scope
499
+ ]): boolean;
495
500
 
496
- export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
501
+ export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
package/dist/index.d.ts CHANGED
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
452
452
 
453
453
  declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
454
454
 
455
+ declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
456
+
455
457
  declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
456
458
 
457
459
  /**
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
491
493
  * @param initialScopes initial scopes of the two nodes
492
494
  * @returns `true` if node value equal
493
495
  */
494
- declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [Scope, Scope]): boolean;
496
+ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
497
+ aScope: Scope,
498
+ bScope: Scope
499
+ ]): boolean;
495
500
 
496
- export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
501
+ export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var tools = require('@eslint-react/tools');
5
5
  var scopeManager = require('@typescript-eslint/scope-manager');
6
6
  var types = require('@typescript-eslint/types');
7
7
  var tsPattern = require('ts-pattern');
8
- var astUtils = require('@typescript-eslint/utils/ast-utils');
8
+ var ASTUtils = require('@typescript-eslint/utils/ast-utils');
9
9
 
10
10
  function _interopNamespace(e) {
11
11
  if (e && e.__esModule) return e;
@@ -26,6 +26,7 @@ function _interopNamespace(e) {
26
26
  }
27
27
 
28
28
  var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
29
+ var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
29
30
 
30
31
  // src/construction.ts
31
32
  var Construction = tools.Data.taggedEnum();
@@ -122,8 +123,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
122
123
  };
123
124
  return detect(node);
124
125
  }
125
- var findVariable = tools.F.dual(2, (nameOrNode, initialScope) => {
126
- return tools.O.fromNullable(astUtils.findVariable(initialScope, nameOrNode));
126
+ var findVariable2 = tools.F.dual(2, (nameOrNode, initialScope) => {
127
+ return tools.O.fromNullable(ASTUtils__namespace.findVariable(initialScope, nameOrNode));
127
128
  });
128
129
 
129
130
  // src/get-child-scopes.ts
@@ -138,6 +139,12 @@ function getScope(node, scopeManager) {
138
139
  if (parent) return getScope(parent, scopeManager);
139
140
  return null;
140
141
  }
142
+ function getStaticValue2(node, initialScope) {
143
+ return tools.F.pipe(
144
+ tools.O.fromNullable(ASTUtils__namespace.getStaticValue(node, initialScope)),
145
+ tools.O.map((v) => v.value)
146
+ );
147
+ }
141
148
  function getVariableDeclaratorID(node, prev) {
142
149
  switch (true) {
143
150
  case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
@@ -187,7 +194,7 @@ function getVariables(initialScope) {
187
194
  return variables.reverse();
188
195
  }
189
196
  function isInitializedFromSource(name, source, initialScope) {
190
- const maybeLatestDef = tools.O.flatMapNullable(findVariable(name, initialScope), (v) => v.defs.at(-1));
197
+ const maybeLatestDef = tools.O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
191
198
  if (tools.O.isNone(maybeLatestDef)) return false;
192
199
  const latestDef = maybeLatestDef.value;
193
200
  const { node, parent } = latestDef;
@@ -236,8 +243,8 @@ function isNodeValueEqual(a, b, initialScopes) {
236
243
  return a.value.cooked === b.value.cooked;
237
244
  }
238
245
  case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
239
- const aVar = findVariable(a, aScope);
240
- const bVar = findVariable(b, bScope);
246
+ const aVar = findVariable2(a, aScope);
247
+ const bVar = findVariable2(b, bScope);
241
248
  const aVarNode = tools.O.flatMap(aVar, getVariableNode(0));
242
249
  const bVarNode = tools.O.flatMap(bVar, getVariableNode(0));
243
250
  const aVarNodeParent = tools.O.flatMapNullable(aVarNode, (n) => n.parent);
@@ -268,13 +275,16 @@ function isNodeValueEqual(a, b, initialScopes) {
268
275
  case (tools.O.exists(aDefParentParent, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement)) && tools.O.exists(bDefParentParent, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement))): {
269
276
  return tools.F.pipe(
270
277
  tools.O.Do,
278
+ tools.O.bind("aLeft", () => tools.O.map(aDefParentParent, (d) => d.left)),
279
+ tools.O.bind("bLeft", () => tools.O.map(bDefParentParent, (d) => d.left)),
280
+ tools.O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
271
281
  tools.O.bind("aRight", () => tools.O.map(aDefParentParent, (d) => d.right)),
272
282
  tools.O.bind("bRight", () => tools.O.map(bDefParentParent, (d) => d.right)),
273
283
  tools.O.exists(({ aRight, bRight }) => AST__namespace.isNodeEqual(aRight, bRight))
274
284
  );
275
285
  }
276
286
  default: {
277
- return tools.O.isSome(aVar) && tools.O.isSome(bVar) && aVar.value === bVar.value;
287
+ return tools.O.isSome(aVar) && tools.O.isSome(bVar) && tools.Equal.equals(aVar, bVar);
278
288
  }
279
289
  }
280
290
  }
@@ -283,23 +293,30 @@ function isNodeValueEqual(a, b, initialScopes) {
283
293
  }
284
294
  case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
285
295
  if (aScope.block === bScope.block) return true;
286
- const fa = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
287
- const fb = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
288
- return tools.O.isSome(fa) && tools.O.isSome(fb) && fa.value === fb.value;
296
+ return tools.F.pipe(
297
+ tools.O.Do,
298
+ tools.O.bind("aFunction", () => AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes))),
299
+ tools.O.bind("bFunction", () => AST__namespace.traverseUp(b, AST__namespace.isOneOf(thisBlockTypes))),
300
+ tools.O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
301
+ );
289
302
  }
290
303
  default: {
291
- const aStatic = astUtils.getStaticValue(a, aScope);
292
- const bStatic = astUtils.getStaticValue(b, bScope);
293
- return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
304
+ return tools.F.pipe(
305
+ tools.O.Do,
306
+ tools.O.bind("aStatic", () => getStaticValue2(a, aScope)),
307
+ tools.O.bind("bStatic", () => getStaticValue2(b, bScope)),
308
+ tools.O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
309
+ );
294
310
  }
295
311
  }
296
312
  }
297
313
 
298
314
  exports.Construction = Construction;
299
315
  exports.ConstructionHint = ConstructionHint;
300
- exports.findVariable = findVariable;
316
+ exports.findVariable = findVariable2;
301
317
  exports.getChidScopes = getChidScopes;
302
318
  exports.getScope = getScope;
319
+ exports.getStaticValue = getStaticValue2;
303
320
  exports.getVariableDeclaratorID = getVariableDeclaratorID;
304
321
  exports.getVariableDef = getVariableDef;
305
322
  exports.getVariableNode = getVariableNode;
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as AST from '@eslint-react/ast';
2
- import { Data, F, O, isString, isNullable, isObject } from '@eslint-react/tools';
2
+ import { Data, F, O, isString, Equal, isNullable, isObject } from '@eslint-react/tools';
3
3
  import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
4
4
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
5
  import { match, isMatching } from 'ts-pattern';
6
- import { findVariable as findVariable$1, getStaticValue } from '@typescript-eslint/utils/ast-utils';
6
+ import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
7
7
 
8
8
  // src/construction.ts
9
9
  var Construction = Data.taggedEnum();
@@ -100,8 +100,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
100
100
  };
101
101
  return detect(node);
102
102
  }
103
- var findVariable = F.dual(2, (nameOrNode, initialScope) => {
104
- return O.fromNullable(findVariable$1(initialScope, nameOrNode));
103
+ var findVariable2 = F.dual(2, (nameOrNode, initialScope) => {
104
+ return O.fromNullable(ASTUtils.findVariable(initialScope, nameOrNode));
105
105
  });
106
106
 
107
107
  // src/get-child-scopes.ts
@@ -116,6 +116,12 @@ function getScope(node, scopeManager) {
116
116
  if (parent) return getScope(parent, scopeManager);
117
117
  return null;
118
118
  }
119
+ function getStaticValue2(node, initialScope) {
120
+ return F.pipe(
121
+ O.fromNullable(ASTUtils.getStaticValue(node, initialScope)),
122
+ O.map((v) => v.value)
123
+ );
124
+ }
119
125
  function getVariableDeclaratorID(node, prev) {
120
126
  switch (true) {
121
127
  case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
@@ -165,7 +171,7 @@ function getVariables(initialScope) {
165
171
  return variables.reverse();
166
172
  }
167
173
  function isInitializedFromSource(name, source, initialScope) {
168
- const maybeLatestDef = O.flatMapNullable(findVariable(name, initialScope), (v) => v.defs.at(-1));
174
+ const maybeLatestDef = O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
169
175
  if (O.isNone(maybeLatestDef)) return false;
170
176
  const latestDef = maybeLatestDef.value;
171
177
  const { node, parent } = latestDef;
@@ -214,8 +220,8 @@ function isNodeValueEqual(a, b, initialScopes) {
214
220
  return a.value.cooked === b.value.cooked;
215
221
  }
216
222
  case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
217
- const aVar = findVariable(a, aScope);
218
- const bVar = findVariable(b, bScope);
223
+ const aVar = findVariable2(a, aScope);
224
+ const bVar = findVariable2(b, bScope);
219
225
  const aVarNode = O.flatMap(aVar, getVariableNode(0));
220
226
  const bVarNode = O.flatMap(bVar, getVariableNode(0));
221
227
  const aVarNodeParent = O.flatMapNullable(aVarNode, (n) => n.parent);
@@ -246,13 +252,16 @@ function isNodeValueEqual(a, b, initialScopes) {
246
252
  case (O.exists(aDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement)) && O.exists(bDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement))): {
247
253
  return F.pipe(
248
254
  O.Do,
255
+ O.bind("aLeft", () => O.map(aDefParentParent, (d) => d.left)),
256
+ O.bind("bLeft", () => O.map(bDefParentParent, (d) => d.left)),
257
+ O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
249
258
  O.bind("aRight", () => O.map(aDefParentParent, (d) => d.right)),
250
259
  O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
251
260
  O.exists(({ aRight, bRight }) => AST.isNodeEqual(aRight, bRight))
252
261
  );
253
262
  }
254
263
  default: {
255
- return O.isSome(aVar) && O.isSome(bVar) && aVar.value === bVar.value;
264
+ return O.isSome(aVar) && O.isSome(bVar) && Equal.equals(aVar, bVar);
256
265
  }
257
266
  }
258
267
  }
@@ -261,16 +270,22 @@ function isNodeValueEqual(a, b, initialScopes) {
261
270
  }
262
271
  case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
263
272
  if (aScope.block === bScope.block) return true;
264
- const fa = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
265
- const fb = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
266
- return O.isSome(fa) && O.isSome(fb) && fa.value === fb.value;
273
+ return F.pipe(
274
+ O.Do,
275
+ O.bind("aFunction", () => AST.traverseUp(a, AST.isOneOf(thisBlockTypes))),
276
+ O.bind("bFunction", () => AST.traverseUp(b, AST.isOneOf(thisBlockTypes))),
277
+ O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
278
+ );
267
279
  }
268
280
  default: {
269
- const aStatic = getStaticValue(a, aScope);
270
- const bStatic = getStaticValue(b, bScope);
271
- return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
281
+ return F.pipe(
282
+ O.Do,
283
+ O.bind("aStatic", () => getStaticValue2(a, aScope)),
284
+ O.bind("bStatic", () => getStaticValue2(b, bScope)),
285
+ O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
286
+ );
272
287
  }
273
288
  }
274
289
  }
275
290
 
276
- export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
291
+ export { Construction, ConstructionHint, findVariable2 as findVariable, getChidScopes, getScope, getStaticValue2 as getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "1.17.4-next.1",
3
+ "version": "1.17.4-next.11",
4
4
  "description": "TSESTree AST utility module for static analysis of variables",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -39,9 +39,9 @@
39
39
  "@typescript-eslint/types": "^8.17.0",
40
40
  "@typescript-eslint/utils": "^8.17.0",
41
41
  "ts-pattern": "^5.5.0",
42
- "@eslint-react/ast": "1.17.4-next.1",
43
- "@eslint-react/tools": "1.17.4-next.1",
44
- "@eslint-react/types": "1.17.4-next.1"
42
+ "@eslint-react/ast": "1.17.4-next.11",
43
+ "@eslint-react/tools": "1.17.4-next.11",
44
+ "@eslint-react/types": "1.17.4-next.11"
45
45
  },
46
46
  "devDependencies": {
47
47
  "string-ts": "^2.2.0",