@typescript-eslint/scope-manager
TypeScript scope analyser for ESLint
Last updated 3 years ago by jameshenry .
MIT · Repository · Bugs · Original npm
$ cnpm install @typescript-eslint/scope-manager 
SYNC missed versions from official npm registry.

TypeScript Scope Manager

CI NPM Version NPM Downloads

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 {
  /**
   * Known visitor keys.
   */
  childVisitorKeys?: Record<string, string[]> | null;

  /**
   * Which ECMAScript version is considered.
   * Defaults to `2018`.
   * `'latest'` is converted to 1e8 at parser.
   */
  ecmaVersion?: EcmaVersion | 1e8;

  /**
   * Whether the whole script is executed under node.js environment.
   * When enabled, the scope manager adds a function scope immediately following the global scope.
   * Defaults to `false`.
   */
  globalReturn?: boolean;

  /**
   * Implied strict mode (if ecmaVersion >= 5).
   * Defaults to `false`.
   */
  impliedStrict?: boolean;

  /**
   * The identifier that's used for JSX Element creation (after transpilation).
   * This should not be a member expression - just the root identifier (i.e. use "React" instead of "React.createElement").
   * Defaults to `"React"`.
   */
  jsxPragma?: string;

  /**
   * The identifier that's used for JSX fragment elements (after transpilation).
   * If `null`, assumes transpilation will always use a member on `jsxFactory` (i.e. React.Fragment).
   * This should not be a member expression - just the root identifier (i.e. use "h" instead of "h.Fragment").
   * Defaults to `null`.
   */
  jsxFragmentName?: string | null;

  /**
   * The lib used by the project.
   * This automatically defines a type variable for any types provided by the configured TS libs.
   * For more information, see https://www.typescriptlang.org/tsconfig#lib
   *
   * Defaults to the lib for the provided `ecmaVersion`.
   */
  lib?: Lib[];

  /**
   * The source type of the script.
   */
  sourceType?: 'script' | 'module';

  /**
   * Emit design-type metadata for decorated declarations in source.
   * Defaults to `false`.
   */
  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, {
  // note that scope-manager requires ranges on the AST
  range: true,
});
const scope = analyze(ast, {
  ecmaVersion: 2020,
  sourceType: 'module',
});

References

Contributing

See the contributing guide here

Current Tags

  • 6.0.1-alpha.0                                ...           canary (2 years ago)
  • 6.0.0                                ...           latest (2 years ago)

70 Versions

  • 7.0.0-alpha.0                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 6.0.1-alpha.0                                ...           2 years ago
  • 5.62.0                                ...           2 years ago
  • 6.0.0-alpha.165                                ...           2 years ago
  • 5.61.1-alpha.0                                ...           2 years ago
  • 5.61.0                                ...           2 years ago
  • 6.0.0-alpha.138                                ...           2 years ago
  • 5.57.1-alpha.8                                ...           2 years ago
  • 6.0.0-alpha.139                                ...           2 years ago
  • 6.0.0-alpha.58                                ...           3 years ago
  • 5.57.1-alpha.9                                ...           2 years ago
  • 5.59.1                                ...           2 years ago
  • 5.52.1-alpha.4                                ...           3 years ago
  • 5.52.0                                ...           3 years ago
  • 5.48.0                                ...           3 years ago
  • 5.48.1-alpha.4                                ...           3 years ago
  • 5.43.1-alpha.14                                ...           3 years ago
  • 5.43.0                                ...           3 years ago
  • 5.27.1                                ...           3 years ago
  • 5.36.1                                ...           3 years ago
  • 5.42.1-alpha.4                                ...           3 years ago
  • 5.42.1-alpha.0                                ...           3 years ago
  • 5.42.0                                ...           3 years ago
  • 5.40.1-alpha.3                                ...           3 years ago
  • 5.40.1-alpha.9                                ...           3 years ago
  • 5.40.0                                ...           3 years ago
  • 5.38.1-alpha.0                                ...           3 years ago
  • 5.38.0                                ...           3 years ago
  • 5.32.1-alpha.0                                ...           3 years ago
  • 5.32.0                                ...           3 years ago
  • 5.26.1-alpha.25                                ...           3 years ago
  • 5.26.1-alpha.26                                ...           3 years ago
  • 5.26.0                                ...           3 years ago
  • 5.26.1-alpha.28                                ...           3 years ago
  • 4.15.2                                ...           5 years ago
  • 5.23.1-alpha.18                                ...           3 years ago
  • 5.23.0                                ...           3 years ago
  • 5.16.1-alpha.10                                ...           3 years ago
  • 5.16.0                                ...           3 years ago
  • 5.14.0                                ...           3 years ago
  • 5.14.1-alpha.14                                ...           3 years ago
  • 5.10.2-alpha.0                                ...           4 years ago
  • 5.10.1                                ...           4 years ago
  • 5.9.2-alpha.23                                ...           4 years ago
  • 4.33.0                                ...           4 years ago
  • 5.0.0-alpha.42                                ...           4 years ago
  • 5.9.2-alpha.21                                ...           4 years ago
  • 5.9.1                                ...           4 years ago
  • 5.0.0-alpha.48                                ...           4 years ago
  • 4.31.3-alpha.28                                ...           4 years ago
  • 4.31.2                                ...           4 years ago
  • 5.0.0-alpha.39                                ...           4 years ago
  • 4.31.1-alpha.0                                ...           4 years ago
  • 4.31.0                                ...           4 years ago
  • 5.0.0-alpha.25                                ...           4 years ago
  • 4.30.1-alpha.6                                ...           4 years ago
  • 4.30.0                                ...           4 years ago
  • 4.29.2-alpha.0                                ...           4 years ago
  • 4.29.1                                ...           4 years ago
  • 4.18.1-alpha.1                                ...           4 years ago
  • 4.18.0                                ...           4 years ago
  • 4.11.0                                ...           5 years ago
  • 4.11.1-alpha.0                                ...           5 years ago
  • 4.0.0-alpha.16                                ...           5 years ago
  • 4.0.2-alpha.2                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 3.9.0                                ...           5 years ago
  • 3.9.1-alpha.0                                ...           5 years ago
  • 4.0.0-alpha.8                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org