diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 2e4504bc23076..311de4501bf62 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -22,9 +22,6 @@ pub struct AstBuilder<'a> { impl<'a> AstBuilder<'a> { /// Build a [`Program`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_program`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `source_type` @@ -59,44 +56,8 @@ impl<'a> AstBuilder<'a> { } } - /// Build a [`Program`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::program`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `source_type` - /// * `source_text` - /// * `comments`: Sorted comments - /// * `hashbang` - /// * `directives` - /// * `body` - #[inline] - pub fn alloc_program( - self, - span: Span, - source_type: SourceType, - source_text: S, - comments: Vec<'a, Comment>, - hashbang: Option>, - directives: Vec<'a, Directive<'a>>, - body: Vec<'a, Statement<'a>>, - ) -> Box<'a, Program<'a>> - where - S: IntoIn<'a, &'a str>, - { - Box::new_in( - self.program(span, source_type, source_text, comments, hashbang, directives, body), - self.allocator, - ) - } - /// Build a [`Program`] with `scope_id`. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_program_with_scope_id`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `source_type` @@ -133,50 +94,6 @@ impl<'a> AstBuilder<'a> { } } - /// Build a [`Program`] with `scope_id`, and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::program_with_scope_id`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `source_type` - /// * `source_text` - /// * `comments`: Sorted comments - /// * `hashbang` - /// * `directives` - /// * `body` - /// * `scope_id` - #[inline] - pub fn alloc_program_with_scope_id( - self, - span: Span, - source_type: SourceType, - source_text: S, - comments: Vec<'a, Comment>, - hashbang: Option>, - directives: Vec<'a, Directive<'a>>, - body: Vec<'a, Statement<'a>>, - scope_id: ScopeId, - ) -> Box<'a, Program<'a>> - where - S: IntoIn<'a, &'a str>, - { - Box::new_in( - self.program_with_scope_id( - span, - source_type, - source_text, - comments, - hashbang, - directives, - body, - scope_id, - ), - self.allocator, - ) - } - /// Build an [`Expression::BooleanLiteral`]. /// /// This node contains a [`BooleanLiteral`] that will be stored in the memory arena. @@ -1511,9 +1428,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`LabelIdentifier`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_label_identifier`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `name` @@ -1525,22 +1439,6 @@ impl<'a> AstBuilder<'a> { LabelIdentifier { span, name: name.into_in(self.allocator) } } - /// Build a [`LabelIdentifier`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::label_identifier`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `name` - #[inline] - pub fn alloc_label_identifier(self, span: Span, name: A) -> Box<'a, LabelIdentifier<'a>> - where - A: IntoIn<'a, Atom<'a>>, - { - Box::new_in(self.label_identifier(span, name), self.allocator) - } - /// Build a [`ThisExpression`]. /// /// If you want the built node to be allocated in the memory arena, @@ -1630,9 +1528,6 @@ impl<'a> AstBuilder<'a> { /// Build an [`Elision`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_elision`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node #[inline] @@ -1640,18 +1535,6 @@ impl<'a> AstBuilder<'a> { Elision { span } } - /// Build an [`Elision`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::elision`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - #[inline] - pub fn alloc_elision(self, span: Span) -> Box<'a, Elision> { - Box::new_in(self.elision(span), self.allocator) - } - /// Build an [`ObjectExpression`]. /// /// If you want the built node to be allocated in the memory arena, @@ -1917,9 +1800,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`TemplateElement`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_template_element`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `value` @@ -1934,30 +1814,8 @@ impl<'a> AstBuilder<'a> { TemplateElement { span, value, tail, lone_surrogates: Default::default() } } - /// Build a [`TemplateElement`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::template_element`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `value` - /// * `tail` - #[inline] - pub fn alloc_template_element( - self, - span: Span, - value: TemplateElementValue<'a>, - tail: bool, - ) -> Box<'a, TemplateElement<'a>> { - Box::new_in(self.template_element(span, value, tail), self.allocator) - } - /// Build a [`TemplateElement`] with `lone_surrogates`. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_template_element_with_lone_surrogates`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `value` @@ -1974,30 +1832,6 @@ impl<'a> AstBuilder<'a> { TemplateElement { span, value, tail, lone_surrogates } } - /// Build a [`TemplateElement`] with `lone_surrogates`, and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::template_element_with_lone_surrogates`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `value` - /// * `tail` - /// * `lone_surrogates`: The template element contains lone surrogates. - #[inline] - pub fn alloc_template_element_with_lone_surrogates( - self, - span: Span, - value: TemplateElementValue<'a>, - tail: bool, - lone_surrogates: bool, - ) -> Box<'a, TemplateElement<'a>> { - Box::new_in( - self.template_element_with_lone_surrogates(span, value, tail, lone_surrogates), - self.allocator, - ) - } - /// Build a [`MemberExpression::ComputedMemberExpression`]. /// /// This node contains a [`ComputedMemberExpression`] that will be stored in the memory arena. @@ -3060,9 +2894,6 @@ impl<'a> AstBuilder<'a> { /// Build an [`AssignmentTargetRest`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_assignment_target_rest`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `target` @@ -3075,23 +2906,6 @@ impl<'a> AstBuilder<'a> { AssignmentTargetRest { span, target } } - /// Build an [`AssignmentTargetRest`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::assignment_target_rest`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `target` - #[inline] - pub fn alloc_assignment_target_rest( - self, - span: Span, - target: AssignmentTarget<'a>, - ) -> Box<'a, AssignmentTargetRest<'a>> { - Box::new_in(self.assignment_target_rest(span, target), self.allocator) - } - /// Build an [`AssignmentTargetMaybeDefault::AssignmentTargetWithDefault`]. /// /// This node contains an [`AssignmentTargetWithDefault`] that will be stored in the memory arena. @@ -3926,9 +3740,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`Directive`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_directive`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `expression`: Directive with any escapes unescaped @@ -3946,33 +3757,8 @@ impl<'a> AstBuilder<'a> { Directive { span, expression, directive: directive.into_in(self.allocator) } } - /// Build a [`Directive`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::directive`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `expression`: Directive with any escapes unescaped - /// * `directive`: Raw content of directive as it appears in source, any escapes left as is - #[inline] - pub fn alloc_directive( - self, - span: Span, - expression: StringLiteral<'a>, - directive: A, - ) -> Box<'a, Directive<'a>> - where - A: IntoIn<'a, Atom<'a>>, - { - Box::new_in(self.directive(span, expression, directive), self.allocator) - } - /// Build a [`Hashbang`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_hashbang`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `value` @@ -3984,22 +3770,6 @@ impl<'a> AstBuilder<'a> { Hashbang { span, value: value.into_in(self.allocator) } } - /// Build a [`Hashbang`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::hashbang`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `value` - #[inline] - pub fn alloc_hashbang(self, span: Span, value: A) -> Box<'a, Hashbang<'a>> - where - A: IntoIn<'a, Atom<'a>>, - { - Box::new_in(self.hashbang(span, value), self.allocator) - } - /// Build a [`BlockStatement`]. /// /// If you want the built node to be allocated in the memory arena, @@ -4619,9 +4389,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`VariableDeclarator`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_variable_declarator`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `kind` @@ -4640,29 +4407,6 @@ impl<'a> AstBuilder<'a> { VariableDeclarator { span, kind, id, init, definite } } - /// Build a [`VariableDeclarator`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::variable_declarator`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `kind` - /// * `id` - /// * `init` - /// * `definite` - #[inline] - pub fn alloc_variable_declarator( - self, - span: Span, - kind: VariableDeclarationKind, - id: BindingPattern<'a>, - init: Option>, - definite: bool, - ) -> Box<'a, VariableDeclarator<'a>> { - Box::new_in(self.variable_declarator(span, kind, id, init, definite), self.allocator) - } - /// Build an [`EmptyStatement`]. /// /// If you want the built node to be allocated in the memory arena, @@ -5403,9 +5147,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`SwitchCase`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_switch_case`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `test` @@ -5420,25 +5161,6 @@ impl<'a> AstBuilder<'a> { SwitchCase { span, test, consequent } } - /// Build a [`SwitchCase`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::switch_case`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `test` - /// * `consequent` - #[inline] - pub fn alloc_switch_case( - self, - span: Span, - test: Option>, - consequent: Vec<'a, Statement<'a>>, - ) -> Box<'a, SwitchCase<'a>> { - Box::new_in(self.switch_case(span, test, consequent), self.allocator) - } - /// Build a [`LabeledStatement`]. /// /// If you want the built node to be allocated in the memory arena, @@ -5668,9 +5390,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`CatchParameter`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_catch_parameter`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `pattern`: The bound error @@ -5679,23 +5398,6 @@ impl<'a> AstBuilder<'a> { CatchParameter { span, pattern } } - /// Build a [`CatchParameter`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::catch_parameter`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `pattern`: The bound error - #[inline] - pub fn alloc_catch_parameter( - self, - span: Span, - pattern: BindingPattern<'a>, - ) -> Box<'a, CatchParameter<'a>> { - Box::new_in(self.catch_parameter(span, pattern), self.allocator) - } - /// Build a [`DebuggerStatement`]. /// /// If you want the built node to be allocated in the memory arena, @@ -5722,9 +5424,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`BindingPattern`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_binding_pattern`] instead. - /// /// ## Parameters /// * `kind` /// * `type_annotation` @@ -5742,28 +5441,6 @@ impl<'a> AstBuilder<'a> { BindingPattern { kind, type_annotation: type_annotation.into_in(self.allocator), optional } } - /// Build a [`BindingPattern`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::binding_pattern`] instead. - /// - /// ## Parameters - /// * `kind` - /// * `type_annotation` - /// * `optional` - #[inline] - pub fn alloc_binding_pattern( - self, - kind: BindingPatternKind<'a>, - type_annotation: T1, - optional: bool, - ) -> Box<'a, BindingPattern<'a>> - where - T1: IntoIn<'a, Option>>>, - { - Box::new_in(self.binding_pattern(kind, type_annotation, optional), self.allocator) - } - /// Build a [`BindingPatternKind::BindingIdentifier`]. /// /// This node contains a [`BindingIdentifier`] that will be stored in the memory arena. @@ -5950,9 +5627,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`BindingProperty`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_binding_property`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `key` @@ -5971,29 +5645,6 @@ impl<'a> AstBuilder<'a> { BindingProperty { span, key, value, shorthand, computed } } - /// Build a [`BindingProperty`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::binding_property`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `key` - /// * `value` - /// * `shorthand` - /// * `computed` - #[inline] - pub fn alloc_binding_property( - self, - span: Span, - key: PropertyKey<'a>, - value: BindingPattern<'a>, - shorthand: bool, - computed: bool, - ) -> Box<'a, BindingProperty<'a>> { - Box::new_in(self.binding_property(span, key, value, shorthand, computed), self.allocator) - } - /// Build an [`ArrayPattern`]. /// /// If you want the built node to be allocated in the memory arena, @@ -6358,9 +6009,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`FormalParameter`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_formal_parameter`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `decorators` @@ -6381,34 +6029,6 @@ impl<'a> AstBuilder<'a> { FormalParameter { span, decorators, pattern, accessibility, readonly, r#override } } - /// Build a [`FormalParameter`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::formal_parameter`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `decorators` - /// * `pattern` - /// * `accessibility` - /// * `readonly` - /// * `override` - #[inline] - pub fn alloc_formal_parameter( - self, - span: Span, - decorators: Vec<'a, Decorator<'a>>, - pattern: BindingPattern<'a>, - accessibility: Option, - readonly: bool, - r#override: bool, - ) -> Box<'a, FormalParameter<'a>> { - Box::new_in( - self.formal_parameter(span, decorators, pattern, accessibility, readonly, r#override), - self.allocator, - ) - } - /// Build a [`FunctionBody`]. /// /// If you want the built node to be allocated in the memory arena, @@ -8033,9 +7653,6 @@ impl<'a> AstBuilder<'a> { /// Build an [`ImportAttribute`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_import_attribute`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `key` @@ -8050,25 +7667,6 @@ impl<'a> AstBuilder<'a> { ImportAttribute { span, key, value } } - /// Build an [`ImportAttribute`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::import_attribute`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `key` - /// * `value` - #[inline] - pub fn alloc_import_attribute( - self, - span: Span, - key: ImportAttributeKey<'a>, - value: StringLiteral<'a>, - ) -> Box<'a, ImportAttribute<'a>> { - Box::new_in(self.import_attribute(span, key, value), self.allocator) - } - /// Build an [`ImportAttributeKey::Identifier`]. /// /// ## Parameters @@ -8301,9 +7899,6 @@ impl<'a> AstBuilder<'a> { /// Build an [`ExportSpecifier`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_export_specifier`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `local` @@ -8320,27 +7915,6 @@ impl<'a> AstBuilder<'a> { ExportSpecifier { span, local, exported, export_kind } } - /// Build an [`ExportSpecifier`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::export_specifier`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `local` - /// * `exported` - /// * `export_kind` - #[inline] - pub fn alloc_export_specifier( - self, - span: Span, - local: ModuleExportName<'a>, - exported: ModuleExportName<'a>, - export_kind: ImportOrExportKind, - ) -> Box<'a, ExportSpecifier<'a>> { - Box::new_in(self.export_specifier(span, local, exported, export_kind), self.allocator) - } - /// Build an [`ExportDefaultDeclarationKind::FunctionDeclaration`]. /// /// This node contains a [`Function`] that will be stored in the memory arena. @@ -9241,9 +8815,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`JSXOpeningFragment`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_jsx_opening_fragment`] instead. - /// /// ## Parameters /// * `span`: Node location in source code #[inline] @@ -9251,23 +8822,8 @@ impl<'a> AstBuilder<'a> { JSXOpeningFragment { span } } - /// Build a [`JSXOpeningFragment`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::jsx_opening_fragment`] instead. - /// - /// ## Parameters - /// * `span`: Node location in source code - #[inline] - pub fn alloc_jsx_opening_fragment(self, span: Span) -> Box<'a, JSXOpeningFragment> { - Box::new_in(self.jsx_opening_fragment(span), self.allocator) - } - /// Build a [`JSXClosingFragment`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_jsx_closing_fragment`] instead. - /// /// ## Parameters /// * `span`: Node location in source code #[inline] @@ -9275,18 +8831,6 @@ impl<'a> AstBuilder<'a> { JSXClosingFragment { span } } - /// Build a [`JSXClosingFragment`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::jsx_closing_fragment`] instead. - /// - /// ## Parameters - /// * `span`: Node location in source code - #[inline] - pub fn alloc_jsx_closing_fragment(self, span: Span) -> Box<'a, JSXClosingFragment> { - Box::new_in(self.jsx_closing_fragment(span), self.allocator) - } - /// Build a [`JSXElementName::Identifier`]. /// /// This node contains a [`JSXIdentifier`] that will be stored in the memory arena. @@ -9586,9 +9130,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`JSXEmptyExpression`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_jsx_empty_expression`] instead. - /// /// ## Parameters /// * `span`: Node location in source code #[inline] @@ -9596,18 +9137,6 @@ impl<'a> AstBuilder<'a> { JSXEmptyExpression { span } } - /// Build a [`JSXEmptyExpression`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::jsx_empty_expression`] instead. - /// - /// ## Parameters - /// * `span`: Node location in source code - #[inline] - pub fn alloc_jsx_empty_expression(self, span: Span) -> Box<'a, JSXEmptyExpression> { - Box::new_in(self.jsx_empty_expression(span), self.allocator) - } - /// Build a [`JSXAttributeItem::Attribute`]. /// /// This node contains a [`JSXAttribute`] that will be stored in the memory arena. @@ -10218,9 +9747,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`TSEnumMember`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_ts_enum_member`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `id` @@ -10235,25 +9761,6 @@ impl<'a> AstBuilder<'a> { TSEnumMember { span, id, initializer } } - /// Build a [`TSEnumMember`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::ts_enum_member`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `id` - /// * `initializer` - #[inline] - pub fn alloc_ts_enum_member( - self, - span: Span, - id: TSEnumMemberName<'a>, - initializer: Option>, - ) -> Box<'a, TSEnumMember<'a>> { - Box::new_in(self.ts_enum_member(span, id, initializer), self.allocator) - } - /// Build a [`TSEnumMemberName::Identifier`]. /// /// This node contains an [`IdentifierName`] that will be stored in the memory arena. @@ -12483,9 +11990,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`TSClassImplements`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_ts_class_implements`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `expression` @@ -12507,28 +12011,6 @@ impl<'a> AstBuilder<'a> { } } - /// Build a [`TSClassImplements`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::ts_class_implements`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `expression` - /// * `type_arguments` - #[inline] - pub fn alloc_ts_class_implements( - self, - span: Span, - expression: TSTypeName<'a>, - type_arguments: T1, - ) -> Box<'a, TSClassImplements<'a>> - where - T1: IntoIn<'a, Option>>>, - { - Box::new_in(self.ts_class_implements(span, expression, type_arguments), self.allocator) - } - /// Build a [`TSInterfaceDeclaration`]. /// /// If you want the built node to be allocated in the memory arena, @@ -13504,9 +12986,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`TSIndexSignatureName`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_ts_index_signature_name`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `name` @@ -13529,34 +13008,8 @@ impl<'a> AstBuilder<'a> { } } - /// Build a [`TSIndexSignatureName`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::ts_index_signature_name`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `name` - /// * `type_annotation` - #[inline] - pub fn alloc_ts_index_signature_name( - self, - span: Span, - name: A, - type_annotation: T1, - ) -> Box<'a, TSIndexSignatureName<'a>> - where - A: IntoIn<'a, Atom<'a>>, - T1: IntoIn<'a, Box<'a, TSTypeAnnotation<'a>>>, - { - Box::new_in(self.ts_index_signature_name(span, name, type_annotation), self.allocator) - } - /// Build a [`TSInterfaceHeritage`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_ts_interface_heritage`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `expression` @@ -13578,28 +13031,6 @@ impl<'a> AstBuilder<'a> { } } - /// Build a [`TSInterfaceHeritage`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::ts_interface_heritage`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `expression` - /// * `type_arguments` - #[inline] - pub fn alloc_ts_interface_heritage( - self, - span: Span, - expression: Expression<'a>, - type_arguments: T1, - ) -> Box<'a, TSInterfaceHeritage<'a>> - where - T1: IntoIn<'a, Option>>>, - { - Box::new_in(self.ts_interface_heritage(span, expression, type_arguments), self.allocator) - } - /// Build a [`TSTypePredicate`]. /// /// If you want the built node to be allocated in the memory arena, @@ -14835,9 +14266,6 @@ impl<'a> AstBuilder<'a> { /// Build a [`Decorator`]. /// - /// If you want the built node to be allocated in the memory arena, - /// use [`AstBuilder::alloc_decorator`] instead. - /// /// ## Parameters /// * `span`: The [`Span`] covering this node /// * `expression` @@ -14846,19 +14274,6 @@ impl<'a> AstBuilder<'a> { Decorator { span, expression } } - /// Build a [`Decorator`], and store it in the memory arena. - /// - /// Returns a [`Box`] containing the newly-allocated node. - /// If you want a stack-allocated node, use [`AstBuilder::decorator`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `expression` - #[inline] - pub fn alloc_decorator(self, span: Span, expression: Expression<'a>) -> Box<'a, Decorator<'a>> { - Box::new_in(self.decorator(span, expression), self.allocator) - } - /// Build a [`TSExportAssignment`]. /// /// If you want the built node to be allocated in the memory arena, diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index dfce6d34915d5..71134985e213d 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -209,39 +209,57 @@ fn generate_builder_methods_for_struct_impl( fn_name_base.push_str(fn_name_postfix); } let fn_name = struct_builder_name(&fn_name_base, false); - let alloc_fn_name = struct_builder_name(&fn_name_base, true); - // Generate doc comments + // Only generate an `alloc_*` method if `Box` exists in AST + let alloc_fn_name = if struct_def.containers.box_id.is_some() { + Some(struct_builder_name(&fn_name_base, true)) + } else { + None + }; + + // Generate main builder method let struct_name = struct_def.name(); let article = article_for(struct_name); let fn_doc1 = format!(" Build {article} [`{struct_name}`]{doc_postfix}."); - let fn_doc2 = " If you want the built node to be allocated in the memory arena,"; - let fn_doc3 = format!(" use [`AstBuilder::{alloc_fn_name}`] instead."); - let alloc_doc1 = format!( - " Build {article} [`{struct_name}`]{doc_postfix}, and store it in the memory arena." - ); - let alloc_doc2 = " Returns a [`Box`] containing the newly-allocated node."; - let alloc_doc3 = - format!(" If you want a stack-allocated node, use [`AstBuilder::{fn_name}`] instead."); + let mut fn_docs = quote!( #[doc = #fn_doc1] ); + if let Some(alloc_fn_name) = &alloc_fn_name { + let fn_doc2 = format!(" use [`AstBuilder::{alloc_fn_name}`] instead."); + fn_docs.extend(quote! { + #[doc = ""] + #[doc = " If you want the built node to be allocated in the memory arena,"] + #[doc = #fn_doc2] + }); + } + let params_docs = generate_doc_comment_for_params(params); - quote! { + let method = quote! { ///@@line_break - #[doc = #fn_doc1] - #[doc = ""] - #[doc = #fn_doc2] - #[doc = #fn_doc3] + #fn_docs #params_docs #[inline] pub fn #fn_name #generic_params (self, #fn_params) -> #struct_ty #where_clause { #struct_ident { #fields } } + }; + + let Some(alloc_fn_name) = alloc_fn_name else { return method }; + + // Generate `alloc_*` builder method, if required + let alloc_doc1 = format!( + " Build {article} [`{struct_name}`]{doc_postfix}, and store it in the memory arena." + ); + let alloc_doc2 = + format!(" If you want a stack-allocated node, use [`AstBuilder::{fn_name}`] instead."); + + quote! { + #method ///@@line_break #[doc = #alloc_doc1] #[doc = ""] + #[doc = " Returns a [`Box`] containing the newly-allocated node."] #[doc = #alloc_doc2] - #[doc = #alloc_doc3] #params_docs #[inline] pub fn #alloc_fn_name #generic_params (self, #fn_params) -> Box<'a, #struct_ty> #where_clause {