swc_xml_ast/
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
#[cfg(feature = "serde-impl")]
use serde::{Deserialize, Serialize};
use swc_atoms::Atom;
use swc_common::{ast_node, EqIgnoreSpan, Span};

#[ast_node("TokenAndSpan")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct TokenAndSpan {
    pub span: Span,
    pub token: Token,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))]
pub struct AttributeToken {
    pub span: Span,
    pub name: Atom,
    pub raw_name: Option<Atom>,
    pub value: Option<Atom>,
    pub raw_value: Option<Atom>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))]
pub enum Token {
    Doctype {
        // Name
        name: Option<Atom>,
        // Public identifier
        public_id: Option<Atom>,
        // System identifier
        system_id: Option<Atom>,
        // Raw value
        raw: Option<Atom>,
    },
    StartTag {
        tag_name: Atom,
        attributes: Vec<AttributeToken>,
    },
    EndTag {
        tag_name: Atom,
        attributes: Vec<AttributeToken>,
    },
    EmptyTag {
        tag_name: Atom,
        attributes: Vec<AttributeToken>,
    },
    Comment {
        data: Atom,
        raw: Atom,
    },
    Character {
        value: char,
        raw: Option<Atom>,
    },
    ProcessingInstruction {
        target: Atom,
        data: Atom,
    },
    Cdata {
        data: Atom,
        raw: Atom,
    },
    Eof,
}