@eslint-react/var 1.26.3-next.8 → 1.27.0-beta.1

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
@@ -13,6 +13,8 @@ declare function getChidScopes(scope: Scope): readonly Scope[];
13
13
 
14
14
  declare function getVariableDeclaratorId(node: TSESTree.Node | _, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | _;
15
15
 
16
+ declare function getVariableId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.Identifier | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | TSESTree.PrivateIdentifier | undefined;
17
+
16
18
  declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
17
19
 
18
20
  /**
@@ -43,6 +45,11 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
43
45
  bScope: Scope
44
46
  ]): boolean;
45
47
 
48
+ declare function isVariableIdEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
49
+ aScope: Scope,
50
+ bScope: Scope
51
+ ]): boolean;
52
+
46
53
  type LazyValue = {
47
54
  kind: "lazy";
48
55
  node: TSESTree.Node;
@@ -110,4 +117,4 @@ declare const ValueConstructionHint: {
110
117
  */
111
118
  declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
112
119
 
113
- export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
120
+ export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, isVariableIdEqual, toStaticValue };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ declare function getChidScopes(scope: Scope): readonly Scope[];
13
13
 
14
14
  declare function getVariableDeclaratorId(node: TSESTree.Node | _, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | _;
15
15
 
16
+ declare function getVariableId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.Identifier | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | TSESTree.PrivateIdentifier | undefined;
17
+
16
18
  declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
17
19
 
18
20
  /**
@@ -43,6 +45,11 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
43
45
  bScope: Scope
44
46
  ]): boolean;
45
47
 
48
+ declare function isVariableIdEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
49
+ aScope: Scope,
50
+ bScope: Scope
51
+ ]): boolean;
52
+
46
53
  type LazyValue = {
47
54
  kind: "lazy";
48
55
  node: TSESTree.Node;
@@ -110,4 +117,4 @@ declare const ValueConstructionHint: {
110
117
  */
111
118
  declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
112
119
 
113
- export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
120
+ export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, isVariableIdEqual, toStaticValue };
package/dist/index.js CHANGED
@@ -110,6 +110,20 @@ function getVariableDeclaratorId(node, prev) {
110
110
  return getVariableDeclaratorId(node.parent, node);
111
111
  }
112
112
  }
113
+ function getVariableId(node, prev) {
114
+ switch (true) {
115
+ case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
116
+ return node.id;
117
+ case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
118
+ return node.left;
119
+ case (node.type === types.AST_NODE_TYPES.PropertyDefinition && node.value === prev):
120
+ return node.key;
121
+ case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
122
+ return eff._;
123
+ default:
124
+ return getVariableId(node.parent, node);
125
+ }
126
+ }
113
127
  function getVariables(initialScope) {
114
128
  let scope = initialScope;
115
129
  const variables = [...scope.variables];
@@ -236,6 +250,9 @@ function isNodeValueEqual(a, b, initialScopes) {
236
250
  }
237
251
  }
238
252
  }
253
+ function isVariableIdEqual(a, b, initialScopes) {
254
+ return AST3__namespace.isNodeEqual(a, b) || isNodeValueEqual(a, b, initialScopes);
255
+ }
239
256
  var ValueConstructionHint = {
240
257
  None: 0n,
241
258
  StrictCallExpression: 1n << 0n
@@ -289,7 +306,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
289
306
  return getValueConstruction(node.alternate, initialScope, hint);
290
307
  }
