Skip to main content

@babel/types

This module contains methods for building ASTs manually and for checking the types of AST nodes.

Install

npm install --save-dev @babel/types

API

Node Builders

anyTypeAnnotation

JavaScript
t.anyTypeAnnotation();

See also t.isAnyTypeAnnotation(node, opts) and t.assertAnyTypeAnnotation(node, opts).

Aliases: Flow, FlowType, FlowBaseAnnotation


argumentPlaceholder

JavaScript
t.argumentPlaceholder();

See also t.isArgumentPlaceholder(node, opts) and t.assertArgumentPlaceholder(node, opts).


arrayExpression

JavaScript
t.arrayExpression(elements);

See also t.isArrayExpression(node, opts) and t.assertArrayExpression(node, opts).

AST Node ArrayExpression shape:

  • elements: (null | Expression | SpreadElement)[] (default: [])

Aliases: Standardized, Expression


arrayPattern

JavaScript
t.arrayPattern(elements);

See also t.isArrayPattern(node, opts) and t.assertArrayPattern(node, opts).

AST Node ArrayPattern shape:

  • elements: (null | PatternLike)[] (required)
  • decorators: Decorator[] (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)

Aliases: Standardized, FunctionParameter, Pattern, PatternLike, LVal


arrayTypeAnnotation

JavaScript
t.arrayTypeAnnotation(elementType);

See also t.isArrayTypeAnnotation(node, opts) and t.assertArrayTypeAnnotation(node, opts).

AST Node ArrayTypeAnnotation shape:

  • elementType: FlowType (required)

Aliases: Flow, FlowType


arrowFunctionExpression

JavaScript
t.arrowFunctionExpression(params, body, async);

See also t.isArrowFunctionExpression(node, opts) and t.assertArrowFunctionExpression(node, opts).

AST Node ArrowFunctionExpression shape:

  • params: FunctionParameter[] (required)
  • body: BlockStatement | Expression (required)
  • async: boolean (default: false)
  • expression: boolean (required)
  • generator: boolean (default: false, excluded from builder function)
  • predicate: DeclaredPredicate | InferredPredicate (default: null, excluded from builder function)
  • returnType: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Scopable, Function, BlockParent, FunctionParent, Expression, Pureish


assignmentExpression

JavaScript
t.assignmentExpression(operator, left, right);

See also t.isAssignmentExpression(node, opts) and t.assertAssignmentExpression(node, opts).

AST Node AssignmentExpression shape:

  • operator: string (required)
  • left: LVal | OptionalMemberExpression (required)
  • right: Expression (required)

Aliases: Standardized, Expression


assignmentPattern

JavaScript
t.assignmentPattern(left, right);

See also t.isAssignmentPattern(node, opts) and t.assertAssignmentPattern(node, opts).

AST Node AssignmentPattern shape:

  • left: Identifier | ObjectPattern | ArrayPattern | MemberExpression | TSAsExpression | TSSatisfiesExpression | TSTypeAssertion | TSNonNullExpression (required)
  • right: Expression (required)
  • decorators: Decorator[] (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)

Aliases: Standardized, FunctionParameter, Pattern, PatternLike, LVal


awaitExpression

JavaScript
t.awaitExpression(argument);

See also t.isAwaitExpression(node, opts) and t.assertAwaitExpression(node, opts).

AST Node AwaitExpression shape:

  • argument: Expression (required)

Aliases: Standardized, Expression, Terminatorless


bigIntLiteral

JavaScript
t.bigIntLiteral(value);

See also t.isBigIntLiteral(node, opts) and t.assertBigIntLiteral(node, opts).

AST Node BigIntLiteral shape:

  • value: string (required)

Aliases: Standardized, Expression, Pureish, Literal, Immutable


binaryExpression

JavaScript
t.binaryExpression(operator, left, right);

See also t.isBinaryExpression(node, opts) and t.assertBinaryExpression(node, opts).

AST Node BinaryExpression shape:

  • operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=" | "|>" (required)
  • left: Expression | PrivateName (required)
  • right: Expression (required)

Aliases: Standardized, Binary, Expression


bindExpression

JavaScript
t.bindExpression(object, callee);

See also t.isBindExpression(node, opts) and t.assertBindExpression(node, opts).

AST Node BindExpression shape:

  • object: Expression (required)
  • callee: Expression (required)

Aliases: Expression


blockStatement

JavaScript
t.blockStatement(body, directives);

See also t.isBlockStatement(node, opts) and t.assertBlockStatement(node, opts).

AST Node BlockStatement shape:

  • body: Statement[] (required)
  • directives: Directive[] (default: [])

Aliases: Standardized, Scopable, BlockParent, Block, Statement


booleanLiteral

JavaScript
t.booleanLiteral(value);

