diff --git a/types/babel__core/index.d.ts b/types/babel__core/index.d.ts index 8358fee456..e3f229e793 100644 --- a/types/babel__core/index.d.ts +++ b/types/babel__core/index.d.ts @@ -6,7 +6,6 @@ // Jessica Franco // Ifiok Jr. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Minimum TypeScript Version: 3.4 import { GeneratorOptions } from '@babel/generator'; import { ParserOptions } from '@babel/parser'; diff --git a/types/babel__traverse/babel__traverse-tests.ts b/types/babel__traverse/babel__traverse-tests.ts index ff785527f0..ae9ad2ecdd 100644 --- a/types/babel__traverse/babel__traverse-tests.ts +++ b/types/babel__traverse/babel__traverse-tests.ts @@ -1,4 +1,4 @@ -import traverse, { Binding, Hub, NodePath, Visitor, visitors } from '@babel/traverse'; +import traverse, { Binding, Hub, NodePath, TraverseOptions, Visitor, visitors } from '@babel/traverse'; import * as t from '@babel/types'; // Examples from: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md @@ -23,6 +23,9 @@ const MyVisitor2: Visitor = { path.parentPath; // $ExpectType NodePath console.log('Visiting: ' + path.node.name); }, + ArrayExpression(path) { + path.get('elements'); // $ExpectType NodePath[] + }, Program(path) { path.parentPath; // $ExpectType null }, @@ -99,10 +102,14 @@ const v1: Visitor = { return a + b; }`); + // $ExpectType [NodePath] path.get('body').unshiftContainer('body', t.expressionStatement(t.stringLiteral('Start of function'))); + // $ExpectType [NodePath] path.get('body').pushContainer('body', t.expressionStatement(t.stringLiteral('End of function'))); + // $ExpectType [NodePath] path.insertBefore(t.expressionStatement(t.stringLiteral("Because I'm easy come, easy go."))); + // $ExpectType [NodePath] path.insertAfter(t.expressionStatement(t.stringLiteral('A little high, little low.'))); path.remove(); @@ -143,9 +150,9 @@ const v1: Visitor = { t.stringLiteral('hello'), t.booleanLiteral(false), ]); - // $ExpectType NodePath + // $ExpectType NodePath stringPath; - // $ExpectType NodePath + // $ExpectType NodePath booleanPath; } { @@ -169,41 +176,21 @@ const v1: Visitor = { newPath; } }, - Program(path) { - path.type; // $ExpectType "Program" + SequenceExpression(path) { + path.type; // $ExpectType "SequenceExpression" { - const [newPath] = path.unshiftContainer('body', t.stringLiteral('hello')); + const [newPath] = path.unshiftContainer('expressions', t.stringLiteral('hello')); // $ExpectType NodePath newPath; } { - const [newPath] = path.pushContainer('body', t.stringLiteral('hello')); + const [newPath] = path.pushContainer('expressions', t.stringLiteral('hello')); // $ExpectType NodePath newPath; } { - const [stringPath, booleanPath] = path.unshiftContainer('body', [ - t.stringLiteral('hello'), - t.booleanLiteral(false), - ]); - // $ExpectType NodePath - stringPath; - // $ExpectType NodePath - booleanPath; - } - { - const [stringPath, booleanPath] = path.pushContainer('body', [ - t.stringLiteral('hello'), - t.booleanLiteral(false), - ]); - // $ExpectType NodePath - stringPath; - // $ExpectType NodePath - booleanPath; - } - { - const [stringPath, booleanPath] = path.unshiftContainer<[t.StringLiteral, t.BooleanLiteral]>('body', [ + const [stringPath, booleanPath] = path.unshiftContainer('expressions', [ t.stringLiteral('hello'), t.booleanLiteral(false), ]); @@ -213,7 +200,7 @@ const v1: Visitor = { booleanPath; } { - const [stringPath, booleanPath] = path.pushContainer<[t.StringLiteral, t.BooleanLiteral]>('body', [ + const [stringPath, booleanPath] = path.pushContainer('expressions', [ t.stringLiteral('hello'), t.booleanLiteral(false), ]); @@ -222,6 +209,28 @@ const v1: Visitor = { // $ExpectType NodePath booleanPath; } + { + const [stringPath, booleanPath] = path.unshiftContainer< + t.SequenceExpression, + 'expressions', + [t.StringLiteral, t.BooleanLiteral] + >('expressions', [t.stringLiteral('hello'), t.booleanLiteral(false)]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [stringPath, booleanPath] = path.pushContainer< + t.SequenceExpression, + 'expressions', + [t.StringLiteral, t.BooleanLiteral] + >('expressions', [t.stringLiteral('hello'), t.booleanLiteral(false)]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } }, }; @@ -244,7 +253,7 @@ interface SomeVisitorState { someState: string; } -const VisitorStateTest: Visitor = { +const VisitorStateTest: TraverseOptions = { enter(path, state) { let actualType = path.type; const expectedType: t.Node['type'] = actualType; @@ -334,18 +343,23 @@ function testNullishPath( ) { nullPath.type; // $ExpectType undefined undefinedPath.type; // $ExpectType undefined - unknownPath.type; // $ExpectType string | undefined + unknownPath.type; // $ExpectAssignable t.Node['type'] | undefined let actualType = optionalPath.type; const expectedType: t.Node['type'] | undefined = actualType; actualType = expectedType; } -const visitorWithDenylist: Visitor = { +function testEnsureBlock(path: NodePath) { + path.ensureBlock(); + path.node.body; // $ExpectType BlockStatement +} + +const optionsWithDenylist: TraverseOptions = { denylist: ['TypeAnnotation'], }; -const visitorWithInvalidDenylist: Visitor = { +const optionsWithInvalidDenylist: TraverseOptions = { // @ts-expect-error denylist: ['SomeRandomType'], }; @@ -386,6 +400,17 @@ const newPath = NodePath.get({ newPath; // $ExpectType NodePath +const program: t.Program = {} as any; +// $ExpectType NodePath +NodePath.get({ + hub: {} as any, + parentPath: null, + parent: program, + container: program, + listKey: 'body', + key: 0, +}); + const binding = new Binding({ identifier: {} as any, scope: {} as any, diff --git a/types/babel__traverse/index.d.ts b/types/babel__traverse/index.d.ts index 98ddb88ac1..d874ea0352 100644 --- a/types/babel__traverse/index.d.ts +++ b/types/babel__traverse/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for @babel/traverse 7.18 +// Type definitions for @babel/traverse 7.20 // Project: https://github.com/babel/babel/tree/main/packages/babel-traverse, https://babeljs.io // Definitions by: Troy Gerwien // Marvin Hagemeister @@ -12,26 +12,30 @@ import * as t from '@babel/types'; export import Node = t.Node; +export import RemovePropertiesOptions = t.RemovePropertiesOptions; declare const traverse: { - ( - parent: Node | Node[] | null | undefined, - opts: TraverseOptions, - scope: Scope | undefined, - state: S, - parentPath?: NodePath, - ): void; - ( - parent: Node | Node[] | null | undefined, - opts?: TraverseOptions, - scope?: Scope, - state?: any, - parentPath?: NodePath, - ): void; + (parent: Node, opts: TraverseOptions, scope: Scope | undefined, state: S, parentPath?: NodePath): void; + (parent: Node, opts?: TraverseOptions, scope?: Scope, state?: any, parentPath?: NodePath): void; visitors: typeof visitors; verify: typeof visitors.verify; explode: typeof visitors.explode; + + cheap: (node: Node, enter: (node: Node) => void) => void; + node: ( + node: Node, + opts: TraverseOptions, + scope?: Scope, + state?: any, + path?: NodePath, + skipKeys?: Record, + ) => void; + clearNode: (node: Node, opts?: RemovePropertiesOptions) => void; + removeProperties: (tree: Node, opts?: RemovePropertiesOptions) => Node; + hasType: (tree: Node, type: Node['type'], denylistTypes?: string[]) => boolean; + + cache: typeof cache; }; export namespace visitors { @@ -49,32 +53,66 @@ export namespace visitors { * - Visitors of virtual types are wrapped, so that they are only visited when their dynamic check passes * - `enter` and `exit` functions are wrapped in arrays, to ease merging of visitors */ - function explode( + function explode( visitor: Visitor, ): { - [Type in Node['type']]?: VisitNodeObject>; + [Type in Exclude['type']]?: VisitNodeObject>; }; function verify(visitor: Visitor): void; - function merge(visitors: Array>, states?: S[]): Visitor; + function merge(visitors: Array>): Visitor; + function merge( + visitors: Visitor[], + states?: any[], + wrapper?: ( + stateKey: any, + visitorKey: keyof Visitor, + func: VisitNodeFunction, + ) => VisitNodeFunction | null, + ): Visitor; +} + +export namespace cache { + let path: WeakMap>; + let scope: WeakMap; + function clear(): void; + function clearPath(): void; + function clearScope(): void; } export default traverse; -export interface TraverseOptions extends Visitor { - scope?: Scope | undefined; - noScope?: boolean | undefined; -} - -export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P }; +export type TraverseOptions = { + scope?: Scope; + noScope?: boolean; + denylist?: NodeType[]; + /** @deprecated will be removed in Babel 8 */ + blacklist?: NodeType[]; + shouldSkip?: (node: NodePath) => boolean; +} & Visitor; export class Scope { + /** + * This searches the current "scope" and collects all references/bindings + * within. + */ constructor(path: NodePath, parentScope?: Scope); + uid: number; path: NodePath; block: Node; + labels: Map>; parentBlock: Node; parent: Scope; hub: HubInterface; bindings: { [name: string]: Binding }; + references: { [name: string]: true }; + globals: { [name: string]: t.Identifier | t.JSXIdentifier }; + uids: { [name: string]: boolean }; + data: Record; + crawling: boolean; + + static globals: string[]; + /** Variables available in current context. */ + static contextVariables: string[]; /** Traverse node with current scope and path. */ traverse(node: Node | Node[], opts: TraverseOptions, state: S): void; @@ -112,17 +150,27 @@ export class Scope { dump(): void; - toArray(node: Node, i?: number): Node; + toArray( + node: t.Node, + i?: number | boolean, + arrayLikeIsIterable?: boolean, + ): t.ArrayExpression | t.CallExpression | t.Identifier; + + hasLabel(name: string): boolean; + + getLabel(name: string): NodePath | undefined; + + registerLabel(path: NodePath): void; registerDeclaration(path: NodePath): void; - buildUndefinedNode(): Node; + buildUndefinedNode(): t.UnaryExpression; registerConstantViolation(path: NodePath): void; - registerBinding(kind: string, path: NodePath, bindingPath?: NodePath): void; + registerBinding(kind: BindingKind, path: NodePath, bindingPath?: NodePath): void; - addGlobal(node: Node): void; + addGlobal(node: t.Identifier | t.JSXIdentifier): void; hasUid(name: string): boolean; @@ -132,29 +180,56 @@ export class Scope { isPure(node: Node, constantsOnly?: boolean): boolean; + /** + * Set some arbitrary data on the current scope. + */ setData(key: string, val: any): any; + /** + * Recursively walk up scope tree looking for the data `key`. + */ getData(key: string): any; + /** + * Recursively walk up scope tree looking for the data `key` and if it exists, + * remove it. + */ removeData(key: string): void; crawl(): void; push(opts: { id: t.LVal; - init?: t.Expression | undefined; - unique?: boolean | undefined; - kind?: 'var' | 'let' | 'const' | undefined; + init?: t.Expression; + unique?: boolean; + _blockHoist?: number | undefined; + kind?: 'var' | 'let' | 'const'; }): void; + /** Walk up to the top of the scope tree and get the `Program`. */ getProgramParent(): Scope; + /** Walk up the scope tree until we hit either a Function or return null. */ getFunctionParent(): Scope | null; + /** + * Walk up the scope tree until we hit either a BlockStatement/Loop/Program/Function/Switch or reach the + * very top and hit Program. + */ getBlockParent(): Scope; + /** + * Walk up from a pattern scope (function param initializer) until we hit a non-pattern scope, + * then returns its block parent + * @returns An ancestry scope whose path is a block parent + */ + getPatternParent(): Scope; + /** Walks the scope tree and gathers **all** bindings. */ - getAllBindings(...kinds: string[]): object; + getAllBindings(): Record; + + /** Walks the scope tree and gathers all declarations of `kind`. */ + getAllBindingsOfKind(...kinds: string[]): Record; bindingIdentifierEquals(name: string, node: Node): boolean; @@ -168,9 +243,23 @@ export class Scope { hasOwnBinding(name: string): boolean; - hasBinding(name: string, noGlobals?: boolean): boolean; + hasBinding( + name: string, + optsOrNoGlobals?: + | boolean + | { + noGlobals?: boolean; + noUids?: boolean; + }, + ): boolean; - parentHasBinding(name: string, noGlobals?: boolean): boolean; + parentHasBinding( + name: string, + opts?: { + noGlobals?: boolean; + noUids?: boolean; + }, + ): boolean; /** Move a binding of `name` to another `scope`. */ moveBindingTo(name: string, scope: Scope): void; @@ -182,6 +271,16 @@ export class Scope { export type BindingKind = 'var' | 'let' | 'const' | 'module' | 'hoisted' | 'param' | 'local' | 'unknown'; +/** + * This class is responsible for a binding inside of a scope. + * + * It tracks the following: + * + * * Node path. + * * Amount of times referenced by other nodes. + * * Paths to nodes that reassign or modify this binding. + * * The kind of binding. (Is it a parameter, declaration etc) + */ export class Binding { constructor(opts: { identifier: t.Identifier; scope: Scope; path: NodePath; kind: BindingKind }); identifier: t.Identifier; @@ -193,23 +292,33 @@ export class Binding { referencePaths: NodePath[]; constant: boolean; constantViolations: NodePath[]; - hasDeoptedValue?: boolean; - hasValue?: boolean; - value?: any; + hasDeoptedValue: boolean; + hasValue: boolean; + value: any; deopValue(): void; setValue(value: any): void; clearValue(): void; + /** Register a constant violation with the provided `path`. */ reassign(path: NodePath): void; + /** Increment the amount of references to this binding. */ reference(path: NodePath): void; + /** Decrement the amount of references to this binding. */ dereference(): void; } -export type Visitor = VisitNodeObject & { +export type Visitor = VisitNodeObject & { [Type in Node['type']]?: VisitNode>; } & { [K in keyof t.Aliases]?: VisitNode; +} & { + [K in keyof VirtualTypeAliases]?: VisitNode; +} & { + // Babel supports `NodeTypesWithoutComment | NodeTypesWithoutComment | ... ` but it is + // too complex for TS. So we type it as a general visitor only if the key contains `|` + // this is good enough for non-visitor traverse options e.g. `noScope` + [k: `${string}|${string}`]: VisitNode; }; export type VisitNode = VisitNodeFunction | VisitNodeObject; @@ -219,74 +328,88 @@ export type VisitNodeFunction = (this: S, path: NodePath

