UNPKG

3.31 kBTypeScriptView Raw
1import { TSESTree } from '../../ts-estree';
2import * as TSESLint from '../../ts-eslint';
3declare const ReferenceTrackerREAD: unique symbol;
4declare const ReferenceTrackerCALL: unique symbol;
5declare const ReferenceTrackerCONSTRUCT: unique symbol;
6interface ReferenceTracker {
7 /**
8 * Iterate the references that the given `traceMap` determined.
9 * This method starts to search from global variables.
10 *
11 * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iterateglobalreferences}
12 */
13 iterateGlobalReferences<T>(traceMap: ReferenceTracker.TraceMap<T>): IterableIterator<ReferenceTracker.FoundReference<T>>;
14 /**
15 * Iterate the references that the given `traceMap` determined.
16 * This method starts to search from `require()` expression.
17 *
18 * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iteratecjsreferences}
19 */
20 iterateCjsReferences<T>(traceMap: ReferenceTracker.TraceMap<T>): IterableIterator<ReferenceTracker.FoundReference<T>>;
21 /**
22 * Iterate the references that the given `traceMap` determined.
23 * This method starts to search from `import`/`export` declarations.
24 *
25 * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iterateesmreferences}
26 */
27 iterateEsmReferences<T>(traceMap: ReferenceTracker.TraceMap<T>): IterableIterator<ReferenceTracker.FoundReference<T>>;
28}
29interface ReferenceTrackerStatic {
30 new (globalScope: TSESLint.Scope.Scope, options?: {
31 /**
32 * The mode which determines how the `tracker.iterateEsmReferences()` method scans CommonJS modules.
33 * If this is `"strict"`, the method binds CommonJS modules to the default export. Otherwise, the method binds
34 * CommonJS modules to both the default export and named exports. Optional. Default is `"strict"`.
35 */
36 mode: 'strict' | 'legacy';
37 /**
38 * The name list of Global Object. Optional. Default is `["global", "globalThis", "self", "window"]`.
39 */
40 globalObjectNames: readonly string[];
41 }): ReferenceTracker;
42 readonly READ: typeof ReferenceTrackerREAD;
43 readonly CALL: typeof ReferenceTrackerCALL;
44 readonly CONSTRUCT: typeof ReferenceTrackerCONSTRUCT;
45}
46declare namespace ReferenceTracker {
47 type READ = ReferenceTrackerStatic['READ'];
48 type CALL = ReferenceTrackerStatic['CALL'];
49 type CONSTRUCT = ReferenceTrackerStatic['CONSTRUCT'];
50 type ReferenceType = READ | CALL | CONSTRUCT;
51 type TraceMap<T = any> = Record<string, TraceMapElement<T>>;
52 interface TraceMapElement<T> {
53 [ReferenceTrackerREAD]?: T;
54 [ReferenceTrackerCALL]?: T;
55 [ReferenceTrackerCONSTRUCT]?: T;
56 [key: string]: TraceMapElement<T>;
57 }
58 interface FoundReference<T = any> {
59 node: TSESTree.Node;
60 path: readonly string[];
61 type: ReferenceType;
62 entry: T;
63 }
64}
65/**
66 * The tracker for references. This provides reference tracking for global variables, CommonJS modules, and ES modules.
67 *
68 * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#referencetracker-class}
69 */
70declare const ReferenceTracker: ReferenceTrackerStatic;
71export { ReferenceTracker };
72//# sourceMappingURL=ReferenceTracker.d.ts.map
\No newline at end of file