TypeScript Scope Manager
This is a fork of eslint-scope
, enhanced to support TypeScript functionality.
You can view the original license for the code here.
This package is consumed automatically by @typescript-eslint/parser
.
You probably don't want to use it directly.
Getting Started
You can find our Getting Started docs here
Installation
$ yarn add -D typescript @typescript-eslint/scope-manager
$ npm i --save-dev typescript @typescript-eslint/scope-manager
API
analyze(tree, options)
Analyses a given AST and returns the resulting ScopeManager
.
interface AnalyzeOptions {
childVisitorKeys?: Record<string, string[]> | null;
ecmaVersion?: EcmaVersion | 1e8;
globalReturn?: boolean;
impliedStrict?: boolean;
jsxPragma?: string;
jsxFragmentName?: string | null;
lib?: Lib[];
sourceType?: 'script' | 'module';
emitDecoratorMetadata?: boolean;
}
Example usage:
import { analyze } from '@typescript-eslint/scope-manager';
import { parse } from '@typescript-eslint/typescript-estree';
const code = `const hello: string = 'world';`;
const ast = parse(code, {
range: true,
});
const scope = analyze(ast, {
ecmaVersion: 2020,
sourceType: 'module',
});
References
Contributing
See the contributing guide here