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 NoQuirks,
17 LimitedQuirks,
19 Quirks,
21}
22
23#[ast_node]
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 pub name: Option<Atom>,
45 pub public_id: Option<Atom>,
46 pub system_id: Option<Atom>,
47 pub raw: Option<Atom>,
48}
49
50#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
51pub enum Namespace {
52 HTML,
54 MATHML,
56 SVG,
58 XLINK,
60 XML,
62 XMLNS,
64}
65
66#[ast_node("Element")]
67#[derive(Eq, Hash, EqIgnoreSpan)]
68pub struct Element {
69 pub span: Span,
70 pub tag_name: Atom,
71 pub attributes: Vec<Attribute>,
72 pub children: Vec<Child>,
73}
74
75#[ast_node("Attribute")]
76#[derive(Eq, Hash, EqIgnoreSpan)]
77pub struct Attribute {
78 pub span: Span,
79 pub namespace: Option<Namespace>,
80 pub prefix: Option<Atom>,
81 pub name: Atom,
82 pub raw_name: Option<Atom>,
83 pub value: Option<Atom>,
84 pub raw_value: Option<Atom>,
85}
86
87#[ast_node("Text")]
88#[derive(Eq, Hash, EqIgnoreSpan)]
89pub struct Text {
90 pub span: Span,
91 pub data: Atom,
92 pub raw: Option<Atom>,
93}
94
95#[ast_node("CdataSection")]
96#[derive(Eq, Hash, EqIgnoreSpan)]
97pub struct CdataSection {
98 pub span: Span,
99 pub data: Atom,
100 pub raw: Option<Atom>,
101}
102
103#[ast_node("ProcessingInstruction")]
104#[derive(Eq, Hash, EqIgnoreSpan)]
105pub struct ProcessingInstruction {
106 pub span: Span,
107 pub target: Atom,
108 pub data: Atom,
109}
110
111#[ast_node("Comment")]
112#[derive(Eq, Hash, EqIgnoreSpan)]
113pub struct Comment {
114 pub span: Span,
115 pub data: Atom,
116 pub raw: Option<Atom>,
117}