swc_xml_ast/
base.rs

1use is_macro::Is;
2use string_enum::StringEnum;
3use swc_atoms::Atom;
4use swc_common::{ast_node, EqIgnoreSpan, Span};
5
6#[ast_node("Document")]
7#[derive(Eq, Hash, EqIgnoreSpan)]
8pub struct Document {
9    pub span: Span,
10    pub children: Vec<Child>,
11}
12
13#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
14pub enum DocumentMode {
15    /// `no-quirks`
16    NoQuirks,
17    /// `limited-quirks`
18    LimitedQuirks,
19    /// `quirks`
20    Quirks,
21}
22
23#[ast_node(no_unknown)]
24#[derive(Eq, Hash, Is, EqIgnoreSpan)]
25pub enum Child {
26    #[tag("DocumentType")]
27    DocumentType(DocumentType),
28    #[tag("Element")]
29    Element(Element),
30    #[tag("Text")]
31    Text(Text),
32    #[tag("CdataSection")]
33    CdataSection(CdataSection),
34    #[tag("Comment")]
35    Comment(Comment),
36    #[tag("ProcessingInstruction")]
37    ProcessingInstruction(ProcessingInstruction),
38}
39
40#[ast_node("DocumentType")]
41#[derive(Eq, Hash, EqIgnoreSpan)]
42pub struct DocumentType {
43    pub span: Span,
44    #[cfg_attr(
45        feature = "encoding-impl",
46        encoding(with = "cbor4ii::core::types::Maybe")
47    )]
48    pub name: Option<Atom>,
49    #[cfg_attr(
50        feature = "encoding-impl",
51        encoding(with = "cbor4ii::core::types::Maybe")
52    )]
53    pub public_id: Option<Atom>,
54    #[cfg_attr(
55        feature = "encoding-impl",
56        encoding(with = "cbor4ii::core::types::Maybe")
57    )]
58    pub system_id: Option<Atom>,
59    #[cfg_attr(
60        feature = "encoding-impl",
61        encoding(with = "cbor4ii::core::types::Maybe")
62    )]
63    pub raw: Option<Atom>,
64}
65
66#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
67#[cfg_attr(
68    feature = "encoding-impl",
69    derive(::swc_common::Encode, ::swc_common::Decode)
70)]
71pub enum Namespace {
72    /// `http://www.w3.org/1999/xhtml`
73    HTML,
74    /// `http://www.w3.org/1998/Math/MathML`
75    MATHML,
76    /// `http://www.w3.org/2000/svg`
77    SVG,
78    /// `http://www.w3.org/1999/xlink`
79    XLINK,
80    /// `http://www.w3.org/XML/1998/namespace`
81    XML,
82    /// `http://www.w3.org/2000/xmlns/`
83    XMLNS,
84}
85
86#[ast_node("Element")]
87#[derive(Eq, Hash, EqIgnoreSpan)]
88pub struct Element {
89    pub span: Span,
90    pub tag_name: Atom,
91    pub attributes: Vec<Attribute>,
92    pub children: Vec<Child>,
93}
94
95#[ast_node("Attribute")]
96#[derive(Eq, Hash, EqIgnoreSpan)]
97pub struct Attribute {
98    pub span: Span,
99    #[cfg_attr(
100        feature = "encoding-impl",
101        encoding(with = "cbor4ii::core::types::Maybe")
102    )]
103    pub namespace: Option<Namespace>,
104    #[cfg_attr(
105        feature = "encoding-impl",
106        encoding(with = "cbor4ii::core::types::Maybe")
107    )]
108    pub prefix: Option<Atom>,
109    pub name: Atom,
110    #[cfg_attr(
111        feature = "encoding-impl",
112        encoding(with = "cbor4ii::core::types::Maybe")
113    )]
114    pub raw_name: Option<Atom>,
115    #[cfg_attr(
116        feature = "encoding-impl",
117        encoding(with = "cbor4ii::core::types::Maybe")
118    )]
119    pub value: Option<Atom>,
120    #[cfg_attr(
121        feature = "encoding-impl",
122        encoding(with = "cbor4ii::core::types::Maybe")
123    )]
124    pub raw_value: Option<Atom>,
125}
126
127#[ast_node("Text")]
128#[derive(Eq, Hash, EqIgnoreSpan)]
129pub struct Text {
130    pub span: Span,
131    pub data: Atom,
132    #[cfg_attr(
133        feature = "encoding-impl",
134        encoding(with = "cbor4ii::core::types::Maybe")
135    )]
136    pub raw: Option<Atom>,
137}
138
139#[ast_node("CdataSection")]
140#[derive(Eq, Hash, EqIgnoreSpan)]
141pub struct CdataSection {
142    pub span: Span,
143    pub data: Atom,
144    #[cfg_attr(
145        feature = "encoding-impl",
146        encoding(with = "cbor4ii::core::types::Maybe")
147    )]
148    pub raw: Option<Atom>,
149}
150
151#[ast_node("ProcessingInstruction")]
152#[derive(Eq, Hash, EqIgnoreSpan)]
153pub struct ProcessingInstruction {
154    pub span: Span,
155    pub target: Atom,
156    pub data: Atom,
157}
158
159#[ast_node("Comment")]
160#[derive(Eq, Hash, EqIgnoreSpan)]
161pub struct Comment {
162    pub span: Span,
163    pub data: Atom,
164    #[cfg_attr(
165        feature = "encoding-impl",
166        encoding(with = "cbor4ii::core::types::Maybe")
167    )]
168    pub raw: Option<Atom>,
169}