Skip to content

Commit 7c58687

Browse files
committed
feat: enhance test-utils
1 parent e2f8d84 commit 7c58687

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

test/test-utils.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import type { Identifier } from "estree"
2-
import type { Scope, ScopeManager } from "eslint-scope"
1+
import type { Identifier, Node } from "estree"
2+
import type {
3+
Scope,
4+
ScopeManager,
5+
Variable,
6+
VariableDefinition,
7+
} from "eslint-scope"
38
import type { ESLintProgram, Token } from "../src/ast"
49
import type { ParserOptions } from "../src/common/parser-options"
510
import escope from "eslint-scope"
@@ -41,7 +46,7 @@ export function getAllTokens(ast: ESLintProgram): Token[] {
4146
export function scopeToJSON(scopeManager: ScopeManager) {
4247
return JSON.stringify(normalizeScope(scopeManager.globalScope), replacer, 4)
4348

44-
function normalizeScope(scope: Scope) {
49+
function normalizeScope(scope: Scope): any {
4550
return {
4651
type: scope.type,
4752
variables: scope.variables.map(normalizeVar),
@@ -51,7 +56,7 @@ export function scopeToJSON(scopeManager: ScopeManager) {
5156
}
5257
}
5358

54-
function normalizeVar(v) {
59+
function normalizeVar(v: Variable) {
5560
return {
5661
name: v.name,
5762
identifiers: v.identifiers.map(normalizeId),
@@ -60,7 +65,7 @@ export function scopeToJSON(scopeManager: ScopeManager) {
6065
}
6166
}
6267

63-
function normalizeReference(reference) {
68+
function normalizeReference(reference: any) {
6469
return {
6570
identifier: normalizeId(reference.identifier),
6671
from: reference.from.type,
@@ -77,15 +82,15 @@ export function scopeToJSON(scopeManager: ScopeManager) {
7782
}
7883
}
7984

80-
function normalizeDef(def) {
85+
function normalizeDef(def: VariableDefinition) {
8186
return {
8287
type: def.type,
8388
node: normalizeDefNode(def.node),
8489
name: def.name.name,
8590
}
8691
}
8792

88-
function normalizeId(identifier: Identifier) {
93+
function normalizeId(identifier: Identifier | null) {
8994
return (
9095
identifier && {
9196
type: identifier.type,
@@ -95,7 +100,7 @@ export function scopeToJSON(scopeManager: ScopeManager) {
95100
)
96101
}
97102

98-
function normalizeDefNode(node) {
103+
function normalizeDefNode(node: Node) {
99104
return {
100105
type: node.type,
101106
loc: node.loc,
@@ -106,7 +111,10 @@ export function scopeToJSON(scopeManager: ScopeManager) {
106111
/**
107112
* Analyze scope
108113
*/
109-
export function analyze(ast: ESLintProgram, parserOptions: ParserOptions) {
114+
export function analyze(
115+
ast: ESLintProgram,
116+
parserOptions: ParserOptions,
117+
): ScopeManager {
110118
const ecmaVersion = parserOptions.ecmaVersion ?? 2022
111119
const ecmaFeatures = parserOptions.ecmaFeatures ?? {}
112120
const sourceType = parserOptions.sourceType ?? "script"
@@ -121,11 +129,11 @@ export function analyze(ast: ESLintProgram, parserOptions: ParserOptions) {
121129

122130
return result
123131

124-
function getFallbackKeys(node) {
132+
function getFallbackKeys(node: any) {
125133
return Object.keys(node).filter(fallbackKeysFilter, node)
126134
}
127135

128-
function fallbackKeysFilter(key) {
136+
function fallbackKeysFilter(key: string) {
129137
const value = null
130138
return (
131139
key !== "comments" &&

0 commit comments

Comments
 (0)