@eslint-react/var
Advanced tools
+9
-6
@@ -1,2 +0,1 @@ | ||
| import { Scope } from "@typescript-eslint/scope-manager"; | ||
| import { TSESTree } from "@typescript-eslint/types"; | ||
@@ -72,8 +71,8 @@ import { RuleContext } from "@eslint-react/shared"; | ||
| * Determine whether node value equals to another node value | ||
| * @param context rule context | ||
| * @param a node to compare | ||
| * @param b node to compare | ||
| * @param initialScopes initial scopes of the two nodes | ||
| * @returns `true` if node value equal | ||
| */ | ||
| declare function isValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [aScope: Scope, bScope: Scope]): boolean; | ||
| declare function isValueEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean; | ||
| //#endregion | ||
@@ -103,4 +102,5 @@ //#region src/resolve.d.ts | ||
| * @param node The identifier to resolve. | ||
| * @param at Which definition to use when multiple exist (default: `0`; pass `-1` for the last). | ||
| * @param localOnly When `true`, look up the variable only in the node's own scope (faster, but | ||
| * @param options Optional settings: | ||
| * - `at`: Index of the definition to resolve (default: `0` for the first definition). | ||
| * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier | ||
| * will miss variables declared in an outer scope). When `false` (default), traverse the scope | ||
@@ -111,4 +111,7 @@ * chain upward via `findVariable` so that references to outer-scope bindings are resolved | ||
| */ | ||
| declare function resolve(context: RuleContext, node: TSESTree.Identifier, at?: number, localOnly?: boolean): TSESTree.Node | null; | ||
| declare function resolve(context: RuleContext, node: TSESTree.Identifier, options?: Partial<{ | ||
| at: number; | ||
| localOnly: boolean; | ||
| }>): TSESTree.Node | null; | ||
| //#endregion | ||
| export { AssignmentTarget, ObjectType, computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, isValueEqual, resolve }; |
+14
-9
@@ -29,4 +29,5 @@ import { DefinitionType } from "@typescript-eslint/scope-manager"; | ||
| * @param node The identifier to resolve. | ||
| * @param at Which definition to use when multiple exist (default: `0`; pass `-1` for the last). | ||
| * @param localOnly When `true`, look up the variable only in the node's own scope (faster, but | ||
| * @param options Optional settings: | ||
| * - `at`: Index of the definition to resolve (default: `0` for the first definition). | ||
| * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier | ||
| * will miss variables declared in an outer scope). When `false` (default), traverse the scope | ||
@@ -37,3 +38,4 @@ * chain upward via `findVariable` so that references to outer-scope bindings are resolved | ||
| */ | ||
| function resolve(context, node, at = 0, localOnly = false) { | ||
| function resolve(context, node, options) { | ||
| const { at = 0, localOnly = false } = options ?? {}; | ||
| const scope = context.sourceCode.getScope(node); | ||
@@ -112,3 +114,6 @@ const variable = localOnly ? scope.set.get(node.name) : findVariable(scope, node); | ||
| if ((context.sourceCode.getScope(node).set.get(node.name)?.defs.at(-1))?.type === DefinitionType.Parameter) return null; | ||
| const initNode = resolve(context, node, -1, true); | ||
| const initNode = resolve(context, node, { | ||
| at: -1, | ||
| localOnly: true | ||
| }); | ||
| if (initNode == null) return null; | ||
@@ -169,11 +174,11 @@ return computeObjectType(context, initNode); | ||
| * Determine whether node value equals to another node value | ||
| * @param context rule context | ||
| * @param a node to compare | ||
| * @param b node to compare | ||
| * @param initialScopes initial scopes of the two nodes | ||
| * @returns `true` if node value equal | ||
| */ | ||
| function isValueEqual(a, b, initialScopes) { | ||
| function isValueEqual(context, a, b) { | ||
| a = ast.isTypeExpression(a) ? ast.getUnderlyingExpression(a) : a; | ||
| b = ast.isTypeExpression(b) ? ast.getUnderlyingExpression(b) : b; | ||
| const [aScope, bScope] = initialScopes; | ||
| const [aScope, bScope] = [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]; | ||
| switch (true) { | ||
@@ -225,3 +230,3 @@ case a === b: return true; | ||
| } | ||
| case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return ast.isNodeEqual(a.property, b.property) && isValueEqual(a.object, b.object, initialScopes); | ||
| case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return ast.isNodeEqual(a.property, b.property) && isValueEqual(context, a.object, b.object); | ||
| case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: | ||
@@ -250,3 +255,3 @@ if (aScope.block === bScope.block) return true; | ||
| function isAssignmentTargetEqual(context, a, b) { | ||
| return ast.isNodeEqual(a, b) || isValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]); | ||
| return ast.isNodeEqual(a, b) || isValueEqual(context, a, b); | ||
| } | ||
@@ -253,0 +258,0 @@ |
+4
-4
| { | ||
| "name": "@eslint-react/var", | ||
| "version": "3.0.0-next.65", | ||
| "version": "3.0.0-next.66", | ||
| "description": "ESLint React's TSESTree AST utility module for static analysis of variables.", | ||
@@ -37,5 +37,5 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
| "ts-pattern": "^5.9.0", | ||
| "@eslint-react/ast": "3.0.0-next.65", | ||
| "@eslint-react/eff": "3.0.0-next.65", | ||
| "@eslint-react/shared": "3.0.0-next.65" | ||
| "@eslint-react/ast": "3.0.0-next.66", | ||
| "@eslint-react/eff": "3.0.0-next.66", | ||
| "@eslint-react/shared": "3.0.0-next.66" | ||
| }, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
364
2.25%20396
-0.01%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed