svg-eslint-parser 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1982 @@
1
+ import { t as __exportAll } from "./chunk-CzXV76rE.js";
2
+ import { unionWith } from "eslint-visitor-keys";
3
+
4
+ //#region package.json
5
+ var name$1 = "svg-eslint-parser";
6
+ var version = "0.0.5";
7
+
8
+ //#endregion
9
+ //#region src/meta.ts
10
+ const meta = {
11
+ name: name$1,
12
+ version
13
+ };
14
+
15
+ //#endregion
16
+ //#region src/parser/error.ts
17
+ /**
18
+ * parse error
19
+ */
20
+ var ParseError = class extends SyntaxError {
21
+ index;
22
+ lineNumber;
23
+ column;
24
+ constructor(message, offset, line, column) {
25
+ super(message);
26
+ this.name = "ParseError";
27
+ this.index = offset;
28
+ this.lineNumber = line;
29
+ this.column = column;
30
+ }
31
+ };
32
+
33
+ //#endregion
34
+ //#region src/constants/parse.ts
35
+ /**
36
+ * svg comment start
37
+ */
38
+ const COMMENT_START = "<!--";
39
+ /**
40
+ * svg comment end
41
+ */
42
+ const COMMENT_END = "-->";
43
+ /**
44
+ * xml declaration start
45
+ */
46
+ const XML_DECLARATION_START = "<?xml";
47
+ /**
48
+ * xml declaration end
49
+ */
50
+ const XML_DECLARATION_END = "?>";
51
+ /**
52
+ * regexp for open tag start
53
+ * @regex101 https://regex101.com/?regex=%5E%3C%5Cw&flavor=javascript
54
+ */
55
+ const RE_OPEN_TAG_START = /^<\w/;
56
+ /**
57
+ * regexp for open tag name
58
+ * @regex101 https://regex101.com/?regex=%5E%3C%28%5CS%2B%29&flavor=javascript
59
+ */
60
+ const RE_OPEN_TAG_NAME = /^<(\S+)/;
61
+ /**
62
+ * regexp for close tag name
63
+ * @regex101 https://regex101.com/?regex=%5E%3C%5C%2F%28%28%3F%3A.%7C%5Cr%3F%5Cn%29*%29%3E%24&flavor=javascript
64
+ */
65
+ const RE_CLOSE_TAG_NAME = /^<\/((?:.|\r?\n)*)>$/;
66
+ /**
67
+ * regexp for incomplete closing tag
68
+ * @regex101 https://regex101.com/?regex=%3C%5C%2F%5B%5E%3E%5D%2B%24&flavor=javascript
69
+ */
70
+ const RE_INCOMPLETE_CLOSING_TAG = /<\/[^>]+$/;
71
+
72
+ //#endregion
73
+ //#region src/constants/nodeTypes.ts
74
+ let NodeTypes = /* @__PURE__ */ function(NodeTypes$1) {
75
+ NodeTypes$1["Attribute"] = "Attribute";
76
+ NodeTypes$1["AttributeKey"] = "AttributeKey";
77
+ NodeTypes$1["AttributeValue"] = "AttributeValue";
78
+ NodeTypes$1["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
79
+ NodeTypes$1["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
80
+ NodeTypes$1["CloseTag"] = "CloseTag";
81
+ NodeTypes$1["Comment"] = "Comment";
82
+ NodeTypes$1["CommentClose"] = "CommentClose";
83
+ NodeTypes$1["CommentContent"] = "CommentContent";
84
+ NodeTypes$1["CommentOpen"] = "CommentOpen";
85
+ NodeTypes$1["Doctype"] = "Doctype";
86
+ NodeTypes$1["DoctypeAttribute"] = "DoctypeAttribute";
87
+ NodeTypes$1["DoctypeAttributeValue"] = "DoctypeAttributeValue";
88
+ NodeTypes$1["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
89
+ NodeTypes$1["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
90
+ NodeTypes$1["DoctypeClose"] = "DoctypeClose";
91
+ NodeTypes$1["DoctypeOpen"] = "DoctypeOpen";
92
+ NodeTypes$1["Document"] = "Document";
93
+ NodeTypes$1["OpenTagEnd"] = "OpenTagEnd";
94
+ NodeTypes$1["OpenTagStart"] = "OpenTagStart";
95
+ NodeTypes$1["Program"] = "Program";
96
+ NodeTypes$1["Tag"] = "Tag";
97
+ NodeTypes$1["Text"] = "Text";
98
+ NodeTypes$1["XMLDeclaration"] = "XMLDeclaration";
99
+ NodeTypes$1["XMLDeclarationAttribute"] = "XMLDeclarationAttribute";
100
+ NodeTypes$1["XMLDeclarationAttributeKey"] = "XMLDeclarationAttributeKey";
101
+ NodeTypes$1["XMLDeclarationAttributeValue"] = "XMLDeclarationAttributeValue";
102
+ NodeTypes$1["XMLDeclarationAttributeValueWrapperEnd"] = "XMLDeclarationAttributeValueWrapperEnd";
103
+ NodeTypes$1["XMLDeclarationAttributeValueWrapperStart"] = "XMLDeclarationAttributeValueWrapperStart";
104
+ NodeTypes$1["XMLDeclarationClose"] = "XMLDeclarationClose";
105
+ NodeTypes$1["XMLDeclarationOpen"] = "XMLDeclarationOpen";
106
+ return NodeTypes$1;
107
+ }({});
108
+
109
+ //#endregion
110
+ //#region src/constants/tokenTypes.ts
111
+ let TokenTypes = /* @__PURE__ */ function(TokenTypes$1) {
112
+ TokenTypes$1["Attribute"] = "Attribute";
113
+ TokenTypes$1["AttributeAssignment"] = "AttributeAssignment";
114
+ TokenTypes$1["AttributeKey"] = "AttributeKey";
115
+ TokenTypes$1["AttributeValue"] = "AttributeValue";
116
+ TokenTypes$1["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
117
+ TokenTypes$1["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
118
+ TokenTypes$1["CloseTag"] = "CloseTag";
119
+ TokenTypes$1["Comment"] = "Comment";
120
+ TokenTypes$1["CommentClose"] = "CommentClose";
121
+ TokenTypes$1["CommentContent"] = "CommentContent";
122
+ TokenTypes$1["CommentOpen"] = "CommentOpen";
123
+ TokenTypes$1["Doctype"] = "Doctype";
124
+ TokenTypes$1["DoctypeAttributeValue"] = "DoctypeAttributeValue";
125
+ TokenTypes$1["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
126
+ TokenTypes$1["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
127
+ TokenTypes$1["DoctypeClose"] = "DoctypeClose";
128
+ TokenTypes$1["DoctypeOpen"] = "DoctypeOpen";
129
+ TokenTypes$1["Document"] = "Document";
130
+ TokenTypes$1["OpenTagEnd"] = "OpenTagEnd";
131
+ TokenTypes$1["OpenTagStart"] = "OpenTagStart";
132
+ TokenTypes$1["Program"] = "Program";
133
+ TokenTypes$1["Tag"] = "Tag";
134
+ TokenTypes$1["Text"] = "Text";
135
+ TokenTypes$1["XMLDeclarationAttribute"] = "XMLDeclarationAttribute";
136
+ TokenTypes$1["XMLDeclarationAttributeAssignment"] = "XMLDeclarationAttributeAssignment";
137
+ TokenTypes$1["XMLDeclarationAttributeKey"] = "XMLDeclarationAttributeKey";
138
+ TokenTypes$1["XMLDeclarationAttributeValue"] = "XMLDeclarationAttributeValue";
139
+ TokenTypes$1["XMLDeclarationAttributeValueWrapperEnd"] = "XMLDeclarationAttributeValueWrapperEnd";
140
+ TokenTypes$1["XMLDeclarationAttributeValueWrapperStart"] = "XMLDeclarationAttributeValueWrapperStart";
141
+ TokenTypes$1["XMLDeclarationClose"] = "XMLDeclarationClose";
142
+ TokenTypes$1["XMLDeclarationOpen"] = "XMLDeclarationOpen";
143
+ return TokenTypes$1;
144
+ }({});
145
+
146
+ //#endregion
147
+ //#region src/constants/specialChar.ts
148
+ const SPECIAL_CHAR = {
149
+ closingCorner: `>`,
150
+ colon: `:`,
151
+ comma: `,`,
152
+ doubleQuote: `"`,
153
+ equal: `=`,
154
+ exclamation: `!`,
155
+ hyphen: `-`,
156
+ newline: `\n`,
157
+ openingCorner: `<`,
158
+ question: `?`,
159
+ return: `\r`,
160
+ singleQuote: `'`,
161
+ slash: `/`,
162
+ space: ` `,
163
+ tab: `\t`
164
+ };
165
+
166
+ //#endregion
167
+ //#region src/constants/svgElements.ts
168
+ /**
169
+ * @copyright {@link https://github.com/davidohlin/svg-elements}
170
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element}
171
+ */
172
+ const SVG_ELEMENTS = new Set([
173
+ "a",
174
+ "animate",
175
+ "animateMotion",
176
+ "animateTransform",
177
+ "circle",
178
+ "clipPath",
179
+ "color-profile",
180
+ "defs",
181
+ "desc",
182
+ "ellipse",
183
+ "feBlend",
184
+ "feColorMatrix",
185
+ "feComponentTransfer",
186
+ "feComposite",
187
+ "feConvolveMatrix",
188
+ "feDiffuseLighting",
189
+ "feDisplacementMap",
190
+ "feDistantLight",
191
+ "feDropShadow",
192
+ "feFlood",
193
+ "feFuncA",
194
+ "feFuncB",
195
+ "feFuncG",
196
+ "feFuncR",
197
+ "feGaussianBlur",
198
+ "feImage",
199
+ "feMerge",
200
+ "feMergeNode",
201
+ "feMorphology",
202
+ "feOffset",
203
+ "fePointLight",
204
+ "feSpecularLighting",
205
+ "feSpotLight",
206
+ "feTile",
207
+ "feTurbulence",
208
+ "filter",
209
+ "foreignObject",
210
+ "g",
211
+ "image",
212
+ "line",
213
+ "linearGradient",
214
+ "marker",
215
+ "mask",
216
+ "metadata",
217
+ "mpath",
218
+ "path",
219
+ "pattern",
220
+ "polygon",
221
+ "polyline",
222
+ "radialGradient",
223
+ "rect",
224
+ "script",
225
+ "set",
226
+ "stop",
227
+ "style",
228
+ "svg",
229
+ "switch",
230
+ "symbol",
231
+ "text",
232
+ "textPath",
233
+ "title",
234
+ "tspan",
235
+ "use",
236
+ "view"
237
+ ]);
238
+ /**
239
+ * obsolete and deprecated elements
240
+ *
241
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element#obsolete_and_deprecated_elements}
242
+ */
243
+ const DEPRECATED_SVG_ELEMENTS = new Set([
244
+ "altGlyph",
245
+ "altGlyphDef",
246
+ "altGlyphItem",
247
+ "animateColor",
248
+ "cursor",
249
+ "font",
250
+ "font-face",
251
+ "font-face-format",
252
+ "font-face-name",
253
+ "font-face-src",
254
+ "font-face-uri",
255
+ "glyph",
256
+ "glyphRef",
257
+ "hkern",
258
+ "missing-glyph",
259
+ "tref",
260
+ "vkern"
261
+ ]);
262
+ /**
263
+ * self closing svg elements
264
+ */
265
+ const SELF_CLOSING_ELEMENTS = new Set([
266
+ "animate",
267
+ "animateMotion",
268
+ "animateTransform",
269
+ "circle",
270
+ "ellipse",
271
+ "feBlend",
272
+ "feColorMatrix",
273
+ "feComposite",
274
+ "feConvolveMatrix",
275
+ "feDisplacementMap",
276
+ "feDropShadow",
277
+ "feFlood",
278
+ "feGaussianBlur",
279
+ "feImage",
280
+ "feMergeNode",
281
+ "feMorphology",
282
+ "feOffset",
283
+ "fePointLight",
284
+ "feSpotLight",
285
+ "feTile",
286
+ "feTurbulence",
287
+ "image",
288
+ "line",
289
+ "mpath",
290
+ "path",
291
+ "polygon",
292
+ "polyline",
293
+ "rect",
294
+ "set",
295
+ "stop",
296
+ "use",
297
+ "view"
298
+ ]);
299
+
300
+ //#endregion
301
+ //#region src/constants/tokenizerContextTypes.ts
302
+ let TokenizerContextTypes = /* @__PURE__ */ function(TokenizerContextTypes$1) {
303
+ TokenizerContextTypes$1["AttributeKey"] = "AttributeKey";
304
+ TokenizerContextTypes$1["Attributes"] = "Attributes";
305
+ TokenizerContextTypes$1["AttributeValue"] = "AttributeValue";
306
+ TokenizerContextTypes$1["AttributeValueBare"] = "AttributeValueBare";
307
+ TokenizerContextTypes$1["AttributeValueWrapped"] = "AttributeValueWrapped";
308
+ TokenizerContextTypes$1["CloseTag"] = "CloseTag";
309
+ TokenizerContextTypes$1["CommentClose"] = "CommentClose";
310
+ TokenizerContextTypes$1["CommentContent"] = "CommentContent";
311
+ TokenizerContextTypes$1["CommentOpen"] = "CommentOpen";
312
+ TokenizerContextTypes$1["Data"] = "Data";
313
+ TokenizerContextTypes$1["DoctypeAttributeBare"] = "DoctypeAttributeBare";
314
+ TokenizerContextTypes$1["DoctypeAttributes"] = "DoctypeAttributes";
315
+ TokenizerContextTypes$1["DoctypeAttributeWrapped"] = "DoctypeAttributeWrapped";
316
+ TokenizerContextTypes$1["DoctypeClose"] = "DoctypeClose";
317
+ TokenizerContextTypes$1["DoctypeOpen"] = "DoctypeOpen";
318
+ TokenizerContextTypes$1["OpenTagEnd"] = "OpenTagEnd";
319
+ TokenizerContextTypes$1["OpenTagStart"] = "OpenTagStart";
320
+ TokenizerContextTypes$1["XMLDeclarationAttributeKey"] = "XMLDeclarationAttributeKey";
321
+ TokenizerContextTypes$1["XMLDeclarationAttributes"] = "XMLDeclarationAttributes";
322
+ TokenizerContextTypes$1["XMLDeclarationAttributeValue"] = "XMLDeclarationAttributeValue";
323
+ TokenizerContextTypes$1["XMLDeclarationAttributeValueWrapped"] = "XMLDeclarationAttributeValueWrapped";
324
+ TokenizerContextTypes$1["XMLDeclarationClose"] = "XMLDeclarationClose";
325
+ TokenizerContextTypes$1["XMLDeclarationOpen"] = "XMLDeclarationOpen";
326
+ return TokenizerContextTypes$1;
327
+ }({});
328
+
329
+ //#endregion
330
+ //#region src/constants/constructTreeContextTypes.ts
331
+ let ConstructTreeContextTypes = /* @__PURE__ */ function(ConstructTreeContextTypes$1) {
332
+ ConstructTreeContextTypes$1["Attribute"] = "Attribute";
333
+ ConstructTreeContextTypes$1["Attributes"] = "Attributes";
334
+ ConstructTreeContextTypes$1["AttributeValue"] = "AttributeValue";
335
+ ConstructTreeContextTypes$1["Comment"] = "Comment";
336
+ ConstructTreeContextTypes$1["Doctype"] = "Doctype";
337
+ ConstructTreeContextTypes$1["DoctypeAttribute"] = "DoctypeAttribute";
338
+ ConstructTreeContextTypes$1["DoctypeAttributes"] = "DoctypeAttributes";
339
+ ConstructTreeContextTypes$1["Tag"] = "Tag";
340
+ ConstructTreeContextTypes$1["TagContent"] = "TagContent";
341
+ ConstructTreeContextTypes$1["TagName"] = "TagName";
342
+ ConstructTreeContextTypes$1["XMLDeclaration"] = "XMLDeclaration";
343
+ ConstructTreeContextTypes$1["XMLDeclarationAttribute"] = "XMLDeclarationAttribute";
344
+ ConstructTreeContextTypes$1["XMLDeclarationAttributes"] = "XMLDeclarationAttributes";
345
+ ConstructTreeContextTypes$1["XMLDeclarationAttributeValue"] = "XMLDeclarationAttributeValue";
346
+ return ConstructTreeContextTypes$1;
347
+ }({});
348
+
349
+ //#endregion
350
+ //#region src/utils/firstLast.ts
351
+ function first(items) {
352
+ return items[0];
353
+ }
354
+ function last(items) {
355
+ return items[items.length - 1];
356
+ }
357
+
358
+ //#endregion
359
+ //#region src/utils/cloneRange.ts
360
+ function cloneRange(range) {
361
+ return [range[0], range[1]];
362
+ }
363
+
364
+ //#endregion
365
+ //#region src/utils/initIfNone.ts
366
+ function initChildrenIfNone(node) {
367
+ if (!node.children) node.children = [];
368
+ }
369
+ function initAttributesIfNone(node) {
370
+ if (!node.attributes) node.attributes = [];
371
+ }
372
+
373
+ //#endregion
374
+ //#region src/utils/clearParent.ts
375
+ function clearParent(ast) {
376
+ const cleanAst = ast;
377
+ delete cleanAst.parentRef;
378
+ if (Array.isArray(ast.children)) cleanAst.children = ast.children.map((node) => {
379
+ return clearParent(node);
380
+ });
381
+ return cleanAst;
382
+ }
383
+
384
+ //#endregion
385
+ //#region src/utils/getLineInfo.ts
386
+ function isNewLine(code) {
387
+ return code === 10 || code === 13 || code === 8232 || code === 8233;
388
+ }
389
+ function nextLineBreak(code, from, end = code.length) {
390
+ for (let i = from; i < end; i++) {
391
+ const next = code.codePointAt(i);
392
+ if (!next) continue;
393
+ if (isNewLine(next)) return i < end - 1 && next === 13 && code.codePointAt(i + 1) === 10 ? i + 2 : i + 1;
394
+ }
395
+ return -1;
396
+ }
397
+ function getLineInfo(input, offset) {
398
+ for (let line = 1, cur = 0;;) {
399
+ const nextBreak = nextLineBreak(input, cur, offset);
400
+ if (nextBreak < 0) return {
401
+ line,
402
+ column: offset - cur
403
+ };
404
+ ++line;
405
+ cur = nextBreak;
406
+ }
407
+ }
408
+
409
+ //#endregion
410
+ //#region src/utils/isWhitespace.ts
411
+ function isWhitespace(char) {
412
+ return char === SPECIAL_CHAR.space || char === SPECIAL_CHAR.newline || char === SPECIAL_CHAR.return || char === SPECIAL_CHAR.tab;
413
+ }
414
+
415
+ //#endregion
416
+ //#region src/utils/cloneLocation.ts
417
+ function cloneLocation(loc) {
418
+ return {
419
+ start: {
420
+ line: loc.start.line,
421
+ column: loc.start.column
422
+ },
423
+ end: {
424
+ line: loc.end.line,
425
+ column: loc.end.column
426
+ }
427
+ };
428
+ }
429
+
430
+ //#endregion
431
+ //#region src/utils/updateNodeEnd.ts
432
+ function updateNodeEnd(node, token) {
433
+ node.range[1] = token.range[1];
434
+ node.loc.end = { ...token.loc.end };
435
+ }
436
+
437
+ //#endregion
438
+ //#region src/utils/createNodeFrom.ts
439
+ function createNodeFrom(token) {
440
+ const loc = cloneLocation(token.loc);
441
+ const range = cloneRange(token.range);
442
+ return {
443
+ type: token.type,
444
+ value: token.value,
445
+ loc,
446
+ range
447
+ };
448
+ }
449
+
450
+ //#endregion
451
+ //#region src/utils/getLastAttribute.ts
452
+ function getLastAttribute(state) {
453
+ const attributes = state.currentNode.attributes;
454
+ return last(attributes);
455
+ }
456
+
457
+ //#endregion
458
+ //#region src/utils/parseOpenTagName.ts
459
+ function parseOpenTagName(openTagStartTokenContent) {
460
+ const match = openTagStartTokenContent.match(RE_OPEN_TAG_NAME);
461
+ if (match === null) throw new Error(`Unable to parse open tag name.\n${openTagStartTokenContent} does not match pattern of opening tag.`);
462
+ return match[1].toLowerCase();
463
+ }
464
+
465
+ //#endregion
466
+ //#region src/utils/parseCloseTagName.ts
467
+ function parseCloseTagName(closeTagTokenContent) {
468
+ const match = closeTagTokenContent.match(RE_CLOSE_TAG_NAME);
469
+ if (match === null) throw new Error(`Unable to parse close tag name.\n${closeTagTokenContent} does not match pattern of closing tag.`);
470
+ return match[1].trim().toLowerCase();
471
+ }
472
+
473
+ //#endregion
474
+ //#region src/utils/calculateTokenLocation.ts
475
+ function calculateTokenLocation(source, range) {
476
+ return {
477
+ start: getLineInfo(source, range[0]),
478
+ end: getLineInfo(source, range[1])
479
+ };
480
+ }
481
+
482
+ //#endregion
483
+ //#region src/utils/calculateTokenCharactersRange.ts
484
+ function calculateTokenCharactersRange(state, options) {
485
+ const startPosition = state.sourceCode.index() - (state.accumulatedContent.length() - 1) - state.decisionBuffer.length();
486
+ let endPosition;
487
+ if (options.keepBuffer) endPosition = state.sourceCode.index();
488
+ else endPosition = state.sourceCode.index() - state.decisionBuffer.length();
489
+ return [startPosition, endPosition + 1];
490
+ }
491
+
492
+ //#endregion
493
+ //#region src/utils/calculateTokenPosition.ts
494
+ function calculateTokenPosition(state, options) {
495
+ const range = calculateTokenCharactersRange(state, options);
496
+ return {
497
+ range,
498
+ loc: calculateTokenLocation(state.sourceCode.source, range)
499
+ };
500
+ }
501
+
502
+ //#endregion
503
+ //#region src/constructor/handlers/tag.ts
504
+ var tag_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$13 });
505
+ const ATTRIBUTE_START_TOKENS$2 = new Set([TokenTypes.AttributeKey, TokenTypes.AttributeAssignment]);
506
+ function construct$13(token, state) {
507
+ if (token.type === TokenTypes.OpenTagStart) return handleOpenTagStart$1(state, token);
508
+ if (ATTRIBUTE_START_TOKENS$2.has(token.type)) return handleAttributeStart$1(state);
509
+ if (token.type === TokenTypes.OpenTagEnd) return handleOpenTagEnd$2(state, token);
510
+ if (token.type === TokenTypes.CloseTag) return handleCloseTag$1(state, token);
511
+ state.caretPosition++;
512
+ return state;
513
+ }
514
+ function handleOpenTagStart$1(state, token) {
515
+ state.currentNode.openStart = createNodeFrom(token);
516
+ state.currentContext = {
517
+ parentRef: state.currentContext,
518
+ type: ConstructTreeContextTypes.TagName
519
+ };
520
+ return state;
521
+ }
522
+ function handleAttributeStart$1(state) {
523
+ state.currentContext = {
524
+ parentRef: state.currentContext,
525
+ type: ConstructTreeContextTypes.Attributes
526
+ };
527
+ return state;
528
+ }
529
+ function handleOpenTagEnd$2(state, token) {
530
+ const tagName = state.currentNode.name;
531
+ state.currentNode.openEnd = createNodeFrom(token);
532
+ updateNodeEnd(state.currentNode, token);
533
+ if (tagName && SELF_CLOSING_ELEMENTS.has(tagName) && state.currentNode.openEnd.value === "/>") {
534
+ state.currentNode.selfClosing = true;
535
+ state.currentNode = state.currentNode.parentRef;
536
+ state.currentContext = state.currentContext.parentRef;
537
+ state.caretPosition++;
538
+ return state;
539
+ }
540
+ state.currentNode.selfClosing = false;
541
+ state.currentContext = {
542
+ parentRef: state.currentContext,
543
+ type: ConstructTreeContextTypes.TagContent
544
+ };
545
+ state.caretPosition++;
546
+ return state;
547
+ }
548
+ function handleCloseTag$1(state, token) {
549
+ state.currentNode.close = createNodeFrom(token);
550
+ updateNodeEnd(state.currentNode, token);
551
+ state.currentNode = state.currentNode.parentRef;
552
+ state.currentContext = state.currentContext.parentRef;
553
+ state.caretPosition++;
554
+ return state;
555
+ }
556
+
557
+ //#endregion
558
+ //#region src/constructor/handlers/comment.ts
559
+ var comment_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$12 });
560
+ function construct$12(token, state) {
561
+ if (token.type === TokenTypes.CommentOpen) return handleCommentOpen$1(state, token);
562
+ if (token.type === TokenTypes.CommentContent) return handleCommentContent(state, token);
563
+ if (token.type === TokenTypes.CommentClose) return handleCommentClose(state, token);
564
+ return state;
565
+ }
566
+ function handleCommentOpen$1(state, token) {
567
+ state.currentNode.open = createNodeFrom(token);
568
+ state.caretPosition++;
569
+ return state;
570
+ }
571
+ function handleCommentContent(state, token) {
572
+ state.currentNode.value = createNodeFrom(token);
573
+ state.caretPosition++;
574
+ return state;
575
+ }
576
+ function handleCommentClose(state, token) {
577
+ state.currentNode.close = createNodeFrom(token);
578
+ updateNodeEnd(state.currentNode, token);
579
+ state.currentNode = state.currentNode.parentRef;
580
+ state.currentContext = state.currentContext.parentRef;
581
+ state.caretPosition++;
582
+ return state;
583
+ }
584
+
585
+ //#endregion
586
+ //#region src/constructor/handlers/doctype.ts
587
+ var doctype_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$11 });
588
+ const ATTRIBUTES_START_TOKENS = new Set([TokenTypes.DoctypeAttributeWrapperStart, TokenTypes.DoctypeAttributeValue]);
589
+ function construct$11(token, state) {
590
+ if (token.type === TokenTypes.DoctypeOpen) return handleDoctypeOpen$1(state, token);
591
+ if (token.type === TokenTypes.DoctypeClose) return handleDoctypeClose$2(state, token);
592
+ if (ATTRIBUTES_START_TOKENS.has(token.type)) return handleDoctypeAttributes(state);
593
+ state.caretPosition++;
594
+ return state;
595
+ }
596
+ function handleDoctypeOpen$1(state, token) {
597
+ state.currentNode.open = createNodeFrom(token);
598
+ state.caretPosition++;
599
+ return state;
600
+ }
601
+ function handleDoctypeClose$2(state, token) {
602
+ state.currentNode.close = createNodeFrom(token);
603
+ updateNodeEnd(state.currentNode, token);
604
+ state.currentNode = state.currentNode.parentRef;
605
+ state.currentContext = state.currentContext.parentRef;
606
+ state.caretPosition++;
607
+ return state;
608
+ }
609
+ function handleDoctypeAttributes(state) {
610
+ state.currentContext = {
611
+ parentRef: state.currentContext,
612
+ type: ConstructTreeContextTypes.DoctypeAttributes
613
+ };
614
+ return state;
615
+ }
616
+
617
+ //#endregion
618
+ //#region src/constructor/handlers/tagName.ts
619
+ var tagName_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$10 });
620
+ function construct$10(token, state) {
621
+ if (token.type === TokenTypes.OpenTagStart) handleTagOpenStart$4(state, token);
622
+ state.caretPosition++;
623
+ return state;
624
+ }
625
+ function handleTagOpenStart$4(state, token) {
626
+ state.currentNode.name = parseOpenTagName(token.value);
627
+ state.currentContext = state.currentContext.parentRef;
628
+ return state;
629
+ }
630
+
631
+ //#endregion
632
+ //#region src/constructor/handlers/attribute.ts
633
+ var attribute_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$9 });
634
+ const OPEN_TAG_END_TOKENS = new Set([TokenTypes.OpenTagEnd]);
635
+ function construct$9(token, state) {
636
+ if (OPEN_TAG_END_TOKENS.has(token.type)) return handleOpenTagEnd$1(state);
637
+ if (token.type === TokenTypes.AttributeKey) return handleAttributeKey(state, token);
638
+ if (token.type === TokenTypes.AttributeAssignment) return handleAttributeAssignment(state);
639
+ state.caretPosition++;
640
+ return state;
641
+ }
642
+ function handleOpenTagEnd$1(state) {
643
+ state.currentContext = state.currentContext.parentRef;
644
+ return state;
645
+ }
646
+ function handleAttributeKey(state, token) {
647
+ const attribute = getLastAttribute(state);
648
+ if (attribute.key !== void 0 || attribute.value !== void 0) {
649
+ state.currentContext = state.currentContext.parentRef;
650
+ return state;
651
+ }
652
+ attribute.key = createNodeFrom(token);
653
+ state.caretPosition++;
654
+ return state;
655
+ }
656
+ function handleAttributeAssignment(state) {
657
+ if (getLastAttribute(state).value !== void 0) {
658
+ state.currentContext = state.currentContext.parentRef;
659
+ return state;
660
+ }
661
+ state.currentContext = {
662
+ parentRef: state.currentContext,
663
+ type: ConstructTreeContextTypes.AttributeValue
664
+ };
665
+ state.caretPosition++;
666
+ return state;
667
+ }
668
+
669
+ //#endregion
670
+ //#region src/constructor/handlers/attributes.ts
671
+ var attributes_exports$1 = /* @__PURE__ */ __exportAll({ construct: () => construct$8 });
672
+ const ATTRIBUTE_START_TOKENS$1 = new Set([TokenTypes.AttributeKey, TokenTypes.AttributeAssignment]);
673
+ const ATTRIBUTE_END_TOKENS = new Set([TokenTypes.OpenTagEnd]);
674
+ function construct$8(token, state) {
675
+ if (ATTRIBUTE_START_TOKENS$1.has(token.type)) return handleAttributeStart(state, token);
676
+ if (ATTRIBUTE_END_TOKENS.has(token.type)) return handleOpenTagEnd(state);
677
+ state.caretPosition++;
678
+ return state;
679
+ }
680
+ function handleAttributeStart(state, token) {
681
+ initAttributesIfNone(state.currentNode);
682
+ state.currentNode.attributes.push({
683
+ type: NodeTypes.Attribute,
684
+ range: cloneRange(token.range),
685
+ loc: cloneLocation(token.loc)
686
+ });
687
+ state.currentContext = {
688
+ parentRef: state.currentContext,
689
+ type: ConstructTreeContextTypes.Attribute
690
+ };
691
+ return state;
692
+ }
693
+ function handleOpenTagEnd(state) {
694
+ state.currentContext = state.currentContext.parentRef;
695
+ return state;
696
+ }
697
+
698
+ //#endregion
699
+ //#region src/constructor/handlers/tagContent.ts
700
+ var tagContent_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$7 });
701
+ function construct$7(token, state) {
702
+ if (token.type === TokenTypes.OpenTagStart) return handleOpenTagStart(state, token);
703
+ if (token.type === TokenTypes.Text) return handleText(state, token);
704
+ if (token.type === TokenTypes.CloseTag) return handleCloseTag(state, token);
705
+ if (token.type === TokenTypes.CommentOpen) return handleCommentOpen(state, token);
706
+ if (token.type === TokenTypes.DoctypeOpen) return handleDoctypeOpen(state, token);
707
+ state.caretPosition++;
708
+ return state;
709
+ }
710
+ function handleOpenTagStart(state, token) {
711
+ initChildrenIfNone(state.currentNode);
712
+ const tagNode = {
713
+ type: NodeTypes.Tag,
714
+ parentRef: state.currentNode,
715
+ range: cloneRange(token.range),
716
+ loc: cloneLocation(token.loc),
717
+ attributes: [],
718
+ children: []
719
+ };
720
+ state.currentNode.children.push(tagNode);
721
+ state.currentNode = tagNode;
722
+ state.currentContext = {
723
+ parentRef: state.currentContext,
724
+ type: ConstructTreeContextTypes.Tag
725
+ };
726
+ return state;
727
+ }
728
+ function handleText(state, token) {
729
+ initChildrenIfNone(state.currentNode);
730
+ const textNode = createNodeFrom(token);
731
+ state.currentNode.children.push(textNode);
732
+ state.caretPosition++;
733
+ return state;
734
+ }
735
+ function handleCloseTag(state, token) {
736
+ if (parseCloseTagName(token.value) !== state.currentNode.name) {
737
+ state.caretPosition++;
738
+ return state;
739
+ }
740
+ state.currentContext = state.currentContext.parentRef;
741
+ return state;
742
+ }
743
+ function handleCommentOpen(state, token) {
744
+ initChildrenIfNone(state.currentNode);
745
+ const commentNode = {
746
+ type: NodeTypes.Comment,
747
+ parentRef: state.currentNode,
748
+ range: cloneRange(token.range),
749
+ loc: cloneLocation(token.loc)
750
+ };
751
+ state.currentNode.children.push(commentNode);
752
+ state.currentNode = commentNode;
753
+ state.currentContext = {
754
+ parentRef: state.currentContext,
755
+ type: ConstructTreeContextTypes.Comment
756
+ };
757
+ return state;
758
+ }
759
+ function handleDoctypeOpen(state, token) {
760
+ initChildrenIfNone(state.currentNode);
761
+ const doctypeNode = {
762
+ type: NodeTypes.Doctype,
763
+ parentRef: state.currentNode,
764
+ range: cloneRange(token.range),
765
+ loc: cloneLocation(token.loc),
766
+ attributes: []
767
+ };
768
+ state.currentNode.children.push(doctypeNode);
769
+ state.currentNode = doctypeNode;
770
+ state.currentContext = {
771
+ parentRef: state.currentContext,
772
+ type: ConstructTreeContextTypes.Doctype
773
+ };
774
+ return state;
775
+ }
776
+
777
+ //#endregion
778
+ //#region src/constructor/handlers/attributeValue.ts
779
+ var attributeValue_exports$1 = /* @__PURE__ */ __exportAll({ construct: () => construct$6 });
780
+ const VALUE_END_TOKENS = new Set([
781
+ TokenTypes.OpenTagEnd,
782
+ TokenTypes.AttributeKey,
783
+ TokenTypes.AttributeAssignment
784
+ ]);
785
+ function construct$6(token, state) {
786
+ if (VALUE_END_TOKENS.has(token.type)) return handleValueEnd(state);
787
+ if (token.type === TokenTypes.AttributeValue) return handleAttributeValue(state, token);
788
+ if (token.type === TokenTypes.AttributeValueWrapperStart) return handleAttributeValueWrapperStart(state, token);
789
+ if (token.type === TokenTypes.AttributeValueWrapperEnd) return handleAttributeValueWrapperEnd(state, token);
790
+ state.caretPosition++;
791
+ return state;
792
+ }
793
+ function handleValueEnd(state) {
794
+ state.currentContext = state.currentContext.parentRef;
795
+ return state;
796
+ }
797
+ function handleAttributeValue(state, token) {
798
+ const attribute = getLastAttribute(state);
799
+ attribute.value = createNodeFrom(token);
800
+ updateNodeEnd(attribute, token);
801
+ state.caretPosition++;
802
+ return state;
803
+ }
804
+ function handleAttributeValueWrapperStart(state, token) {
805
+ const attribute = getLastAttribute(state);
806
+ attribute.startWrapper = createNodeFrom(token);
807
+ if (!attribute.key) {
808
+ attribute.range = cloneRange(token.range);
809
+ attribute.loc = cloneLocation(token.loc);
810
+ }
811
+ state.caretPosition++;
812
+ return state;
813
+ }
814
+ function handleAttributeValueWrapperEnd(state, token) {
815
+ const attribute = getLastAttribute(state);
816
+ attribute.endWrapper = createNodeFrom(token);
817
+ updateNodeEnd(attribute, token);
818
+ state.caretPosition++;
819
+ return state;
820
+ }
821
+
822
+ //#endregion
823
+ //#region src/constructor/handlers/xmlDeclaration.ts
824
+ var xmlDeclaration_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$5 });
825
+ function construct$5(token, state) {
826
+ if (token.type === TokenTypes.OpenTagStart) handleTagOpenStart$3(state, token);
827
+ state.caretPosition++;
828
+ return state;
829
+ }
830
+ function handleTagOpenStart$3(state, token) {
831
+ state.currentNode.name = parseOpenTagName(token.value);
832
+ state.currentContext = state.currentContext.parentRef;
833
+ return state;
834
+ }
835
+
836
+ //#endregion
837
+ //#region src/constructor/handlers/doctypeAttribute.ts
838
+ var doctypeAttribute_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$4 });
839
+ function construct$4(token, state) {
840
+ if (token.type === TokenTypes.DoctypeClose) return handleDoctypeClose$1(state);
841
+ if (token.type === TokenTypes.DoctypeAttributeWrapperStart) return handleDoctypeAttributeWrapperStart(state, token);
842
+ if (token.type === TokenTypes.DoctypeAttributeWrapperEnd) return handleDoctypeAttributeWrapperEnd(state, token);
843
+ if (token.type === TokenTypes.DoctypeAttributeValue) return handleDoctypeAttributeValue(state, token);
844
+ state.caretPosition++;
845
+ return state;
846
+ }
847
+ function handleDoctypeClose$1(state) {
848
+ state.currentContext = state.currentContext.parentRef;
849
+ return state;
850
+ }
851
+ function handleDoctypeAttributeWrapperStart(state, token) {
852
+ const attribute = getLastAttribute(state);
853
+ if (attribute.value !== void 0) {
854
+ state.currentContext = state.currentContext.parentRef;
855
+ return state;
856
+ }
857
+ attribute.startWrapper = createNodeFrom(token);
858
+ attribute.range = cloneRange(token.range);
859
+ state.caretPosition++;
860
+ return state;
861
+ }
862
+ function handleDoctypeAttributeWrapperEnd(state, token) {
863
+ const attribute = getLastAttribute(state);
864
+ attribute.endWrapper = createNodeFrom(token);
865
+ updateNodeEnd(attribute, token);
866
+ state.currentContext = state.currentContext.parentRef;
867
+ state.caretPosition++;
868
+ return state;
869
+ }
870
+ function handleDoctypeAttributeValue(state, token) {
871
+ const attribute = getLastAttribute(state);
872
+ if (attribute.value !== void 0) {
873
+ state.currentContext = state.currentContext.parentRef;
874
+ return state;
875
+ }
876
+ attribute.value = createNodeFrom(token);
877
+ if (!attribute.startWrapper) attribute.range = cloneRange(token.range);
878
+ state.caretPosition++;
879
+ return state;
880
+ }
881
+
882
+ //#endregion
883
+ //#region src/constructor/handlers/doctypeAttributes.ts
884
+ var doctypeAttributes_exports$1 = /* @__PURE__ */ __exportAll({ construct: () => construct$3 });
885
+ const ATTRIBUTE_START_TOKENS = new Set([TokenTypes.DoctypeAttributeWrapperStart, TokenTypes.DoctypeAttributeValue]);
886
+ function construct$3(token, state) {
887
+ if (token.type === TokenTypes.DoctypeClose) return handleDoctypeClose(state);
888
+ if (ATTRIBUTE_START_TOKENS.has(token.type)) return handleAttribute(state, token);
889
+ state.caretPosition++;
890
+ return state;
891
+ }
892
+ function handleDoctypeClose(state) {
893
+ state.currentContext = state.currentContext.parentRef;
894
+ return state;
895
+ }
896
+ function handleAttribute(state, token) {
897
+ initAttributesIfNone(state.currentNode);
898
+ state.currentNode.attributes.push({
899
+ type: NodeTypes.DoctypeAttribute,
900
+ range: cloneRange(token.range),
901
+ loc: cloneLocation(token.loc)
902
+ });
903
+ state.currentContext = {
904
+ type: ConstructTreeContextTypes.DoctypeAttribute,
905
+ parentRef: state.currentContext
906
+ };
907
+ return state;
908
+ }
909
+
910
+ //#endregion
911
+ //#region src/constructor/handlers/xmlDeclarationAttribute.ts
912
+ var xmlDeclarationAttribute_exports = /* @__PURE__ */ __exportAll({ construct: () => construct$2 });
913
+ function construct$2(token, state) {
914
+ if (token.type === TokenTypes.OpenTagStart) handleTagOpenStart$2(state, token);
915
+ state.caretPosition++;
916
+ return state;
917
+ }
918
+ function handleTagOpenStart$2(state, token) {
919
+ state.currentNode.name = parseOpenTagName(token.value);
920
+ state.currentContext = state.currentContext.parentRef;
921
+ return state;
922
+ }
923
+
924
+ //#endregion
925
+ //#region src/constructor/handlers/xmlDeclarationAttributes.ts
926
+ var xmlDeclarationAttributes_exports$1 = /* @__PURE__ */ __exportAll({ construct: () => construct$1 });
927
+ function construct$1(token, state) {
928
+ if (token.type === TokenTypes.OpenTagStart) handleTagOpenStart$1(state, token);
929
+ state.caretPosition++;
930
+ return state;
931
+ }
932
+ function handleTagOpenStart$1(state, token) {
933
+ state.currentNode.name = parseOpenTagName(token.value);
934
+ state.currentContext = state.currentContext.parentRef;
935
+ return state;
936
+ }
937
+
938
+ //#endregion
939
+ //#region src/constructor/handlers/xmlDeclarationAttributeValue.ts
940
+ var xmlDeclarationAttributeValue_exports$1 = /* @__PURE__ */ __exportAll({ construct: () => construct });
941
+ function construct(token, state) {
942
+ if (token.type === TokenTypes.OpenTagStart) handleTagOpenStart(state, token);
943
+ state.caretPosition++;
944
+ return state;
945
+ }
946
+ function handleTagOpenStart(state, token) {
947
+ state.currentNode.name = parseOpenTagName(token.value);
948
+ state.currentContext = state.currentContext.parentRef;
949
+ return state;
950
+ }
951
+
952
+ //#endregion
953
+ //#region src/constructor/constructTree.ts
954
+ const EMPTY_RANGE = [0, 0];
955
+ const EMPTY_LOC = {
956
+ start: {
957
+ line: 1,
958
+ column: 0
959
+ },
960
+ end: {
961
+ line: 1,
962
+ column: 0
963
+ }
964
+ };
965
+ const contextHandlers$1 = {
966
+ [ConstructTreeContextTypes.Tag]: tag_exports,
967
+ [ConstructTreeContextTypes.TagName]: tagName_exports,
968
+ [ConstructTreeContextTypes.TagContent]: tagContent_exports,
969
+ [ConstructTreeContextTypes.Attributes]: attributes_exports$1,
970
+ [ConstructTreeContextTypes.Attribute]: attribute_exports,
971
+ [ConstructTreeContextTypes.AttributeValue]: attributeValue_exports$1,
972
+ [ConstructTreeContextTypes.Doctype]: doctype_exports,
973
+ [ConstructTreeContextTypes.DoctypeAttribute]: doctypeAttribute_exports,
974
+ [ConstructTreeContextTypes.DoctypeAttributes]: doctypeAttributes_exports$1,
975
+ [ConstructTreeContextTypes.Comment]: comment_exports,
976
+ [ConstructTreeContextTypes.XMLDeclaration]: xmlDeclaration_exports,
977
+ [ConstructTreeContextTypes.XMLDeclarationAttribute]: xmlDeclarationAttribute_exports,
978
+ [ConstructTreeContextTypes.XMLDeclarationAttributes]: xmlDeclarationAttributes_exports$1,
979
+ [ConstructTreeContextTypes.XMLDeclarationAttributeValue]: xmlDeclarationAttributeValue_exports$1
980
+ };
981
+ function constructTree(tokens) {
982
+ const rootContext = {
983
+ type: ConstructTreeContextTypes.TagContent,
984
+ parentRef: void 0,
985
+ content: []
986
+ };
987
+ const lastToken = last(tokens);
988
+ const firstToken = first(tokens);
989
+ const range = lastToken ? [0, lastToken.range[1]] : EMPTY_RANGE;
990
+ const loc = lastToken && firstToken ? {
991
+ start: cloneLocation(firstToken.loc).start,
992
+ end: cloneLocation(lastToken.loc).end
993
+ } : EMPTY_LOC;
994
+ loc.start.line = 1;
995
+ const rootNode = {
996
+ type: NodeTypes.Document,
997
+ range,
998
+ children: [],
999
+ loc
1000
+ };
1001
+ const state = {
1002
+ caretPosition: 0,
1003
+ currentContext: rootContext,
1004
+ currentNode: rootNode,
1005
+ rootNode
1006
+ };
1007
+ const positionOffset = state.caretPosition;
1008
+ processTokens(tokens, state, positionOffset);
1009
+ return {
1010
+ state,
1011
+ ast: state.rootNode
1012
+ };
1013
+ }
1014
+ function processTokens(tokens, state, positionOffset) {
1015
+ let tokenIndex = state.caretPosition - positionOffset;
1016
+ while (tokenIndex < tokens.length) {
1017
+ const token = tokens[tokenIndex];
1018
+ const handler = contextHandlers$1[state.currentContext.type].construct;
1019
+ state = handler(token, state);
1020
+ tokenIndex = state.caretPosition - positionOffset;
1021
+ }
1022
+ return state;
1023
+ }
1024
+
1025
+ //#endregion
1026
+ //#region src/tokenizer/charsBuffer.ts
1027
+ var CharsBuffer = class {
1028
+ charsBuffer = [];
1029
+ concat(chars) {
1030
+ const last$1 = this.last();
1031
+ if (last$1) last$1.concat(chars);
1032
+ else this.charsBuffer.push(chars);
1033
+ }
1034
+ concatBuffer(buffer) {
1035
+ this.charsBuffer.push(...buffer.charsBuffer);
1036
+ }
1037
+ length() {
1038
+ return this.charsBuffer.map((chars) => chars.length()).reduce((a, b) => a + b, 0);
1039
+ }
1040
+ clear() {
1041
+ this.charsBuffer = [];
1042
+ }
1043
+ value() {
1044
+ return this.charsBuffer.map((chars) => chars.value).join("");
1045
+ }
1046
+ last() {
1047
+ return last(this.charsBuffer);
1048
+ }
1049
+ first() {
1050
+ return first(this.charsBuffer);
1051
+ }
1052
+ removeLast() {
1053
+ this.charsBuffer.splice(-1, 1);
1054
+ }
1055
+ removeFirst() {
1056
+ this.charsBuffer.splice(0, 1);
1057
+ }
1058
+ replace(other) {
1059
+ this.charsBuffer = [...other.charsBuffer];
1060
+ }
1061
+ };
1062
+
1063
+ //#endregion
1064
+ //#region src/tokenizer/handlers/data.ts
1065
+ var data_exports = /* @__PURE__ */ __exportAll({
1066
+ handleContentEnd: () => handleContentEnd,
1067
+ parse: () => parse$22
1068
+ });
1069
+ const INCOMPLETE_DOCTYPE_CHARS = new Set([
1070
+ "<!",
1071
+ "<!D",
1072
+ "<!DO",
1073
+ "<!DOC",
1074
+ "<!DOCT",
1075
+ "<!DOCTY",
1076
+ "<!DOCTYP"
1077
+ ]);
1078
+ function parse$22(chars, state) {
1079
+ const value = chars.value();
1080
+ if (value === XML_DECLARATION_START) return parseXMLDeclarationOpen(state);
1081
+ if (RE_OPEN_TAG_START.test(value)) return parseOpeningCornerBraceWithText(state);
1082
+ if (value === "</") return parseOpeningCornerBraceWithSlash(state);
1083
+ if (value === SPECIAL_CHAR.openingCorner || value === "<!" || value === "<!-") return state.sourceCode.next();
1084
+ if (value === COMMENT_START) return parseCommentOpen(state);
1085
+ if (isIncompleteDoctype(value)) return state.sourceCode.next();
1086
+ if (value.toUpperCase() === "<!DOCTYPE") return parseDoctypeOpen(state);
1087
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1088
+ state.decisionBuffer.clear();
1089
+ state.sourceCode.next();
1090
+ }
1091
+ function handleContentEnd(state) {
1092
+ const textContent = state.accumulatedContent.value() + state.decisionBuffer.value();
1093
+ if (textContent.length !== 0) {
1094
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1095
+ state.tokens.push({
1096
+ type: TokenTypes.Text,
1097
+ value: textContent,
1098
+ range: position.range,
1099
+ loc: position.loc
1100
+ });
1101
+ }
1102
+ }
1103
+ function generateTextToken(state) {
1104
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1105
+ return {
1106
+ type: TokenTypes.Text,
1107
+ value: state.accumulatedContent.value(),
1108
+ range: position.range,
1109
+ loc: position.loc
1110
+ };
1111
+ }
1112
+ function isIncompleteDoctype(chars) {
1113
+ return INCOMPLETE_DOCTYPE_CHARS.has(chars.toUpperCase());
1114
+ }
1115
+ function parseOpeningCornerBraceWithText(state) {
1116
+ if (state.accumulatedContent.length() !== 0) state.tokens.push(generateTextToken(state));
1117
+ state.accumulatedContent.replace(state.decisionBuffer);
1118
+ state.decisionBuffer.clear();
1119
+ state.currentContext = TokenizerContextTypes.OpenTagStart;
1120
+ state.sourceCode.next();
1121
+ }
1122
+ function parseOpeningCornerBraceWithSlash(state) {
1123
+ if (state.accumulatedContent.length() !== 0) state.tokens.push(generateTextToken(state));
1124
+ state.accumulatedContent.replace(state.decisionBuffer);
1125
+ state.decisionBuffer.clear();
1126
+ state.currentContext = TokenizerContextTypes.CloseTag;
1127
+ state.sourceCode.next();
1128
+ }
1129
+ function parseCommentOpen(state) {
1130
+ if (state.accumulatedContent.length() !== 0) state.tokens.push(generateTextToken(state));
1131
+ const range = [state.sourceCode.index() - (COMMENT_START.length - 1), state.sourceCode.index() + 1];
1132
+ state.tokens.push({
1133
+ type: TokenTypes.CommentOpen,
1134
+ value: state.decisionBuffer.value(),
1135
+ range,
1136
+ loc: state.sourceCode.getLocationOf(range)
1137
+ });
1138
+ state.accumulatedContent.clear();
1139
+ state.decisionBuffer.clear();
1140
+ state.currentContext = TokenizerContextTypes.CommentContent;
1141
+ state.sourceCode.next();
1142
+ }
1143
+ function parseDoctypeOpen(state) {
1144
+ if (state.accumulatedContent.length() !== 0) state.tokens.push(generateTextToken(state));
1145
+ state.accumulatedContent.replace(state.decisionBuffer);
1146
+ state.decisionBuffer.clear();
1147
+ state.currentContext = TokenizerContextTypes.DoctypeOpen;
1148
+ state.sourceCode.next();
1149
+ }
1150
+ function parseXMLDeclarationOpen(state) {
1151
+ if (state.accumulatedContent.length() !== 0) state.tokens.push(generateTextToken(state));
1152
+ state.accumulatedContent.clear();
1153
+ state.decisionBuffer.clear();
1154
+ state.currentContext = TokenizerContextTypes.XMLDeclarationAttributes;
1155
+ state.sourceCode.next();
1156
+ }
1157
+
1158
+ //#endregion
1159
+ //#region src/tokenizer/handlers/closeTag.ts
1160
+ var closeTag_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$21 });
1161
+ function parse$21(chars, state) {
1162
+ if (chars.value() === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace$5(state);
1163
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1164
+ state.decisionBuffer.clear();
1165
+ state.sourceCode.next();
1166
+ }
1167
+ function parseClosingCornerBrace$5(state) {
1168
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1169
+ state.tokens.push({
1170
+ type: TokenTypes.CloseTag,
1171
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
1172
+ range: position.range,
1173
+ loc: position.loc
1174
+ });
1175
+ state.accumulatedContent.clear();
1176
+ state.decisionBuffer.clear();
1177
+ state.currentContext = TokenizerContextTypes.Data;
1178
+ state.sourceCode.next();
1179
+ }
1180
+
1181
+ //#endregion
1182
+ //#region src/tokenizer/handlers/attributes.ts
1183
+ var attributes_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$20 });
1184
+ function parse$20(chars, state) {
1185
+ const value = chars.value();
1186
+ if (value === SPECIAL_CHAR.closingCorner || value === SPECIAL_CHAR.slash) return parseTagEnd$3(state);
1187
+ if (value === SPECIAL_CHAR.equal) return parseEqual(state);
1188
+ if (!isWhitespace(value)) return parseNoneWhitespace(chars, state);
1189
+ state.decisionBuffer.clear();
1190
+ state.sourceCode.next();
1191
+ }
1192
+ function parseTagEnd$3(state) {
1193
+ const tagName = state.contextParams[TokenizerContextTypes.Attributes]?.tagName;
1194
+ state.accumulatedContent.clear();
1195
+ state.decisionBuffer.clear();
1196
+ state.currentContext = TokenizerContextTypes.OpenTagEnd;
1197
+ state.contextParams[TokenizerContextTypes.OpenTagEnd] = { tagName };
1198
+ state.contextParams[TokenizerContextTypes.Attributes] = void 0;
1199
+ }
1200
+ function parseEqual(state) {
1201
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1202
+ state.tokens.push({
1203
+ type: TokenTypes.AttributeAssignment,
1204
+ value: state.decisionBuffer.value(),
1205
+ range: position.range,
1206
+ loc: position.loc
1207
+ });
1208
+ state.accumulatedContent.clear();
1209
+ state.decisionBuffer.clear();
1210
+ state.currentContext = TokenizerContextTypes.AttributeValue;
1211
+ state.sourceCode.next();
1212
+ }
1213
+ function parseNoneWhitespace(chars, state) {
1214
+ state.accumulatedContent.replace(state.decisionBuffer);
1215
+ state.currentContext = TokenizerContextTypes.AttributeKey;
1216
+ state.decisionBuffer.clear();
1217
+ state.sourceCode.next();
1218
+ }
1219
+
1220
+ //#endregion
1221
+ //#region src/tokenizer/handlers/openTagEnd.ts
1222
+ var openTagEnd_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$19 });
1223
+ function parse$19(chars, state) {
1224
+ if (chars.value() === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace$4(state);
1225
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1226
+ state.decisionBuffer.clear();
1227
+ state.sourceCode.next();
1228
+ }
1229
+ function parseClosingCornerBrace$4(state) {
1230
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1231
+ state.tokens.push({
1232
+ type: TokenTypes.OpenTagEnd,
1233
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
1234
+ range: position.range,
1235
+ loc: position.loc
1236
+ });
1237
+ state.accumulatedContent.clear();
1238
+ state.decisionBuffer.clear();
1239
+ state.currentContext = TokenizerContextTypes.Data;
1240
+ state.sourceCode.next();
1241
+ state.contextParams[TokenizerContextTypes.OpenTagEnd] = void 0;
1242
+ }
1243
+
1244
+ //#endregion
1245
+ //#region src/tokenizer/handlers/doctypeOpen.ts
1246
+ var doctypeOpen_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$18 });
1247
+ function parse$18(chars, state) {
1248
+ const value = chars.value();
1249
+ if (isWhitespace(value)) return parseWhitespace$1(state);
1250
+ if (value === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace$3(state);
1251
+ state.decisionBuffer.clear();
1252
+ state.sourceCode.next();
1253
+ }
1254
+ function generateDoctypeOpenToken(state) {
1255
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1256
+ return {
1257
+ type: TokenTypes.DoctypeOpen,
1258
+ value: state.accumulatedContent.value(),
1259
+ range: position.range,
1260
+ loc: position.loc
1261
+ };
1262
+ }
1263
+ function parseWhitespace$1(state) {
1264
+ state.tokens.push(generateDoctypeOpenToken(state));
1265
+ state.accumulatedContent.clear();
1266
+ state.decisionBuffer.clear();
1267
+ state.currentContext = TokenizerContextTypes.DoctypeAttributes;
1268
+ }
1269
+ function parseClosingCornerBrace$3(state) {
1270
+ state.tokens.push(generateDoctypeOpenToken(state));
1271
+ state.accumulatedContent.clear();
1272
+ state.decisionBuffer.clear();
1273
+ state.currentContext = TokenizerContextTypes.DoctypeClose;
1274
+ }
1275
+
1276
+ //#endregion
1277
+ //#region src/tokenizer/handlers/attributeKey.ts
1278
+ var attributeKey_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$17 });
1279
+ function parse$17(chars, state) {
1280
+ if (isKeyBreak$1(chars)) return parseKeyEnd$1(state);
1281
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1282
+ state.decisionBuffer.clear();
1283
+ state.sourceCode.next();
1284
+ }
1285
+ function isKeyBreak$1(chars) {
1286
+ const value = chars.value();
1287
+ return value === SPECIAL_CHAR.equal || value === SPECIAL_CHAR.slash || value === SPECIAL_CHAR.closingCorner || isWhitespace(value);
1288
+ }
1289
+ function parseKeyEnd$1(state) {
1290
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1291
+ state.tokens.push({
1292
+ type: TokenTypes.AttributeKey,
1293
+ value: state.accumulatedContent.value(),
1294
+ range: position.range,
1295
+ loc: position.loc
1296
+ });
1297
+ state.accumulatedContent.clear();
1298
+ state.decisionBuffer.clear();
1299
+ state.currentContext = TokenizerContextTypes.Attributes;
1300
+ }
1301
+
1302
+ //#endregion
1303
+ //#region src/tokenizer/handlers/doctypeClose.ts
1304
+ var doctypeClose_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$16 });
1305
+ function parse$16(chars, state) {
1306
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1307
+ state.tokens.push({
1308
+ type: TokenTypes.DoctypeClose,
1309
+ value: state.decisionBuffer.value(),
1310
+ range: position.range,
1311
+ loc: position.loc
1312
+ });
1313
+ state.accumulatedContent.clear();
1314
+ state.decisionBuffer.clear();
1315
+ state.currentContext = TokenizerContextTypes.Data;
1316
+ state.sourceCode.next();
1317
+ }
1318
+
1319
+ //#endregion
1320
+ //#region src/tokenizer/handlers/openTagStart.ts
1321
+ var openTagStart_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$15 });
1322
+ function parse$15(chars, state) {
1323
+ const value = chars.value();
1324
+ if (value === SPECIAL_CHAR.closingCorner || value === SPECIAL_CHAR.slash) return parseTagEnd$2(state);
1325
+ if (isWhitespace(value)) return parseWhitespace(state);
1326
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1327
+ state.decisionBuffer.clear();
1328
+ state.sourceCode.next();
1329
+ }
1330
+ function parseTagEnd$2(state) {
1331
+ const tagName = parseOpenTagName(state.accumulatedContent.value());
1332
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1333
+ state.tokens.push({
1334
+ type: TokenTypes.OpenTagStart,
1335
+ value: state.accumulatedContent.value(),
1336
+ range: position.range,
1337
+ loc: position.loc
1338
+ });
1339
+ state.accumulatedContent.clear();
1340
+ state.decisionBuffer.clear();
1341
+ state.currentContext = TokenizerContextTypes.OpenTagEnd;
1342
+ state.contextParams[TokenizerContextTypes.OpenTagEnd] = { tagName };
1343
+ }
1344
+ function parseWhitespace(state) {
1345
+ const tagName = parseOpenTagName(state.accumulatedContent.value());
1346
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1347
+ state.tokens.push({
1348
+ type: TokenTypes.OpenTagStart,
1349
+ value: state.accumulatedContent.value(),
1350
+ range: position.range,
1351
+ loc: position.loc
1352
+ });
1353
+ state.accumulatedContent.clear();
1354
+ state.decisionBuffer.clear();
1355
+ state.currentContext = TokenizerContextTypes.Attributes;
1356
+ state.contextParams[TokenizerContextTypes.Attributes] = { tagName };
1357
+ state.sourceCode.next();
1358
+ }
1359
+
1360
+ //#endregion
1361
+ //#region src/tokenizer/handlers/attributeValue.ts
1362
+ var attributeValue_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$14 });
1363
+ function parse$14(chars, state) {
1364
+ const value = chars.value();
1365
+ if (value === SPECIAL_CHAR.doubleQuote || value === SPECIAL_CHAR.singleQuote) return parseWrapper$5(state);
1366
+ if (value === SPECIAL_CHAR.closingCorner || value === SPECIAL_CHAR.slash) return parseTagEnd$1(state);
1367
+ if (!isWhitespace(value)) return parseBare$2(state);
1368
+ state.decisionBuffer.clear();
1369
+ state.sourceCode.next();
1370
+ }
1371
+ function parseWrapper$5(state) {
1372
+ const wrapper = state.decisionBuffer.value();
1373
+ const range = [state.sourceCode.index(), state.sourceCode.index() + 1];
1374
+ state.tokens.push({
1375
+ type: TokenTypes.AttributeValueWrapperStart,
1376
+ value: wrapper,
1377
+ range,
1378
+ loc: state.sourceCode.getLocationOf(range)
1379
+ });
1380
+ state.accumulatedContent.clear();
1381
+ state.decisionBuffer.clear();
1382
+ state.currentContext = TokenizerContextTypes.AttributeValueWrapped;
1383
+ state.contextParams[TokenizerContextTypes.AttributeValueWrapped] = { wrapper };
1384
+ state.sourceCode.next();
1385
+ }
1386
+ function parseTagEnd$1(state) {
1387
+ state.accumulatedContent.clear();
1388
+ state.decisionBuffer.clear();
1389
+ state.currentContext = TokenizerContextTypes.Attributes;
1390
+ }
1391
+ function parseBare$2(state) {
1392
+ state.accumulatedContent.replace(state.decisionBuffer);
1393
+ state.decisionBuffer.clear();
1394
+ state.currentContext = TokenizerContextTypes.AttributeValueBare;
1395
+ state.sourceCode.next();
1396
+ }
1397
+
1398
+ //#endregion
1399
+ //#region src/tokenizer/handlers/commentContent.ts
1400
+ var commentContent_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$13 });
1401
+ function parse$13(chars, state) {
1402
+ const value = chars.value();
1403
+ if (value === SPECIAL_CHAR.hyphen || value === "--") return state.sourceCode.next();
1404
+ if (value === COMMENT_END) return parseCommentClose(state);
1405
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1406
+ state.decisionBuffer.clear();
1407
+ state.sourceCode.next();
1408
+ }
1409
+ function parseCommentClose(state) {
1410
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1411
+ const endRange = [position.range[1], position.range[1] + COMMENT_END.length];
1412
+ state.tokens.push({
1413
+ type: TokenTypes.CommentContent,
1414
+ value: state.accumulatedContent.value(),
1415
+ range: position.range,
1416
+ loc: position.loc
1417
+ });
1418
+ state.tokens.push({
1419
+ type: TokenTypes.CommentClose,
1420
+ value: state.decisionBuffer.value(),
1421
+ range: endRange,
1422
+ loc: state.sourceCode.getLocationOf(endRange)
1423
+ });
1424
+ state.accumulatedContent.clear();
1425
+ state.decisionBuffer.clear();
1426
+ state.currentContext = TokenizerContextTypes.Data;
1427
+ state.sourceCode.next();
1428
+ }
1429
+
1430
+ //#endregion
1431
+ //#region src/tokenizer/handlers/doctypeAttributes.ts
1432
+ var doctypeAttributes_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$12 });
1433
+ function parse$12(chars, state) {
1434
+ const value = chars.value();
1435
+ if (value === SPECIAL_CHAR.doubleQuote || value === SPECIAL_CHAR.singleQuote) return parseWrapper$4(state);
1436
+ if (value === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace$2(state);
1437
+ if (!isWhitespace(value)) return parseBare$1(state);
1438
+ state.decisionBuffer.clear();
1439
+ state.sourceCode.next();
1440
+ }
1441
+ function parseWrapper$4(state) {
1442
+ const wrapper = state.decisionBuffer.value();
1443
+ const range = [state.sourceCode.index(), state.sourceCode.index() + wrapper.length];
1444
+ state.tokens.push({
1445
+ type: TokenTypes.DoctypeAttributeWrapperStart,
1446
+ value: wrapper,
1447
+ range,
1448
+ loc: state.sourceCode.getLocationOf(range)
1449
+ });
1450
+ state.accumulatedContent.clear();
1451
+ state.decisionBuffer.clear();
1452
+ state.currentContext = TokenizerContextTypes.DoctypeAttributeWrapped;
1453
+ state.contextParams[TokenizerContextTypes.DoctypeAttributeWrapped] = { wrapper };
1454
+ state.sourceCode.next();
1455
+ }
1456
+ function parseClosingCornerBrace$2(state) {
1457
+ state.accumulatedContent.clear();
1458
+ state.decisionBuffer.clear();
1459
+ state.currentContext = TokenizerContextTypes.DoctypeClose;
1460
+ }
1461
+ function parseBare$1(state) {
1462
+ state.accumulatedContent.replace(state.decisionBuffer);
1463
+ state.decisionBuffer.clear();
1464
+ state.currentContext = TokenizerContextTypes.DoctypeAttributeBare;
1465
+ state.sourceCode.next();
1466
+ }
1467
+
1468
+ //#endregion
1469
+ //#region src/tokenizer/handlers/attributeValueBare.ts
1470
+ var attributeValueBare_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$11 });
1471
+ function parse$11(chars, state) {
1472
+ const value = chars.value();
1473
+ if (isWhitespace(value) || value === SPECIAL_CHAR.closingCorner || value === SPECIAL_CHAR.slash) return parseValueEnd(state);
1474
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1475
+ state.decisionBuffer.clear();
1476
+ state.sourceCode.next();
1477
+ }
1478
+ function parseValueEnd(state) {
1479
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1480
+ state.tokens.push({
1481
+ type: TokenTypes.AttributeValue,
1482
+ value: state.accumulatedContent.value(),
1483
+ range: position.range,
1484
+ loc: position.loc
1485
+ });
1486
+ state.accumulatedContent.clear();
1487
+ state.decisionBuffer.clear();
1488
+ state.currentContext = TokenizerContextTypes.Attributes;
1489
+ }
1490
+
1491
+ //#endregion
1492
+ //#region src/tokenizer/handlers/xmlDeclarationOpen.ts
1493
+ var xmlDeclarationOpen_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$10 });
1494
+ function parse$10(chars, state) {
1495
+ if (chars.value() === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace$1(state);
1496
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1497
+ state.decisionBuffer.clear();
1498
+ state.sourceCode.next();
1499
+ }
1500
+ function parseClosingCornerBrace$1(state) {
1501
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1502
+ state.tokens.push({
1503
+ type: TokenTypes.OpenTagEnd,
1504
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
1505
+ range: position.range,
1506
+ loc: position.loc
1507
+ });
1508
+ state.accumulatedContent.clear();
1509
+ state.decisionBuffer.clear();
1510
+ state.currentContext = TokenizerContextTypes.Data;
1511
+ state.sourceCode.next();
1512
+ state.contextParams[TokenizerContextTypes.OpenTagEnd] = void 0;
1513
+ }
1514
+
1515
+ //#endregion
1516
+ //#region src/tokenizer/handlers/xmlDeclarationClose.ts
1517
+ var xmlDeclarationClose_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$9 });
1518
+ function parse$9(chars, state) {
1519
+ if (chars.value() === SPECIAL_CHAR.closingCorner) return parseClosingCornerBrace(state);
1520
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1521
+ state.decisionBuffer.clear();
1522
+ state.sourceCode.next();
1523
+ }
1524
+ function parseClosingCornerBrace(state) {
1525
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1526
+ state.tokens.push({
1527
+ type: TokenTypes.OpenTagEnd,
1528
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
1529
+ range: position.range,
1530
+ loc: position.loc
1531
+ });
1532
+ state.accumulatedContent.clear();
1533
+ state.decisionBuffer.clear();
1534
+ state.currentContext = TokenizerContextTypes.Data;
1535
+ state.sourceCode.next();
1536
+ state.contextParams[TokenizerContextTypes.OpenTagEnd] = void 0;
1537
+ }
1538
+
1539
+ //#endregion
1540
+ //#region src/tokenizer/handlers/doctypeAttributeBare.ts
1541
+ var doctypeAttributeBare_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$8 });
1542
+ function parse$8(chars, state) {
1543
+ const value = chars.value();
1544
+ if (isWhitespace(value) || value === SPECIAL_CHAR.closingCorner) return parseAttributeEnd(state);
1545
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1546
+ state.decisionBuffer.clear();
1547
+ state.sourceCode.next();
1548
+ }
1549
+ function parseAttributeEnd(state) {
1550
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1551
+ state.tokens.push({
1552
+ type: TokenTypes.DoctypeAttributeValue,
1553
+ value: state.accumulatedContent.value(),
1554
+ range: position.range,
1555
+ loc: position.loc
1556
+ });
1557
+ state.accumulatedContent.clear();
1558
+ state.decisionBuffer.clear();
1559
+ state.currentContext = TokenizerContextTypes.DoctypeAttributes;
1560
+ }
1561
+
1562
+ //#endregion
1563
+ //#region src/tokenizer/handlers/attributeValueWrapped.ts
1564
+ var attributeValueWrapped_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$7 });
1565
+ function parse$7(chars, state) {
1566
+ const wrapperChar = state.contextParams[TokenizerContextTypes.AttributeValueWrapped]?.wrapper;
1567
+ if (chars.value() === wrapperChar) return parseWrapper$3(state);
1568
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1569
+ state.decisionBuffer.clear();
1570
+ state.sourceCode.next();
1571
+ }
1572
+ function parseWrapper$3(state) {
1573
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1574
+ const endWrapperPosition = position.range[1];
1575
+ state.tokens.push({
1576
+ type: TokenTypes.AttributeValue,
1577
+ value: state.accumulatedContent.value(),
1578
+ range: position.range,
1579
+ loc: position.loc
1580
+ });
1581
+ const range = [endWrapperPosition, endWrapperPosition + 1];
1582
+ state.tokens.push({
1583
+ type: TokenTypes.AttributeValueWrapperEnd,
1584
+ value: state.decisionBuffer.value(),
1585
+ range,
1586
+ loc: state.sourceCode.getLocationOf(range)
1587
+ });
1588
+ state.accumulatedContent.clear();
1589
+ state.decisionBuffer.clear();
1590
+ state.currentContext = TokenizerContextTypes.Attributes;
1591
+ state.sourceCode.next();
1592
+ state.contextParams[TokenizerContextTypes.AttributeValueWrapped] = void 0;
1593
+ }
1594
+
1595
+ //#endregion
1596
+ //#region src/tokenizer/handlers/doctypeAttributeWrapped.ts
1597
+ var doctypeAttributeWrapped_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$6 });
1598
+ function parse$6(chars, state) {
1599
+ if (chars.value() === state.contextParams[TokenizerContextTypes.DoctypeAttributeWrapped]?.wrapper) return parseWrapper$2(state);
1600
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1601
+ state.decisionBuffer.clear();
1602
+ state.sourceCode.next();
1603
+ }
1604
+ function parseWrapper$2(state) {
1605
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1606
+ const endWrapperPosition = position.range[1];
1607
+ state.tokens.push({
1608
+ type: TokenTypes.DoctypeAttributeValue,
1609
+ value: state.accumulatedContent.value(),
1610
+ range: position.range,
1611
+ loc: position.loc
1612
+ });
1613
+ const range = [endWrapperPosition, endWrapperPosition + 1];
1614
+ state.tokens.push({
1615
+ type: TokenTypes.DoctypeAttributeWrapperEnd,
1616
+ value: state.decisionBuffer.value(),
1617
+ range,
1618
+ loc: state.sourceCode.getLocationOf(range)
1619
+ });
1620
+ state.accumulatedContent.clear();
1621
+ state.decisionBuffer.clear();
1622
+ state.currentContext = TokenizerContextTypes.DoctypeAttributes;
1623
+ state.sourceCode.next();
1624
+ state.contextParams[TokenizerContextTypes.DoctypeAttributeWrapped] = void 0;
1625
+ }
1626
+
1627
+ //#endregion
1628
+ //#region src/tokenizer/handlers/xmlDeclarationAttributes.ts
1629
+ var xmlDeclarationAttributes_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$5 });
1630
+ function parse$5(chars, state) {
1631
+ const value = chars.value();
1632
+ if (value === SPECIAL_CHAR.question || value === SPECIAL_CHAR.closingCorner) return parseXMLDeclarationClose(state);
1633
+ if (value === XML_DECLARATION_END) return parseXMLDeclarationClose(state);
1634
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1635
+ state.decisionBuffer.clear();
1636
+ state.sourceCode.next();
1637
+ }
1638
+ function parseXMLDeclarationClose(state) {
1639
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1640
+ const endRange = [position.range[1], position.range[1] + XML_DECLARATION_END.length];
1641
+ state.tokens.push({
1642
+ type: TokenTypes.XMLDeclarationClose,
1643
+ value: state.decisionBuffer.value(),
1644
+ range: endRange,
1645
+ loc: state.sourceCode.getLocationOf(endRange)
1646
+ });
1647
+ state.accumulatedContent.clear();
1648
+ state.decisionBuffer.clear();
1649
+ state.currentContext = TokenizerContextTypes.Data;
1650
+ state.sourceCode.next();
1651
+ }
1652
+
1653
+ //#endregion
1654
+ //#region src/tokenizer/handlers/xmlDeclarationAttributeKey.ts
1655
+ var xmlDeclarationAttributeKey_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$4 });
1656
+ function parse$4(chars, state) {
1657
+ if (isKeyBreak(chars)) return parseKeyEnd(state);
1658
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1659
+ state.decisionBuffer.clear();
1660
+ state.sourceCode.next();
1661
+ }
1662
+ function isKeyBreak(chars) {
1663
+ const value = chars.value();
1664
+ return value === SPECIAL_CHAR.equal || value === SPECIAL_CHAR.slash || value === SPECIAL_CHAR.closingCorner || isWhitespace(value);
1665
+ }
1666
+ function parseKeyEnd(state) {
1667
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1668
+ state.tokens.push({
1669
+ type: TokenTypes.XMLDeclarationAttributeKey,
1670
+ value: state.accumulatedContent.value(),
1671
+ range: position.range,
1672
+ loc: position.loc
1673
+ });
1674
+ state.accumulatedContent.clear();
1675
+ state.decisionBuffer.clear();
1676
+ state.currentContext = TokenizerContextTypes.XMLDeclarationAttributes;
1677
+ }
1678
+
1679
+ //#endregion
1680
+ //#region src/tokenizer/handlers/xmlDeclarationAttributeValue.ts
1681
+ var xmlDeclarationAttributeValue_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$3 });
1682
+ function parse$3(chars, state) {
1683
+ const value = chars.value();
1684
+ if (value === SPECIAL_CHAR.doubleQuote || value === SPECIAL_CHAR.singleQuote) return parseWrapper$1(state);
1685
+ if (value === SPECIAL_CHAR.closingCorner || value === SPECIAL_CHAR.slash) return parseTagEnd(state);
1686
+ if (!isWhitespace(value)) return parseBare(state);
1687
+ state.decisionBuffer.clear();
1688
+ state.sourceCode.next();
1689
+ }
1690
+ function parseWrapper$1(state) {
1691
+ const wrapper = state.decisionBuffer.value();
1692
+ const range = [state.sourceCode.index(), state.sourceCode.index() + 1];
1693
+ state.tokens.push({
1694
+ type: TokenTypes.AttributeValueWrapperStart,
1695
+ value: wrapper,
1696
+ range,
1697
+ loc: state.sourceCode.getLocationOf(range)
1698
+ });
1699
+ state.accumulatedContent.clear();
1700
+ state.decisionBuffer.clear();
1701
+ state.currentContext = TokenizerContextTypes.AttributeValueWrapped;
1702
+ state.contextParams[TokenizerContextTypes.AttributeValueWrapped] = { wrapper };
1703
+ state.sourceCode.next();
1704
+ }
1705
+ function parseTagEnd(state) {
1706
+ state.accumulatedContent.clear();
1707
+ state.decisionBuffer.clear();
1708
+ state.currentContext = TokenizerContextTypes.Attributes;
1709
+ }
1710
+ function parseBare(state) {
1711
+ state.accumulatedContent.replace(state.decisionBuffer);
1712
+ state.decisionBuffer.clear();
1713
+ state.currentContext = TokenizerContextTypes.AttributeValueBare;
1714
+ state.sourceCode.next();
1715
+ }
1716
+
1717
+ //#endregion
1718
+ //#region src/tokenizer/handlers/xmlDeclarationAttributeValueWrapped.ts
1719
+ var xmlDeclarationAttributeValueWrapped_exports = /* @__PURE__ */ __exportAll({ parse: () => parse$2 });
1720
+ function parse$2(chars, state) {
1721
+ const wrapperChar = state.contextParams[TokenizerContextTypes.AttributeValueWrapped]?.wrapper;
1722
+ if (chars.value() === wrapperChar) return parseWrapper(state);
1723
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1724
+ state.decisionBuffer.clear();
1725
+ state.sourceCode.next();
1726
+ }
1727
+ function parseWrapper(state) {
1728
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1729
+ const endWrapperPosition = position.range[1];
1730
+ state.tokens.push({
1731
+ type: TokenTypes.AttributeValue,
1732
+ value: state.accumulatedContent.value(),
1733
+ range: position.range,
1734
+ loc: position.loc
1735
+ });
1736
+ const range = [endWrapperPosition, endWrapperPosition + 1];
1737
+ state.tokens.push({
1738
+ type: TokenTypes.AttributeValueWrapperEnd,
1739
+ value: state.decisionBuffer.value(),
1740
+ range,
1741
+ loc: state.sourceCode.getLocationOf(range)
1742
+ });
1743
+ state.accumulatedContent.clear();
1744
+ state.decisionBuffer.clear();
1745
+ state.currentContext = TokenizerContextTypes.Attributes;
1746
+ state.sourceCode.next();
1747
+ state.contextParams[TokenizerContextTypes.AttributeValueWrapped] = void 0;
1748
+ }
1749
+
1750
+ //#endregion
1751
+ //#region src/tokenizer/handlers/index.ts
1752
+ const noop = { parse: () => {} };
1753
+
1754
+ //#endregion
1755
+ //#region src/tokenizer/chars.ts
1756
+ var Chars = class {
1757
+ constructor(value, range) {
1758
+ this.value = value;
1759
+ this.range = range;
1760
+ }
1761
+ concat(chars) {
1762
+ this.value += chars.value;
1763
+ this.range[1] = chars.range[1];
1764
+ }
1765
+ equals(chars) {
1766
+ return this.value === chars;
1767
+ }
1768
+ length() {
1769
+ return this.value.length;
1770
+ }
1771
+ };
1772
+
1773
+ //#endregion
1774
+ //#region src/tokenizer/sourceCode.ts
1775
+ var SourceCode = class {
1776
+ charsList;
1777
+ charsIndex = 0;
1778
+ constructor(source) {
1779
+ this.source = source;
1780
+ this.charsList = this.createCharsList();
1781
+ }
1782
+ getLocationOf(range) {
1783
+ return {
1784
+ start: getLineInfo(this.source, range[0]),
1785
+ end: getLineInfo(this.source, range[1])
1786
+ };
1787
+ }
1788
+ current() {
1789
+ return this.charsList[this.charsIndex];
1790
+ }
1791
+ next() {
1792
+ this.charsIndex++;
1793
+ }
1794
+ prev() {
1795
+ this.charsIndex--;
1796
+ }
1797
+ isEof() {
1798
+ return this.charsIndex >= this.charsList.length;
1799
+ }
1800
+ index() {
1801
+ return this.current().range[1] - 1;
1802
+ }
1803
+ createCharsList() {
1804
+ const charsList = [];
1805
+ let sourceIndex = 0;
1806
+ while (sourceIndex < this.source.length) {
1807
+ charsList.push(new Chars(this.source[sourceIndex], [sourceIndex, sourceIndex + 1]));
1808
+ sourceIndex++;
1809
+ }
1810
+ return charsList;
1811
+ }
1812
+ };
1813
+
1814
+ //#endregion
1815
+ //#region src/tokenizer/tokenize.ts
1816
+ const contextHandlers = {
1817
+ [TokenizerContextTypes.Data]: data_exports,
1818
+ [TokenizerContextTypes.XMLDeclarationOpen]: xmlDeclarationOpen_exports,
1819
+ [TokenizerContextTypes.XMLDeclarationClose]: xmlDeclarationClose_exports,
1820
+ [TokenizerContextTypes.XMLDeclarationAttributes]: xmlDeclarationAttributes_exports,
1821
+ [TokenizerContextTypes.XMLDeclarationAttributeKey]: xmlDeclarationAttributeKey_exports,
1822
+ [TokenizerContextTypes.XMLDeclarationAttributeValue]: xmlDeclarationAttributeValue_exports,
1823
+ [TokenizerContextTypes.XMLDeclarationAttributeValueWrapped]: xmlDeclarationAttributeValueWrapped_exports,
1824
+ [TokenizerContextTypes.Attributes]: attributes_exports,
1825
+ [TokenizerContextTypes.AttributeKey]: attributeKey_exports,
1826
+ [TokenizerContextTypes.AttributeValue]: attributeValue_exports,
1827
+ [TokenizerContextTypes.AttributeValueBare]: attributeValueBare_exports,
1828
+ [TokenizerContextTypes.AttributeValueWrapped]: attributeValueWrapped_exports,
1829
+ [TokenizerContextTypes.OpenTagStart]: openTagStart_exports,
1830
+ [TokenizerContextTypes.OpenTagEnd]: openTagEnd_exports,
1831
+ [TokenizerContextTypes.CloseTag]: closeTag_exports,
1832
+ [TokenizerContextTypes.DoctypeOpen]: doctypeOpen_exports,
1833
+ [TokenizerContextTypes.DoctypeClose]: doctypeClose_exports,
1834
+ [TokenizerContextTypes.DoctypeAttributes]: doctypeAttributes_exports,
1835
+ [TokenizerContextTypes.DoctypeAttributeBare]: doctypeAttributeBare_exports,
1836
+ [TokenizerContextTypes.DoctypeAttributeWrapped]: doctypeAttributeWrapped_exports,
1837
+ [TokenizerContextTypes.CommentContent]: commentContent_exports,
1838
+ [TokenizerContextTypes.CommentOpen]: noop,
1839
+ [TokenizerContextTypes.CommentClose]: noop
1840
+ };
1841
+ function tokenizeChars(state) {
1842
+ while (!state.sourceCode.isEof()) {
1843
+ const handler$1 = contextHandlers[state.currentContext];
1844
+ state.decisionBuffer.concat(state.sourceCode.current());
1845
+ handler$1.parse(state.decisionBuffer, state);
1846
+ }
1847
+ const handler = contextHandlers[state.currentContext];
1848
+ state.sourceCode.prev();
1849
+ if (handler.handleContentEnd !== void 0) handler.handleContentEnd(state);
1850
+ }
1851
+ function tokenize(source) {
1852
+ const tokens = [];
1853
+ const state = {
1854
+ contextParams: {},
1855
+ currentContext: TokenizerContextTypes.Data,
1856
+ sourceCode: new SourceCode(source),
1857
+ decisionBuffer: new CharsBuffer(),
1858
+ accumulatedContent: new CharsBuffer(),
1859
+ tokens: { push(token) {
1860
+ tokens.push(token);
1861
+ } }
1862
+ };
1863
+ tokenizeChars(state);
1864
+ return {
1865
+ state,
1866
+ tokens
1867
+ };
1868
+ }
1869
+
1870
+ //#endregion
1871
+ //#region src/parser/parse.ts
1872
+ function parse$1(source, _options = {}) {
1873
+ const { tokens } = tokenize(source);
1874
+ const { ast } = constructTree(tokens);
1875
+ return {
1876
+ ast: clearParent(ast),
1877
+ tokens
1878
+ };
1879
+ }
1880
+
1881
+ //#endregion
1882
+ //#region src/visitorKeys.ts
1883
+ const keys = {
1884
+ Program: ["body"],
1885
+ Document: ["children"],
1886
+ XMLDeclaration: [],
1887
+ XMLDeclarationOpen: [],
1888
+ XMLDeclarationClose: [],
1889
+ XMLDeclarationAttribute: ["key", "value"],
1890
+ XMLDeclarationAttributeKey: [],
1891
+ XMLDeclarationAttributeValue: [],
1892
+ XMLDeclarationAttributeValueWrapperStart: [],
1893
+ XMLDeclarationAttributeValueWrapperEnd: [],
1894
+ Doctype: [
1895
+ "open",
1896
+ "close",
1897
+ "attributes"
1898
+ ],
1899
+ DoctypeOpen: [],
1900
+ DoctypeClose: [],
1901
+ DoctypeAttribute: ["key", "value"],
1902
+ DoctypeAttributeValue: ["value"],
1903
+ DoctypeAttributeWrapperEnd: [],
1904
+ DoctypeAttributeWrapperStart: [],
1905
+ Attribute: ["key", "value"],
1906
+ AttributeKey: ["value"],
1907
+ AttributeValue: ["value"],
1908
+ AttributeValueWrapperEnd: [],
1909
+ AttributeValueWrapperStart: [],
1910
+ Tag: ["children", "attributes"],
1911
+ OpenTagEnd: [],
1912
+ OpenTagStart: [],
1913
+ CloseTag: [],
1914
+ Comment: [
1915
+ "open",
1916
+ "close",
1917
+ "value"
1918
+ ],
1919
+ CommentOpen: [],
1920
+ CommentClose: [],
1921
+ CommentContent: [],
1922
+ Text: []
1923
+ };
1924
+ let vistorKeysCache = null;
1925
+ function getVisitorKeys() {
1926
+ if (!vistorKeysCache) vistorKeysCache = unionWith(keys);
1927
+ return vistorKeysCache;
1928
+ }
1929
+ const visitorKeys = getVisitorKeys();
1930
+
1931
+ //#endregion
1932
+ //#region src/parser/traverse.ts
1933
+ function traverse(node, visitor) {
1934
+ if (!node) return;
1935
+ visitor(node);
1936
+ const keys$1 = visitorKeys[node.type];
1937
+ if (!keys$1 || keys$1.length <= 0) return;
1938
+ keys$1.forEach((key) => {
1939
+ const value = node[key];
1940
+ if (value) if (Array.isArray(value)) value.forEach((n) => traverse(n, visitor));
1941
+ else traverse(value, visitor);
1942
+ });
1943
+ }
1944
+
1945
+ //#endregion
1946
+ //#region src/parser/parseForESLint.ts
1947
+ function parseForESLint(source, options = {}) {
1948
+ const { ast, tokens } = parse$1(source, options);
1949
+ const programNode = {
1950
+ type: NodeTypes.Program,
1951
+ body: [ast],
1952
+ comments: [],
1953
+ tokens: tokens.filter((token) => token.type !== TokenTypes.CommentOpen && token.type !== TokenTypes.CommentClose && token.type !== TokenTypes.CommentContent),
1954
+ range: ast.range,
1955
+ loc: ast.loc
1956
+ };
1957
+ traverse(programNode, (node) => {
1958
+ if (node.type === NodeTypes.CommentContent) programNode.comments.push({
1959
+ type: node.type,
1960
+ range: node.range,
1961
+ loc: node.loc,
1962
+ value: node.value
1963
+ });
1964
+ });
1965
+ return {
1966
+ ast: programNode,
1967
+ visitorKeys,
1968
+ scopeManager: null,
1969
+ services: { isSVG: true }
1970
+ };
1971
+ }
1972
+
1973
+ //#endregion
1974
+ //#region src/index.ts
1975
+ const name = meta.name;
1976
+ const VisitorKeys = visitorKeys;
1977
+ function parse(code, options = {}) {
1978
+ return parseForESLint(code, options).ast;
1979
+ }
1980
+
1981
+ //#endregion
1982
+ export { COMMENT_END, COMMENT_START, ConstructTreeContextTypes, DEPRECATED_SVG_ELEMENTS, NodeTypes, ParseError, RE_CLOSE_TAG_NAME, RE_INCOMPLETE_CLOSING_TAG, RE_OPEN_TAG_NAME, RE_OPEN_TAG_START, SELF_CLOSING_ELEMENTS, SPECIAL_CHAR, SVG_ELEMENTS, TokenTypes, TokenizerContextTypes, VisitorKeys, XML_DECLARATION_END, XML_DECLARATION_START, meta, name, parse, parseForESLint };