From 33386ef19752fd809df7e040868a7c78b1356618 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 15 May 2024 22:16:16 +0800 Subject: [PATCH] perf(ast): inline all `ASTBuilder` methods (#3295) --- crates/oxc_ast/src/ast_builder.rs | 207 ++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index a4cf87f4c411..d31f2c6a4e51 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -25,6 +25,7 @@ pub struct AstBuilder<'a> { } impl<'a> AstBuilder<'a> { + #[inline] pub fn new(allocator: &'a Allocator) -> Self { Self { allocator } } @@ -66,6 +67,7 @@ impl<'a> AstBuilder<'a> { Atom::from(String::from_str_in(value, self.allocator).into_bump_str()) } + #[inline] pub fn copy(&self, src: &T) -> T { // SAFETY: // This should be safe as long as `src` is an reference from the allocator. @@ -77,21 +79,25 @@ impl<'a> AstBuilder<'a> { } /// Moves the expression out by replacing it with a null expression. + #[inline] pub fn move_expression(&self, expr: &mut Expression<'a>) -> Expression<'a> { let null_literal = NullLiteral::new(expr.span()); let null_expr = self.literal_null_expression(null_literal); mem::replace(expr, null_expr) } + #[inline] pub fn move_statement(&self, stmt: &mut Statement<'a>) -> Statement<'a> { let empty_stmt = self.empty_statement(stmt.span()); mem::replace(stmt, empty_stmt) } + #[inline] pub fn move_statement_vec(&self, stmts: &mut Vec<'a, Statement<'a>>) -> Vec<'a, Statement<'a>> { mem::replace(stmts, self.new_vec()) } + #[inline] pub fn move_assignment_target( &self, target: &mut AssignmentTarget<'a>, @@ -101,6 +107,7 @@ impl<'a> AstBuilder<'a> { mem::replace(target, dummy) } + #[inline] pub fn move_declaration(&self, decl: &mut Declaration<'a>) -> Declaration<'a> { let empty_decl = self.variable_declaration( Span::default(), @@ -112,6 +119,7 @@ impl<'a> AstBuilder<'a> { mem::replace(decl, empty_decl) } + #[inline] pub fn program( &self, span: Span, @@ -126,6 +134,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Constructors ---------- */ /// `void 0` + #[inline] pub fn void_0(&self) -> Expression<'a> { let left = self.number_literal(Span::default(), 0.0, "0", NumberBase::Decimal); let num = self.literal_number_expression(left); @@ -134,6 +143,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Literals ---------- */ + #[inline] pub fn number_literal( &self, span: Span, @@ -144,18 +154,22 @@ impl<'a> AstBuilder<'a> { NumericLiteral { span, value, raw, base } } + #[inline] pub fn boolean_literal(&self, span: Span, value: bool) -> BooleanLiteral { BooleanLiteral { span, value } } + #[inline] pub fn string_literal(&self, span: Span, name: &str) -> StringLiteral<'a> { StringLiteral::new(span, self.new_atom(name)) } + #[inline] pub fn bigint_literal(&self, span: Span, raw: Atom<'a>, base: BigintBase) -> BigIntLiteral<'a> { BigIntLiteral { span, raw, base } } + #[inline] pub fn template_literal( &self, span: Span, @@ -165,6 +179,7 @@ impl<'a> AstBuilder<'a> { TemplateLiteral { span, quasis, expressions } } + #[inline] pub fn template_element( &self, span: Span, @@ -174,6 +189,7 @@ impl<'a> AstBuilder<'a> { TemplateElement { span, tail, value } } + #[inline] pub fn template_element_value( &self, raw: Atom<'a>, @@ -182,6 +198,7 @@ impl<'a> AstBuilder<'a> { TemplateElementValue { raw, cooked } } + #[inline] pub fn reg_exp_literal( &self, span: Span, @@ -191,42 +208,52 @@ impl<'a> AstBuilder<'a> { RegExpLiteral { span, value: EmptyObject, regex: RegExp { pattern: pattern.into(), flags } } } + #[inline] pub fn literal_string_expression(&self, literal: StringLiteral<'a>) -> Expression<'a> { Expression::StringLiteral(self.alloc(literal)) } + #[inline] pub fn literal_boolean_expression(&self, literal: BooleanLiteral) -> Expression<'a> { Expression::BooleanLiteral(self.alloc(literal)) } + #[inline] pub fn literal_null_expression(&self, literal: NullLiteral) -> Expression<'a> { Expression::NullLiteral(self.alloc(literal)) } + #[inline] pub fn literal_regexp_expression(&self, literal: RegExpLiteral<'a>) -> Expression<'a> { Expression::RegExpLiteral(self.alloc(literal)) } + #[inline] pub fn literal_number_expression(&self, literal: NumericLiteral<'a>) -> Expression<'a> { Expression::NumericLiteral(self.alloc(literal)) } + #[inline] pub fn literal_bigint_expression(&self, literal: BigIntLiteral<'a>) -> Expression<'a> { Expression::BigintLiteral(self.alloc(literal)) } + #[inline] pub fn literal_template_expression(&self, literal: TemplateLiteral<'a>) -> Expression<'a> { Expression::TemplateLiteral(self.alloc(literal)) } + #[inline] pub fn identifier_name(&self, span: Span, name: &str) -> IdentifierName<'a> { IdentifierName::new(span, self.new_atom(name)) } + #[inline] pub fn identifier_reference(&self, span: Span, name: &str) -> IdentifierReference<'a> { IdentifierReference::new(span, self.new_atom(name)) } + #[inline] pub fn identifier_reference_expression( &self, ident: IdentifierReference<'a>, @@ -236,6 +263,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Statements ---------- */ + #[inline] pub fn directive( &self, span: Span, @@ -245,24 +273,29 @@ impl<'a> AstBuilder<'a> { Directive { span, expression, directive } } + #[inline] pub fn hashbang(&self, span: Span, value: Atom<'a>) -> Hashbang<'a> { Hashbang { span, value } } + #[inline] pub fn block(&self, span: Span, body: Vec<'a, Statement<'a>>) -> Box<'a, BlockStatement<'a>> { self.alloc(BlockStatement { span, body }) } + #[inline] pub fn block_statement(&self, block: Box<'a, BlockStatement<'a>>) -> Statement<'a> { Statement::BlockStatement( self.alloc(BlockStatement { span: block.span, body: block.unbox().body }), ) } + #[inline] pub fn break_statement(&self, span: Span, label: Option>) -> Statement<'a> { Statement::BreakStatement(self.alloc(BreakStatement { span, label })) } + #[inline] pub fn continue_statement( &self, span: Span, @@ -271,10 +304,12 @@ impl<'a> AstBuilder<'a> { Statement::ContinueStatement(self.alloc(ContinueStatement { span, label })) } + #[inline] pub fn debugger_statement(&self, span: Span) -> Statement<'a> { Statement::DebuggerStatement(self.alloc(DebuggerStatement { span })) } + #[inline] pub fn using_statement( &self, span: Span, @@ -284,6 +319,7 @@ impl<'a> AstBuilder<'a> { Statement::UsingDeclaration(self.alloc(UsingDeclaration { span, is_await, declarations })) } + #[inline] pub fn do_while_statement( &self, span: Span, @@ -293,14 +329,17 @@ impl<'a> AstBuilder<'a> { Statement::DoWhileStatement(self.alloc(DoWhileStatement { span, body, test })) } + #[inline] pub fn empty_statement(&self, span: Span) -> Statement<'a> { Statement::EmptyStatement(self.alloc(EmptyStatement { span })) } + #[inline] pub fn expression_statement(&self, span: Span, expression: Expression<'a>) -> Statement<'a> { Statement::ExpressionStatement(self.alloc(ExpressionStatement { span, expression })) } + #[inline] pub fn for_in_statement( &self, span: Span, @@ -311,6 +350,7 @@ impl<'a> AstBuilder<'a> { Statement::ForInStatement(self.alloc(ForInStatement { span, left, right, body })) } + #[inline] pub fn for_of_statement( &self, span: Span, @@ -322,6 +362,7 @@ impl<'a> AstBuilder<'a> { Statement::ForOfStatement(self.alloc(ForOfStatement { span, r#await, left, right, body })) } + #[inline] pub fn for_statement( &self, span: Span, @@ -333,6 +374,7 @@ impl<'a> AstBuilder<'a> { Statement::ForStatement(self.alloc(ForStatement { span, init, test, update, body })) } + #[inline] pub fn if_statement( &self, span: Span, @@ -343,6 +385,7 @@ impl<'a> AstBuilder<'a> { Statement::IfStatement(self.alloc(IfStatement { span, test, consequent, alternate })) } + #[inline] pub fn labeled_statement( &self, span: Span, @@ -352,10 +395,12 @@ impl<'a> AstBuilder<'a> { Statement::LabeledStatement(self.alloc(LabeledStatement { span, label, body })) } + #[inline] pub fn return_statement(&self, span: Span, argument: Option>) -> Statement<'a> { Statement::ReturnStatement(self.alloc(ReturnStatement { span, argument })) } + #[inline] pub fn switch_statement( &self, span: Span, @@ -365,6 +410,7 @@ impl<'a> AstBuilder<'a> { Statement::SwitchStatement(self.alloc(SwitchStatement { span, discriminant, cases })) } + #[inline] pub fn switch_case( &self, span: Span, @@ -374,10 +420,12 @@ impl<'a> AstBuilder<'a> { SwitchCase { span, test, consequent } } + #[inline] pub fn throw_statement(&self, span: Span, argument: Expression<'a>) -> Statement<'a> { Statement::ThrowStatement(self.alloc(ThrowStatement { span, argument })) } + #[inline] pub fn try_statement( &self, span: Span, @@ -388,6 +436,7 @@ impl<'a> AstBuilder<'a> { Statement::TryStatement(self.alloc(TryStatement { span, block, handler, finalizer })) } + #[inline] pub fn catch_clause( &self, span: Span, @@ -397,10 +446,12 @@ impl<'a> AstBuilder<'a> { self.alloc(CatchClause { span, param, body }) } + #[inline] pub fn catch_parameter(&self, span: Span, pattern: BindingPattern<'a>) -> CatchParameter<'a> { CatchParameter { span, pattern } } + #[inline] pub fn while_statement( &self, span: Span, @@ -410,6 +461,7 @@ impl<'a> AstBuilder<'a> { Statement::WhileStatement(self.alloc(WhileStatement { span, test, body })) } + #[inline] pub fn with_statement( &self, span: Span, @@ -421,10 +473,12 @@ impl<'a> AstBuilder<'a> { /* ---------- Expressions ---------- */ + #[inline] pub fn super_(&self, span: Span) -> Expression<'a> { Expression::Super(self.alloc(Super { span })) } + #[inline] pub fn meta_property( &self, span: Span, @@ -434,6 +488,7 @@ impl<'a> AstBuilder<'a> { Expression::MetaProperty(self.alloc(MetaProperty { span, meta, property })) } + #[inline] pub fn array_expression( &self, span: Span, @@ -443,6 +498,7 @@ impl<'a> AstBuilder<'a> { Expression::ArrayExpression(self.alloc(ArrayExpression { span, elements, trailing_comma })) } + #[inline] pub fn arrow_function_expression( &self, span: Span, @@ -464,6 +520,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn assignment_expression( &self, span: Span, @@ -479,6 +536,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn array_assignment_target( &self, array: ArrayAssignmentTarget<'a>, @@ -486,6 +544,7 @@ impl<'a> AstBuilder<'a> { AssignmentTarget::ArrayAssignmentTarget(self.alloc(array)) } + #[inline] pub fn array_assignment_target_maybe_default( &self, array: ArrayAssignmentTarget<'a>, @@ -493,6 +552,7 @@ impl<'a> AstBuilder<'a> { AssignmentTargetMaybeDefault::ArrayAssignmentTarget(self.alloc(array)) } + #[inline] pub fn object_assignment_target( &self, array: ObjectAssignmentTarget<'a>, @@ -500,6 +560,7 @@ impl<'a> AstBuilder<'a> { AssignmentTarget::ObjectAssignmentTarget(self.alloc(array)) } + #[inline] pub fn assignment_target_property_property( &self, span: Span, @@ -511,6 +572,7 @@ impl<'a> AstBuilder<'a> { ) } + #[inline] pub fn simple_assignment_target_identifier( &self, ident: IdentifierReference<'a>, @@ -518,6 +580,7 @@ impl<'a> AstBuilder<'a> { AssignmentTarget::AssignmentTargetIdentifier(self.alloc(ident)) } + #[inline] pub fn simple_assignment_target_member_expression( &self, expr: MemberExpression<'a>, @@ -525,10 +588,12 @@ impl<'a> AstBuilder<'a> { AssignmentTarget::from(SimpleAssignmentTarget::from(expr)) } + #[inline] pub fn await_expression(&self, span: Span, argument: Expression<'a>) -> Expression<'a> { Expression::AwaitExpression(self.alloc(AwaitExpression { span, argument })) } + #[inline] pub fn binary_expression( &self, span: Span, @@ -539,6 +604,7 @@ impl<'a> AstBuilder<'a> { Expression::BinaryExpression(self.alloc(BinaryExpression { span, left, operator, right })) } + #[inline] pub fn call_expression( &self, span: Span, @@ -556,14 +622,17 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn chain_expression(&self, span: Span, expression: ChainElement<'a>) -> Expression<'a> { Expression::ChainExpression(self.alloc(ChainExpression { span, expression })) } + #[inline] pub fn class_expression(&self, class: Box<'a, Class<'a>>) -> Expression<'a> { Expression::ClassExpression(class) } + #[inline] pub fn conditional_expression( &self, span: Span, @@ -579,10 +648,12 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn function_expression(&self, function: Box<'a, Function<'a>>) -> Expression<'a> { Expression::FunctionExpression(function) } + #[inline] pub fn import_expression( &self, span: Span, @@ -592,6 +663,7 @@ impl<'a> AstBuilder<'a> { Expression::ImportExpression(self.alloc(ImportExpression { span, source, arguments })) } + #[inline] pub fn logical_expression( &self, span: Span, @@ -602,10 +674,12 @@ impl<'a> AstBuilder<'a> { Expression::LogicalExpression(self.alloc(LogicalExpression { span, left, operator, right })) } + #[inline] pub fn member_expression(&self, expr: MemberExpression<'a>) -> Expression<'a> { Expression::from(expr) } + #[inline] pub fn computed_member( &self, span: Span, @@ -621,6 +695,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn computed_member_expression( &self, span: Span, @@ -631,6 +706,7 @@ impl<'a> AstBuilder<'a> { self.member_expression(self.computed_member(span, object, expression, optional)) } + #[inline] pub fn static_member( &self, span: Span, @@ -646,6 +722,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn static_member_expression( &self, span: Span, @@ -656,6 +733,7 @@ impl<'a> AstBuilder<'a> { self.member_expression(self.static_member(span, object, property, optional)) } + #[inline] pub fn private_field( &self, span: Span, @@ -671,6 +749,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn private_in_expression( &self, span: Span, @@ -685,6 +764,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn private_field_expression( &self, span: Span, @@ -695,6 +775,7 @@ impl<'a> AstBuilder<'a> { self.member_expression(self.private_field(span, object, field, optional)) } + #[inline] pub fn new_expression( &self, span: Span, @@ -710,6 +791,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn object_expression( &self, span: Span, @@ -723,6 +805,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn object_property( &self, span: Span, @@ -737,6 +820,7 @@ impl<'a> AstBuilder<'a> { self.alloc(ObjectProperty { span, kind, key, value, init, method, shorthand, computed }) } + #[inline] pub fn parenthesized_expression( &self, span: Span, @@ -747,6 +831,7 @@ impl<'a> AstBuilder<'a> { ) } + #[inline] pub fn sequence_expression( &self, span: Span, @@ -755,6 +840,7 @@ impl<'a> AstBuilder<'a> { Expression::SequenceExpression(self.alloc(SequenceExpression { span, expressions })) } + #[inline] pub fn tagged_template_expression( &self, span: Span, @@ -770,6 +856,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn template_literal_expression( &self, template_literal: TemplateLiteral<'a>, @@ -777,10 +864,12 @@ impl<'a> AstBuilder<'a> { Expression::TemplateLiteral(self.alloc(template_literal)) } + #[inline] pub fn this_expression(&self, span: Span) -> Expression<'a> { Expression::ThisExpression(self.alloc(ThisExpression { span })) } + #[inline] pub fn unary_expression( &self, span: Span, @@ -790,6 +879,7 @@ impl<'a> AstBuilder<'a> { Expression::UnaryExpression(self.alloc(UnaryExpression { span, operator, argument })) } + #[inline] pub fn update_expression( &self, span: Span, @@ -805,6 +895,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn yield_expression( &self, span: Span, @@ -815,10 +906,12 @@ impl<'a> AstBuilder<'a> { } /* ---------- Functions ---------- */ + #[inline] pub fn function_declaration(&self, func: Box<'a, Function<'a>>) -> Statement<'a> { Statement::FunctionDeclaration(func) } + #[inline] pub fn formal_parameters( &self, span: Span, @@ -829,6 +922,7 @@ impl<'a> AstBuilder<'a> { self.alloc(FormalParameters { span, kind, items, rest }) } + #[inline] pub fn plain_formal_parameter( &self, span: Span, @@ -837,6 +931,7 @@ impl<'a> AstBuilder<'a> { self.formal_parameter(span, pattern, None, false, false, self.new_vec()) } + #[inline] pub fn formal_parameter( &self, span: Span, @@ -849,6 +944,7 @@ impl<'a> AstBuilder<'a> { FormalParameter { span, pattern, accessibility, readonly, r#override, decorators } } + #[inline] pub fn ts_this_parameter( &self, span: Span, @@ -858,6 +954,7 @@ impl<'a> AstBuilder<'a> { TSThisParameter { span, this, type_annotation } } + #[inline] pub fn plain_function( &self, r#type: FunctionType, @@ -881,6 +978,7 @@ impl<'a> AstBuilder<'a> { ) } + #[inline] pub fn function( &self, r#type: FunctionType, @@ -910,6 +1008,7 @@ impl<'a> AstBuilder<'a> { }) } + #[inline] pub fn function_body( &self, span: Span, @@ -921,6 +1020,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Class ---------- */ + #[inline] pub fn class( &self, r#type: ClassType, @@ -948,6 +1048,7 @@ impl<'a> AstBuilder<'a> { }) } + #[inline] pub fn class_body( &self, span: Span, @@ -956,14 +1057,17 @@ impl<'a> AstBuilder<'a> { self.alloc(ClassBody { span, body }) } + #[inline] pub fn class_declaration(&self, class: Box<'a, Class<'a>>) -> Statement<'a> { Statement::ClassDeclaration(class) } + #[inline] pub fn static_block(&self, span: Span, body: Vec<'a, Statement<'a>>) -> ClassElement<'a> { ClassElement::StaticBlock(self.alloc(StaticBlock { span, body })) } + #[inline] pub fn class_property( &self, r#type: PropertyDefinitionType, @@ -992,6 +1096,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn class_constructor(&self, span: Span, value: Box<'a, Function<'a>>) -> ClassElement<'a> { ClassElement::MethodDefinition(self.alloc(MethodDefinition { r#type: MethodDefinitionType::MethodDefinition, @@ -1010,6 +1115,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn accessor_property( &self, r#type: AccessorPropertyType, @@ -1033,6 +1139,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Declarations ---------- */ + #[inline] pub fn variable_declaration( &self, span: Span, @@ -1043,6 +1150,7 @@ impl<'a> AstBuilder<'a> { self.alloc(VariableDeclaration { span, kind, declarations, modifiers }) } + #[inline] pub fn variable_declarator( &self, span: Span, @@ -1054,6 +1162,7 @@ impl<'a> AstBuilder<'a> { VariableDeclarator { span, kind, id, init, definite } } + #[inline] pub fn using_declaration( &self, span: Span, @@ -1065,6 +1174,7 @@ impl<'a> AstBuilder<'a> { /* ---------- Patterns ---------- */ + #[inline] pub fn binding_pattern( &self, kind: BindingPatternKind<'a>, @@ -1074,6 +1184,7 @@ impl<'a> AstBuilder<'a> { BindingPattern { kind, type_annotation, optional } } + #[inline] pub fn binding_pattern_identifier( &self, identifier: BindingIdentifier<'a>, @@ -1081,6 +1192,7 @@ impl<'a> AstBuilder<'a> { BindingPatternKind::BindingIdentifier(self.alloc(identifier)) } + #[inline] pub fn object_pattern( &self, span: Span, @@ -1090,6 +1202,7 @@ impl<'a> AstBuilder<'a> { BindingPatternKind::ObjectPattern(self.alloc(ObjectPattern { span, properties, rest })) } + #[inline] pub fn binding_property( &self, span: Span, @@ -1101,6 +1214,7 @@ impl<'a> AstBuilder<'a> { BindingProperty { span, key, value, shorthand, computed } } + #[inline] pub fn spread_element( &self, span: Span, @@ -1109,6 +1223,7 @@ impl<'a> AstBuilder<'a> { self.alloc(SpreadElement { span, argument }) } + #[inline] pub fn array_pattern( &self, span: Span, @@ -1118,6 +1233,7 @@ impl<'a> AstBuilder<'a> { BindingPatternKind::ArrayPattern(self.alloc(ArrayPattern { span, elements, rest })) } + #[inline] pub fn assignment_pattern( &self, span: Span, @@ -1132,6 +1248,7 @@ impl<'a> AstBuilder<'a> { } } + #[inline] pub fn rest_element( &self, span: Span, @@ -1140,20 +1257,24 @@ impl<'a> AstBuilder<'a> { self.alloc(BindingRestElement { span, argument }) } + #[inline] pub fn property_key_identifier(&self, ident: IdentifierName<'a>) -> PropertyKey<'a> { PropertyKey::StaticIdentifier(self.alloc(ident)) } + #[inline] pub fn property_key_expression(&self, expr: Expression<'a>) -> PropertyKey<'a> { PropertyKey::from(expr) } /* ---------- Modules ---------- */ + #[inline] pub fn module_declaration(&self, decl: ModuleDeclaration<'a>) -> Statement<'a> { Statement::from(decl) } + #[inline] pub fn import_declaration( &self, span: Span, @@ -1165,6 +1286,7 @@ impl<'a> AstBuilder<'a> { self.alloc(ImportDeclaration { span, specifiers, source, with_clause, import_kind }) } + #[inline] pub fn export_all_declaration( &self, span: Span, @@ -1176,6 +1298,7 @@ impl<'a> AstBuilder<'a> { self.alloc(ExportAllDeclaration { span, exported, source, with_clause, export_kind }) } + #[inline] pub fn export_default_declaration( &self, span: Span, @@ -1185,6 +1308,7 @@ impl<'a> AstBuilder<'a> { self.alloc(ExportDefaultDeclaration { span, declaration, exported }) } + #[inline] pub fn export_named_declaration( &self, span: Span, @@ -1204,6 +1328,7 @@ impl<'a> AstBuilder<'a> { }) } + #[inline] pub fn plain_export_named_declaration_declaration( &self, span: Span, @@ -1219,6 +1344,7 @@ impl<'a> AstBuilder<'a> { ) } + #[inline] pub fn plain_export_named_declaration( &self, span: Span, @@ -1236,6 +1362,7 @@ impl<'a> AstBuilder<'a> { } /* ---------- JSX ----------------- */ + #[inline] pub fn jsx_element( &self, span: Span, @@ -1246,6 +1373,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXElement { span, opening_element, closing_element, children }) } + #[inline] pub fn jsx_opening_element( &self, span: Span, @@ -1257,6 +1385,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXOpeningElement { span, self_closing, name, attributes, type_parameters }) } + #[inline] pub fn jsx_closing_element( &self, span: Span, @@ -1265,6 +1394,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXClosingElement { span, name }) } + #[inline] pub fn jsx_fragment( &self, span: Span, @@ -1275,14 +1405,17 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXFragment { span, opening_fragment, closing_fragment, children }) } + #[inline] pub fn jsx_opening_fragment(&self, span: Span) -> JSXOpeningFragment { JSXOpeningFragment { span } } + #[inline] pub fn jsx_closing_fragment(&self, span: Span) -> JSXClosingFragment { JSXClosingFragment { span } } + #[inline] pub fn jsx_namespaced_name( &self, span: Span, @@ -1292,6 +1425,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXNamespacedName { span, namespace, property }) } + #[inline] pub fn jsx_member_expression( &self, span: Span, @@ -1301,6 +1435,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXMemberExpression { span, object, property }) } + #[inline] pub fn jsx_expression_container( &self, span: Span, @@ -1309,6 +1444,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXExpressionContainer { span, expression }) } + #[inline] pub fn jsx_spread_child( &self, span: Span, @@ -1317,10 +1453,12 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXSpreadChild { span, expression }) } + #[inline] pub fn jsx_empty_expression(&self, span: Span) -> JSXEmptyExpression { JSXEmptyExpression { span } } + #[inline] pub fn jsx_attribute( &self, span: Span, @@ -1330,6 +1468,7 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXAttribute { span, name, value }) } + #[inline] pub fn jsx_spread_attribute( &self, span: Span, @@ -1338,15 +1477,18 @@ impl<'a> AstBuilder<'a> { self.alloc(JSXSpreadAttribute { span, argument }) } + #[inline] pub fn jsx_identifier(&self, span: Span, name: Atom<'a>) -> JSXIdentifier<'a> { JSXIdentifier { span, name } } + #[inline] pub fn jsx_text(&self, span: Span, value: Atom<'a>) -> Box<'a, JSXText<'a>> { self.alloc(JSXText { span, value }) } /* ---------- TypeScript ---------- */ + #[inline] pub fn ts_module_declaration( &self, span: Span, @@ -1358,6 +1500,7 @@ impl<'a> AstBuilder<'a> { self.alloc(TSModuleDeclaration { span, id, body, kind, modifiers }) } + #[inline] pub fn ts_type_annotation( &self, span: Span, @@ -1366,18 +1509,22 @@ impl<'a> AstBuilder<'a> { self.alloc(TSTypeAnnotation { span, type_annotation }) } + #[inline] pub fn ts_literal_type(&self, span: Span, literal: TSLiteral<'a>) -> TSType<'a> { TSType::TSLiteralType(self.alloc(TSLiteralType { span, literal })) } + #[inline] pub fn ts_union_type(&self, span: Span, types: Vec<'a, TSType<'a>>) -> TSType<'a> { TSType::TSUnionType(self.alloc(TSUnionType { span, types })) } + #[inline] pub fn ts_intersection_type(&self, span: Span, types: Vec<'a, TSType<'a>>) -> TSType<'a> { TSType::TSIntersectionType(self.alloc(TSIntersectionType { span, types })) } + #[inline] pub fn ts_type_operator_type( &self, span: Span, @@ -1387,10 +1534,12 @@ impl<'a> AstBuilder<'a> { TSType::TSTypeOperatorType(self.alloc(TSTypeOperator { span, operator, type_annotation })) } + #[inline] pub fn ts_array_type(&self, span: Span, element_type: TSType<'a>) -> TSType<'a> { TSType::TSArrayType(self.alloc(TSArrayType { span, element_type })) } + #[inline] pub fn ts_indexed_access_type( &self, span: Span, @@ -1404,6 +1553,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_tuple_type( &self, span: Span, @@ -1412,6 +1562,7 @@ impl<'a> AstBuilder<'a> { TSType::TSTupleType(self.alloc(TSTupleType { span, element_types })) } + #[inline] pub fn ts_type_reference( &self, span: Span, @@ -1421,10 +1572,12 @@ impl<'a> AstBuilder<'a> { TSType::TSTypeReference(self.alloc(TSTypeReference { span, type_name, type_parameters })) } + #[inline] pub fn ts_type_literal(&self, span: Span, members: Vec<'a, TSSignature<'a>>) -> TSType<'a> { TSType::TSTypeLiteral(self.alloc(TSTypeLiteral { span, members })) } + #[inline] pub fn ts_type_implement( &self, span: Span, @@ -1434,6 +1587,7 @@ impl<'a> AstBuilder<'a> { TSClassImplements { span, expression, type_parameters } } + #[inline] pub fn ts_type_parameter( &self, span: Span, @@ -1447,6 +1601,7 @@ impl<'a> AstBuilder<'a> { TSTypeParameter { span, name, constraint, default, r#in, out, r#const } } + #[inline] pub fn ts_type_parameters( &self, span: Span, @@ -1455,6 +1610,7 @@ impl<'a> AstBuilder<'a> { self.alloc(TSTypeParameterDeclaration { span, params }) } + #[inline] pub fn ts_interface_heritages( &self, extends: Vec<'a, (Expression<'a>, Option>>, Span)>, @@ -1469,6 +1625,7 @@ impl<'a> AstBuilder<'a> { ) } + #[inline] pub fn ts_interface_body( &self, span: Span, @@ -1477,6 +1634,7 @@ impl<'a> AstBuilder<'a> { self.alloc(TSInterfaceBody { span, body }) } + #[inline] pub fn ts_index_signature( &self, span: Span, @@ -1492,6 +1650,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_property_signature( &self, span: Span, @@ -1511,6 +1670,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_call_signature_declaration( &self, span: Span, @@ -1528,6 +1688,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_construct_signature_declaration( &self, span: Span, @@ -1543,6 +1704,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_method_signature( &self, span: Span, @@ -1568,6 +1730,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_module_block( &self, span: Span, @@ -1576,6 +1739,7 @@ impl<'a> AstBuilder<'a> { self.alloc(TSModuleBlock { span, body }) } + #[inline] pub fn ts_type_arguments( &self, span: Span, @@ -1584,6 +1748,7 @@ impl<'a> AstBuilder<'a> { self.alloc(TSTypeParameterInstantiation { span, params }) } + #[inline] pub fn ts_as_expression( &self, span: Span, @@ -1593,6 +1758,7 @@ impl<'a> AstBuilder<'a> { Expression::TSAsExpression(self.alloc(TSAsExpression { span, expression, type_annotation })) } + #[inline] pub fn ts_satisfies_expression( &self, span: Span, @@ -1606,10 +1772,12 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_non_null_expression(&self, span: Span, expression: Expression<'a>) -> Expression<'a> { Expression::TSNonNullExpression(self.alloc(TSNonNullExpression { span, expression })) } + #[inline] pub fn ts_type_assertion( &self, span: Span, @@ -1623,6 +1791,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_import_equals_declaration( &self, span: Span, @@ -1638,6 +1807,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_interface_declaration( &self, span: Span, @@ -1657,6 +1827,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_type_alias_declaration( &self, span: Span, @@ -1674,6 +1845,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_enum_declaration( &self, span: Span, @@ -1689,62 +1861,77 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn decorator(&self, span: Span, expression: Expression<'a>) -> Decorator<'a> { Decorator { span, expression } } + #[inline] pub fn ts_void_keyword(&self, span: Span) -> TSType<'a> { TSType::TSVoidKeyword(self.alloc(TSVoidKeyword { span })) } + #[inline] pub fn ts_this_keyword(&self, span: Span) -> TSType<'a> { TSType::TSThisType(self.alloc(TSThisType { span })) } + #[inline] pub fn ts_any_keyword(&self, span: Span) -> TSType<'a> { TSType::TSAnyKeyword(self.alloc(TSAnyKeyword { span })) } + #[inline] pub fn ts_unknown_keyword(&self, span: Span) -> TSType<'a> { TSType::TSUnknownKeyword(self.alloc(TSUnknownKeyword { span })) } + #[inline] pub fn ts_number_keyword(&self, span: Span) -> TSType<'a> { TSType::TSNumberKeyword(self.alloc(TSNumberKeyword { span })) } + #[inline] pub fn ts_boolean_keyword(&self, span: Span) -> TSType<'a> { TSType::TSBooleanKeyword(self.alloc(TSBooleanKeyword { span })) } + #[inline] pub fn ts_object_keyword(&self, span: Span) -> TSType<'a> { TSType::TSObjectKeyword(self.alloc(TSObjectKeyword { span })) } + #[inline] pub fn ts_string_keyword(&self, span: Span) -> TSType<'a> { TSType::TSStringKeyword(self.alloc(TSStringKeyword { span })) } + #[inline] pub fn ts_bigint_keyword(&self, span: Span) -> TSType<'a> { TSType::TSBigIntKeyword(self.alloc(TSBigIntKeyword { span })) } + #[inline] pub fn ts_symbol_keyword(&self, span: Span) -> TSType<'a> { TSType::TSSymbolKeyword(self.alloc(TSSymbolKeyword { span })) } + #[inline] pub fn ts_null_keyword(&self, span: Span) -> TSType<'a> { TSType::TSNullKeyword(self.alloc(TSNullKeyword { span })) } + #[inline] pub fn ts_undefined_keyword(&self, span: Span) -> TSType<'a> { TSType::TSUndefinedKeyword(self.alloc(TSUndefinedKeyword { span })) } + #[inline] pub fn ts_never_keyword(&self, span: Span) -> TSType<'a> { TSType::TSNeverKeyword(self.alloc(TSNeverKeyword { span })) } + #[inline] pub fn ts_template_literal_type( &self, span: Span, @@ -1754,6 +1941,7 @@ impl<'a> AstBuilder<'a> { TSType::TSTemplateLiteralType(self.alloc(TSTemplateLiteralType { span, quasis, types })) } + #[inline] pub fn ts_type_query_type( &self, span: Span, @@ -1763,6 +1951,7 @@ impl<'a> AstBuilder<'a> { TSType::TSTypeQuery(self.alloc(TSTypeQuery { span, expr_name, type_parameters })) } + #[inline] pub fn ts_conditional_type( &self, span: Span, @@ -1780,6 +1969,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_mapped_type( &self, span: Span, @@ -1799,6 +1989,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_import_type( &self, span: Span, @@ -1816,6 +2007,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_constructor_type( &self, span: Span, @@ -1833,6 +2025,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_function_type( &self, span: Span, @@ -1850,6 +2043,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_infer_type( &self, span: Span, @@ -1858,6 +2052,7 @@ impl<'a> AstBuilder<'a> { TSType::TSInferType(self.alloc(TSInferType { span, type_parameter })) } + #[inline] pub fn ts_type_predicate( &self, span: Span, @@ -1873,6 +2068,7 @@ impl<'a> AstBuilder<'a> { })) } + #[inline] pub fn ts_enum_member_name_identifier( &self, ident: IdentifierName<'a>, @@ -1880,6 +2076,7 @@ impl<'a> AstBuilder<'a> { TSEnumMemberName::StaticIdentifier(self.alloc(ident)) } + #[inline] pub fn ts_enum_member_name_string_literal( &self, lit: StringLiteral<'a>, @@ -1887,6 +2084,7 @@ impl<'a> AstBuilder<'a> { TSEnumMemberName::StaticStringLiteral(self.alloc(lit)) } + #[inline] pub fn ts_enum_member_name_computed_property_name( &self, expr: Expression<'a>, @@ -1894,6 +2092,7 @@ impl<'a> AstBuilder<'a> { TSEnumMemberName::from(expr) } + #[inline] pub fn ts_enum_member_name_number_literal( &self, lit: NumericLiteral<'a>, @@ -1901,6 +2100,7 @@ impl<'a> AstBuilder<'a> { TSEnumMemberName::StaticNumericLiteral(self.alloc(lit)) } + #[inline] pub fn ts_module_reference_external_module_reference( &self, reference: TSExternalModuleReference<'a>, @@ -1908,6 +2108,7 @@ impl<'a> AstBuilder<'a> { TSModuleReference::ExternalModuleReference(self.alloc(reference)) } + #[inline] pub fn ts_module_reference_type_name( &self, reference: TSTypeName<'a>, @@ -1915,10 +2116,12 @@ impl<'a> AstBuilder<'a> { TSModuleReference::from(reference) } + #[inline] pub fn ts_type_predicate_name_this(&self, ty: TSThisType) -> TSTypePredicateName<'a> { TSTypePredicateName::This(ty) } + #[inline] pub fn ts_type_predicate_name_identifier( &self, ident: IdentifierName<'a>, @@ -1926,6 +2129,7 @@ impl<'a> AstBuilder<'a> { TSTypePredicateName::Identifier(self.alloc(ident)) } + #[inline] pub fn ts_type_query_expr_name_import_type( &self, ty: TSImportType<'a>, @@ -1933,11 +2137,13 @@ impl<'a> AstBuilder<'a> { TSTypeQueryExprName::TSImportType(self.alloc(ty)) } + #[inline] pub fn ts_type_query_expr_name_type_name(&self, ty: TSTypeName<'a>) -> TSTypeQueryExprName<'a> { TSTypeQueryExprName::from(ty) } /* JSDoc */ + #[inline] pub fn js_doc_nullable_type( &self, span: Span, @@ -1947,6 +2153,7 @@ impl<'a> AstBuilder<'a> { TSType::JSDocNullableType(self.alloc(JSDocNullableType { span, type_annotation, postfix })) } + #[inline] pub fn js_doc_unknown_type(&self, span: Span) -> TSType<'a> { TSType::JSDocUnknownType(self.alloc(JSDocUnknownType { span })) }