svg-eslint-parser 0.0.0

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,1681 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name3 in all)
4
+ __defProp(target, name3, { get: all[name3], enumerable: true });
5
+ };
6
+
7
+ // package.json
8
+ var name = "svg-eslint-parser";
9
+ var version = "0.0.0";
10
+
11
+ // src/meta.ts
12
+ var meta = {
13
+ name,
14
+ version
15
+ };
16
+
17
+ // src/parser/error.ts
18
+ var ParseError = class extends SyntaxError {
19
+ index;
20
+ lineNumber;
21
+ column;
22
+ constructor(message, offset, line, column) {
23
+ super(message);
24
+ this.name = "ParseError";
25
+ this.index = offset;
26
+ this.lineNumber = line;
27
+ this.column = column;
28
+ }
29
+ };
30
+
31
+ // src/constants/char.ts
32
+ var SPECIAL_CHAR = {
33
+ newline: "\n",
34
+ return: "\r",
35
+ space: " ",
36
+ tab: " "
37
+ };
38
+
39
+ // src/constants/parse.ts
40
+ var COMMENT_START = "<!--";
41
+ var COMMENT_END = "-->";
42
+ var RE_OPEN_TAG_START = /^<\w/;
43
+ var RE_OPEN_TAG_NAME = /^<(\S+)/;
44
+ var RE_CLOSE_TAG_NAME = /^<\/((?:.|\n)*)>$/;
45
+
46
+ // src/constants/svgElements.ts
47
+ var SELF_CLOSING_ELEMENTS = /* @__PURE__ */ new Set([
48
+ "animate",
49
+ "animateMotion",
50
+ "animateTransform",
51
+ "circle",
52
+ "ellipse",
53
+ "feBlend",
54
+ "feColorMatrix",
55
+ "feComposite",
56
+ "feConvolveMatrix",
57
+ "feDisplacementMap",
58
+ "feDropShadow",
59
+ "feFlood",
60
+ "feGaussianBlur",
61
+ "feImage",
62
+ "feMergeNode",
63
+ "feMorphology",
64
+ "feOffset",
65
+ "fePointLight",
66
+ "feSpotLight",
67
+ "feTile",
68
+ "feTurbulence",
69
+ "image",
70
+ "line",
71
+ "mpath",
72
+ "path",
73
+ "polygon",
74
+ "polyline",
75
+ "rect",
76
+ "set",
77
+ "stop",
78
+ "use",
79
+ "view"
80
+ ]);
81
+
82
+ // src/utils/firstLast.ts
83
+ function first(items) {
84
+ return items[0];
85
+ }
86
+ function last(items) {
87
+ return items[items.length - 1];
88
+ }
89
+
90
+ // src/utils/cloneRange.ts
91
+ function cloneRange(range) {
92
+ return [range[0], range[1]];
93
+ }
94
+
95
+ // src/utils/initIfNone.ts
96
+ function initChildrenIfNone(node) {
97
+ if (!node.children) {
98
+ node.children = [];
99
+ }
100
+ }
101
+ function initAttributesIfNone(node) {
102
+ if (!node.attributes) {
103
+ node.attributes = [];
104
+ }
105
+ }
106
+
107
+ // src/utils/getLineInfo.ts
108
+ function isNewLine(code) {
109
+ return code === 10 || code === 13 || code === 8232 || code === 8233;
110
+ }
111
+ function nextLineBreak(code, from, end = code.length) {
112
+ for (let i = from; i < end; i++) {
113
+ const next = code.codePointAt(i);
114
+ if (!next) {
115
+ continue;
116
+ }
117
+ if (isNewLine(next)) {
118
+ return i < end - 1 && next === 13 && code.codePointAt(i + 1) === 10 ? i + 2 : i + 1;
119
+ }
120
+ }
121
+ return -1;
122
+ }
123
+ function getLineInfo(input, offset) {
124
+ for (let line = 1, cur = 0; ; ) {
125
+ const nextBreak = nextLineBreak(input, cur, offset);
126
+ if (nextBreak < 0) return { line, column: offset - cur };
127
+ ++line;
128
+ cur = nextBreak;
129
+ }
130
+ }
131
+
132
+ // src/utils/clearParent.ts
133
+ function clearParent(ast) {
134
+ const cleanAst = ast;
135
+ delete cleanAst.parentRef;
136
+ if (Array.isArray(ast.children)) {
137
+ cleanAst.children = ast.children.map((node) => {
138
+ return clearParent(node);
139
+ });
140
+ }
141
+ return cleanAst;
142
+ }
143
+
144
+ // src/utils/isWhitespace.ts
145
+ function isWhitespace(char) {
146
+ return char === SPECIAL_CHAR.space || char === SPECIAL_CHAR.newline || char === SPECIAL_CHAR.return || char === SPECIAL_CHAR.tab;
147
+ }
148
+
149
+ // src/utils/cloneLocation.ts
150
+ function cloneLocation(loc) {
151
+ return {
152
+ start: {
153
+ line: loc.start.line,
154
+ column: loc.start.column
155
+ },
156
+ end: {
157
+ line: loc.end.line,
158
+ column: loc.end.column
159
+ }
160
+ };
161
+ }
162
+
163
+ // src/utils/updateNodeEnd.ts
164
+ function updateNodeEnd(node, token) {
165
+ node.range[1] = token.range[1];
166
+ node.loc.end = {
167
+ ...token.loc.end
168
+ };
169
+ }
170
+
171
+ // src/utils/createNodeFrom.ts
172
+ function createNodeFrom(token) {
173
+ const loc = cloneLocation(token.loc);
174
+ const range = cloneRange(token.range);
175
+ const result = {
176
+ type: token.type,
177
+ value: token.value,
178
+ loc,
179
+ range
180
+ };
181
+ return result;
182
+ }
183
+
184
+ // src/utils/parseOpenTagName.ts
185
+ function parseOpenTagName(openTagStartTokenContent) {
186
+ const match = openTagStartTokenContent.match(RE_OPEN_TAG_NAME);
187
+ if (match === null) {
188
+ throw new Error(
189
+ `Unable to parse open tag name.
190
+ ${openTagStartTokenContent} does not match pattern of opening tag.`
191
+ );
192
+ }
193
+ return match[1].toLowerCase();
194
+ }
195
+
196
+ // src/utils/parseCloseTagName.ts
197
+ function parseCloseTagName(closeTagTokenContent) {
198
+ const match = closeTagTokenContent.match(RE_CLOSE_TAG_NAME);
199
+ if (match === null) {
200
+ throw new Error(
201
+ `Unable to parse close tag name.
202
+ ${closeTagTokenContent} does not match pattern of closing tag.`
203
+ );
204
+ }
205
+ return match[1].trim().toLowerCase();
206
+ }
207
+
208
+ // src/utils/calculateTokenLocation.ts
209
+ function calculateTokenLocation(source, range) {
210
+ return {
211
+ start: getLineInfo(source, range[0]),
212
+ end: getLineInfo(source, range[1])
213
+ };
214
+ }
215
+
216
+ // src/utils/calculateTokenCharactersRange.ts
217
+ function calculateTokenCharactersRange(state, options) {
218
+ const startPosition = state.sourceCode.index() - (state.accumulatedContent.length() - 1) - state.decisionBuffer.length();
219
+ let endPosition;
220
+ if (options.keepBuffer) {
221
+ endPosition = state.sourceCode.index() - state.decisionBuffer.length();
222
+ } else {
223
+ endPosition = state.sourceCode.index();
224
+ }
225
+ return [startPosition, endPosition];
226
+ }
227
+
228
+ // src/utils/calculateTokenPosition.ts
229
+ function calculateTokenPosition(state, options) {
230
+ const range = calculateTokenCharactersRange(state, options);
231
+ const loc = calculateTokenLocation(state.sourceCode.source, range);
232
+ return {
233
+ range,
234
+ loc
235
+ };
236
+ }
237
+
238
+ // src/constructor/handlers/tag.ts
239
+ var tag_exports = {};
240
+ __export(tag_exports, {
241
+ construct: () => construct
242
+ });
243
+ var ATTRIBUTE_START_TOKENS = /* @__PURE__ */ new Set(["AttributeKey" /* AttributeKey */, "AttributeAssignment" /* AttributeAssignment */]);
244
+ function construct(token, state) {
245
+ if (token.type === "OpenTagStart" /* OpenTagStart */) {
246
+ return handleOpenTagStart(state, token);
247
+ }
248
+ if (ATTRIBUTE_START_TOKENS.has(token.type)) {
249
+ return handleAttributeStart(state);
250
+ }
251
+ if (token.type === "OpenTagEnd" /* OpenTagEnd */) {
252
+ return handleOpenTagEnd(state, token);
253
+ }
254
+ if (token.type === "CloseTag" /* CloseTag */) {
255
+ return handleCloseTag(state, token);
256
+ }
257
+ state.caretPosition++;
258
+ return state;
259
+ }
260
+ function handleOpenTagStart(state, token) {
261
+ state.currentNode.openStart = createNodeFrom(token);
262
+ state.currentContext = {
263
+ parentRef: state.currentContext,
264
+ type: "TagName" /* TagName */
265
+ };
266
+ return state;
267
+ }
268
+ function handleAttributeStart(state) {
269
+ state.currentContext = {
270
+ parentRef: state.currentContext,
271
+ type: "Attributes" /* Attributes */
272
+ };
273
+ return state;
274
+ }
275
+ function handleOpenTagEnd(state, token) {
276
+ const tagName = state.currentNode.name;
277
+ state.currentNode.openEnd = createNodeFrom(token);
278
+ updateNodeEnd(state.currentNode, token);
279
+ if (tagName && SELF_CLOSING_ELEMENTS.has(tagName) && state.currentNode.openEnd.value === "/>") {
280
+ state.currentNode.selfClosing = true;
281
+ state.currentNode = state.currentNode.parentRef;
282
+ state.currentContext = state.currentContext.parentRef;
283
+ state.caretPosition++;
284
+ return state;
285
+ }
286
+ state.currentNode.selfClosing = false;
287
+ state.currentContext = {
288
+ parentRef: state.currentContext,
289
+ type: "TagContent" /* TagContent */
290
+ };
291
+ state.caretPosition++;
292
+ return state;
293
+ }
294
+ function handleCloseTag(state, token) {
295
+ state.currentNode.close = createNodeFrom(token);
296
+ updateNodeEnd(state.currentNode, token);
297
+ state.currentNode = state.currentNode.parentRef;
298
+ state.currentContext = state.currentContext.parentRef;
299
+ state.caretPosition++;
300
+ return state;
301
+ }
302
+
303
+ // src/constructor/handlers/comment.ts
304
+ var comment_exports = {};
305
+ __export(comment_exports, {
306
+ construct: () => construct2
307
+ });
308
+ function construct2(token, state) {
309
+ if (token.type === "CommentOpen" /* CommentOpen */) {
310
+ return handleCommentOpen(state, token);
311
+ }
312
+ if (token.type === "CommentContent" /* CommentContent */) {
313
+ return handleCommentContent(state, token);
314
+ }
315
+ if (token.type === "CommentClose" /* CommentClose */) {
316
+ return handleCommentClose(state, token);
317
+ }
318
+ return state;
319
+ }
320
+ function handleCommentOpen(state, token) {
321
+ state.currentNode.open = createNodeFrom(token);
322
+ state.caretPosition++;
323
+ return state;
324
+ }
325
+ function handleCommentContent(state, token) {
326
+ state.currentNode.value = createNodeFrom(token);
327
+ state.caretPosition++;
328
+ return state;
329
+ }
330
+ function handleCommentClose(state, token) {
331
+ state.currentNode.close = createNodeFrom(token);
332
+ updateNodeEnd(state.currentNode, token);
333
+ state.currentNode = state.currentNode.parentRef;
334
+ state.currentContext = state.currentContext.parentRef;
335
+ state.caretPosition++;
336
+ return state;
337
+ }
338
+
339
+ // src/constructor/handlers/doctype.ts
340
+ var doctype_exports = {};
341
+ __export(doctype_exports, {
342
+ construct: () => construct3
343
+ });
344
+ var ATTRIBUTES_START_TOKENS = /* @__PURE__ */ new Set([
345
+ "DoctypeAttributeWrapperStart" /* DoctypeAttributeWrapperStart */,
346
+ "DoctypeAttributeValue" /* DoctypeAttributeValue */
347
+ ]);
348
+ function construct3(token, state) {
349
+ if (token.type === "DoctypeOpen" /* DoctypeOpen */) {
350
+ return handleDoctypeOpen(state, token);
351
+ }
352
+ if (token.type === "DoctypeClose" /* DoctypeClose */) {
353
+ return handleDoctypeClose(state, token);
354
+ }
355
+ if (ATTRIBUTES_START_TOKENS.has(token.type)) {
356
+ return handleDoctypeAttributes(state);
357
+ }
358
+ state.caretPosition++;
359
+ return state;
360
+ }
361
+ function handleDoctypeOpen(state, token) {
362
+ state.currentNode.open = createNodeFrom(token);
363
+ state.caretPosition++;
364
+ return state;
365
+ }
366
+ function handleDoctypeClose(state, token) {
367
+ state.currentNode.close = createNodeFrom(token);
368
+ updateNodeEnd(state.currentNode, token);
369
+ state.currentNode = state.currentNode.parentRef;
370
+ state.currentContext = state.currentContext.parentRef;
371
+ state.caretPosition++;
372
+ return state;
373
+ }
374
+ function handleDoctypeAttributes(state) {
375
+ state.currentContext = {
376
+ parentRef: state.currentContext,
377
+ type: "DoctypeAttributes" /* DoctypeAttributes */
378
+ };
379
+ return state;
380
+ }
381
+
382
+ // src/constructor/handlers/tagName.ts
383
+ var tagName_exports = {};
384
+ __export(tagName_exports, {
385
+ construct: () => construct4
386
+ });
387
+ function construct4(token, state) {
388
+ if (token.type === "OpenTagStart" /* OpenTagStart */) {
389
+ handleTagOpenStart(state, token);
390
+ }
391
+ state.caretPosition++;
392
+ return state;
393
+ }
394
+ function handleTagOpenStart(state, token) {
395
+ state.currentNode.name = parseOpenTagName(token.value);
396
+ state.currentContext = state.currentContext.parentRef;
397
+ return state;
398
+ }
399
+
400
+ // src/constructor/handlers/attribute.ts
401
+ var attribute_exports = {};
402
+ __export(attribute_exports, {
403
+ construct: () => construct5
404
+ });
405
+ var OPEN_TAG_END_TOKENS = /* @__PURE__ */ new Set(["OpenTagEnd" /* OpenTagEnd */]);
406
+ function construct5(token, state) {
407
+ if (OPEN_TAG_END_TOKENS.has(token.type)) {
408
+ return handleOpenTagEnd2(state);
409
+ }
410
+ if (token.type === "AttributeKey" /* AttributeKey */) {
411
+ return handleAttributeKey(state, token);
412
+ }
413
+ if (token.type === "AttributeAssignment" /* AttributeAssignment */) {
414
+ return handleAttributeAssignment(state);
415
+ }
416
+ state.caretPosition++;
417
+ return state;
418
+ }
419
+ function getLastAttribute(state) {
420
+ const attributes = state.currentNode.attributes;
421
+ return last(attributes);
422
+ }
423
+ function handleOpenTagEnd2(state) {
424
+ state.currentContext = state.currentContext.parentRef;
425
+ return state;
426
+ }
427
+ function handleAttributeKey(state, token) {
428
+ const attribute = getLastAttribute(state);
429
+ if (attribute.key !== void 0 || attribute.value !== void 0) {
430
+ state.currentContext = state.currentContext.parentRef;
431
+ return state;
432
+ }
433
+ attribute.key = createNodeFrom(token);
434
+ state.caretPosition++;
435
+ return state;
436
+ }
437
+ function handleAttributeAssignment(state) {
438
+ const attribute = getLastAttribute(state);
439
+ if (attribute.value !== void 0) {
440
+ state.currentContext = state.currentContext.parentRef;
441
+ return state;
442
+ }
443
+ state.currentContext = {
444
+ parentRef: state.currentContext,
445
+ type: "AttributeValue" /* AttributeValue */
446
+ };
447
+ state.caretPosition++;
448
+ return state;
449
+ }
450
+
451
+ // src/constructor/handlers/attributes.ts
452
+ var attributes_exports = {};
453
+ __export(attributes_exports, {
454
+ construct: () => construct6
455
+ });
456
+ var ATTRIBUTE_START_TOKENS2 = /* @__PURE__ */ new Set(["AttributeKey" /* AttributeKey */, "AttributeAssignment" /* AttributeAssignment */]);
457
+ var ATTRIBUTE_END_TOKENS = /* @__PURE__ */ new Set(["OpenTagEnd" /* OpenTagEnd */]);
458
+ function construct6(token, state) {
459
+ if (ATTRIBUTE_START_TOKENS2.has(token.type)) {
460
+ return handleAttributeStart2(state, token);
461
+ }
462
+ if (ATTRIBUTE_END_TOKENS.has(token.type)) {
463
+ return handleOpenTagEnd3(state);
464
+ }
465
+ state.caretPosition++;
466
+ return state;
467
+ }
468
+ function handleAttributeStart2(state, token) {
469
+ initAttributesIfNone(state.currentNode);
470
+ state.currentNode.attributes.push({
471
+ type: "Attribute" /* Attribute */,
472
+ range: cloneRange(token.range),
473
+ loc: cloneLocation(token.loc)
474
+ });
475
+ state.currentContext = {
476
+ parentRef: state.currentContext,
477
+ type: "Attribute" /* Attribute */
478
+ };
479
+ return state;
480
+ }
481
+ function handleOpenTagEnd3(state) {
482
+ state.currentContext = state.currentContext.parentRef;
483
+ return state;
484
+ }
485
+
486
+ // src/constructor/handlers/tagContent.ts
487
+ var tagContent_exports = {};
488
+ __export(tagContent_exports, {
489
+ construct: () => construct7
490
+ });
491
+ function construct7(token, state) {
492
+ if (token.type === "OpenTagStart" /* OpenTagStart */) {
493
+ return handleOpenTagStart2(state, token);
494
+ }
495
+ if (token.type === "Text" /* Text */) {
496
+ return handleText(state, token);
497
+ }
498
+ if (token.type === "CloseTag" /* CloseTag */) {
499
+ return handleCloseTag2(state, token);
500
+ }
501
+ if (token.type === "CommentOpen" /* CommentOpen */) {
502
+ return handleCommentOpen2(state, token);
503
+ }
504
+ if (token.type === "DoctypeOpen" /* DoctypeOpen */) {
505
+ return handleDoctypeOpen2(state, token);
506
+ }
507
+ state.caretPosition++;
508
+ return state;
509
+ }
510
+ function handleOpenTagStart2(state, token) {
511
+ initChildrenIfNone(state.currentNode);
512
+ const tagNode = {
513
+ type: "Tag" /* Tag */,
514
+ parentRef: state.currentNode,
515
+ range: cloneRange(token.range),
516
+ loc: cloneLocation(token.loc),
517
+ attributes: [],
518
+ children: []
519
+ };
520
+ state.currentNode.children.push(tagNode);
521
+ state.currentNode = tagNode;
522
+ state.currentContext = {
523
+ parentRef: state.currentContext,
524
+ type: "Tag" /* Tag */
525
+ };
526
+ return state;
527
+ }
528
+ function handleText(state, token) {
529
+ initChildrenIfNone(state.currentNode);
530
+ const textNode = createNodeFrom(token);
531
+ state.currentNode.children.push(textNode);
532
+ state.caretPosition++;
533
+ return state;
534
+ }
535
+ function handleCloseTag2(state, token) {
536
+ const closeTagName = parseCloseTagName(token.value);
537
+ if (closeTagName !== state.currentNode.name) {
538
+ state.caretPosition++;
539
+ return state;
540
+ }
541
+ state.currentContext = state.currentContext.parentRef;
542
+ return state;
543
+ }
544
+ function handleCommentOpen2(state, token) {
545
+ initChildrenIfNone(state.currentNode);
546
+ const commentNode = {
547
+ type: "Comment" /* Comment */,
548
+ parentRef: state.currentNode,
549
+ range: cloneRange(token.range),
550
+ loc: cloneLocation(token.loc)
551
+ };
552
+ state.currentNode.children.push(commentNode);
553
+ state.currentNode = commentNode;
554
+ state.currentContext = {
555
+ parentRef: state.currentContext,
556
+ type: "Comment" /* Comment */
557
+ };
558
+ return state;
559
+ }
560
+ function handleDoctypeOpen2(state, token) {
561
+ initChildrenIfNone(state.currentNode);
562
+ const doctypeNode = {
563
+ type: "Doctype" /* Doctype */,
564
+ parentRef: state.currentNode,
565
+ range: cloneRange(token.range),
566
+ loc: cloneLocation(token.loc),
567
+ attributes: []
568
+ };
569
+ state.currentNode.children.push(doctypeNode);
570
+ state.currentNode = doctypeNode;
571
+ state.currentContext = {
572
+ parentRef: state.currentContext,
573
+ type: "Doctype" /* Doctype */
574
+ };
575
+ return state;
576
+ }
577
+
578
+ // src/constructor/handlers/attributeValue.ts
579
+ var attributeValue_exports = {};
580
+ __export(attributeValue_exports, {
581
+ construct: () => construct8
582
+ });
583
+ var VALUE_END_TOKENS = /* @__PURE__ */ new Set([
584
+ "OpenTagEnd" /* OpenTagEnd */,
585
+ "AttributeKey" /* AttributeKey */,
586
+ "AttributeAssignment" /* AttributeAssignment */
587
+ ]);
588
+ function construct8(token, state) {
589
+ if (VALUE_END_TOKENS.has(token.type)) {
590
+ return handleValueEnd(state);
591
+ }
592
+ if (token.type === "AttributeValue" /* AttributeValue */) {
593
+ return handleAttributeValue(state, token);
594
+ }
595
+ if (token.type === "AttributeValueWrapperStart" /* AttributeValueWrapperStart */) {
596
+ return handleAttributeValueWrapperStart(state, token);
597
+ }
598
+ if (token.type === "AttributeValueWrapperEnd" /* AttributeValueWrapperEnd */) {
599
+ return handleAttributeValueWrapperEnd(state, token);
600
+ }
601
+ state.caretPosition++;
602
+ return state;
603
+ }
604
+ function getLastAttribute2(state) {
605
+ const attributes = state.currentNode.attributes;
606
+ return last(attributes);
607
+ }
608
+ function handleValueEnd(state) {
609
+ state.currentContext = state.currentContext.parentRef;
610
+ return state;
611
+ }
612
+ function handleAttributeValue(state, token) {
613
+ const attribute = getLastAttribute2(state);
614
+ attribute.value = createNodeFrom(token);
615
+ updateNodeEnd(attribute, token);
616
+ state.caretPosition++;
617
+ return state;
618
+ }
619
+ function handleAttributeValueWrapperStart(state, token) {
620
+ const attribute = getLastAttribute2(state);
621
+ attribute.startWrapper = createNodeFrom(token);
622
+ if (!attribute.key) {
623
+ attribute.range = cloneRange(token.range);
624
+ attribute.loc = cloneLocation(token.loc);
625
+ }
626
+ state.caretPosition++;
627
+ return state;
628
+ }
629
+ function handleAttributeValueWrapperEnd(state, token) {
630
+ const attribute = getLastAttribute2(state);
631
+ attribute.endWrapper = createNodeFrom(token);
632
+ updateNodeEnd(attribute, token);
633
+ state.caretPosition++;
634
+ return state;
635
+ }
636
+
637
+ // src/constructor/handlers/doctypeAttribute.ts
638
+ var doctypeAttribute_exports = {};
639
+ __export(doctypeAttribute_exports, {
640
+ construct: () => construct9
641
+ });
642
+ function construct9(token, state) {
643
+ if (token.type === "DoctypeClose" /* DoctypeClose */) {
644
+ return handleDoctypeClose2(state);
645
+ }
646
+ if (token.type === "DoctypeAttributeWrapperStart" /* DoctypeAttributeWrapperStart */) {
647
+ return handleDoctypeAttributeWrapperStart(state, token);
648
+ }
649
+ if (token.type === "DoctypeAttributeWrapperEnd" /* DoctypeAttributeWrapperEnd */) {
650
+ return handleDoctypeAttributeWrapperEnd(state, token);
651
+ }
652
+ if (token.type === "DoctypeAttributeValue" /* DoctypeAttributeValue */) {
653
+ return handleDoctypeAttributeValue(state, token);
654
+ }
655
+ state.caretPosition++;
656
+ return state;
657
+ }
658
+ function getLastAttribute3(state) {
659
+ const attributes = state.currentNode.attributes;
660
+ return last(attributes);
661
+ }
662
+ function handleDoctypeClose2(state) {
663
+ state.currentContext = state.currentContext.parentRef;
664
+ return state;
665
+ }
666
+ function handleDoctypeAttributeWrapperStart(state, token) {
667
+ const attribute = getLastAttribute3(state);
668
+ if (attribute.value !== void 0) {
669
+ state.currentContext = state.currentContext.parentRef;
670
+ return state;
671
+ }
672
+ attribute.startWrapper = createNodeFrom(token);
673
+ attribute.range = cloneRange(token.range);
674
+ state.caretPosition++;
675
+ return state;
676
+ }
677
+ function handleDoctypeAttributeWrapperEnd(state, token) {
678
+ const attribute = getLastAttribute3(state);
679
+ attribute.endWrapper = createNodeFrom(token);
680
+ updateNodeEnd(attribute, token);
681
+ state.currentContext = state.currentContext.parentRef;
682
+ state.caretPosition++;
683
+ return state;
684
+ }
685
+ function handleDoctypeAttributeValue(state, token) {
686
+ const attribute = getLastAttribute3(state);
687
+ if (attribute.value !== void 0) {
688
+ state.currentContext = state.currentContext.parentRef;
689
+ return state;
690
+ }
691
+ attribute.value = createNodeFrom(token);
692
+ if (!attribute.startWrapper) {
693
+ attribute.range = cloneRange(token.range);
694
+ }
695
+ state.caretPosition++;
696
+ return state;
697
+ }
698
+
699
+ // src/constructor/handlers/doctypeAttributes.ts
700
+ var doctypeAttributes_exports = {};
701
+ __export(doctypeAttributes_exports, {
702
+ construct: () => construct10
703
+ });
704
+ var ATTRIBUTE_START_TOKENS3 = /* @__PURE__ */ new Set([
705
+ "DoctypeAttributeWrapperStart" /* DoctypeAttributeWrapperStart */,
706
+ "DoctypeAttributeValue" /* DoctypeAttributeValue */
707
+ ]);
708
+ function construct10(token, state) {
709
+ if (token.type === "DoctypeClose" /* DoctypeClose */) {
710
+ return handleDoctypeClose3(state);
711
+ }
712
+ if (ATTRIBUTE_START_TOKENS3.has(token.type)) {
713
+ return handleAttribute(state, token);
714
+ }
715
+ state.caretPosition++;
716
+ return state;
717
+ }
718
+ function handleDoctypeClose3(state) {
719
+ state.currentContext = state.currentContext.parentRef;
720
+ return state;
721
+ }
722
+ function handleAttribute(state, token) {
723
+ initAttributesIfNone(state.currentNode);
724
+ state.currentNode.attributes.push({
725
+ type: "DoctypeAttribute" /* DoctypeAttribute */,
726
+ range: cloneRange(token.range),
727
+ loc: cloneLocation(token.loc)
728
+ });
729
+ state.currentContext = {
730
+ type: "DoctypeAttribute" /* DoctypeAttribute */,
731
+ parentRef: state.currentContext
732
+ };
733
+ return state;
734
+ }
735
+
736
+ // src/constructor/constructTree.ts
737
+ var EMPTY_RANGE = [0, 0];
738
+ var EMPTY_LOC = {
739
+ start: {
740
+ line: 1,
741
+ column: 0
742
+ },
743
+ end: {
744
+ line: 1,
745
+ column: 0
746
+ }
747
+ };
748
+ var contextHandlers = {
749
+ ["Tag" /* Tag */]: tag_exports,
750
+ ["TagName" /* TagName */]: tagName_exports,
751
+ ["TagContent" /* TagContent */]: tagContent_exports,
752
+ ["Attributes" /* Attributes */]: attributes_exports,
753
+ ["Attribute" /* Attribute */]: attribute_exports,
754
+ ["AttributeValue" /* AttributeValue */]: attributeValue_exports,
755
+ ["Doctype" /* Doctype */]: doctype_exports,
756
+ ["DoctypeAttribute" /* DoctypeAttribute */]: doctypeAttribute_exports,
757
+ ["DoctypeAttributes" /* DoctypeAttributes */]: doctypeAttributes_exports,
758
+ ["Comment" /* Comment */]: comment_exports
759
+ };
760
+ function constructTree(tokens) {
761
+ const rootContext = {
762
+ type: "TagContent" /* TagContent */,
763
+ parentRef: void 0,
764
+ content: []
765
+ };
766
+ const lastToken = last(tokens);
767
+ const firstToken = first(tokens);
768
+ const range = lastToken ? [0, lastToken.range[1]] : EMPTY_RANGE;
769
+ const loc = lastToken && firstToken ? {
770
+ start: cloneLocation(firstToken.loc).start,
771
+ end: cloneLocation(lastToken.loc).end
772
+ } : EMPTY_LOC;
773
+ loc.start.line = 1;
774
+ const rootNode = {
775
+ type: "Document" /* Document */,
776
+ range,
777
+ children: [],
778
+ loc
779
+ };
780
+ const state = {
781
+ caretPosition: 0,
782
+ currentContext: rootContext,
783
+ currentNode: rootNode,
784
+ rootNode
785
+ };
786
+ const positionOffset = state.caretPosition;
787
+ processTokens(tokens, state, positionOffset);
788
+ return {
789
+ state,
790
+ ast: state.rootNode
791
+ };
792
+ }
793
+ function processTokens(tokens, state, positionOffset) {
794
+ let tokenIndex = state.caretPosition - positionOffset;
795
+ while (tokenIndex < tokens.length) {
796
+ const token = tokens[tokenIndex];
797
+ const handler = contextHandlers[state.currentContext.type].construct;
798
+ state = handler(token, state);
799
+ tokenIndex = state.caretPosition - positionOffset;
800
+ }
801
+ return state;
802
+ }
803
+
804
+ // src/tokenizer/charsBuffer.ts
805
+ var CharsBuffer = class {
806
+ charsBuffer = [];
807
+ concat(chars) {
808
+ const last2 = this.last();
809
+ if (!last2) {
810
+ this.charsBuffer.push(chars);
811
+ } else {
812
+ last2.concat(chars);
813
+ }
814
+ }
815
+ concatBuffer(buffer) {
816
+ this.charsBuffer.push(...buffer.charsBuffer);
817
+ }
818
+ length() {
819
+ return this.charsBuffer.map((chars) => chars.length()).reduce((a, b) => a + b, 0);
820
+ }
821
+ clear() {
822
+ this.charsBuffer = [];
823
+ }
824
+ value() {
825
+ return this.charsBuffer.map((chars) => chars.value).join("");
826
+ }
827
+ last() {
828
+ return last(this.charsBuffer);
829
+ }
830
+ first() {
831
+ return first(this.charsBuffer);
832
+ }
833
+ removeLast() {
834
+ this.charsBuffer.splice(-1, 1);
835
+ }
836
+ removeFirst() {
837
+ this.charsBuffer.splice(0, 1);
838
+ }
839
+ replace(other) {
840
+ this.charsBuffer = [...other.charsBuffer];
841
+ }
842
+ };
843
+
844
+ // src/tokenizer/handlers/data.ts
845
+ var data_exports = {};
846
+ __export(data_exports, {
847
+ handleContentEnd: () => handleContentEnd,
848
+ parse: () => parse
849
+ });
850
+ function parse(chars, state) {
851
+ const value = chars.value();
852
+ if (RE_OPEN_TAG_START.test(value)) {
853
+ return parseOpeningCornerBraceWithText(state);
854
+ }
855
+ if (value === "</") {
856
+ return parseOpeningCornerBraceWithSlash(state);
857
+ }
858
+ if (value === "<" || value === "<!" || value === "<!-") {
859
+ return state.sourceCode.next();
860
+ }
861
+ if (value === COMMENT_START) {
862
+ return parseCommentOpen(state);
863
+ }
864
+ if (isIncompleteDoctype(value)) {
865
+ return state.sourceCode.next();
866
+ }
867
+ if (value.toUpperCase() === "<!DOCTYPE") {
868
+ return parseDoctypeOpen(state);
869
+ }
870
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
871
+ state.decisionBuffer.clear();
872
+ state.sourceCode.next();
873
+ }
874
+ function handleContentEnd(state) {
875
+ const textContent = state.accumulatedContent.value() + state.decisionBuffer.value();
876
+ if (textContent.length !== 0) {
877
+ const position = calculateTokenPosition(state, { keepBuffer: false });
878
+ state.tokens.push({
879
+ type: "Text" /* Text */,
880
+ value: textContent,
881
+ range: position.range,
882
+ loc: position.loc
883
+ });
884
+ }
885
+ }
886
+ function generateTextToken(state) {
887
+ const position = calculateTokenPosition(state, { keepBuffer: false });
888
+ return {
889
+ type: "Text" /* Text */,
890
+ value: state.accumulatedContent.value(),
891
+ range: position.range,
892
+ loc: position.loc
893
+ };
894
+ }
895
+ function isIncompleteDoctype(chars) {
896
+ const charsUpperCase = chars.toUpperCase();
897
+ return charsUpperCase === "<!" || charsUpperCase === "<!D" || charsUpperCase === "<!DO" || charsUpperCase === "<!DOC" || // cSpell: disable-next-line
898
+ charsUpperCase === "<!DOCT" || // cSpell: disable-next-line
899
+ charsUpperCase === "<!DOCTY" || charsUpperCase === "<!DOCTYP";
900
+ }
901
+ function parseOpeningCornerBraceWithText(state) {
902
+ if (state.accumulatedContent.length() !== 0) {
903
+ state.tokens.push(generateTextToken(state));
904
+ }
905
+ state.accumulatedContent.replace(state.decisionBuffer);
906
+ state.decisionBuffer.clear();
907
+ state.currentContext = "OpenTagStart" /* OpenTagStart */;
908
+ state.sourceCode.next();
909
+ }
910
+ function parseOpeningCornerBraceWithSlash(state) {
911
+ if (state.accumulatedContent.length() !== 0) {
912
+ state.tokens.push(generateTextToken(state));
913
+ }
914
+ state.accumulatedContent.replace(state.decisionBuffer);
915
+ state.decisionBuffer.clear();
916
+ state.currentContext = "CloseTag" /* CloseTag */;
917
+ state.sourceCode.next();
918
+ }
919
+ function parseCommentOpen(state) {
920
+ if (state.accumulatedContent.length() !== 0) {
921
+ state.tokens.push(generateTextToken(state));
922
+ }
923
+ const range = [
924
+ state.sourceCode.index() - (COMMENT_START.length - 1),
925
+ state.sourceCode.index() + 1
926
+ ];
927
+ state.tokens.push({
928
+ type: "CommentOpen" /* CommentOpen */,
929
+ value: state.decisionBuffer.value(),
930
+ range,
931
+ loc: state.sourceCode.getLocationOf(range)
932
+ });
933
+ state.accumulatedContent.clear();
934
+ state.decisionBuffer.clear();
935
+ state.currentContext = "CommentContent" /* CommentContent */;
936
+ state.sourceCode.next();
937
+ }
938
+ function parseDoctypeOpen(state) {
939
+ if (state.accumulatedContent.length() !== 0) {
940
+ state.tokens.push(generateTextToken(state));
941
+ }
942
+ state.accumulatedContent.replace(state.decisionBuffer);
943
+ state.decisionBuffer.clear();
944
+ state.currentContext = "DoctypeOpen" /* DoctypeOpen */;
945
+ state.sourceCode.next();
946
+ }
947
+
948
+ // src/tokenizer/handlers/closeTag.ts
949
+ var closeTag_exports = {};
950
+ __export(closeTag_exports, {
951
+ parse: () => parse2
952
+ });
953
+ function parse2(chars, state) {
954
+ const value = chars.value();
955
+ if (value === ">") {
956
+ return parseClosingCornerBrace(state);
957
+ }
958
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
959
+ state.decisionBuffer.clear();
960
+ state.sourceCode.next();
961
+ }
962
+ function parseClosingCornerBrace(state) {
963
+ const position = calculateTokenPosition(state, { keepBuffer: true });
964
+ state.tokens.push({
965
+ type: "CloseTag" /* CloseTag */,
966
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
967
+ range: position.range,
968
+ loc: position.loc
969
+ });
970
+ state.accumulatedContent.clear();
971
+ state.decisionBuffer.clear();
972
+ state.currentContext = "Data" /* Data */;
973
+ state.sourceCode.next();
974
+ }
975
+
976
+ // src/tokenizer/handlers/attributes.ts
977
+ var attributes_exports2 = {};
978
+ __export(attributes_exports2, {
979
+ parse: () => parse3
980
+ });
981
+ function parse3(chars, state) {
982
+ const value = chars.value();
983
+ if (value === ">" || value === "/") {
984
+ return parseTagEnd(state);
985
+ }
986
+ if (value === "=") {
987
+ return parseEqual(state);
988
+ }
989
+ if (!isWhitespace(value)) {
990
+ return parseNoneWhitespace(chars, state);
991
+ }
992
+ state.decisionBuffer.clear();
993
+ state.sourceCode.next();
994
+ }
995
+ function parseTagEnd(state) {
996
+ const tagName = state.contextParams["Attributes" /* Attributes */]?.tagName;
997
+ state.accumulatedContent.clear();
998
+ state.decisionBuffer.clear();
999
+ state.currentContext = "OpenTagEnd" /* OpenTagEnd */;
1000
+ state.contextParams["OpenTagEnd" /* OpenTagEnd */] = { tagName };
1001
+ state.contextParams["Attributes" /* Attributes */] = void 0;
1002
+ }
1003
+ function parseEqual(state) {
1004
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1005
+ state.tokens.push({
1006
+ type: "AttributeAssignment" /* AttributeAssignment */,
1007
+ value: state.decisionBuffer.value(),
1008
+ range: position.range,
1009
+ loc: position.loc
1010
+ });
1011
+ state.accumulatedContent.clear();
1012
+ state.decisionBuffer.clear();
1013
+ state.currentContext = "AttributeValue" /* AttributeValue */;
1014
+ state.sourceCode.next();
1015
+ }
1016
+ function parseNoneWhitespace(chars, state) {
1017
+ state.accumulatedContent.replace(state.decisionBuffer);
1018
+ state.currentContext = "AttributeKey" /* AttributeKey */;
1019
+ state.decisionBuffer.clear();
1020
+ state.sourceCode.next();
1021
+ }
1022
+
1023
+ // src/tokenizer/handlers/openTagEnd.ts
1024
+ var openTagEnd_exports = {};
1025
+ __export(openTagEnd_exports, {
1026
+ parse: () => parse4
1027
+ });
1028
+ function parse4(chars, state) {
1029
+ if (chars.value() === ">") {
1030
+ return parseClosingCornerBrace2(state);
1031
+ }
1032
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1033
+ state.decisionBuffer.clear();
1034
+ state.sourceCode.next();
1035
+ }
1036
+ function parseClosingCornerBrace2(state) {
1037
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1038
+ state.tokens.push({
1039
+ type: "OpenTagEnd" /* OpenTagEnd */,
1040
+ value: state.accumulatedContent.value() + state.decisionBuffer.value(),
1041
+ range: position.range,
1042
+ loc: position.loc
1043
+ });
1044
+ state.accumulatedContent.clear();
1045
+ state.decisionBuffer.clear();
1046
+ state.currentContext = "Data" /* Data */;
1047
+ state.sourceCode.next();
1048
+ state.contextParams["OpenTagEnd" /* OpenTagEnd */] = void 0;
1049
+ }
1050
+
1051
+ // src/tokenizer/handlers/doctypeOpen.ts
1052
+ var doctypeOpen_exports = {};
1053
+ __export(doctypeOpen_exports, {
1054
+ parse: () => parse5
1055
+ });
1056
+ function parse5(chars, state) {
1057
+ const value = chars.value();
1058
+ if (isWhitespace(value)) {
1059
+ return parseWhitespace(state);
1060
+ }
1061
+ if (value === ">") {
1062
+ return parseClosingCornerBrace3(state);
1063
+ }
1064
+ state.decisionBuffer.clear();
1065
+ state.sourceCode.next();
1066
+ }
1067
+ function generateDoctypeOpenToken(state) {
1068
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1069
+ const token = {
1070
+ type: "DoctypeOpen" /* DoctypeOpen */,
1071
+ value: state.accumulatedContent.value(),
1072
+ range: position.range,
1073
+ loc: position.loc
1074
+ };
1075
+ return token;
1076
+ }
1077
+ function parseWhitespace(state) {
1078
+ state.tokens.push(generateDoctypeOpenToken(state));
1079
+ state.accumulatedContent.clear();
1080
+ state.decisionBuffer.clear();
1081
+ state.currentContext = "DoctypeAttributes" /* DoctypeAttributes */;
1082
+ }
1083
+ function parseClosingCornerBrace3(state) {
1084
+ state.tokens.push(generateDoctypeOpenToken(state));
1085
+ state.accumulatedContent.clear();
1086
+ state.decisionBuffer.clear();
1087
+ state.currentContext = "DoctypeClose" /* DoctypeClose */;
1088
+ }
1089
+
1090
+ // src/tokenizer/handlers/doctypeClose.ts
1091
+ var doctypeClose_exports = {};
1092
+ __export(doctypeClose_exports, {
1093
+ parse: () => parse6
1094
+ });
1095
+ function parse6(chars, state) {
1096
+ const position = calculateTokenPosition(state, { keepBuffer: true });
1097
+ state.tokens.push({
1098
+ type: "DoctypeClose" /* DoctypeClose */,
1099
+ value: state.decisionBuffer.value(),
1100
+ range: position.range,
1101
+ loc: position.loc
1102
+ });
1103
+ state.accumulatedContent.clear();
1104
+ state.decisionBuffer.clear();
1105
+ state.currentContext = "Data" /* Data */;
1106
+ state.sourceCode.next();
1107
+ }
1108
+
1109
+ // src/tokenizer/handlers/attributeKey.ts
1110
+ var attributeKey_exports = {};
1111
+ __export(attributeKey_exports, {
1112
+ parse: () => parse7
1113
+ });
1114
+ function parse7(chars, state) {
1115
+ if (isKeyBreak(chars)) {
1116
+ return parseKeyEnd(state);
1117
+ }
1118
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1119
+ state.decisionBuffer.clear();
1120
+ state.sourceCode.next();
1121
+ }
1122
+ function isKeyBreak(chars) {
1123
+ const value = chars.value();
1124
+ return value === "=" || value === "/" || value === ">" || isWhitespace(value);
1125
+ }
1126
+ function parseKeyEnd(state) {
1127
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1128
+ state.tokens.push({
1129
+ type: "AttributeKey" /* AttributeKey */,
1130
+ value: state.accumulatedContent.value(),
1131
+ range: position.range,
1132
+ loc: position.loc
1133
+ });
1134
+ state.accumulatedContent.clear();
1135
+ state.decisionBuffer.clear();
1136
+ state.currentContext = "Attributes" /* Attributes */;
1137
+ }
1138
+
1139
+ // src/tokenizer/handlers/openTagStart.ts
1140
+ var openTagStart_exports = {};
1141
+ __export(openTagStart_exports, {
1142
+ parse: () => parse8
1143
+ });
1144
+ function parse8(chars, state) {
1145
+ if (chars.value() === ">" || chars.value() === "/") {
1146
+ return parseTagEnd2(state);
1147
+ }
1148
+ if (isWhitespace(chars.value())) {
1149
+ return parseWhitespace2(state);
1150
+ }
1151
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1152
+ state.decisionBuffer.clear();
1153
+ state.sourceCode.next();
1154
+ }
1155
+ function parseTagEnd2(state) {
1156
+ const tagName = parseOpenTagName(state.accumulatedContent.value());
1157
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1158
+ state.tokens.push({
1159
+ type: "OpenTagStart" /* OpenTagStart */,
1160
+ value: state.accumulatedContent.value(),
1161
+ range: position.range,
1162
+ loc: position.loc
1163
+ });
1164
+ state.accumulatedContent.clear();
1165
+ state.decisionBuffer.clear();
1166
+ state.currentContext = "OpenTagEnd" /* OpenTagEnd */;
1167
+ state.contextParams["OpenTagEnd" /* OpenTagEnd */] = { tagName };
1168
+ }
1169
+ function parseWhitespace2(state) {
1170
+ const tagName = parseOpenTagName(state.accumulatedContent.value());
1171
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1172
+ state.tokens.push({
1173
+ type: "OpenTagStart" /* OpenTagStart */,
1174
+ value: state.accumulatedContent.value(),
1175
+ range: position.range,
1176
+ loc: position.loc
1177
+ });
1178
+ state.accumulatedContent.clear();
1179
+ state.decisionBuffer.clear();
1180
+ state.currentContext = "Attributes" /* Attributes */;
1181
+ state.contextParams["Attributes" /* Attributes */] = { tagName };
1182
+ state.sourceCode.next();
1183
+ }
1184
+
1185
+ // src/tokenizer/handlers/attributeValue.ts
1186
+ var attributeValue_exports2 = {};
1187
+ __export(attributeValue_exports2, {
1188
+ parse: () => parse9
1189
+ });
1190
+ function parse9(chars, state) {
1191
+ const value = chars.value();
1192
+ if (value === '"' || value === `'`) {
1193
+ return parseWrapper(state);
1194
+ }
1195
+ if (value === ">" || value === "/") {
1196
+ return parseTagEnd3(state);
1197
+ }
1198
+ if (!isWhitespace(value)) {
1199
+ return parseBare(state);
1200
+ }
1201
+ state.decisionBuffer.clear();
1202
+ state.sourceCode.next();
1203
+ }
1204
+ function parseWrapper(state) {
1205
+ const wrapper = state.decisionBuffer.value();
1206
+ const range = [state.sourceCode.index(), state.sourceCode.index() + 1];
1207
+ state.tokens.push({
1208
+ type: "AttributeValueWrapperStart" /* AttributeValueWrapperStart */,
1209
+ value: wrapper,
1210
+ range,
1211
+ loc: state.sourceCode.getLocationOf(range)
1212
+ });
1213
+ state.accumulatedContent.clear();
1214
+ state.decisionBuffer.clear();
1215
+ state.currentContext = "AttributeValueWrapped" /* AttributeValueWrapped */;
1216
+ state.contextParams["AttributeValueWrapped" /* AttributeValueWrapped */] = {
1217
+ wrapper
1218
+ };
1219
+ state.sourceCode.next();
1220
+ }
1221
+ function parseTagEnd3(state) {
1222
+ state.accumulatedContent.clear();
1223
+ state.decisionBuffer.clear();
1224
+ state.currentContext = "Attributes" /* Attributes */;
1225
+ }
1226
+ function parseBare(state) {
1227
+ state.accumulatedContent.replace(state.decisionBuffer);
1228
+ state.decisionBuffer.clear();
1229
+ state.currentContext = "AttributeValueBare" /* AttributeValueBare */;
1230
+ state.sourceCode.next();
1231
+ }
1232
+
1233
+ // src/tokenizer/handlers/commentContent.ts
1234
+ var commentContent_exports = {};
1235
+ __export(commentContent_exports, {
1236
+ parse: () => parse10
1237
+ });
1238
+ function parse10(chars, state) {
1239
+ const value = chars.value();
1240
+ if (value === "-" || value === "--") {
1241
+ return state.sourceCode.next();
1242
+ }
1243
+ if (value === COMMENT_END) {
1244
+ return parseCommentClose(state);
1245
+ }
1246
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1247
+ state.decisionBuffer.clear();
1248
+ state.sourceCode.next();
1249
+ }
1250
+ function parseCommentClose(state) {
1251
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1252
+ const endRange = [position.range[1], position.range[1] + COMMENT_END.length];
1253
+ state.tokens.push({
1254
+ type: "CommentContent" /* CommentContent */,
1255
+ value: state.accumulatedContent.value(),
1256
+ range: position.range,
1257
+ loc: position.loc
1258
+ });
1259
+ state.tokens.push({
1260
+ type: "CommentClose" /* CommentClose */,
1261
+ value: state.decisionBuffer.value(),
1262
+ range: endRange,
1263
+ loc: state.sourceCode.getLocationOf(endRange)
1264
+ });
1265
+ state.accumulatedContent.clear();
1266
+ state.decisionBuffer.clear();
1267
+ state.currentContext = "Data" /* Data */;
1268
+ state.sourceCode.next();
1269
+ }
1270
+
1271
+ // src/tokenizer/handlers/doctypeAttributes.ts
1272
+ var doctypeAttributes_exports2 = {};
1273
+ __export(doctypeAttributes_exports2, {
1274
+ parse: () => parse11
1275
+ });
1276
+ function parse11(chars, state) {
1277
+ const value = chars.value();
1278
+ if (value === '"' || value === `'`) {
1279
+ return parseWrapper2(state);
1280
+ }
1281
+ if (value === ">") {
1282
+ return parseClosingCornerBrace4(state);
1283
+ }
1284
+ if (!isWhitespace(value)) {
1285
+ return parseBare2(state);
1286
+ }
1287
+ state.decisionBuffer.clear();
1288
+ state.sourceCode.next();
1289
+ }
1290
+ function parseWrapper2(state) {
1291
+ const wrapper = state.decisionBuffer.value();
1292
+ const range = [state.sourceCode.index(), state.sourceCode.index() + wrapper.length];
1293
+ state.tokens.push({
1294
+ type: "DoctypeAttributeWrapperStart" /* DoctypeAttributeWrapperStart */,
1295
+ value: wrapper,
1296
+ range,
1297
+ loc: state.sourceCode.getLocationOf(range)
1298
+ });
1299
+ state.accumulatedContent.clear();
1300
+ state.decisionBuffer.clear();
1301
+ state.currentContext = "DoctypeAttributeWrapped" /* DoctypeAttributeWrapped */;
1302
+ state.contextParams["DoctypeAttributeWrapped" /* DoctypeAttributeWrapped */] = {
1303
+ wrapper
1304
+ };
1305
+ state.sourceCode.next();
1306
+ }
1307
+ function parseClosingCornerBrace4(state) {
1308
+ state.accumulatedContent.clear();
1309
+ state.decisionBuffer.clear();
1310
+ state.currentContext = "DoctypeClose" /* DoctypeClose */;
1311
+ }
1312
+ function parseBare2(state) {
1313
+ state.accumulatedContent.replace(state.decisionBuffer);
1314
+ state.decisionBuffer.clear();
1315
+ state.currentContext = "DoctypeAttributeBare" /* DoctypeAttributeBare */;
1316
+ state.sourceCode.next();
1317
+ }
1318
+
1319
+ // src/tokenizer/handlers/attributeValueBare.ts
1320
+ var attributeValueBare_exports = {};
1321
+ __export(attributeValueBare_exports, {
1322
+ parse: () => parse12
1323
+ });
1324
+ function parse12(chars, state) {
1325
+ const value = chars.value();
1326
+ if (isWhitespace(value) || value === ">" || value === "/") {
1327
+ return parseValueEnd(state);
1328
+ }
1329
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1330
+ state.decisionBuffer.clear();
1331
+ state.sourceCode.next();
1332
+ }
1333
+ function parseValueEnd(state) {
1334
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1335
+ state.tokens.push({
1336
+ type: "AttributeValue" /* AttributeValue */,
1337
+ value: state.accumulatedContent.value(),
1338
+ range: position.range,
1339
+ loc: position.loc
1340
+ });
1341
+ state.accumulatedContent.clear();
1342
+ state.decisionBuffer.clear();
1343
+ state.currentContext = "Attributes" /* Attributes */;
1344
+ }
1345
+
1346
+ // src/tokenizer/handlers/doctypeAttributeBare.ts
1347
+ var doctypeAttributeBare_exports = {};
1348
+ __export(doctypeAttributeBare_exports, {
1349
+ parse: () => parse13
1350
+ });
1351
+ function parse13(chars, state) {
1352
+ const value = chars.value();
1353
+ if (isWhitespace(value) || value === ">") {
1354
+ return parseAttributeEnd(state);
1355
+ }
1356
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1357
+ state.decisionBuffer.clear();
1358
+ state.sourceCode.next();
1359
+ }
1360
+ function parseAttributeEnd(state) {
1361
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1362
+ state.tokens.push({
1363
+ type: "DoctypeAttributeValue" /* DoctypeAttributeValue */,
1364
+ value: state.accumulatedContent.value(),
1365
+ range: position.range,
1366
+ loc: position.loc
1367
+ });
1368
+ state.accumulatedContent.clear();
1369
+ state.decisionBuffer.clear();
1370
+ state.currentContext = "DoctypeAttributes" /* DoctypeAttributes */;
1371
+ }
1372
+
1373
+ // src/tokenizer/handlers/attributeValueWrapped.ts
1374
+ var attributeValueWrapped_exports = {};
1375
+ __export(attributeValueWrapped_exports, {
1376
+ parse: () => parse14
1377
+ });
1378
+ function parse14(chars, state) {
1379
+ const wrapperChar = state.contextParams["AttributeValueWrapped" /* AttributeValueWrapped */]?.wrapper;
1380
+ if (chars.value() === wrapperChar) {
1381
+ return parseWrapper3(state);
1382
+ }
1383
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1384
+ state.decisionBuffer.clear();
1385
+ state.sourceCode.next();
1386
+ }
1387
+ function parseWrapper3(state) {
1388
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1389
+ const endWrapperPosition = position.range[1];
1390
+ state.tokens.push({
1391
+ type: "AttributeValue" /* AttributeValue */,
1392
+ value: state.accumulatedContent.value(),
1393
+ range: position.range,
1394
+ loc: position.loc
1395
+ });
1396
+ const range = [endWrapperPosition, endWrapperPosition + 1];
1397
+ state.tokens.push({
1398
+ type: "AttributeValueWrapperEnd" /* AttributeValueWrapperEnd */,
1399
+ value: state.decisionBuffer.value(),
1400
+ range,
1401
+ loc: state.sourceCode.getLocationOf(range)
1402
+ });
1403
+ state.accumulatedContent.clear();
1404
+ state.decisionBuffer.clear();
1405
+ state.currentContext = "Attributes" /* Attributes */;
1406
+ state.sourceCode.next();
1407
+ state.contextParams["AttributeValueWrapped" /* AttributeValueWrapped */] = void 0;
1408
+ }
1409
+
1410
+ // src/tokenizer/handlers/doctypeAttributeWrapped.ts
1411
+ var doctypeAttributeWrapped_exports = {};
1412
+ __export(doctypeAttributeWrapped_exports, {
1413
+ parse: () => parse15
1414
+ });
1415
+ function parse15(chars, state) {
1416
+ const value = chars.value();
1417
+ const wrapperChar = state.contextParams["DoctypeAttributeWrapped" /* DoctypeAttributeWrapped */]?.wrapper;
1418
+ if (value === wrapperChar) {
1419
+ return parseWrapper4(state);
1420
+ }
1421
+ state.accumulatedContent.concatBuffer(state.decisionBuffer);
1422
+ state.decisionBuffer.clear();
1423
+ state.sourceCode.next();
1424
+ }
1425
+ function parseWrapper4(state) {
1426
+ const position = calculateTokenPosition(state, { keepBuffer: false });
1427
+ const endWrapperPosition = position.range[1];
1428
+ state.tokens.push({
1429
+ type: "DoctypeAttributeValue" /* DoctypeAttributeValue */,
1430
+ value: state.accumulatedContent.value(),
1431
+ range: position.range,
1432
+ loc: position.loc
1433
+ });
1434
+ const range = [endWrapperPosition, endWrapperPosition + 1];
1435
+ state.tokens.push({
1436
+ type: "DoctypeAttributeWrapperEnd" /* DoctypeAttributeWrapperEnd */,
1437
+ value: state.decisionBuffer.value(),
1438
+ range,
1439
+ loc: state.sourceCode.getLocationOf(range)
1440
+ });
1441
+ state.accumulatedContent.clear();
1442
+ state.decisionBuffer.clear();
1443
+ state.currentContext = "DoctypeAttributes" /* DoctypeAttributes */;
1444
+ state.sourceCode.next();
1445
+ state.contextParams["DoctypeAttributeWrapped" /* DoctypeAttributeWrapped */] = void 0;
1446
+ }
1447
+
1448
+ // src/tokenizer/handlers/index.ts
1449
+ var noop = {
1450
+ parse: () => {
1451
+ }
1452
+ };
1453
+
1454
+ // src/tokenizer/chars.ts
1455
+ var Chars = class {
1456
+ constructor(value, range) {
1457
+ this.value = value;
1458
+ this.range = range;
1459
+ }
1460
+ concat(chars) {
1461
+ this.value += chars.value;
1462
+ this.range[1] = chars.range[1];
1463
+ }
1464
+ equals(chars) {
1465
+ return this.value === chars;
1466
+ }
1467
+ length() {
1468
+ return this.value.length;
1469
+ }
1470
+ };
1471
+
1472
+ // src/tokenizer/sourceCode.ts
1473
+ var SourceCode = class {
1474
+ constructor(source) {
1475
+ this.source = source;
1476
+ this.charsList = this.createCharsList();
1477
+ }
1478
+ charsList;
1479
+ charsIndex = 0;
1480
+ getLocationOf(range) {
1481
+ return {
1482
+ start: getLineInfo(this.source, range[0]),
1483
+ end: getLineInfo(this.source, range[1])
1484
+ };
1485
+ }
1486
+ current() {
1487
+ return this.charsList[this.charsIndex];
1488
+ }
1489
+ next() {
1490
+ this.charsIndex++;
1491
+ }
1492
+ prev() {
1493
+ this.charsIndex--;
1494
+ }
1495
+ isEof() {
1496
+ return this.charsIndex >= this.charsList.length;
1497
+ }
1498
+ index() {
1499
+ const current = this.current();
1500
+ return current.range[1] - 1;
1501
+ }
1502
+ createCharsList() {
1503
+ const charsList = [];
1504
+ let sourceIndex = 0;
1505
+ while (sourceIndex < this.source.length) {
1506
+ charsList.push(new Chars(this.source[sourceIndex], [sourceIndex, sourceIndex + 1]));
1507
+ sourceIndex++;
1508
+ }
1509
+ return charsList;
1510
+ }
1511
+ };
1512
+
1513
+ // src/tokenizer/tokenize.ts
1514
+ var contextHandlers2 = {
1515
+ ["Data" /* Data */]: data_exports,
1516
+ ["Attributes" /* Attributes */]: attributes_exports2,
1517
+ ["AttributeKey" /* AttributeKey */]: attributeKey_exports,
1518
+ ["AttributeValue" /* AttributeValue */]: attributeValue_exports2,
1519
+ ["AttributeValueBare" /* AttributeValueBare */]: attributeValueBare_exports,
1520
+ ["AttributeValueWrapped" /* AttributeValueWrapped */]: attributeValueWrapped_exports,
1521
+ ["OpenTagStart" /* OpenTagStart */]: openTagStart_exports,
1522
+ ["OpenTagEnd" /* OpenTagEnd */]: openTagEnd_exports,
1523
+ ["CloseTag" /* CloseTag */]: closeTag_exports,
1524
+ ["DoctypeOpen" /* DoctypeOpen */]: doctypeOpen_exports,
1525
+ ["DoctypeClose" /* DoctypeClose */]: doctypeClose_exports,
1526
+ ["DoctypeAttributes" /* DoctypeAttributes */]: doctypeAttributes_exports2,
1527
+ ["DoctypeAttributeBare" /* DoctypeAttributeBare */]: doctypeAttributeBare_exports,
1528
+ ["DoctypeAttributeWrapped" /* DoctypeAttributeWrapped */]: doctypeAttributeWrapped_exports,
1529
+ ["CommentOpen" /* CommentOpen */]: noop,
1530
+ ["CommentClose" /* CommentClose */]: noop,
1531
+ ["CommentContent" /* CommentContent */]: commentContent_exports
1532
+ };
1533
+ function tokenizeChars(state) {
1534
+ while (!state.sourceCode.isEof()) {
1535
+ const handler2 = contextHandlers2[state.currentContext];
1536
+ state.decisionBuffer.concat(state.sourceCode.current());
1537
+ handler2.parse(state.decisionBuffer, state);
1538
+ }
1539
+ const handler = contextHandlers2[state.currentContext];
1540
+ state.sourceCode.prev();
1541
+ if (handler.handleContentEnd !== void 0) {
1542
+ handler.handleContentEnd(state);
1543
+ }
1544
+ }
1545
+ function tokenize(source) {
1546
+ const tokens = [];
1547
+ const state = {
1548
+ contextParams: {},
1549
+ currentContext: "Data" /* Data */,
1550
+ sourceCode: new SourceCode(source),
1551
+ decisionBuffer: new CharsBuffer(),
1552
+ accumulatedContent: new CharsBuffer(),
1553
+ tokens: {
1554
+ push(token) {
1555
+ tokens.push(token);
1556
+ }
1557
+ }
1558
+ };
1559
+ tokenizeChars(state);
1560
+ return {
1561
+ state,
1562
+ tokens
1563
+ };
1564
+ }
1565
+
1566
+ // src/parser/parse.ts
1567
+ function parse16(source, _options = {}) {
1568
+ const { tokens } = tokenize(source);
1569
+ const { ast } = constructTree(tokens);
1570
+ return {
1571
+ ast: clearParent(ast),
1572
+ tokens
1573
+ };
1574
+ }
1575
+
1576
+ // src/visitorKeys.ts
1577
+ import { unionWith } from "eslint-visitor-keys";
1578
+ var keys = {
1579
+ Program: ["body"],
1580
+ Document: ["children"],
1581
+ Doctype: ["open", "close", "attributes"],
1582
+ DoctypeOpen: [],
1583
+ DoctypeClose: [],
1584
+ DoctypeAttribute: ["key"],
1585
+ DoctypeAttributeKey: [],
1586
+ DoctypeAttributeValue: [],
1587
+ DoctypeAttributeWrapperEnd: [],
1588
+ DoctypeAttributeWrapperStart: [],
1589
+ Attribute: ["key", "value"],
1590
+ AttributeKey: [],
1591
+ AttributeValue: [],
1592
+ AttributeValueWrapperEnd: [],
1593
+ AttributeValueWrapperStart: [],
1594
+ Tag: ["children", "attributes"],
1595
+ OpenTagEnd: [],
1596
+ OpenTagStart: [],
1597
+ CloseTag: [],
1598
+ Comment: ["open", "close", "value"],
1599
+ CommentOpen: [],
1600
+ CommentClose: [],
1601
+ CommentContent: [],
1602
+ Text: []
1603
+ };
1604
+ var vistorKeysCache = null;
1605
+ function getVisitorKeys() {
1606
+ if (!vistorKeysCache) {
1607
+ vistorKeysCache = unionWith(keys);
1608
+ }
1609
+ return vistorKeysCache;
1610
+ }
1611
+ var visitorKeys = getVisitorKeys();
1612
+
1613
+ // src/parser/traverse.ts
1614
+ function traverse(node, visitor) {
1615
+ if (!node) {
1616
+ return;
1617
+ }
1618
+ visitor(node);
1619
+ const type = node.type;
1620
+ const keys2 = visitorKeys[type];
1621
+ if (!keys2 || keys2.length <= 0) {
1622
+ return;
1623
+ }
1624
+ keys2.forEach((key) => {
1625
+ const value = node[key];
1626
+ if (value) {
1627
+ if (Array.isArray(value)) {
1628
+ value.forEach((n) => traverse(n, visitor));
1629
+ } else {
1630
+ traverse(value, visitor);
1631
+ }
1632
+ }
1633
+ });
1634
+ }
1635
+
1636
+ // src/parser/parseForESLint.ts
1637
+ function parseForESLint(source, options = {}) {
1638
+ const { ast, tokens } = parse16(source, options);
1639
+ const programNode = {
1640
+ type: "Program" /* Program */,
1641
+ body: [ast],
1642
+ comments: [],
1643
+ tokens: tokens.filter(
1644
+ (token) => token.type !== "CommentOpen" /* CommentOpen */ && token.type !== "CommentClose" /* CommentClose */ && token.type !== "CommentContent" /* CommentContent */
1645
+ ),
1646
+ range: ast.range,
1647
+ loc: ast.loc
1648
+ };
1649
+ traverse(programNode, (node) => {
1650
+ if (node.type === "CommentContent" /* CommentContent */) {
1651
+ programNode.comments.push({
1652
+ type: node.type,
1653
+ range: node.range,
1654
+ loc: node.loc,
1655
+ value: node.value
1656
+ });
1657
+ }
1658
+ });
1659
+ return {
1660
+ ast: programNode,
1661
+ visitorKeys,
1662
+ services: {
1663
+ isSVG: true
1664
+ }
1665
+ };
1666
+ }
1667
+
1668
+ // src/index.ts
1669
+ function parseSVG(code, options = {}) {
1670
+ return parseForESLint(code, options).ast;
1671
+ }
1672
+ var name2 = meta.name;
1673
+ var VisitorKeys = visitorKeys;
1674
+ export {
1675
+ ParseError,
1676
+ VisitorKeys,
1677
+ meta,
1678
+ name2 as name,
1679
+ parseForESLint,
1680
+ parseSVG
1681
+ };