1- const escope = require ( "eslint-scope" )
2-
3- module . exports = { replacer, getAllTokens, scopeToJSON, analyze }
1+ import type { Identifier } from "estree"
2+ import type { Scope , ScopeManager } from "eslint-scope"
3+ import type { ESLintProgram , Token } from "../src/ast"
4+ import type { ParserOptions } from "../src/common/parser-options"
5+ import escope from "eslint-scope"
46
57/**
68 * Remove `parent` properties from the given AST.
7- * @param { string } key The key.
8- * @param { any } value The value of the key.
9- * @returns { any } The value of the key to output.
9+ * @param key The key.
10+ * @param value The value of the key.
11+ * @returns The value of the key to output.
1012 */
11- function replacer ( key , value ) {
13+ export function replacer ( key : string , value : any ) : any {
1214 if ( key === "parent" ) {
1315 return undefined
1416 }
@@ -25,21 +27,21 @@ function replacer(key, value) {
2527
2628/**
2729 * Get all tokens of the given AST.
28- * @param { ASTNode } ast The root node of AST.
29- * @returns { Token[] } Tokens.
30+ * @param ast The root node of AST.
31+ * @returns Tokens.
3032 */
31- function getAllTokens ( ast ) {
33+ export function getAllTokens ( ast : ESLintProgram ) : Token [ ] {
3234 const tokenArrays = [ ast . tokens , ast . comments ]
3335 if ( ast . templateBody != null ) {
3436 tokenArrays . push ( ast . templateBody . tokens , ast . templateBody . comments )
3537 }
3638 return Array . prototype . concat . apply ( [ ] , tokenArrays )
3739}
3840
39- function scopeToJSON ( scopeManager ) {
41+ export function scopeToJSON ( scopeManager : ScopeManager ) {
4042 return JSON . stringify ( normalizeScope ( scopeManager . globalScope ) , replacer , 4 )
4143
42- function normalizeScope ( scope ) {
44+ function normalizeScope ( scope : Scope ) {
4345 return {
4446 type : scope . type ,
4547 variables : scope . variables . map ( normalizeVar ) ,
@@ -83,7 +85,7 @@ function scopeToJSON(scopeManager) {
8385 }
8486 }
8587
86- function normalizeId ( identifier ) {
88+ function normalizeId ( identifier : Identifier ) {
8789 return (
8890 identifier && {
8991 type : identifier . type ,
@@ -104,7 +106,7 @@ function scopeToJSON(scopeManager) {
104106/**
105107 * Analyze scope
106108 */
107- function analyze ( ast , parserOptions ) {
109+ export function analyze ( ast : ESLintProgram , parserOptions : ParserOptions ) {
108110 const ecmaVersion = parserOptions . ecmaVersion ?? 2022
109111 const ecmaFeatures = parserOptions . ecmaFeatures ?? { }
110112 const sourceType = parserOptions . sourceType ?? "script"
0 commit comments