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