forked from swc-project/swc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.rs
83 lines (80 loc) · 2.64 KB
/
token.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use swc_atoms::JsWord;
use swc_common::{ast_node, EqIgnoreSpan, Span};
#[ast_node("TokenAndSpan")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct TokenAndSpan {
pub span: Span,
pub token: Token,
}
#[ast_node]
#[derive(Eq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
pub struct AttributeToken {
pub span: Span,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
pub name: JsWord,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
pub raw_name: Option<JsWord>,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
pub value: Option<JsWord>,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
pub raw_value: Option<JsWord>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, EqIgnoreSpan)]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
feature = "rkyv",
archive(bound(
serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \
rkyv::ser::SharedSerializeRegistry",
deserialize = "__D: rkyv::de::SharedDeserializeRegistry"
))
)]
pub enum Token {
Doctype {
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
// Name
name: Option<JsWord>,
// Is force quirks?
force_quirks: bool,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
// Public identifier
public_id: Option<JsWord>,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
// System identifier
system_id: Option<JsWord>,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
// Raw value
raw: Option<JsWord>,
},
StartTag {
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
tag_name: JsWord,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
raw_tag_name: Option<JsWord>,
is_self_closing: bool,
attributes: Vec<AttributeToken>,
},
EndTag {
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
tag_name: JsWord,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
raw_tag_name: Option<JsWord>,
is_self_closing: bool,
attributes: Vec<AttributeToken>,
},
Comment {
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
data: JsWord,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
raw: Option<JsWord>,
},
Character {
value: char,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
raw: Option<JsWord>,
},
Eof,
}