Skip to content

Commit 77e387e

Browse files
authored
refactor(var): rename utility files and improve code organization (#1221)
1 parent ad0354e commit 77e387e

File tree

9 files changed

+41
-34
lines changed

9 files changed

+41
-34
lines changed

packages/utilities/var/src/value-construction.ts renamed to packages/utilities/var/src/construction-detection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Scope } from "@typescript-eslint/scope-manager";
33
import type { TSESTree } from "@typescript-eslint/types";
44

55
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
6-
import { getVariableDefinitionNode } from "./variable-resolver";
6+
import { getVariableDefinitionNode } from "./get-variable-definition-node";
77

88
export const ConstructionDetectionHint = {
99
None: 0n,

packages/utilities/var/src/misc.ts renamed to packages/utilities/var/src/find-property.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ import type { unit } from "@eslint-react/eff";
22
import type { Scope } from "@typescript-eslint/scope-manager";
33
import type { TSESTree } from "@typescript-eslint/types";
44
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
5-
import { findVariable } from "./variable-extractor";
6-
import { getVariableDefinitionNode } from "./variable-resolver";
7-
8-
export function getChildScopes(scope: Scope): readonly Scope[] {
9-
const scopes = [scope];
10-
for (const childScope of scope.childScopes) {
11-
scopes.push(...getChildScopes(childScope));
12-
}
13-
return scopes;
14-
}
5+
import { getVariableDefinitionNode } from "./get-variable-definition-node";
6+
import { findVariable } from "./get-variables-from-scope";
157

168
export function findProperty(
179
name: string,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Scope } from "@typescript-eslint/scope-manager";
2+
3+
export function getChildScopes(scope: Scope): readonly Scope[] {
4+
const scopes = [scope];
5+
for (const childScope of scope.childScopes) {
6+
scopes.push(...getChildScopes(childScope));
7+
}
8+
return scopes;
9+
}

packages/utilities/var/src/variable-resolver.ts renamed to packages/utilities/var/src/get-variable-definition-node.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as AST from "@eslint-react/ast";
12
import { unit } from "@eslint-react/eff";
23
import type { Variable } from "@typescript-eslint/scope-manager";
34
import { DefinitionType } from "@typescript-eslint/scope-manager";
@@ -32,3 +33,21 @@ export function getVariableDefinitionNode(variable: Variable | unit, at: number)
3233
return unit;
3334
}
3435
}
36+
37+
export function getVariableDefinitionNodeLoose(variable: Variable | unit, at: number):
38+
| unit
39+
| TSESTree.ClassDeclaration
40+
| TSESTree.ClassDeclarationWithName
41+
| TSESTree.ClassDeclarationWithOptionalName
42+
| TSESTree.Expression
43+
| TSESTree.FunctionDeclaration
44+
| TSESTree.FunctionDeclarationWithName
45+
| TSESTree.FunctionDeclarationWithOptionalName
46+
{
47+
if (variable == null) return unit;
48+
const node = getVariableDefinitionNode(variable, at);
49+
if (node != null) return node;
50+
const def = variable.defs.at(at);
51+
if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node;
52+
return unit;
53+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export * from "./misc";
2-
export * from "./value-construction";
3-
export * from "./value-equal";
4-
export * from "./variable-assignment";
5-
export type * from "./variable-declaration";
6-
export * from "./variable-extractor";
7-
export * from "./variable-resolver";
1+
export * from "./construction-detection";
2+
export * from "./find-assignment-target";
3+
export * from "./find-property";
4+
export * from "./get-child-scopes";
5+
export * from "./get-variable-definition-node";
6+
export * from "./get-variables-from-scope";
7+
export * from "./is-node-value-equal";

packages/utilities/var/src/value-equal.ts renamed to packages/utilities/var/src/is-node-value-equal.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as AST from "@eslint-react/ast";
2-
import { unit } from "@eslint-react/eff";
3-
import { DefinitionType, type Scope, type Variable } from "@typescript-eslint/scope-manager";
2+
import { type Scope } from "@typescript-eslint/scope-manager";
43
import type { TSESTree } from "@typescript-eslint/types";
54
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
65
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
7-
import { findVariable } from "./variable-extractor";
8-
import { getVariableDefinitionNode } from "./variable-resolver";
6+
import { getVariableDefinitionNodeLoose } from "./get-variable-definition-node";
7+
import { findVariable } from "./get-variables-from-scope";
98

109
const thisBlockTypes = [
1110
T.FunctionDeclaration,
@@ -105,15 +104,3 @@ export function isNodeValueEqual(
105104
}
106105
}
107106
}
108-
109-
function getVariableDefinitionNodeLoose(
110-
variable: Variable | unit,
111-
at: number,
112-
): ReturnType<typeof getVariableDefinitionNode> {
113-
if (variable == null) return unit;
114-
const node = getVariableDefinitionNode(variable, at);
115-
if (node != null) return node;
116-
const def = variable.defs.at(at);
117-
if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node;
118-
return unit;
119-
}

packages/utilities/var/src/variable-declaration.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)