@eslint-react/var 1.17.4-next.2 → 1.17.4-next.4

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();
@@ -123,7 +124,7 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
123
124
  return detect(node);
124
125
  }
125
126
  var findVariable = tools.F.dual(2, (nameOrNode, initialScope) => {
126
- return tools.O.fromNullable(astUtils.findVariable(initialScope, nameOrNode));
127
+ return tools.O.fromNullable(ASTUtils.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):
@@ -277,7 +284,7 @@ function isNodeValueEqual(a, b, initialScopes) {
277
284
  );
278
285
  }
279
286
  default: {
280
- 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);
281
288
  }
282
289
  }
283
290
  }
@@ -286,14 +293,20 @@ function isNodeValueEqual(a, b, initialScopes) {
286
293
  }
287
294
  case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
288
295
  if (aScope.block === bScope.block) return true;
289
- const fa = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
290
- const fb = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
291
- 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
+ );
292
302
  }
293
303
  default: {
294
- const aStatic = astUtils.getStaticValue(a, aScope);
295
- const bStatic = astUtils.getStaticValue(b, bScope);
296
- 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
+ );
297
310
  }
298
311
  }
299
312
  }
@@ -303,6 +316,7 @@ exports.ConstructionHint = ConstructionHint;
303
316
  exports.findVariable = findVariable;
304
317
  exports.getChidScopes = getChidScopes;
305
318
  exports.getScope = getScope;
319
+ exports.getStaticValue = getStaticValue2;
306
320
  exports.getVariableDeclaratorID = getVariableDeclaratorID;
307
321
  exports.getVariableDef = getVariableDef;
308
322
  exports.getVariableNode = getVariableNode;
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
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
+ import { findVariable as findVariable$1 } from '@typescript-eslint/utils/ast-utils';
7
8
 
8
9
  // src/construction.ts
9
10
  var Construction = Data.taggedEnum();
@@ -116,6 +117,12 @@ function getScope(node, scopeManager) {
116
117
  if (parent) return getScope(parent, scopeManager);
117
118
  return null;
118
119
  }
120
+ function getStaticValue2(node, initialScope) {
121
+ return F.pipe(
122
+ O.fromNullable(ASTUtils.getStaticValue(node, initialScope)),
123
+ O.map((v) => v.value)
124
+ );
125
+ }
119
126
  function getVariableDeclaratorID(node, prev) {
120
127
  switch (true) {
121
128
  case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
@@ -255,7 +262,7 @@ function isNodeValueEqual(a, b, initialScopes) {
255
262
  );
256
263
  }
257
264
  default: {
258
- return O.isSome(aVar) && O.isSome(bVar) && aVar.value === bVar.value;
265
+ return O.isSome(aVar) && O.isSome(bVar) && Equal.equals(aVar, bVar);
259
266
  }
260
267
  }
261
268
  }
@@ -264,16 +271,22 @@ function isNodeValueEqual(a, b, initialScopes) {
264
271
  }
265
272
  case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
266
273
  if (aScope.block === bScope.block) return true;
267
- const fa = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
268
- const fb = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
269
- return O.isSome(fa) && O.isSome(fb) && fa.value === fb.value;
274
+ return F.pipe(
275
+ O.Do,
276
+ O.bind("aFunction", () => AST.traverseUp(a, AST.isOneOf(thisBlockTypes))),
277
+ O.bind("bFunction", () => AST.traverseUp(b, AST.isOneOf(thisBlockTypes))),
278
+ O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
279
+ );
270
280
  }
271
281
  default: {
272
- const aStatic = getStaticValue(a, aScope);
273
- const bStatic = getStaticValue(b, bScope);
274
- return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
282
+ return F.pipe(
283
+ O.Do,
284
+ O.bind("aStatic", () => getStaticValue2(a, aScope)),
285
+ O.bind("bStatic", () => getStaticValue2(b, bScope)),
286
+ O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
287
+ );
275
288
  }
276
289
  }
277
290
  }
278
291
 
279
- export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
292
+ export { Construction, ConstructionHint, 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.2",
3
+ "version": "1.17.4-next.4",
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.2",
43
- "@eslint-react/types": "1.17.4-next.2",
44
- "@eslint-react/tools": "1.17.4-next.2"
42
+ "@eslint-react/tools": "1.17.4-next.4",
43
+ "@eslint-react/ast": "1.17.4-next.4",
44
+ "@eslint-react/types": "1.17.4-next.4"
45
45
  },
46
46
  "devDependencies": {
47
47
  "string-ts": "^2.2.0",