diff --git a/packages/utilities/var/src/value-construction.ts b/packages/utilities/var/src/construction-detection.ts similarity index 97% rename from packages/utilities/var/src/value-construction.ts rename to packages/utilities/var/src/construction-detection.ts index 3bd3628c1c..cca5633b06 100644 --- a/packages/utilities/var/src/value-construction.ts +++ b/packages/utilities/var/src/construction-detection.ts @@ -3,7 +3,7 @@ import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { getVariableDefinitionNode } from "./variable-resolver"; +import { getVariableDefinitionNode } from "./get-variable-definition-node"; export const ConstructionDetectionHint = { None: 0n, diff --git a/packages/utilities/var/src/variable-assignment.ts b/packages/utilities/var/src/find-assignment-target.ts similarity index 100% rename from packages/utilities/var/src/variable-assignment.ts rename to packages/utilities/var/src/find-assignment-target.ts diff --git a/packages/utilities/var/src/misc.ts b/packages/utilities/var/src/find-property.ts similarity index 82% rename from packages/utilities/var/src/misc.ts rename to packages/utilities/var/src/find-property.ts index 8e5f7413d0..8dc8c3f4fd 100644 --- a/packages/utilities/var/src/misc.ts +++ b/packages/utilities/var/src/find-property.ts @@ -2,16 +2,8 @@ import type { unit } from "@eslint-react/eff"; import type { Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; -import { findVariable } from "./variable-extractor"; -import { getVariableDefinitionNode } from "./variable-resolver"; - -export function getChildScopes(scope: Scope): readonly Scope[] { - const scopes = [scope]; - for (const childScope of scope.childScopes) { - scopes.push(...getChildScopes(childScope)); - } - return scopes; -} +import { getVariableDefinitionNode } from "./get-variable-definition-node"; +import { findVariable } from "./get-variables-from-scope"; export function findProperty( name: string, diff --git a/packages/utilities/var/src/get-child-scopes.ts b/packages/utilities/var/src/get-child-scopes.ts new file mode 100644 index 0000000000..16ec013580 --- /dev/null +++ b/packages/utilities/var/src/get-child-scopes.ts @@ -0,0 +1,9 @@ +import type { Scope } from "@typescript-eslint/scope-manager"; + +export function getChildScopes(scope: Scope): readonly Scope[] { + const scopes = [scope]; + for (const childScope of scope.childScopes) { + scopes.push(...getChildScopes(childScope)); + } + return scopes; +} diff --git a/packages/utilities/var/src/variable-resolver.ts b/packages/utilities/var/src/get-variable-definition-node.ts similarity index 63% rename from packages/utilities/var/src/variable-resolver.ts rename to packages/utilities/var/src/get-variable-definition-node.ts index 103146cb8e..ec80dda093 100644 --- a/packages/utilities/var/src/variable-resolver.ts +++ b/packages/utilities/var/src/get-variable-definition-node.ts @@ -1,3 +1,4 @@ +import * as AST from "@eslint-react/ast"; import { unit } from "@eslint-react/eff"; import type { Variable } from "@typescript-eslint/scope-manager"; import { DefinitionType } from "@typescript-eslint/scope-manager"; @@ -32,3 +33,21 @@ export function getVariableDefinitionNode(variable: Variable | unit, at: number) return unit; } } + +export function getVariableDefinitionNodeLoose(variable: Variable | unit, at: number): + | unit + | TSESTree.ClassDeclaration + | TSESTree.ClassDeclarationWithName + | TSESTree.ClassDeclarationWithOptionalName + | TSESTree.Expression + | TSESTree.FunctionDeclaration + | TSESTree.FunctionDeclarationWithName + | TSESTree.FunctionDeclarationWithOptionalName +{ + if (variable == null) return unit; + const node = getVariableDefinitionNode(variable, at); + if (node != null) return node; + const def = variable.defs.at(at); + if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node; + return unit; +} diff --git a/packages/utilities/var/src/variable-extractor.ts b/packages/utilities/var/src/get-variables-from-scope.ts similarity index 100% rename from packages/utilities/var/src/variable-extractor.ts rename to packages/utilities/var/src/get-variables-from-scope.ts diff --git a/packages/utilities/var/src/index.ts b/packages/utilities/var/src/index.ts index 2d6eaf363c..e3f2abc654 100644 --- a/packages/utilities/var/src/index.ts +++ b/packages/utilities/var/src/index.ts @@ -1,7 +1,7 @@ -export * from "./misc"; -export * from "./value-construction"; -export * from "./value-equal"; -export * from "./variable-assignment"; -export type * from "./variable-declaration"; -export * from "./variable-extractor"; -export * from "./variable-resolver"; +export * from "./construction-detection"; +export * from "./find-assignment-target"; +export * from "./find-property"; +export * from "./get-child-scopes"; +export * from "./get-variable-definition-node"; +export * from "./get-variables-from-scope"; +export * from "./is-node-value-equal"; diff --git a/packages/utilities/var/src/value-equal.ts b/packages/utilities/var/src/is-node-value-equal.ts similarity index 84% rename from packages/utilities/var/src/value-equal.ts rename to packages/utilities/var/src/is-node-value-equal.ts index 4b32ce8af2..24b11dab25 100644 --- a/packages/utilities/var/src/value-equal.ts +++ b/packages/utilities/var/src/is-node-value-equal.ts @@ -1,11 +1,10 @@ import * as AST from "@eslint-react/ast"; -import { unit } from "@eslint-react/eff"; -import { DefinitionType, type Scope, type Variable } from "@typescript-eslint/scope-manager"; +import { type Scope } from "@typescript-eslint/scope-manager"; import type { TSESTree } from "@typescript-eslint/types"; import { AST_NODE_TYPES as T } from "@typescript-eslint/types"; import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; -import { findVariable } from "./variable-extractor"; -import { getVariableDefinitionNode } from "./variable-resolver"; +import { getVariableDefinitionNodeLoose } from "./get-variable-definition-node"; +import { findVariable } from "./get-variables-from-scope"; const thisBlockTypes = [ T.FunctionDeclaration, @@ -105,15 +104,3 @@ export function isNodeValueEqual( } } } - -function getVariableDefinitionNodeLoose( - variable: Variable | unit, - at: number, -): ReturnType { - if (variable == null) return unit; - const node = getVariableDefinitionNode(variable, at); - if (node != null) return node; - const def = variable.defs.at(at); - if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node; - return unit; -} diff --git a/packages/utilities/var/src/variable-declaration.ts b/packages/utilities/var/src/variable-declaration.ts deleted file mode 100644 index e69de29bb2..0000000000