svg-eslint-parser 0.0.1 → 0.0.3

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