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