Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions packages/utilities/var/src/get-child-scopes.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
14 changes: 7 additions & 7 deletions packages/utilities/var/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -105,15 +104,3 @@ export function isNodeValueEqual(
}
}
}

function getVariableDefinitionNodeLoose(
variable: Variable | unit,
at: number,
): ReturnType<typeof getVariableDefinitionNode> {
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;
}
Empty file.