@eslint-react/var 1.24.0-beta.1 → 1.24.0-beta.16

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
@@ -2,6 +2,8 @@ import { _ } from '@eslint-react/eff';
2
2
  import { Scope, Variable } from '@typescript-eslint/scope-manager';
3
3
  import { TSESTree } from '@typescript-eslint/types';
4
4
 
5
+ declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
6
+
5
7
  declare const findVariable: {
6
8
  (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
7
9
  (nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
@@ -41,7 +43,7 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
41
43
  bScope: Scope
42
44
  ]): boolean;
43
45
 
44
- type StaticValue = {
46
+ type LazyValue = {
45
47
  kind: "lazy";
46
48
  node: TSESTree.Node;
47
49
  initialScope: Scope | _;
@@ -55,7 +57,7 @@ type StaticValue = {
55
57
  value: unknown;
56
58
  initialScope: Scope | _;
57
59
  };
58
- declare function toResolved(sv: StaticValue): {
60
+ declare function toStaticValue(lazyValue: LazyValue): {
59
61
  readonly kind: "none";
60
62
  readonly node: TSESTree.Node;
61
63
  readonly initialScope: Scope | undefined;
@@ -108,4 +110,4 @@ declare const ValueConstructionHint: {
108
110
  */
109
111
  declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
110
112
 
111
- export { type StaticValue, type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
113
+ export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import { _ } from '@eslint-react/eff';
2
2
  import { Scope, Variable } from '@typescript-eslint/scope-manager';
3
3
  import { TSESTree } from '@typescript-eslint/types';
4
4
 
5
+ declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
6
+
5
7
  declare const findVariable: {
6
8
  (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
7
9
  (nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
@@ -41,7 +43,7 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
41
43
  bScope: Scope
42
44
  ]): boolean;
43
45
 
44
- type StaticValue = {
46
+ type LazyValue = {
45
47
  kind: "lazy";
46
48
  node: TSESTree.Node;
47
49
  initialScope: Scope | _;
@@ -55,7 +57,7 @@ type StaticValue = {
55
57
  value: unknown;
56
58
  initialScope: Scope | _;
57
59
  };
58
- declare function toResolved(sv: StaticValue): {
60
+ declare function toStaticValue(lazyValue: LazyValue): {
59
61
  readonly kind: "none";
60
62
  readonly node: TSESTree.Node;
61
63
  readonly initialScope: Scope | undefined;
@@ -108,4 +110,4 @@ declare const ValueConstructionHint: {
108
110
  */
109
111
  declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
110
112
 
111
- export { type StaticValue, type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
113
+ export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var types = require('@typescript-eslint/types');
3
4
  var eff = require('@eslint-react/eff');
4
5
  var ASTUtils = require('@typescript-eslint/utils/ast-utils');
5
- var types = require('@typescript-eslint/types');
6
6
  var AST3 = require('@eslint-react/ast');
7
7
  var scopeManager = require('@typescript-eslint/scope-manager');
8
8
 
@@ -27,11 +27,67 @@ function _interopNamespace(e) {
27
27
  var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
28
28
  var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
29
29
 
30
- // src/find-variable.ts
30
+ // src/find-property-in-properties.ts
31
31
  var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
32
32
  if (nameOrNode == null) return eff._;
33
33
  return ASTUtils__namespace.findVariable(initialScope, nameOrNode) ?? eff._;
34
34
  });
35
+ function getVariableNode(variable, at) {
36
+ if (variable == null) return eff._;
37
+ const def = variable.defs.at(at);
38
+ if (def == null) return eff._;
39
+ switch (true) {
40
+ case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
41
+ return def.node;
42
+ case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
43
+ return def.node;
44
+ case (def.type === scopeManager.DefinitionType.Parameter && AST3__namespace.isFunction(def.node)):
45
+ return def.node;
46
+ case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
47
+ return def.node.init;
48
+ default:
49
+ return eff._;
50
+ }
51
+ }
52
+
53
+ // src/find-property-in-properties.ts
54
+ function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
55
+ return properties.findLast((prop) => {
56
+ if (prop.type === types.AST_NODE_TYPES.Property) {
57
+ return "name" in prop.key && prop.key.name === name;
58
+ }
59
+ if (prop.type === types.AST_NODE_TYPES.SpreadElement) {
60
+ switch (prop.argument.type) {
61
+ case types.AST_NODE_TYPES.Identifier: {
62
+ if (seen.has(prop.argument.name)) return false;
63
+ const variable = findVariable2(prop.argument.name, initialScope);
64
+ const variableNode = getVariableNode(variable, 0);
65
+ if (variableNode?.type === types.AST_NODE_TYPES.ObjectExpression) {
66
+ seen.add(prop.argument.name);
67
+ return findPropertyInProperties(
68
+ name,
69
+ variableNode.properties,
70
+ initialScope,
71
+ seen
72
+ ) != null;
73
+ }
74
+ return false;
75
+ }
76
+ case types.AST_NODE_TYPES.ObjectExpression: {
77
+ return findPropertyInProperties(
78
+ name,
79
+ prop.argument.properties,
80
+ initialScope,
81
+ seen
82
+ ) != null;
83
+ }
84
+ default:
85
+ return false;
86
+ }
87
+ }
88
+ return false;
89
+ });
90
+ }
35
91
 
36
92
  // src/get-child-scopes.ts
37
93
  function getChidScopes(scope) {
@@ -54,23 +110,6 @@ function getVariableDeclaratorId(node, prev) {
54
110
  return getVariableDeclaratorId(node.parent, node);
55
111
  }
56
112
  }
57
- function getVariableNode(variable, at) {
58
- if (variable == null) return eff._;
59
- const def = variable.defs.at(at);
60
- if (def == null) return eff._;
61
- switch (true) {
62
- case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
63
- return def.node;
64
- case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
65
- return def.node;
66
- case (def.type === scopeManager.DefinitionType.Parameter && AST3__namespace.isFunction(def.node)):
67
- return def.node;
68
- case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
69
- return def.node.init;
70
- default:
71
- return eff._;
72
- }
73
- }
74
113
  function getVariables(initialScope) {
75
114
  let scope = initialScope;
76
115
  const variables = [...scope.variables];
@@ -114,13 +153,13 @@ function getRequireExpressionArguments(node) {
114
153
  }
115
154
  return eff._;
116
155
  }
117
- function toResolved(sv) {
118
- const { kind, node, initialScope } = sv;
156
+ function toStaticValue(lazyValue) {
157
+ const { kind, node, initialScope } = lazyValue;
119
158
  if (kind !== "lazy") {
120
- return sv;
159
+ return lazyValue;
121
160
  }
122
- const resolvedValue = initialScope == null ? ASTUtils.getStaticValue(node) : ASTUtils.getStaticValue(node, initialScope);
123
- return resolvedValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: resolvedValue.value };
161
+ const staticValue = initialScope == null ? ASTUtils.getStaticValue(node) : ASTUtils.getStaticValue(node, initialScope);
162
+ return staticValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: staticValue.value };
124
163
  }
125
164
 
126
165
  // src/is-node-value-equal.ts
@@ -191,8 +230,8 @@ function isNodeValueEqual(a, b, initialScopes) {
191
230
  return aFunction === bFunction;
192
231
  }
193
232
  default: {
194
- const aStatic = toResolved({ kind: "lazy", node: a, initialScope: aScope });
195
- const bStatic = toResolved({ kind: "lazy", node: b, initialScope: bScope });
233
+ const aStatic = toStaticValue({ kind: "lazy", node: a, initialScope: aScope });
234
+ const bStatic = toStaticValue({ kind: "lazy", node: b, initialScope: bScope });
196
235
  return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
197
236
  }
198
237
  }
@@ -273,6 +312,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
273
312
  }
274
313
 
275
314
  exports.ValueConstructionHint = ValueConstructionHint;
315
+ exports.findPropertyInProperties = findPropertyInProperties;
276
316
  exports.findVariable = findVariable2;
277
317
  exports.getChidScopes = getChidScopes;
278
318
  exports.getValueConstruction = getValueConstruction;
@@ -281,4 +321,4 @@ exports.getVariableNode = getVariableNode;
281
321
  exports.getVariables = getVariables;
282
322
  exports.isInitializedFromSource = isInitializedFromSource;
283
323
  exports.isNodeValueEqual = isNodeValueEqual;
284
- exports.toResolved = toResolved;
324
+ exports.toStaticValue = toStaticValue;
package/dist/index.mjs CHANGED
@@ -1,15 +1,71 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types';
1
2
  import { dual, _ } from '@eslint-react/eff';
2
3
  import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
3
4
  import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
4
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
5
  import * as AST3 from '@eslint-react/ast';
6
6
  import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
7
7
 
8
- // src/find-variable.ts
8
+ // src/find-property-in-properties.ts
9
9
  var findVariable2 = dual(2, (nameOrNode, initialScope) => {
10
10
  if (nameOrNode == null) return _;
11
11
  return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
12
12
  });
13
+ function getVariableNode(variable, at) {
14
+ if (variable == null) return _;
15
+ const def = variable.defs.at(at);
16
+ if (def == null) return _;
17
+ switch (true) {
18
+ case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
19
+ return def.node;
20
+ case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
21
+ return def.node;
22
+ case (def.type === DefinitionType.Parameter && AST3.isFunction(def.node)):
23
+ return def.node;
24
+ case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
25
+ return def.node.init;
26
+ default:
27
+ return _;
28
+ }
29
+ }
30
+
31
+ // src/find-property-in-properties.ts
32
+ function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
33
+ return properties.findLast((prop) => {
34
+ if (prop.type === AST_NODE_TYPES.Property) {
35
+ return "name" in prop.key && prop.key.name === name;
36
+ }
37
+ if (prop.type === AST_NODE_TYPES.SpreadElement) {
38
+ switch (prop.argument.type) {
39
+ case AST_NODE_TYPES.Identifier: {
40
+ if (seen.has(prop.argument.name)) return false;
41
+ const variable = findVariable2(prop.argument.name, initialScope);
42
+ const variableNode = getVariableNode(variable, 0);
43
+ if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
44
+ seen.add(prop.argument.name);
45
+ return findPropertyInProperties(
46
+ name,
47
+ variableNode.properties,
48
+ initialScope,
49
+ seen
50
+ ) != null;
51
+ }
52
+ return false;
53
+ }
54
+ case AST_NODE_TYPES.ObjectExpression: {
55
+ return findPropertyInProperties(
56
+ name,
57
+ prop.argument.properties,
58
+ initialScope,
59
+ seen
60
+ ) != null;
61
+ }
62
+ default:
63
+ return false;
64
+ }
65
+ }
66
+ return false;
67
+ });
68
+ }
13
69
 
14
70
  // src/get-child-scopes.ts
15
71
  function getChidScopes(scope) {
@@ -32,23 +88,6 @@ function getVariableDeclaratorId(node, prev) {
32
88
  return getVariableDeclaratorId(node.parent, node);
33
89
  }
34
90
  }
35
- function getVariableNode(variable, at) {
36
- if (variable == null) return _;
37
- const def = variable.defs.at(at);
38
- if (def == null) return _;
39
- switch (true) {
40
- case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
41
- return def.node;
42
- case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
43
- return def.node;
44
- case (def.type === DefinitionType.Parameter && AST3.isFunction(def.node)):
45
- return def.node;
46
- case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
47
- return def.node.init;
48
- default:
49
- return _;
50
- }
51
- }
52
91
  function getVariables(initialScope) {
53
92
  let scope = initialScope;
54
93
  const variables = [...scope.variables];
@@ -92,13 +131,13 @@ function getRequireExpressionArguments(node) {
92
131
  }
93
132
  return _;
94
133
  }
95
- function toResolved(sv) {
96
- const { kind, node, initialScope } = sv;
134
+ function toStaticValue(lazyValue) {
135
+ const { kind, node, initialScope } = lazyValue;
97
136
  if (kind !== "lazy") {
98
- return sv;
137
+ return lazyValue;
99
138
  }
100
- const resolvedValue = initialScope == null ? getStaticValue(node) : getStaticValue(node, initialScope);
101
- return resolvedValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: resolvedValue.value };
139
+ const staticValue = initialScope == null ? getStaticValue(node) : getStaticValue(node, initialScope);
140
+ return staticValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: staticValue.value };
102
141
  }
103
142
 
104
143
  // src/is-node-value-equal.ts
@@ -169,8 +208,8 @@ function isNodeValueEqual(a, b, initialScopes) {
169
208
  return aFunction === bFunction;
170
209
  }
171
210
  default: {
172
- const aStatic = toResolved({ kind: "lazy", node: a, initialScope: aScope });
173
- const bStatic = toResolved({ kind: "lazy", node: b, initialScope: bScope });
211
+ const aStatic = toStaticValue({ kind: "lazy", node: a, initialScope: aScope });
212
+ const bStatic = toStaticValue({ kind: "lazy", node: b, initialScope: bScope });
174
213
  return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
175
214
  }
176
215
  }
@@ -250,4 +289,4 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
250
289
  }
251
290
  }
252
291
 
253
- export { ValueConstructionHint, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
292
+ export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "1.24.0-beta.1",
3
+ "version": "1.24.0-beta.16",
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": {
@@ -33,14 +33,13 @@
33
33
  "./package.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@typescript-eslint/scope-manager": "^8.19.1",
37
- "@typescript-eslint/types": "^8.19.1",
38
- "@typescript-eslint/utils": "^8.19.1",
36
+ "@typescript-eslint/scope-manager": "^8.20.0",
37
+ "@typescript-eslint/types": "^8.20.0",
38
+ "@typescript-eslint/utils": "^8.20.0",
39
39
  "string-ts": "^2.2.0",
40
40
  "ts-pattern": "^5.6.0",
41
- "@eslint-react/ast": "1.24.0-beta.1",
42
- "@eslint-react/eff": "1.24.0-beta.1",
43
- "@eslint-react/types": "1.24.0-beta.1"
41
+ "@eslint-react/ast": "1.24.0-beta.16",
42
+ "@eslint-react/eff": "1.24.0-beta.16"
44
43
  },
45
44
  "devDependencies": {
46
45
  "tsup": "^8.3.5",