@eslint-react/var 5.28.3 → 5.28.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.ts CHANGED
@@ -181,12 +181,7 @@ export declare function isValueEqual(context: RuleContext, a: TSESTree.Node, b:
181
181
  * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier
182
182
  * (this will miss variables declared in an outer scope). When `false` (default), traverse the
183
183
  * scope chain upward via `findVariable` so that references to outer-scope bindings are resolved
184
- * correctly. Ignored when `boundary` is set.
185
- * - `boundary`: A node (typically the enclosing component or hook function) that bounds the
186
- * scope-chain traversal. The identifier is resolved only if its binding is declared in a scope
187
- * between the identifier's own scope and the boundary's scope (inclusive); bindings declared
188
- * outside the boundary (e.g. module-level constants, which are stable across renders) are
189
- * treated as unresolvable. The boundary node must be an ancestor of `node`.
184
+ * correctly.
190
185
  * @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
191
186
  *
192
187
  * For origin/pedigree tracking that maps destructured bindings to the declarator's
@@ -194,7 +189,6 @@ export declare function isValueEqual(context: RuleContext, a: TSESTree.Node, b:
194
189
  */
195
190
  export declare function resolve(context: RuleContext, node: TSESTree.Identifier, options?: Partial<{
196
191
  at: number;
197
- boundary: TSESTree.Node;
198
192
  localOnly: boolean;
199
193
  }>): TSESTree.Node | null;
200
194
  //#endregion
@@ -252,18 +246,9 @@ export type ObjectType = {
252
246
  * Resolve the object type of the node.
253
247
  * @param context The ESLint rule context.
254
248
  * @param node The node to resolve.
255
- * @param options Optional settings:
256
- * - `boundary`: A node (typically the enclosing component or hook function) that bounds
257
- * identifier resolution. Identifiers are resolved through their initializer only when the
258
- * binding is declared within the boundary — this catches render-scoped constructions referenced
259
- * from nested callbacks, while values declared outside the boundary (e.g. module-level
260
- * constants, which are stable across renders) are treated as unresolvable. When omitted, only
261
- * the identifier's own scope is searched.
262
249
  * @returns The object type of the node, or `null` when it cannot be resolved.
263
250
  */
264
- export declare function resolveObjectType(context: RuleContext, node: TSESTree.Node | null | undefined, options?: Partial<{
265
- boundary: TSESTree.Node;
266
- }>): ObjectType | null;
251
+ export declare function resolveObjectType(context: RuleContext, node: TSESTree.Node | null | undefined): ObjectType | null;
267
252
  //#endregion
268
253
  //#region src/resolve-origin.d.ts
269
254
  /**
package/dist/index.js CHANGED
@@ -318,9 +318,9 @@ function isInitializedFromReactNative(name, initialScope, importSource = "react-
318
318
  //#endregion
319
319
  //#region src/resolve.ts
320
320
  function resolve(context, node, options) {
321
- const { at = 0, boundary, localOnly = false } = options ?? {};
321
+ const { at = 0, localOnly = false } = options ?? {};
322
322
  const scope = context.sourceCode.getScope(node);
323
- const variable = boundary != null ? findVariableWithinBoundary(scope, node.name, context.sourceCode.getScope(boundary)) : localOnly ? scope.set.get(node.name) : findVariable(scope, node);
323
+ const variable = localOnly ? scope.set.get(node.name) : findVariable(scope, node);
324
324
  if (variable == null) return null;
325
325
  const def = variable.defs.at(at);
326
326
  if (def == null) return null;
@@ -345,14 +345,6 @@ function resolve(context, node, options) {
345
345
  default: return null;
346
346
  }
347
347
  }
348
- function findVariableWithinBoundary(scope, name, boundaryScope) {
349
- while (scope != null) {
350
- const variable = scope.set.get(name);
351
- if (variable != null || scope === boundaryScope) return variable ?? null;
352
- scope = scope.upper;
353
- }
354
- return null;
355
- }
356
348
  //#endregion
357
349
  //#region src/resolve-enclosing-assignment-target.ts
358
350
  function resolveEnclosingAssignmentTarget(node) {
@@ -368,7 +360,7 @@ function resolveEnclosingAssignmentTarget(node) {
368
360
  }
369
361
  //#endregion
370
362
  //#region src/resolve-object-type.ts
371
- function resolveObjectType(context, node, options) {
363
+ function resolveObjectType(context, node) {
372
364
  if (node == null) return null;
373
365
  switch (node.type) {
374
366
  case AST_NODE_TYPES.JSXElement:
@@ -407,24 +399,22 @@ function resolveObjectType(context, node, options) {
407
399
  };
408
400
  return null;
409
401
  case AST_NODE_TYPES.Identifier: {
410
- const initNode = options?.boundary != null ? resolve(context, node, {
411
- at: -1,
412
- boundary: options.boundary
413
- }) : resolve(context, node, {
402
+ if ((context.sourceCode.getScope(node).set.get(node.name)?.defs.at(-1))?.type === DefinitionType.Parameter) return null;
403
+ const initNode = resolve(context, node, {
414
404
  at: -1,
415
405
  localOnly: true
416
406
  });
417
407
  if (initNode == null) return null;
418
- return resolveObjectType(context, initNode, options);
408
+ return resolveObjectType(context, initNode);
419
409
  }
420
- case AST_NODE_TYPES.MemberExpression: return resolveObjectType(context, node.object, options);
410
+ case AST_NODE_TYPES.MemberExpression: return resolveObjectType(context, node.object);
421
411
  case AST_NODE_TYPES.AssignmentExpression:
422
- case AST_NODE_TYPES.AssignmentPattern: return resolveObjectType(context, node.right, options);
423
- case AST_NODE_TYPES.LogicalExpression: return resolveObjectType(context, node.left, options) ?? resolveObjectType(context, node.right, options);
424
- case AST_NODE_TYPES.ConditionalExpression: return resolveObjectType(context, node.consequent, options) ?? resolveObjectType(context, node.alternate, options);
412
+ case AST_NODE_TYPES.AssignmentPattern: return resolveObjectType(context, node.right);
413
+ case AST_NODE_TYPES.LogicalExpression: return resolveObjectType(context, node.left) ?? resolveObjectType(context, node.right);
414
+ case AST_NODE_TYPES.ConditionalExpression: return resolveObjectType(context, node.consequent) ?? resolveObjectType(context, node.alternate);
425
415
  case AST_NODE_TYPES.SequenceExpression:
426
416
  if (node.expressions.length === 0) return null;
427
- return resolveObjectType(context, node.expressions.at(-1) ?? null, options);
417
+ return resolveObjectType(context, node.expressions.at(-1) ?? null);
428
418
  case AST_NODE_TYPES.CallExpression: {
429
419
  const callee = Extract.unwrap(node.callee);
430
420
  switch (true) {
@@ -468,7 +458,7 @@ function resolveObjectType(context, node, options) {
468
458
  }
469
459
  default:
470
460
  if (!hasProperty(node, "expression") || typeof node.expression !== "object") return null;
471
- return resolveObjectType(context, node.expression, options);
461
+ return resolveObjectType(context, node.expression);
472
462
  }
473
463
  }
474
464
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.28.3",
3
+ "version": "5.28.4",
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": {
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@eslint-react/ast": "5.28.3",
33
- "@eslint-react/eslint": "5.28.3",
32
+ "@eslint-react/ast": "5.28.4",
33
+ "@eslint-react/eslint": "5.28.4",
34
34
  "@typescript-eslint/scope-manager": "^8.72.0",
35
35
  "@typescript-eslint/types": "^8.72.0",
36
36
  "@typescript-eslint/utils": "^8.72.0",