forked from markuplint/markuplint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
200 lines (173 loc) · 4.91 KB
/
types.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
export interface MLToken {
readonly uuid: string;
raw: string;
startOffset: number;
endOffset: number;
startLine: number;
endLine: number;
startCol: number;
endCol: number;
[extendKey: `__${string}`]: string | number | boolean | null;
}
export type MLASTNodeType =
| 'doctype'
| 'starttag'
| 'endtag'
| 'comment'
| 'text'
| 'omittedtag'
| 'psblock'
| 'html-attr'
| 'ps-attr';
export type MLASTNode = MLASTDoctype | MLASTTag | MLASTComment | MLASTText | MLASTPreprocessorSpecificBlock | MLASTAttr;
export interface MLASTAbstractNode extends MLToken {
readonly type: MLASTNodeType;
nodeName: string;
parentNode: MLASTParentNode | null;
prevNode: MLASTNode | null;
nextNode: MLASTNode | null;
isFragment: boolean;
isGhost: boolean;
}
export interface MLASTDoctype extends MLASTAbstractNode {
readonly type: 'doctype';
name: string;
readonly publicId: string;
readonly systemId: string;
}
export interface MLASTElement extends MLASTAbstractNode {
readonly type: 'starttag';
namespace: string;
elementType: ElementType;
attributes: MLASTAttr[];
hasSpreadAttr: boolean;
childNodes?: MLASTNode[];
pearNode: MLASTElementCloseTag | null;
readonly selfClosingSolidus?: MLToken;
readonly endSpace?: MLToken;
readonly tagOpenChar: string;
readonly tagCloseChar: string;
}
/**
* Element type
*
* - `html`: From native HTML Standard
* - `web-component`: As the Web Component according to HTML Standard
* - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine.
*/
export type ElementType = 'html' | 'web-component' | 'authored';
export interface MLASTElementCloseTag extends MLASTAbstractNode {
readonly type: 'endtag';
readonly namespace: string;
attributes: MLASTAttr[];
childNodes?: MLASTNode[];
pearNode: MLASTTag | null;
readonly tagOpenChar: string;
readonly tagCloseChar: string;
}
export interface MLASTPreprocessorSpecificBlock extends MLASTAbstractNode {
readonly type: 'psblock';
nodeName: string;
parentNode: MLASTParentNode | null;
prevNode: MLASTNode | null;
nextNode: MLASTNode | null;
childNodes?: MLASTNode[];
branchedChildNodes?: MLASTNode[];
}
export type MLASTTag = MLASTElement | MLASTElementCloseTag;
export type MLASTParentNode = MLASTElement | MLASTPreprocessorSpecificBlock;
export interface MLASTComment extends MLASTAbstractNode {
readonly type: 'comment';
}
export interface MLASTText extends MLASTAbstractNode {
readonly type: 'text';
}
export type MLASTAttr = MLASTHTMLAttr | MLASTPreprocessorSpecificAttr;
export interface MLASTHTMLAttr extends MLASTAbstractNode {
readonly type: 'html-attr';
spacesBeforeName: MLToken;
name: MLToken;
spacesBeforeEqual: MLToken;
equal: MLToken;
spacesAfterEqual: MLToken;
startQuote: MLToken;
value: MLToken;
endQuote: MLToken;
isDynamicValue?: true;
isDirective?: true;
potentialName?: string;
candidate?: string;
isDuplicatable: boolean;
parentNode: null;
nextNode: null;
prevNode: null;
isFragment: false;
isGhost: false;
}
export interface MLASTPreprocessorSpecificAttr extends MLASTAbstractNode {
readonly type: 'ps-attr';
readonly potentialName: string;
readonly potentialValue: string;
readonly valueType: 'string' | 'number' | 'boolean' | 'code';
isDuplicatable: boolean;
}
export interface MLASTDocument {
nodeList: MLASTNode[];
readonly isFragment: boolean;
unknownParseError?: string;
}
export interface MLMarkupLanguageParser {
parse(
sourceCode: string,
options?: ParserOptions & {
readonly offsetOffset?: number;
readonly offsetLine?: number;
readonly offsetColumn?: number;
},
): MLASTDocument;
/**
* @default "omittable"
*/
endTag?: EndTagType;
/**
* Detect value as a true if its attribute is booleanish value and omitted.
*
* Ex:
* ```jsx
* <Component aria-hidden />
* ```
*
* In the above, the `aria-hidden` is `true`.
*/
booleanish?: boolean;
}
/**
* The end tag omittable type.
*
* - `"xml"`: Must need an end tag or must self-close
* - `"omittable"`: May omit
* - `"never"`: Never need
*/
export type EndTagType = 'xml' | 'omittable' | 'never';
export type ParserOptions = {
readonly ignoreFrontMatter?: boolean;
readonly authoredElementName?: ParserAuthoredElementNameDistinguishing;
};
export type ParserAuthoredElementNameDistinguishing =
| string
| Readonly<RegExp>
| Readonly<ParserAuthoredElementNameDistinguishingFunction>
| readonly (string | Readonly<RegExp> | ParserAuthoredElementNameDistinguishingFunction)[];
export type ParserAuthoredElementNameDistinguishingFunction = (name: string) => boolean;
export type Parse = MLMarkupLanguageParser['parse'];
export type Walker = (
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
node: MLASTNode,
depth: number,
) => void;
export type NamespaceURI =
| 'http://www.w3.org/1999/xhtml'
| 'http://www.w3.org/2000/svg'
| 'http://www.w3.org/1998/Math/MathML'
| 'http://www.w3.org/1999/xlink';
export type Namespace = 'html' | 'svg' | 'mml' | 'xlink';