跳至主内容

@babel/types

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

该模块包含用于手动构建 AST 节点以及检查 AST 节点类型的方法。

安装

npm install --save-dev @babel/types

API

节点构造器

anyTypeAnnotation

JavaScript
t.anyTypeAnnotation();

另请参阅 t.isAnyTypeAnnotation(node, opts)t.assertAnyTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


argumentPlaceholder

JavaScript
t.argumentPlaceholder();

另请参阅 t.isArgumentPlaceholder(node, opts)t.assertArgumentPlaceholder(node, opts)


arrayExpression

JavaScript
t.arrayExpression(elements);

另请参阅 t.isArrayExpression(node, opts)t.assertArrayExpression(node, opts)

AST 节点 ArrayExpression 结构:

  • elements: (null | Expression | SpreadElement)[] (默认值:[])

别名:Standardized, Expression


arrayPattern

JavaScript
t.arrayPattern(elements);

另请参阅 t.isArrayPattern(node, opts)t.assertArrayPattern(node, opts)

AST 节点 ArrayPattern 结构:

  • elements: (null | PatternLike)[] (必需)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:StandardizedFunctionParameterPatternPatternLikeLVal


arrayTypeAnnotation

JavaScript
t.arrayTypeAnnotation(elementType);

另请参阅 t.isArrayTypeAnnotation(node, opts)t.assertArrayTypeAnnotation(node, opts)

AST 节点 ArrayTypeAnnotation 结构:

  • elementType: FlowType (必需)

别名:Flow, FlowType


arrowFunctionExpression

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

另请参阅 t.isArrowFunctionExpression(node, opts)t.assertArrowFunctionExpression(node, opts)