, type NodeType = Node['type'] | keyof t.Aliases; export interface VisitNodeObject { - enter?: VisitNodeFunction | undefined; - exit?: VisitNodeFunction | undefined; - denylist?: NodeType[] | undefined; - /** - * @deprecated will be removed in Babel 8 - */ - blacklist?: NodeType[] | undefined; + enter?: VisitNodeFunction; + exit?: VisitNodeFunction; } +export type NodeKeyOfArrays = { + [P in keyof T]-?: T[P] extends Array ? P : never; +}[keyof T]; + +export type NodeKeyOfNodes = { + [P in keyof T]-?: T[P] extends Node | null | undefined ? P : never; +}[keyof T]; + export type NodePaths = T extends readonly Node[] ? { -readonly [K in keyof T]: NodePath> } : T extends Node ? [NodePath] : never; +type NodeListType = N[K] extends Array ? (P extends Node ? P : never) : never; + +type NodesInsertionParam = T | readonly T[] | [T, ...T[]]; + export class NodePath { - constructor(hub: Hub, parent: Node); + constructor(hub: HubInterface, parent: Node); parent: Node; hub: Hub; + data: Record; + context: TraversalContext; + scope: Scope; contexts: TraversalContext[]; - data: object; + state: any; + opts: any; // exploded TraverseOptions + skipKeys: Record | null; + parentPath: T extends t.Program ? null : NodePath; + container: Node | Node[] | null; + listKey: string | null; + key: string | number | null; + node: T; + type: T extends Node ? T['type'] : T extends null | undefined ? undefined : Node['type'] | undefined; shouldSkip: boolean; shouldStop: boolean; removed: boolean; - state: any; - opts: object; - skipKeys: object; - parentPath: T extends t.Program ? null : NodePath; - context: TraversalContext; - container: object | object[]; - listKey: string; inList: boolean; parentKey: string; - key: string | number; - node: T; - scope: Scope; - type: T extends null | undefined ? undefined : T extends Node ? T['type'] : string | undefined; typeAnnotation: object; + static get(opts: { + hub?: HubInterface; + parentPath: NodePath | null; + parent: Node; + container: C; + key: K; + }): NodePath; + static get>(opts: { + hub?: HubInterface; + parentPath: NodePath | null; + parent: Node; + container: C; + listKey: L; + key: number; + }): C[L] extends Array ? NodePath : never; + getScope(scope: Scope): Scope; - setData(key: string, val: any): any; + setData(key: string | symbol, val: any): any; - getData(key: string, def?: any): any; + getData(key: string | symbol, def?: any): any; - hasNode(): this is NodePath>; + hasNode(): this is NodePath>; - buildCodeFrameError(msg: string, Error?: new (msg: string) => TError): TError; + buildCodeFrameError(msg: string, Error?: ErrorConstructor): Error; traverse(visitor: Visitor, state: T): void; traverse(visitor: Visitor): void; - set(key: string, node: Node): void; + set(key: string, node: any): void; getPathLocation(): string; // Example: https://github.com/babel/babel/blob/63204ae51e020d84a5b246312f5eeb4d981ab952/packages/babel-traverse/src/path/modification.js#L83 debug(buildMessage: () => string): void; - static get(opts: { - hub: HubInterface; - parentPath: NodePath | null; - parent: Node; - container: C; - listKey?: string | undefined; - key: K; - }): NodePath; - //#region ------------------------- ancestry ------------------------- /** * Starting at the parent path of the current `NodePath` and going up the @@ -321,7 +444,7 @@ export class NodePath { /** Get the earliest path in the tree where the provided `paths` intersect. */ getDeepestCommonAncestorFrom( paths: NodePath[], - filter?: (deepest: Node, i: number, ancestries: NodePath[]) => NodePath, + filter?: (deepest: Node, i: number, ancestries: NodePath[][]) => NodePath, ): NodePath; /** @@ -346,13 +469,13 @@ export class NodePath { //#region ------------------------- inference ------------------------- /** Infer the type of the current `NodePath`. */ - getTypeAnnotation(): t.FlowType; + getTypeAnnotation(): t.FlowType | t.TSType; isBaseType(baseName: string, soft?: boolean): boolean; couldBeBaseType(name: string): boolean; - baseTypeStrictlyMatches(right: NodePath): boolean; + baseTypeStrictlyMatches(rightArg: NodePath): boolean; isGenericType(genericName: string): boolean; //#endregion @@ -365,7 +488,7 @@ export class NodePath { * - Insert the provided nodes after the current node. * - Remove the current node. */ - replaceWithMultiple(nodes: Nodes): NodePaths; + replaceWithMultiple(nodes: Nodes): NodePaths; /** * Parse a string as an expression and replace the current node with the result. @@ -374,19 +497,20 @@ export class NodePath { * 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): [NodePath]; + replaceWithSourceString(replacement: string): [NodePath]; /** Replace the current node with another. */ - replaceWith(replacement: T | NodePath): [NodePath]; + replaceWith(replacementPath: R | NodePath): [NodePath]; + replaceWith(replacementPath: R): [R]; /** * 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: Nodes): NodePaths; + replaceExpressionWithStatements(nodes: t.Statement[]): NodePaths; - replaceInline(nodes: Nodes): NodePaths; + replaceInline(nodes: Nodes): NodePaths; //#endregion //#region ------------------------- evaluation ------------------------- @@ -398,22 +522,28 @@ export class NodePath { * 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; + evaluateTruthy(): boolean | undefined; /** * 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. + * Returns an object in the form `{ confident, value, deopt }`. `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, in which case `deopt` is the path of said node. * * 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 } + * t.evaluate(parse("foo + foo")) // { confident: false, value: undefined, deopt: NodePath } + * */ - evaluate(): { confident: boolean; value: any }; + evaluate(): { + confident: boolean; + value: any; + deopt?: NodePath; + }; //#endregion //#region ------------------------- introspection ------------------------- @@ -430,17 +560,21 @@ export class NodePath { * if the array has any items, otherwise we just check if it's falsy. */ has(key: string): boolean; + // has(key: keyof T): boolean; isStatic(): boolean; /** Alias of `has`. */ is(key: string): boolean; + // is(key: keyof T): boolean; /** Opposite of `has`. */ isnt(key: string): boolean; + // isnt(key: keyof T): boolean; /** Check whether the path node `key` strict equals `value`. */ equals(key: string, value: any): boolean; + // equals(key: keyof T, value: any): boolean; /** * Check the type against our stored internal type of the node. This is handy when a node has @@ -484,12 +618,21 @@ export class NodePath { getSource(): string; /** Check if the current path will maybe execute before another path */ - willIMaybeExecuteBefore(path: NodePath): boolean; + willIMaybeExecuteBefore(target: NodePath): boolean; + + resolve(dangerous?: boolean, resolved?: NodePath[]): NodePath; + + isConstantExpression(): boolean; + + isInStrictMode(): boolean; //#endregion //#region ------------------------- context ------------------------- call(key: string): boolean; + isDenylisted(): boolean; + + /** @deprecated will be removed in Babel 8 */ isBlacklisted(): boolean; visit(): boolean; @@ -504,24 +647,72 @@ export class NodePath { setContext(context?: TraversalContext): this; + /** + * Here we resync the node paths `key` and `container`. If they've changed according + * to what we have stored internally then we attempt to resync by crawling and looking + * for the new values. + */ + resync(): void; + popContext(): void; pushContext(context: TraversalContext): void; + + requeue(pathToQueue?: NodePath): void; //#endregion //#region ------------------------- removal ------------------------- remove(): void; //#endregion + //#region ------------------------- conversion ------------------------- + toComputedKey(): t.PrivateName | t.Expression; + + /** @deprecated Use `arrowFunctionToExpression` */ + arrowFunctionToShadowed(): void; + + /** + * Given an arbitrary function, process its content as if it were an arrow function, moving references + * to "this", "arguments", "super", and such into the function's parent scope. This method is useful if + * you have wrapped some set of items in an IIFE or other function, but want "this", "arguments", and super" + * to continue behaving as expected. + */ + unwrapFunctionEnvironment(): void; + + /** + * Convert a given arrow function into a normal ES5 function expression. + */ + arrowFunctionToExpression({ + allowInsertArrow, + allowInsertArrowWithRest, + /** @deprecated Use `noNewArrows` instead */ + specCompliant, + noNewArrows, + }?: { + allowInsertArrow?: boolean; + allowInsertArrowWithRest?: boolean; + specCompliant?: boolean; + noNewArrows?: boolean; + }): NodePath | t.CallExpression>; + + ensureBlock( + this: NodePath, + ): asserts this is NodePath< + T & { + body: t.BlockStatement; + } + >; + //#endregion + //#region ------------------------- modification ------------------------- /** Insert the provided nodes before the current one. */ - insertBefore(nodes: Nodes): NodePaths; + insertBefore>(nodes: Nodes): NodePaths; /** * 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: Nodes): NodePaths; + insertAfter>(nodes: Nodes): NodePaths; /** Update all sibling node paths after `fromIndex` by `incrementBy`. */ updateSiblingKeys(fromIndex: number, incrementBy: number): void; @@ -531,21 +722,29 @@ export class NodePath { * @param listKey - The key at which the child nodes are stored (usually body). * @param nodes - the nodes to insert. */ - unshiftContainer(listKey: ArrayKeys, nodes: Nodes): NodePaths; + unshiftContainer< + T extends Node, + K extends NodeKeyOfArrays, + Nodes extends NodesInsertionParam>, + >(this: NodePath, listKey: K, nodes: Nodes): NodePaths; /** * Insert child nodes at the end of the current node. * @param listKey - The key at which the child nodes are stored (usually body). * @param nodes - the nodes to insert. */ - pushContainer(listKey: ArrayKeys, nodes: Nodes): NodePaths; + pushContainer, Nodes extends NodesInsertionParam>>( + this: NodePath, + listKey: K, + nodes: Nodes, + ): NodePaths; /** Hoist the current node to the highest scope possible and return a UID referencing it. */ hoist(scope: Scope): void; //#endregion //#region ------------------------- family ------------------------- - getOpposite(): NodePath; + getOpposite(): NodePath | null; getCompletionRecords(): NodePath[]; @@ -585,590 +784,654 @@ export class NodePath { /** Share comments amongst siblings. */ shareCommentsWithSiblings(): void; - addComment(type: string, content: string, line?: boolean): void; + addComment(type: t.CommentTypeShorthand, content: string, line?: boolean): void; /** Give node `comments` of the specified `type`. */ - addComments(type: string, comments: any[]): void; + addComments(type: t.CommentTypeShorthand, comments: t.Comment[]): void; //#endregion //#region ------------------------- isXXX ------------------------- - isAnyTypeAnnotation(props?: object | null): this is NodePath; - isArrayExpression(props?: object | null): this is NodePath; - isArrayPattern(props?: object | null): this is NodePath; - isArrayTypeAnnotation(props?: object | null): this is NodePath; - isArrowFunctionExpression(props?: object | null): this is NodePath; - isAssignmentExpression(props?: object | null): this is NodePath; - isAssignmentPattern(props?: object | null): this is NodePath; - isAwaitExpression(props?: object | null): this is NodePath; - isBigIntLiteral(props?: object | null): this is NodePath; - isBinary(props?: object | null): this is NodePath; - isBinaryExpression(props?: object | null): this is NodePath; - isBindExpression(props?: object | null): this is NodePath; - isBlock(props?: object | null): this is NodePath; - isBlockParent(props?: object | null): this is NodePath; - isBlockStatement(props?: object | null): this is NodePath; - isBooleanLiteral(props?: object | null): this is NodePath; - isBooleanLiteralTypeAnnotation(props?: object | null): this is NodePath; - isBooleanTypeAnnotation(props?: object | null): this is NodePath; - isBreakStatement(props?: object | null): this is NodePath; - isCallExpression(props?: object | null): this is NodePath; - isCatchClause(props?: object | null): this is NodePath; - isClass(props?: object | null): this is NodePath; - isClassBody(props?: object | null): this is NodePath; - isClassDeclaration(props?: object | null): this is NodePath; - isClassExpression(props?: object | null): this is NodePath; - isClassImplements(props?: object | null): this is NodePath; - isClassMethod(props?: object | null): this is NodePath; - isClassPrivateMethod(props?: object | null): this is NodePath; - isClassPrivateProperty(props?: object | null): this is NodePath; - isClassProperty(props?: object | null): this is NodePath; - isCompletionStatement(props?: object | null): this is NodePath; - isConditional(props?: object | null): this is NodePath; - isConditionalExpression(props?: object | null): this is NodePath; - isContinueStatement(props?: object | null): this is NodePath; - isDebuggerStatement(props?: object | null): this is NodePath; - isDeclaration(props?: object | null): this is NodePath; - isDeclareClass(props?: object | null): this is NodePath; - isDeclareExportAllDeclaration(props?: object | null): this is NodePath; - isDeclareExportDeclaration(props?: object | null): this is NodePath; - isDeclareFunction(props?: object | null): this is NodePath; - isDeclareInterface(props?: object | null): this is NodePath; - isDeclareModule(props?: object | null): this is NodePath; - isDeclareModuleExports(props?: object | null): this is NodePath; - isDeclareOpaqueType(props?: object | null): this is NodePath; - isDeclareTypeAlias(props?: object | null): this is NodePath; - isDeclareVariable(props?: object | null): this is NodePath; - isDeclaredPredicate(props?: object | null): this is NodePath; - isDecorator(props?: object | null): this is NodePath; - isDirective(props?: object | null): this is NodePath; - isDirectiveLiteral(props?: object | null): this is NodePath; - isDoExpression(props?: object | null): this is NodePath; - isDoWhileStatement(props?: object | null): this is NodePath; - isEmptyStatement(props?: object | null): this is NodePath; - isEmptyTypeAnnotation(props?: object | null): this is NodePath; - isExistsTypeAnnotation(props?: object | null): this is NodePath; - isExportAllDeclaration(props?: object | null): this is NodePath; - isExportDeclaration(props?: object | null): this is NodePath; - isExportDefaultDeclaration(props?: object | null): this is NodePath; - isExportDefaultSpecifier(props?: object | null): this is NodePath; - isExportNamedDeclaration(props?: object | null): this is NodePath; - isExportNamespaceSpecifier(props?: object | null): this is NodePath; - isExportSpecifier(props?: object | null): this is NodePath; - isExpression(props?: object | null): this is NodePath; - isExpressionStatement(props?: object | null): this is NodePath; - isExpressionWrapper(props?: object | null): this is NodePath; - isFile(props?: object | null): this is NodePath; - isFlow(props?: object | null): this is NodePath; - isFlowBaseAnnotation(props?: object | null): this is NodePath; - isFlowDeclaration(props?: object | null): this is NodePath; - isFlowPredicate(props?: object | null): this is NodePath; - isFlowType(props?: object | null): this is NodePath; - isFor(props?: object | null): this is NodePath; - isForInStatement(props?: object | null): this is NodePath; - isForOfStatement(props?: object | null): this is NodePath; - isForStatement(props?: object | null): this is NodePath; - isForXStatement(props?: object | null): this is NodePath; - isFunction(props?: object | null): this is NodePath; - isFunctionDeclaration(props?: object | null): this is NodePath; - isFunctionExpression(props?: object | null): this is NodePath; - isFunctionParent(props?: object | null): this is NodePath; - isFunctionTypeAnnotation(props?: object | null): this is NodePath; - isFunctionTypeParam(props?: object | null): this is NodePath; - isGenericTypeAnnotation(props?: object | null): this is NodePath; - isIdentifier(props?: object | null): this is NodePath; - isIfStatement(props?: object | null): this is NodePath; - isImmutable(props?: object | null): this is NodePath; - isImport(props?: object | null): this is NodePath; - isImportDeclaration(props?: object | null): this is NodePath; - isImportDefaultSpecifier(props?: object | null): this is NodePath; - isImportNamespaceSpecifier(props?: object | null): this is NodePath; - isImportSpecifier(props?: object | null): this is NodePath; - isInferredPredicate(props?: object | null): this is NodePath; - isInterfaceDeclaration(props?: object | null): this is NodePath; - isInterfaceExtends(props?: object | null): this is NodePath; - isInterfaceTypeAnnotation(props?: object | null): this is NodePath; - isInterpreterDirective(props?: object | null): this is NodePath; - isIntersectionTypeAnnotation(props?: object | null): this is NodePath; - isJSX(props?: object | null): this is NodePath; - isJSXAttribute(props?: object | null): this is NodePath; - isJSXClosingElement(props?: object | null): this is NodePath; - isJSXClosingFragment(props?: object | null): this is NodePath; - isJSXElement(props?: object | null): this is NodePath; - isJSXEmptyExpression(props?: object | null): this is NodePath; - isJSXExpressionContainer(props?: object | null): this is NodePath; - isJSXFragment(props?: object | null): this is NodePath; - isJSXIdentifier(props?: object | null): this is NodePath; - isJSXMemberExpression(props?: object | null): this is NodePath; - isJSXNamespacedName(props?: object | null): this is NodePath; - isJSXOpeningElement(props?: object | null): this is NodePath; - isJSXOpeningFragment(props?: object | null): this is NodePath; - isJSXSpreadAttribute(props?: object | null): this is NodePath; - isJSXSpreadChild(props?: object | null): this is NodePath; - isJSXText(props?: object | null): this is NodePath; - isLVal(props?: object | null): this is NodePath; - isLabeledStatement(props?: object | null): this is NodePath; - isLiteral(props?: object | null): this is NodePath; - isLogicalExpression(props?: object | null): this is NodePath; - isLoop(props?: object | null): this is NodePath; - isMemberExpression(props?: object | null): this is NodePath; - isMetaProperty(props?: object | null): this is NodePath; - isMethod(props?: object | null): this is NodePath; - isMixedTypeAnnotation(props?: object | null): this is NodePath; - isModuleDeclaration(props?: object | null): this is NodePath; - isModuleSpecifier(props?: object | null): this is NodePath; - isNewExpression(props?: object | null): this is NodePath; - isNoop(props?: object | null): this is NodePath; - isNullLiteral(props?: object | null): this is NodePath; - isNullLiteralTypeAnnotation(props?: object | null): this is NodePath; - isNullableTypeAnnotation(props?: object | null): this is NodePath; + isAccessor(opts?: object): this is NodePath; + isAnyTypeAnnotation(opts?: object): this is NodePath; + isArgumentPlaceholder(opts?: object): this is NodePath; + isArrayExpression(opts?: object): this is NodePath; + isArrayPattern(opts?: object): this is NodePath; + isArrayTypeAnnotation(opts?: object): this is NodePath; + isArrowFunctionExpression(opts?: object): this is NodePath; + isAssignmentExpression(opts?: object): this is NodePath; + isAssignmentPattern(opts?: object): this is NodePath; + isAwaitExpression(opts?: object): this is NodePath; + isBigIntLiteral(opts?: object): this is NodePath; + isBinary(opts?: object): this is NodePath; + isBinaryExpression(opts?: object): this is NodePath; + isBindExpression(opts?: object): this is NodePath; + isBlock(opts?: object): this is NodePath; + isBlockParent(opts?: object): this is NodePath; + isBlockStatement(opts?: object): this is NodePath; + isBooleanLiteral(opts?: object): this is NodePath; + isBooleanLiteralTypeAnnotation(opts?: object): this is NodePath; + isBooleanTypeAnnotation(opts?: object): this is NodePath; + isBreakStatement(opts?: object): this is NodePath; + isCallExpression(opts?: object): this is NodePath; + isCatchClause(opts?: object): this is NodePath; + isClass(opts?: object): this is NodePath; + isClassAccessorProperty(opts?: object): this is NodePath; + isClassBody(opts?: object): this is NodePath; + isClassDeclaration(opts?: object): this is NodePath; + isClassExpression(opts?: object): this is NodePath; + isClassImplements(opts?: object): this is NodePath; + isClassMethod(opts?: object): this is NodePath; + isClassPrivateMethod(opts?: object): this is NodePath; + isClassPrivateProperty(opts?: object): this is NodePath; + isClassProperty(opts?: object): this is NodePath; + isCompletionStatement(opts?: object): this is NodePath; + isConditional(opts?: object): this is NodePath; + isConditionalExpression(opts?: object): this is NodePath; + isContinueStatement(opts?: object): this is NodePath; + isDebuggerStatement(opts?: object): this is NodePath; + isDecimalLiteral(opts?: object): this is NodePath; + isDeclaration(opts?: object): this is NodePath; + isDeclareClass(opts?: object): this is NodePath; + isDeclareExportAllDeclaration(opts?: object): this is NodePath; + isDeclareExportDeclaration(opts?: object): this is NodePath; + isDeclareFunction(opts?: object): this is NodePath; + isDeclareInterface(opts?: object): this is NodePath; + isDeclareModule(opts?: object): this is NodePath; + isDeclareModuleExports(opts?: object): this is NodePath; + isDeclareOpaqueType(opts?: object): this is NodePath; + isDeclareTypeAlias(opts?: object): this is NodePath; + isDeclareVariable(opts?: object): this is NodePath; + isDeclaredPredicate(opts?: object): this is NodePath; + isDecorator(opts?: object): this is NodePath; + isDirective(opts?: object): this is NodePath; + isDirectiveLiteral(opts?: object): this is NodePath; + isDoExpression(opts?: object): this is NodePath; + isDoWhileStatement(opts?: object): this is NodePath; + isEmptyStatement(opts?: object): this is NodePath; + isEmptyTypeAnnotation(opts?: object): this is NodePath; + isEnumBody(opts?: object): this is NodePath; + isEnumBooleanBody(opts?: object): this is NodePath; + isEnumBooleanMember(opts?: object): this is NodePath; + isEnumDeclaration(opts?: object): this is NodePath; + isEnumDefaultedMember(opts?: object): this is NodePath; + isEnumMember(opts?: object): this is NodePath; + isEnumNumberBody(opts?: object): this is NodePath; + isEnumNumberMember(opts?: object): this is NodePath; + isEnumStringBody(opts?: object): this is NodePath; + isEnumStringMember(opts?: object): this is NodePath; + isEnumSymbolBody(opts?: object): this is NodePath; + isExistsTypeAnnotation(opts?: object): this is NodePath; + isExportAllDeclaration(opts?: object): this is NodePath; + isExportDeclaration(opts?: object): this is NodePath; + isExportDefaultDeclaration(opts?: object): this is NodePath; + isExportDefaultSpecifier(opts?: object): this is NodePath; + isExportNamedDeclaration(opts?: object): this is NodePath; + isExportNamespaceSpecifier(opts?: object): this is NodePath; + isExportSpecifier(opts?: object): this is NodePath; + isExpression(opts?: object): this is NodePath; + isExpressionStatement(opts?: object): this is NodePath; + isExpressionWrapper(opts?: object): this is NodePath; + isFile(opts?: object): this is NodePath; + isFlow(opts?: object): this is NodePath; + isFlowBaseAnnotation(opts?: object): this is NodePath; + isFlowDeclaration(opts?: object): this is NodePath; + isFlowPredicate(opts?: object): this is NodePath; + isFlowType(opts?: object): this is NodePath; + isFor(opts?: object): this is NodePath; + isForInStatement(opts?: object): this is NodePath; + isForOfStatement(opts?: object): this is NodePath; + isForStatement(opts?: object): this is NodePath; + isForXStatement(opts?: object): this is NodePath; + isFunction(opts?: object): this is NodePath; + isFunctionDeclaration(opts?: object): this is NodePath; + isFunctionExpression(opts?: object): this is NodePath; + isFunctionParent(opts?: object): this is NodePath; + isFunctionTypeAnnotation(opts?: object): this is NodePath; + isFunctionTypeParam(opts?: object): this is NodePath; + isGenericTypeAnnotation(opts?: object): this is NodePath; + isIdentifier(opts?: object): this is NodePath; + isIfStatement(opts?: object): this is NodePath; + isImmutable(opts?: object): this is NodePath; + isImport(opts?: object): this is NodePath; + isImportAttribute(opts?: object): this is NodePath; + isImportDeclaration(opts?: object): this is NodePath; + isImportDefaultSpecifier(opts?: object): this is NodePath; + isImportNamespaceSpecifier(opts?: object): this is NodePath; + isImportSpecifier(opts?: object): this is NodePath; + isIndexedAccessType(opts?: object): this is NodePath; + isInferredPredicate(opts?: object): this is NodePath; + isInterfaceDeclaration(opts?: object): this is NodePath; + isInterfaceExtends(opts?: object): this is NodePath; + isInterfaceTypeAnnotation(opts?: object): this is NodePath; + isInterpreterDirective(opts?: object): this is NodePath; + isIntersectionTypeAnnotation(opts?: object): this is NodePath; + isJSX(opts?: object): this is NodePath; + isJSXAttribute(opts?: object): this is NodePath; + isJSXClosingElement(opts?: object): this is NodePath; + isJSXClosingFragment(opts?: object): this is NodePath; + isJSXElement(opts?: object): this is NodePath; + isJSXEmptyExpression(opts?: object): this is NodePath; + isJSXExpressionContainer(opts?: object): this is NodePath; + isJSXFragment(opts?: object): this is NodePath; + isJSXIdentifier(opts?: object): this is NodePath; + isJSXMemberExpression(opts?: object): this is NodePath; + isJSXNamespacedName(opts?: object): this is NodePath; + isJSXOpeningElement(opts?: object): this is NodePath; + isJSXOpeningFragment(opts?: object): this is NodePath; + isJSXSpreadAttribute(opts?: object): this is NodePath; + isJSXSpreadChild(opts?: object): this is NodePath; + isJSXText(opts?: object): this is NodePath; + isLVal(opts?: object): this is NodePath; + isLabeledStatement(opts?: object): this is NodePath; + isLiteral(opts?: object): this is NodePath; + isLogicalExpression(opts?: object): this is NodePath; + isLoop(opts?: object): this is NodePath; + isMemberExpression(opts?: object): this is NodePath; + isMetaProperty(opts?: object): this is NodePath; + isMethod(opts?: object): this is NodePath; + isMiscellaneous(opts?: object): this is NodePath; + isMixedTypeAnnotation(opts?: object): this is NodePath; + isModuleDeclaration(opts?: object): this is NodePath; + isModuleExpression(opts?: object): this is NodePath; + isModuleSpecifier(opts?: object): this is NodePath; + isNewExpression(opts?: object): this is NodePath; + isNoop(opts?: object): this is NodePath; + isNullLiteral(opts?: object): this is NodePath; + isNullLiteralTypeAnnotation(opts?: object): this is NodePath; + isNullableTypeAnnotation(opts?: object): this is NodePath; /** @deprecated Use `isNumericLiteral` */ - isNumberLiteral(props?: object | null): this is NodePath; - isNumberLiteralTypeAnnotation(props?: object | null): this is NodePath; - isNumberTypeAnnotation(props?: object | null): this is NodePath; - isNumericLiteral(props?: object | null): this is NodePath; - isObjectExpression(props?: object | null): this is NodePath; - isObjectMember(props?: object | null): this is NodePath; - isObjectMethod(props?: object | null): this is NodePath; - isObjectPattern(props?: object | null): this is NodePath; - isObjectProperty(props?: object | null): this is NodePath; - isObjectTypeAnnotation(props?: object | null): this is NodePath; - isObjectTypeCallProperty(props?: object | null): this is NodePath; - isObjectTypeIndexer(props?: object | null): this is NodePath; - isObjectTypeInternalSlot(props?: object | null): this is NodePath; - isObjectTypeProperty(props?: object | null): this is NodePath; - isObjectTypeSpreadProperty(props?: object | null): this is NodePath; - isOpaqueType(props?: object | null): this is NodePath; - isOptionalCallExpression(props?: object | null): this is NodePath; - isOptionalMemberExpression(props?: object | null): this is NodePath; - isParenthesizedExpression(props?: object | null): this is NodePath; - isPattern(props?: object | null): this is NodePath; - isPatternLike(props?: object | null): this is NodePath; - isPipelineBareFunction(props?: object | null): this is NodePath; - isPipelinePrimaryTopicReference(props?: object | null): this is NodePath; - isPipelineTopicExpression(props?: object | null): this is NodePath; - isPrivate(props?: object | null): this is NodePath; - isPrivateName(props?: object | null): this is NodePath; - isProgram(props?: object | null): this is NodePath; - isProperty(props?: object | null): this is NodePath; - isPureish(props?: object | null): this is NodePath; - isQualifiedTypeIdentifier(props?: object | null): this is NodePath; - isRegExpLiteral(props?: object | null): this is NodePath; + isNumberLiteral(opts?: object): this is NodePath; + isNumberLiteralTypeAnnotation(opts?: object): this is NodePath; + isNumberTypeAnnotation(opts?: object): this is NodePath; + isNumericLiteral(opts?: object): this is NodePath; + isObjectExpression(opts?: object): this is NodePath; + isObjectMember(opts?: object): this is NodePath; + isObjectMethod(opts?: object): this is NodePath; + isObjectPattern(opts?: object): this is NodePath; + isObjectProperty(opts?: object): this is NodePath; + isObjectTypeAnnotation(opts?: object): this is NodePath; + isObjectTypeCallProperty(opts?: object): this is NodePath; + isObjectTypeIndexer(opts?: object): this is NodePath; + isObjectTypeInternalSlot(opts?: object): this is NodePath; + isObjectTypeProperty(opts?: object): this is NodePath; + isObjectTypeSpreadProperty(opts?: object): this is NodePath; + isOpaqueType(opts?: object): this is NodePath; + isOptionalCallExpression(opts?: object): this is NodePath; + isOptionalIndexedAccessType(opts?: object): this is NodePath; + isOptionalMemberExpression(opts?: object): this is NodePath; + isParenthesizedExpression(opts?: object): this is NodePath; + isPattern(opts?: object): this is NodePath; + isPatternLike(opts?: object): this is NodePath; + isPipelineBareFunction(opts?: object): this is NodePath; + isPipelinePrimaryTopicReference(opts?: object): this is NodePath; + isPipelineTopicExpression(opts?: object): this is NodePath; + isPlaceholder(opts?: object): this is NodePath; + isPrivate(opts?: object): this is NodePath; + isPrivateName(opts?: object): this is NodePath; + isProgram(opts?: object): this is NodePath; + isProperty(opts?: object): this is NodePath; + isPureish(opts?: object): this is NodePath; + isQualifiedTypeIdentifier(opts?: object): this is NodePath; + isRecordExpression(opts?: object): this is NodePath; + isRegExpLiteral(opts?: object): this is NodePath; /** @deprecated Use `isRegExpLiteral` */ - isRegexLiteral(props?: object | null): this is NodePath; - isRestElement(props?: object | null): this is NodePath; + isRegexLiteral(opts?: object): this is NodePath; + isRestElement(opts?: object): this is NodePath; /** @deprecated Use `isRestElement` */ - isRestProperty(props?: object | null): this is NodePath; - isReturnStatement(props?: object | null): this is NodePath; - isScopable(props?: object | null): this is NodePath; - isSequenceExpression(props?: object | null): this is NodePath; - isSpreadElement(props?: object | null): this is NodePath; + isRestProperty(opts?: object): this is NodePath; + isReturnStatement(opts?: object): this is NodePath; + isScopable(opts?: object): this is NodePath; + isSequenceExpression(opts?: object): this is NodePath; + isSpreadElement(opts?: object): this is NodePath; /** @deprecated Use `isSpreadElement` */ - isSpreadProperty(props?: object | null): this is NodePath; - isStatement(props?: object | null): this is NodePath; - isStringLiteral(props?: object | null): this is NodePath; - isStringLiteralTypeAnnotation(props?: object | null): this is NodePath; - isStringTypeAnnotation(props?: object | null): this is NodePath; - isSuper(props?: object | null): this is NodePath; - isSwitchCase(props?: object | null): this is NodePath; - isSwitchStatement(props?: object | null): this is NodePath; - isTSAnyKeyword(props?: object | null): this is NodePath; - isTSArrayType(props?: object | null): this is NodePath; - isTSAsExpression(props?: object | null): this is NodePath; - isTSBooleanKeyword(props?: object | null): this is NodePath; - isTSCallSignatureDeclaration(props?: object | null): this is NodePath; - isTSConditionalType(props?: object | null): this is NodePath; - isTSConstructSignatureDeclaration(props?: object | null): this is NodePath; - isTSConstructorType(props?: object | null): this is NodePath; - isTSDeclareFunction(props?: object | null): this is NodePath; - isTSDeclareMethod(props?: object | null): this is NodePath; - isTSEntityName(props?: object | null): this is NodePath; - isTSEnumDeclaration(props?: object | null): this is NodePath; - isTSEnumMember(props?: object | null): this is NodePath; - isTSExportAssignment(props?: object | null): this is NodePath; - isTSExpressionWithTypeArguments(props?: object | null): this is NodePath; - isTSExternalModuleReference(props?: object | null): this is NodePath; - isTSFunctionType(props?: object | null): this is NodePath; - isTSImportEqualsDeclaration(props?: object | null): this is NodePath; - isTSImportType(props?: object | null): this is NodePath; - isTSIndexSignature(props?: object | null): this is NodePath; - isTSIndexedAccessType(props?: object | null): this is NodePath; - isTSInferType(props?: object | null): this is NodePath; - isTSInterfaceBody(props?: object | null): this is NodePath; - isTSInterfaceDeclaration(props?: object | null): this is NodePath; - isTSIntersectionType(props?: object | null): this is NodePath; - isTSLiteralType(props?: object | null): this is NodePath; - isTSMappedType(props?: object | null): this is NodePath; - isTSMethodSignature(props?: object | null): this is NodePath; - isTSModuleBlock(props?: object | null): this is NodePath; - isTSModuleDeclaration(props?: object | null): this is NodePath; - isTSNamespaceExportDeclaration(props?: object | null): this is NodePath; - isTSNeverKeyword(props?: object | null): this is NodePath; - isTSNonNullExpression(props?: object | null): this is NodePath; - isTSNullKeyword(props?: object | null): this is NodePath; - isTSNumberKeyword(props?: object | null): this is NodePath; - isTSObjectKeyword(props?: object | null): this is NodePath; - isTSOptionalType(props?: object | null): this is NodePath; - isTSParameterProperty(props?: object | null): this is NodePath; - isTSParenthesizedType(props?: object | null): this is NodePath; - isTSPropertySignature(props?: object | null): this is NodePath; - isTSQualifiedName(props?: object | null): this is NodePath; - isTSRestType(props?: object | null): this is NodePath; - isTSStringKeyword(props?: object | null): this is NodePath; - isTSSymbolKeyword(props?: object | null): this is NodePath; - isTSThisType(props?: object | null): this is NodePath; - isTSTupleType(props?: object | null): this is NodePath; - isTSType(props?: object | null): this is NodePath; - isTSTypeAliasDeclaration(props?: object | null): this is NodePath; - isTSTypeAnnotation(props?: object | null): this is NodePath; - isTSTypeAssertion(props?: object | null): this is NodePath; - isTSTypeElement(props?: object | null): this is NodePath; - isTSTypeLiteral(props?: object | null): this is NodePath; - isTSTypeOperator(props?: object | null): this is NodePath; - isTSTypeParameter(props?: object | null): this is NodePath; - isTSTypeParameterDeclaration(props?: object | null): this is NodePath; - isTSTypeParameterInstantiation(props?: object | null): this is NodePath; - isTSTypePredicate(props?: object | null): this is NodePath; - isTSTypeQuery(props?: object | null): this is NodePath; - isTSTypeReference(props?: object | null): this is NodePath; - isTSUndefinedKeyword(props?: object | null): this is NodePath; - isTSUnionType(props?: object | null): this is NodePath; - isTSUnknownKeyword(props?: object | null): this is NodePath; - isTSVoidKeyword(props?: object | null): this is NodePath; - isTaggedTemplateExpression(props?: object | null): this is NodePath; - isTemplateElement(props?: object | null): this is NodePath; - isTemplateLiteral(props?: object | null): this is NodePath; - isTerminatorless(props?: object | null): this is NodePath; - isThisExpression(props?: object | null): this is NodePath; - isThisTypeAnnotation(props?: object | null): this is NodePath; - isThrowStatement(props?: object | null): this is NodePath; - isTryStatement(props?: object | null): this is NodePath; - isTupleTypeAnnotation(props?: object | null): this is NodePath; - isTypeAlias(props?: object | null): this is NodePath; - isTypeAnnotation(props?: object | null): this is NodePath; - isTypeCastExpression(props?: object | null): this is NodePath; - isTypeParameter(props?: object | null): this is NodePath; - isTypeParameterDeclaration(props?: object | null): this is NodePath; - isTypeParameterInstantiation(props?: object | null): this is NodePath; - isTypeofTypeAnnotation(props?: object | null): this is NodePath; - isUnaryExpression(props?: object | null): this is NodePath; - isUnaryLike(props?: object | null): this is NodePath; - isUnionTypeAnnotation(props?: object | null): this is NodePath; - isUpdateExpression(props?: object | null): this is NodePath; - isUserWhitespacable(props?: object | null): this is NodePath; - isVariableDeclaration(props?: object | null): this is NodePath; - isVariableDeclarator(props?: object | null): this is NodePath; - isVariance(props?: object | null): this is NodePath; - isVoidTypeAnnotation(props?: object | null): this is NodePath; - isWhile(props?: object | null): this is NodePath; - isWhileStatement(props?: object | null): this is NodePath; - isWithStatement(props?: object | null): this is NodePath; - isYieldExpression(props?: object | null): this is NodePath; + isSpreadProperty(opts?: object): this is NodePath; + isStandardized(opts?: object): this is NodePath; + isStatement(opts?: object): this is NodePath; + isStaticBlock(opts?: object): this is NodePath; + isStringLiteral(opts?: object): this is NodePath; + isStringLiteralTypeAnnotation(opts?: object): this is NodePath; + isStringTypeAnnotation(opts?: object): this is NodePath; + isSuper(opts?: object): this is NodePath; + isSwitchCase(opts?: object): this is NodePath; + isSwitchStatement(opts?: object): this is NodePath; + isSymbolTypeAnnotation(opts?: object): this is NodePath; + isTSAnyKeyword(opts?: object): this is NodePath; + isTSArrayType(opts?: object): this is NodePath; + isTSAsExpression(opts?: object): this is NodePath; + isTSBaseType(opts?: object): this is NodePath; + isTSBigIntKeyword(opts?: object): this is NodePath; + isTSBooleanKeyword(opts?: object): this is NodePath; + isTSCallSignatureDeclaration(opts?: object): this is NodePath; + isTSConditionalType(opts?: object): this is NodePath; + isTSConstructSignatureDeclaration(opts?: object): this is NodePath; + isTSConstructorType(opts?: object): this is NodePath; + isTSDeclareFunction(opts?: object): this is NodePath; + isTSDeclareMethod(opts?: object): this is NodePath; + isTSEntityName(opts?: object): this is NodePath; + isTSEnumDeclaration(opts?: object): this is NodePath; + isTSEnumMember(opts?: object): this is NodePath; + isTSExportAssignment(opts?: object): this is NodePath; + isTSExpressionWithTypeArguments(opts?: object): this is NodePath; + isTSExternalModuleReference(opts?: object): this is NodePath; + isTSFunctionType(opts?: object): this is NodePath; + isTSImportEqualsDeclaration(opts?: object): this is NodePath; + isTSImportType(opts?: object): this is NodePath; + isTSIndexSignature(opts?: object): this is NodePath; + isTSIndexedAccessType(opts?: object): this is NodePath; + isTSInferType(opts?: object): this is NodePath; + isTSInstantiationExpression(opts?: object): this is NodePath; + isTSInterfaceBody(opts?: object): this is NodePath; + isTSInterfaceDeclaration(opts?: object): this is NodePath; + isTSIntersectionType(opts?: object): this is NodePath; + isTSIntrinsicKeyword(opts?: object): this is NodePath; + isTSLiteralType(opts?: object): this is NodePath; + isTSMappedType(opts?: object): this is NodePath; + isTSMethodSignature(opts?: object): this is NodePath; + isTSModuleBlock(opts?: object): this is NodePath; + isTSModuleDeclaration(opts?: object): this is NodePath; + isTSNamedTupleMember(opts?: object): this is NodePath; + isTSNamespaceExportDeclaration(opts?: object): this is NodePath; + isTSNeverKeyword(opts?: object): this is NodePath; + isTSNonNullExpression(opts?: object): this is NodePath; + isTSNullKeyword(opts?: object): this is NodePath; + isTSNumberKeyword(opts?: object): this is NodePath; + isTSObjectKeyword(opts?: object): this is NodePath; + isTSOptionalType(opts?: object): this is NodePath; + isTSParameterProperty(opts?: object): this is NodePath; + isTSParenthesizedType(opts?: object): this is NodePath; + isTSPropertySignature(opts?: object): this is NodePath; + isTSQualifiedName(opts?: object): this is NodePath; + isTSRestType(opts?: object): this is NodePath; + isTSSatisfiesExpression(opts?: object): this is NodePath; + isTSStringKeyword(opts?: object): this is NodePath; + isTSSymbolKeyword(opts?: object): this is NodePath; + isTSThisType(opts?: object): this is NodePath; + isTSTupleType(opts?: object): this is NodePath; + isTSType(opts?: object): this is NodePath; + isTSTypeAliasDeclaration(opts?: object): this is NodePath; + isTSTypeAnnotation(opts?: object): this is NodePath; + isTSTypeAssertion(opts?: object): this is NodePath; + isTSTypeElement(opts?: object): this is NodePath; + isTSTypeLiteral(opts?: object): this is NodePath; + isTSTypeOperator(opts?: object): this is NodePath; + isTSTypeParameter(opts?: object): this is NodePath; + isTSTypeParameterDeclaration(opts?: object): this is NodePath; + isTSTypeParameterInstantiation(opts?: object): this is NodePath; + isTSTypePredicate(opts?: object): this is NodePath; + isTSTypeQuery(opts?: object): this is NodePath; + isTSTypeReference(opts?: object): this is NodePath; + isTSUndefinedKeyword(opts?: object): this is NodePath; + isTSUnionType(opts?: object): this is NodePath; + isTSUnknownKeyword(opts?: object): this is NodePath; + isTSVoidKeyword(opts?: object): this is NodePath; + isTaggedTemplateExpression(opts?: object): this is NodePath; + isTemplateElement(opts?: object): this is NodePath; + isTemplateLiteral(opts?: object): this is NodePath; + isTerminatorless(opts?: object): this is NodePath; + isThisExpression(opts?: object): this is NodePath; + isThisTypeAnnotation(opts?: object): this is NodePath; + isThrowStatement(opts?: object): this is NodePath; + isTopicReference(opts?: object): this is NodePath; + isTryStatement(opts?: object): this is NodePath; + isTupleExpression(opts?: object): this is NodePath; + isTupleTypeAnnotation(opts?: object): this is NodePath; + isTypeAlias(opts?: object): this is NodePath; + isTypeAnnotation(opts?: object): this is NodePath; + isTypeCastExpression(opts?: object): this is NodePath; + isTypeParameter(opts?: object): this is NodePath; + isTypeParameterDeclaration(opts?: object): this is NodePath; + isTypeParameterInstantiation(opts?: object): this is NodePath; + isTypeScript(opts?: object): this is NodePath; + isTypeofTypeAnnotation(opts?: object): this is NodePath; + isUnaryExpression(opts?: object): this is NodePath; + isUnaryLike(opts?: object): this is NodePath; + isUnionTypeAnnotation(opts?: object): this is NodePath; + isUpdateExpression(opts?: object): this is NodePath; + isUserWhitespacable(opts?: object): this is NodePath; + isV8IntrinsicIdentifier(opts?: object): this is NodePath; + isVariableDeclaration(opts?: object): this is NodePath; + isVariableDeclarator(opts?: object): this is NodePath; + isVariance(opts?: object): this is NodePath; + isVoidTypeAnnotation(opts?: object): this is NodePath; + isWhile(opts?: object): this is NodePath; + isWhileStatement(opts?: object): this is NodePath; + isWithStatement(opts?: object): this is NodePath; + isYieldExpression(opts?: object): this is NodePath; - isBindingIdentifier(props?: object | null): this is NodePath; - isBlockScoped( - props?: object | null, - ): this is NodePath; - isGenerated(props?: object | null): boolean; - isPure(props?: object | null): boolean; - isReferenced(props?: object | null): boolean; - isReferencedIdentifier(props?: object | null): this is NodePath; - isReferencedMemberExpression(props?: object | null): this is NodePath; - isScope(props?: object | null): this is NodePath; - isUser(props?: object | null): boolean; - isVar(props?: object | null): this is NodePath; + isBindingIdentifier(opts?: object): this is NodePath; + isBlockScoped(opts?: object): this is NodePath; + + /** @deprecated */ + isExistentialTypeParam(opts?: object): this is NodePath; + isForAwaitStatement(opts?: object): this is NodePath; + isGenerated(opts?: object): boolean; + + /** @deprecated */ + isNumericLiteralTypeAnnotation(opts?: object): void; + isPure(opts?: object): boolean; + isReferenced(opts?: object): boolean; + isReferencedIdentifier(opts?: object): this is NodePath; + isReferencedMemberExpression(opts?: object): this is NodePath; + isScope(opts?: object): this is NodePath; + isUser(opts?: object): boolean; + isVar(opts?: object): this is NodePath; //#endregion //#region ------------------------- assertXXX ------------------------- - assertAnyTypeAnnotation(props?: object | null): void; - assertArrayExpression(props?: object | null): void; - assertArrayPattern(props?: object | null): void; - assertArrayTypeAnnotation(props?: object | null): void; - assertArrowFunctionExpression(props?: object | null): void; - assertAssignmentExpression(props?: object | null): void; - assertAssignmentPattern(props?: object | null): void; - assertAwaitExpression(props?: object | null): void; - assertBigIntLiteral(props?: object | null): void; - assertBinary(props?: object | null): void; - assertBinaryExpression(props?: object | null): void; - assertBindExpression(props?: object | null): void; - assertBlock(props?: object | null): void; - assertBlockParent(props?: object | null): void; - assertBlockStatement(props?: object | null): void; - assertBooleanLiteral(props?: object | null): void; - assertBooleanLiteralTypeAnnotation(props?: object | null): void; - assertBooleanTypeAnnotation(props?: object | null): void; - assertBreakStatement(props?: object | null): void; - assertCallExpression(props?: object | null): void; - assertCatchClause(props?: object | null): void; - assertClass(props?: object | null): void; - assertClassBody(props?: object | null): void; - assertClassDeclaration(props?: object | null): void; - assertClassExpression(props?: object | null): void; - assertClassImplements(props?: object | null): void; - assertClassMethod(props?: object | null): void; - assertClassPrivateMethod(props?: object | null): void; - assertClassPrivateProperty(props?: object | null): void; - assertClassProperty(props?: object | null): void; - assertCompletionStatement(props?: object | null): void; - assertConditional(props?: object | null): void; - assertConditionalExpression(props?: object | null): void; - assertContinueStatement(props?: object | null): void; - assertDebuggerStatement(props?: object | null): void; - assertDeclaration(props?: object | null): void; - assertDeclareClass(props?: object | null): void; - assertDeclareExportAllDeclaration(props?: object | null): void; - assertDeclareExportDeclaration(props?: object | null): void; - assertDeclareFunction(props?: object | null): void; - assertDeclareInterface(props?: object | null): void; - assertDeclareModule(props?: object | null): void; - assertDeclareModuleExports(props?: object | null): void; - assertDeclareOpaqueType(props?: object | null): void; - assertDeclareTypeAlias(props?: object | null): void; - assertDeclareVariable(props?: object | null): void; - assertDeclaredPredicate(props?: object | null): void; - assertDecorator(props?: object | null): void; - assertDirective(props?: object | null): void; - assertDirectiveLiteral(props?: object | null): void; - assertDoExpression(props?: object | null): void; - assertDoWhileStatement(props?: object | null): void; - assertEmptyStatement(props?: object | null): void; - assertEmptyTypeAnnotation(props?: object | null): void; - assertExistsTypeAnnotation(props?: object | null): void; - assertExportAllDeclaration(props?: object | null): void; - assertExportDeclaration(props?: object | null): void; - assertExportDefaultDeclaration(props?: object | null): void; - assertExportDefaultSpecifier(props?: object | null): void; - assertExportNamedDeclaration(props?: object | null): void; - assertExportNamespaceSpecifier(props?: object | null): void; - assertExportSpecifier(props?: object | null): void; - assertExpression(props?: object | null): void; - assertExpressionStatement(props?: object | null): void; - assertExpressionWrapper(props?: object | null): void; - assertFile(props?: object | null): void; - assertFlow(props?: object | null): void; - assertFlowBaseAnnotation(props?: object | null): void; - assertFlowDeclaration(props?: object | null): void; - assertFlowPredicate(props?: object | null): void; - assertFlowType(props?: object | null): void; - assertFor(props?: object | null): void; - assertForInStatement(props?: object | null): void; - assertForOfStatement(props?: object | null): void; - assertForStatement(props?: object | null): void; - assertForXStatement(props?: object | null): void; - assertFunction(props?: object | null): void; - assertFunctionDeclaration(props?: object | null): void; - assertFunctionExpression(props?: object | null): void; - assertFunctionParent(props?: object | null): void; - assertFunctionTypeAnnotation(props?: object | null): void; - assertFunctionTypeParam(props?: object | null): void; - assertGenericTypeAnnotation(props?: object | null): void; - assertIdentifier(props?: object | null): void; - assertIfStatement(props?: object | null): void; - assertImmutable(props?: object | null): void; - assertImport(props?: object | null): void; - assertImportDeclaration(props?: object | null): void; - assertImportDefaultSpecifier(props?: object | null): void; - assertImportNamespaceSpecifier(props?: object | null): void; - assertImportSpecifier(props?: object | null): void; - assertInferredPredicate(props?: object | null): void; - assertInterfaceDeclaration(props?: object | null): void; - assertInterfaceExtends(props?: object | null): void; - assertInterfaceTypeAnnotation(props?: object | null): void; - assertInterpreterDirective(props?: object | null): void; - assertIntersectionTypeAnnotation(props?: object | null): void; - assertJSX(props?: object | null): void; - assertJSXAttribute(props?: object | null): void; - assertJSXClosingElement(props?: object | null): void; - assertJSXClosingFragment(props?: object | null): void; - assertJSXElement(props?: object | null): void; - assertJSXEmptyExpression(props?: object | null): void; - assertJSXExpressionContainer(props?: object | null): void; - assertJSXFragment(props?: object | null): void; - assertJSXIdentifier(props?: object | null): void; - assertJSXMemberExpression(props?: object | null): void; - assertJSXNamespacedName(props?: object | null): void; - assertJSXOpeningElement(props?: object | null): void; - assertJSXOpeningFragment(props?: object | null): void; - assertJSXSpreadAttribute(props?: object | null): void; - assertJSXSpreadChild(props?: object | null): void; - assertJSXText(props?: object | null): void; - assertLVal(props?: object | null): void; - assertLabeledStatement(props?: object | null): void; - assertLiteral(props?: object | null): void; - assertLogicalExpression(props?: object | null): void; - assertLoop(props?: object | null): void; - assertMemberExpression(props?: object | null): void; - assertMetaProperty(props?: object | null): void; - assertMethod(props?: object | null): void; - assertMixedTypeAnnotation(props?: object | null): void; - assertModuleDeclaration(props?: object | null): void; - assertModuleSpecifier(props?: object | null): void; - assertNewExpression(props?: object | null): void; - assertNoop(props?: object | null): void; - assertNullLiteral(props?: object | null): void; - assertNullLiteralTypeAnnotation(props?: object | null): void; - assertNullableTypeAnnotation(props?: object | null): void; + assertAccessor(opts?: object): asserts this is NodePath; + assertAnyTypeAnnotation(opts?: object): asserts this is NodePath; + assertArgumentPlaceholder(opts?: object): asserts this is NodePath; + assertArrayExpression(opts?: object): asserts this is NodePath; + assertArrayPattern(opts?: object): asserts this is NodePath; + assertArrayTypeAnnotation(opts?: object): asserts this is NodePath; + assertArrowFunctionExpression(opts?: object): asserts this is NodePath; + assertAssignmentExpression(opts?: object): asserts this is NodePath; + assertAssignmentPattern(opts?: object): asserts this is NodePath; + assertAwaitExpression(opts?: object): asserts this is NodePath; + assertBigIntLiteral(opts?: object): asserts this is NodePath; + assertBinary(opts?: object): asserts this is NodePath; + assertBinaryExpression(opts?: object): asserts this is NodePath; + assertBindExpression(opts?: object): asserts this is NodePath; + assertBlock(opts?: object): asserts this is NodePath; + assertBlockParent(opts?: object): asserts this is NodePath; + assertBlockStatement(opts?: object): asserts this is NodePath; + assertBooleanLiteral(opts?: object): asserts this is NodePath; + assertBooleanLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertBooleanTypeAnnotation(opts?: object): asserts this is NodePath; + assertBreakStatement(opts?: object): asserts this is NodePath; + assertCallExpression(opts?: object): asserts this is NodePath; + assertCatchClause(opts?: object): asserts this is NodePath; + assertClass(opts?: object): asserts this is NodePath; + assertClassAccessorProperty(opts?: object): asserts this is NodePath; + assertClassBody(opts?: object): asserts this is NodePath; + assertClassDeclaration(opts?: object): asserts this is NodePath; + assertClassExpression(opts?: object): asserts this is NodePath; + assertClassImplements(opts?: object): asserts this is NodePath; + assertClassMethod(opts?: object): asserts this is NodePath; + assertClassPrivateMethod(opts?: object): asserts this is NodePath; + assertClassPrivateProperty(opts?: object): asserts this is NodePath; + assertClassProperty(opts?: object): asserts this is NodePath; + assertCompletionStatement(opts?: object): asserts this is NodePath; + assertConditional(opts?: object): asserts this is NodePath; + assertConditionalExpression(opts?: object): asserts this is NodePath; + assertContinueStatement(opts?: object): asserts this is NodePath; + assertDebuggerStatement(opts?: object): asserts this is NodePath; + assertDecimalLiteral(opts?: object): asserts this is NodePath; + assertDeclaration(opts?: object): asserts this is NodePath; + assertDeclareClass(opts?: object): asserts this is NodePath; + assertDeclareExportAllDeclaration(opts?: object): asserts this is NodePath; + assertDeclareExportDeclaration(opts?: object): asserts this is NodePath; + assertDeclareFunction(opts?: object): asserts this is NodePath; + assertDeclareInterface(opts?: object): asserts this is NodePath; + assertDeclareModule(opts?: object): asserts this is NodePath; + assertDeclareModuleExports(opts?: object): asserts this is NodePath; + assertDeclareOpaqueType(opts?: object): asserts this is NodePath; + assertDeclareTypeAlias(opts?: object): asserts this is NodePath; + assertDeclareVariable(opts?: object): asserts this is NodePath; + assertDeclaredPredicate(opts?: object): asserts this is NodePath; + assertDecorator(opts?: object): asserts this is NodePath; + assertDirective(opts?: object): asserts this is NodePath; + assertDirectiveLiteral(opts?: object): asserts this is NodePath; + assertDoExpression(opts?: object): asserts this is NodePath; + assertDoWhileStatement(opts?: object): asserts this is NodePath; + assertEmptyStatement(opts?: object): asserts this is NodePath; + assertEmptyTypeAnnotation(opts?: object): asserts this is NodePath; + assertEnumBody(opts?: object): asserts this is NodePath; + assertEnumBooleanBody(opts?: object): asserts this is NodePath; + assertEnumBooleanMember(opts?: object): asserts this is NodePath; + assertEnumDeclaration(opts?: object): asserts this is NodePath; + assertEnumDefaultedMember(opts?: object): asserts this is NodePath; + assertEnumMember(opts?: object): asserts this is NodePath; + assertEnumNumberBody(opts?: object): asserts this is NodePath; + assertEnumNumberMember(opts?: object): asserts this is NodePath; + assertEnumStringBody(opts?: object): asserts this is NodePath; + assertEnumStringMember(opts?: object): asserts this is NodePath; + assertEnumSymbolBody(opts?: object): asserts this is NodePath; + assertExistsTypeAnnotation(opts?: object): asserts this is NodePath; + assertExportAllDeclaration(opts?: object): asserts this is NodePath; + assertExportDeclaration(opts?: object): asserts this is NodePath; + assertExportDefaultDeclaration(opts?: object): asserts this is NodePath; + assertExportDefaultSpecifier(opts?: object): asserts this is NodePath; + assertExportNamedDeclaration(opts?: object): asserts this is NodePath; + assertExportNamespaceSpecifier(opts?: object): asserts this is NodePath; + assertExportSpecifier(opts?: object): asserts this is NodePath; + assertExpression(opts?: object): asserts this is NodePath; + assertExpressionStatement(opts?: object): asserts this is NodePath; + assertExpressionWrapper(opts?: object): asserts this is NodePath; + assertFile(opts?: object): asserts this is NodePath; + assertFlow(opts?: object): asserts this is NodePath; + assertFlowBaseAnnotation(opts?: object): asserts this is NodePath; + assertFlowDeclaration(opts?: object): asserts this is NodePath; + assertFlowPredicate(opts?: object): asserts this is NodePath; + assertFlowType(opts?: object): asserts this is NodePath; + assertFor(opts?: object): asserts this is NodePath; + assertForInStatement(opts?: object): asserts this is NodePath; + assertForOfStatement(opts?: object): asserts this is NodePath; + assertForStatement(opts?: object): asserts this is NodePath; + assertForXStatement(opts?: object): asserts this is NodePath; + assertFunction(opts?: object): asserts this is NodePath; + assertFunctionDeclaration(opts?: object): asserts this is NodePath; + assertFunctionExpression(opts?: object): asserts this is NodePath; + assertFunctionParent(opts?: object): asserts this is NodePath; + assertFunctionTypeAnnotation(opts?: object): asserts this is NodePath; + assertFunctionTypeParam(opts?: object): asserts this is NodePath; + assertGenericTypeAnnotation(opts?: object): asserts this is NodePath; + assertIdentifier(opts?: object): asserts this is NodePath; + assertIfStatement(opts?: object): asserts this is NodePath; + assertImmutable(opts?: object): asserts this is NodePath; + assertImport(opts?: object): asserts this is NodePath; + assertImportAttribute(opts?: object): asserts this is NodePath; + assertImportDeclaration(opts?: object): asserts this is NodePath; + assertImportDefaultSpecifier(opts?: object): asserts this is NodePath; + assertImportNamespaceSpecifier(opts?: object): asserts this is NodePath; + assertImportSpecifier(opts?: object): asserts this is NodePath; + assertIndexedAccessType(opts?: object): asserts this is NodePath; + assertInferredPredicate(opts?: object): asserts this is NodePath; + assertInterfaceDeclaration(opts?: object): asserts this is NodePath; + assertInterfaceExtends(opts?: object): asserts this is NodePath; + assertInterfaceTypeAnnotation(opts?: object): asserts this is NodePath; + assertInterpreterDirective(opts?: object): asserts this is NodePath; + assertIntersectionTypeAnnotation(opts?: object): asserts this is NodePath; + assertJSX(opts?: object): asserts this is NodePath; + assertJSXAttribute(opts?: object): asserts this is NodePath; + assertJSXClosingElement(opts?: object): asserts this is NodePath; + assertJSXClosingFragment(opts?: object): asserts this is NodePath; + assertJSXElement(opts?: object): asserts this is NodePath; + assertJSXEmptyExpression(opts?: object): asserts this is NodePath; + assertJSXExpressionContainer(opts?: object): asserts this is NodePath; + assertJSXFragment(opts?: object): asserts this is NodePath; + assertJSXIdentifier(opts?: object): asserts this is NodePath; + assertJSXMemberExpression(opts?: object): asserts this is NodePath; + assertJSXNamespacedName(opts?: object): asserts this is NodePath; + assertJSXOpeningElement(opts?: object): asserts this is NodePath; + assertJSXOpeningFragment(opts?: object): asserts this is NodePath; + assertJSXSpreadAttribute(opts?: object): asserts this is NodePath; + assertJSXSpreadChild(opts?: object): asserts this is NodePath; + assertJSXText(opts?: object): asserts this is NodePath; + assertLVal(opts?: object): asserts this is NodePath; + assertLabeledStatement(opts?: object): asserts this is NodePath; + assertLiteral(opts?: object): asserts this is NodePath; + assertLogicalExpression(opts?: object): asserts this is NodePath; + assertLoop(opts?: object): asserts this is NodePath; + assertMemberExpression(opts?: object): asserts this is NodePath; + assertMetaProperty(opts?: object): asserts this is NodePath; + assertMethod(opts?: object): asserts this is NodePath; + assertMiscellaneous(opts?: object): asserts this is NodePath; + assertMixedTypeAnnotation(opts?: object): asserts this is NodePath; + assertModuleDeclaration(opts?: object): asserts this is NodePath; + assertModuleExpression(opts?: object): asserts this is NodePath; + assertModuleSpecifier(opts?: object): asserts this is NodePath; + assertNewExpression(opts?: object): asserts this is NodePath; + assertNoop(opts?: object): asserts this is NodePath; + assertNullLiteral(opts?: object): asserts this is NodePath; + assertNullLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertNullableTypeAnnotation(opts?: object): asserts this is NodePath; /** @deprecated Use `assertNumericLiteral` */ - assertNumberLiteral(props?: object | null): void; - assertNumberLiteralTypeAnnotation(props?: object | null): void; - assertNumberTypeAnnotation(props?: object | null): void; - assertNumericLiteral(props?: object | null): void; - assertObjectExpression(props?: object | null): void; - assertObjectMember(props?: object | null): void; - assertObjectMethod(props?: object | null): void; - assertObjectPattern(props?: object | null): void; - assertObjectProperty(props?: object | null): void; - assertObjectTypeAnnotation(props?: object | null): void; - assertObjectTypeCallProperty(props?: object | null): void; - assertObjectTypeIndexer(props?: object | null): void; - assertObjectTypeInternalSlot(props?: object | null): void; - assertObjectTypeProperty(props?: object | null): void; - assertObjectTypeSpreadProperty(props?: object | null): void; - assertOpaqueType(props?: object | null): void; - assertOptionalCallExpression(props?: object | null): void; - assertOptionalMemberExpression(props?: object | null): void; - assertParenthesizedExpression(props?: object | null): void; - assertPattern(props?: object | null): void; - assertPatternLike(props?: object | null): void; - assertPipelineBareFunction(props?: object | null): void; - assertPipelinePrimaryTopicReference(props?: object | null): void; - assertPipelineTopicExpression(props?: object | null): void; - assertPrivate(props?: object | null): void; - assertPrivateName(props?: object | null): void; - assertProgram(props?: object | null): void; - assertProperty(props?: object | null): void; - assertPureish(props?: object | null): void; - assertQualifiedTypeIdentifier(props?: object | null): void; - assertRegExpLiteral(props?: object | null): void; + assertNumberLiteral(opts?: object): asserts this is NodePath; + assertNumberLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertNumberTypeAnnotation(opts?: object): asserts this is NodePath; + assertNumericLiteral(opts?: object): asserts this is NodePath; + assertObjectExpression(opts?: object): asserts this is NodePath; + assertObjectMember(opts?: object): asserts this is NodePath; + assertObjectMethod(opts?: object): asserts this is NodePath; + assertObjectPattern(opts?: object): asserts this is NodePath; + assertObjectProperty(opts?: object): asserts this is NodePath; + assertObjectTypeAnnotation(opts?: object): asserts this is NodePath; + assertObjectTypeCallProperty(opts?: object): asserts this is NodePath; + assertObjectTypeIndexer(opts?: object): asserts this is NodePath; + assertObjectTypeInternalSlot(opts?: object): asserts this is NodePath; + assertObjectTypeProperty(opts?: object): asserts this is NodePath; + assertObjectTypeSpreadProperty(opts?: object): asserts this is NodePath; + assertOpaqueType(opts?: object): asserts this is NodePath; + assertOptionalCallExpression(opts?: object): asserts this is NodePath; + assertOptionalIndexedAccessType(opts?: object): asserts this is NodePath; + assertOptionalMemberExpression(opts?: object): asserts this is NodePath; + assertParenthesizedExpression(opts?: object): asserts this is NodePath; + assertPattern(opts?: object): asserts this is NodePath; + assertPatternLike(opts?: object): asserts this is NodePath; + assertPipelineBareFunction(opts?: object): asserts this is NodePath; + assertPipelinePrimaryTopicReference(opts?: object): asserts this is NodePath; + assertPipelineTopicExpression(opts?: object): asserts this is NodePath; + assertPlaceholder(opts?: object): asserts this is NodePath; + assertPrivate(opts?: object): asserts this is NodePath; + assertPrivateName(opts?: object): asserts this is NodePath; + assertProgram(opts?: object): asserts this is NodePath; + assertProperty(opts?: object): asserts this is NodePath; + assertPureish(opts?: object): asserts this is NodePath; + assertQualifiedTypeIdentifier(opts?: object): asserts this is NodePath; + assertRecordExpression(opts?: object): asserts this is NodePath; + assertRegExpLiteral(opts?: object): asserts this is NodePath; /** @deprecated Use `assertRegExpLiteral` */ - assertRegexLiteral(props?: object | null): void; - assertRestElement(props?: object | null): void; + assertRegexLiteral(opts?: object): asserts this is NodePath; + assertRestElement(opts?: object): asserts this is NodePath; /** @deprecated Use `assertRestElement` */ - assertRestProperty(props?: object | null): void; - assertReturnStatement(props?: object | null): void; - assertScopable(props?: object | null): void; - assertSequenceExpression(props?: object | null): void; - assertSpreadElement(props?: object | null): void; + assertRestProperty(opts?: object): asserts this is NodePath; + assertReturnStatement(opts?: object): asserts this is NodePath; + assertScopable(opts?: object): asserts this is NodePath; + assertSequenceExpression(opts?: object): asserts this is NodePath; + assertSpreadElement(opts?: object): asserts this is NodePath; /** @deprecated Use `assertSpreadElement` */ - assertSpreadProperty(props?: object | null): void; - assertStatement(props?: object | null): void; - assertStringLiteral(props?: object | null): void; - assertStringLiteralTypeAnnotation(props?: object | null): void; - assertStringTypeAnnotation(props?: object | null): void; - assertSuper(props?: object | null): void; - assertSwitchCase(props?: object | null): void; - assertSwitchStatement(props?: object | null): void; - assertTSAnyKeyword(props?: object | null): void; - assertTSArrayType(props?: object | null): void; - assertTSAsExpression(props?: object | null): void; - assertTSBooleanKeyword(props?: object | null): void; - assertTSCallSignatureDeclaration(props?: object | null): void; - assertTSConditionalType(props?: object | null): void; - assertTSConstructSignatureDeclaration(props?: object | null): void; - assertTSConstructorType(props?: object | null): void; - assertTSDeclareFunction(props?: object | null): void; - assertTSDeclareMethod(props?: object | null): void; - assertTSEntityName(props?: object | null): void; - assertTSEnumDeclaration(props?: object | null): void; - assertTSEnumMember(props?: object | null): void; - assertTSExportAssignment(props?: object | null): void; - assertTSExpressionWithTypeArguments(props?: object | null): void; - assertTSExternalModuleReference(props?: object | null): void; - assertTSFunctionType(props?: object | null): void; - assertTSImportEqualsDeclaration(props?: object | null): void; - assertTSImportType(props?: object | null): void; - assertTSIndexSignature(props?: object | null): void; - assertTSIndexedAccessType(props?: object | null): void; - assertTSInferType(props?: object | null): void; - assertTSInterfaceBody(props?: object | null): void; - assertTSInterfaceDeclaration(props?: object | null): void; - assertTSIntersectionType(props?: object | null): void; - assertTSLiteralType(props?: object | null): void; - assertTSMappedType(props?: object | null): void; - assertTSMethodSignature(props?: object | null): void; - assertTSModuleBlock(props?: object | null): void; - assertTSModuleDeclaration(props?: object | null): void; - assertTSNamespaceExportDeclaration(props?: object | null): void; - assertTSNeverKeyword(props?: object | null): void; - assertTSNonNullExpression(props?: object | null): void; - assertTSNullKeyword(props?: object | null): void; - assertTSNumberKeyword(props?: object | null): void; - assertTSObjectKeyword(props?: object | null): void; - assertTSOptionalType(props?: object | null): void; - assertTSParameterProperty(props?: object | null): void; - assertTSParenthesizedType(props?: object | null): void; - assertTSPropertySignature(props?: object | null): void; - assertTSQualifiedName(props?: object | null): void; - assertTSRestType(props?: object | null): void; - assertTSStringKeyword(props?: object | null): void; - assertTSSymbolKeyword(props?: object | null): void; - assertTSThisType(props?: object | null): void; - assertTSTupleType(props?: object | null): void; - assertTSType(props?: object | null): void; - assertTSTypeAliasDeclaration(props?: object | null): void; - assertTSTypeAnnotation(props?: object | null): void; - assertTSTypeAssertion(props?: object | null): void; - assertTSTypeElement(props?: object | null): void; - assertTSTypeLiteral(props?: object | null): void; - assertTSTypeOperator(props?: object | null): void; - assertTSTypeParameter(props?: object | null): void; - assertTSTypeParameterDeclaration(props?: object | null): void; - assertTSTypeParameterInstantiation(props?: object | null): void; - assertTSTypePredicate(props?: object | null): void; - assertTSTypeQuery(props?: object | null): void; - assertTSTypeReference(props?: object | null): void; - assertTSUndefinedKeyword(props?: object | null): void; - assertTSUnionType(props?: object | null): void; - assertTSUnknownKeyword(props?: object | null): void; - assertTSVoidKeyword(props?: object | null): void; - assertTaggedTemplateExpression(props?: object | null): void; - assertTemplateElement(props?: object | null): void; - assertTemplateLiteral(props?: object | null): void; - assertTerminatorless(props?: object | null): void; - assertThisExpression(props?: object | null): void; - assertThisTypeAnnotation(props?: object | null): void; - assertThrowStatement(props?: object | null): void; - assertTryStatement(props?: object | null): void; - assertTupleTypeAnnotation(props?: object | null): void; - assertTypeAlias(props?: object | null): void; - assertTypeAnnotation(props?: object | null): void; - assertTypeCastExpression(props?: object | null): void; - assertTypeParameter(props?: object | null): void; - assertTypeParameterDeclaration(props?: object | null): void; - assertTypeParameterInstantiation(props?: object | null): void; - assertTypeofTypeAnnotation(props?: object | null): void; - assertUnaryExpression(props?: object | null): void; - assertUnaryLike(props?: object | null): void; - assertUnionTypeAnnotation(props?: object | null): void; - assertUpdateExpression(props?: object | null): void; - assertUserWhitespacable(props?: object | null): void; - assertVariableDeclaration(props?: object | null): void; - assertVariableDeclarator(props?: object | null): void; - assertVariance(props?: object | null): void; - assertVoidTypeAnnotation(props?: object | null): void; - assertWhile(props?: object | null): void; - assertWhileStatement(props?: object | null): void; - assertWithStatement(props?: object | null): void; - assertYieldExpression(props?: object | null): void; - - assertBindingIdentifier(props?: object | null): void; - assertBlockScoped(props?: object | null): void; - assertGenerated(props?: object | null): void; - assertPure(props?: object | null): void; - assertReferenced(props?: object | null): void; - assertReferencedIdentifier(props?: object | null): void; - assertReferencedMemberExpression(props?: object | null): void; - assertScope(props?: object | null): void; - assertUser(props?: object | null): void; - assertVar(props?: object | null): void; + assertSpreadProperty(opts?: object): asserts this is NodePath; + assertStandardized(opts?: object): asserts this is NodePath; + assertStatement(opts?: object): asserts this is NodePath; + assertStaticBlock(opts?: object): asserts this is NodePath; + assertStringLiteral(opts?: object): asserts this is NodePath; + assertStringLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertStringTypeAnnotation(opts?: object): asserts this is NodePath; + assertSuper(opts?: object): asserts this is NodePath; + assertSwitchCase(opts?: object): asserts this is NodePath; + assertSwitchStatement(opts?: object): asserts this is NodePath; + assertSymbolTypeAnnotation(opts?: object): asserts this is NodePath; + assertTSAnyKeyword(opts?: object): asserts this is NodePath; + assertTSArrayType(opts?: object): asserts this is NodePath; + assertTSAsExpression(opts?: object): asserts this is NodePath; + assertTSBaseType(opts?: object): asserts this is NodePath; + assertTSBigIntKeyword(opts?: object): asserts this is NodePath; + assertTSBooleanKeyword(opts?: object): asserts this is NodePath; + assertTSCallSignatureDeclaration(opts?: object): asserts this is NodePath; + assertTSConditionalType(opts?: object): asserts this is NodePath; + assertTSConstructSignatureDeclaration(opts?: object): asserts this is NodePath; + assertTSConstructorType(opts?: object): asserts this is NodePath; + assertTSDeclareFunction(opts?: object): asserts this is NodePath; + assertTSDeclareMethod(opts?: object): asserts this is NodePath; + assertTSEntityName(opts?: object): asserts this is NodePath; + assertTSEnumDeclaration(opts?: object): asserts this is NodePath; + assertTSEnumMember(opts?: object): asserts this is NodePath; + assertTSExportAssignment(opts?: object): asserts this is NodePath; + assertTSExpressionWithTypeArguments(opts?: object): asserts this is NodePath; + assertTSExternalModuleReference(opts?: object): asserts this is NodePath; + assertTSFunctionType(opts?: object): asserts this is NodePath; + assertTSImportEqualsDeclaration(opts?: object): asserts this is NodePath; + assertTSImportType(opts?: object): asserts this is NodePath; + assertTSIndexSignature(opts?: object): asserts this is NodePath; + assertTSIndexedAccessType(opts?: object): asserts this is NodePath; + assertTSInferType(opts?: object): asserts this is NodePath; + assertTSInstantiationExpression(opts?: object): asserts this is NodePath; + assertTSInterfaceBody(opts?: object): asserts this is NodePath; + assertTSInterfaceDeclaration(opts?: object): asserts this is NodePath; + assertTSIntersectionType(opts?: object): asserts this is NodePath; + assertTSIntrinsicKeyword(opts?: object): asserts this is NodePath; + assertTSLiteralType(opts?: object): asserts this is NodePath; + assertTSMappedType(opts?: object): asserts this is NodePath; + assertTSMethodSignature(opts?: object): asserts this is NodePath; + assertTSModuleBlock(opts?: object): asserts this is NodePath; + assertTSModuleDeclaration(opts?: object): asserts this is NodePath; + assertTSNamedTupleMember(opts?: object): asserts this is NodePath; + assertTSNamespaceExportDeclaration(opts?: object): asserts this is NodePath; + assertTSNeverKeyword(opts?: object): asserts this is NodePath; + assertTSNonNullExpression(opts?: object): asserts this is NodePath; + assertTSNullKeyword(opts?: object): asserts this is NodePath; + assertTSNumberKeyword(opts?: object): asserts this is NodePath; + assertTSObjectKeyword(opts?: object): asserts this is NodePath; + assertTSOptionalType(opts?: object): asserts this is NodePath; + assertTSParameterProperty(opts?: object): asserts this is NodePath; + assertTSParenthesizedType(opts?: object): asserts this is NodePath; + assertTSPropertySignature(opts?: object): asserts this is NodePath; + assertTSQualifiedName(opts?: object): asserts this is NodePath; + assertTSRestType(opts?: object): asserts this is NodePath; + assertTSSatisfiesExpression(opts?: object): asserts this is NodePath; + assertTSStringKeyword(opts?: object): asserts this is NodePath; + assertTSSymbolKeyword(opts?: object): asserts this is NodePath; + assertTSThisType(opts?: object): asserts this is NodePath; + assertTSTupleType(opts?: object): asserts this is NodePath; + assertTSType(opts?: object): asserts this is NodePath; + assertTSTypeAliasDeclaration(opts?: object): asserts this is NodePath; + assertTSTypeAnnotation(opts?: object): asserts this is NodePath; + assertTSTypeAssertion(opts?: object): asserts this is NodePath; + assertTSTypeElement(opts?: object): asserts this is NodePath; + assertTSTypeLiteral(opts?: object): asserts this is NodePath; + assertTSTypeOperator(opts?: object): asserts this is NodePath; + assertTSTypeParameter(opts?: object): asserts this is NodePath; + assertTSTypeParameterDeclaration(opts?: object): asserts this is NodePath; + assertTSTypeParameterInstantiation(opts?: object): asserts this is NodePath; + assertTSTypePredicate(opts?: object): asserts this is NodePath; + assertTSTypeQuery(opts?: object): asserts this is NodePath; + assertTSTypeReference(opts?: object): asserts this is NodePath; + assertTSUndefinedKeyword(opts?: object): asserts this is NodePath; + assertTSUnionType(opts?: object): asserts this is NodePath; + assertTSUnknownKeyword(opts?: object): asserts this is NodePath; + assertTSVoidKeyword(opts?: object): asserts this is NodePath; + assertTaggedTemplateExpression(opts?: object): asserts this is NodePath; + assertTemplateElement(opts?: object): asserts this is NodePath; + assertTemplateLiteral(opts?: object): asserts this is NodePath; + assertTerminatorless(opts?: object): asserts this is NodePath; + assertThisExpression(opts?: object): asserts this is NodePath; + assertThisTypeAnnotation(opts?: object): asserts this is NodePath; + assertThrowStatement(opts?: object): asserts this is NodePath; + assertTopicReference(opts?: object): asserts this is NodePath; + assertTryStatement(opts?: object): asserts this is NodePath; + assertTupleExpression(opts?: object): asserts this is NodePath; + assertTupleTypeAnnotation(opts?: object): asserts this is NodePath; + assertTypeAlias(opts?: object): asserts this is NodePath; + assertTypeAnnotation(opts?: object): asserts this is NodePath; + assertTypeCastExpression(opts?: object): asserts this is NodePath; + assertTypeParameter(opts?: object): asserts this is NodePath; + assertTypeParameterDeclaration(opts?: object): asserts this is NodePath; + assertTypeParameterInstantiation(opts?: object): asserts this is NodePath; + assertTypeScript(opts?: object): asserts this is NodePath; + assertTypeofTypeAnnotation(opts?: object): asserts this is NodePath; + assertUnaryExpression(opts?: object): asserts this is NodePath; + assertUnaryLike(opts?: object): asserts this is NodePath; + assertUnionTypeAnnotation(opts?: object): asserts this is NodePath; + assertUpdateExpression(opts?: object): asserts this is NodePath; + assertUserWhitespacable(opts?: object): asserts this is NodePath; + assertV8IntrinsicIdentifier(opts?: object): asserts this is NodePath; + assertVariableDeclaration(opts?: object): asserts this is NodePath; + assertVariableDeclarator(opts?: object): asserts this is NodePath; + assertVariance(opts?: object): asserts this is NodePath; + assertVoidTypeAnnotation(opts?: object): asserts this is NodePath; + assertWhile(opts?: object): asserts this is NodePath; + assertWhileStatement(opts?: object): asserts this is NodePath; + assertWithStatement(opts?: object): asserts this is NodePath; + assertYieldExpression(opts?: object): asserts this is NodePath; //#endregion } @@ -1176,7 +1439,7 @@ export interface HubInterface { getCode(): string | undefined; getScope(): Scope | undefined; addHelper(name: string): any; - buildError(node: Node, msg: string, Error: new (message?: string) => E): E; + buildError(node: Node, msg: string, Error: ErrorConstructor): Error; } export class Hub implements HubInterface { @@ -1184,16 +1447,35 @@ export class Hub implements HubInterface { getCode(): string | undefined; getScope(): Scope | undefined; addHelper(name: string): any; - buildError(node: Node, msg: string, Constructor: new (message?: string) => E): E; + buildError(node: Node, msg: string, Error?: ErrorConstructor): Error; } -export interface TraversalContext { +export interface TraversalContext { parentPath: NodePath; scope: Scope; - state: any; - opts: any; + state: S; + opts: TraverseOptions; } export type NodePathResult = | (Extract extends never ? never : NodePath>) | (T extends Array ? Array> : never); + +export interface VirtualTypeAliases { + BindingIdentifier: t.Identifier; + BlockScoped: Node; + ExistentialTypeParam: t.ExistsTypeAnnotation; + Flow: t.Flow | t.ImportDeclaration | t.ExportDeclaration | t.ImportSpecifier; + ForAwaitStatement: t.ForOfStatement; + Generated: Node; + NumericLiteralTypeAnnotation: t.NumberLiteralTypeAnnotation; + Pure: Node; + Referenced: Node; + ReferencedIdentifier: t.Identifier | t.JSXIdentifier; + ReferencedMemberExpression: t.MemberExpression; + RestProperty: t.RestElement; + Scope: t.Scopable | t.Pattern; + SpreadProperty: t.RestElement; + User: Node; + Var: t.VariableDeclaration; +} diff --git a/types/babel__traverse/package.json b/types/babel__traverse/package.json index 47a2d3dc48..881c7e6d0b 100644 --- a/types/babel__traverse/package.json +++ b/types/babel__traverse/package.json @@ -1,6 +1,10 @@ { "private": true, "dependencies": { - "@babel/types": "^7.3.0" + "@babel/types": "^7.20.7" + }, + "types": "index", + "typesVersions": { + "<=4.3": { "*": ["ts4.3/*"] } } } diff --git a/types/babel__traverse/ts4.3/babel__traverse-tests.ts b/types/babel__traverse/ts4.3/babel__traverse-tests.ts new file mode 100644 index 0000000000..ae9ad2ecdd --- /dev/null +++ b/types/babel__traverse/ts4.3/babel__traverse-tests.ts @@ -0,0 +1,466 @@ +import traverse, { Binding, Hub, NodePath, TraverseOptions, Visitor, visitors } from '@babel/traverse'; +import * as t from '@babel/types'; + +// Examples from: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md +const MyVisitor: Visitor = { + Identifier: { + enter(path) { + path.type; // $ExpectType "Identifier" + const x: NodePath = path; + console.log('Entered!'); + }, + exit(path) { + path.type; // $ExpectType "Identifier" + const x: NodePath = path; + console.log('Exited!'); + }, + }, +}; + +const MyVisitor2: Visitor = { + Identifier(path) { + path.type; // $ExpectType "Identifier" + path.parentPath; // $ExpectType NodePath + console.log('Visiting: ' + path.node.name); + }, + ArrayExpression(path) { + path.get('elements'); // $ExpectType NodePath[] + }, + Program(path) { + path.parentPath; // $ExpectType null + }, +}; + +// Example from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-traverse +declare const ast: t.Node; + +traverse(ast, { + enter(path) { + let actualType = path.type; + const expectedType: t.Node['type'] = actualType; + actualType = ast.type; + + const node = path.node; + if (t.isIdentifier(node) && node.name === 'n') { + node.name = 'x'; + } + }, +}); + +// Examples from https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#writing-your-first-babel-plugin + +const v1: Visitor = { + BinaryExpression(path) { + path.type; // $ExpectType "BinaryExpression" + + if (t.isIdentifier(path.node.left)) { + // ... + } + // $ExpectType [NodePath] + path.replaceWith(t.binaryExpression('**', path.node.left, t.numericLiteral(2))); + path.parentPath.replaceWith( + t.expressionStatement(t.stringLiteral("Anyway the wind blows, doesn't really matter to me, to me.")), + ); + // $ExpectType [NodePath] + path.replaceInline(t.binaryExpression('**', path.node.left, t.numericLiteral(2))); + // $ExpectType [NodePath] + path.replaceWithSourceString('3 * 4') as [NodePath]; + // $ExpectType [NodePath, NodePath] + path.replaceInline([ + t.binaryExpression('**', path.node.left, t.numericLiteral(2)), + t.expressionStatement(t.stringLiteral("Anyway the wind blows, doesn't really matter to me, to me.")), + ] as const); + path.parentPath.remove(); + }, + + Identifier(path) { + path.type; // $ExpectType "Identifier" + + if (path.isReferencedIdentifier()) { + // ... + } + if (t.isQualifiedTypeIdentifier(path.node, path.parent)) { + // ... + } + }, + + ReturnStatement(path) { + path.type; // $ExpectType "ReturnStatement" + + // $ExpectType [NodePath, NodePath, NodePath] + path.replaceWithMultiple([ + t.expressionStatement(t.stringLiteral('Is this the real life?')), + t.expressionStatement(t.stringLiteral('Is this just fantasy?')), + t.expressionStatement(t.stringLiteral('(Enjoy singing the rest of the song in your head)')), + ] as const); + }, + + FunctionDeclaration(path, state) { + path.type; // $ExpectType "FunctionDeclaration" + + path.replaceWithSourceString(`function add(a, b) { + return a + b; + }`); + + // $ExpectType [NodePath] + path.get('body').unshiftContainer('body', t.expressionStatement(t.stringLiteral('Start of function'))); + // $ExpectType [NodePath] + path.get('body').pushContainer('body', t.expressionStatement(t.stringLiteral('End of function'))); + + // $ExpectType [NodePath] + path.insertBefore(t.expressionStatement(t.stringLiteral("Because I'm easy come, easy go."))); + // $ExpectType [NodePath] + path.insertAfter(t.expressionStatement(t.stringLiteral('A little high, little low.'))); + path.remove(); + + if (path.scope.hasBinding('n')) { + // ... + } + if (path.scope.hasOwnBinding('n')) { + // ... + } + + const id1 = path.scope.generateUidIdentifier('uid'); + id1.type; + id1.name; + const id2 = path.scope.generateUidIdentifier('uid'); + id2.type; + id2.name; + + const id = path.scope.generateUidIdentifierBasedOnNode(path.node.id!); + path.remove(); + path.scope.parent.push({ id }); + path.scope.parent.push({ id, init: t.stringLiteral('foo'), kind: 'const' }); + + path.scope.rename('n', 'x'); + path.scope.rename('n'); + + path.scope.crawl(); + + // @ts-expect-error + path.pushContainer('returnType', t.stringLiteral('hello')); + // @ts-expect-error + path.unshiftContainer('returnType', t.stringLiteral('hello')); + }, + ExportDefaultDeclaration(path) { + path.type; // $ExpectType "ExportDefaultDeclaration" + + { + const [stringPath, booleanPath] = path.replaceWithMultiple([ + t.stringLiteral('hello'), + t.booleanLiteral(false), + ]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [stringPath, booleanPath] = path.replaceWithMultiple<[t.StringLiteral, t.BooleanLiteral]>([ + t.stringLiteral('hello'), + t.booleanLiteral(false), + ]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [newPath] = path.insertBefore(t.stringLiteral('hello')); + // $ExpectType NodePath + newPath; + } + { + const [newPath] = path.insertAfter(t.stringLiteral('hello')); + // $ExpectType NodePath + newPath; + } + }, + SequenceExpression(path) { + path.type; // $ExpectType "SequenceExpression" + + { + const [newPath] = path.unshiftContainer('expressions', t.stringLiteral('hello')); + // $ExpectType NodePath + newPath; + } + { + const [newPath] = path.pushContainer('expressions', t.stringLiteral('hello')); + // $ExpectType NodePath + newPath; + } + { + const [stringPath, booleanPath] = path.unshiftContainer('expressions', [ + t.stringLiteral('hello'), + t.booleanLiteral(false), + ]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [stringPath, booleanPath] = path.pushContainer('expressions', [ + t.stringLiteral('hello'), + t.booleanLiteral(false), + ]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [stringPath, booleanPath] = path.unshiftContainer< + t.SequenceExpression, + 'expressions', + [t.StringLiteral, t.BooleanLiteral] + >('expressions', [t.stringLiteral('hello'), t.booleanLiteral(false)]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + { + const [stringPath, booleanPath] = path.pushContainer< + t.SequenceExpression, + 'expressions', + [t.StringLiteral, t.BooleanLiteral] + >('expressions', [t.stringLiteral('hello'), t.booleanLiteral(false)]); + // $ExpectType NodePath + stringPath; + // $ExpectType NodePath + booleanPath; + } + }, +}; + +// Binding.kind +const BindingKindTest: Visitor = { + Identifier(path) { + path.type; // $ExpectType "Identifier" + + const kind = path.scope.getBinding('str')!.kind; + kind === 'module'; + kind === 'const'; + kind === 'let'; + kind === 'var'; + // @ts-expect-error + kind === 'anythingElse'; + }, +}; + +interface SomeVisitorState { + someState: string; +} + +const VisitorStateTest: TraverseOptions = { + enter(path, state) { + let actualType = path.type; + const expectedType: t.Node['type'] = actualType; + actualType = ast.type; + + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + exit(path, state) { + let actualType = path.type; + const expectedType: t.Node['type'] = actualType; + actualType = ast.type; + + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + Identifier(path, state) { + path.type; // $ExpectType "Identifier" + + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + FunctionDeclaration: { + enter(path, state) { + path.type; // $ExpectType "FunctionDeclaration" + + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + exit(path, state) { + path.type; // $ExpectType "FunctionDeclaration" + + // $ExpectType SomeVisitorState + state; + // $ExpectType SomeVisitorState + this; + }, + }, +}; + +traverse(ast, VisitorStateTest, undefined, { someState: 'test' }); + +const VisitorAliasTest: Visitor = { + Function() {}, + Expression() {}, +}; + +const hub = new Hub(); +// $ExpectType string | undefined +hub.getCode(); + +declare const astExpression: t.Expression; + +traverse.visitors; // $ExpectType typeof visitors + +// $ExpectType Visitor +visitors.merge([ + { + Expression(path) { + let actualType = path.type; + const expectedType: t.Expression['type'] = actualType; + actualType = astExpression.type; + }, + }, + { + Expression(path) { + let actualType = path.type; + const expectedType: t.Expression['type'] = actualType; + actualType = astExpression.type; + }, + }, +]); + +function testNullishPath( + optionalPath: NodePath, + nullPath: NodePath, + undefinedPath: NodePath, + unknownPath: NodePath, +) { + nullPath.type; // $ExpectType undefined + undefinedPath.type; // $ExpectType undefined + unknownPath.type; // $ExpectAssignable t.Node['type'] | undefined + + let actualType = optionalPath.type; + const expectedType: t.Node['type'] | undefined = actualType; + actualType = expectedType; +} + +function testEnsureBlock(path: NodePath) { + path.ensureBlock(); + path.node.body; // $ExpectType BlockStatement +} + +const optionsWithDenylist: TraverseOptions = { + denylist: ['TypeAnnotation'], +}; + +const optionsWithInvalidDenylist: TraverseOptions = { + // @ts-expect-error + denylist: ['SomeRandomType'], +}; + +const objectTypeAnnotation: NodePath = new NodePath( + null as any, + {} as any, +); + +objectTypeAnnotation.get('indexers'); // $ExpectType NodePathResult + +// Test that NodePath can be narrowed from union to single type +const path: NodePath = new NodePath( + null as any, + {} as any, +); + +if (path.isExportNamedDeclaration()) { + path.type; // $ExpectType "ExportNamedDeclaration" +} + +const nullPath: NodePath = new NodePath(null as any, {} as any); + +nullPath.type; // $ExpectType "Identifier" | undefined + +if (nullPath.hasNode()) { + nullPath.type; // $ExpectType "Identifier" +} + +const file: t.File = {} as any; +const newPath = NodePath.get({ + hub: {} as any, + parentPath: null, + parent: file, + container: file, + key: 'program', +}).setContext(); + +newPath; // $ExpectType NodePath + +const program: t.Program = {} as any; +// $ExpectType NodePath +NodePath.get({ + hub: {} as any, + parentPath: null, + parent: program, + container: program, + listKey: 'body', + key: 0, +}); + +const binding = new Binding({ + identifier: {} as any, + scope: {} as any, + path: {} as any, + kind: 'unknown', +}); + +binding.setValue('value'); +binding.deopValue(); +binding.clearValue(); + +binding.reassign(newPath.get('body')[0]); +binding.reference(newPath.get('body')[0]); +binding.dereference(); + +newPath.scope.checkBlockScopedCollisions(binding, 'local', 'name', {}); + +const booleanVar: boolean = true as boolean; +const identifier = newPath.getBindingIdentifiers(); +identifier; // $ExpectType Record +const identifierFalse = newPath.getBindingIdentifiers(false); +identifierFalse; // $ExpectType Record +const identifierTrue = newPath.getBindingIdentifiers(true); +identifierTrue; // $ExpectType Record +const identifierBoolean = newPath.getBindingIdentifiers(booleanVar); +identifierBoolean; // $ExpectType Record + +const outerIdentifier = newPath.getOuterBindingIdentifiers(); +outerIdentifier; // $ExpectType Record +const outerIdentifierFalse = newPath.getOuterBindingIdentifiers(false); +outerIdentifierFalse; // $ExpectType Record +const outerIdentifierTrue = newPath.getOuterBindingIdentifiers(true); +outerIdentifierTrue; // $ExpectType Record +const outerIdentifierBoolean = newPath.getOuterBindingIdentifiers(booleanVar); +outerIdentifierBoolean; // $ExpectType Record + +const identifierPath = newPath.getBindingIdentifierPaths(); +identifierPath; // $ExpectType Record> +const identifierPathFalse = newPath.getBindingIdentifierPaths(false); +identifierPathFalse; // $ExpectType Record> +const identifierPathTrue = newPath.getBindingIdentifierPaths(true); +identifierPathTrue; // $ExpectType Record[]> +const identifierPathBoolean = newPath.getBindingIdentifierPaths(booleanVar); +identifierPathBoolean; // $ExpectType Record | NodePath[]> + +const outerIdentifierPath = newPath.getOuterBindingIdentifierPaths(); +outerIdentifierPath; // $ExpectType Record> +const outerIdentifierPathFalse = newPath.getOuterBindingIdentifierPaths(false); +outerIdentifierPathFalse; // $ExpectType Record> +const outerIdentifierPathTrue = newPath.getOuterBindingIdentifierPaths(true); +outerIdentifierPathTrue; // $ExpectType Record[]> +const outerIdentifierPathBoolean = newPath.getOuterBindingIdentifierPaths(booleanVar); +outerIdentifierPathBoolean; // $ExpectType Record | NodePath[]> diff --git a/types/babel__traverse/ts4.3/index.d.ts b/types/babel__traverse/ts4.3/index.d.ts new file mode 100644 index 0000000000..35dd4cc0d4 --- /dev/null +++ b/types/babel__traverse/ts4.3/index.d.ts @@ -0,0 +1,1464 @@ +import * as t from '@babel/types'; +export import Node = t.Node; +export import RemovePropertiesOptions = t.RemovePropertiesOptions; + +declare const traverse: { + (parent: Node, opts: TraverseOptions, scope: Scope | undefined, state: S, parentPath?: NodePath): void; + (parent: Node, opts?: TraverseOptions, scope?: Scope, state?: any, parentPath?: NodePath): void; + + visitors: typeof visitors; + verify: typeof visitors.verify; + explode: typeof visitors.explode; + + cheap: (node: Node, enter: (node: Node) => void) => void; + node: ( + node: Node, + opts: TraverseOptions, + scope?: Scope, + state?: any, + path?: NodePath, + skipKeys?: Record, + ) => void; + clearNode: (node: Node, opts?: RemovePropertiesOptions) => void; + removeProperties: (tree: Node, opts?: RemovePropertiesOptions) => Node; + hasType: (tree: Node, type: Node['type'], denylistTypes?: string[]) => boolean; + + cache: typeof cache; +}; + +export namespace visitors { + /** + * `explode()` will take a `Visitor` object with all of the various shorthands + * that we support, and validates & normalizes it into a common format, ready + * to be used in traversal. + * + * The various shorthands are: + * - `Identifier() { ... }` -> `Identifier: { enter() { ... } }` + * - `"Identifier|NumericLiteral": { ... }` -> `Identifier: { ... }, NumericLiteral: { ... }` + * - Aliases in `@babel/types`: e.g. `Property: { ... }` -> `ObjectProperty: { ... }, ClassProperty: { ... }` + * + * Other normalizations are: + * - Visitors of virtual types are wrapped, so that they are only visited when their dynamic check passes + * - `enter` and `exit` functions are wrapped in arrays, to ease merging of visitors + */ + function explode( + visitor: Visitor, + ): { + [Type in Exclude['type']]?: VisitNodeObject>; + }; + function verify(visitor: Visitor): void; + function merge(visitors: Array>): Visitor; + function merge( + visitors: Visitor[], + states?: any[], + wrapper?: ( + stateKey: any, + visitorKey: keyof Visitor, + func: VisitNodeFunction, + ) => VisitNodeFunction | null, + ): Visitor; +} + +export namespace cache { + let path: WeakMap>; + let scope: WeakMap; + function clear(): void; + function clearPath(): void; + function clearScope(): void; +} + +export default traverse; + +export type TraverseOptions = { + scope?: Scope; + noScope?: boolean; + denylist?: NodeType[]; + /** @deprecated will be removed in Babel 8 */ + blacklist?: NodeType[]; + shouldSkip?: (node: NodePath) => boolean; +} & Visitor; + +export class Scope { + /** + * This searches the current "scope" and collects all references/bindings + * within. + */ + constructor(path: NodePath, parentScope?: Scope); + uid: number; + path: NodePath; + block: Node; + labels: Map>; + parentBlock: Node; + parent: Scope; + hub: HubInterface; + bindings: { [name: string]: Binding }; + references: { [name: string]: true }; + globals: { [name: string]: t.Identifier | t.JSXIdentifier }; + uids: { [name: string]: boolean }; + data: Record; + crawling: boolean; + + static globals: string[]; + /** Variables available in current context. */ + static contextVariables: string[]; + + /** Traverse node with current scope and path. */ + traverse(node: Node | Node[], opts: TraverseOptions, 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: Binding, kind: BindingKind, name: string, id: object): void; + + rename(oldName: string, newName?: string, block?: Node): void; + + dump(): void; + + toArray( + node: t.Node, + i?: number | boolean, + arrayLikeIsIterable?: boolean, + ): t.ArrayExpression | t.CallExpression | t.Identifier; + + hasLabel(name: string): boolean; + + getLabel(name: string): NodePath | undefined; + + registerLabel(path: NodePath): void; + + registerDeclaration(path: NodePath): void; + + buildUndefinedNode(): t.UnaryExpression; + + registerConstantViolation(path: NodePath): void; + + registerBinding(kind: BindingKind, path: NodePath, bindingPath?: NodePath): void; + + addGlobal(node: t.Identifier | t.JSXIdentifier): void; + + hasUid(name: string): boolean; + + hasGlobal(name: string): boolean; + + hasReference(name: string): boolean; + + isPure(node: Node, constantsOnly?: boolean): boolean; + + /** + * Set some arbitrary data on the current scope. + */ + setData(key: string, val: any): any; + + /** + * Recursively walk up scope tree looking for the data `key`. + */ + getData(key: string): any; + + /** + * Recursively walk up scope tree looking for the data `key` and if it exists, + * remove it. + */ + removeData(key: string): void; + + crawl(): void; + + push(opts: { + id: t.LVal; + init?: t.Expression; + unique?: boolean; + _blockHoist?: number | undefined; + kind?: 'var' | 'let' | 'const'; + }): void; + + /** Walk up to the top of the scope tree and get the `Program`. */ + getProgramParent(): Scope; + + /** Walk up the scope tree until we hit either a Function or return null. */ + getFunctionParent(): Scope | null; + + /** + * Walk up the scope tree until we hit either a BlockStatement/Loop/Program/Function/Switch or reach the + * very top and hit Program. + */ + getBlockParent(): Scope; + + /** + * Walk up from a pattern scope (function param initializer) until we hit a non-pattern scope, + * then returns its block parent + * @returns An ancestry scope whose path is a block parent + */ + getPatternParent(): Scope; + + /** Walks the scope tree and gathers **all** bindings. */ + getAllBindings(): Record; + + /** Walks the scope tree and gathers all declarations of `kind`. */ + getAllBindingsOfKind(...kinds: string[]): Record; + + 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, + optsOrNoGlobals?: + | boolean + | { + noGlobals?: boolean; + noUids?: boolean; + }, + ): boolean; + + parentHasBinding( + name: string, + opts?: { + noGlobals?: boolean; + noUids?: 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 type BindingKind = 'var' | 'let' | 'const' | 'module' | 'hoisted' | 'param' | 'local' | 'unknown'; + +/** + * This class is responsible for a binding inside of a scope. + * + * It tracks the following: + * + * * Node path. + * * Amount of times referenced by other nodes. + * * Paths to nodes that reassign or modify this binding. + * * The kind of binding. (Is it a parameter, declaration etc) + */ +export class Binding { + constructor(opts: { identifier: t.Identifier; scope: Scope; path: NodePath; kind: BindingKind }); + identifier: t.Identifier; + scope: Scope; + path: NodePath; + kind: BindingKind; + referenced: boolean; + references: number; + referencePaths: NodePath[]; + constant: boolean; + constantViolations: NodePath[]; + hasDeoptedValue: boolean; + hasValue: boolean; + value: any; + + deopValue(): void; + setValue(value: any): void; + clearValue(): void; + + /** Register a constant violation with the provided `path`. */ + reassign(path: NodePath): void; + /** Increment the amount of references to this binding. */ + reference(path: NodePath): void; + /** Decrement the amount of references to this binding. */ + dereference(): void; +} + +export type Visitor = VisitNodeObject & { + [Type in Node['type']]?: VisitNode>; +} & { + [K in keyof t.Aliases]?: VisitNode; +} & { + [K in keyof VirtualTypeAliases]?: VisitNode; +}; + +export type VisitNode = VisitNodeFunction | VisitNodeObject; + +export type VisitNodeFunction = (this: S, path: NodePath

, state: S) => void; + +type NodeType = Node['type'] | keyof t.Aliases; + +export interface VisitNodeObject { + enter?: VisitNodeFunction; + exit?: VisitNodeFunction; +} + +export type NodeKeyOfArrays = { + [P in keyof T]-?: T[P] extends Array ? P : never; +}[keyof T]; + +export type NodeKeyOfNodes = { + [P in keyof T]-?: T[P] extends Node | null | undefined ? P : never; +}[keyof T]; + +export type NodePaths = T extends readonly Node[] + ? { -readonly [K in keyof T]: NodePath> } + : T extends Node + ? [NodePath] + : never; + +type NodeListType = N[K] extends Array ? (P extends Node ? P : never) : never; + +type NodesInsertionParam = T | readonly T[] | [T, ...T[]]; + +export class NodePath { + constructor(hub: HubInterface, parent: Node); + parent: Node; + hub: Hub; + data: Record; + context: TraversalContext; + scope: Scope; + contexts: TraversalContext[]; + state: any; + opts: any; // exploded TraverseOptions + skipKeys: Record | null; + parentPath: T extends t.Program ? null : NodePath; + container: Node | Node[] | null; + listKey: string | null; + key: string | number | null; + node: T; + type: T extends Node ? T['type'] : T extends null | undefined ? undefined : Node['type'] | undefined; + shouldSkip: boolean; + shouldStop: boolean; + removed: boolean; + inList: boolean; + parentKey: string; + typeAnnotation: object; + + static get(opts: { + hub?: HubInterface; + parentPath: NodePath | null; + parent: Node; + container: C; + key: K; + }): NodePath; + static get>(opts: { + hub?: HubInterface; + parentPath: NodePath | null; + parent: Node; + container: C; + listKey: L; + key: number; + }): C[L] extends Array ? NodePath : never; + + getScope(scope: Scope): Scope; + + setData(key: string | symbol, val: any): any; + + getData(key: string | symbol, def?: any): any; + + hasNode(): this is NodePath>; + + buildCodeFrameError(msg: string, Error?: ErrorConstructor): Error; + + traverse(visitor: Visitor, state: T): void; + traverse(visitor: Visitor): void; + + set(key: string, node: any): void; + + getPathLocation(): string; + + // Example: https://github.com/babel/babel/blob/63204ae51e020d84a5b246312f5eeb4d981ab952/packages/babel-traverse/src/path/modification.js#L83 + debug(buildMessage: () => string): void; + + //#region ------------------------- ancestry ------------------------- + /** + * Starting at the parent path of the current `NodePath` and going up the + * tree, return the first `NodePath` that causes the provided `callback` + * to return a truthy value, or `null` if the `callback` never returns a + * truthy value. + */ + findParent(callback: (path: NodePath) => boolean): NodePath | null; + + /** + * Starting at current `NodePath` and going up the tree, return the first + * `NodePath` that causes the provided `callback` to return a truthy value, + * or `null` if the `callback` never returns a truthy value. + */ + find(callback: (path: NodePath) => boolean): NodePath | null; + + /** Get the parent function of the current path. */ + getFunctionParent(): NodePath | null; + + /** Walk up the tree until we hit a parent node path in a list. */ + getStatementParent(): NodePath | null; + + /** + * 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(): [this, ...NodePath[]]; + + /** + * A helper to find if `this` path is an ancestor of `maybeDescendant` + */ + isAncestor(maybeDescendant: NodePath): boolean; + + /** + * A helper to find if `this` path is a descendant of `maybeAncestor` + */ + isDescendant(maybeAncestor: NodePath): boolean; + + inType(...candidateTypes: string[]): boolean; + //#endregion + + //#region ------------------------- inference ------------------------- + /** Infer the type of the current `NodePath`. */ + getTypeAnnotation(): t.FlowType | t.TSType; + + isBaseType(baseName: string, soft?: boolean): boolean; + + couldBeBaseType(name: string): boolean; + + baseTypeStrictlyMatches(rightArg: NodePath): boolean; + + isGenericType(genericName: string): boolean; + //#endregion + + //#region ------------------------- 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: Nodes): NodePaths; + + /** + * 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: string): [NodePath]; + + /** Replace the current node with another. */ + replaceWith(replacementPath: R | NodePath): [NodePath]; + replaceWith(replacementPath: R): [R]; + + /** + * 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: t.Statement[]): NodePaths; + + replaceInline(nodes: Nodes): NodePaths; + //#endregion + + //#region ------------------------- 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 | undefined; + + /** + * Walk the input `node` and statically evaluate it. + * + * Returns an object in the form `{ confident, value, deopt }`. `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, in which case `deopt` is the path of said node. + * + * 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, deopt: NodePath } + * + */ + evaluate(): { + confident: boolean; + value: any; + deopt?: NodePath; + }; + //#endregion + + //#region ------------------------- 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; + // has(key: keyof T): boolean; + + isStatic(): boolean; + + /** Alias of `has`. */ + is(key: string): boolean; + // is(key: keyof T): boolean; + + /** Opposite of `has`. */ + isnt(key: string): boolean; + // isnt(key: keyof T): boolean; + + /** Check whether the path node `key` strict equals `value`. */ + equals(key: string, value: any): boolean; + // equals(key: keyof T, 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(target: NodePath): boolean; + + resolve(dangerous?: boolean, resolved?: NodePath[]): NodePath; + + isConstantExpression(): boolean; + + isInStrictMode(): boolean; + //#endregion + + //#region ------------------------- context ------------------------- + call(key: string): boolean; + + isDenylisted(): boolean; + + /** @deprecated will be removed in Babel 8 */ + isBlacklisted(): boolean; + + visit(): boolean; + + skip(): void; + + skipKey(key: string): void; + + stop(): void; + + setScope(): void; + + setContext(context?: TraversalContext): this; + + /** + * Here we resync the node paths `key` and `container`. If they've changed according + * to what we have stored internally then we attempt to resync by crawling and looking + * for the new values. + */ + resync(): void; + + popContext(): void; + + pushContext(context: TraversalContext): void; + + requeue(pathToQueue?: NodePath): void; + //#endregion + + //#region ------------------------- removal ------------------------- + remove(): void; + //#endregion + + //#region ------------------------- conversion ------------------------- + toComputedKey(): t.PrivateName | t.Expression; + + /** @deprecated Use `arrowFunctionToExpression` */ + arrowFunctionToShadowed(): void; + + /** + * Given an arbitrary function, process its content as if it were an arrow function, moving references + * to "this", "arguments", "super", and such into the function's parent scope. This method is useful if + * you have wrapped some set of items in an IIFE or other function, but want "this", "arguments", and super" + * to continue behaving as expected. + */ + unwrapFunctionEnvironment(): void; + + /** + * Convert a given arrow function into a normal ES5 function expression. + */ + arrowFunctionToExpression({ + allowInsertArrow, + allowInsertArrowWithRest, + /** @deprecated Use `noNewArrows` instead */ + specCompliant, + noNewArrows, + }?: { + allowInsertArrow?: boolean; + allowInsertArrowWithRest?: boolean; + specCompliant?: boolean; + noNewArrows?: boolean; + }): NodePath | t.CallExpression>; + + ensureBlock( + this: NodePath, + ): asserts this is NodePath< + T & { + body: t.BlockStatement; + } + >; + //#endregion + + //#region ------------------------- modification ------------------------- + /** Insert the provided nodes before the current one. */ + insertBefore>(nodes: Nodes): NodePaths; + + /** + * 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: Nodes): NodePaths; + + /** Update all sibling node paths after `fromIndex` by `incrementBy`. */ + updateSiblingKeys(fromIndex: number, incrementBy: number): void; + + /** + * Insert child nodes at the start of the current node. + * @param listKey - The key at which the child nodes are stored (usually body). + * @param nodes - the nodes to insert. + */ + unshiftContainer< + T extends Node, + K extends NodeKeyOfArrays, + Nodes extends NodesInsertionParam>, + >(this: NodePath, listKey: K, nodes: Nodes): NodePaths; + + /** + * Insert child nodes at the end of the current node. + * @param listKey - The key at which the child nodes are stored (usually body). + * @param nodes - the nodes to insert. + */ + pushContainer, Nodes extends NodesInsertionParam>>( + this: NodePath, + listKey: K, + nodes: Nodes, + ): NodePaths; + + /** Hoist the current node to the highest scope possible and return a UID referencing it. */ + hoist(scope: Scope): void; + //#endregion + + //#region ------------------------- family ------------------------- + getOpposite(): NodePath | null; + + getCompletionRecords(): NodePath[]; + + getSibling(key: string | number): NodePath; + getPrevSibling(): NodePath; + getNextSibling(): NodePath; + getAllPrevSiblings(): NodePath[]; + getAllNextSiblings(): NodePath[]; + + get(key: K, context?: boolean | TraversalContext): NodePathResult; + get(key: string, context?: boolean | TraversalContext): NodePath | NodePath[]; + + getBindingIdentifiers(duplicates: true): Record; + getBindingIdentifiers(duplicates?: false): Record; + getBindingIdentifiers(duplicates?: boolean): Record; + + getOuterBindingIdentifiers(duplicates: true): Record; + getOuterBindingIdentifiers(duplicates?: false): Record; + getOuterBindingIdentifiers(duplicates?: boolean): Record; + + getBindingIdentifierPaths(duplicates: true, outerOnly?: boolean): Record>>; + getBindingIdentifierPaths(duplicates?: false, outerOnly?: boolean): Record>; + getBindingIdentifierPaths( + duplicates?: boolean, + outerOnly?: boolean, + ): Record | Array>>; + + getOuterBindingIdentifierPaths(duplicates: true): Record>>; + getOuterBindingIdentifierPaths(duplicates?: false): Record>; + getOuterBindingIdentifierPaths( + duplicates?: boolean, + outerOnly?: boolean, + ): Record | Array>>; + //#endregion + + //#region ------------------------- comments ------------------------- + /** Share comments amongst siblings. */ + shareCommentsWithSiblings(): void; + + addComment(type: t.CommentTypeShorthand, content: string, line?: boolean): void; + + /** Give node `comments` of the specified `type`. */ + addComments(type: t.CommentTypeShorthand, comments: t.Comment[]): void; + //#endregion + + //#region ------------------------- isXXX ------------------------- + isAccessor(opts?: object): this is NodePath; + isAnyTypeAnnotation(opts?: object): this is NodePath; + isArgumentPlaceholder(opts?: object): this is NodePath; + isArrayExpression(opts?: object): this is NodePath; + isArrayPattern(opts?: object): this is NodePath; + isArrayTypeAnnotation(opts?: object): this is NodePath; + isArrowFunctionExpression(opts?: object): this is NodePath; + isAssignmentExpression(opts?: object): this is NodePath; + isAssignmentPattern(opts?: object): this is NodePath; + isAwaitExpression(opts?: object): this is NodePath; + isBigIntLiteral(opts?: object): this is NodePath; + isBinary(opts?: object): this is NodePath; + isBinaryExpression(opts?: object): this is NodePath; + isBindExpression(opts?: object): this is NodePath; + isBlock(opts?: object): this is NodePath; + isBlockParent(opts?: object): this is NodePath; + isBlockStatement(opts?: object): this is NodePath; + isBooleanLiteral(opts?: object): this is NodePath; + isBooleanLiteralTypeAnnotation(opts?: object): this is NodePath; + isBooleanTypeAnnotation(opts?: object): this is NodePath; + isBreakStatement(opts?: object): this is NodePath; + isCallExpression(opts?: object): this is NodePath; + isCatchClause(opts?: object): this is NodePath; + isClass(opts?: object): this is NodePath; + isClassAccessorProperty(opts?: object): this is NodePath; + isClassBody(opts?: object): this is NodePath; + isClassDeclaration(opts?: object): this is NodePath; + isClassExpression(opts?: object): this is NodePath; + isClassImplements(opts?: object): this is NodePath; + isClassMethod(opts?: object): this is NodePath; + isClassPrivateMethod(opts?: object): this is NodePath; + isClassPrivateProperty(opts?: object): this is NodePath; + isClassProperty(opts?: object): this is NodePath; + isCompletionStatement(opts?: object): this is NodePath; + isConditional(opts?: object): this is NodePath; + isConditionalExpression(opts?: object): this is NodePath; + isContinueStatement(opts?: object): this is NodePath; + isDebuggerStatement(opts?: object): this is NodePath; + isDecimalLiteral(opts?: object): this is NodePath; + isDeclaration(opts?: object): this is NodePath; + isDeclareClass(opts?: object): this is NodePath; + isDeclareExportAllDeclaration(opts?: object): this is NodePath; + isDeclareExportDeclaration(opts?: object): this is NodePath; + isDeclareFunction(opts?: object): this is NodePath; + isDeclareInterface(opts?: object): this is NodePath; + isDeclareModule(opts?: object): this is NodePath; + isDeclareModuleExports(opts?: object): this is NodePath; + isDeclareOpaqueType(opts?: object): this is NodePath; + isDeclareTypeAlias(opts?: object): this is NodePath; + isDeclareVariable(opts?: object): this is NodePath; + isDeclaredPredicate(opts?: object): this is NodePath; + isDecorator(opts?: object): this is NodePath; + isDirective(opts?: object): this is NodePath; + isDirectiveLiteral(opts?: object): this is NodePath; + isDoExpression(opts?: object): this is NodePath; + isDoWhileStatement(opts?: object): this is NodePath; + isEmptyStatement(opts?: object): this is NodePath; + isEmptyTypeAnnotation(opts?: object): this is NodePath; + isEnumBody(opts?: object): this is NodePath; + isEnumBooleanBody(opts?: object): this is NodePath; + isEnumBooleanMember(opts?: object): this is NodePath; + isEnumDeclaration(opts?: object): this is NodePath; + isEnumDefaultedMember(opts?: object): this is NodePath; + isEnumMember(opts?: object): this is NodePath; + isEnumNumberBody(opts?: object): this is NodePath; + isEnumNumberMember(opts?: object): this is NodePath; + isEnumStringBody(opts?: object): this is NodePath; + isEnumStringMember(opts?: object): this is NodePath; + isEnumSymbolBody(opts?: object): this is NodePath; + isExistsTypeAnnotation(opts?: object): this is NodePath; + isExportAllDeclaration(opts?: object): this is NodePath; + isExportDeclaration(opts?: object): this is NodePath; + isExportDefaultDeclaration(opts?: object): this is NodePath; + isExportDefaultSpecifier(opts?: object): this is NodePath; + isExportNamedDeclaration(opts?: object): this is NodePath; + isExportNamespaceSpecifier(opts?: object): this is NodePath; + isExportSpecifier(opts?: object): this is NodePath; + isExpression(opts?: object): this is NodePath; + isExpressionStatement(opts?: object): this is NodePath; + isExpressionWrapper(opts?: object): this is NodePath; + isFile(opts?: object): this is NodePath; + isFlow(opts?: object): this is NodePath; + isFlowBaseAnnotation(opts?: object): this is NodePath; + isFlowDeclaration(opts?: object): this is NodePath; + isFlowPredicate(opts?: object): this is NodePath; + isFlowType(opts?: object): this is NodePath; + isFor(opts?: object): this is NodePath; + isForInStatement(opts?: object): this is NodePath; + isForOfStatement(opts?: object): this is NodePath; + isForStatement(opts?: object): this is NodePath; + isForXStatement(opts?: object): this is NodePath; + isFunction(opts?: object): this is NodePath; + isFunctionDeclaration(opts?: object): this is NodePath; + isFunctionExpression(opts?: object): this is NodePath; + isFunctionParent(opts?: object): this is NodePath; + isFunctionTypeAnnotation(opts?: object): this is NodePath; + isFunctionTypeParam(opts?: object): this is NodePath; + isGenericTypeAnnotation(opts?: object): this is NodePath; + isIdentifier(opts?: object): this is NodePath; + isIfStatement(opts?: object): this is NodePath; + isImmutable(opts?: object): this is NodePath; + isImport(opts?: object): this is NodePath; + isImportAttribute(opts?: object): this is NodePath; + isImportDeclaration(opts?: object): this is NodePath; + isImportDefaultSpecifier(opts?: object): this is NodePath; + isImportNamespaceSpecifier(opts?: object): this is NodePath; + isImportSpecifier(opts?: object): this is NodePath; + isIndexedAccessType(opts?: object): this is NodePath; + isInferredPredicate(opts?: object): this is NodePath; + isInterfaceDeclaration(opts?: object): this is NodePath; + isInterfaceExtends(opts?: object): this is NodePath; + isInterfaceTypeAnnotation(opts?: object): this is NodePath; + isInterpreterDirective(opts?: object): this is NodePath; + isIntersectionTypeAnnotation(opts?: object): this is NodePath; + isJSX(opts?: object): this is NodePath; + isJSXAttribute(opts?: object): this is NodePath; + isJSXClosingElement(opts?: object): this is NodePath; + isJSXClosingFragment(opts?: object): this is NodePath; + isJSXElement(opts?: object): this is NodePath; + isJSXEmptyExpression(opts?: object): this is NodePath; + isJSXExpressionContainer(opts?: object): this is NodePath; + isJSXFragment(opts?: object): this is NodePath; + isJSXIdentifier(opts?: object): this is NodePath; + isJSXMemberExpression(opts?: object): this is NodePath; + isJSXNamespacedName(opts?: object): this is NodePath; + isJSXOpeningElement(opts?: object): this is NodePath; + isJSXOpeningFragment(opts?: object): this is NodePath; + isJSXSpreadAttribute(opts?: object): this is NodePath; + isJSXSpreadChild(opts?: object): this is NodePath; + isJSXText(opts?: object): this is NodePath; + isLVal(opts?: object): this is NodePath; + isLabeledStatement(opts?: object): this is NodePath; + isLiteral(opts?: object): this is NodePath; + isLogicalExpression(opts?: object): this is NodePath; + isLoop(opts?: object): this is NodePath; + isMemberExpression(opts?: object): this is NodePath; + isMetaProperty(opts?: object): this is NodePath; + isMethod(opts?: object): this is NodePath; + isMiscellaneous(opts?: object): this is NodePath; + isMixedTypeAnnotation(opts?: object): this is NodePath; + isModuleDeclaration(opts?: object): this is NodePath; + isModuleExpression(opts?: object): this is NodePath; + isModuleSpecifier(opts?: object): this is NodePath; + isNewExpression(opts?: object): this is NodePath; + isNoop(opts?: object): this is NodePath; + isNullLiteral(opts?: object): this is NodePath; + isNullLiteralTypeAnnotation(opts?: object): this is NodePath; + isNullableTypeAnnotation(opts?: object): this is NodePath; + + /** @deprecated Use `isNumericLiteral` */ + isNumberLiteral(opts?: object): this is NodePath; + isNumberLiteralTypeAnnotation(opts?: object): this is NodePath; + isNumberTypeAnnotation(opts?: object): this is NodePath; + isNumericLiteral(opts?: object): this is NodePath; + isObjectExpression(opts?: object): this is NodePath; + isObjectMember(opts?: object): this is NodePath; + isObjectMethod(opts?: object): this is NodePath; + isObjectPattern(opts?: object): this is NodePath; + isObjectProperty(opts?: object): this is NodePath; + isObjectTypeAnnotation(opts?: object): this is NodePath; + isObjectTypeCallProperty(opts?: object): this is NodePath; + isObjectTypeIndexer(opts?: object): this is NodePath; + isObjectTypeInternalSlot(opts?: object): this is NodePath; + isObjectTypeProperty(opts?: object): this is NodePath; + isObjectTypeSpreadProperty(opts?: object): this is NodePath; + isOpaqueType(opts?: object): this is NodePath; + isOptionalCallExpression(opts?: object): this is NodePath; + isOptionalIndexedAccessType(opts?: object): this is NodePath; + isOptionalMemberExpression(opts?: object): this is NodePath; + isParenthesizedExpression(opts?: object): this is NodePath; + isPattern(opts?: object): this is NodePath; + isPatternLike(opts?: object): this is NodePath; + isPipelineBareFunction(opts?: object): this is NodePath; + isPipelinePrimaryTopicReference(opts?: object): this is NodePath; + isPipelineTopicExpression(opts?: object): this is NodePath; + isPlaceholder(opts?: object): this is NodePath; + isPrivate(opts?: object): this is NodePath; + isPrivateName(opts?: object): this is NodePath; + isProgram(opts?: object): this is NodePath; + isProperty(opts?: object): this is NodePath; + isPureish(opts?: object): this is NodePath; + isQualifiedTypeIdentifier(opts?: object): this is NodePath; + isRecordExpression(opts?: object): this is NodePath; + isRegExpLiteral(opts?: object): this is NodePath; + + /** @deprecated Use `isRegExpLiteral` */ + isRegexLiteral(opts?: object): this is NodePath; + isRestElement(opts?: object): this is NodePath; + + /** @deprecated Use `isRestElement` */ + isRestProperty(opts?: object): this is NodePath; + isReturnStatement(opts?: object): this is NodePath; + isScopable(opts?: object): this is NodePath; + isSequenceExpression(opts?: object): this is NodePath; + isSpreadElement(opts?: object): this is NodePath; + + /** @deprecated Use `isSpreadElement` */ + isSpreadProperty(opts?: object): this is NodePath; + isStandardized(opts?: object): this is NodePath; + isStatement(opts?: object): this is NodePath; + isStaticBlock(opts?: object): this is NodePath; + isStringLiteral(opts?: object): this is NodePath; + isStringLiteralTypeAnnotation(opts?: object): this is NodePath; + isStringTypeAnnotation(opts?: object): this is NodePath; + isSuper(opts?: object): this is NodePath; + isSwitchCase(opts?: object): this is NodePath; + isSwitchStatement(opts?: object): this is NodePath; + isSymbolTypeAnnotation(opts?: object): this is NodePath; + isTSAnyKeyword(opts?: object): this is NodePath; + isTSArrayType(opts?: object): this is NodePath; + isTSAsExpression(opts?: object): this is NodePath; + isTSBaseType(opts?: object): this is NodePath; + isTSBigIntKeyword(opts?: object): this is NodePath; + isTSBooleanKeyword(opts?: object): this is NodePath; + isTSCallSignatureDeclaration(opts?: object): this is NodePath; + isTSConditionalType(opts?: object): this is NodePath; + isTSConstructSignatureDeclaration(opts?: object): this is NodePath; + isTSConstructorType(opts?: object): this is NodePath; + isTSDeclareFunction(opts?: object): this is NodePath; + isTSDeclareMethod(opts?: object): this is NodePath; + isTSEntityName(opts?: object): this is NodePath; + isTSEnumDeclaration(opts?: object): this is NodePath; + isTSEnumMember(opts?: object): this is NodePath; + isTSExportAssignment(opts?: object): this is NodePath; + isTSExpressionWithTypeArguments(opts?: object): this is NodePath; + isTSExternalModuleReference(opts?: object): this is NodePath; + isTSFunctionType(opts?: object): this is NodePath; + isTSImportEqualsDeclaration(opts?: object): this is NodePath; + isTSImportType(opts?: object): this is NodePath; + isTSIndexSignature(opts?: object): this is NodePath; + isTSIndexedAccessType(opts?: object): this is NodePath; + isTSInferType(opts?: object): this is NodePath; + isTSInstantiationExpression(opts?: object): this is NodePath; + isTSInterfaceBody(opts?: object): this is NodePath; + isTSInterfaceDeclaration(opts?: object): this is NodePath; + isTSIntersectionType(opts?: object): this is NodePath; + isTSIntrinsicKeyword(opts?: object): this is NodePath; + isTSLiteralType(opts?: object): this is NodePath; + isTSMappedType(opts?: object): this is NodePath; + isTSMethodSignature(opts?: object): this is NodePath; + isTSModuleBlock(opts?: object): this is NodePath; + isTSModuleDeclaration(opts?: object): this is NodePath; + isTSNamedTupleMember(opts?: object): this is NodePath; + isTSNamespaceExportDeclaration(opts?: object): this is NodePath; + isTSNeverKeyword(opts?: object): this is NodePath; + isTSNonNullExpression(opts?: object): this is NodePath; + isTSNullKeyword(opts?: object): this is NodePath; + isTSNumberKeyword(opts?: object): this is NodePath; + isTSObjectKeyword(opts?: object): this is NodePath; + isTSOptionalType(opts?: object): this is NodePath; + isTSParameterProperty(opts?: object): this is NodePath; + isTSParenthesizedType(opts?: object): this is NodePath; + isTSPropertySignature(opts?: object): this is NodePath; + isTSQualifiedName(opts?: object): this is NodePath; + isTSRestType(opts?: object): this is NodePath; + isTSSatisfiesExpression(opts?: object): this is NodePath; + isTSStringKeyword(opts?: object): this is NodePath; + isTSSymbolKeyword(opts?: object): this is NodePath; + isTSThisType(opts?: object): this is NodePath; + isTSTupleType(opts?: object): this is NodePath; + isTSType(opts?: object): this is NodePath; + isTSTypeAliasDeclaration(opts?: object): this is NodePath; + isTSTypeAnnotation(opts?: object): this is NodePath; + isTSTypeAssertion(opts?: object): this is NodePath; + isTSTypeElement(opts?: object): this is NodePath; + isTSTypeLiteral(opts?: object): this is NodePath; + isTSTypeOperator(opts?: object): this is NodePath; + isTSTypeParameter(opts?: object): this is NodePath; + isTSTypeParameterDeclaration(opts?: object): this is NodePath; + isTSTypeParameterInstantiation(opts?: object): this is NodePath; + isTSTypePredicate(opts?: object): this is NodePath; + isTSTypeQuery(opts?: object): this is NodePath; + isTSTypeReference(opts?: object): this is NodePath; + isTSUndefinedKeyword(opts?: object): this is NodePath; + isTSUnionType(opts?: object): this is NodePath; + isTSUnknownKeyword(opts?: object): this is NodePath; + isTSVoidKeyword(opts?: object): this is NodePath; + isTaggedTemplateExpression(opts?: object): this is NodePath; + isTemplateElement(opts?: object): this is NodePath; + isTemplateLiteral(opts?: object): this is NodePath; + isTerminatorless(opts?: object): this is NodePath; + isThisExpression(opts?: object): this is NodePath; + isThisTypeAnnotation(opts?: object): this is NodePath; + isThrowStatement(opts?: object): this is NodePath; + isTopicReference(opts?: object): this is NodePath; + isTryStatement(opts?: object): this is NodePath; + isTupleExpression(opts?: object): this is NodePath; + isTupleTypeAnnotation(opts?: object): this is NodePath; + isTypeAlias(opts?: object): this is NodePath; + isTypeAnnotation(opts?: object): this is NodePath; + isTypeCastExpression(opts?: object): this is NodePath; + isTypeParameter(opts?: object): this is NodePath; + isTypeParameterDeclaration(opts?: object): this is NodePath; + isTypeParameterInstantiation(opts?: object): this is NodePath; + isTypeScript(opts?: object): this is NodePath; + isTypeofTypeAnnotation(opts?: object): this is NodePath; + isUnaryExpression(opts?: object): this is NodePath; + isUnaryLike(opts?: object): this is NodePath; + isUnionTypeAnnotation(opts?: object): this is NodePath; + isUpdateExpression(opts?: object): this is NodePath; + isUserWhitespacable(opts?: object): this is NodePath; + isV8IntrinsicIdentifier(opts?: object): this is NodePath; + isVariableDeclaration(opts?: object): this is NodePath; + isVariableDeclarator(opts?: object): this is NodePath; + isVariance(opts?: object): this is NodePath; + isVoidTypeAnnotation(opts?: object): this is NodePath; + isWhile(opts?: object): this is NodePath; + isWhileStatement(opts?: object): this is NodePath; + isWithStatement(opts?: object): this is NodePath; + isYieldExpression(opts?: object): this is NodePath; + + isBindingIdentifier(opts?: object): this is NodePath; + isBlockScoped(opts?: object): this is NodePath; + + /** @deprecated */ + isExistentialTypeParam(opts?: object): this is NodePath; + isForAwaitStatement(opts?: object): this is NodePath; + isGenerated(opts?: object): boolean; + + /** @deprecated */ + isNumericLiteralTypeAnnotation(opts?: object): void; + isPure(opts?: object): boolean; + isReferenced(opts?: object): boolean; + isReferencedIdentifier(opts?: object): this is NodePath; + isReferencedMemberExpression(opts?: object): this is NodePath; + isScope(opts?: object): this is NodePath; + isUser(opts?: object): boolean; + isVar(opts?: object): this is NodePath; + //#endregion + + //#region ------------------------- assertXXX ------------------------- + assertAccessor(opts?: object): asserts this is NodePath; + assertAnyTypeAnnotation(opts?: object): asserts this is NodePath; + assertArgumentPlaceholder(opts?: object): asserts this is NodePath; + assertArrayExpression(opts?: object): asserts this is NodePath; + assertArrayPattern(opts?: object): asserts this is NodePath; + assertArrayTypeAnnotation(opts?: object): asserts this is NodePath; + assertArrowFunctionExpression(opts?: object): asserts this is NodePath; + assertAssignmentExpression(opts?: object): asserts this is NodePath; + assertAssignmentPattern(opts?: object): asserts this is NodePath; + assertAwaitExpression(opts?: object): asserts this is NodePath; + assertBigIntLiteral(opts?: object): asserts this is NodePath; + assertBinary(opts?: object): asserts this is NodePath; + assertBinaryExpression(opts?: object): asserts this is NodePath; + assertBindExpression(opts?: object): asserts this is NodePath; + assertBlock(opts?: object): asserts this is NodePath; + assertBlockParent(opts?: object): asserts this is NodePath; + assertBlockStatement(opts?: object): asserts this is NodePath; + assertBooleanLiteral(opts?: object): asserts this is NodePath; + assertBooleanLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertBooleanTypeAnnotation(opts?: object): asserts this is NodePath; + assertBreakStatement(opts?: object): asserts this is NodePath; + assertCallExpression(opts?: object): asserts this is NodePath; + assertCatchClause(opts?: object): asserts this is NodePath; + assertClass(opts?: object): asserts this is NodePath; + assertClassAccessorProperty(opts?: object): asserts this is NodePath; + assertClassBody(opts?: object): asserts this is NodePath; + assertClassDeclaration(opts?: object): asserts this is NodePath; + assertClassExpression(opts?: object): asserts this is NodePath; + assertClassImplements(opts?: object): asserts this is NodePath; + assertClassMethod(opts?: object): asserts this is NodePath; + assertClassPrivateMethod(opts?: object): asserts this is NodePath; + assertClassPrivateProperty(opts?: object): asserts this is NodePath; + assertClassProperty(opts?: object): asserts this is NodePath; + assertCompletionStatement(opts?: object): asserts this is NodePath; + assertConditional(opts?: object): asserts this is NodePath; + assertConditionalExpression(opts?: object): asserts this is NodePath; + assertContinueStatement(opts?: object): asserts this is NodePath; + assertDebuggerStatement(opts?: object): asserts this is NodePath; + assertDecimalLiteral(opts?: object): asserts this is NodePath; + assertDeclaration(opts?: object): asserts this is NodePath; + assertDeclareClass(opts?: object): asserts this is NodePath; + assertDeclareExportAllDeclaration(opts?: object): asserts this is NodePath; + assertDeclareExportDeclaration(opts?: object): asserts this is NodePath; + assertDeclareFunction(opts?: object): asserts this is NodePath; + assertDeclareInterface(opts?: object): asserts this is NodePath; + assertDeclareModule(opts?: object): asserts this is NodePath; + assertDeclareModuleExports(opts?: object): asserts this is NodePath; + assertDeclareOpaqueType(opts?: object): asserts this is NodePath; + assertDeclareTypeAlias(opts?: object): asserts this is NodePath; + assertDeclareVariable(opts?: object): asserts this is NodePath; + assertDeclaredPredicate(opts?: object): asserts this is NodePath; + assertDecorator(opts?: object): asserts this is NodePath; + assertDirective(opts?: object): asserts this is NodePath; + assertDirectiveLiteral(opts?: object): asserts this is NodePath; + assertDoExpression(opts?: object): asserts this is NodePath; + assertDoWhileStatement(opts?: object): asserts this is NodePath; + assertEmptyStatement(opts?: object): asserts this is NodePath; + assertEmptyTypeAnnotation(opts?: object): asserts this is NodePath; + assertEnumBody(opts?: object): asserts this is NodePath; + assertEnumBooleanBody(opts?: object): asserts this is NodePath; + assertEnumBooleanMember(opts?: object): asserts this is NodePath; + assertEnumDeclaration(opts?: object): asserts this is NodePath; + assertEnumDefaultedMember(opts?: object): asserts this is NodePath; + assertEnumMember(opts?: object): asserts this is NodePath; + assertEnumNumberBody(opts?: object): asserts this is NodePath; + assertEnumNumberMember(opts?: object): asserts this is NodePath; + assertEnumStringBody(opts?: object): asserts this is NodePath; + assertEnumStringMember(opts?: object): asserts this is NodePath; + assertEnumSymbolBody(opts?: object): asserts this is NodePath; + assertExistsTypeAnnotation(opts?: object): asserts this is NodePath; + assertExportAllDeclaration(opts?: object): asserts this is NodePath; + assertExportDeclaration(opts?: object): asserts this is NodePath; + assertExportDefaultDeclaration(opts?: object): asserts this is NodePath; + assertExportDefaultSpecifier(opts?: object): asserts this is NodePath; + assertExportNamedDeclaration(opts?: object): asserts this is NodePath; + assertExportNamespaceSpecifier(opts?: object): asserts this is NodePath; + assertExportSpecifier(opts?: object): asserts this is NodePath; + assertExpression(opts?: object): asserts this is NodePath; + assertExpressionStatement(opts?: object): asserts this is NodePath; + assertExpressionWrapper(opts?: object): asserts this is NodePath; + assertFile(opts?: object): asserts this is NodePath; + assertFlow(opts?: object): asserts this is NodePath; + assertFlowBaseAnnotation(opts?: object): asserts this is NodePath; + assertFlowDeclaration(opts?: object): asserts this is NodePath; + assertFlowPredicate(opts?: object): asserts this is NodePath; + assertFlowType(opts?: object): asserts this is NodePath; + assertFor(opts?: object): asserts this is NodePath; + assertForInStatement(opts?: object): asserts this is NodePath; + assertForOfStatement(opts?: object): asserts this is NodePath; + assertForStatement(opts?: object): asserts this is NodePath; + assertForXStatement(opts?: object): asserts this is NodePath; + assertFunction(opts?: object): asserts this is NodePath; + assertFunctionDeclaration(opts?: object): asserts this is NodePath; + assertFunctionExpression(opts?: object): asserts this is NodePath; + assertFunctionParent(opts?: object): asserts this is NodePath; + assertFunctionTypeAnnotation(opts?: object): asserts this is NodePath; + assertFunctionTypeParam(opts?: object): asserts this is NodePath; + assertGenericTypeAnnotation(opts?: object): asserts this is NodePath; + assertIdentifier(opts?: object): asserts this is NodePath; + assertIfStatement(opts?: object): asserts this is NodePath; + assertImmutable(opts?: object): asserts this is NodePath; + assertImport(opts?: object): asserts this is NodePath; + assertImportAttribute(opts?: object): asserts this is NodePath; + assertImportDeclaration(opts?: object): asserts this is NodePath; + assertImportDefaultSpecifier(opts?: object): asserts this is NodePath; + assertImportNamespaceSpecifier(opts?: object): asserts this is NodePath; + assertImportSpecifier(opts?: object): asserts this is NodePath; + assertIndexedAccessType(opts?: object): asserts this is NodePath; + assertInferredPredicate(opts?: object): asserts this is NodePath; + assertInterfaceDeclaration(opts?: object): asserts this is NodePath; + assertInterfaceExtends(opts?: object): asserts this is NodePath; + assertInterfaceTypeAnnotation(opts?: object): asserts this is NodePath; + assertInterpreterDirective(opts?: object): asserts this is NodePath; + assertIntersectionTypeAnnotation(opts?: object): asserts this is NodePath; + assertJSX(opts?: object): asserts this is NodePath; + assertJSXAttribute(opts?: object): asserts this is NodePath; + assertJSXClosingElement(opts?: object): asserts this is NodePath; + assertJSXClosingFragment(opts?: object): asserts this is NodePath; + assertJSXElement(opts?: object): asserts this is NodePath; + assertJSXEmptyExpression(opts?: object): asserts this is NodePath; + assertJSXExpressionContainer(opts?: object): asserts this is NodePath; + assertJSXFragment(opts?: object): asserts this is NodePath; + assertJSXIdentifier(opts?: object): asserts this is NodePath; + assertJSXMemberExpression(opts?: object): asserts this is NodePath; + assertJSXNamespacedName(opts?: object): asserts this is NodePath; + assertJSXOpeningElement(opts?: object): asserts this is NodePath; + assertJSXOpeningFragment(opts?: object): asserts this is NodePath; + assertJSXSpreadAttribute(opts?: object): asserts this is NodePath; + assertJSXSpreadChild(opts?: object): asserts this is NodePath; + assertJSXText(opts?: object): asserts this is NodePath; + assertLVal(opts?: object): asserts this is NodePath; + assertLabeledStatement(opts?: object): asserts this is NodePath; + assertLiteral(opts?: object): asserts this is NodePath; + assertLogicalExpression(opts?: object): asserts this is NodePath; + assertLoop(opts?: object): asserts this is NodePath; + assertMemberExpression(opts?: object): asserts this is NodePath; + assertMetaProperty(opts?: object): asserts this is NodePath; + assertMethod(opts?: object): asserts this is NodePath; + assertMiscellaneous(opts?: object): asserts this is NodePath; + assertMixedTypeAnnotation(opts?: object): asserts this is NodePath; + assertModuleDeclaration(opts?: object): asserts this is NodePath; + assertModuleExpression(opts?: object): asserts this is NodePath; + assertModuleSpecifier(opts?: object): asserts this is NodePath; + assertNewExpression(opts?: object): asserts this is NodePath; + assertNoop(opts?: object): asserts this is NodePath; + assertNullLiteral(opts?: object): asserts this is NodePath; + assertNullLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertNullableTypeAnnotation(opts?: object): asserts this is NodePath; + + /** @deprecated Use `assertNumericLiteral` */ + assertNumberLiteral(opts?: object): asserts this is NodePath; + assertNumberLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertNumberTypeAnnotation(opts?: object): asserts this is NodePath; + assertNumericLiteral(opts?: object): asserts this is NodePath; + assertObjectExpression(opts?: object): asserts this is NodePath; + assertObjectMember(opts?: object): asserts this is NodePath; + assertObjectMethod(opts?: object): asserts this is NodePath; + assertObjectPattern(opts?: object): asserts this is NodePath; + assertObjectProperty(opts?: object): asserts this is NodePath; + assertObjectTypeAnnotation(opts?: object): asserts this is NodePath; + assertObjectTypeCallProperty(opts?: object): asserts this is NodePath; + assertObjectTypeIndexer(opts?: object): asserts this is NodePath; + assertObjectTypeInternalSlot(opts?: object): asserts this is NodePath; + assertObjectTypeProperty(opts?: object): asserts this is NodePath; + assertObjectTypeSpreadProperty(opts?: object): asserts this is NodePath; + assertOpaqueType(opts?: object): asserts this is NodePath; + assertOptionalCallExpression(opts?: object): asserts this is NodePath; + assertOptionalIndexedAccessType(opts?: object): asserts this is NodePath; + assertOptionalMemberExpression(opts?: object): asserts this is NodePath; + assertParenthesizedExpression(opts?: object): asserts this is NodePath; + assertPattern(opts?: object): asserts this is NodePath; + assertPatternLike(opts?: object): asserts this is NodePath; + assertPipelineBareFunction(opts?: object): asserts this is NodePath; + assertPipelinePrimaryTopicReference(opts?: object): asserts this is NodePath; + assertPipelineTopicExpression(opts?: object): asserts this is NodePath; + assertPlaceholder(opts?: object): asserts this is NodePath; + assertPrivate(opts?: object): asserts this is NodePath; + assertPrivateName(opts?: object): asserts this is NodePath; + assertProgram(opts?: object): asserts this is NodePath; + assertProperty(opts?: object): asserts this is NodePath; + assertPureish(opts?: object): asserts this is NodePath; + assertQualifiedTypeIdentifier(opts?: object): asserts this is NodePath; + assertRecordExpression(opts?: object): asserts this is NodePath; + assertRegExpLiteral(opts?: object): asserts this is NodePath; + + /** @deprecated Use `assertRegExpLiteral` */ + assertRegexLiteral(opts?: object): asserts this is NodePath; + assertRestElement(opts?: object): asserts this is NodePath; + + /** @deprecated Use `assertRestElement` */ + assertRestProperty(opts?: object): asserts this is NodePath; + assertReturnStatement(opts?: object): asserts this is NodePath; + assertScopable(opts?: object): asserts this is NodePath; + assertSequenceExpression(opts?: object): asserts this is NodePath; + assertSpreadElement(opts?: object): asserts this is NodePath; + + /** @deprecated Use `assertSpreadElement` */ + assertSpreadProperty(opts?: object): asserts this is NodePath; + assertStandardized(opts?: object): asserts this is NodePath; + assertStatement(opts?: object): asserts this is NodePath; + assertStaticBlock(opts?: object): asserts this is NodePath; + assertStringLiteral(opts?: object): asserts this is NodePath; + assertStringLiteralTypeAnnotation(opts?: object): asserts this is NodePath; + assertStringTypeAnnotation(opts?: object): asserts this is NodePath; + assertSuper(opts?: object): asserts this is NodePath; + assertSwitchCase(opts?: object): asserts this is NodePath; + assertSwitchStatement(opts?: object): asserts this is NodePath; + assertSymbolTypeAnnotation(opts?: object): asserts this is NodePath; + assertTSAnyKeyword(opts?: object): asserts this is NodePath; + assertTSArrayType(opts?: object): asserts this is NodePath; + assertTSAsExpression(opts?: object): asserts this is NodePath; + assertTSBaseType(opts?: object): asserts this is NodePath; + assertTSBigIntKeyword(opts?: object): asserts this is NodePath; + assertTSBooleanKeyword(opts?: object): asserts this is NodePath; + assertTSCallSignatureDeclaration(opts?: object): asserts this is NodePath; + assertTSConditionalType(opts?: object): asserts this is NodePath; + assertTSConstructSignatureDeclaration(opts?: object): asserts this is NodePath; + assertTSConstructorType(opts?: object): asserts this is NodePath; + assertTSDeclareFunction(opts?: object): asserts this is NodePath; + assertTSDeclareMethod(opts?: object): asserts this is NodePath; + assertTSEntityName(opts?: object): asserts this is NodePath; + assertTSEnumDeclaration(opts?: object): asserts this is NodePath; + assertTSEnumMember(opts?: object): asserts this is NodePath; + assertTSExportAssignment(opts?: object): asserts this is NodePath; + assertTSExpressionWithTypeArguments(opts?: object): asserts this is NodePath; + assertTSExternalModuleReference(opts?: object): asserts this is NodePath; + assertTSFunctionType(opts?: object): asserts this is NodePath; + assertTSImportEqualsDeclaration(opts?: object): asserts this is NodePath; + assertTSImportType(opts?: object): asserts this is NodePath; + assertTSIndexSignature(opts?: object): asserts this is NodePath; + assertTSIndexedAccessType(opts?: object): asserts this is NodePath; + assertTSInferType(opts?: object): asserts this is NodePath; + assertTSInstantiationExpression(opts?: object): asserts this is NodePath; + assertTSInterfaceBody(opts?: object): asserts this is NodePath; + assertTSInterfaceDeclaration(opts?: object): asserts this is NodePath; + assertTSIntersectionType(opts?: object): asserts this is NodePath; + assertTSIntrinsicKeyword(opts?: object): asserts this is NodePath; + assertTSLiteralType(opts?: object): asserts this is NodePath; + assertTSMappedType(opts?: object): asserts this is NodePath; + assertTSMethodSignature(opts?: object): asserts this is NodePath; + assertTSModuleBlock(opts?: object): asserts this is NodePath; + assertTSModuleDeclaration(opts?: object): asserts this is NodePath; + assertTSNamedTupleMember(opts?: object): asserts this is NodePath; + assertTSNamespaceExportDeclaration(opts?: object): asserts this is NodePath; + assertTSNeverKeyword(opts?: object): asserts this is NodePath; + assertTSNonNullExpression(opts?: object): asserts this is NodePath; + assertTSNullKeyword(opts?: object): asserts this is NodePath; + assertTSNumberKeyword(opts?: object): asserts this is NodePath; + assertTSObjectKeyword(opts?: object): asserts this is NodePath; + assertTSOptionalType(opts?: object): asserts this is NodePath; + assertTSParameterProperty(opts?: object): asserts this is NodePath; + assertTSParenthesizedType(opts?: object): asserts this is NodePath; + assertTSPropertySignature(opts?: object): asserts this is NodePath; + assertTSQualifiedName(opts?: object): asserts this is NodePath; + assertTSRestType(opts?: object): asserts this is NodePath; + assertTSSatisfiesExpression(opts?: object): asserts this is NodePath; + assertTSStringKeyword(opts?: object): asserts this is NodePath; + assertTSSymbolKeyword(opts?: object): asserts this is NodePath; + assertTSThisType(opts?: object): asserts this is NodePath; + assertTSTupleType(opts?: object): asserts this is NodePath; + assertTSType(opts?: object): asserts this is NodePath; + assertTSTypeAliasDeclaration(opts?: object): asserts this is NodePath; + assertTSTypeAnnotation(opts?: object): asserts this is NodePath; + assertTSTypeAssertion(opts?: object): asserts this is NodePath; + assertTSTypeElement(opts?: object): asserts this is NodePath; + assertTSTypeLiteral(opts?: object): asserts this is NodePath; + assertTSTypeOperator(opts?: object): asserts this is NodePath; + assertTSTypeParameter(opts?: object): asserts this is NodePath; + assertTSTypeParameterDeclaration(opts?: object): asserts this is NodePath; + assertTSTypeParameterInstantiation(opts?: object): asserts this is NodePath; + assertTSTypePredicate(opts?: object): asserts this is NodePath; + assertTSTypeQuery(opts?: object): asserts this is NodePath; + assertTSTypeReference(opts?: object): asserts this is NodePath; + assertTSUndefinedKeyword(opts?: object): asserts this is NodePath; + assertTSUnionType(opts?: object): asserts this is NodePath; + assertTSUnknownKeyword(opts?: object): asserts this is NodePath; + assertTSVoidKeyword(opts?: object): asserts this is NodePath; + assertTaggedTemplateExpression(opts?: object): asserts this is NodePath; + assertTemplateElement(opts?: object): asserts this is NodePath; + assertTemplateLiteral(opts?: object): asserts this is NodePath; + assertTerminatorless(opts?: object): asserts this is NodePath; + assertThisExpression(opts?: object): asserts this is NodePath; + assertThisTypeAnnotation(opts?: object): asserts this is NodePath; + assertThrowStatement(opts?: object): asserts this is NodePath; + assertTopicReference(opts?: object): asserts this is NodePath; + assertTryStatement(opts?: object): asserts this is NodePath; + assertTupleExpression(opts?: object): asserts this is NodePath; + assertTupleTypeAnnotation(opts?: object): asserts this is NodePath; + assertTypeAlias(opts?: object): asserts this is NodePath; + assertTypeAnnotation(opts?: object): asserts this is NodePath; + assertTypeCastExpression(opts?: object): asserts this is NodePath; + assertTypeParameter(opts?: object): asserts this is NodePath; + assertTypeParameterDeclaration(opts?: object): asserts this is NodePath; + assertTypeParameterInstantiation(opts?: object): asserts this is NodePath; + assertTypeScript(opts?: object): asserts this is NodePath; + assertTypeofTypeAnnotation(opts?: object): asserts this is NodePath; + assertUnaryExpression(opts?: object): asserts this is NodePath; + assertUnaryLike(opts?: object): asserts this is NodePath; + assertUnionTypeAnnotation(opts?: object): asserts this is NodePath; + assertUpdateExpression(opts?: object): asserts this is NodePath; + assertUserWhitespacable(opts?: object): asserts this is NodePath; + assertV8IntrinsicIdentifier(opts?: object): asserts this is NodePath; + assertVariableDeclaration(opts?: object): asserts this is NodePath; + assertVariableDeclarator(opts?: object): asserts this is NodePath; + assertVariance(opts?: object): asserts this is NodePath; + assertVoidTypeAnnotation(opts?: object): asserts this is NodePath; + assertWhile(opts?: object): asserts this is NodePath; + assertWhileStatement(opts?: object): asserts this is NodePath; + assertWithStatement(opts?: object): asserts this is NodePath; + assertYieldExpression(opts?: object): asserts this is NodePath; + //#endregion +} + +export interface HubInterface { + getCode(): string | undefined; + getScope(): Scope | undefined; + addHelper(name: string): any; + buildError(node: Node, msg: string, Error: ErrorConstructor): Error; +} + +export class Hub implements HubInterface { + constructor(); + getCode(): string | undefined; + getScope(): Scope | undefined; + addHelper(name: string): any; + buildError(node: Node, msg: string, Error?: ErrorConstructor): Error; +} + +export interface TraversalContext { + parentPath: NodePath; + scope: Scope; + state: S; + opts: TraverseOptions; +} + +export type NodePathResult = + | (Extract extends never ? never : NodePath>) + | (T extends Array ? Array> : never); + +export interface VirtualTypeAliases { + BindingIdentifier: t.Identifier; + BlockScoped: Node; + ExistentialTypeParam: t.ExistsTypeAnnotation; + Flow: t.Flow | t.ImportDeclaration | t.ExportDeclaration | t.ImportSpecifier; + ForAwaitStatement: t.ForOfStatement; + Generated: Node; + NumericLiteralTypeAnnotation: t.NumberLiteralTypeAnnotation; + Pure: Node; + Referenced: Node; + ReferencedIdentifier: t.Identifier | t.JSXIdentifier; + ReferencedMemberExpression: t.MemberExpression; + RestProperty: t.RestElement; + Scope: t.Scopable | t.Pattern; + SpreadProperty: t.RestElement; + User: Node; + Var: t.VariableDeclaration; +} diff --git a/types/babel__traverse/ts4.3/tsconfig.json b/types/babel__traverse/ts4.3/tsconfig.json new file mode 100644 index 0000000000..66e32a81b7 --- /dev/null +++ b/types/babel__traverse/ts4.3/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@babel/*": [ + "babel__*" + ] + } + }, + "files": [ + "index.d.ts", + "babel__traverse-tests.ts" + ] +} diff --git a/types/babel__traverse/ts4.3/tslint.json b/types/babel__traverse/ts4.3/tslint.json new file mode 100644 index 0000000000..794cb4bf3e --- /dev/null +++ b/types/babel__traverse/ts4.3/tslint.json @@ -0,0 +1 @@ +{ "extends": "@definitelytyped/dtslint/dt.json" }