svg-eslint-parser 0.0.4 → 0.0.5

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