UNPKG

@types/babel-traverse

Version:
1,002 lines (883 loc) 48.6 kB
import * as t from "babel-types"; export type Node = t.Node; export default function traverse<S>( parent: Node | Node[], opts: TraverseOptions<S>, scope: Scope, state: S, parentPath?: NodePath, ): void; export default function traverse( parent: Node | Node[], opts: TraverseOptions, scope?: Scope, state?: any, parentPath?: NodePath, ): void; export interface TraverseOptions<S = Node> extends Visitor<S> { scope?: Scope | undefined; noScope?: boolean | undefined; } export class Scope { constructor(path: NodePath, parentScope?: Scope); path: NodePath; block: Node; parentBlock: Node; parent: Scope; hub: Hub; bindings: { [name: string]: Binding }; /** Traverse node with current scope and path. */ traverse<S>(node: Node | Node[], opts: TraverseOptions<S>, state: S): void; traverse(node: Node | Node[], opts?: TraverseOptions, state?: any): void; /** Generate a unique identifier and add it to the current scope. */ generateDeclaredUidIdentifier(name?: string): t.Identifier; /** Generate a unique identifier. */ generateUidIdentifier(name?: string): t.Identifier; /** Generate a unique `_id1` binding. */ generateUid(name?: string): string; /** Generate a unique identifier based on a node. */ generateUidIdentifierBasedOnNode(parent: Node, defaultName?: string): t.Identifier; /** * Determine whether evaluating the specific input `node` is a consequenceless reference. ie. * evaluating it wont result in potentially arbitrary code from being ran. The following are * whitelisted and determined not to cause side effects: * * - `this` expressions * - `super` expressions * - Bound identifiers */ isStatic(node: Node): boolean; /** Possibly generate a memoised identifier if it is not static and has consequences. */ maybeGenerateMemoised(node: Node, dontPush?: boolean): t.Identifier; checkBlockScopedCollisions(local: Node, kind: string, name: string, id: object): void; rename(oldName: string, newName?: string, block?: Node): void; dump(): void; toArray(node: Node, i?: number): Node; registerDeclaration(path: NodePath): void; buildUndefinedNode(): Node; registerConstantViolation(path: NodePath): void; registerBinding(kind: string, path: NodePath, bindingPath?: NodePath): void; addGlobal(node: Node): void; hasUid(name: string): boolean; hasGlobal(name: string): boolean; hasReference(name: string): boolean; isPure(node: Node, constantsOnly?: boolean): boolean; setData(key: string, val: any): any; getData(key: string): any; removeData(key: string): void; push(opts: any): void; getProgramParent(): Scope; getFunctionParent(): Scope; getBlockParent(): Scope; /** Walks the scope tree and gathers **all** bindings. */ getAllBindings(...kinds: string[]): object; bindingIdentifierEquals(name: string, node: Node): boolean; getBinding(name: string): Binding | undefined; getOwnBinding(name: string): Binding | undefined; getBindingIdentifier(name: string): t.Identifier; getOwnBindingIdentifier(name: string): t.Identifier; hasOwnBinding(name: string): boolean; hasBinding(name: string, noGlobals?: boolean): boolean; parentHasBinding(name: string, noGlobals?: boolean): boolean; /** Move a binding of `name` to another `scope`. */ moveBindingTo(name: string, scope: Scope): void; removeOwnBinding(name: string): void; removeBinding(name: string): void; } export class Binding { constructor( opts: { existing: Binding; identifier: t.Identifier; scope: Scope; path: NodePath; kind: "var" | "let" | "const"; }, ); identifier: t.Identifier; scope: Scope; path: NodePath; kind: "var" | "let" | "const" | "module"; referenced: boolean; references: number; referencePaths: NodePath[]; constant: boolean; constantViolations: NodePath[]; } // The Visitor has to be generic because babel binds `this` for each property. // `this` is usually used in babel plugins to pass plugin state from // `pre` -> `visitor` -> `post`. An example of this can be seen in the official // babel handbook: // https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#-pre-and-post-in-plugins export interface Visitor<S = Node> extends VisitNodeObject<Node> { ArrayExpression?: VisitNode<S, t.ArrayExpression> | undefined; AssignmentExpression?: VisitNode<S, t.AssignmentExpression> | undefined; LVal?: VisitNode<S, t.LVal> | undefined; Expression?: VisitNode<S, t.Expression> | undefined; BinaryExpression?: VisitNode<S, t.BinaryExpression> | undefined; Directive?: VisitNode<S, t.Directive> | undefined; DirectiveLiteral?: VisitNode<S, t.DirectiveLiteral> | undefined; BlockStatement?: VisitNode<S, t.BlockStatement> | undefined; BreakStatement?: VisitNode<S, t.BreakStatement> | undefined; Identifier?: VisitNode<S, t.Identifier> | undefined; CallExpression?: VisitNode<S, t.CallExpression> | undefined; CatchClause?: VisitNode<S, t.CatchClause> | undefined; ConditionalExpression?: VisitNode<S, t.ConditionalExpression> | undefined; ContinueStatement?: VisitNode<S, t.ContinueStatement> | undefined; DebuggerStatement?: VisitNode<S, t.DebuggerStatement> | undefined; DoWhileStatement?: VisitNode<S, t.DoWhileStatement> | undefined; Statement?: VisitNode<S, t.Statement> | undefined; EmptyStatement?: VisitNode<S, t.EmptyStatement> | undefined; ExpressionStatement?: VisitNode<S, t.ExpressionStatement> | undefined; File?: VisitNode<S, t.File> | undefined; Program?: VisitNode<S, t.Program> | undefined; ForInStatement?: VisitNode<S, t.ForInStatement> | undefined; VariableDeclaration?: VisitNode<S, t.VariableDeclaration> | undefined; ForStatement?: VisitNode<S, t.ForStatement> | undefined; FunctionDeclaration?: VisitNode<S, t.FunctionDeclaration> | undefined; FunctionExpression?: VisitNode<S, t.FunctionExpression> | undefined; IfStatement?: VisitNode<S, t.IfStatement> | undefined; LabeledStatement?: VisitNode<S, t.LabeledStatement> | undefined; StringLiteral?: VisitNode<S, t.StringLiteral> | undefined; NumericLiteral?: VisitNode<S, t.NumericLiteral> | undefined; NullLiteral?: VisitNode<S, t.NullLiteral> | undefined; BooleanLiteral?: VisitNode<S, t.BooleanLiteral> | undefined; RegExpLiteral?: VisitNode<S, t.RegExpLiteral> | undefined; LogicalExpression?: VisitNode<S, t.LogicalExpression> | undefined; MemberExpression?: VisitNode<S, t.MemberExpression> | undefined; NewExpression?: VisitNode<S, t.NewExpression> | undefined; ObjectExpression?: VisitNode<S, t.ObjectExpression> | undefined; ObjectMethod?: VisitNode<S, t.ObjectMethod> | undefined; ObjectProperty?: VisitNode<S, t.ObjectProperty> | undefined; RestElement?: VisitNode<S, t.RestElement> | undefined; ReturnStatement?: VisitNode<S, t.ReturnStatement> | undefined; SequenceExpression?: VisitNode<S, t.SequenceExpression> | undefined; SwitchCase?: VisitNode<S, t.SwitchCase> | undefined; SwitchStatement?: VisitNode<S, t.SwitchStatement> | undefined; ThisExpression?: VisitNode<S, t.ThisExpression> | undefined; ThrowStatement?: VisitNode<S, t.ThrowStatement> | undefined; TryStatement?: VisitNode<S, t.TryStatement> | undefined; UnaryExpression?: VisitNode<S, t.UnaryExpression> | undefined; UpdateExpression?: VisitNode<S, t.UpdateExpression> | undefined; VariableDeclarator?: VisitNode<S, t.VariableDeclarator> | undefined; WhileStatement?: VisitNode<S, t.WhileStatement> | undefined; WithStatement?: VisitNode<S, t.WithStatement> | undefined; AssignmentPattern?: VisitNode<S, t.AssignmentPattern> | undefined; ArrayPattern?: VisitNode<S, t.ArrayPattern> | undefined; ArrowFunctionExpression?: VisitNode<S, t.ArrowFunctionExpression> | undefined; ClassBody?: VisitNode<S, t.ClassBody> | undefined; ClassDeclaration?: VisitNode<S, t.ClassDeclaration> | undefined; ClassExpression?: VisitNode<S, t.ClassExpression> | undefined; ExportAllDeclaration?: VisitNode<S, t.ExportAllDeclaration> | undefined; ExportDefaultDeclaration?: VisitNode<S, t.ExportDefaultDeclaration> | undefined; ExportNamedDeclaration?: VisitNode<S, t.ExportNamedDeclaration> | undefined; Declaration?: VisitNode<S, t.Declaration> | undefined; ExportSpecifier?: VisitNode<S, t.ExportSpecifier> | undefined; ForOfStatement?: VisitNode<S, t.ForOfStatement> | undefined; ImportDeclaration?: VisitNode<S, t.ImportDeclaration> | undefined; ImportDefaultSpecifier?: VisitNode<S, t.ImportDefaultSpecifier> | undefined; ImportNamespaceSpecifier?: VisitNode<S, t.ImportNamespaceSpecifier> | undefined; ImportSpecifier?: VisitNode<S, t.ImportSpecifier> | undefined; MetaProperty?: VisitNode<S, t.MetaProperty> | undefined; ClassMethod?: VisitNode<S, t.ClassMethod> | undefined; ObjectPattern?: VisitNode<S, t.ObjectPattern> | undefined; SpreadElement?: VisitNode<S, t.SpreadElement> | undefined; Super?: VisitNode<S, t.Super> | undefined; TaggedTemplateExpression?: VisitNode<S, t.TaggedTemplateExpression> | undefined; TemplateLiteral?: VisitNode<S, t.TemplateLiteral> | undefined; TemplateElement?: VisitNode<S, t.TemplateElement> | undefined; YieldExpression?: VisitNode<S, t.YieldExpression> | undefined; AnyTypeAnnotation?: VisitNode<S, t.AnyTypeAnnotation> | undefined; ArrayTypeAnnotation?: VisitNode<S, t.ArrayTypeAnnotation> | undefined; BooleanTypeAnnotation?: VisitNode<S, t.BooleanTypeAnnotation> | undefined; BooleanLiteralTypeAnnotation?: VisitNode<S, t.BooleanLiteralTypeAnnotation> | undefined; NullLiteralTypeAnnotation?: VisitNode<S, t.NullLiteralTypeAnnotation> | undefined; ClassImplements?: VisitNode<S, t.ClassImplements> | undefined; ClassProperty?: VisitNode<S, t.ClassProperty> | undefined; DeclareClass?: VisitNode<S, t.DeclareClass> | undefined; DeclareFunction?: VisitNode<S, t.DeclareFunction> | undefined; DeclareInterface?: VisitNode<S, t.DeclareInterface> | undefined; DeclareModule?: VisitNode<S, t.DeclareModule> | undefined; DeclareTypeAlias?: VisitNode<S, t.DeclareTypeAlias> | undefined; DeclareVariable?: VisitNode<S, t.DeclareVariable> | undefined; ExistentialTypeParam?: VisitNode<S, t.ExistentialTypeParam> | undefined; FunctionTypeAnnotation?: VisitNode<S, t.FunctionTypeAnnotation> | undefined; FunctionTypeParam?: VisitNode<S, t.FunctionTypeParam> | undefined; GenericTypeAnnotation?: VisitNode<S, t.GenericTypeAnnotation> | undefined; InterfaceExtends?: VisitNode<S, t.InterfaceExtends> | undefined; InterfaceDeclaration?: VisitNode<S, t.InterfaceDeclaration> | undefined; IntersectionTypeAnnotation?: VisitNode<S, t.IntersectionTypeAnnotation> | undefined; MixedTypeAnnotation?: VisitNode<S, t.MixedTypeAnnotation> | undefined; NullableTypeAnnotation?: VisitNode<S, t.NullableTypeAnnotation> | undefined; NumericLiteralTypeAnnotation?: VisitNode<S, t.NumericLiteralTypeAnnotation> | undefined; NumberTypeAnnotation?: VisitNode<S, t.NumberTypeAnnotation> | undefined; StringLiteralTypeAnnotation?: VisitNode<S, t.StringLiteralTypeAnnotation> | undefined; StringTypeAnnotation?: VisitNode<S, t.StringTypeAnnotation> | undefined; ThisTypeAnnotation?: VisitNode<S, t.ThisTypeAnnotation> | undefined; TupleTypeAnnotation?: VisitNode<S, t.TupleTypeAnnotation> | undefined; TypeofTypeAnnotation?: VisitNode<S, t.TypeofTypeAnnotation> | undefined; TypeAlias?: VisitNode<S, t.TypeAlias> | undefined; TypeAnnotation?: VisitNode<S, t.TypeAnnotation> | undefined; TypeCastExpression?: VisitNode<S, t.TypeCastExpression> | undefined; TypeParameterDeclaration?: VisitNode<S, t.TypeParameterDeclaration> | undefined; TypeParameterInstantiation?: VisitNode<S, t.TypeParameterInstantiation> | undefined; ObjectTypeAnnotation?: VisitNode<S, t.ObjectTypeAnnotation> | undefined; ObjectTypeCallProperty?: VisitNode<S, t.ObjectTypeCallProperty> | undefined; ObjectTypeIndexer?: VisitNode<S, t.ObjectTypeIndexer> | undefined; ObjectTypeProperty?: VisitNode<S, t.ObjectTypeProperty> | undefined; QualifiedTypeIdentifier?: VisitNode<S, t.QualifiedTypeIdentifier> | undefined; UnionTypeAnnotation?: VisitNode<S, t.UnionTypeAnnotation> | undefined; VoidTypeAnnotation?: VisitNode<S, t.VoidTypeAnnotation> | undefined; JSXAttribute?: VisitNode<S, t.JSXAttribute> | undefined; JSXIdentifier?: VisitNode<S, t.JSXIdentifier> | undefined; JSXNamespacedName?: VisitNode<S, t.JSXNamespacedName> | undefined; JSXElement?: VisitNode<S, t.JSXElement> | undefined; JSXExpressionContainer?: VisitNode<S, t.JSXExpressionContainer> | undefined; JSXClosingElement?: VisitNode<S, t.JSXClosingElement> | undefined; JSXMemberExpression?: VisitNode<S, t.JSXMemberExpression> | undefined; JSXOpeningElement?: VisitNode<S, t.JSXOpeningElement> | undefined; JSXEmptyExpression?: VisitNode<S, t.JSXEmptyExpression> | undefined; JSXSpreadAttribute?: VisitNode<S, t.JSXSpreadAttribute> | undefined; JSXText?: VisitNode<S, t.JSXText> | undefined; Noop?: VisitNode<S, t.Noop> | undefined; ParenthesizedExpression?: VisitNode<S, t.ParenthesizedExpression> | undefined; AwaitExpression?: VisitNode<S, t.AwaitExpression> | undefined; BindExpression?: VisitNode<S, t.BindExpression> | undefined; Decorator?: VisitNode<S, t.Decorator> | undefined; DoExpression?: VisitNode<S, t.DoExpression> | undefined; ExportDefaultSpecifier?: VisitNode<S, t.ExportDefaultSpecifier> | undefined; ExportNamespaceSpecifier?: VisitNode<S, t.ExportNamespaceSpecifier> | undefined; RestProperty?: VisitNode<S, t.RestProperty> | undefined; SpreadProperty?: VisitNode<S, t.SpreadProperty> | undefined; Binary?: VisitNode<S, t.Binary> | undefined; Scopable?: VisitNode<S, t.Scopable> | undefined; BlockParent?: VisitNode<S, t.BlockParent> | undefined; Block?: VisitNode<S, t.Block> | undefined; Terminatorless?: VisitNode<S, t.Terminatorless> | undefined; CompletionStatement?: VisitNode<S, t.CompletionStatement> | undefined; Conditional?: VisitNode<S, t.Conditional> | undefined; Loop?: VisitNode<S, t.Loop> | undefined; While?: VisitNode<S, t.While> | undefined; ExpressionWrapper?: VisitNode<S, t.ExpressionWrapper> | undefined; For?: VisitNode<S, t.For> | undefined; ForXStatement?: VisitNode<S, t.ForXStatement> | undefined; Function?: VisitNode<S, t.Function> | undefined; FunctionParent?: VisitNode<S, t.FunctionParent> | undefined; Pureish?: VisitNode<S, t.Pureish> | undefined; Literal?: VisitNode<S, t.Literal> | undefined; Immutable?: VisitNode<S, t.Immutable> | undefined; UserWhitespacable?: VisitNode<S, t.UserWhitespacable> | undefined; Method?: VisitNode<S, t.Method> | undefined; ObjectMember?: VisitNode<S, t.ObjectMember> | undefined; Property?: VisitNode<S, t.Property> | undefined; UnaryLike?: VisitNode<S, t.UnaryLike> | undefined; Pattern?: VisitNode<S, t.Pattern> | undefined; Class?: VisitNode<S, t.Class> | undefined; ModuleDeclaration?: VisitNode<S, t.ModuleDeclaration> | undefined; ExportDeclaration?: VisitNode<S, t.ExportDeclaration> | undefined; ModuleSpecifier?: VisitNode<S, t.ModuleSpecifier> | undefined; Flow?: VisitNode<S, t.Flow> | undefined; FlowBaseAnnotation?: VisitNode<S, t.FlowBaseAnnotation> | undefined; FlowDeclaration?: VisitNode<S, t.FlowDeclaration> | undefined; JSX?: VisitNode<S, t.JSX> | undefined; Scope?: VisitNode<S, t.Scopable> | undefined; } export type VisitNode<T, P> = VisitNodeFunction<T, P> | VisitNodeObject<T>; export type VisitNodeFunction<T, P> = (this: T, path: NodePath<P>, state: any) => void; export interface VisitNodeObject<T> { enter?(path: NodePath<T>, state: any): void; exit?(path: NodePath<T>, state: any): void; } export class NodePath<T = Node> { constructor(hub: Hub, parent: Node); parent: Node; hub: Hub; contexts: TraversalContext[]; data: object; shouldSkip: boolean; shouldStop: boolean; removed: boolean; state: any; opts: object; skipKeys: object; parentPath: NodePath; context: TraversalContext; container: object | object[]; listKey: string; inList: boolean; parentKey: string; key: string | number; node: T; scope: Scope; type: T extends undefined | null ? string | null : string; typeAnnotation: object; getScope(scope: Scope): Scope; setData(key: string, val: any): any; getData(key: string, def?: any): any; buildCodeFrameError<TError extends Error>(msg: string, Error?: new(msg: string) => TError): TError; traverse<T>(visitor: Visitor<T>, state: T): void; traverse(visitor: Visitor): void; set(key: string, node: Node): void; getPathLocation(): string; // Example: https://github.com/babel/babel/blob/63204ae51e020d84a5b246312f5eeb4d981ab952/packages/babel-traverse/src/path/modification.js#L83 debug(buildMessage: () => string): void; // ------------------------- ancestry ------------------------- /** * Call the provided `callback` with the `NodePath`s of all the parents. * When the `callback` returns a truthy value, we return that node path. */ findParent(callback: (path: NodePath) => boolean): NodePath; find(callback: (path: NodePath) => boolean): NodePath; /** Get the parent function of the current path. */ getFunctionParent(): NodePath<t.Function>; /** Walk up the tree until we hit a parent node path in a list. */ getStatementParent(): NodePath<t.Statement>; /** * Get the deepest common ancestor and then from it, get the earliest relationship path * to that ancestor. * * Earliest is defined as being "before" all the other nodes in terms of list container * position and visiting key. */ getEarliestCommonAncestorFrom(paths: NodePath[]): NodePath[]; /** Get the earliest path in the tree where the provided `paths` intersect. */ getDeepestCommonAncestorFrom( paths: NodePath[], filter?: (deepest: Node, i: number, ancestries: NodePath[]) => NodePath, ): NodePath; /** * Build an array of node paths containing the entire ancestry of the current node path. * * NOTE: The current node path is included in this. */ getAncestry(): NodePath[]; inType(...candidateTypes: string[]): boolean; // ------------------------- inference ------------------------- /** Infer the type of the current `NodePath`. */ getTypeAnnotation(): t.FlowTypeAnnotation; isBaseType(baseName: string, soft?: boolean): boolean; couldBeBaseType(name: string): boolean; baseTypeStrictlyMatches(right: NodePath): boolean; isGenericType(genericName: string): boolean; // ------------------------- replacement ------------------------- /** * Replace a node with an array of multiple. This method performs the following steps: * * - Inherit the comments of first provided node with that of the current node. * - Insert the provided nodes after the current node. * - Remove the current node. */ replaceWithMultiple(nodes: Node[]): void; /** * Parse a string as an expression and replace the current node with the result. * * NOTE: This is typically not a good idea to use. Building source strings when * transforming ASTs is an antipattern and SHOULD NOT be encouraged. Even if it's * easier to use, your transforms will be extremely brittle. */ replaceWithSourceString(replacement: any): void; /** Replace the current node with another. */ replaceWith(replacement: Node | NodePath): void; /** * This method takes an array of statements nodes and then explodes it * into expressions. This method retains completion records which is * extremely important to retain original semantics. */ replaceExpressionWithStatements(nodes: Node[]): Node; replaceInline(nodes: Node | Node[]): void; // ------------------------- evaluation ------------------------- /** * Walk the input `node` and statically evaluate if it's truthy. * * Returning `true` when we're sure that the expression will evaluate to a * truthy value, `false` if we're sure that it will evaluate to a falsy * value and `undefined` if we aren't sure. Because of this please do not * rely on coercion when using this method and check with === if it's false. */ evaluateTruthy(): boolean; /** * Walk the input `node` and statically evaluate it. * * Returns an object in the form `{ confident, value }`. `confident` indicates * whether or not we had to drop out of evaluating the expression because of * hitting an unknown node that we couldn't confidently find the value of. * * Example: * * t.evaluate(parse("5 + 5")) // { confident: true, value: 10 } * t.evaluate(parse("!true")) // { confident: true, value: false } * t.evaluate(parse("foo + foo")) // { confident: false, value: undefined } */ evaluate(): { confident: boolean; value: any }; // ------------------------- introspection ------------------------- /** * Match the current node if it matches the provided `pattern`. * * For example, given the match `React.createClass` it would match the * parsed nodes of `React.createClass` and `React["createClass"]`. */ matchesPattern(pattern: string, allowPartial?: boolean): boolean; /** * Check whether we have the input `key`. If the `key` references an array then we check * if the array has any items, otherwise we just check if it's falsy. */ has(key: string): boolean; isStatic(): boolean; /** Alias of `has`. */ is(key: string): boolean; /** Opposite of `has`. */ isnt(key: string): boolean; /** Check whether the path node `key` strict equals `value`. */ equals(key: string, value: any): boolean; /** * Check the type against our stored internal type of the node. This is handy when a node has * been removed yet we still internally know the type and need it to calculate node replacement. */ isNodeType(type: string): boolean; /** * This checks whether or not we're in one of the following positions: * * for (KEY in right); * for (KEY;;); * * This is because these spots allow VariableDeclarations AND normal expressions so we need * to tell the path replacement that it's ok to replace this with an expression. */ canHaveVariableDeclarationOrExpression(): boolean; /** * This checks whether we are swapping an arrow function's body between an * expression and a block statement (or vice versa). * * This is because arrow functions may implicitly return an expression, which * is the same as containing a block statement. */ canSwapBetweenExpressionAndStatement(replacement: Node): boolean; /** Check whether the current path references a completion record */ isCompletionRecord(allowInsideFunction?: boolean): boolean; /** * Check whether or not the current `key` allows either a single statement or block statement * so we can explode it if necessary. */ isStatementOrBlock(): boolean; /** Check if the currently assigned path references the `importName` of `moduleSource`. */ referencesImport(moduleSource: string, importName: string): boolean; /** Get the source code associated with this node. */ getSource(): string; /** Check if the current path will maybe execute before another path */ willIMaybeExecuteBefore(path: NodePath): boolean; // ------------------------- context ------------------------- call(key: string): boolean; isBlacklisted(): boolean; visit(): boolean; skip(): void; skipKey(key: string): void; stop(): void; setScope(): void; setContext(context: TraversalContext): NodePath<T>; popContext(): void; pushContext(context: TraversalContext): void; // ------------------------- removal ------------------------- remove(): void; // ------------------------- modification ------------------------- /** Insert the provided nodes before the current one. */ insertBefore(nodes: Node | Node[]): any; /** * Insert the provided nodes after the current one. When inserting nodes after an * expression, ensure that the completion record is correct by pushing the current node. */ insertAfter(nodes: Node | Node[]): any; /** Update all sibling node paths after `fromIndex` by `incrementBy`. */ updateSiblingKeys(fromIndex: number, incrementBy: number): void; /** Hoist the current node to the highest scope possible and return a UID referencing it. */ hoist(scope: Scope): void; // ------------------------- family ------------------------- getOpposite(): NodePath; getCompletionRecords(): NodePath[]; getSibling(key: string | number): NodePath; getNextSibling(): NodePath; getPrevSibling(): NodePath; getAllPrevSiblings(): NodePath[]; getAllNextSiblings(): NodePath[]; get<K extends keyof T>( key: K, context?: boolean | TraversalContext, ): T[K] extends Array<Node | null | undefined> ? Array<NodePath<T[K][number]>> : T[K] extends Node | null | undefined ? NodePath<T[K]> : never; get(key: string, context?: boolean | TraversalContext): NodePath | NodePath[]; getBindingIdentifiers(duplicates?: boolean): Node[]; getOuterBindingIdentifiers(duplicates?: boolean): Node[]; // ------------------------- comments ------------------------- /** Share comments amongst siblings. */ shareCommentsWithSiblings(): void; addComment(type: string, content: string, line?: boolean): void; /** Give node `comments` of the specified `type`. */ addComments(type: string, comments: any[]): void; // ------------------------- isXXX ------------------------- isArrayExpression(opts?: object): this is NodePath<t.ArrayExpression>; isAssignmentExpression(opts?: object): this is NodePath<t.AssignmentExpression>; isBinaryExpression(opts?: object): this is NodePath<t.BinaryExpression>; isDirective(opts?: object): this is NodePath<t.Directive>; isDirectiveLiteral(opts?: object): this is NodePath<t.DirectiveLiteral>; isBlockStatement(opts?: object): this is NodePath<t.BlockStatement>; isBreakStatement(opts?: object): this is NodePath<t.BreakStatement>; isCallExpression(opts?: object): this is NodePath<t.CallExpression>; isCatchClause(opts?: object): this is NodePath<t.CatchClause>; isConditionalExpression(opts?: object): this is NodePath<t.ConditionalExpression>; isContinueStatement(opts?: object): this is NodePath<t.ContinueStatement>; isDebuggerStatement(opts?: object): this is NodePath<t.DebuggerStatement>; isDoWhileStatement(opts?: object): this is NodePath<t.DoWhileStatement>; isEmptyStatement(opts?: object): this is NodePath<t.EmptyStatement>; isExpressionStatement(opts?: object): this is NodePath<t.ExpressionStatement>; isFile(opts?: object): this is NodePath<t.File>; isForInStatement(opts?: object): this is NodePath<t.ForInStatement>; isForStatement(opts?: object): this is NodePath<t.ForStatement>; isFunctionDeclaration(opts?: object): this is NodePath<t.FunctionDeclaration>; isFunctionExpression(opts?: object): this is NodePath<t.FunctionExpression>; isIdentifier(opts?: object): this is NodePath<t.Identifier>; isIfStatement(opts?: object): this is NodePath<t.IfStatement>; isLabeledStatement(opts?: object): this is NodePath<t.LabeledStatement>; isStringLiteral(opts?: object): this is NodePath<t.StringLiteral>; isNumericLiteral(opts?: object): this is NodePath<t.NumericLiteral>; isNullLiteral(opts?: object): this is NodePath<t.NullLiteral>; isBooleanLiteral(opts?: object): this is NodePath<t.BooleanLiteral>; isRegExpLiteral(opts?: object): this is NodePath<t.RegExpLiteral>; isLogicalExpression(opts?: object): this is NodePath<t.LogicalExpression>; isMemberExpression(opts?: object): this is NodePath<t.MemberExpression>; isNewExpression(opts?: object): this is NodePath<t.NewExpression>; isProgram(opts?: object): this is NodePath<t.Program>; isObjectExpression(opts?: object): this is NodePath<t.ObjectExpression>; isObjectMethod(opts?: object): this is NodePath<t.ObjectMethod>; isObjectProperty(opts?: object): this is NodePath<t.ObjectProperty>; isRestElement(opts?: object): this is NodePath<t.RestElement>; isReturnStatement(opts?: object): this is NodePath<t.ReturnStatement>; isSequenceExpression(opts?: object): this is NodePath<t.SequenceExpression>; isSwitchCase(opts?: object): this is NodePath<t.SwitchCase>; isSwitchStatement(opts?: object): this is NodePath<t.SwitchStatement>; isThisExpression(opts?: object): this is NodePath<t.ThisExpression>; isThrowStatement(opts?: object): this is NodePath<t.ThrowStatement>; isTryStatement(opts?: object): this is NodePath<t.TryStatement>; isUnaryExpression(opts?: object): this is NodePath<t.UnaryExpression>; isUpdateExpression(opts?: object): this is NodePath<t.UpdateExpression>; isVariableDeclaration(opts?: object): this is NodePath<t.VariableDeclaration>; isVariableDeclarator(opts?: object): this is NodePath<t.VariableDeclarator>; isWhileStatement(opts?: object): this is NodePath<t.WhileStatement>; isWithStatement(opts?: object): this is NodePath<t.WithStatement>; isAssignmentPattern(opts?: object): this is NodePath<t.AssignmentPattern>; isArrayPattern(opts?: object): this is NodePath<t.ArrayPattern>; isArrowFunctionExpression(opts?: object): this is NodePath<t.ArrowFunctionExpression>; isClassBody(opts?: object): this is NodePath<t.ClassBody>; isClassDeclaration(opts?: object): this is NodePath<t.ClassDeclaration>; isClassExpression(opts?: object): this is NodePath<t.ClassExpression>; isExportAllDeclaration(opts?: object): this is NodePath<t.ExportAllDeclaration>; isExportDefaultDeclaration(opts?: object): this is NodePath<t.ExportDefaultDeclaration>; isExportNamedDeclaration(opts?: object): this is NodePath<t.ExportNamedDeclaration>; isExportSpecifier(opts?: object): this is NodePath<t.ExportSpecifier>; isForOfStatement(opts?: object): this is NodePath<t.ForOfStatement>; isImportDeclaration(opts?: object): this is NodePath<t.ImportDeclaration>; isImportDefaultSpecifier(opts?: object): this is NodePath<t.ImportDefaultSpecifier>; isImportNamespaceSpecifier(opts?: object): this is NodePath<t.ImportNamespaceSpecifier>; isImportSpecifier(opts?: object): this is NodePath<t.ImportSpecifier>; isMetaProperty(opts?: object): this is NodePath<t.MetaProperty>; isClassMethod(opts?: object): this is NodePath<t.ClassMethod>; isObjectPattern(opts?: object): this is NodePath<t.ObjectPattern>; isSpreadElement(opts?: object): this is NodePath<t.SpreadElement>; isSuper(opts?: object): this is NodePath<t.Super>; isTaggedTemplateExpression(opts?: object): this is NodePath<t.TaggedTemplateExpression>; isTemplateElement(opts?: object): this is NodePath<t.TemplateElement>; isTemplateLiteral(opts?: object): this is NodePath<t.TemplateLiteral>; isYieldExpression(opts?: object): this is NodePath<t.YieldExpression>; isAnyTypeAnnotation(opts?: object): this is NodePath<t.AnyTypeAnnotation>; isArrayTypeAnnotation(opts?: object): this is NodePath<t.ArrayTypeAnnotation>; isBooleanTypeAnnotation(opts?: object): this is NodePath<t.BooleanTypeAnnotation>; isBooleanLiteralTypeAnnotation(opts?: object): this is NodePath<t.BooleanLiteralTypeAnnotation>; isNullLiteralTypeAnnotation(opts?: object): this is NodePath<t.NullLiteralTypeAnnotation>; isClassImplements(opts?: object): this is NodePath<t.ClassImplements>; isClassProperty(opts?: object): this is NodePath<t.ClassProperty>; isDeclareClass(opts?: object): this is NodePath<t.DeclareClass>; isDeclareFunction(opts?: object): this is NodePath<t.DeclareFunction>; isDeclareInterface(opts?: object): this is NodePath<t.DeclareInterface>; isDeclareModule(opts?: object): this is NodePath<t.DeclareModule>; isDeclareTypeAlias(opts?: object): this is NodePath<t.DeclareTypeAlias>; isDeclareVariable(opts?: object): this is NodePath<t.DeclareVariable>; isExistentialTypeParam(opts?: object): this is NodePath<t.ExistentialTypeParam>; isFunctionTypeAnnotation(opts?: object): this is NodePath<t.FunctionTypeAnnotation>; isFunctionTypeParam(opts?: object): this is NodePath<t.FunctionTypeParam>; isGenericTypeAnnotation(opts?: object): this is NodePath<t.GenericTypeAnnotation>; isInterfaceExtends(opts?: object): this is NodePath<t.InterfaceExtends>; isInterfaceDeclaration(opts?: object): this is NodePath<t.InterfaceDeclaration>; isIntersectionTypeAnnotation(opts?: object): this is NodePath<t.IntersectionTypeAnnotation>; isMixedTypeAnnotation(opts?: object): this is NodePath<t.MixedTypeAnnotation>; isNullableTypeAnnotation(opts?: object): this is NodePath<t.NullableTypeAnnotation>; isNumericLiteralTypeAnnotation(opts?: object): this is NodePath<t.NumericLiteralTypeAnnotation>; isNumberTypeAnnotation(opts?: object): this is NodePath<t.NumberTypeAnnotation>; isStringLiteralTypeAnnotation(opts?: object): this is NodePath<t.StringLiteralTypeAnnotation>; isStringTypeAnnotation(opts?: object): this is NodePath<t.StringTypeAnnotation>; isThisTypeAnnotation(opts?: object): this is NodePath<t.ThisTypeAnnotation>; isTupleTypeAnnotation(opts?: object): this is NodePath<t.TupleTypeAnnotation>; isTypeofTypeAnnotation(opts?: object): this is NodePath<t.TypeofTypeAnnotation>; isTypeAlias(opts?: object): this is NodePath<t.TypeAlias>; isTypeAnnotation(opts?: object): this is NodePath<t.TypeAnnotation>; isTypeCastExpression(opts?: object): this is NodePath<t.TypeCastExpression>; isTypeParameterDeclaration(opts?: object): this is NodePath<t.TypeParameterDeclaration>; isTypeParameterInstantiation(opts?: object): this is NodePath<t.TypeParameterInstantiation>; isObjectTypeAnnotation(opts?: object): this is NodePath<t.ObjectTypeAnnotation>; isObjectTypeCallProperty(opts?: object): this is NodePath<t.ObjectTypeCallProperty>; isObjectTypeIndexer(opts?: object): this is NodePath<t.ObjectTypeIndexer>; isObjectTypeProperty(opts?: object): this is NodePath<t.ObjectTypeProperty>; isQualifiedTypeIdentifier(opts?: object): this is NodePath<t.QualifiedTypeIdentifier>; isUnionTypeAnnotation(opts?: object): this is NodePath<t.UnionTypeAnnotation>; isVoidTypeAnnotation(opts?: object): this is NodePath<t.VoidTypeAnnotation>; isJSXAttribute(opts?: object): this is NodePath<t.JSXAttribute>; isJSXClosingElement(opts?: object): this is NodePath<t.JSXClosingElement>; isJSXElement(opts?: object): this is NodePath<t.JSXElement>; isJSXEmptyExpression(opts?: object): this is NodePath<t.JSXEmptyExpression>; isJSXExpressionContainer(opts?: object): this is NodePath<t.JSXExpressionContainer>; isJSXIdentifier(opts?: object): this is NodePath<t.JSXIdentifier>; isJSXMemberExpression(opts?: object): this is NodePath<t.JSXMemberExpression>; isJSXNamespacedName(opts?: object): this is NodePath<t.JSXNamespacedName>; isJSXOpeningElement(opts?: object): this is NodePath<t.JSXOpeningElement>; isJSXSpreadAttribute(opts?: object): this is NodePath<t.JSXSpreadAttribute>; isJSXText(opts?: object): this is NodePath<t.JSXText>; isNoop(opts?: object): this is NodePath<t.Noop>; isParenthesizedExpression(opts?: object): this is NodePath<t.ParenthesizedExpression>; isAwaitExpression(opts?: object): this is NodePath<t.AwaitExpression>; isBindExpression(opts?: object): this is NodePath<t.BindExpression>; isDecorator(opts?: object): this is NodePath<t.Decorator>; isDoExpression(opts?: object): this is NodePath<t.DoExpression>; isExportDefaultSpecifier(opts?: object): this is NodePath<t.ExportDefaultSpecifier>; isExportNamespaceSpecifier(opts?: object): this is NodePath<t.ExportNamespaceSpecifier>; isRestProperty(opts?: object): this is NodePath<t.RestProperty>; isSpreadProperty(opts?: object): this is NodePath<t.SpreadProperty>; isExpression(opts?: object): this is NodePath<t.Expression>; isBinary(opts?: object): this is NodePath<t.Binary>; isScopable(opts?: object): this is NodePath<t.Scopable>; isBlockParent(opts?: object): this is NodePath<t.BlockParent>; isBlock(opts?: object): this is NodePath<t.Block>; isStatement(opts?: object): this is NodePath<t.Statement>; isTerminatorless(opts?: object): this is NodePath<t.Terminatorless>; isCompletionStatement(opts?: object): this is NodePath<t.CompletionStatement>; isConditional(opts?: object): this is NodePath<t.Conditional>; isLoop(opts?: object): this is NodePath<t.Loop>; isWhile(opts?: object): this is NodePath<t.While>; isExpressionWrapper(opts?: object): this is NodePath<t.ExpressionWrapper>; isFor(opts?: object): this is NodePath<t.For>; isForXStatement(opts?: object): this is NodePath<t.ForXStatement>; isFunction(opts?: object): this is NodePath<t.Function>; isFunctionParent(opts?: object): this is NodePath<t.FunctionParent>; isPureish(opts?: object): this is NodePath<t.Pureish>; isDeclaration(opts?: object): this is NodePath<t.Declaration>; isLVal(opts?: object): this is NodePath<t.LVal>; isLiteral(opts?: object): this is NodePath<t.Literal>; isImmutable(opts?: object): this is NodePath<t.Immutable>; isUserWhitespacable(opts?: object): this is NodePath<t.UserWhitespacable>; isMethod(opts?: object): this is NodePath<t.Method>; isObjectMember(opts?: object): this is NodePath<t.ObjectMember>; isProperty(opts?: object): this is NodePath<t.Property>; isUnaryLike(opts?: object): this is NodePath<t.UnaryLike>; isPattern(opts?: object): this is NodePath<t.Pattern>; isClass(opts?: object): this is NodePath<t.Class>; isModuleDeclaration(opts?: object): this is NodePath<t.ModuleDeclaration>; isExportDeclaration(opts?: object): this is NodePath<t.ExportDeclaration>; isModuleSpecifier(opts?: object): this is NodePath<t.ModuleSpecifier>; isFlow(opts?: object): this is NodePath<t.Flow>; isFlowBaseAnnotation(opts?: object): this is NodePath<t.FlowBaseAnnotation>; isFlowDeclaration(opts?: object): this is NodePath<t.FlowDeclaration>; isJSX(opts?: object): this is NodePath<t.JSX>; isNumberLiteral(opts?: object): this is NodePath<t.NumericLiteral>; isRegexLiteral(opts?: object): this is NodePath<t.RegExpLiteral>; isReferencedIdentifier(opts?: object): this is NodePath<t.Identifier | t.JSXIdentifier>; isReferencedMemberExpression(opts?: object): this is NodePath<t.MemberExpression>; isBindingIdentifier(opts?: object): this is NodePath<t.Identifier>; isScope(opts?: object): this is NodePath<t.Scopable>; isReferenced(opts?: object): boolean; isBlockScoped(opts?: object): this is NodePath<t.FunctionDeclaration | t.ClassDeclaration | t.VariableDeclaration>; isVar(opts?: object): this is NodePath<t.VariableDeclaration>; isUser(opts?: object): boolean; isGenerated(opts?: object): boolean; isPure(opts?: object): boolean; // ------------------------- assertXXX ------------------------- assertArrayExpression(opts?: object): void; assertAssignmentExpression(opts?: object): void; assertBinaryExpression(opts?: object): void; assertDirective(opts?: object): void; assertDirectiveLiteral(opts?: object): void; assertBlockStatement(opts?: object): void; assertBreakStatement(opts?: object): void; assertCallExpression(opts?: object): void; assertCatchClause(opts?: object): void; assertConditionalExpression(opts?: object): void; assertContinueStatement(opts?: object): void; assertDebuggerStatement(opts?: object): void; assertDoWhileStatement(opts?: object): void; assertEmptyStatement(opts?: object): void; assertExpressionStatement(opts?: object): void; assertFile(opts?: object): void; assertForInStatement(opts?: object): void; assertForStatement(opts?: object): void; assertFunctionDeclaration(opts?: object): void; assertFunctionExpression(opts?: object): void; assertIdentifier(opts?: object): void; assertIfStatement(opts?: object): void; assertLabeledStatement(opts?: object): void; assertStringLiteral(opts?: object): void; assertNumericLiteral(opts?: object): void; assertNullLiteral(opts?: object): void; assertBooleanLiteral(opts?: object): void; assertRegExpLiteral(opts?: object): void; assertLogicalExpression(opts?: object): void; assertMemberExpression(opts?: object): void; assertNewExpression(opts?: object): void; assertProgram(opts?: object): void; assertObjectExpression(opts?: object): void; assertObjectMethod(opts?: object): void; assertObjectProperty(opts?: object): void; assertRestElement(opts?: object): void; assertReturnStatement(opts?: object): void; assertSequenceExpression(opts?: object): void; assertSwitchCase(opts?: object): void; assertSwitchStatement(opts?: object): void; assertThisExpression(opts?: object): void; assertThrowStatement(opts?: object): void; assertTryStatement(opts?: object): void; assertUnaryExpression(opts?: object): void; assertUpdateExpression(opts?: object): void; assertVariableDeclaration(opts?: object): void; assertVariableDeclarator(opts?: object): void; assertWhileStatement(opts?: object): void; assertWithStatement(opts?: object): void; assertAssignmentPattern(opts?: object): void; assertArrayPattern(opts?: object): void; assertArrowFunctionExpression(opts?: object): void; assertClassBody(opts?: object): void; assertClassDeclaration(opts?: object): void; assertClassExpression(opts?: object): void; assertExportAllDeclaration(opts?: object): void; assertExportDefaultDeclaration(opts?: object): void; assertExportNamedDeclaration(opts?: object): void; assertExportSpecifier(opts?: object): void; assertForOfStatement(opts?: object): void; assertImportDeclaration(opts?: object): void; assertImportDefaultSpecifier(opts?: object): void; assertImportNamespaceSpecifier(opts?: object): void; assertImportSpecifier(opts?: object): void; assertMetaProperty(opts?: object): void; assertClassMethod(opts?: object): void; assertObjectPattern(opts?: object): void; assertSpreadElement(opts?: object): void; assertSuper(opts?: object): void; assertTaggedTemplateExpression(opts?: object): void; assertTemplateElement(opts?: object): void; assertTemplateLiteral(opts?: object): void; assertYieldExpression(opts?: object): void; assertAnyTypeAnnotation(opts?: object): void; assertArrayTypeAnnotation(opts?: object): void; assertBooleanTypeAnnotation(opts?: object): void; assertBooleanLiteralTypeAnnotation(opts?: object): void; assertNullLiteralTypeAnnotation(opts?: object): void; assertClassImplements(opts?: object): void; assertClassProperty(opts?: object): void; assertDeclareClass(opts?: object): void; assertDeclareFunction(opts?: object): void; assertDeclareInterface(opts?: object): void; assertDeclareModule(opts?: object): void; assertDeclareTypeAlias(opts?: object): void; assertDeclareVariable(opts?: object): void; assertExistentialTypeParam(opts?: object): void; assertFunctionTypeAnnotation(opts?: object): void; assertFunctionTypeParam(opts?: object): void; assertGenericTypeAnnotation(opts?: object): void; assertInterfaceExtends(opts?: object): void; assertInterfaceDeclaration(opts?: object): void; assertIntersectionTypeAnnotation(opts?: object): void; assertMixedTypeAnnotation(opts?: object): void; assertNullableTypeAnnotation(opts?: object): void; assertNumericLiteralTypeAnnotation(opts?: object): void; assertNumberTypeAnnotation(opts?: object): void; assertStringLiteralTypeAnnotation(opts?: object): void; assertStringTypeAnnotation(opts?: object): void; assertThisTypeAnnotation(opts?: object): void; assertTupleTypeAnnotation(opts?: object): void; assertTypeofTypeAnnotation(opts?: object): void; assertTypeAlias(opts?: object): void; assertTypeAnnotation(opts?: object): void; assertTypeCastExpression(opts?: object): void; assertTypeParameterDeclaration(opts?: object): void; assertTypeParameterInstantiation(opts?: object): void; assertObjectTypeAnnotation(opts?: object): void; assertObjectTypeCallProperty(opts?: object): void; assertObjectTypeIndexer(opts?: object): void; assertObjectTypeProperty(opts?: object): void; assertQualifiedTypeIdentifier(opts?: object): void; assertUnionTypeAnnotation(opts?: object): void; assertVoidTypeAnnotation(opts?: object): void; assertJSXAttribute(opts?: object): void; assertJSXClosingElement(opts?: object): void; assertJSXElement(opts?: object): void; assertJSXEmptyExpression(opts?: object): void; assertJSXExpressionContainer(opts?: object): void; assertJSXIdentifier(opts?: object): void; assertJSXMemberExpression(opts?: object): void; assertJSXNamespacedName(opts?: object): void; assertJSXOpeningElement(opts?: object): void; assertJSXSpreadAttribute(opts?: object): void; assertJSXText(opts?: object): void; assertNoop(opts?: object): void; assertParenthesizedExpression(opts?: object): void; assertAwaitExpression(opts?: object): void; assertBindExpression(opts?: object): void; assertDecorator(opts?: object): void; assertDoExpression(opts?: object): void; assertExportDefaultSpecifier(opts?: object): void; assertExportNamespaceSpecifier(opts?: object): void; assertRestProperty(opts?: object): void; assertSpreadProperty(opts?: object): void; assertExpression(opts?: object): void; assertBinary(opts?: object): void; assertScopable(opts?: object): void; assertBlockParent(opts?: object): void; assertBlock(opts?: object): void; assertStatement(opts?: object): void; assertTerminatorless(opts?: object): void; assertCompletionStatement(opts?: object): void; assertConditional(opts?: object): void; assertLoop(opts?: object): void; assertWhile(opts?: object): void; assertExpressionWrapper(opts?: object): void; assertFor(opts?: object): void; assertForXStatement(opts?: object): void; assertFunction(opts?: object): void; assertFunctionParent(opts?: object): void; assertPureish(opts?: object): void; assertDeclaration(opts?: object): void; assertLVal(opts?: object): void; assertLiteral(opts?: object): void; assertImmutable(opts?: object): void; assertUserWhitespacable(opts?: object): void; assertMethod(opts?: object): void; assertObjectMember(opts?: object): void; assertProperty(opts?: object): void; assertUnaryLike(opts?: object): void; assertPattern(opts?: object): void; assertClass(opts?: object): void; assertModuleDeclaration(opts?: object): void; assertExportDeclaration(opts?: object): void; assertModuleSpecifier(opts?: object): void; assertFlow(opts?: object): void; assertFlowBaseAnnotation(opts?: object): void; assertFlowDeclaration(opts?: object): void; assertJSX(opts?: object): void; assertNumberLiteral(opts?: object): void; assertRegexLiteral(opts?: object): void; } export class Hub { constructor(file: any, options: any); file: any; options: any; } export interface TraversalContext { parentPath: NodePath; scope: Scope; state: any; opts: any; }