-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.d.ts
More file actions
115 lines (96 loc) · 1.95 KB
/
index.d.ts
File metadata and controls
115 lines (96 loc) · 1.95 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
export declare const enum NodeTypes {
TAG = 1,
ATTR = 2,
TEXT = 3,
CDATA = 4,
COMMENT = 8,
DOCUMENT = 9,
DOCTYPE = 10,
DOCUMENT_FRAGMENT = 11,
}
export type ParserState = {
options: ParserOptions
regexCache: Record<string, RegExp>
pos: number
count: number
root: TagNode | null
last: TagNode | null
scryle: ScriptNode | StyleNode | null
builder: TreeBuilder
data: string
}
export type Position = {
start: number
end: number
}
export type Expression = Position & {
text: string
}
export type ExpressionContainer = {
expressions?: Expression[]
unescape?: string
parts?: string[]
}
export type Attribute = Position &
ExpressionContainer & {
name: string
value: string
valueStart?: number
}
export type Node = Position & {
type: NodeTypes
}
export type TagNode = Node & {
type: NodeTypes.TAG
name: string
isRaw?: boolean
isCustom?: boolean
isVoid?: boolean
attributes?: Attribute[]
selfclose?: boolean
}
export type CommentNode = Node & {
type: NodeTypes.COMMENT
}
export type TextNode = Node &
ExpressionContainer & {
type: NodeTypes.TEXT
text: string
}
export type ParsedNode = TagNode | TextNode | CommentNode
export type ParserOutput = {
javascript: ScriptNode | null
css: StyleNode | null
template: TemplateNode | null
}
type TreeBuilder = {
get(): ParserOutput
push(node: ParsedNode): void
}
export type ParserOptions = {
brackets?: [string, string]
comments?: boolean
compact?: boolean
}
export type ParserResult = {
data: string
output: ParserOutput
}
export type RiotNode = TemplateNode | TextNode | ScriptNode | StyleNode
export type TemplateNode = TagNode & {
nodes?: RiotNode[]
}
export type ScriptNode = TagNode & {
name: 'script'
text?: TextNode
}
export type StyleNode = TagNode & {
name: 'style'
text?: TextNode
}
export default function parser(
options: ParserOptions,
treeBuilder?: TreeBuilder,
): {
parse: (data: string) => ParserResult
}