UNPKG

estree-toolkit

Version:

Traverser, scope tracker, and more tools for working with ESTree AST

57 lines (56 loc) 2.59 kB
import { Identifier } from 'estree-jsx'; import { NodeT } from './helpers'; import { NodePath, NodePathT } from './nodepath'; import { Binding, BindingKind, BindingPathT, GlobalBinding } from './binding'; declare const scopedNodeTypes: readonly ["ArrowFunctionExpression", "BlockStatement", "CatchClause", "ClassDeclaration", "ClassExpression", "DoWhileStatement", "ForInStatement", "ForOfStatement", "ForStatement", "FunctionDeclaration", "FunctionExpression", "Program", "SwitchStatement", "WhileStatement"]; type ScopedNode = typeof scopedNodeTypes[number]; export type Label = { path: NodePath<Identifier, NodeT<'LabeledStatement'>>; references: NodePath<Identifier, NodeT<'BreakStatement' | 'ContinueStatement'>>[]; }; export declare class Scope { readonly path: NodePathT<ScopedNode>; readonly parent: Scope | null; readonly children: Scope[]; private initialized; bindings: Record<string, Binding | undefined>; globalBindings: Record<string, GlobalBinding | undefined>; labels: Record<string, Label | undefined>; private priv; private constructor(); static for(path: NodePath, parentScope: Scope | null): Scope | null; init(): void; private getMemoBinding; private getMemoLabel; private clearMemo; getProgramScope(): Scope; crawl(): void; /** Rollback all the changes contributed by this scope * @internal */ static rollbackState(scope: Scope): void; /** @internal */ static recursiveRollback(scope: Scope): void; /** @internal */ static handleRemoval(scope: Scope, path: NodePath): void; /** @internal */ registerBinding<T extends BindingKind>(kind: T, identifierPath: NodePath<Identifier>, bindingPath: BindingPathT<T>): void; hasOwnBinding(name: string): boolean; getOwnBinding(name: string): Binding | undefined; hasBinding(name: string): boolean; getBinding(name: string): Binding | undefined; getAllBindings(...kind: BindingKind[]): Record<string, Binding>; hasGlobalBinding(name: string): boolean; getGlobalBinding(name: string): GlobalBinding | undefined; /** @internal */ registerLabel(path: NodePath<Identifier, NodeT<'LabeledStatement'>>): void; hasLabel(name: string): boolean; getLabel(name: string): Label | undefined; generateUid(name?: string): string; generateUidIdentifier(name?: string): Identifier; generateDeclaredUidIdentifier(name?: string): NodeT<'Identifier'>; /** @internal */ private renameConsideringParent; renameBinding(oldName: string, newName: string): void; } export {};