diff --git a/crates/oxc_ast/src/ast/jsx.rs b/crates/oxc_ast/src/ast/jsx.rs index c3cf3a306b1153..c1f75377927f00 100644 --- a/crates/oxc_ast/src/ast/jsx.rs +++ b/crates/oxc_ast/src/ast/jsx.rs @@ -44,8 +44,11 @@ use super::{inherit_variants, js::*, literal::*, ts::*}; pub struct JSXElement<'a> { #[serde(flatten)] pub span: Span, + /// Opening tag of the element. pub opening_element: Box<'a, JSXOpeningElement<'a>>, + /// Closing tag of the element. Will be [`None`] for self-closing tags. pub closing_element: Option>>, + /// Children of the element. This can be text, other elements, or expressions. pub children: Vec<'a, JSXChild<'a>>, } @@ -89,7 +92,15 @@ pub struct JSXOpeningElement<'a> { /// JSX Closing Element /// -/// Closing tag in a [`JSXElement`]. Not all JSX elements have a closing tag. +/// Closing tag in a [`JSXElement`]. Self-closing tags do not have closing elements. +/// +/// ## Example +/// +/// ```tsx +/// Hello, World! +/// // ^^^ name +/// // <- no closing element +/// ``` #[ast(visit)] #[derive(Debug, Hash)] #[generate_derive(CloneIn, GetSpan, GetSpanMut)] @@ -117,8 +128,11 @@ pub struct JSXClosingElement<'a> { pub struct JSXFragment<'a> { #[serde(flatten)] pub span: Span, + /// `<>` pub opening_fragment: JSXOpeningFragment, + /// `` pub closing_fragment: JSXClosingFragment, + /// Elements inside the fragment. pub children: Vec<'a, JSXChild<'a>>, } @@ -240,6 +254,7 @@ pub enum JSXMemberExpressionObject<'a> { pub struct JSXExpressionContainer<'a> { #[serde(flatten)] pub span: Span, + /// The expression inside the container. pub expression: JSXExpression<'a>, } @@ -276,21 +291,35 @@ pub struct JSXEmptyExpression { // 1.3 JSX Attributes /// JSX Attributes +/// +/// ## Example +/// +/// ```tsx +/// +/// // ^^^^^^^^^ ^^^^^^^ ^^^^^^^^^ +/// // Attribute SpreadAttribute +/// ``` #[ast(visit)] #[derive(Debug, Hash)] #[generate_derive(CloneIn, GetSpan, GetSpanMut)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[serde(untagged)] pub enum JSXAttributeItem<'a> { + /// A `key="value"` attribute Attribute(Box<'a, JSXAttribute<'a>>) = 0, + /// a `{...spread}` attribute SpreadAttribute(Box<'a, JSXSpreadAttribute<'a>>) = 1, } /// JSX Attribute /// +/// An attribute in a JSX opening tag. May or may not have a value. Part of +/// [`JSXAttributeItem`]. +/// /// ## Example /// /// ```tsx +/// // `has-no-value` is a JSXAttribute with no value. /// /// // name ^^^ ^^^^ value #[ast(visit)] @@ -301,7 +330,11 @@ pub enum JSXAttributeItem<'a> { pub struct JSXAttribute<'a> { #[serde(flatten)] pub span: Span, + /// The name of the attribute. This is a prop in React-like applications. pub name: JSXAttributeName<'a>, + /// The value of the attribute. This can be a string literal, an expression, + /// or an element. Will be [`None`] for boolean-like attributes (e.g. + /// `