See also t.isBooleanLiteral(node, opts) and t.assertBooleanLiteral(node, opts).

AST Node BooleanLiteral shape:

  • value: boolean (required)

Aliases: Standardized, Expression, Pureish, Literal, Immutable


booleanLiteralTypeAnnotation

JavaScript
t.booleanLiteralTypeAnnotation(value);

See also t.isBooleanLiteralTypeAnnotation(node, opts) and t.assertBooleanLiteralTypeAnnotation(node, opts).

AST Node BooleanLiteralTypeAnnotation shape:

  • value: boolean (required)

Aliases: Flow, FlowType


booleanTypeAnnotation

JavaScript
t.booleanTypeAnnotation();

See also t.isBooleanTypeAnnotation(node, opts) and t.assertBooleanTypeAnnotation(node, opts).

Aliases: Flow, FlowType, FlowBaseAnnotation


breakStatement

JavaScript
t.breakStatement(label);

See also t.isBreakStatement(node, opts) and t.assertBreakStatement(node, opts).

AST Node BreakStatement shape:

  • label: Identifier (default: null)

Aliases: Standardized, Statement, Terminatorless, CompletionStatement


callExpression

JavaScript
t.callExpression(callee, arguments);

See also t.isCallExpression(node, opts) and t.assertCallExpression(node, opts).

AST Node CallExpression shape:

  • callee: Expression | Super | V8IntrinsicIdentifier (required)
  • arguments: (Expression | SpreadElement | ArgumentPlaceholder)[] (required)
  • optional: boolean (default: null, excluded from builder function)
  • typeArguments: TypeParameterInstantiation (default: null, excluded from builder function)
  • typeParameters: TSTypeParameterInstantiation (default: null, excluded from builder function)

Aliases: Standardized, Expression


catchClause

JavaScript
t.catchClause(param, body);

See also t.isCatchClause(node, opts) and t.assertCatchClause(node, opts).

AST Node CatchClause shape:

  • param: Identifier | ArrayPattern | ObjectPattern (default: null)
  • body: BlockStatement (required)

Aliases: Standardized, Scopable, BlockParent


classAccessorProperty

JavaScript
t.classAccessorProperty(key, value, typeAnnotation, decorators, computed, static);

See also t.isClassAccessorProperty(node, opts) and t.assertClassAccessorProperty(node, opts).