AST 节点 ArrowFunctionExpression 结构:

  • params: FunctionParameter[] (必需)

  • body: BlockStatement | Expression (必需)

  • async: boolean(默认值:false

  • expression: boolean (必需)

  • generator: boolean(默认值:false,不包含在构建函数中)

  • predicate: DeclaredPredicate | InferredPredicate (默认值: null, 不包含在构建器函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名: Standardized, Scopable, Function, BlockParent, FunctionParent, Expression, Pureish


assignmentExpression

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

另请参阅 t.isAssignmentExpression(node, opts)t.assertAssignmentExpression(node, opts)

AST 节点 AssignmentExpression 的结构:

  • operator: string(必需)

  • left: LVal | OptionalMemberExpression(必需)

  • right: Expression (必需)

别名:Standardized, Expression


assignmentPattern

JavaScript
t.assignmentPattern(left, right);

另请参阅 t.isAssignmentPattern(node, opts)t.assertAssignmentPattern(node, opts)

AST 节点 AssignmentPattern 的结构:

  • left: Identifier | ObjectPattern | ArrayPattern | MemberExpression | TSAsExpression | TSSatisfiesExpression | TSTypeAssertion | TSNonNullExpression(必需)

  • right: Expression (必需)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:StandardizedFunctionParameterPatternPatternLikeLVal


awaitExpression

JavaScript
t.awaitExpression(argument);

另请参阅 t.isAwaitExpression(node, opts)t.assertAwaitExpression(node, opts)

AST 节点 AwaitExpression 的结构:

  • argument: Expression (必填)

别名: Standardized, Expression, Terminatorless


bigIntLiteral

JavaScript
t.bigIntLiteral(value);

另请参阅 t.isBigIntLiteral(node, opts)t.assertBigIntLiteral(node, opts)

AST 节点 BigIntLiteral 的结构:

  • value: string (required)

别名:Standardized, Expression, Pureish, Literal, Immutable


binaryExpression

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

另请参阅 t.isBinaryExpression(node, opts)t.assertBinaryExpression(node, opts)

AST 节点 BinaryExpression 的结构:

  • operator: "+" | "-" | "/" | "%" | "*" | "**" | "&" | "|" | ">>" | ">>>" | "<<" | "^" | "==" | "===" | "!=" | "!==" | "in" | "instanceof" | ">" | "<" | ">=" | "<=" | "|>"(必需)

  • left: Expression | PrivateName(必需)

  • right: Expression (必需)

别名: Standardized, Binary, Expression


bindExpression

JavaScript
t.bindExpression(object, callee);

另请参阅 t.isBindExpression(node, opts)t.assertBindExpression(node, opts)

AST 节点 BindExpression 的结构:

  • object: Expression (必需)

  • callee: Expression(必须)

别名:Expression


块语句

JavaScript
t.blockStatement(body, directives);

另请参阅 t.isBlockStatement(node, opts)t.assertBlockStatement(node, opts)

AST 节点 BlockStatement 的结构:

  • body: Statement[] (必需)

  • directives: Directive[] (默认值:[])

别名:Standardized, Scopable, BlockParent, Block, Statement


布尔字面量

JavaScript
t.booleanLiteral(value);

另请参阅 t.isBooleanLiteral(node, opts)t.assertBooleanLiteral(node, opts)

AST 节点 BooleanLiteral 的结构:

  • value: boolean (必须)

别名:Standardized, Expression, Pureish, Literal, Immutable


布尔字面量类型注解

JavaScript
t.booleanLiteralTypeAnnotation(value);

另请参阅 t.isBooleanLiteralTypeAnnotation(node, opts)t.assertBooleanLiteralTypeAnnotation(node, opts)

AST 节点 BooleanLiteralTypeAnnotation 的结构:

  • value: boolean (必须)

别名:Flow, FlowType


布尔类型注解

JavaScript
t.booleanTypeAnnotation();

另请参阅 t.isBooleanTypeAnnotation(node, opts)t.assertBooleanTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


break 语句

JavaScript
t.breakStatement(label);

另请参阅 t.isBreakStatement(node, opts)t.assertBreakStatement(node, opts)

AST 节点 BreakStatement 的结构:

  • label: Identifier(默认值:null

别名:Standardized, Statement, Terminatorless, CompletionStatement


调用表达式

JavaScript
t.callExpression(callee, arguments);

另请参阅 t.isCallExpression(node, opts)t.assertCallExpression(node, opts)

AST 节点 CallExpression 的结构:

  • callee: Expression | Super | V8IntrinsicIdentifier (必需)

  • arguments: (Expression | SpreadElement | ArgumentPlaceholder)[] (必需)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeArguments: TypeParameterInstantiation(默认值:null,不包含在构建器函数中)

  • typeParameters: TSTypeParameterInstantiation(默认值:null,不包含在构建器函数中)

别名:Standardized, Expression


catch 子句

JavaScript
t.catchClause(param, body);

另请参阅 t.isCatchClause(node, opts)t.assertCatchClause(node, opts)

AST 节点 CatchClause 的结构:

  • param: Identifier | ArrayPattern | ObjectPattern (默认值:null)

  • body: BlockStatement(必需)

别名:Standardized, Scopable, BlockParent


classAccessorProperty

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

另请参阅 t.isClassAccessorProperty(node, opts)t.assertClassAccessorProperty(node, opts)

AST 节点 ClassAccessorProperty 的结构:

  • key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression | PrivateName (必需)

  • value: Expression(默认值:null

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null

  • decorators: Decorator[] (默认值:null)

  • computed: boolean(默认值:false

  • static: boolean(默认值:false

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • declare: boolean (默认: null, 构建函数中排除)

  • definite: boolean (默认值: null,构建函数中不包含此参数)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • override: boolean(默认值:false,不包含在构建函数中)

  • readonly: boolean (默认值:null,不包含在构建器函数中)

  • variance: Variance(默认值:null,不包含在构建器函数中)

别名:Standardized, Property, Accessor


classBody

JavaScript
t.classBody(body);

另请参阅 t.isClassBody(node, opts)t.assertClassBody(node, opts)

AST 节点 ClassBody 的结构:

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

别名: Standardized


classDeclaration

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

另请参阅 t.isClassDeclaration(node, opts)t.assertClassDeclaration(node, opts)

AST 节点 ClassDeclaration 的结构:

  • id: Identifier(默认值:null

  • superClass: Expression (默认值:null)

  • body: ClassBody (必填)

  • decorators: Decorator[] (默认值:null)

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • declare: boolean (默认: null, 构建函数中排除)

  • implements: (TSExpressionWithTypeArguments | ClassImplements)[] (默认值:null,不包含在构建器函数中)

  • mixins: InterfaceExtends (默认值:null,不包含在构建器函数中)

  • superTypeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation (默认值:null,不包含在构建器函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名:StandardizedScopableClassStatementDeclaration


classExpression

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

另请参阅 t.isClassExpression(node, opts)t.assertClassExpression(node, opts)

AST 节点 ClassExpression 结构:

  • id: Identifier(默认值:null

  • superClass: Expression (默认值:null)

  • body: ClassBody (必填)

  • decorators: Decorator[] (默认值:null)

  • implements: (TSExpressionWithTypeArguments | ClassImplements)[] (默认值:null,不包含在构建器函数中)

  • mixins: InterfaceExtends (默认值:null,不包含在构建器函数中)

  • superTypeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation (默认值:null,不包含在构建器函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名:StandardizedScopableClassExpression


classImplements

JavaScript
t.classImplements(id, typeParameters);

另请参阅 t.isClassImplements(node, opts)t.assertClassImplements(node, opts)

AST 节点 ClassImplements 结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterInstantiation (默认: null)

别名: Flow


classMethod

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

另请参阅 t.isClassMethod(node, opts)t.assertClassMethod(node, opts)

AST 节点 ClassMethod 结构:

  • kind: "get" | "set" | "method" | "constructor" (默认值:'method')

  • key: 如果是计算属性则为 Expression,否则为 Identifier | Literal(必需)

  • params: (FunctionParameter | TSParameterProperty)[] (必需)

  • body: BlockStatement(必需)

  • computed: boolean(默认值:false

  • static: boolean(默认值:false

  • generator: boolean(默认值:false

  • async: boolean(默认值:false

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • access: "public" | "private" | "protected"(默认值:null,不包含在构建函数中)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • override: boolean(默认值:false,不包含在构建函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名:Standardized, Function, Scopable, BlockParent, FunctionParent, Method


classPrivateMethod

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

另见 t.isClassPrivateMethod(node, opts)t.assertClassPrivateMethod(node, opts)

AST 节点 ClassPrivateMethod 结构:

  • kind: "get" | "set" | "method"(默认值:'method'

  • key: PrivateName(必需)

  • params: (FunctionParameter | TSParameterProperty)[] (必需)

  • body: BlockStatement(必需)

  • static: boolean(默认值:false

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • access: "public" | "private" | "protected"(默认值:null,不包含在构建函数中)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • async: boolean(默认值:false,不包含在构建函数中)

  • computed: 'false'(默认值:false,不包含在构建函数中)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • generator: boolean(默认值:false,不包含在构建函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • override: boolean(默认值:false,不包含在构建函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名:Standardized, Function, Scopable, BlockParent, FunctionParent, Method, Private


classPrivateProperty

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

另见 t.isClassPrivateProperty(node, opts)t.assertClassPrivateProperty(node, opts)

AST 节点 ClassPrivateProperty 结构:

  • key: PrivateName(必需)

  • value: Expression(默认值:null

  • decorators: Decorator[] (默认值:null)

  • static: boolean(默认值:false

  • definite: boolean (默认值: null,构建函数中不包含此参数)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • readonly: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

  • variance: Variance(默认值:null,不包含在构建器函数中)

别名:Standardized, Property, Private


classProperty

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

另请参阅 t.isClassProperty(node, opts)t.assertClassProperty(node, opts)

AST 节点 ClassProperty 的形状:

  • key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression(必需)

  • value: Expression(默认值:null

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null

  • decorators: Decorator[] (默认值:null)

  • computed: boolean(默认值:false

  • static: boolean(默认值:false

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • declare: boolean (默认: null, 构建函数中排除)

  • definite: boolean (默认值: null,构建函数中不包含此参数)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • override: boolean(默认值:false,不包含在构建函数中)

  • readonly: boolean (默认值:null,不包含在构建器函数中)

  • variance: Variance(默认值:null,不包含在构建器函数中)

别名:Standardized, Property


conditionalExpression

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

另请参阅 t.isConditionalExpression(node, opts)t.assertConditionalExpression(node, opts)

AST 节点 ConditionalExpression 的形状:

  • test: Expression (必需)

  • consequent: Expression(必需)

  • alternate: Expression(必需)

别名:Standardized, Expression, Conditional


continueStatement

JavaScript
t.continueStatement(label);

另请参阅 t.isContinueStatement(node, opts)t.assertContinueStatement(node, opts)

AST 节点 ContinueStatement 的形状:

  • label: Identifier(默认值:null

别名:Standardized, Statement, Terminatorless, CompletionStatement


debuggerStatement

JavaScript
t.debuggerStatement();

另请参阅 t.isDebuggerStatement(node, opts)t.assertDebuggerStatement(node, opts)

别名: Standardized, Statement


decimalLiteral

JavaScript
t.decimalLiteral(value);

另请参见 t.isDecimalLiteral(node, opts)t.assertDecimalLiteral(node, opts)

AST 节点 DecimalLiteral 的结构:

  • value: string (required)

别名: Expression, Pureish, Literal, Immutable


declareClass

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

另请参见 t.isDeclareClass(node, opts)t.assertDeclareClass(node, opts)

AST 节点 DeclareClass 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • extends: InterfaceExtends[] (默认值:null)

  • body: ObjectTypeAnnotation (必需)

  • implements: ClassImplements[] (默认值:null,不包含在构建器函数中)

  • mixins: InterfaceExtends[] (默认值:null,不包含在构建器函数中)

别名:Flow, FlowDeclaration, Statement, Declaration


declareExportAllDeclaration

JavaScript
t.declareExportAllDeclaration(source, attributes);

另请参见 t.isDeclareExportAllDeclaration(node, opts)t.assertDeclareExportAllDeclaration(node, opts)

AST 节点 DeclareExportAllDeclaration 的结构:

  • source: StringLiteral (必需)

  • attributes: ImportAttribute[] (默认值:null)

  • assertions: ImportAttribute[] (默认值:null,不包含在构建器函数中)

  • exportKind: "type" | "value"(默认值:null,不包含在构建器函数中)

别名:Flow, FlowDeclaration, Statement, Declaration


declareExportDeclaration

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

另请参见 t.isDeclareExportDeclaration(node, opts)t.assertDeclareExportDeclaration(node, opts)

AST 节点 DeclareExportDeclaration 的结构:

  • declaration: Flow (默认值: null)

  • specifiers: (ExportSpecifier | ExportNamespaceSpecifier)[] (默认值:null)

  • source: StringLiteral (默认值:null)

  • attributes: ImportAttribute[] (默认值:null)

  • assertions: ImportAttribute[] (默认值:null,不包含在构建器函数中)

  • default: boolean (默认值: null,不包含在构建函数中)

别名:Flow, FlowDeclaration, Statement, Declaration


declareFunction

JavaScript
t.declareFunction(id);

另请参见 t.isDeclareFunction(node, opts)t.assertDeclareFunction(node, opts)

AST 节点 DeclareFunction 的结构:

  • id: Identifier (必需)

  • predicate: DeclaredPredicate (默认值: null,不包含在构建函数中)

别名:Flow, FlowDeclaration, Statement, Declaration


declareInterface

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

另见 t.isDeclareInterface(node, opts)t.assertDeclareInterface(node, opts)

AST 节点 DeclareInterface 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • extends: InterfaceExtends[] (默认值:null)

  • body: ObjectTypeAnnotation (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


declareModule

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

另见 t.isDeclareModule(node, opts)t.assertDeclareModule(node, opts)

AST 节点 DeclareModule 的结构:

  • id: Identifier | StringLiteral (必填)

  • body: BlockStatement(必需)

  • kind: "CommonJS" | "ES" (默认值: null)

别名:Flow, FlowDeclaration, Statement, Declaration


declareModuleExports

JavaScript
t.declareModuleExports(typeAnnotation);

另见 t.isDeclareModuleExports(node, opts)t.assertDeclareModuleExports(node, opts)

AST 节点 DeclareModuleExports 的结构:

  • typeAnnotation: TypeAnnotation (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


declareOpaqueType

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

另见 t.isDeclareOpaqueType(node, opts)t.assertDeclareOpaqueType(node, opts)

AST 节点 DeclareOpaqueType 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • supertype: FlowType (默认: null)

  • impltype: FlowType (默认值: null, 不包含在构建器函数中)

别名:Flow, FlowDeclaration, Statement, Declaration


declareTypeAlias

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

另见 t.isDeclareTypeAlias(node, opts)t.assertDeclareTypeAlias(node, opts)

AST 节点 DeclareTypeAlias 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • right: FlowType (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


declareVariable

JavaScript
t.declareVariable(id);

另见 t.isDeclareVariable(node, opts)t.assertDeclareVariable(node, opts)

AST 节点 DeclareVariable 的结构:

  • id: Identifier (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


declaredPredicate

JavaScript
t.declaredPredicate(value);

另请参阅 t.isDeclaredPredicate(node, opts)t.assertDeclaredPredicate(node, opts)

AST 节点 DeclaredPredicate 结构:

  • value: Flow (必填)

别名: Flow, FlowPredicate


decorator

JavaScript
t.decorator(expression);

另请参阅 t.isDecorator(node, opts)t.assertDecorator(node, opts)

AST 节点 Decorator 结构:

  • expression: Expression (必需)

directive

JavaScript
t.directive(value);

另请参阅 t.isDirective(node, opts)t.assertDirective(node, opts)

AST 节点 Directive 结构:

  • value: DirectiveLiteral (必填)

别名: Standardized


directiveLiteral

JavaScript
t.directiveLiteral(value);

另请参阅 t.isDirectiveLiteral(node, opts)t.assertDirectiveLiteral(node, opts)

AST 节点 DirectiveLiteral 结构:

  • value: string (required)

别名: Standardized


doExpression

JavaScript
t.doExpression(body, async);

另请参阅 t.isDoExpression(node, opts)t.assertDoExpression(node, opts)

AST 节点 DoExpression 结构:

  • body: BlockStatement(必需)

  • async: boolean(默认值:false

别名:Expression


doWhileStatement

JavaScript
t.doWhileStatement(test, body);

另请参阅 t.isDoWhileStatement(node, opts)t.assertDoWhileStatement(node, opts)

AST 节点 DoWhileStatement 结构:

  • test: Expression (必需)

  • body: Statement (必需)

别名: Standardized, Statement, BlockParent, Loop, While, Scopable


emptyStatement

JavaScript
t.emptyStatement();

另请参阅 t.isEmptyStatement(node, opts)t.assertEmptyStatement(node, opts)

别名: Standardized, Statement


emptyTypeAnnotation

JavaScript
t.emptyTypeAnnotation();

另请参阅 t.isEmptyTypeAnnotation(node, opts)t.assertEmptyTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


enumBooleanBody

JavaScript
t.enumBooleanBody(members);

另请参阅 t.isEnumBooleanBody(node, opts)t.assertEnumBooleanBody(node, opts)

AST 节点 EnumBooleanBody 结构:

  • members: EnumBooleanMember[] (必需)

  • explicitType: boolean(必需)

  • hasUnknownMembers: boolean (必需)

别名:Flow, EnumBody


布尔枚举成员

JavaScript
t.enumBooleanMember(id);

另见 t.isEnumBooleanMember(node, opts)t.assertEnumBooleanMember(node, opts)

AST 节点 EnumBooleanMember 的结构:

  • id: Identifier (必需)

  • init: BooleanLiteral(必需)

别名:Flow, EnumMember


枚举声明

JavaScript
t.enumDeclaration(id, body);

另见 t.isEnumDeclaration(node, opts)t.assertEnumDeclaration(node, opts)

AST 节点 EnumDeclaration 的结构:

  • id: Identifier (必需)

  • body: EnumBooleanBody | EnumNumberBody | EnumStringBody | EnumSymbolBody(必需)

别名:Flow, Statement, Declaration


默认枚举成员

JavaScript
t.enumDefaultedMember(id);

另见 t.isEnumDefaultedMember(node, opts)t.assertEnumDefaultedMember(node, opts)

AST 节点 EnumDefaultedMember 的结构:

  • id: Identifier (必需)

别名:Flow, EnumMember


数值枚举体

JavaScript
t.enumNumberBody(members);

另见 t.isEnumNumberBody(node, opts)t.assertEnumNumberBody(node, opts)

AST 节点 EnumNumberBody 的结构:

  • members: EnumNumberMember[] (必需)

  • explicitType: boolean(必需)

  • hasUnknownMembers: boolean (必需)

别名:Flow, EnumBody


数值枚举成员

JavaScript
t.enumNumberMember(id, init);

另见 t.isEnumNumberMember(node, opts)t.assertEnumNumberMember(node, opts)

AST 节点 EnumNumberMember 的结构:

  • id: Identifier (必需)

  • init: NumericLiteral(必需)

别名:Flow, EnumMember


字符串枚举体

JavaScript
t.enumStringBody(members);

另见 t.isEnumStringBody(node, opts)t.assertEnumStringBody(node, opts)

AST 节点 EnumStringBody 的结构:

  • members: (EnumStringMember | EnumDefaultedMember)[] (必需)

  • explicitType: boolean(必需)

  • hasUnknownMembers: boolean (必需)

别名:Flow, EnumBody


字符串枚举成员

JavaScript
t.enumStringMember(id, init);

另见 t.isEnumStringMember(node, opts)t.assertEnumStringMember(node, opts)

AST 节点 EnumStringMember 的结构:

  • id: Identifier (必需)

  • init: StringLiteral(必需)

别名:Flow, EnumMember


enumSymbolBody

JavaScript
t.enumSymbolBody(members);

另请参阅 t.isEnumSymbolBody(node, opts)t.assertEnumSymbolBody(node, opts)

AST 节点 EnumSymbolBody 的结构:

  • members: EnumDefaultedMember[] (必需)

  • hasUnknownMembers: boolean (必需)

别名:Flow, EnumBody


existsTypeAnnotation

JavaScript
t.existsTypeAnnotation();

另请参阅 t.isExistsTypeAnnotation(node, opts)t.assertExistsTypeAnnotation(node, opts)

别名:Flow, FlowType


exportAllDeclaration

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

另请参阅 t.isExportAllDeclaration(node, opts)t.assertExportAllDeclaration(node, opts)

AST 节点 ExportAllDeclaration 的结构:

  • source: StringLiteral (必需)

  • attributes: ImportAttribute[] (默认值:null)

  • assertions: ImportAttribute[] (默认值:null,不包含在构建器函数中)

  • exportKind: "type" | "value"(默认值:null,不包含在构建器函数中)

别名:StandardizedStatementDeclarationImportOrExportDeclarationExportDeclaration


exportDefaultDeclaration

JavaScript
t.exportDefaultDeclaration(declaration);

另请参阅 t.isExportDefaultDeclaration(node, opts)t.assertExportDefaultDeclaration(node, opts)

AST 节点 ExportDefaultDeclaration 的结构:

  • declaration: TSDeclareFunction | FunctionDeclaration | ClassDeclaration | Expression (必需)

  • exportKind: "value" (默认值:null,不包含在构建函数中)

别名:StandardizedStatementDeclarationImportOrExportDeclarationExportDeclaration


exportDefaultSpecifier

JavaScript
t.exportDefaultSpecifier(exported);

另请参阅 t.isExportDefaultSpecifier(node, opts)t.assertExportDefaultSpecifier(node, opts)

AST 节点 ExportDefaultSpecifier 的结构:

  • exported: Identifier(必填)

别名:ModuleSpecifier


exportNamedDeclaration

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

另请参阅 t.isExportNamedDeclaration(node, opts)t.assertExportNamedDeclaration(node, opts)

AST 节点 ExportNamedDeclaration 的结构:

  • declaration: Declaration (默认值:null)

  • specifiers: (ExportSpecifier | ExportDefaultSpecifier | ExportNamespaceSpecifier)[] (默认值:[])

  • source: StringLiteral (默认值:null)

  • attributes: ImportAttribute[] (默认值:null)

  • assertions: ImportAttribute[] (默认值:null,不包含在构建器函数中)

  • exportKind: "type" | "value"(默认值:null,不包含在构建器函数中)

别名:StandardizedStatementDeclarationImportOrExportDeclarationExportDeclaration


exportNamespaceSpecifier

JavaScript
t.exportNamespaceSpecifier(exported);

另见 t.isExportNamespaceSpecifier(node, opts)t.assertExportNamespaceSpecifier(node, opts)

AST 节点 ExportNamespaceSpecifier 的结构:

  • exported: Identifier(必填)

别名:Standardized, ModuleSpecifier


exportSpecifier

JavaScript
t.exportSpecifier(local, exported);

另见 t.isExportSpecifier(node, opts)t.assertExportSpecifier(node, opts)

AST 节点 ExportSpecifier 的结构:

  • local: Identifier (必需)

  • exported: Identifier | StringLiteral(必填)

  • exportKind: "type" | "value"(默认值:null,不包含在构建器函数中)

别名:Standardized, ModuleSpecifier


expressionStatement

JavaScript
t.expressionStatement(expression);

另见 t.isExpressionStatement(node, opts)t.assertExpressionStatement(node, opts)

AST 节点 ExpressionStatement 的结构:

  • expression: Expression (必需)

别名:StandardizedStatementExpressionWrapper


file

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

另见 t.isFile(node, opts)t.assertFile(node, opts)

AST 节点 File 的结构:

  • program: Program(必填)

  • comments: (CommentBlock | CommentLine)[] (默认值:null)

  • tokens: any[] (默认值:null)

别名: Standardized


forInStatement

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

另见 t.isForInStatement(node, opts)t.assertForInStatement(node, opts)

AST 节点 ForInStatement 的结构:

  • left: VariableDeclaration | LVal(必填)

  • right: Expression (必需)

  • body: Statement (必需)

别名: Standardized, Scopable, Statement, For, BlockParent, Loop, ForXStatement


forOfStatement

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

另见 t.isForOfStatement(node, opts)t.assertForOfStatement(node, opts)

AST 节点 ForOfStatement 的结构:

  • left: VariableDeclaration | LVal(必填)

  • right: Expression (必需)

  • body: Statement (必需)

  • await: boolean(默认值:false

别名: Standardized, Scopable, Statement, For, BlockParent, Loop, ForXStatement


forStatement

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

另请参阅 t.isForStatement(node, opts)t.assertForStatement(node, opts)

AST 节点 ForStatement 结构:

  • init: VariableDeclaration | Expression (默认值: null)

  • test: Expression(默认值:null

  • update: Expression (默认值: null)

  • body: Statement (必需)

别名: Standardized, Scopable, Statement, For, BlockParent, Loop


functionDeclaration

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

另请参阅 t.isFunctionDeclaration(node, opts)t.assertFunctionDeclaration(node, opts)

AST 节点 FunctionDeclaration 结构:

  • id: Identifier(默认值:null

  • params: FunctionParameter[] (必需)

  • body: BlockStatement(必需)

  • generator: boolean(默认值:false

  • async: boolean(默认值:false

  • declare: boolean (默认: null, 构建函数中排除)

  • predicate: DeclaredPredicate | InferredPredicate (默认值: null, 不包含在构建器函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名: Standardized, Scopable, Function, BlockParent, FunctionParent, Statement, Pureish, Declaration


functionExpression

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

另请参阅 t.isFunctionExpression(node, opts)t.assertFunctionExpression(node, opts)

AST 节点 FunctionExpression 结构:

  • id: Identifier(默认值:null

  • params: FunctionParameter[] (必需)

  • body: BlockStatement(必需)

  • generator: boolean(默认值:false

  • async: boolean(默认值:false

  • predicate: DeclaredPredicate | InferredPredicate (默认值: null, 不包含在构建器函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名: Standardized, Scopable, Function, BlockParent, FunctionParent, Expression, Pureish


functionTypeAnnotation

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

另请参阅 t.isFunctionTypeAnnotation(node, opts)t.assertFunctionTypeAnnotation(node, opts)

AST 节点 FunctionTypeAnnotation 的结构:

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • params: FunctionTypeParam[] (必需)

  • rest: FunctionTypeParam(默认值:null

  • returnType: FlowType(必填)

  • this: FunctionTypeParam(默认值:null,构建函数中排除)

别名:Flow, FlowType


functionTypeParam

JavaScript
t.functionTypeParam(name, typeAnnotation);

另请参阅 t.isFunctionTypeParam(node, opts)t.assertFunctionTypeParam(node, opts)

AST 节点 FunctionTypeParam 的结构:

  • name: Identifier(默认值:null

  • typeAnnotation: FlowType (必需)

  • optional: boolean (默认值:null,不包含在构建器函数中)

别名: Flow


genericTypeAnnotation

JavaScript
t.genericTypeAnnotation(id, typeParameters);

另请参阅 t.isGenericTypeAnnotation(node, opts)t.assertGenericTypeAnnotation(node, opts)

AST 节点 GenericTypeAnnotation 的结构:

  • id: Identifier | QualifiedTypeIdentifier (必需)

  • typeParameters: TypeParameterInstantiation (默认: null)

别名:Flow, FlowType


identifier

JavaScript
t.identifier(name);

另请参阅 t.isIdentifier(node, opts)t.assertIdentifier(node, opts)

AST 节点 Identifier 的结构:

  • name: string (必填)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:Standardized, Expression, FunctionParameter, PatternLike, LVal, TSEntityName


ifStatement

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

另请参阅 t.isIfStatement(node, opts)t.assertIfStatement(node, opts)

AST 节点 IfStatement 的结构:

  • test: Expression (必需)

  • consequent: Statement(必填)

  • alternate: Statement(默认值:null

别名:Standardized, Statement, Conditional


import

JavaScript
t.import();

另请参阅 t.isImport(node, opts)t.assertImport(node, opts)

别名:Standardized, Expression


importAttribute

JavaScript
t.importAttribute(key, value);

另请参见 t.isImportAttribute(node, opts)t.assertImportAttribute(node, opts)

AST 节点 ImportAttribute 结构:

  • key: Identifier | StringLiteral (必需)

  • value: StringLiteral (必需)

别名: Standardized


importDeclaration

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

另请参见 t.isImportDeclaration(node, opts)t.assertImportDeclaration(node, opts)

AST 节点 ImportDeclaration 结构:

  • specifiers: (ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[] (必需)

  • source: StringLiteral (必需)

  • attributes: ImportAttribute[] (默认值:null)

  • assertions: ImportAttribute[] (默认值:null,不包含在构建器函数中)

  • importKind: "type" | "typeof" | "value" (默认值: null,构建器函数中不包含)

  • module: boolean (默认值: null,构建器函数中不包含)

  • phase: "source" | "defer" (默认值: null,构建器函数中不包含)

别名:Standardized, Statement, Declaration, ImportOrExportDeclaration


importDefaultSpecifier

JavaScript
t.importDefaultSpecifier(local);

另请参见 t.isImportDefaultSpecifier(node, opts)t.assertImportDefaultSpecifier(node, opts)

AST 节点 ImportDefaultSpecifier 结构:

  • local: Identifier (必需)

别名:Standardized, ModuleSpecifier


importExpression

JavaScript
t.importExpression(source, options);

另请参见 t.isImportExpression(node, opts)t.assertImportExpression(node, opts)

AST 节点 ImportExpression 结构:

  • source: Expression (必需)

  • options: Expression (默认值: null)

  • phase: "source" | "defer" (默认值: null,构建器函数中不包含)

别名:Standardized, Expression


importNamespaceSpecifier

JavaScript
t.importNamespaceSpecifier(local);

另请参见 t.isImportNamespaceSpecifier(node, opts)t.assertImportNamespaceSpecifier(node, opts)

AST 节点 ImportNamespaceSpecifier 结构:

  • local: Identifier (必需)

别名:Standardized, ModuleSpecifier


importSpecifier

JavaScript
t.importSpecifier(local, imported);

另请参见 t.isImportSpecifier(node, opts)t.assertImportSpecifier(node, opts)

AST 节点 ImportSpecifier 结构:

  • local: Identifier (必需)

  • imported: Identifier | StringLiteral (必需)

  • importKind: "type" | "typeof" | "value" (默认值: null,构建器函数中不包含)

别名:Standardized, ModuleSpecifier


indexedAccessType

JavaScript
t.indexedAccessType(objectType, indexType);

另请参见 t.isIndexedAccessType(node, opts)t.assertIndexedAccessType(node, opts)

AST 节点 IndexedAccessType 结构:

  • objectType: FlowType(必须)

  • indexType: FlowType(必须)

别名:Flow, FlowType


inferredPredicate

JavaScript
t.inferredPredicate();

另请参见 t.isInferredPredicate(node, opts)t.assertInferredPredicate(node, opts)

别名: Flow, FlowPredicate


interfaceDeclaration

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

另请参见 t.isInterfaceDeclaration(node, opts)t.assertInterfaceDeclaration(node, opts)

AST 节点 InterfaceDeclaration 结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • extends: InterfaceExtends[] (默认值:null)

  • body: ObjectTypeAnnotation (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


interfaceExtends

JavaScript
t.interfaceExtends(id, typeParameters);

另请参见 t.isInterfaceExtends(node, opts)t.assertInterfaceExtends(node, opts)

AST 节点 InterfaceExtends 结构:

  • id: Identifier | QualifiedTypeIdentifier (必需)

  • typeParameters: TypeParameterInstantiation (默认: null)

别名: Flow


interfaceTypeAnnotation

JavaScript
t.interfaceTypeAnnotation(extends, body);

另请参见 t.isInterfaceTypeAnnotation(node, opts)t.assertInterfaceTypeAnnotation(node, opts)

AST 节点 InterfaceTypeAnnotation 结构:

  • extends: InterfaceExtends[] (默认值:null)

  • body: ObjectTypeAnnotation (必需)

别名:Flow, FlowType


interpreterDirective

JavaScript
t.interpreterDirective(value);

另请参见 t.isInterpreterDirective(node, opts)t.assertInterpreterDirective(node, opts)

AST 节点 InterpreterDirective 结构:

  • value: string (required)

别名: Standardized


intersectionTypeAnnotation

JavaScript
t.intersectionTypeAnnotation(types);

另请参见 t.isIntersectionTypeAnnotation(node, opts)t.assertIntersectionTypeAnnotation(node, opts)

AST 节点 IntersectionTypeAnnotation 结构:

  • types: FlowType[] (必需)

别名:Flow, FlowType


jsxAttribute

JavaScript
t.jsxAttribute(name, value);

另请参见 t.isJSXAttribute(node, opts)t.assertJSXAttribute(node, opts)

AST 节点 JSXAttribute 结构:

  • name: JSXIdentifier | JSXNamespacedName (必需)

  • value: JSXElement | JSXFragment | StringLiteral | JSXExpressionContainer (默认值: null)

别名: JSX, Immutable


jsxClosingElement

JavaScript
t.jsxClosingElement(name);

另请参阅 t.isJSXClosingElement(node, opts)t.assertJSXClosingElement(node, opts)

AST 节点 JSXClosingElement 结构:

  • name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName (必须)

别名: JSX, Immutable


jsxClosingFragment

JavaScript
t.jsxClosingFragment();

另请参阅 t.isJSXClosingFragment(node, opts)t.assertJSXClosingFragment(node, opts)

别名: JSX, Immutable


jsxElement

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

另请参阅 t.isJSXElement(node, opts)t.assertJSXElement(node, opts)

AST 节点 JSXElement 结构:

  • openingElement: JSXOpeningElement (必需)

  • closingElement: JSXClosingElement (默认值: null)

  • children: (JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment)[] (必需)

  • selfClosing: boolean (默认值: null)

别名: JSX, Immutable, Expression


jsxEmptyExpression

JavaScript
t.jsxEmptyExpression();

另请参阅 t.isJSXEmptyExpression(node, opts)t.assertJSXEmptyExpression(node, opts)

别名: JSX


jsxExpressionContainer

JavaScript
t.jsxExpressionContainer(expression);

另请参阅 t.isJSXExpressionContainer(node, opts)t.assertJSXExpressionContainer(node, opts)

AST 节点 JSXExpressionContainer 结构:

  • expression: Expression | JSXEmptyExpression (必需)

别名: JSX, Immutable


jsxFragment

JavaScript
t.jsxFragment(openingFragment, closingFragment, children);

另请参阅 t.isJSXFragment(node, opts)t.assertJSXFragment(node, opts)

AST 节点 JSXFragment 结构:

  • openingFragment: JSXOpeningFragment (必需)

  • closingFragment: JSXClosingFragment (必需)

  • children: (JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment)[] (必需)

别名: JSX, Immutable, Expression


jsxIdentifier

JavaScript
t.jsxIdentifier(name);

另请参阅 t.isJSXIdentifier(node, opts)t.assertJSXIdentifier(node, opts)

AST 节点 JSXIdentifier 结构:

  • name: string (必填)

别名: JSX


jsxMemberExpression

JavaScript
t.jsxMemberExpression(object, property);

另请参阅 t.isJSXMemberExpression(node, opts)t.assertJSXMemberExpression(node, opts)

AST 节点 JSXMemberExpression 的结构:

  • object: JSXMemberExpression | JSXIdentifier (必须)

  • property: JSXIdentifier (必须)

别名: JSX


jsxNamespacedName

JavaScript
t.jsxNamespacedName(namespace, name);

另请参阅 t.isJSXNamespacedName(node, opts)t.assertJSXNamespacedName(node, opts)

AST 节点 JSXNamespacedName 的结构:

  • namespace: JSXIdentifier (必须)

  • name: JSXIdentifier (必须)

别名: JSX


jsxOpeningElement

JavaScript
t.jsxOpeningElement(name, attributes, selfClosing);

另请参阅 t.isJSXOpeningElement(node, opts)t.assertJSXOpeningElement(node, opts)

AST 节点 JSXOpeningElement 的结构:

  • name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName (必须)

  • attributes: (JSXAttribute | JSXSpreadAttribute)[] (必需)

  • selfClosing: boolean (默认值: false)

  • typeArguments: TypeParameterInstantiation(默认值:null,不包含在构建器函数中)

  • typeParameters: TSTypeParameterInstantiation(默认值:null,不包含在构建器函数中)

别名: JSX, Immutable


jsxOpeningFragment

JavaScript
t.jsxOpeningFragment();

另请参阅 t.isJSXOpeningFragment(node, opts)t.assertJSXOpeningFragment(node, opts)

别名: JSX, Immutable


jsxSpreadAttribute

JavaScript
t.jsxSpreadAttribute(argument);

另请参阅 t.isJSXSpreadAttribute(node, opts)t.assertJSXSpreadAttribute(node, opts)

AST 节点 JSXSpreadAttribute 的结构:

  • argument: Expression (必填)

别名: JSX


jsxSpreadChild

JavaScript
t.jsxSpreadChild(expression);

另请参阅 t.isJSXSpreadChild(node, opts)t.assertJSXSpreadChild(node, opts)

AST 节点 JSXSpreadChild 的结构:

  • expression: Expression (必需)

别名: JSX, Immutable


jsxText

JavaScript
t.jsxText(value);

另请参阅 t.isJSXText(node, opts)t.assertJSXText(node, opts)

AST 节点 JSXText 的结构:

  • value: string (required)

别名: JSX, Immutable


labeledStatement

JavaScript
t.labeledStatement(label, body);

另请参阅 t.isLabeledStatement(node, opts)t.assertLabeledStatement(node, opts)

AST 节点 LabeledStatement 的结构:

  • label: Identifier (必填)

  • body: Statement (必需)

别名: Standardized, Statement


logicalExpression

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

另见 t.isLogicalExpression(node, opts)t.assertLogicalExpression(node, opts)

AST 节点 LogicalExpression 的结构:

  • operator: "||" | "&&" | "??" (必需)

  • left: Expression (必需)

  • right: Expression (必需)

别名: Standardized, Binary, Expression


memberExpression

JavaScript
t.memberExpression(object, property, computed, optional);

另见 t.isMemberExpression(node, opts)t.assertMemberExpression(node, opts)

AST 节点 MemberExpression 的结构:

  • object: Expression | Super (必需)

  • property: 若为计算属性则需 Expression,否则需 Identifier (必需)

  • computed: boolean(默认值:false

  • optional: boolean (默认值: null)

别名: Standardized, Expression, LVal, PatternLike


metaProperty

JavaScript
t.metaProperty(meta, property);

另见 t.isMetaProperty(node, opts)t.assertMetaProperty(node, opts)

AST 节点 MetaProperty 的结构:

  • meta: Identifier (必需)

  • property: Identifier (必需)

别名:Standardized, Expression


mixedTypeAnnotation

JavaScript
t.mixedTypeAnnotation();

另见 t.isMixedTypeAnnotation(node, opts)t.assertMixedTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


moduleExpression

JavaScript
t.moduleExpression(body);

另见 t.isModuleExpression(node, opts)t.assertModuleExpression(node, opts)

AST 节点 ModuleExpression 的结构:

  • body: Program (必需)

别名:Expression


newExpression

JavaScript
t.newExpression(callee, arguments);

另见 t.isNewExpression(node, opts)t.assertNewExpression(node, opts)

AST 节点 NewExpression 的结构:

  • callee: Expression | Super | V8IntrinsicIdentifier (必需)

  • arguments: (Expression | SpreadElement | ArgumentPlaceholder)[] (必需)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeArguments: TypeParameterInstantiation(默认值:null,不包含在构建器函数中)

  • typeParameters: TSTypeParameterInstantiation(默认值:null,不包含在构建器函数中)

别名:Standardized, Expression


noop

JavaScript
t.noop();

参见 t.isNoop(node, opts)t.assertNoop(node, opts)

别名:Miscellaneous


nullLiteral

JavaScript
t.nullLiteral();

参见 t.isNullLiteral(node, opts)t.assertNullLiteral(node, opts)

别名:Standardized, Expression, Pureish, Literal, Immutable


nullLiteralTypeAnnotation

JavaScript
t.nullLiteralTypeAnnotation();

参见 t.isNullLiteralTypeAnnotation(node, opts)t.assertNullLiteralTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


nullableTypeAnnotation

JavaScript
t.nullableTypeAnnotation(typeAnnotation);

参见 t.isNullableTypeAnnotation(node, opts)t.assertNullableTypeAnnotation(node, opts)

AST节点 NullableTypeAnnotation 结构:

  • typeAnnotation: FlowType (必需)

别名:Flow, FlowType


numberLiteralTypeAnnotation

JavaScript
t.numberLiteralTypeAnnotation(value);

参见 t.isNumberLiteralTypeAnnotation(node, opts)t.assertNumberLiteralTypeAnnotation(node, opts)

AST节点 NumberLiteralTypeAnnotation 结构:

  • value: number(必需)

别名:Flow, FlowType


numberTypeAnnotation

JavaScript
t.numberTypeAnnotation();

参见 t.isNumberTypeAnnotation(node, opts)t.assertNumberTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


numericLiteral

JavaScript
t.numericLiteral(value);

参见 t.isNumericLiteral(node, opts)t.assertNumericLiteral(node, opts)

AST节点 NumericLiteral 结构:

  • value: 非负有限 number(必需)

别名:Standardized, Expression, Pureish, Literal, Immutable


objectExpression

JavaScript
t.objectExpression(properties);

参见 t.isObjectExpression(node, opts)t.assertObjectExpression(node, opts)

AST节点 ObjectExpression 结构:

  • properties: (ObjectMethod | ObjectProperty | SpreadElement)[] (必需)

别名:Standardized, Expression


objectMethod

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

参见 t.isObjectMethod(node, opts)t.assertObjectMethod(node, opts)

AST节点 ObjectMethod 结构:

  • kind: "method" | "get" | "set"(默认:'method'

  • key: 如果是计算属性则为 Expression,否则为 Identifier | Literal(必需)

  • params: FunctionParameter[] (必需)

  • body: BlockStatement(必需)

  • computed: boolean(默认值:false

  • generator: boolean(默认值:false

  • async: boolean(默认值:false

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • returnType: TypeAnnotation | TSTypeAnnotation | Noop(默认值:null,不包含在构建函数中)

  • typeParameters: TypeParameterDeclaration | TSTypeParameterDeclaration | Noop(默认值:null,不包含在构建函数中)

别名:StandardizedUserWhitespacableFunctionScopableBlockParentFunctionParentMethodObjectMember


objectPattern

JavaScript
t.objectPattern(properties);

另请参见 t.isObjectPattern(node, opts)t.assertObjectPattern(node, opts)

AST 节点 ObjectPattern 的结构:

  • properties: (RestElement | ObjectProperty)[] (必需)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:StandardizedFunctionParameterPatternPatternLikeLVal


objectProperty

JavaScript
t.objectProperty(key, value, computed, shorthand, decorators);

另请参见 t.isObjectProperty(node, opts)t.assertObjectProperty(node, opts)

AST 节点 ObjectProperty 的结构:

  • key: 如果是计算属性则为 Expression,否则为 Identifier | Literal(必需)

  • value: Expression | PatternLike(必需)

  • computed: boolean(默认值:false

  • shorthand: boolean(默认值:false

  • decorators: Decorator[] (默认值:null)

别名:StandardizedUserWhitespacablePropertyObjectMember


objectTypeAnnotation

JavaScript
t.objectTypeAnnotation(properties, indexers, callProperties, internalSlots, exact);

另请参见 t.isObjectTypeAnnotation(node, opts)t.assertObjectTypeAnnotation(node, opts)

AST 节点 ObjectTypeAnnotation 的结构:

  • properties: (ObjectTypeProperty | ObjectTypeSpreadProperty)[] (必需)

  • indexers: ObjectTypeIndexer[] (默认值:[])

  • callProperties: ObjectTypeCallProperty[] (默认值:[])

  • internalSlots: ObjectTypeInternalSlot[] (默认值:[])

  • exact: boolean(默认值:false

  • inexact: boolean(默认值:null,不包含在构建函数中)

别名:Flow, FlowType


objectTypeCallProperty

JavaScript
t.objectTypeCallProperty(value);

另请参见 t.isObjectTypeCallProperty(node, opts)t.assertObjectTypeCallProperty(node, opts)

AST 节点 ObjectTypeCallProperty 的结构:

  • value: FlowType (必需)

  • static: boolean (必需)

别名:Flow, UserWhitespacable


objectTypeIndexer

JavaScript
t.objectTypeIndexer(id, key, value, variance);

另见 t.isObjectTypeIndexer(node, opts)t.assertObjectTypeIndexer(node, opts)

AST 节点 ObjectTypeIndexer 的结构:

  • id: Identifier(默认值:null

  • key: FlowType (必需)

  • value: FlowType (必需)

  • variance: Variance (默认值:null)

  • static: boolean (必需)

别名:Flow, UserWhitespacable


objectTypeInternalSlot

JavaScript
t.objectTypeInternalSlot(id, value, optional, static, method);

另见 t.isObjectTypeInternalSlot(node, opts)t.assertObjectTypeInternalSlot(node, opts)

AST 节点 ObjectTypeInternalSlot 的结构:

  • id: Identifier (必需)

  • value: FlowType (必需)

  • optional: boolean(必须)

  • static: boolean (必需)

  • method: boolean (必需)

别名:Flow, UserWhitespacable


objectTypeProperty

JavaScript
t.objectTypeProperty(key, value, variance);

另见 t.isObjectTypeProperty(node, opts)t.assertObjectTypeProperty(node, opts)

AST 节点 ObjectTypeProperty 的结构:

  • key: Identifier | StringLiteral (必需)

  • value: FlowType (必需)

  • variance: Variance (默认值:null)

  • kind: "init" | "get" | "set" (必需)

  • method: boolean (必需)

  • optional: boolean(必须)

  • proto: boolean (必需)

  • static: boolean (必需)

别名:Flow, UserWhitespacable


objectTypeSpreadProperty

JavaScript
t.objectTypeSpreadProperty(argument);

另见 t.isObjectTypeSpreadProperty(node, opts)t.assertObjectTypeSpreadProperty(node, opts)

AST 节点 ObjectTypeSpreadProperty 的结构:

  • argument: FlowType (必填)

别名:Flow, UserWhitespacable


opaqueType

JavaScript
t.opaqueType(id, typeParameters, supertype, impltype);

另见 t.isOpaqueType(node, opts)t.assertOpaqueType(node, opts)

AST 节点 OpaqueType 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • supertype: FlowType (默认: null)

  • impltype: FlowType(必须)

别名:Flow, FlowDeclaration, Statement, Declaration


optionalCallExpression

JavaScript
t.optionalCallExpression(callee, arguments, optional);

另请参阅 t.isOptionalCallExpression(node, opts)t.assertOptionalCallExpression(node, opts)

AST 节点 OptionalCallExpression 结构:

  • callee: Expression(必须)

  • arguments: (Expression | SpreadElement | ArgumentPlaceholder)[] (必需)

  • optional: boolean(必须)

  • typeArguments: TypeParameterInstantiation(默认值:null,不包含在构建器函数中)

  • typeParameters: TSTypeParameterInstantiation(默认值:null,不包含在构建器函数中)

别名:Standardized, Expression


optionalIndexedAccessType

JavaScript
t.optionalIndexedAccessType(objectType, indexType);

另请参阅 t.isOptionalIndexedAccessType(node, opts)t.assertOptionalIndexedAccessType(node, opts)

AST 节点 OptionalIndexedAccessType 结构:

  • objectType: FlowType(必须)

  • indexType: FlowType(必须)

  • optional: boolean(必须)

别名:Flow, FlowType


optionalMemberExpression

JavaScript
t.optionalMemberExpression(object, property, computed, optional);

另请参阅 t.isOptionalMemberExpression(node, opts)t.assertOptionalMemberExpression(node, opts)

AST 节点 OptionalMemberExpression 结构:

  • object: Expression (必需)

  • property: Expression | Identifier(必须)

  • computed: boolean(默认值:false

  • optional: boolean(必须)

别名:Standardized, Expression


parenthesizedExpression

JavaScript
t.parenthesizedExpression(expression);

另请参阅 t.isParenthesizedExpression(node, opts)t.assertParenthesizedExpression(node, opts)

AST 节点 ParenthesizedExpression 结构:

  • expression: Expression (必需)

别名:StandardizedExpressionExpressionWrapper


pipelineBareFunction

JavaScript
t.pipelineBareFunction(callee);

另请参阅 t.isPipelineBareFunction(node, opts)t.assertPipelineBareFunction(node, opts)

AST 节点 PipelineBareFunction 结构:

  • callee: Expression(必须)

别名:Expression


pipelinePrimaryTopicReference

JavaScript
t.pipelinePrimaryTopicReference();

另请参阅 t.isPipelinePrimaryTopicReference(node, opts)t.assertPipelinePrimaryTopicReference(node, opts)

别名:Expression


pipelineTopicExpression

JavaScript
t.pipelineTopicExpression(expression);

另请参阅 t.isPipelineTopicExpression(node, opts)t.assertPipelineTopicExpression(node, opts)

AST 节点 PipelineTopicExpression 结构:

  • expression: Expression (必需)

别名:Expression


placeholder

JavaScript
t.placeholder(expectedNode, name);

另请参阅 t.isPlaceholder(node, opts)t.assertPlaceholder(node, opts)

AST 节点 Placeholder 的结构:

  • expectedNode: "Identifier" | "StringLiteral" | "Expression" | "Statement" | "Declaration" | "BlockStatement" | "ClassBody" | "Pattern" (必须)

  • name: Identifier (必须)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:Miscellaneous


privateName

JavaScript
t.privateName(id);

另请参阅 t.isPrivateName(node, opts)t.assertPrivateName(node, opts)

AST 节点 PrivateName 的结构:

  • id: Identifier (必需)

别名:Standardized, Private


program

JavaScript
t.program(body, directives, sourceType, interpreter);

另请参阅 t.isProgram(node, opts)t.assertProgram(node, opts)

AST 节点 Program 的结构:

  • body: Statement[] (必需)

  • directives: Directive[] (默认值:[])

  • sourceType: "script" | "module" (默认值: 'script')

  • interpreter: InterpreterDirective (默认值: null)

别名:Standardized, Scopable, BlockParent, Block


qualifiedTypeIdentifier

JavaScript
t.qualifiedTypeIdentifier(id, qualification);

另请参阅 t.isQualifiedTypeIdentifier(node, opts)t.assertQualifiedTypeIdentifier(node, opts)

AST 节点 QualifiedTypeIdentifier 的结构:

  • id: Identifier (必需)

  • qualification: Identifier | QualifiedTypeIdentifier (必须)

别名: Flow


recordExpression

JavaScript
t.recordExpression(properties);

另请参阅 t.isRecordExpression(node, opts)t.assertRecordExpression(node, opts)

AST 节点 RecordExpression 的结构:

  • properties: (ObjectProperty | SpreadElement)[] (必需)

别名:Expression


regExpLiteral

JavaScript
t.regExpLiteral(pattern, flags);

另请参阅 t.isRegExpLiteral(node, opts)t.assertRegExpLiteral(node, opts)

AST 节点 RegExpLiteral 的结构:

  • pattern: string (必须)

  • flags: string (默认值: '')

别名:Standardized, Expression, Pureish, Literal


restElement

JavaScript
t.restElement(argument);

另请参阅 t.isRestElement(node, opts)t.assertRestElement(node, opts)

AST 节点 RestElement 的结构:

  • argument: Identifier | ArrayPattern | ObjectPattern | MemberExpression | TSAsExpression | TSSatisfiesExpression | TSTypeAssertion | TSNonNullExpression | RestElement | AssignmentPattern (required)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • typeAnnotation: TypeAnnotation | TSTypeAnnotation | Noop (default: null, 不包含在构建器函数中)

别名:Standardized, FunctionParameter, PatternLike, LVal


returnStatement

JavaScript
t.returnStatement(argument);

另请参阅 t.isReturnStatement(node, opts)t.assertReturnStatement(node, opts)

AST 节点 ReturnStatement 的结构:

  • argument: Expression (默认值: null)

别名:Standardized, Statement, Terminatorless, CompletionStatement


sequenceExpression

JavaScript
t.sequenceExpression(expressions);

另请参阅 t.isSequenceExpression(node, opts)t.assertSequenceExpression(node, opts)

AST 节点 SequenceExpression 的结构:

  • expressions: Expression[] (必需)

别名:Standardized, Expression


spreadElement

JavaScript
t.spreadElement(argument);

另请参阅 t.isSpreadElement(node, opts)t.assertSpreadElement(node, opts)

AST 节点 SpreadElement 的结构:

  • argument: Expression (必填)

别名:Standardized, UnaryLike


staticBlock

JavaScript
t.staticBlock(body);

另请参阅 t.isStaticBlock(node, opts)t.assertStaticBlock(node, opts)

AST 节点 StaticBlock 的结构:

  • body: Statement[] (必需)

别名:Standardized, Scopable, BlockParent, FunctionParent


stringLiteral

JavaScript
t.stringLiteral(value);

另请参阅 t.isStringLiteral(node, opts)t.assertStringLiteral(node, opts)

AST 节点 StringLiteral 的结构:

  • value: string (required)

别名:Standardized, Expression, Pureish, Literal, Immutable


stringLiteralTypeAnnotation

JavaScript
t.stringLiteralTypeAnnotation(value);

另请参阅 t.isStringLiteralTypeAnnotation(node, opts)t.assertStringLiteralTypeAnnotation(node, opts)

AST 节点 StringLiteralTypeAnnotation 的结构:

  • value: string (required)

别名:Flow, FlowType


stringTypeAnnotation

JavaScript
t.stringTypeAnnotation();

另见 t.isStringTypeAnnotation(node, opts)t.assertStringTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


super

JavaScript
t.super();

另见 t.isSuper(node, opts)t.assertSuper(node, opts)

别名:Standardized, Expression


switchCase

JavaScript
t.switchCase(test, consequent);

另见 t.isSwitchCase(node, opts)t.assertSwitchCase(node, opts)

AST 节点 SwitchCase 结构:

  • test: Expression(默认值:null

  • consequent: Statement[] (必需)

别名: Standardized


switchStatement

JavaScript
t.switchStatement(discriminant, cases);

另见 t.isSwitchStatement(node, opts)t.assertSwitchStatement(node, opts)

AST 节点 SwitchStatement 结构:

  • discriminant: Expression(必需)

  • cases: SwitchCase[] (必需)

别名:Standardized, Statement, BlockParent, Scopable


symbolTypeAnnotation

JavaScript
t.symbolTypeAnnotation();

另见 t.isSymbolTypeAnnotation(node, opts)t.assertSymbolTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


tsAnyKeyword

JavaScript
t.tsAnyKeyword();

另见 t.isTSAnyKeyword(node, opts)t.assertTSAnyKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsArrayType

JavaScript
t.tsArrayType(elementType);

另见 t.isTSArrayType(node, opts)t.assertTSArrayType(node, opts)

AST 节点 TSArrayType 结构:

  • elementType: TSType (必填)

别名:TypeScript, TSType


tsAsExpression

JavaScript
t.tsAsExpression(expression, typeAnnotation);

另见 t.isTSAsExpression(node, opts)t.assertTSAsExpression(node, opts)

AST 节点 TSAsExpression 结构:

  • expression: Expression (必需)

  • typeAnnotation: TSType (必填)

别名: TypeScript, Expression, LVal, PatternLike


tsBigIntKeyword

JavaScript
t.tsBigIntKeyword();

另见 t.isTSBigIntKeyword(node, opts)t.assertTSBigIntKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsBooleanKeyword

JavaScript
t.tsBooleanKeyword();

另请参阅 t.isTSBooleanKeyword(node, opts)t.assertTSBooleanKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsCallSignatureDeclaration

JavaScript
t.tsCallSignatureDeclaration(typeParameters, parameters, typeAnnotation);

另请参阅 t.isTSCallSignatureDeclaration(node, opts)t.assertTSCallSignatureDeclaration(node, opts)

AST 节点 TSCallSignatureDeclaration 的结构:

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • parameters: (ArrayPattern | Identifier | ObjectPattern | RestElement)[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

别名:TypeScriptTSTypeElement


tsConditionalType

JavaScript
t.tsConditionalType(checkType, extendsType, trueType, falseType);

另请参阅 t.isTSConditionalType(node, opts)t.assertTSConditionalType(node, opts)

AST 节点 TSConditionalType 的结构:

  • checkType: TSType(必需)

  • extendsType: TSType(必需)

  • trueType: TSType(必需)

  • falseType: TSType(必需)

别名:TypeScript, TSType


tsConstructSignatureDeclaration

JavaScript
t.tsConstructSignatureDeclaration(typeParameters, parameters, typeAnnotation);

另请参阅 t.isTSConstructSignatureDeclaration(node, opts)t.assertTSConstructSignatureDeclaration(node, opts)

AST 节点 TSConstructSignatureDeclaration 的结构:

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • parameters: (ArrayPattern | Identifier | ObjectPattern | RestElement)[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

别名:TypeScriptTSTypeElement


tsConstructorType

JavaScript
t.tsConstructorType(typeParameters, parameters, typeAnnotation);

另请参阅 t.isTSConstructorType(node, opts)t.assertTSConstructorType(node, opts)

AST 节点 TSConstructorType 的结构:

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • parameters: (ArrayPattern | Identifier | ObjectPattern | RestElement)[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

  • abstract: boolean(默认值:null,不包含在构建函数中)

别名:TypeScript, TSType


tsDeclareFunction

JavaScript
t.tsDeclareFunction(id, typeParameters, params, returnType);

另请参阅 t.isTSDeclareFunction(node, opts)t.assertTSDeclareFunction(node, opts)

AST 节点 TSDeclareFunction 的结构:

  • id: Identifier(默认值:null

  • typeParameters: TSTypeParameterDeclaration | Noop(默认值:null

  • params: FunctionParameter[] (必需)

  • returnType: TSTypeAnnotation | Noop(默认值:null

  • async: boolean(默认值:false,不包含在构建函数中)

  • declare: boolean (默认: null, 构建函数中排除)

  • generator: boolean(默认值:false,不包含在构建函数中)

别名: TypeScript, Statement, Declaration


tsDeclareMethod

JavaScript
t.tsDeclareMethod(decorators, key, typeParameters, params, returnType);

另请参阅 t.isTSDeclareMethod(node, opts)t.assertTSDeclareMethod(node, opts)

AST 节点 TSDeclareMethod 的结构:

  • decorators: Decorator[] (默认值:null)

  • key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression(必需)

  • typeParameters: TSTypeParameterDeclaration | Noop(默认值:null

  • params: (FunctionParameter | TSParameterProperty)[] (必需)

  • returnType: TSTypeAnnotation | Noop(默认值:null

  • abstract: boolean(默认值:null,不包含在构建函数中)

  • access: "public" | "private" | "protected"(默认值:null,不包含在构建函数中)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • async: boolean(默认值:false,不包含在构建函数中)

  • computed: boolean (默认值:false,不包含在构建器函数中)

  • generator: boolean(默认值:false,不包含在构建函数中)

  • kind: "get" | "set" | "method" | "constructor"(默认值:'method',不包含在构建函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • override: boolean(默认值:false,不包含在构建函数中)

  • static: boolean(默认值:false,不包含在构建函数中)

别名:TypeScript


tsEnumBody

JavaScript
t.tsEnumBody(members);

另请参阅 t.isTSEnumBody(node, opts)t.assertTSEnumBody(node, opts)

AST 节点 TSEnumBody 的结构:

  • members: TSEnumMember[] (必需)

别名:TypeScript


tsEnumDeclaration

JavaScript
t.tsEnumDeclaration(id, members);

另请参阅 t.isTSEnumDeclaration(node, opts)t.assertTSEnumDeclaration(node, opts)

AST 节点 TSEnumDeclaration 的结构:

  • id: Identifier (必需)

  • members: TSEnumMember[] (必需)

  • body: TSEnumBody(默认值:null,不包含在构建函数中)

  • const: boolean (默认值: null, 构建器函数中排除)

  • declare: boolean (默认: null, 构建函数中排除)

  • initializer: Expression(默认值:null,不包含在构建函数中)

别名: TypeScript, Statement, Declaration


tsEnumMember

JavaScript
t.tsEnumMember(id, initializer);

另见 t.isTSEnumMember(node, opts)t.assertTSEnumMember(node, opts)

AST 节点 TSEnumMember 的结构:

  • id: Identifier | StringLiteral (必填)

  • initializer: Expression (默认值: null)

别名:TypeScript


tsExportAssignment

JavaScript
t.tsExportAssignment(expression);

另见 t.isTSExportAssignment(node, opts)t.assertTSExportAssignment(node, opts)

AST 节点 TSExportAssignment 的结构:

  • expression: Expression (必需)

别名:TypeScriptStatement


tsExpressionWithTypeArguments

JavaScript
t.tsExpressionWithTypeArguments(expression, typeParameters);

另见 t.isTSExpressionWithTypeArguments(node, opts)t.assertTSExpressionWithTypeArguments(node, opts)

AST 节点 TSExpressionWithTypeArguments 的结构:

  • expression: TSEntityName (必需)

  • typeParameters: TSTypeParameterInstantiation (默认值:null

别名:TypeScript, TSType


tsExternalModuleReference

JavaScript
t.tsExternalModuleReference(expression);

另见 t.isTSExternalModuleReference(node, opts)t.assertTSExternalModuleReference(node, opts)

AST 节点 TSExternalModuleReference 的结构:

  • expression: StringLiteral (必需)

别名:TypeScript


tsFunctionType

JavaScript
t.tsFunctionType(typeParameters, parameters, typeAnnotation);

另见 t.isTSFunctionType(node, opts)t.assertTSFunctionType(node, opts)

AST 节点 TSFunctionType 的结构:

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • parameters: (ArrayPattern | Identifier | ObjectPattern | RestElement)[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

别名:TypeScript, TSType


tsImportEqualsDeclaration

JavaScript
t.tsImportEqualsDeclaration(id, moduleReference);

另见 t.isTSImportEqualsDeclaration(node, opts)t.assertTSImportEqualsDeclaration(node, opts)

AST 节点 TSImportEqualsDeclaration 的结构:

  • id: Identifier (必需)

  • moduleReference: TSEntityName | TSExternalModuleReference (必需)

  • importKind: "type" | "value" (默认值: null, 不包含在构建器函数中)

  • isExport: boolean (必需)

别名: TypeScript, Statement, Declaration


tsImportType

JavaScript
t.tsImportType(argument, qualifier, typeParameters);

另见 t.isTSImportType(node, opts)t.assertTSImportType(node, opts)

AST 节点 TSImportType 的结构:

  • argument: StringLiteral (必须)

  • qualifier: TSEntityName (默认值: null)

  • typeParameters: TSTypeParameterInstantiation (默认值:null

  • options: ObjectExpression (默认值: null, 不包含在构建函数中)

别名:TypeScript, TSType


tsIndexSignature

JavaScript
t.tsIndexSignature(parameters, typeAnnotation);

另请参阅 t.isTSIndexSignature(node, opts)t.assertTSIndexSignature(node, opts)

AST 节点 TSIndexSignature 的结构:

  • parameters: Identifier[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

  • readonly: boolean (默认值:null,不包含在构建器函数中)

  • static: boolean (默认值: null, 不包含在构建函数中)

别名:TypeScriptTSTypeElement


tsIndexedAccessType

JavaScript
t.tsIndexedAccessType(objectType, indexType);

另请参阅 t.isTSIndexedAccessType(node, opts)t.assertTSIndexedAccessType(node, opts)

AST 节点 TSIndexedAccessType 的结构:

  • objectType: TSType (必须)

  • indexType: TSType (必须)

别名:TypeScript, TSType


tsInferType

JavaScript
t.tsInferType(typeParameter);

另请参阅 t.isTSInferType(node, opts)t.assertTSInferType(node, opts)

AST 节点 TSInferType 的结构:

  • typeParameter: TSTypeParameter (必填)

别名:TypeScript, TSType


tsInstantiationExpression

JavaScript
t.tsInstantiationExpression(expression, typeParameters);

另请参阅 t.isTSInstantiationExpression(node, opts)t.assertTSInstantiationExpression(node, opts)

AST 节点 TSInstantiationExpression 的结构:

  • expression: Expression (必需)

  • typeParameters: TSTypeParameterInstantiation (默认值:null

别名:TypeScript, Expression


tsInterfaceBody

JavaScript
t.tsInterfaceBody(body);

另请参阅 t.isTSInterfaceBody(node, opts)t.assertTSInterfaceBody(node, opts)

AST 节点 TSInterfaceBody 的结构:

  • body: TSTypeElement[] (必需)

别名:TypeScript


tsInterfaceDeclaration

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

另请参阅 t.isTSInterfaceDeclaration(node, opts)t.assertTSInterfaceDeclaration(node, opts)

AST 节点 TSInterfaceDeclaration 的结构:

  • id: Identifier (必需)

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • extends: TSExpressionWithTypeArguments[] (默认值:null)

  • body: TSInterfaceBody (必填)

  • declare: boolean (默认: null, 构建函数中排除)

别名: TypeScript, Statement, Declaration


tsIntersectionType

JavaScript
t.tsIntersectionType(types);

另请参阅 t.isTSIntersectionType(node, opts)t.assertTSIntersectionType(node, opts)

AST 节点 TSIntersectionType 结构:

  • types: TSType[] (必需)

别名:TypeScript, TSType


tsIntrinsicKeyword

JavaScript
t.tsIntrinsicKeyword();

另请参阅 t.isTSIntrinsicKeyword(node, opts)t.assertTSIntrinsicKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsLiteralType

JavaScript
t.tsLiteralType(literal);

另请参阅 t.isTSLiteralType(node, opts)t.assertTSLiteralType(node, opts)

AST 节点 TSLiteralType 结构:

  • literal: NumericLiteral | StringLiteral | BooleanLiteral | BigIntLiteral | TemplateLiteral | UnaryExpression (必填)

别名:TypeScript, TSType, TSBaseType


tsMappedType

JavaScript
t.tsMappedType(typeParameter, typeAnnotation, nameType);

另请参阅 t.isTSMappedType(node, opts)t.assertTSMappedType(node, opts)

AST 节点 TSMappedType 结构:

  • typeParameter: TSTypeParameter (必填)

  • typeAnnotation: TSType (默认值: null)

  • nameType: TSType (默认值: null)

  • optional: true | false | "+" | "-" (默认值: null, 不包含在构建函数中)

  • readonly: true | false | "+" | "-" (默认值: null, 不包含在构建函数中)

别名:TypeScript, TSType


tsMethodSignature

JavaScript
t.tsMethodSignature(key, typeParameters, parameters, typeAnnotation);

另请参阅 t.isTSMethodSignature(node, opts)t.assertTSMethodSignature(node, opts)

AST 节点 TSMethodSignature 结构:

  • key: Expression (必需)

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • parameters: (ArrayPattern | Identifier | ObjectPattern | RestElement)[] (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

  • computed: boolean (默认值:false,不包含在构建器函数中)

  • kind: "method" | "get" | "set" (必填)

  • optional: boolean (默认值:null,不包含在构建器函数中)

别名:TypeScriptTSTypeElement


tsModuleBlock

JavaScript
t.tsModuleBlock(body);

另请参阅 t.isTSModuleBlock(node, opts)t.assertTSModuleBlock(node, opts)

AST 节点 TSModuleBlock 结构:

  • body: Statement[] (必需)

别名:TypeScriptScopableBlockBlockParentFunctionParent


tsModuleDeclaration

JavaScript
t.tsModuleDeclaration(id, body);

另请参阅 t.isTSModuleDeclaration(node, opts)t.assertTSModuleDeclaration(node, opts)

AST 节点 TSModuleDeclaration 结构:

  • id: Identifier | StringLiteral (必填)

  • body: TSModuleBlock | TSModuleDeclaration (必填)

  • declare: boolean (默认: null, 构建函数中排除)

  • global: boolean (默认:null,构建函数中不包含)

  • kind: "global" | "module" | "namespace" (必填)

别名: TypeScript, Statement, Declaration


tsNamedTupleMember

JavaScript
t.tsNamedTupleMember(label, elementType, optional);

另请参阅 t.isTSNamedTupleMember(node, opts)t.assertTSNamedTupleMember(node, opts)

AST 节点 TSNamedTupleMember 结构:

  • label: Identifier (必填)

  • elementType: TSType (必填)

  • optional: boolean (默认:false)

别名:TypeScript


tsNamespaceExportDeclaration

JavaScript
t.tsNamespaceExportDeclaration(id);

另请参阅 t.isTSNamespaceExportDeclaration(node, opts)t.assertTSNamespaceExportDeclaration(node, opts)

AST 节点 TSNamespaceExportDeclaration 结构:

  • id: Identifier (必需)

别名:TypeScriptStatement


tsNeverKeyword

JavaScript
t.tsNeverKeyword();

另请参阅 t.isTSNeverKeyword(node, opts)t.assertTSNeverKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsNonNullExpression

JavaScript
t.tsNonNullExpression(expression);

另请参阅 t.isTSNonNullExpression(node, opts)t.assertTSNonNullExpression(node, opts)

AST 节点 TSNonNullExpression 结构:

  • expression: Expression (必需)

别名: TypeScript, Expression, LVal, PatternLike


tsNullKeyword

JavaScript
t.tsNullKeyword();

另请参阅 t.isTSNullKeyword(node, opts)t.assertTSNullKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsNumberKeyword

JavaScript
t.tsNumberKeyword();

另请参阅 t.isTSNumberKeyword(node, opts)t.assertTSNumberKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsObjectKeyword

JavaScript
t.tsObjectKeyword();

另见 t.isTSObjectKeyword(node, opts)t.assertTSObjectKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsOptionalType

JavaScript
t.tsOptionalType(typeAnnotation);

另见 t.isTSOptionalType(node, opts)t.assertTSOptionalType(node, opts)

AST 节点 TSOptionalType 结构:

  • typeAnnotation: TSType (必填)

别名:TypeScript, TSType


tsParameterProperty

JavaScript
t.tsParameterProperty(parameter);

另见 t.isTSParameterProperty(node, opts)t.assertTSParameterProperty(node, opts)

AST 节点 TSParameterProperty 结构:

  • parameter: Identifier | AssignmentPattern (必需)

  • accessibility: "public" | "private" | "protected" (默认值:null,不包含在构建器函数中)

  • decorators: Decorator[] (默认值:null,不包含在构建器函数中)

  • override: boolean (默认值:null,不包含在构建器函数中)

  • readonly: boolean (默认值:null,不包含在构建器函数中)

别名:TypeScriptLVal


tsParenthesizedType

JavaScript
t.tsParenthesizedType(typeAnnotation);

另见 t.isTSParenthesizedType(node, opts)t.assertTSParenthesizedType(node, opts)

AST 节点 TSParenthesizedType 结构:

  • typeAnnotation: TSType (必填)

别名:TypeScript, TSType


tsPropertySignature

JavaScript
t.tsPropertySignature(key, typeAnnotation);

另见 t.isTSPropertySignature(node, opts)t.assertTSPropertySignature(node, opts)

AST 节点 TSPropertySignature 结构:

  • key: Expression (必需)

  • typeAnnotation: TSTypeAnnotation (默认值:null

  • computed: boolean (默认值:false,不包含在构建器函数中)

  • kind: "get" | "set" (默认值:null,不包含在构建器函数中)

  • optional: boolean (默认值:null,不包含在构建器函数中)

  • readonly: boolean (默认值:null,不包含在构建器函数中)

别名:TypeScriptTSTypeElement


tsQualifiedName

JavaScript
t.tsQualifiedName(left, right);

另见 t.isTSQualifiedName(node, opts)t.assertTSQualifiedName(node, opts)

AST 节点 TSQualifiedName 结构:

  • left: TSEntityName (必需)

  • right: Identifier (必需)

别名:TypeScript, TSEntityName


tsRestType

JavaScript
t.tsRestType(typeAnnotation);

另请参见 t.isTSRestType(node, opts)t.assertTSRestType(node, opts)

AST 节点 TSRestType 结构:

  • typeAnnotation: TSType (必填)

别名:TypeScript, TSType


tsSatisfiesExpression

JavaScript
t.tsSatisfiesExpression(expression, typeAnnotation);
History
VersionChanges
v7.20.0Introduced

另请参见 t.isTSSatisfiesExpression(node, opts)t.assertTSSatisfiesExpression(node, opts)

AST 节点 TSSatisfiesExpression 结构:

  • expression: Expression (必需)

  • typeAnnotation: TSType (必填)

别名: TypeScript, Expression, LVal, PatternLike


tsStringKeyword

JavaScript
t.tsStringKeyword();

另请参见 t.isTSStringKeyword(node, opts)t.assertTSStringKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsSymbolKeyword

JavaScript
t.tsSymbolKeyword();

另请参见 t.isTSSymbolKeyword(node, opts)t.assertTSSymbolKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsTemplateLiteralType

JavaScript
t.tsTemplateLiteralType(quasis, types);

另请参见 t.isTSTemplateLiteralType(node, opts)t.assertTSTemplateLiteralType(node, opts)

AST 节点 TSTemplateLiteralType 结构:

  • quasis: TemplateElement[] (必需)

  • types: TSType[] (必需)

别名:TypeScript, TSType, TSBaseType


tsThisType

JavaScript
t.tsThisType();

另请参见 t.isTSThisType(node, opts)t.assertTSThisType(node, opts)

别名:TypeScript, TSType, TSBaseType


tsTupleType

JavaScript
t.tsTupleType(elementTypes);

另请参见 t.isTSTupleType(node, opts)t.assertTSTupleType(node, opts)

AST 节点 TSTupleType 结构:

  • elementTypes: (TSType | TSNamedTupleMember)[] (必需)

别名:TypeScript, TSType


tsTypeAliasDeclaration

JavaScript
t.tsTypeAliasDeclaration(id, typeParameters, typeAnnotation);

另请参见 t.isTSTypeAliasDeclaration(node, opts)t.assertTSTypeAliasDeclaration(node, opts)

AST 节点 TSTypeAliasDeclaration 结构:

  • id: Identifier (必需)

  • typeParameters: TSTypeParameterDeclaration (默认值: null)

  • typeAnnotation: TSType (必填)

  • declare: boolean (默认: null, 构建函数中排除)

别名: TypeScript, Statement, Declaration


tsTypeAnnotation

JavaScript
t.tsTypeAnnotation(typeAnnotation);

另见 t.isTSTypeAnnotation(node, opts)t.assertTSTypeAnnotation(node, opts)

AST 节点 TSTypeAnnotation 结构:

  • typeAnnotation: TSType (必填)

别名:TypeScript


tsTypeAssertion

JavaScript
t.tsTypeAssertion(typeAnnotation, expression);

另见 t.isTSTypeAssertion(node, opts)t.assertTSTypeAssertion(node, opts)

AST 节点 TSTypeAssertion 结构:

  • typeAnnotation: TSType (必填)

  • expression: Expression (必需)

别名: TypeScript, Expression, LVal, PatternLike


tsTypeLiteral

JavaScript
t.tsTypeLiteral(members);

另见 t.isTSTypeLiteral(node, opts)t.assertTSTypeLiteral(node, opts)

AST 节点 TSTypeLiteral 结构:

  • members: TSTypeElement[] (必需)

别名:TypeScript, TSType


tsTypeOperator

JavaScript
t.tsTypeOperator(typeAnnotation, operator);

另见 t.isTSTypeOperator(node, opts)t.assertTSTypeOperator(node, opts)

AST 节点 TSTypeOperator 结构:

  • typeAnnotation: TSType (必填)

  • operator: string (默认值: 'keyof')

别名:TypeScript, TSType


tsTypeParameter

JavaScript
t.tsTypeParameter(constraint, default, name);
History
VersionChanges
v7.21.0Supports const

另见 t.isTSTypeParameter(node, opts)t.assertTSTypeParameter(node, opts)

AST 节点 TSTypeParameter 结构:

  • constraint: TSType (默认值: null)

  • default: TSType (默认值: null)

  • name: string (必填)

  • const: boolean (默认值: null, 构建器函数中排除)

  • in: boolean (默认值: null, 构建器函数中排除)

  • out: boolean (默认值: null, 构建器函数中排除)

别名:TypeScript


tsTypeParameterDeclaration

JavaScript
t.tsTypeParameterDeclaration(params);

另见 t.isTSTypeParameterDeclaration(node, opts)t.assertTSTypeParameterDeclaration(node, opts)

AST 节点 TSTypeParameterDeclaration 结构:

  • params: TSTypeParameter[] (必需)

别名:TypeScript


tsTypeParameterInstantiation

JavaScript
t.tsTypeParameterInstantiation(params);

另请参阅 t.isTSTypeParameterInstantiation(node, opts)t.assertTSTypeParameterInstantiation(node, opts)

AST 节点 TSTypeParameterInstantiation 的结构:

  • params: TSType[] (必需)

别名:TypeScript


tsTypePredicate

JavaScript
t.tsTypePredicate(parameterName, typeAnnotation, asserts);

另请参阅 t.isTSTypePredicate(node, opts)t.assertTSTypePredicate(node, opts)

AST 节点 TSTypePredicate 的结构:

  • parameterName: Identifier | TSThisType (必填)

  • typeAnnotation: TSTypeAnnotation (默认值:null

  • asserts: boolean (默认值:null

别名:TypeScript, TSType


tsTypeQuery

JavaScript
t.tsTypeQuery(exprName, typeParameters);

另请参阅 t.isTSTypeQuery(node, opts)t.assertTSTypeQuery(node, opts)

AST 节点 TSTypeQuery 的结构:

  • exprName: TSEntityName | TSImportType (必填)

  • typeParameters: TSTypeParameterInstantiation (默认值:null

别名:TypeScript, TSType


tsTypeReference

JavaScript
t.tsTypeReference(typeName, typeParameters);

另请参阅 t.isTSTypeReference(node, opts)t.assertTSTypeReference(node, opts)

AST 节点 TSTypeReference 的结构:

  • typeName: TSEntityName (必填)

  • typeParameters: TSTypeParameterInstantiation (默认值:null

别名:TypeScript, TSType


tsUndefinedKeyword

JavaScript
t.tsUndefinedKeyword();

另请参阅 t.isTSUndefinedKeyword(node, opts)t.assertTSUndefinedKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsUnionType

JavaScript
t.tsUnionType(types);

另请参阅 t.isTSUnionType(node, opts)t.assertTSUnionType(node, opts)

AST 节点 TSUnionType 的结构:

  • types: TSType[] (必需)

别名:TypeScript, TSType


tsUnknownKeyword

JavaScript
t.tsUnknownKeyword();

另请参阅 t.isTSUnknownKeyword(node, opts)t.assertTSUnknownKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


tsVoidKeyword

JavaScript
t.tsVoidKeyword();

另请参阅 t.isTSVoidKeyword(node, opts)t.assertTSVoidKeyword(node, opts)

别名:TypeScript, TSType, TSBaseType


标签模板表达式

JavaScript
t.taggedTemplateExpression(tag, quasi);

另请参阅 t.isTaggedTemplateExpression(node, opts)t.assertTaggedTemplateExpression(node, opts)

AST 节点 TaggedTemplateExpression 的结构:

  • tag: Expression (必需)

  • quasi: TemplateLiteral (必需)

  • typeParameters: TypeParameterInstantiation | TSTypeParameterInstantiation (默认值: null, 不包含在构造器函数中)

别名:Standardized, Expression


模板元素

JavaScript
t.templateElement(value, tail);

另请参阅 t.isTemplateElement(node, opts)t.assertTemplateElement(node, opts)

AST 节点 TemplateElement 的结构:

  • value: { raw: string, cooked?: string } (必需)

  • tail: boolean (默认值: false)

别名: Standardized


模板字面量

JavaScript
t.templateLiteral(quasis, expressions);

另请参阅 t.isTemplateLiteral(node, opts)t.assertTemplateLiteral(node, opts)

AST 节点 TemplateLiteral 的结构:

  • quasis: TemplateElement[] (必需)

  • expressions: (Expression | TSType)[] (必需)

别名:Standardized, Expression, Literal


this 表达式

JavaScript
t.thisExpression();

另请参阅 t.isThisExpression(node, opts)t.assertThisExpression(node, opts)

别名:Standardized, Expression


this 类型注解

JavaScript
t.thisTypeAnnotation();

另请参阅 t.isThisTypeAnnotation(node, opts)t.assertThisTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


throw 语句

JavaScript
t.throwStatement(argument);

另请参阅 t.isThrowStatement(node, opts)t.assertThrowStatement(node, opts)

AST 节点 ThrowStatement 的结构:

  • argument: Expression (必填)

别名:Standardized, Statement, Terminatorless, CompletionStatement


主题引用

JavaScript
t.topicReference();

另请参阅 t.isTopicReference(node, opts)t.assertTopicReference(node, opts)

别名:Expression


try 语句

JavaScript
t.tryStatement(block, handler, finalizer);

另请参阅 t.isTryStatement(node, opts)t.assertTryStatement(node, opts)

AST 节点 TryStatement 的结构:

  • block: BlockStatement (必需)

  • handler: CatchClause (默认值: null)

  • finalizer: BlockStatement (默认值: null)

别名: Standardized, Statement


元组表达式

JavaScript
t.tupleExpression(elements);

另见 t.isTupleExpression(node, opts)t.assertTupleExpression(node, opts)

AST 节点 TupleExpression 的结构:

  • elements: (Expression | SpreadElement)[] (默认值:[])

别名:Expression


tupleTypeAnnotation

JavaScript
t.tupleTypeAnnotation(types);

另见 t.isTupleTypeAnnotation(node, opts)t.assertTupleTypeAnnotation(node, opts)

AST 节点 TupleTypeAnnotation 的结构:

  • types: FlowType[] (必需)

别名:Flow, FlowType


typeAlias

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

另见 t.isTypeAlias(node, opts)t.assertTypeAlias(node, opts)

AST 节点 TypeAlias 的结构:

  • id: Identifier (必需)

  • typeParameters: TypeParameterDeclaration (默认值:null)

  • right: FlowType (必需)

别名:Flow, FlowDeclaration, Statement, Declaration


typeAnnotation

JavaScript
t.typeAnnotation(typeAnnotation);

另见 t.isTypeAnnotation(node, opts)t.assertTypeAnnotation(node, opts)

AST 节点 TypeAnnotation 的结构:

  • typeAnnotation: FlowType (必需)

别名: Flow


typeCastExpression

JavaScript
t.typeCastExpression(expression, typeAnnotation);

另见 t.isTypeCastExpression(node, opts)t.assertTypeCastExpression(node, opts)

AST 节点 TypeCastExpression 的结构:

  • expression: Expression (必需)

  • typeAnnotation: TypeAnnotation (必需)

别名:Flow, ExpressionWrapper, Expression


typeParameter

JavaScript
t.typeParameter(bound, default, variance);

另见 t.isTypeParameter(node, opts)t.assertTypeParameter(node, opts)

AST 节点 TypeParameter 的结构:

  • bound: TypeAnnotation (默认值:null)

  • default: FlowType (默认值:null)

  • variance: Variance (默认值:null)

  • name: string (必填)

别名: Flow


typeParameterDeclaration

JavaScript
t.typeParameterDeclaration(params);

另见 t.isTypeParameterDeclaration(node, opts)t.assertTypeParameterDeclaration(node, opts)

AST 节点 TypeParameterDeclaration 的结构:

  • params: TypeParameter[] (必需)

别名: Flow


typeParameterInstantiation

JavaScript
t.typeParameterInstantiation(params);

另见 t.isTypeParameterInstantiation(node, opts)t.assertTypeParameterInstantiation(node, opts)

AST 节点 TypeParameterInstantiation 的结构:

  • params: FlowType[] (必需)

别名: Flow


typeofTypeAnnotation

JavaScript
t.typeofTypeAnnotation(argument);

另见 t.isTypeofTypeAnnotation(node, opts)t.assertTypeofTypeAnnotation(node, opts)

AST 节点 TypeofTypeAnnotation 结构:

  • argument: FlowType (必填)

别名:Flow, FlowType


unaryExpression

JavaScript
t.unaryExpression(operator, argument, prefix);

另见 t.isUnaryExpression(node, opts)t.assertUnaryExpression(node, opts)

AST 节点 UnaryExpression 结构:

  • operator: "void" | "throw" | "delete" | "!" | "+" | "-" | "~" | "typeof" (必填)

  • argument: Expression (必填)

  • prefix: boolean (默认: true)

别名:Standardized, UnaryLike, Expression


unionTypeAnnotation

JavaScript
t.unionTypeAnnotation(types);

另见 t.isUnionTypeAnnotation(node, opts)t.assertUnionTypeAnnotation(node, opts)

AST 节点 UnionTypeAnnotation 结构:

  • types: FlowType[] (必需)

别名:Flow, FlowType


updateExpression

JavaScript
t.updateExpression(operator, argument, prefix);

另见 t.isUpdateExpression(node, opts)t.assertUpdateExpression(node, opts)

AST 节点 UpdateExpression 结构:

  • operator: "++" | "--" (必填)

  • argument: Expression (必填)

  • prefix: boolean (默认: false)

别名:Standardized, Expression


v8IntrinsicIdentifier

JavaScript
t.v8IntrinsicIdentifier(name);

另见 t.isV8IntrinsicIdentifier(node, opts)t.assertV8IntrinsicIdentifier(node, opts)

AST 节点 V8IntrinsicIdentifier 结构:

  • name: string (必填)

别名:Miscellaneous


variableDeclaration

JavaScript
t.variableDeclaration(kind, declarations);
History
VersionChanges
v7.20.0kind can be "using".
v7.22.0kind can be "await using".

另见 t.isVariableDeclaration(node, opts)t.assertVariableDeclaration(node, opts)

AST 节点 VariableDeclaration 结构:

  • kind: "var" | "let" | "const" | "using" | "await using" (必填)

  • declarations: VariableDeclarator[] (必需)

  • declare: boolean (默认: null, 构建函数中排除)

别名:Standardized, Statement, Declaration


variableDeclarator

JavaScript
t.variableDeclarator(id, init);

另见 t.isVariableDeclarator(node, opts)t.assertVariableDeclarator(node, opts)

AST 节点 VariableDeclarator 结构:

  • id: LVal | VoidPattern (必填)

  • init: Expression (默认值: null)

  • definite: boolean (默认值: null,构建函数中不包含此参数)

别名: Standardized


variance

JavaScript
t.variance(kind);

另请参阅 t.isVariance(node, opts)t.assertVariance(node, opts)

AST 节点 Variance 的结构:

  • kind: "minus" | "plus" (必需)

别名: Flow


voidPattern

JavaScript
t.voidPattern();
History
VersionChanges
v7.28.0Introduced

另请参阅 t.isVoidPattern(node, opts)t.assertVoidPattern(node, opts)

别名: Pattern, PatternLike, FunctionParameter


voidTypeAnnotation

JavaScript
t.voidTypeAnnotation();

另请参阅 t.isVoidTypeAnnotation(node, opts)t.assertVoidTypeAnnotation(node, opts)

别名: Flow, FlowType, FlowBaseAnnotation


whileStatement

JavaScript
t.whileStatement(test, body);

另请参阅 t.isWhileStatement(node, opts)t.assertWhileStatement(node, opts)

AST 节点 WhileStatement 的结构:

  • test: Expression (必需)

  • body: Statement (必需)

别名: Standardized, Statement, BlockParent, Loop, While, Scopable


withStatement

JavaScript
t.withStatement(object, body);

另请参阅 t.isWithStatement(node, opts)t.assertWithStatement(node, opts)

AST 节点 WithStatement 的结构:

  • object: Expression (必需)

  • body: Statement (必需)

别名: Standardized, Statement


yieldExpression

JavaScript
t.yieldExpression(argument, delegate);

另请参阅 t.isYieldExpression(node, opts)t.assertYieldExpression(node, opts)

AST 节点 YieldExpression 的结构:

  • argument: Expression (默认值: null)

  • delegate: boolean (默认值: false)

别名: Standardized, Expression, Terminatorless


别名

Accessor

已弃用。将在 Babel 8 中移除。

JavaScript
t.isAccessor(node);

涵盖节点:

Binary

涵盖 BinaryExpression 和 LogicalExpression 的统称,二者共享相同的 AST 结构。

JavaScript
t.isBinary(node);

涵盖节点:

Block

已弃用。将在 Babel 8 中移除。

JavaScript
t.isBlock(node);

涵盖节点:

BlockParent

涵盖了一组 AST 节点,这些节点会创建带有新 LexicalEnvironment 的执行上下文。换句话说,它们定义了 letconst 声明的作用域。

JavaScript
t.isBlockParent(node);

涵盖节点:

Class

涵盖 ClassExpression 和 ClassDeclaration 节点,它们共享相同的 AST 结构。

JavaScript
t.isClass(node);

涵盖节点:

CompletionStatement

表示完成记录的语句。它们定义了程序的控制流,例如循环何时中断或操作何时抛出严重错误。

JavaScript
t.isCompletionStatement(node);

涵盖节点:

Conditional

涵盖 ConditionalExpression 和 IfStatement 节点,它们共享相同的 AST 结构。

JavaScript
t.isConditional(node);

涵盖节点:

Declaration

涵盖所有声明节点。

JavaScript
t.isDeclaration(node);

涵盖节点:

EnumBody

Flow 枚举体的分组类别。

JavaScript
t.isEnumBody(node);

涵盖节点:

EnumMember

Flow 枚举成员的分组类别。

JavaScript
t.isEnumMember(node);

涵盖节点:

ExportDeclaration

所有 ExportDeclaration 的分组类别。

JavaScript
t.isExportDeclaration(node);

涵盖节点:

Expression

所有 Expression 的分组类别。

JavaScript
t.isExpression(node);

涵盖节点:

ExpressionWrapper

一种没有运行时语义的表达式包装器。

JavaScript
t.isExpressionWrapper(node);

涵盖节点:

Flow

Flow 类型系统定义的 AST 节点集合。

JavaScript
t.isFlow(node);

涵盖节点:

FlowBaseAnnotation

基础 Flow 类型注解的集合。

JavaScript
t.isFlowBaseAnnotation(node);

涵盖节点:

FlowDeclaration

Flow 声明的集合。

JavaScript
t.isFlowDeclaration(node);

涵盖节点:

FlowPredicate

Flow 断言的集合。

JavaScript
t.isFlowPredicate(node);

涵盖节点:

FlowType

Flow 类型注解的集合。

JavaScript
t.isFlowType(node);

涵盖节点:

For

涵盖 ForStatementForXStatement 的类别。

JavaScript
t.isFor(node);

涵盖节点:

ForXStatement

涵盖 ForIn 和 ForOf 语句的类别。

JavaScript
t.isForXStatement(node);

涵盖节点:

Function

涵盖函数和方法的类别,必须包含 bodyparams。注意:FunctionFunctionParent 不同。例如,StaticBlock 属于 FunctionParent 但不属于 Function

JavaScript
t.isFunction(node);

涵盖节点:

FunctionParameter

涵盖函数参数的类别。它们是形参列表的组成部分。

JavaScript
t.isFunctionParameter(node);

涵盖节点:

FunctionParent

覆盖了通过新建 VariableEnvironment 启动执行上下文的 AST 节点。这些节点定义了 var 声明的范围。从 Babel 7 开始,FunctionParent 不再包含 Program 节点。

JavaScript
t.isFunctionParent(node);

涵盖节点:

不可变

覆盖不可变对象和 JSX 元素。当对象创建后无法再定义其他属性时,该对象即为不可变对象。

JavaScript
t.isImmutable(node);

涵盖节点:

导入或导出声明

History
VersionChanges
v7.21.0Introduced

覆盖 ImportDeclaration 和 ExportDeclaration

JavaScript
t.isImportOrExportDeclaration(node);

涵盖节点:

JSX

覆盖为 JSX 定义的 AST 节点。

JavaScript
t.isJSX(node);

涵盖节点:

LVal

涵盖用于赋值表达式 left 以及 ForXStatement 中的左侧表达式。

JavaScript
t.isLVal(node);

涵盖节点:

Literal

涵盖 LiteralRegular Expression LiteralTemplate Literal

JavaScript
t.isLiteral(node);

涵盖节点:

Loop

涵盖循环语句。

JavaScript
t.isLoop(node);

涵盖节点:

Method

涵盖对象方法和类方法。

JavaScript
t.isMethod(node);

涵盖节点:

杂项

涵盖对开发有时有用的非标准 AST 类型。

JavaScript
t.isMiscellaneous(node);

涵盖节点:

ModuleDeclaration

History
VersionChanges
v7.21.0Deprecated
注意

已弃用,请改用 ImportOrExportDeclaration。迁移说明请参见 PR #15266

JavaScript
t.isModuleDeclaration(node);

涵盖节点:

ModuleSpecifier

涵盖导入/导出说明符的节点类别。注意:它_并非_规范中定义的 ModuleSpecifier

JavaScript
t.isModuleSpecifier(node);

涵盖节点:

ObjectMember

涵盖对象字面量中的成员

JavaScript
t.isObjectMember(node);

涵盖节点:

Pattern

涵盖除 Identifier 外的所有绑定模式

JavaScript
t.isPattern(node);

涵盖节点:

PatternLike

涵盖所有绑定模式

JavaScript
t.isPatternLike(node);

涵盖节点:

Private

涵盖私有类元素和私有标识符。

JavaScript
t.isPrivate(node);

涵盖节点:

Property

涵盖对象属性和类属性。

JavaScript
t.isProperty(node);

涵盖节点:

纯类节点

指没有副作用的 AST 节点。换句话说,即使多次求值也不会产生可观测的行为变化。

JavaScript
t.isPureish(node);

涵盖节点:

作用域节点

覆盖了 FunctionParentBlockParent 类型的节点。

JavaScript
t.isScopable(node);

涵盖节点:

标准节点

指符合 ECMAScript 官方规范的 AST 节点。

JavaScript
t.isStandardized(node);

涵盖节点:

语句

本节涵盖所有语句节点。

JavaScript
t.isStatement(node);

涵盖节点:

TSBaseType

对主要 TypeScript 类型注解的覆盖。

JavaScript
t.isTSBaseType(node);

涵盖节点:

TSEntityName

对 TypeScript 实体的覆盖。

JavaScript
t.isTSEntityName(node);

涵盖节点:

TSType

对 TypeScript 类型注解的覆盖。

JavaScript
t.isTSType(node);

涵盖节点:

TSTypeElement

TypeScript 类型声明的集合。

JavaScript
t.isTSTypeElement(node);

涵盖节点:

Terminatorless

当操作符与操作数间插入行终止符时会改变语义的 AST 节点集合。

JavaScript
t.isTerminatorless(node);

涵盖节点:

TypeScript

TypeScript 专属 AST 节点的集合。

JavaScript
t.isTypeScript(node);

涵盖节点:

一元操作类

涵盖 UnaryExpression 和 SpreadElement 的类别。

JavaScript
t.isUnaryLike(node);

涵盖节点:

用户可空白节点(已弃用)

已弃用。将在 Babel 8 中移除。

JavaScript
t.isUserWhitespacable(node);

涵盖节点:

While 循环节点

涵盖 DoWhileStatement 和 WhileStatement 的类别,它们共享相同的 AST 结构。

JavaScript
t.isWhile(node);

涵盖节点: