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