use std::cell::Cell;
use oxc_allocator::{Box, CloneIn, Dummy, GetAddress, TakeIn, UnstableAddress, Vec};
use oxc_ast_macros::ast;
use oxc_estree::ESTree;
use oxc_span::{ContentEq, GetSpan, GetSpanMut, Span};
use oxc_str::Str;
use oxc_syntax::node::NodeId;
use super::{inherit_variants, js::*, literal::*, ts::*};
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXElement<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
#[estree(via = JSXElementOpeningElement)]
pub opening_element: Box<'a, JSXOpeningElement<'a>>,
pub children: Vec<'a, JSXChild<'a>>,
pub closing_element: Option<Box<'a, JSXClosingElement<'a>>>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
#[estree(add_fields(selfClosing = JSXOpeningElementSelfClosing))]
pub struct JSXOpeningElement<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub name: JSXElementName<'a>,
#[ts]
pub type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
pub attributes: Vec<'a, JSXAttributeItem<'a>>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXClosingElement<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub name: JSXElementName<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXFragment<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub opening_fragment: JSXOpeningFragment,
pub children: Vec<'a, JSXChild<'a>>,
pub closing_fragment: JSXClosingFragment,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
#[estree(add_fields(attributes = JsEmptyArray, selfClosing = JsFalse))]
pub struct JSXOpeningFragment {
pub node_id: Cell<NodeId>,
pub span: Span,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXClosingFragment {
pub node_id: Cell<NodeId>,
pub span: Span,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXElementName<'a> {
Identifier(Box<'a, JSXIdentifier<'a>>) = 0,
#[estree(via = JSXElementIdentifierReference)]
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 1,
NamespacedName(Box<'a, JSXNamespacedName<'a>>) = 2,
MemberExpression(Box<'a, JSXMemberExpression<'a>>) = 3,
#[estree(via = JSXElementThisExpression)]
ThisExpression(Box<'a, ThisExpression>) = 4,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXNamespacedName<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub namespace: JSXIdentifier<'a>,
pub name: JSXIdentifier<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXMemberExpression<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub object: JSXMemberExpressionObject<'a>,
pub property: JSXIdentifier<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXMemberExpressionObject<'a> {
#[estree(via = JSXElementIdentifierReference)]
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
MemberExpression(Box<'a, JSXMemberExpression<'a>>) = 1,
#[estree(via = JSXElementThisExpression)]
ThisExpression(Box<'a, ThisExpression>) = 2,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXExpressionContainer<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub expression: JSXExpression<'a>,
}
inherit_variants! {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub enum JSXExpression<'a> {
EmptyExpression(JSXEmptyExpression) = 64,
@inherit Expression
}
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXEmptyExpression {
pub node_id: Cell<NodeId>,
pub span: Span,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXAttributeItem<'a> {
Attribute(Box<'a, JSXAttribute<'a>>) = 0,
SpreadAttribute(Box<'a, JSXSpreadAttribute<'a>>) = 1,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXAttribute<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub name: JSXAttributeName<'a>,
pub value: Option<JSXAttributeValue<'a>>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXSpreadAttribute<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub argument: Expression<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXAttributeName<'a> {
Identifier(Box<'a, JSXIdentifier<'a>>) = 0,
NamespacedName(Box<'a, JSXNamespacedName<'a>>) = 1,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXAttributeValue<'a> {
StringLiteral(Box<'a, StringLiteral<'a>>) = 0,
ExpressionContainer(Box<'a, JSXExpressionContainer<'a>>) = 1,
Element(Box<'a, JSXElement<'a>>) = 2,
Fragment(Box<'a, JSXFragment<'a>>) = 3,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXIdentifier<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
#[estree(json_safe)]
pub name: Str<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum JSXChild<'a> {
Text(Box<'a, JSXText<'a>>) = 0,
Element(Box<'a, JSXElement<'a>>) = 1,
Fragment(Box<'a, JSXFragment<'a>>) = 2,
ExpressionContainer(Box<'a, JSXExpressionContainer<'a>>) = 3,
Spread(Box<'a, JSXSpreadChild<'a>>) = 4,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXSpreadChild<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub expression: Expression<'a>,
}
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree, UnstableAddress)]
pub struct JSXText<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub value: Str<'a>,
#[content_eq(skip)]
#[estree(from_span)]
pub raw: Option<Str<'a>>,
}