Skip to content

Commit 20d7468

Browse files
committed
refactor(linter/plugins): move type defs to top of file in scope.ts
1 parent 77b5140 commit 20d7468

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

apps/oxlint/src-js/plugins/scope.ts

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,75 @@ import { assertIs } from './utils.js';
1313
import type * as ESTree from '../generated/types.d.ts';
1414
import type { SetNullable } from './utils.ts';
1515

16+
export interface Scope {
17+
type: ScopeType;
18+
isStrict: boolean;
19+
upper: Scope | null;
20+
childScopes: Scope[];
21+
variableScope: Scope;
22+
block: ESTree.Node;
23+
variables: Variable[];
24+
set: Map<string, Variable>;
25+
references: Reference[];
26+
through: Reference[];
27+
functionExpressionScope: boolean;
28+
implicit?: {
29+
variables: Variable[];
30+
set: Map<string, Variable>;
31+
};
32+
}
33+
34+
export type ScopeType =
35+
| 'block'
36+
| 'catch'
37+
| 'class'
38+
| 'class-field-initializer'
39+
| 'class-static-block'
40+
| 'for'
41+
| 'function'
42+
| 'function-expression-name'
43+
| 'global'
44+
| 'module'
45+
| 'switch'
46+
| 'with';
47+
48+
export interface Variable {
49+
name: string;
50+
scope: Scope;
51+
identifiers: Identifier[];
52+
references: Reference[];
53+
defs: Definition[];
54+
}
55+
56+
export interface Reference {
57+
identifier: Identifier;
58+
from: Scope;
59+
resolved: Variable | null;
60+
writeExpr: ESTree.Expression | null;
61+
init: boolean;
62+
isWrite(): boolean;
63+
isRead(): boolean;
64+
isReadOnly(): boolean;
65+
isWriteOnly(): boolean;
66+
isReadWrite(): boolean;
67+
}
68+
69+
export interface Definition {
70+
type: DefinitionType;
71+
name: Identifier;
72+
node: ESTree.Node;
73+
parent: ESTree.Node | null;
74+
}
75+
76+
export type DefinitionType =
77+
| 'CatchClause'
78+
| 'ClassName'
79+
| 'FunctionName'
80+
| 'ImplicitGlobalVariable'
81+
| 'ImportBinding'
82+
| 'Parameter'
83+
| 'Variable';
84+
1685
type Identifier =
1786
| ESTree.IdentifierName
1887
| ESTree.IdentifierReference
@@ -119,75 +188,6 @@ export const SCOPE_MANAGER = Object.freeze({
119188

120189
export type ScopeManager = typeof SCOPE_MANAGER;
121190

122-
export interface Scope {
123-
type: ScopeType;
124-
isStrict: boolean;
125-
upper: Scope | null;
126-
childScopes: Scope[];
127-
variableScope: Scope;
128-
block: ESTree.Node;
129-
variables: Variable[];
130-
set: Map<string, Variable>;
131-
references: Reference[];
132-
through: Reference[];
133-
functionExpressionScope: boolean;
134-
implicit?: {
135-
variables: Variable[];
136-
set: Map<string, Variable>;
137-
};
138-
}
139-
140-
export type ScopeType =
141-
| 'block'
142-
| 'catch'
143-
| 'class'
144-
| 'class-field-initializer'
145-
| 'class-static-block'
146-
| 'for'
147-
| 'function'
148-
| 'function-expression-name'
149-
| 'global'
150-
| 'module'
151-
| 'switch'
152-
| 'with';
153-
154-
export interface Variable {
155-
name: string;
156-
scope: Scope;
157-
identifiers: Identifier[];
158-
references: Reference[];
159-
defs: Definition[];
160-
}
161-
162-
export interface Reference {
163-
identifier: Identifier;
164-
from: Scope;
165-
resolved: Variable | null;
166-
writeExpr: ESTree.Expression | null;
167-
init: boolean;
168-
isWrite(): boolean;
169-
isRead(): boolean;
170-
isReadOnly(): boolean;
171-
isWriteOnly(): boolean;
172-
isReadWrite(): boolean;
173-
}
174-
175-
export interface Definition {
176-
type: DefinitionType;
177-
name: Identifier;
178-
node: ESTree.Node;
179-
parent: ESTree.Node | null;
180-
}
181-
182-
export type DefinitionType =
183-
| 'CatchClause'
184-
| 'ClassName'
185-
| 'FunctionName'
186-
| 'ImplicitGlobalVariable'
187-
| 'ImportBinding'
188-
| 'Parameter'
189-
| 'Variable';
190-
191191
/**
192192
* Determine whether the given identifier node is a reference to a global variable.
193193
* @param node - `Identifier` node to check.

0 commit comments

Comments
 (0)