@babel/types
This module contains methods for building ASTs manually and for checking the types of AST nodes.
Install
- npm
- Yarn
- pnpm
npm install --save-dev @babel/types
yarn add --dev @babel/types
pnpm add --save-dev @babel/types
API
Node Builders
anyTypeAnnotation
t.anyTypeAnnotation();
See also t.isAnyTypeAnnotation(node, opts)
and t.assertAnyTypeAnnotation(node, opts)
.
Aliases: Flow
, FlowType
, FlowBaseAnnotation
argumentPlaceholder
t.argumentPlaceholder();
See also t.isArgumentPlaceholder(node, opts)
and t.assertArgumentPlaceholder(node, opts)
.
arrayExpression
t.arrayExpression(elements);
See also t.isArrayExpression(node, opts)
and t.assertArrayExpression(node, opts)
.
AST Node ArrayExpression
shape:
elements
:Array<null | Expression | SpreadElement>
(default:[]
)
Aliases: Standardized
, Expression
arrayPattern
t.arrayPattern(elements);
See also t.isArrayPattern(node, opts)
and t.assertArrayPattern(node, opts)
.
AST Node ArrayPattern
shape:
elements
:Array<null | PatternLike | LVal>
(required)decorators
:Array<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
, Pattern
, PatternLike
, LVal
arrayTypeAnnotation
t.arrayTypeAnnotation(elementType);
See also t.isArrayTypeAnnotation(node, opts)
and t.assertArrayTypeAnnotation(node, opts)
.
AST Node ArrayTypeAnnotation
shape:
elementType
:FlowType
(required)
arrowFunctionExpression
t.arrowFunctionExpression(params, body, async);
See also t.isArrowFunctionExpression(node, opts)
and t.assertArrowFunctionExpression(node, opts)
.
AST Node ArrowFunctionExpression
shape:
params
:Array<Identifier | Pattern | RestElement>
(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
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
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
:Array<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
, Pattern
, PatternLike
, LVal
awaitExpression
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
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
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
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
t.blockStatement(body, directives);
See also t.isBlockStatement(node, opts)
and t.assertBlockStatement(node, opts)
.
AST Node BlockStatement
shape:
body
:Array<Statement>
(required)directives
:Array<Directive>
(default:[]
)
Aliases: Standardized
, Scopable
, BlockParent
, Block
, Statement
booleanLiteral
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
t.booleanLiteralTypeAnnotation(value);
See also t.isBooleanLiteralTypeAnnotation(node, opts)
and t.assertBooleanLiteralTypeAnnotation(node, opts)
.
AST Node BooleanLiteralTypeAnnotation
shape:
value
:boolean
(required)
booleanTypeAnnotation
t.booleanTypeAnnotation();
See also t.isBooleanTypeAnnotation(node, opts)
and t.assertBooleanTypeAnnotation(node, opts)
.
Aliases: Flow
, FlowType
, FlowBaseAnnotation
breakStatement
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
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
:Array<Expression | SpreadElement | ArgumentPlaceholder>
(required)optional
:true | false
(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
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
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
:Array<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
t.classBody(body);
See also t.isClassBody(node, opts)
and t.assertClassBody(node, opts)
.
AST Node ClassBody
shape:
body
:Array<ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | ClassAccessorProperty | TSDeclareMethod | TSIndexSignature | StaticBlock>
(required)
Aliases: Standardized
classDeclaration
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
:Array<Decorator>
(default:null
)abstract
:boolean
(default:null
, excluded from builder function)declare
:boolean
(default:null
, excluded from builder function)implements
:Array<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
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
:Array<Decorator>
(default:null
)implements
:Array<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
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
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 thenExpression
elseIdentifier | Literal
(required)params
:Array<Identifier | Pattern | RestElement | 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
:Array<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
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
:Array<Identifier | Pattern | RestElement | 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
:Array<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
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
:Array<Decorator>
(default:null
)static
:boolean
(default:false
)definite
: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
t.classProperty(key, value, typeAnnotation, decorators, computed, static);
History
Version | Changes |
---|---|
v7.6.0 | Supports 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
:Array<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
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
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
t.debuggerStatement();
See also t.isDebuggerStatement(node, opts)
and t.assertDebuggerStatement(node, opts)
.
Aliases: Standardized
, Statement
decimalLiteral
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
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
:Array<InterfaceExtends>
(default:null
)body
:ObjectTypeAnnotation
(required)implements
:Array<ClassImplements>
(default:null
, excluded from builder function)mixins
:Array<InterfaceExtends>
(default:null
, excluded from builder function)
Aliases: Flow
, FlowDeclaration
, Statement
, Declaration
declareExportAllDeclaration
t.declareExportAllDeclaration(source);
See also t.isDeclareExportAllDeclaration(node, opts)
and t.assertDeclareExportAllDeclaration(node, opts)
.
AST Node DeclareExportAllDeclaration
shape:
source
:StringLiteral
(required)exportKind
:"type" | "value"
(default:null
, excluded from builder function)
Aliases: Flow
, FlowDeclaration
, Statement
, Declaration
declareExportDeclaration
t.declareExportDeclaration(declaration, specifiers, source);
See also t.isDeclareExportDeclaration(node, opts)
and t.assertDeclareExportDeclaration(node, opts)
.
AST Node DeclareExportDeclaration
shape:
declaration
:Flow
(default:null
)specifiers
:Array<ExportSpecifier | ExportNamespaceSpecifier>
(default:null
)source
:StringLiteral
(default:null
)default
:boolean
(default:null
, excluded from builder function)
Aliases: Flow
, FlowDeclaration
, Statement
, Declaration
declareFunction
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
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
:Array<InterfaceExtends>
(default:null
)body
:ObjectTypeAnnotation
(required)
Aliases: Flow
, FlowDeclaration
, Statement
, Declaration
declareModule
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
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
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
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
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
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
t.decorator(expression);
See also t.isDecorator(node, opts)
and t.assertDecorator(node, opts)
.
AST Node Decorator
shape:
expression
:Expression
(required)
directive
t.directive(value);
See also t.isDirective(node, opts)
and t.assertDirective(node, opts)
.
AST Node Directive
shape:
value
:DirectiveLiteral
(required)
Aliases: Standardized
directiveLiteral
t.directiveLiteral(value);
See also t.isDirectiveLiteral(node, opts)
and t.assertDirectiveLiteral(node, opts)
.
AST Node DirectiveLiteral
shape:
value
:string
(required)
Aliases: Standardized
doExpression
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
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
t.emptyStatement();
See also t.isEmptyStatement(node, opts)
and t.assertEmptyStatement(node, opts)
.
Aliases: Standardized
, Statement
emptyTypeAnnotation
t.emptyTypeAnnotation();
See also t.isEmptyTypeAnnotation(node, opts)
and t.assertEmptyTypeAnnotation(node, opts)
.
Aliases: Flow
, FlowType
, FlowBaseAnnotation
enumBooleanBody
t.enumBooleanBody(members);
See also t.isEnumBooleanBody(node, opts)
and t.assertEnumBooleanBody(node, opts)
.
AST Node EnumBooleanBody
shape:
members
:Array<EnumBooleanMember>
(required)explicitType
:boolean
(required)hasUnknownMembers
:boolean
(required)
enumBooleanMember
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
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
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
t.enumNumberBody(members);
See also t.isEnumNumberBody(node, opts)
and t.assertEnumNumberBody(node, opts)
.
AST Node EnumNumberBody
shape:
members
:Array<EnumNumberMember>
(required)explicitType
:boolean
(required)hasUnknownMembers
:boolean
(required)
enumNumberMember
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
t.enumStringBody(members);
See also t.isEnumStringBody(node, opts)
and t.assertEnumStringBody(node, opts)
.
AST Node EnumStringBody
shape:
members
:Array<EnumStringMember | EnumDefaultedMember>
(required)explicitType
:boolean
(required)hasUnknownMembers
:boolean
(required)
enumStringMember
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
t.enumSymbolBody(members);
See also t.isEnumSymbolBody(node, opts)
and t.assertEnumSymbolBody(node, opts)
.
AST Node EnumSymbolBody
shape:
members
:Array<EnumDefaultedMember>
(required)hasUnknownMembers
:boolean
(required)
existsTypeAnnotation
t.existsTypeAnnotation();
See also t.isExistsTypeAnnotation(node, opts)
and t.assertExistsTypeAnnotation(node, opts)
.
exportAllDeclaration
t.exportAllDeclaration(source);
See also t.isExportAllDeclaration(node, opts)
and t.assertExportAllDeclaration(node, opts)
.
AST Node ExportAllDeclaration
shape:
source
:StringLiteral
(required)assertions
:Array<ImportAttribute>
(default:null
, excluded from builder function)attributes
:Array<ImportAttribute>
(default:null
, excluded from builder function)exportKind
:"type" | "value"
(default:null
, excluded from builder function)
Aliases: Standardized
, Statement
, Declaration
, ImportOrExportDeclaration
, ExportDeclaration
exportDefaultDeclaration
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
t.exportDefaultSpecifier(exported);
See also t.isExportDefaultSpecifier(node, opts)
and t.assertExportDefaultSpecifier(node, opts)
.
AST Node ExportDefaultSpecifier
shape:
exported
:Identifier
(required)
Aliases: ModuleSpecifier
exportNamedDeclaration
t.exportNamedDeclaration(declaration, specifiers, source);
See also t.isExportNamedDeclaration(node, opts)
and t.assertExportNamedDeclaration(node, opts)
.
AST Node ExportNamedDeclaration
shape:
declaration
:Declaration
(default:null
)specifiers
:Array<ExportSpecifier | ExportDefaultSpecifier | ExportNamespaceSpecifier>
(default:[]
)source
:StringLiteral
(default:null
)assertions
:Array<ImportAttribute>
(default:null
, excluded from builder function)attributes
:Array<ImportAttribute>
(default:null
, excluded from builder function)exportKind
:"type" | "value"
(default:null
, excluded from builder function)
Aliases: Standardized
, Statement
, Declaration
, ImportOrExportDeclaration
, ExportDeclaration
exportNamespaceSpecifier
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
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
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
t.file(program, comments, tokens);
See also t.isFile(node, opts)
and t.assertFile(node, opts)
.
AST Node File
shape:
program
:Program
(required)comments
:Array<CommentBlock | CommentLine>
(default:null
)tokens
:Array<any>
(default:null
)
Aliases: Standardized
forInStatement
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
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
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
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
:Array<Identifier | Pattern | RestElement>
(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
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
:Array<Identifier | Pattern | RestElement>
(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
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
:Array<FunctionTypeParam>
(required)rest
:FunctionTypeParam
(default:null
)returnType
:FlowType
(required)this
:FunctionTypeParam
(default:null
, excluded from builder function)
functionTypeParam
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
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
)
identifier
t.identifier(name);
See also t.isIdentifier(node, opts)
and t.assertIdentifier(node, opts)
.
AST Node Identifier
shape:
name
:string
(required)decorators
:Array<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
, PatternLike
, LVal
, TSEntityName
ifStatement
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
t.import();
See also t.isImport(node, opts)
and t.assertImport(node, opts)
.
Aliases: Standardized
, Expression
importAttribute
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)
importDeclaration
t.importDeclaration(specifiers, source);
History
Version | Changes |
---|---|
v7.20.0 | Supports module |
See also t.isImportDeclaration(node, opts)
and t.assertImportDeclaration(node, opts)
.
AST Node ImportDeclaration
shape:
specifiers
:Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>
(required)source
:StringLiteral
(required)assertions
:Array<ImportAttribute>
(default:null
, excluded from builder function)attributes
:Array<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
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
t.importExpression(source, options);