@@ -22,6 +22,81 @@ use oxc_span::{Atom, Ident};
2222use crate :: { AstBuilder , ast:: * } ;
2323
2424impl < ' a > AstBuilder < ' a > {
25+ /// Build an [`AstroRoot`].
26+ ///
27+ /// ## Parameters
28+ /// * `span`: Node location in source code
29+ /// * `frontmatter`: The frontmatter section between `---` delimiters, containing TypeScript code.
30+ /// * `body`: The HTML body of the Astro file, which can contain JSX expressions.
31+ #[ inline]
32+ pub fn astro_root < T1 > (
33+ self ,
34+ span : Span ,
35+ frontmatter : T1 ,
36+ body : Vec < ' a , JSXChild < ' a > > ,
37+ ) -> AstroRoot < ' a >
38+ where
39+ T1 : IntoIn < ' a , Option < Box < ' a , AstroFrontmatter < ' a > > > > ,
40+ {
41+ AstroRoot { span, frontmatter : frontmatter. into_in ( self . allocator ) , body }
42+ }
43+
44+ /// Build an [`AstroFrontmatter`].
45+ ///
46+ /// If you want the built node to be allocated in the memory arena,
47+ /// use [`AstBuilder::alloc_astro_frontmatter`] instead.
48+ ///
49+ /// ## Parameters
50+ /// * `span`: Node location in source code (includes the `---` delimiters)
51+ /// * `program`: The parsed TypeScript program from the frontmatter content
52+ #[ inline]
53+ pub fn astro_frontmatter ( self , span : Span , program : Program < ' a > ) -> AstroFrontmatter < ' a > {
54+ AstroFrontmatter { span, program }
55+ }
56+
57+ /// Build an [`AstroFrontmatter`], and store it in the memory arena.
58+ ///
59+ /// Returns a [`Box`] containing the newly-allocated node.
60+ /// If you want a stack-allocated node, use [`AstBuilder::astro_frontmatter`] instead.
61+ ///
62+ /// ## Parameters
63+ /// * `span`: Node location in source code (includes the `---` delimiters)
64+ /// * `program`: The parsed TypeScript program from the frontmatter content
65+ #[ inline]
66+ pub fn alloc_astro_frontmatter (
67+ self ,
68+ span : Span ,
69+ program : Program < ' a > ,
70+ ) -> Box < ' a , AstroFrontmatter < ' a > > {
71+ Box :: new_in ( self . astro_frontmatter ( span, program) , self . allocator )
72+ }
73+
74+ /// Build an [`AstroScript`].
75+ ///
76+ /// If you want the built node to be allocated in the memory arena,
77+ /// use [`AstBuilder::alloc_astro_script`] instead.
78+ ///
79+ /// ## Parameters
80+ /// * `span`: Node location in source code (includes the `<script>` tags)
81+ /// * `program`: The parsed TypeScript/JavaScript program from the script content
82+ #[ inline]
83+ pub fn astro_script ( self , span : Span , program : Program < ' a > ) -> AstroScript < ' a > {
84+ AstroScript { span, program }
85+ }
86+
87+ /// Build an [`AstroScript`], and store it in the memory arena.
88+ ///
89+ /// Returns a [`Box`] containing the newly-allocated node.
90+ /// If you want a stack-allocated node, use [`AstBuilder::astro_script`] instead.
91+ ///
92+ /// ## Parameters
93+ /// * `span`: Node location in source code (includes the `<script>` tags)
94+ /// * `program`: The parsed TypeScript/JavaScript program from the script content
95+ #[ inline]
96+ pub fn alloc_astro_script ( self , span : Span , program : Program < ' a > ) -> Box < ' a , AstroScript < ' a > > {
97+ Box :: new_in ( self . astro_script ( span, program) , self . allocator )
98+ }
99+
25100 /// Build a [`Program`].
26101 ///
27102 /// ## Parameters
@@ -9734,6 +9809,18 @@ impl<'a> AstBuilder<'a> {
97349809 JSXChild :: Spread ( self . alloc_jsx_spread_child ( span, expression) )
97359810 }
97369811
9812+ /// Build a [`JSXChild::AstroScript`].
9813+ ///
9814+ /// This node contains an [`AstroScript`] that will be stored in the memory arena.
9815+ ///
9816+ /// ## Parameters
9817+ /// * `span`: Node location in source code (includes the `<script>` tags)
9818+ /// * `program`: The parsed TypeScript/JavaScript program from the script content
9819+ #[ inline]
9820+ pub fn jsx_child_astro_script ( self , span : Span , program : Program < ' a > ) -> JSXChild < ' a > {
9821+ JSXChild :: AstroScript ( self . alloc_astro_script ( span, program) )
9822+ }
9823+
97379824 /// Build a [`JSXSpreadChild`].
97389825 ///
97399826 /// If you want the built node to be allocated in the memory arena,
0 commit comments