@eslint-react/var 5.30.0-beta.9 → 5.30.0-rc.0

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
@@ -248,7 +248,30 @@ interface ResolveOptions {
248
248
  * initializer, see {@link resolveOrigin}.
249
249
  */
250
250
  export declare function resolve(context: RuleContext, node: TSESTree.Identifier, options?: ResolveOptions): TSESTree.Node | null;
251
- /** The possible assignment targets returned by {@link resolveEnclosingAssignmentTarget}. */
251
+ /**
252
+ * Resolve every write target of an assignment or loop target, expanding
253
+ * destructuring patterns such as `[local, globalValue] = source` or
254
+ * `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
255
+ * their left side is.
256
+ * @param node The assignment left side or for-in/of loop target to inspect. Declaration-form loop targets are not expanded and return an empty array.
257
+ * @returns The identifier and member expression targets being written.
258
+ */
259
+ export declare function resolveAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
260
+ /**
261
+ * The possible assignment targets returned by {@link resolveEnclosingAssignmentTarget}:
262
+ *
263
+ * - `const <id> = ...`: the declared binding — an `Identifier`, or the whole
264
+ * `ObjectPattern`/`ArrayPattern` for a destructuring declaration.
265
+ * - `<target> = ...`: the assignment's left side (an `Identifier`, a
266
+ * `MemberExpression`, or a destructuring pattern).
267
+ * - `class { <key> = ... }`: the property key.
268
+ * - `export default <declaration>`: the exported declaration.
269
+ *
270
+ * The union is wider than the cases above suggest: `DefaultExportDeclarations`
271
+ * includes `Expression` (`export default <expr>`), and `PropertyName` includes
272
+ * computed keys, which are arbitrary expressions as well. Listing the narrower
273
+ * node types explicitly would be redundant, so they are documented here instead.
274
+ */
252
275
  export type EnclosingAssignmentTarget = TSESTree.DefaultExportDeclarations | TSESTree.PropertyName | null;
253
276
  /**
254
277
  * Resolve the enclosing assignment target (variable, property, etc.) of the node.
@@ -259,7 +282,10 @@ export declare function resolveEnclosingAssignmentTarget(node: TSESTree.Node): E
259
282
  /**
260
283
  * Resolve the import source of a variable by walking its latest definition.
261
284
  * @param name The variable name.
262
- * @param initialScope The initial scope.
285
+ * @param initialScope The initial scope. The lookup walks the scope chain
286
+ * upward only, so this must be the scope of a reference to the variable or
287
+ * one of its descendants (e.g. the module scope); passing an ancestor scope
288
+ * such as the program's global scope resolves nothing.
263
289
  * @returns The import source, or `null` when it cannot be resolved.
264
290
  */
265
291
  export declare function resolveImportSource(name: string, initialScope: Scope): string | null;
package/dist/index.js CHANGED
@@ -234,6 +234,8 @@ function isEqualWith(context, a, b, options) {
234
234
  const { identifierComparison = "identity" } = options ?? {};
235
235
  a = Check.isTypeExpression(a) ? Extract.unwrap(a) : a;
236
236
  b = Check.isTypeExpression(b) ? Extract.unwrap(b) : b;
237
+ a = a.type === AST_NODE_TYPES.ChainExpression ? a.expression : a;
238
+ b = b.type === AST_NODE_TYPES.ChainExpression ? b.expression : b;
237
239
  const [aScope, bScope] = [context.sourceCode.getScope(a), context.sourceCode.getScope(b)];
238
240
  switch (true) {
239
241
  case a === b: return true;
@@ -276,7 +278,9 @@ function isEqualWith(context, a, b, options) {
276
278
  }
277
279
  return aBinding != null && bBinding != null && aBinding.variable === bBinding.variable;
278
280
  }
279
- case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return (a.computed && b.computed ? isEqualWith(context, a.property, b.property, options) : Compare.isEqual(a.property, b.property)) && isEqualWith(context, a.object, b.object, options);
281
+ case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression:
282
+ if (a.computed !== b.computed || a.optional !== b.optional) return false;
283
+ return (a.computed ? isEqualWith(context, a.property, b.property, options) : Compare.isEqual(a.property, b.property)) && isEqualWith(context, a.object, b.object, options);
280
284
  case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression:
281
285
  if (aScope.block === bScope.block) return true;
282
286
  return Traverse.findParent(a, Check.isOneOf(thisBlockTypes)) === Traverse.findParent(b, Check.isOneOf(thisBlockTypes));
@@ -355,6 +359,22 @@ function resolve(context, node, options) {
355
359
  if (binding?.definition == null) return null;
356
360
  return projectBinding(binding.definition, "value");
357
361
  }
362
+ // src/resolve-assignment-targets.ts
363
+ function resolveAssignmentTargets(node) {
364
+ const target = Extract.unwrap(node);
365
+ switch (target.type) {
366
+ case AST_NODE_TYPES.Identifier:
367
+ case AST_NODE_TYPES.MemberExpression: return [target];
368
+ case AST_NODE_TYPES.ArrayPattern: return target.elements.flatMap((element) => element == null ? [] : resolveAssignmentTargets(element));
369
+ case AST_NODE_TYPES.AssignmentPattern: return resolveAssignmentTargets(target.left);
370
+ case AST_NODE_TYPES.ObjectPattern: return target.properties.flatMap((property) => {
371
+ if (property.type === AST_NODE_TYPES.RestElement) return resolveAssignmentTargets(property.argument);
372
+ return resolveAssignmentTargets(property.value);
373
+ });
374
+ case AST_NODE_TYPES.RestElement: return resolveAssignmentTargets(target.argument);
375
+ default: return [];
376
+ }
377
+ }
358
378
  // src/resolve-enclosing-assignment-target.ts
359
379
  function getParent(node) {
360
380
  return node.parent;
@@ -542,4 +562,4 @@ function resolveOriginChain(context, node, options) {
542
562
  }
543
563
  return Check.isIdentifier(current) ? null : current;
544
564
  }
545
- export { createImportLookup, isAssignmentTargetEqual, isInitializedFromReact, isInitializedFromReactNative, isProvenanceEqual, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource, resolveObjectType, resolveOrigin, resolveOriginChain };
565
+ export { createImportLookup, isAssignmentTargetEqual, isInitializedFromReact, isInitializedFromReactNative, isProvenanceEqual, isValueEqual, resolve, resolveAssignmentTargets, resolveEnclosingAssignmentTarget, resolveImportSource, resolveObjectType, resolveOrigin, resolveOriginChain };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.30.0-beta.9",
3
+ "version": "5.30.0-rc.0",
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.30.0-beta.9",
33
- "@eslint-react/eslint": "5.30.0-beta.9",
32
+ "@eslint-react/ast": "5.30.0-rc.0",
33
+ "@eslint-react/eslint": "5.30.0-rc.0",
34
34
  "@typescript-eslint/scope-manager": "^8.72.1",
35
35
  "@typescript-eslint/types": "^8.72.1",
36
36
  "@typescript-eslint/utils": "^8.72.1",
@@ -42,10 +42,10 @@
42
42
  "@local/testkit": "0.0.0",
43
43
  "@tsconfig/node20": "^20.1.10",
44
44
  "@types/node": "^20.19.43",
45
- "eslint": "^10.13.0",
46
- "tsdown": "^0.23.2",
45
+ "eslint": "^10.14.0",
46
+ "tsdown": "^0.23.5",
47
47
  "typescript": "6.0.3",
48
- "vitest": "^5.0.5"
48
+ "vitest": "^5.1.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "eslint": "*",