291
308
  case types.AST_NODE_TYPES.Identifier: {
292
- if (!("name" in node && typeof node.name === "string")) {
309
+ if (!("name" in node) || typeof node.name !== "string") {
293
310
  return eff._;
294
311
  }
295
312
  const variable = initialScope.set.get(node.name);
@@ -303,7 +320,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
303
320
  return eff._;
304
321
  }
305
322
  default: {
306
- if (!("expression" in node && typeof node.expression === "object")) {
323
+ if (!("expression" in node) || typeof node.expression !== "object") {
307
324
  return eff._;
308
325
  }
309
326
  return getValueConstruction(node.expression, initialScope, hint);
@@ -317,8 +334,10 @@ exports.findVariable = findVariable2;
317
334
  exports.getChidScopes = getChidScopes;
318
335
  exports.getValueConstruction = getValueConstruction;
319
336
  exports.getVariableDeclaratorId = getVariableDeclaratorId;
337
+ exports.getVariableId = getVariableId;
320
338
  exports.getVariableNode = getVariableNode;
321
339
  exports.getVariables = getVariables;
322
340
  exports.isInitializedFromSource = isInitializedFromSource;
323
341
  exports.isNodeValueEqual = isNodeValueEqual;
342
+ exports.isVariableIdEqual = isVariableIdEqual;
324
343
  exports.toStaticValue = toStaticValue;
package/dist/index.mjs CHANGED
@@ -88,6 +88,20 @@ function getVariableDeclaratorId(node, prev) {
88
88
  return getVariableDeclaratorId(node.parent, node);
89
89
  }
90
90
  }
91
+ function getVariableId(node, prev) {
92
+ switch (true) {
93
+ case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
94
+ return node.id;
95
+ case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
96
+ return node.left;
97
+ case (node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev):
98
+ return node.key;
99
+ case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
100
+ return _;
101
+ default:
102
+ return getVariableId(node.parent, node);
103
+ }
104
+ }
91
105
  function getVariables(initialScope) {
92
106
  let scope = initialScope;
93
107
  const variables = [...scope.variables];
@@ -214,6 +228,9 @@ function isNodeValueEqual(a, b, initialScopes) {
214
228
  }
215
229
  }
216
230
  }
231
+ function isVariableIdEqual(a, b, initialScopes) {
232
+ return AST3.isNodeEqual(a, b) || isNodeValueEqual(a, b, initialScopes);
233
+ }
217
234
  var ValueConstructionHint = {
218
235
  None: 0n,
219
236
  StrictCallExpression: 1n << 0n
@@ -267,7 +284,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
267
284
  return getValueConstruction(node.alternate, initialScope, hint);
268
285
  }
269
286
  case AST_NODE_TYPES.Identifier: {
270
- if (!("name" in node && typeof node.name === "string")) {
287
+ if (!("name" in node) || typeof node.name !== "string") {
271
288
  return _;
272
289
  }
273
290
  const variable = initialScope.set.get(node.name);
@@ -281,7 +298,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
281
298
  return _;
282
299
  }
283
300
  default: {
284
- if (!("expression" in node && typeof node.expression === "object")) {
301
+ if (!("expression" in node) || typeof node.expression !== "object") {
285
302
  return _;
286
303
  }
287
304
  return getValueConstruction(node.expression, initialScope, hint);
@@ -289,4 +306,4 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
289
306
  }
290
307
  }
291
308
 
292
- export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
309
+ export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, isVariableIdEqual, toStaticValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "1.26.3-next.8",
3
+ "version": "1.27.0-beta.1",
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": {
@@ -35,13 +35,13 @@
35
35
  "./package.json"
36
36
  ],
37
37
  "dependencies": {
38
- "@typescript-eslint/scope-manager": "^8.23.0",
39
- "@typescript-eslint/types": "^8.23.0",
40
- "@typescript-eslint/utils": "^8.23.0",
38
+ "@typescript-eslint/scope-manager": "^8.24.1",
39
+ "@typescript-eslint/types": "^8.24.1",
40
+ "@typescript-eslint/utils": "^8.24.1",
41
41
  "string-ts": "^2.2.1",
42
42
  "ts-pattern": "^5.6.2",
43
- "@eslint-react/ast": "1.26.3-next.8",
44
- "@eslint-react/eff": "1.26.3-next.8"
43
+ "@eslint-react/ast": "1.27.0-beta.1",
44
+ "@eslint-react/eff": "1.27.0-beta.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "tsup": "^8.3.6",
@@ -54,6 +54,6 @@
54
54
  "scripts": {
55
55
  "build": "tsup",
56
56
  "lint:publish": "publint",
57
- "lint:type": "tsc --noEmit"
57
+ "lint:ts": "tsc --noEmit"
58
58
  }
59
59
  }