AST Node ClassAccessorProperty shape:

  • key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression | PrivateName (required)
  • value: Expression (default: null)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null)
  • decorators: Decorator[] (default: null)
  • computed: boolean (default: false)
  • static: boolean (default: false)
  • abstract: boolean (default: null, excluded from builder function)
  • accessibility: "public" | "private" | "protected" (default: null, excluded from builder function)
  • declare: boolean (default: null, excluded from builder function)
  • definite: boolean (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • override: boolean (default: false, excluded from builder function)
  • readonly: boolean (default: null, excluded from builder function)
  • variance: Variance (default: null, excluded from builder function)

Aliases: Standardized, Property, Accessor


classBody

JavaScript
t.classBody(body);

See also t.isClassBody(node, opts) and t.assertClassBody(node, opts).

AST Node ClassBody shape:

  • body: (ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | ClassAccessorProperty | TSDeclareMethod | TSIndexSignature | StaticBlock)[] (required)

Aliases: Standardized


classDeclaration

JavaScript
t.classDeclaration(id, superClass, body, decorators);

See also t.isClassDeclaration(node, opts) and t.assertClassDeclaration(node, opts).

AST Node ClassDeclaration shape:

  • id: Identifier (default: null)
  • superClass: Expression (default: null)
  • body: ClassBody (required)
  • decorators: Decorator[] (default: null)
  • abstract: boolean (default: null, excluded from builder function)
  • declare: boolean (default: null, excluded from builder function)
  • implements: (TSExpressionWithTypeArguments | ClassImplements)[] (default: null, excluded from builder function)
  • mixins: InterfaceExtends (default: null, excluded from builder function)
  • superTypeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Scopable, Class, Statement, Declaration


classExpression

JavaScript
t.classExpression(id, superClass, body, decorators);

See also t.isClassExpression(node, opts) and t.assertClassExpression(node, opts).

AST Node ClassExpression shape:

  • id: Identifier (default: null)
  • superClass: Expression (default: null)
  • body: ClassBody (required)
  • decorators: Decorator[] (default: null)
  • implements: (TSExpressionWithTypeArguments | ClassImplements)[] (default: null, excluded from builder function)
  • mixins: InterfaceExtends (default: null, excluded from builder function)
  • superTypeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Scopable, Class, Expression


classImplements

JavaScript
t.classImplements(id, typeParameters);

See also t.isClassImplements(node, opts) and t.assertClassImplements(node, opts).

AST Node ClassImplements shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterInstantiation (default: null)

Aliases: Flow


classMethod

JavaScript
t.classMethod(kind, key, params, body, computed, static, generator, async);

See also t.isClassMethod(node, opts) and t.assertClassMethod(node, opts).

AST Node ClassMethod shape:

  • kind: "get" | "set" | "method" | "constructor" (default: 'method')
  • key: if computed then Expression else Identifier | Literal (required)
  • params: (FunctionParameter | TSParameterProperty)[] (required)
  • body: BlockStatement (required)
  • computed: boolean (default: false)
  • static: boolean (default: false)
  • generator: boolean (default: false)
  • async: boolean (default: false)
  • abstract: boolean (default: null, excluded from builder function)
  • access: "public" | "private" | "protected" (default: null, excluded from builder function)
  • accessibility: "public" | "private" | "protected" (default: null, excluded from builder function)
  • decorators: Decorator[] (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • override: boolean (default: false, excluded from builder function)
  • returnType: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Function, Scopable, BlockParent, FunctionParent, Method


classPrivateMethod

JavaScript
t.classPrivateMethod(kind, key, params, body, static);

See also t.isClassPrivateMethod(node, opts) and t.assertClassPrivateMethod(node, opts).

AST Node ClassPrivateMethod shape:

  • kind: "get" | "set" | "method" (default: 'method')
  • key: PrivateName (required)
  • params: (FunctionParameter | TSParameterProperty)[] (required)
  • body: BlockStatement (required)
  • static: boolean (default: false)
  • abstract: boolean (default: null, excluded from builder function)
  • access: "public" | "private" | "protected" (default: null, excluded from builder function)
  • accessibility: "public" | "private" | "protected" (default: null, excluded from builder function)
  • async: boolean (default: false, excluded from builder function)
  • computed: 'false' (default: false, excluded from builder function)
  • decorators: Decorator[] (default: null, excluded from builder function)
  • generator: boolean (default: false, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • override: boolean (default: false, excluded from builder function)
  • returnType: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Function, Scopable, BlockParent, FunctionParent, Method, Private


classPrivateProperty

JavaScript
t.classPrivateProperty(key, value, decorators, static);

See also t.isClassPrivateProperty(node, opts) and t.assertClassPrivateProperty(node, opts).

AST Node ClassPrivateProperty shape:

  • key: PrivateName (required)
  • value: Expression (default: null)
  • decorators: Decorator[] (default: null)
  • static: boolean (default: false)
  • definite: boolean (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • readonly: boolean (default: null, excluded from builder function)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • variance: Variance (default: null, excluded from builder function)

Aliases: Standardized, Property, Private


classProperty

JavaScript
t.classProperty(key, value, typeAnnotation, decorators, computed, static);
History
VersionChanges
v7.6.0Supports static

See also t.isClassProperty(node, opts) and t.assertClassProperty(node, opts).

AST Node ClassProperty shape:

  • key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression (required)
  • value: Expression (default: null)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null)
  • decorators: Decorator[] (default: null)
  • computed: boolean (default: false)
  • static: boolean (default: false)
  • abstract: boolean (default: null, excluded from builder function)
  • accessibility: "public" | "private" | "protected" (default: null, excluded from builder function)
  • declare: boolean (default: null, excluded from builder function)
  • definite: boolean (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • override: boolean (default: false, excluded from builder function)
  • readonly: boolean (default: null, excluded from builder function)
  • variance: Variance (default: null, excluded from builder function)

Aliases: Standardized, Property


conditionalExpression

JavaScript
t.conditionalExpression(test, consequent, alternate);

See also t.isConditionalExpression(node, opts) and t.assertConditionalExpression(node, opts).

AST Node ConditionalExpression shape:

  • test: Expression (required)
  • consequent: Expression (required)
  • alternate: Expression (required)

Aliases: Standardized, Expression, Conditional


continueStatement

JavaScript
t.continueStatement(label);

See also t.isContinueStatement(node, opts) and t.assertContinueStatement(node, opts).

AST Node ContinueStatement shape:

  • label: Identifier (default: null)

Aliases: Standardized, Statement, Terminatorless, CompletionStatement


debuggerStatement

JavaScript
t.debuggerStatement();

See also t.isDebuggerStatement(node, opts) and t.assertDebuggerStatement(node, opts).

Aliases: Standardized, Statement


decimalLiteral

JavaScript
t.decimalLiteral(value);

See also t.isDecimalLiteral(node, opts) and t.assertDecimalLiteral(node, opts).

AST Node DecimalLiteral shape:

  • value: string (required)

Aliases: Expression, Pureish, Literal, Immutable


declareClass

JavaScript
t.declareClass(id, typeParameters, extends, body);

See also t.isDeclareClass(node, opts) and t.assertDeclareClass(node, opts).

AST Node DeclareClass shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterDeclaration (default: null)
  • extends: InterfaceExtends[] (default: null)
  • body: ObjectTypeAnnotation (required)
  • implements: ClassImplements[] (default: null, excluded from builder function)
  • mixins: InterfaceExtends[] (default: null, excluded from builder function)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareExportAllDeclaration

JavaScript
t.declareExportAllDeclaration(source, attributes);

See also t.isDeclareExportAllDeclaration(node, opts) and t.assertDeclareExportAllDeclaration(node, opts).

AST Node DeclareExportAllDeclaration shape:

  • source: StringLiteral (required)
  • attributes: ImportAttribute[] (default: null)
  • assertions: ImportAttribute[] (default: null, excluded from builder function)
  • exportKind: "type" | "value" (default: null, excluded from builder function)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareExportDeclaration

JavaScript
t.declareExportDeclaration(declaration, specifiers, source, attributes);

See also t.isDeclareExportDeclaration(node, opts) and t.assertDeclareExportDeclaration(node, opts).

AST Node DeclareExportDeclaration shape:

  • declaration: Flow (default: null)
  • specifiers: (ExportSpecifier | ExportNamespaceSpecifier)[] (default: null)
  • source: StringLiteral (default: null)
  • attributes: ImportAttribute[] (default: null)
  • assertions: ImportAttribute[] (default: null, excluded from builder function)
  • default: boolean (default: null, excluded from builder function)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareFunction

JavaScript
t.declareFunction(id);

See also t.isDeclareFunction(node, opts) and t.assertDeclareFunction(node, opts).

AST Node DeclareFunction shape:

  • id: Identifier (required)
  • predicate: DeclaredPredicate (default: null, excluded from builder function)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareInterface

JavaScript
t.declareInterface(id, typeParameters, extends, body);

See also t.isDeclareInterface(node, opts) and t.assertDeclareInterface(node, opts).

AST Node DeclareInterface shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterDeclaration (default: null)
  • extends: InterfaceExtends[] (default: null)
  • body: ObjectTypeAnnotation (required)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareModule

JavaScript
t.declareModule(id, body, kind);

See also t.isDeclareModule(node, opts) and t.assertDeclareModule(node, opts).

AST Node DeclareModule shape:

  • id: Identifier | StringLiteral (required)
  • body: BlockStatement (required)
  • kind: "CommonJS" | "ES" (default: null)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareModuleExports

JavaScript
t.declareModuleExports(typeAnnotation);

See also t.isDeclareModuleExports(node, opts) and t.assertDeclareModuleExports(node, opts).

AST Node DeclareModuleExports shape:

  • typeAnnotation: TypeAnnotation (required)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareOpaqueType

JavaScript
t.declareOpaqueType(id, typeParameters, supertype);

See also t.isDeclareOpaqueType(node, opts) and t.assertDeclareOpaqueType(node, opts).

AST Node DeclareOpaqueType shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterDeclaration (default: null)
  • supertype: FlowType (default: null)
  • impltype: FlowType (default: null, excluded from builder function)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareTypeAlias

JavaScript
t.declareTypeAlias(id, typeParameters, right);

See also t.isDeclareTypeAlias(node, opts) and t.assertDeclareTypeAlias(node, opts).

AST Node DeclareTypeAlias shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterDeclaration (default: null)
  • right: FlowType (required)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declareVariable

JavaScript
t.declareVariable(id);

See also t.isDeclareVariable(node, opts) and t.assertDeclareVariable(node, opts).

AST Node DeclareVariable shape:

  • id: Identifier (required)

Aliases: Flow, FlowDeclaration, Statement, Declaration


declaredPredicate

JavaScript
t.declaredPredicate(value);

See also t.isDeclaredPredicate(node, opts) and t.assertDeclaredPredicate(node, opts).

AST Node DeclaredPredicate shape:

  • value: Flow (required)

Aliases: Flow, FlowPredicate


decorator

JavaScript
t.decorator(expression);

See also t.isDecorator(node, opts) and t.assertDecorator(node, opts).

AST Node Decorator shape:

  • expression: Expression (required)

directive

JavaScript
t.directive(value);

See also t.isDirective(node, opts) and t.assertDirective(node, opts).

AST Node Directive shape:

  • value: DirectiveLiteral (required)

Aliases: Standardized


directiveLiteral

JavaScript
t.directiveLiteral(value);

See also t.isDirectiveLiteral(node, opts) and t.assertDirectiveLiteral(node, opts).

AST Node DirectiveLiteral shape:

  • value: string (required)

Aliases: Standardized


doExpression

JavaScript
t.doExpression(body, async);

See also t.isDoExpression(node, opts) and t.assertDoExpression(node, opts).

AST Node DoExpression shape:

  • body: BlockStatement (required)
  • async: boolean (default: false)

Aliases: Expression


doWhileStatement

JavaScript
t.doWhileStatement(test, body);

See also t.isDoWhileStatement(node, opts) and t.assertDoWhileStatement(node, opts).

AST Node DoWhileStatement shape:

  • test: Expression (required)
  • body: Statement (required)

Aliases: Standardized, Statement, BlockParent, Loop, While, Scopable


emptyStatement

JavaScript
t.emptyStatement();

See also t.isEmptyStatement(node, opts) and t.assertEmptyStatement(node, opts).

Aliases: Standardized, Statement


emptyTypeAnnotation

JavaScript
t.emptyTypeAnnotation();

See also t.isEmptyTypeAnnotation(node, opts) and t.assertEmptyTypeAnnotation(node, opts).

Aliases: Flow, FlowType, FlowBaseAnnotation


enumBooleanBody

JavaScript
t.enumBooleanBody(members);

See also t.isEnumBooleanBody(node, opts) and t.assertEnumBooleanBody(node, opts).

AST Node EnumBooleanBody shape:

  • members: EnumBooleanMember[] (required)
  • explicitType: boolean (required)
  • hasUnknownMembers: boolean (required)

Aliases: Flow, EnumBody


enumBooleanMember

JavaScript
t.enumBooleanMember(id);

See also t.isEnumBooleanMember(node, opts) and t.assertEnumBooleanMember(node, opts).

AST Node EnumBooleanMember shape:

  • id: Identifier (required)
  • init: BooleanLiteral (required)

Aliases: Flow, EnumMember


enumDeclaration

JavaScript
t.enumDeclaration(id, body);

See also t.isEnumDeclaration(node, opts) and t.assertEnumDeclaration(node, opts).

AST Node EnumDeclaration shape:

  • id: Identifier (required)
  • body: EnumBooleanBody | EnumNumberBody | EnumStringBody | EnumSymbolBody (required)

Aliases: Flow, Statement, Declaration


enumDefaultedMember

JavaScript
t.enumDefaultedMember(id);

See also t.isEnumDefaultedMember(node, opts) and t.assertEnumDefaultedMember(node, opts).

AST Node EnumDefaultedMember shape:

  • id: Identifier (required)

Aliases: Flow, EnumMember


enumNumberBody

JavaScript
t.enumNumberBody(members);

See also t.isEnumNumberBody(node, opts) and t.assertEnumNumberBody(node, opts).

AST Node EnumNumberBody shape:

  • members: EnumNumberMember[] (required)
  • explicitType: boolean (required)
  • hasUnknownMembers: boolean (required)

Aliases: Flow, EnumBody


enumNumberMember

JavaScript
t.enumNumberMember(id, init);

See also t.isEnumNumberMember(node, opts) and t.assertEnumNumberMember(node, opts).

AST Node EnumNumberMember shape:

  • id: Identifier (required)
  • init: NumericLiteral (required)

Aliases: Flow, EnumMember


enumStringBody

JavaScript
t.enumStringBody(members);

See also t.isEnumStringBody(node, opts) and t.assertEnumStringBody(node, opts).

AST Node EnumStringBody shape:

  • members: (EnumStringMember | EnumDefaultedMember)[] (required)
  • explicitType: boolean (required)
  • hasUnknownMembers: boolean (required)

Aliases: Flow, EnumBody


enumStringMember

JavaScript
t.enumStringMember(id, init);

See also t.isEnumStringMember(node, opts) and t.assertEnumStringMember(node, opts).

AST Node EnumStringMember shape:

  • id: Identifier (required)
  • init: StringLiteral (required)

Aliases: Flow, EnumMember


enumSymbolBody

JavaScript
t.enumSymbolBody(members);

See also t.isEnumSymbolBody(node, opts) and t.assertEnumSymbolBody(node, opts).

AST Node EnumSymbolBody shape:

  • members: EnumDefaultedMember[] (required)
  • hasUnknownMembers: boolean (required)

Aliases: Flow, EnumBody


existsTypeAnnotation

JavaScript
t.existsTypeAnnotation();

See also t.isExistsTypeAnnotation(node, opts) and t.assertExistsTypeAnnotation(node, opts).

Aliases: Flow, FlowType


exportAllDeclaration

JavaScript
t.exportAllDeclaration(source, attributes);
History
VersionChanges
v7.29.0Supports attributes

See also t.isExportAllDeclaration(node, opts) and t.assertExportAllDeclaration(node, opts).

AST Node ExportAllDeclaration shape:

  • source: StringLiteral (required)
  • attributes: ImportAttribute[] (default: null)
  • assertions: ImportAttribute[] (default: null, excluded from builder function)
  • exportKind: "type" | "value" (default: null, excluded from builder function)

Aliases: Standardized, Statement, Declaration, ImportOrExportDeclaration, ExportDeclaration


exportDefaultDeclaration

JavaScript
t.exportDefaultDeclaration(declaration);

See also t.isExportDefaultDeclaration(node, opts) and t.assertExportDefaultDeclaration(node, opts).

AST Node ExportDefaultDeclaration shape:

  • declaration: TSDeclareFunction | FunctionDeclaration | ClassDeclaration | Expression (required)
  • exportKind: "value" (default: null, excluded from builder function)

Aliases: Standardized, Statement, Declaration, ImportOrExportDeclaration, ExportDeclaration


exportDefaultSpecifier

JavaScript
t.exportDefaultSpecifier(exported);

See also t.isExportDefaultSpecifier(node, opts) and t.assertExportDefaultSpecifier(node, opts).

AST Node ExportDefaultSpecifier shape:

  • exported: Identifier (required)

Aliases: ModuleSpecifier


exportNamedDeclaration

JavaScript
t.exportNamedDeclaration(declaration, specifiers, source, attributes);
History
VersionChanges
v7.29.0Supports attributes

See also t.isExportNamedDeclaration(node, opts) and t.assertExportNamedDeclaration(node, opts).

AST Node ExportNamedDeclaration shape:

  • declaration: Declaration (default: null)
  • specifiers: (ExportSpecifier | ExportDefaultSpecifier | ExportNamespaceSpecifier)[] (default: [])
  • source: StringLiteral (default: null)
  • attributes: ImportAttribute[] (default: null)
  • assertions: ImportAttribute[] (default: null, excluded from builder function)
  • exportKind: "type" | "value" (default: null, excluded from builder function)

Aliases: Standardized, Statement, Declaration, ImportOrExportDeclaration, ExportDeclaration


exportNamespaceSpecifier

JavaScript
t.exportNamespaceSpecifier(exported);

See also t.isExportNamespaceSpecifier(node, opts) and t.assertExportNamespaceSpecifier(node, opts).

AST Node ExportNamespaceSpecifier shape:

  • exported: Identifier (required)

Aliases: Standardized, ModuleSpecifier


exportSpecifier

JavaScript
t.exportSpecifier(local, exported);

See also t.isExportSpecifier(node, opts) and t.assertExportSpecifier(node, opts).

AST Node ExportSpecifier shape:

  • local: Identifier (required)
  • exported: Identifier | StringLiteral (required)
  • exportKind: "type" | "value" (default: null, excluded from builder function)

Aliases: Standardized, ModuleSpecifier


expressionStatement

JavaScript
t.expressionStatement(expression);

See also t.isExpressionStatement(node, opts) and t.assertExpressionStatement(node, opts).

AST Node ExpressionStatement shape:

  • expression: Expression (required)

Aliases: Standardized, Statement, ExpressionWrapper


file

JavaScript
t.file(program, comments, tokens);

See also t.isFile(node, opts) and t.assertFile(node, opts).

AST Node File shape:

  • program: Program (required)
  • comments: (CommentBlock | CommentLine)[] (default: null)
  • tokens: any[] (default: null)

Aliases: Standardized


forInStatement

JavaScript
t.forInStatement(left, right, body);

See also t.isForInStatement(node, opts) and t.assertForInStatement(node, opts).

AST Node ForInStatement shape:

  • left: VariableDeclaration | LVal (required)
  • right: Expression (required)
  • body: Statement (required)

Aliases: Standardized, Scopable, Statement, For, BlockParent, Loop, ForXStatement


forOfStatement

JavaScript
t.forOfStatement(left, right, body, await);

See also t.isForOfStatement(node, opts) and t.assertForOfStatement(node, opts).

AST Node ForOfStatement shape:

  • left: VariableDeclaration | LVal (required)
  • right: Expression (required)
  • body: Statement (required)
  • await: boolean (default: false)

Aliases: Standardized, Scopable, Statement, For, BlockParent, Loop, ForXStatement


forStatement

JavaScript
t.forStatement(init, test, update, body);

See also t.isForStatement(node, opts) and t.assertForStatement(node, opts).

AST Node ForStatement shape:

  • init: VariableDeclaration | Expression (default: null)
  • test: Expression (default: null)
  • update: Expression (default: null)
  • body: Statement (required)

Aliases: Standardized, Scopable, Statement, For, BlockParent, Loop


functionDeclaration

JavaScript
t.functionDeclaration(id, params, body, generator, async);

See also t.isFunctionDeclaration(node, opts) and t.assertFunctionDeclaration(node, opts).

AST Node FunctionDeclaration shape:

  • id: Identifier (default: null)
  • params: FunctionParameter[] (required)
  • body: BlockStatement (required)
  • generator: boolean (default: false)
  • async: boolean (default: false)
  • declare: boolean (default: null, excluded from builder function)
  • predicate: DeclaredPredicate | InferredPredicate (default: null, excluded from builder function)
  • returnType: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Scopable, Function, BlockParent, FunctionParent, Statement, Pureish, Declaration


functionExpression

JavaScript
t.functionExpression(id, params, body, generator, async);

See also t.isFunctionExpression(node, opts) and t.assertFunctionExpression(node, opts).

AST Node FunctionExpression shape:

  • id: Identifier (default: null)
  • params: FunctionParameter[] (required)
  • body: BlockStatement (required)
  • generator: boolean (default: false)
  • async: boolean (default: false)
  • predicate: DeclaredPredicate | InferredPredicate (default: null, excluded from builder function)
  • returnType: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)
  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop (default: null, excluded from builder function)

Aliases: Standardized, Scopable, Function, BlockParent, FunctionParent, Expression, Pureish


functionTypeAnnotation

JavaScript
t.functionTypeAnnotation(typeParameters, params, rest, returnType);

See also t.isFunctionTypeAnnotation(node, opts) and t.assertFunctionTypeAnnotation(node, opts).

AST Node FunctionTypeAnnotation shape:

  • typeParameters: TypeParameterDeclaration (default: null)
  • params: FunctionTypeParam[] (required)
  • rest: FunctionTypeParam (default: null)
  • returnType: FlowType (required)
  • this: FunctionTypeParam (default: null, excluded from builder function)

Aliases: Flow, FlowType


functionTypeParam

JavaScript
t.functionTypeParam(name, typeAnnotation);

See also t.isFunctionTypeParam(node, opts) and t.assertFunctionTypeParam(node, opts).

AST Node FunctionTypeParam shape:

  • name: Identifier (default: null)
  • typeAnnotation: FlowType (required)
  • optional: boolean (default: null, excluded from builder function)

Aliases: Flow


genericTypeAnnotation

JavaScript
t.genericTypeAnnotation(id, typeParameters);

See also t.isGenericTypeAnnotation(node, opts) and t.assertGenericTypeAnnotation(node, opts).

AST Node GenericTypeAnnotation shape:

  • id: Identifier | QualifiedTypeIdentifier (required)
  • typeParameters: TypeParameterInstantiation (default: null)

Aliases: Flow, FlowType


identifier

JavaScript
t.identifier(name);

See also t.isIdentifier(node, opts) and t.assertIdentifier(node, opts).

AST Node Identifier shape:

  • name: string (required)
  • decorators: Decorator[] (default: null, excluded from builder function)
  • optional: boolean (default: null, excluded from builder function)
  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, excluded from builder function)

Aliases: Standardized, Expression, FunctionParameter, PatternLike, LVal, TSEntityName


ifStatement

JavaScript
t.ifStatement(test, consequent, alternate);

See also t.isIfStatement(node, opts) and t.assertIfStatement(node, opts).

AST Node IfStatement shape:

  • test: Expression (required)
  • consequent: Statement (required)
  • alternate: Statement (default: null)

Aliases: Standardized, Statement, Conditional


import

JavaScript
t.import();

See also t.isImport(node, opts) and t.assertImport(node, opts).

Aliases: Standardized, Expression


importAttribute

JavaScript
t.importAttribute(key, value);

See also t.isImportAttribute(node, opts) and t.assertImportAttribute(node, opts).

AST Node ImportAttribute shape:

  • key: Identifier | StringLiteral (required)
  • value: StringLiteral (required)

Aliases: Standardized


importDeclaration

JavaScript
t.importDeclaration(specifiers, source, attributes);
History
VersionChanges
v7.20.0Supports module
v7.29.0Supports attributes

See also t.isImportDeclaration(node, opts) and t.assertImportDeclaration(node, opts).

AST Node ImportDeclaration shape:

  • specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[] (required)
  • source: StringLiteral (required)
  • attributes: ImportAttribute[] (default: null)
  • assertions: ImportAttribute[] (default: null, excluded from builder function)
  • importKind: "type" | "typeof" | "value" (default: null, excluded from builder function)
  • module: boolean (default: null, excluded from builder function)
  • phase: "source" | "defer" (default: null, excluded from builder function)

Aliases: Standardized, Statement, Declaration, ImportOrExportDeclaration


importDefaultSpecifier

JavaScript
t.importDefaultSpecifier(local);

See also t.isImportDefaultSpecifier(node, opts) and t.assertImportDefaultSpecifier(node, opts).

AST Node ImportDefaultSpecifier shape:

  • local: Identifier (required)

Aliases: Standardized, ModuleSpecifier


importExpression

JavaScript
t.importExpression(source, options);

See also t.isImportExpression(node, opts) and t.assertImportExpression(node, opts).

AST Node ImportExpression shape:

  • source: Expression (required)
  • options: Expression (default: null)
  • phase: "source" | "defer" (default: null, excluded from builder function)

Aliases: Standardized, Expression


importNamespaceSpecifier

JavaScript
t.importNamespaceSpecifier(local);

See also t.isImportNamespaceSpecifier(node, opts) and t.assertImportNamespaceSpecifier(node, opts).

AST Node ImportNamespaceSpecifier shape:

  • local: Identifier (required)

Aliases: Standardized, ModuleSpecifier


importSpecifier

JavaScript
t.importSpecifier(local, imported);

See also t.isImportSpecifier(node, opts) and t.assertImportSpecifier(node, opts).

AST Node ImportSpecifier shape:

  • local: Identifier (required)
  • imported: Identifier | StringLiteral (required)
  • importKind: "type" | "typeof" | "value" (default: null, excluded from builder function)

Aliases: Standardized, ModuleSpecifier


indexedAccessType

JavaScript
t.indexedAccessType(objectType, indexType);

See also t.isIndexedAccessType(node, opts) and t.assertIndexedAccessType(node, opts).

AST Node IndexedAccessType shape:

  • objectType: FlowType (required)
  • indexType: FlowType (required)

Aliases: Flow, FlowType


inferredPredicate

JavaScript
t.inferredPredicate();

See also t.isInferredPredicate(node, opts) and t.assertInferredPredicate(node, opts).

Aliases: Flow, FlowPredicate


interfaceDeclaration

JavaScript
t.interfaceDeclaration(id, typeParameters, extends, body);

See also t.isInterfaceDeclaration(node, opts) and t.assertInterfaceDeclaration(node, opts).

AST Node InterfaceDeclaration shape:

  • id: Identifier (required)
  • typeParameters: TypeParameterDeclaration (default: null)
  • extends: InterfaceExtends[] (default: null)
  • body: ObjectTypeAnnotation (required)

Aliases: Flow, FlowDeclaration, Statement, Declaration


interfaceExtends

JavaScript
t.interfaceExtends(id, typeParameters);

See also t.isInterfaceExtends(node, opts) and t.assertInterfaceExtends(node, opts).

AST Node InterfaceExtends shape:

  • id: Identifier | QualifiedTypeIdentifier (required)
  • typeParameters: TypeParameterInstantiation (default: null)

Aliases: Flow


interfaceTypeAnnotation

JavaScript
t.interfaceTypeAnnotation(extends, body);

See also t.isInterfaceTypeAnnotation(node, opts) and t.assertInterfaceTypeAnnotation(node, opts).

AST Node InterfaceTypeAnnotation shape:

  • extends: InterfaceExtends[] (default: null)
  • body: ObjectTypeAnnotation (required)

Aliases: Flow, FlowType


interpreterDirective

JavaScript
t.interpreterDirective(value);

See also t.isInterpreterDirective(node, opts) and t.assertInterpreterDirective(node, opts).

AST Node InterpreterDirective shape:

  • value: string (required)

Aliases: Standardized


intersectionTypeAnnotation

JavaScript
t.intersectionTypeAnnotation(types);

See also t.isIntersectionTypeAnnotation(node, opts) and t.assertIntersectionTypeAnnotation(node, opts).

AST Node IntersectionTypeAnnotation shape:

  • types: FlowType[] (required)

Aliases: Flow, FlowType


jsxAttribute

JavaScript
t.jsxAttribute(name, value);

See also t.isJSXAttribute(node, opts) and t.assertJSXAttribute(node, opts).

AST Node JSXAttribute shape:

  • name: JSXIdentifier | JSXNamespacedName (required)
  • value: JSXElement | JSXFragment | StringLiteral | JSXExpressionContainer (default: null)

Aliases: JSX, Immutable


jsxClosingElement

JavaScript
t.jsxClosingElement(name);

See also t.isJSXClosingElement(node, opts) and t.assertJSXClosingElement(node, opts).

AST Node JSXClosingElement shape:

  • name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName (required)

Aliases: JSX, Immutable


jsxClosingFragment

JavaScript
t.jsxClosingFragment();

See also t.isJSXClosingFragment(node, opts) and t.assertJSXClosingFragment(node, opts).

Aliases: JSX, Immutable


jsxElement

JavaScript
t.jsxElement(openingElement, closingElement, children, selfClosing);

See also t.isJSXElement(node, opts) and t.assertJSXElement(node, opts).

AST Node JSXElement shape:

  • openingElement: JSXOpeningElement (required)
  • closingElement: JSXClosingElement (default: null)
  • children: (JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment)[] (required)
  • selfClosing: boolean (default: null)

Aliases: