UNPKG

289 kBJavaScriptView Raw
1/**
2 * @author Toru Nagashima <https://github.com/mysticatea>
3 * See LICENSE file in root directory for full license.
4 */
5'use strict';
6
7Object.defineProperty(exports, '__esModule', { value: true });
8
9var path = require('path');
10var Evk = require('eslint-visitor-keys');
11var sortedLastIndex = require('lodash/sortedLastIndex');
12var assert = require('assert');
13var last = require('lodash/last');
14var findLastIndex = require('lodash/findLastIndex');
15var debugFactory = require('debug');
16var first = require('lodash/first');
17var sortedIndexBy = require('lodash/sortedIndexBy');
18var escope = require('eslint-scope');
19var Module = require('module');
20var semver = require('semver');
21var dependencyEspree = require('espree');
22var sortedLastIndexBy = require('lodash/sortedLastIndexBy');
23var EventEmitter = require('events');
24var esquery = require('esquery');
25var union = require('lodash/union');
26var intersection = require('lodash/intersection');
27var memoize = require('lodash/memoize');
28
29function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
30
31function _interopNamespace(e) {
32 if (e && e.__esModule) return e;
33 var n = Object.create(null);
34 if (e) {
35 Object.keys(e).forEach(function (k) {
36 if (k !== 'default') {
37 var d = Object.getOwnPropertyDescriptor(e, k);
38 Object.defineProperty(n, k, d.get ? d : {
39 enumerable: true,
40 get: function () { return e[k]; }
41 });
42 }
43 });
44 }
45 n["default"] = e;
46 return Object.freeze(n);
47}
48
49var path__namespace = /*#__PURE__*/_interopNamespace(path);
50var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
51var Evk__namespace = /*#__PURE__*/_interopNamespace(Evk);
52var sortedLastIndex__default = /*#__PURE__*/_interopDefaultLegacy(sortedLastIndex);
53var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
54var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
55var findLastIndex__default = /*#__PURE__*/_interopDefaultLegacy(findLastIndex);
56var debugFactory__default = /*#__PURE__*/_interopDefaultLegacy(debugFactory);
57var first__default = /*#__PURE__*/_interopDefaultLegacy(first);
58var sortedIndexBy__default = /*#__PURE__*/_interopDefaultLegacy(sortedIndexBy);
59var escope__namespace = /*#__PURE__*/_interopNamespace(escope);
60var Module__default = /*#__PURE__*/_interopDefaultLegacy(Module);
61var dependencyEspree__namespace = /*#__PURE__*/_interopNamespace(dependencyEspree);
62var sortedLastIndexBy__default = /*#__PURE__*/_interopDefaultLegacy(sortedLastIndexBy);
63var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
64var esquery__default = /*#__PURE__*/_interopDefaultLegacy(esquery);
65var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
66var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
67var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
68
69function isAcornStyleParseError(x) {
70 return (typeof x.message === "string" &&
71 typeof x.pos === "number" &&
72 typeof x.loc === "object" &&
73 x.loc !== null &&
74 typeof x.loc.line === "number" &&
75 typeof x.loc.column === "number");
76}
77function isTSError(x) {
78 return (!(x instanceof ParseError) &&
79 typeof x.message === "string" &&
80 typeof x.index === "number" &&
81 typeof x.lineNumber === "number" &&
82 typeof x.column === "number" &&
83 x.name === "TSError");
84}
85class ParseError extends SyntaxError {
86 constructor(message, code, offset, line, column) {
87 super(message);
88 this.code = code;
89 this.index = offset;
90 this.lineNumber = line;
91 this.column = column;
92 }
93 static fromCode(code, offset, line, column) {
94 return new ParseError(code, code, offset, line, column);
95 }
96 static normalize(x) {
97 if (isTSError(x)) {
98 return new ParseError(x.message, undefined, x.index, x.lineNumber, x.column);
99 }
100 if (ParseError.isParseError(x)) {
101 return x;
102 }
103 if (isAcornStyleParseError(x)) {
104 return new ParseError(x.message, undefined, x.pos, x.loc.line, x.loc.column);
105 }
106 return null;
107 }
108 static isParseError(x) {
109 return (x instanceof ParseError ||
110 (typeof x.message === "string" &&
111 typeof x.index === "number" &&
112 typeof x.lineNumber === "number" &&
113 typeof x.column === "number"));
114 }
115}
116
117const NS = Object.freeze({
118 HTML: "http://www.w3.org/1999/xhtml",
119 MathML: "http://www.w3.org/1998/Math/MathML",
120 SVG: "http://www.w3.org/2000/svg",
121 XLink: "http://www.w3.org/1999/xlink",
122 XML: "http://www.w3.org/XML/1998/namespace",
123 XMLNS: "http://www.w3.org/2000/xmlns/",
124});
125
126const KEYS = Evk__namespace.unionWith({
127 VAttribute: ["key", "value"],
128 VDirectiveKey: ["name", "argument", "modifiers"],
129 VDocumentFragment: ["children"],
130 VElement: ["startTag", "children", "endTag"],
131 VEndTag: [],
132 VExpressionContainer: ["expression"],
133 VFilter: ["callee", "arguments"],
134 VFilterSequenceExpression: ["expression", "filters"],
135 VForExpression: ["left", "right"],
136 VIdentifier: [],
137 VLiteral: [],
138 VOnExpression: ["body"],
139 VSlotScopeExpression: ["params"],
140 VStartTag: ["attributes"],
141 VText: [],
142});
143function fallbackKeysFilter(key) {
144 let value = null;
145 return (key !== "comments" &&
146 key !== "leadingComments" &&
147 key !== "loc" &&
148 key !== "parent" &&
149 key !== "range" &&
150 key !== "tokens" &&
151 key !== "trailingComments" &&
152 (value = this[key]) !== null &&
153 typeof value === "object" &&
154 (typeof value.type === "string" || Array.isArray(value)));
155}
156function getFallbackKeys(node) {
157 return Object.keys(node).filter(fallbackKeysFilter, node);
158}
159function isNode(x) {
160 return x !== null && typeof x === "object" && typeof x.type === "string";
161}
162function traverse(node, parent, visitor) {
163 let i = 0;
164 let j = 0;
165 visitor.enterNode(node, parent);
166 const keys = (visitor.visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
167 for (i = 0; i < keys.length; ++i) {
168 const child = node[keys[i]];
169 if (Array.isArray(child)) {
170 for (j = 0; j < child.length; ++j) {
171 if (isNode(child[j])) {
172 traverse(child[j], node, visitor);
173 }
174 }
175 }
176 else if (isNode(child)) {
177 traverse(child, node, visitor);
178 }
179 }
180 visitor.leaveNode(node, parent);
181}
182function traverseNodes(node, visitor) {
183 traverse(node, null, visitor);
184}
185
186var index = /*#__PURE__*/Object.freeze({
187 __proto__: null,
188 ParseError: ParseError,
189 NS: NS,
190 KEYS: KEYS,
191 traverseNodes: traverseNodes,
192 getFallbackKeys: getFallbackKeys
193});
194
195class LinesAndColumns {
196 constructor(ltOffsets) {
197 this.ltOffsets = ltOffsets;
198 }
199 getLocFromIndex(index) {
200 const line = sortedLastIndex__default["default"](this.ltOffsets, index) + 1;
201 const column = index - (line === 1 ? 0 : this.ltOffsets[line - 2]);
202 return { line, column };
203 }
204 createOffsetLocationCalculator(offset) {
205 return {
206 getFixOffset() {
207 return offset;
208 },
209 getLocFromIndex: this.getLocFromIndex.bind(this),
210 };
211 }
212}
213
214class LocationCalculatorForHtml extends LinesAndColumns {
215 constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) {
216 super(ltOffsets);
217 this.gapOffsets = gapOffsets;
218 this.ltOffsets = ltOffsets;
219 this.baseOffset = baseOffset || 0;
220 this.baseIndexOfGap =
221 this.baseOffset === 0
222 ? 0
223 : sortedLastIndex__default["default"](gapOffsets, this.baseOffset);
224 this.shiftOffset = shiftOffset;
225 }
226 getSubCalculatorAfter(offset) {
227 return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset + offset, this.shiftOffset);
228 }
229 getSubCalculatorShift(offset) {
230 return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset, this.shiftOffset + offset);
231 }
232 _getGap(index) {
233 const offsets = this.gapOffsets;
234 let g0 = sortedLastIndex__default["default"](offsets, index + this.baseOffset);
235 let pos = index + this.baseOffset + g0 - this.baseIndexOfGap;
236 while (g0 < offsets.length && offsets[g0] <= pos) {
237 g0 += 1;
238 pos += 1;
239 }
240 return g0 - this.baseIndexOfGap;
241 }
242 getLocation(index) {
243 return this.getLocFromIndex(this.getOffsetWithGap(index));
244 }
245 getOffsetWithGap(index) {
246 return index + this.getFixOffset(index);
247 }
248 getFixOffset(offset) {
249 const shiftOffset = this.shiftOffset;
250 const gap = this._getGap(offset + shiftOffset);
251 return this.baseOffset + gap + shiftOffset;
252 }
253}
254
255const debug = debugFactory__default["default"]("vue-eslint-parser");
256
257function isScriptElement(node) {
258 return node.type === "VElement" && node.name === "script";
259}
260function isScriptSetupElement(script) {
261 return (isScriptElement(script) &&
262 script.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "setup"));
263}
264function isTemplateElement(node) {
265 return node.type === "VElement" && node.name === "template";
266}
267function isStyleElement(node) {
268 return node.type === "VElement" && node.name === "style";
269}
270function getOwnerDocument(leafNode) {
271 let node = leafNode;
272 while (node != null && node.type !== "VDocumentFragment") {
273 node = node.parent;
274 }
275 return node;
276}
277function isLang(attribute) {
278 return attribute.directive === false && attribute.key.name === "lang";
279}
280function getLang(element) {
281 const langAttr = element && element.startTag.attributes.find(isLang);
282 const lang = langAttr && langAttr.value && langAttr.value.value;
283 return lang || null;
284}
285function isTSLang(element) {
286 const lang = getLang(element);
287 return lang === "ts" || lang === "tsx";
288}
289function findGenericDirective(element) {
290 return (element.startTag.attributes.find((attr) => {
291 var _a, _b;
292 return attr.directive &&
293 ((_b = (_a = attr.value) === null || _a === void 0 ? void 0 : _a.expression) === null || _b === void 0 ? void 0 : _b.type) === "VGenericExpression";
294 }) || null);
295}
296
297function isParserObject(value) {
298 return isEnhancedParserObject(value) || isBasicParserObject(value);
299}
300function isEnhancedParserObject(value) {
301 return Boolean(value && typeof value.parseForESLint === "function");
302}
303function isBasicParserObject(value) {
304 return Boolean(value && typeof value.parse === "function");
305}
306
307function isSFCFile(parserOptions) {
308 if (parserOptions.filePath === "<input>") {
309 return true;
310 }
311 return path__namespace.extname(parserOptions.filePath || "unknown.vue") === ".vue";
312}
313function getScriptParser(parser, getParserLang) {
314 if (isParserObject(parser)) {
315 return parser;
316 }
317 if (parser && typeof parser === "object") {
318 const parserLang = getParserLang();
319 const parserLangs = parserLang == null
320 ? []
321 : typeof parserLang === "string"
322 ? [parserLang]
323 : parserLang;
324 for (const lang of parserLangs) {
325 const parserForLang = lang && parser[lang];
326 if (typeof parserForLang === "string" ||
327 isParserObject(parserForLang)) {
328 return parserForLang;
329 }
330 }
331 return parser.js;
332 }
333 return typeof parser === "string" ? parser : undefined;
334}
335function getParserLangFromSFC(doc) {
336 if (doc) {
337 const scripts = doc.children.filter(isScriptElement);
338 const script = (scripts.length === 2 && scripts.find(isScriptSetupElement)) ||
339 scripts[0];
340 if (script) {
341 return getLang(script);
342 }
343 }
344 return null;
345}
346
347const createRequire = Module__default["default"].createRequire ||
348 Module__default["default"].createRequireFromPath ||
349 ((modname) => {
350 const mod = new Module__default["default"](modname);
351 mod.filename = modname;
352 mod.paths = Module__default["default"]._nodeModulePaths(path__default["default"].dirname(modname));
353 mod._compile("module.exports = require;", modname);
354 return mod.exports;
355 });
356
357function isLinterPath(p) {
358 return (p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter${path__default["default"].sep}linter.js`) ||
359 p.includes(`eslint${path__default["default"].sep}lib${path__default["default"].sep}linter.js`));
360}
361function getLinterRequire() {
362 const linterPath = Object.keys(require.cache).find(isLinterPath);
363 if (linterPath) {
364 try {
365 return createRequire(linterPath);
366 }
367 catch (_a) {
368 }
369 }
370 return null;
371}
372
373let escopeCache = null;
374function getEslintScope() {
375 var _a;
376 if (!escopeCache) {
377 escopeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("eslint-scope");
378 if (!escopeCache ||
379 escopeCache.version == null ||
380 semver.lte(escopeCache.version, escope__namespace.version)) {
381 escopeCache = escope__namespace;
382 }
383 }
384 return escopeCache;
385}
386
387let espreeCache = null;
388function getEspreeFromEcmaVersion(ecmaVersion) {
389 const linterEspree = getEspreeFromLinter();
390 if (ecmaVersion == null) {
391 return linterEspree;
392 }
393 if (ecmaVersion === "latest") {
394 return getNewestEspree();
395 }
396 if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(linterEspree)) {
397 return linterEspree;
398 }
399 const userEspree = getEspreeFromUser();
400 if (normalizeEcmaVersion(ecmaVersion) <= getLatestEcmaVersion(userEspree)) {
401 return userEspree;
402 }
403 return linterEspree;
404}
405function getEspreeFromUser() {
406 try {
407 const cwd = process.cwd();
408 const relativeTo = path__default["default"].join(cwd, "__placeholder__.js");
409 return createRequire(relativeTo)("espree");
410 }
411 catch (_a) {
412 return getEspreeFromLinter();
413 }
414}
415function getEspreeFromLinter() {
416 var _a;
417 if (!espreeCache) {
418 espreeCache = (_a = getLinterRequire()) === null || _a === void 0 ? void 0 : _a("espree");
419 if (!espreeCache) {
420 espreeCache = dependencyEspree__namespace;
421 }
422 }
423 return espreeCache;
424}
425function getNewestEspree() {
426 let newest = dependencyEspree__namespace;
427 const linterEspree = getEspreeFromLinter();
428 if (linterEspree.version != null &&
429 semver.lte(newest.version, linterEspree.version)) {
430 newest = linterEspree;
431 }
432 const userEspree = getEspreeFromUser();
433 if (userEspree.version != null && semver.lte(newest.version, userEspree.version)) {
434 newest = userEspree;
435 }
436 return newest;
437}
438function getEcmaVersionIfUseEspree(parserOptions, getDefault) {
439 var _a;
440 if (parserOptions.parser != null && parserOptions.parser !== "espree") {
441 return undefined;
442 }
443 if (parserOptions.ecmaVersion === "latest") {
444 return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
445 }
446 if (parserOptions.ecmaVersion == null) {
447 const defVer = getDefaultEcmaVersion$1();
448 return (_a = getDefault === null || getDefault === void 0 ? void 0 : getDefault(defVer)) !== null && _a !== void 0 ? _a : defVer;
449 }
450 return normalizeEcmaVersion(parserOptions.ecmaVersion);
451}
452function getDefaultEcmaVersion$1() {
453 if (semver.lt(getEspreeFromLinter().version, "9.0.0")) {
454 return 5;
455 }
456 return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()));
457}
458function normalizeEcmaVersion(version) {
459 if (version > 5 && version < 2015) {
460 return version + 2009;
461 }
462 return version;
463}
464function getLatestEcmaVersion(espree) {
465 if (espree.latestEcmaVersion == null) {
466 for (const { v, latest } of [
467 { v: "6.1.0", latest: 2020 },
468 { v: "4.0.0", latest: 2019 },
469 ]) {
470 if (semver.lte(v, espree.version)) {
471 return latest;
472 }
473 }
474 return 2018;
475 }
476 return normalizeEcmaVersion(espree.latestEcmaVersion);
477}
478
479function isUnique(reference, index, references) {
480 return (index === 0 || reference.identifier !== references[index - 1].identifier);
481}
482function hasDefinition(variable) {
483 return variable.defs.length >= 1;
484}
485function transformReference(reference) {
486 const ret = {
487 id: reference.identifier,
488 mode: reference.isReadOnly()
489 ? "r"
490 : reference.isWriteOnly()
491 ? "w"
492 : "rw",
493 variable: null,
494 isValueReference: reference.isValueReference,
495 isTypeReference: reference.isTypeReference,
496 };
497 Object.defineProperty(ret, "variable", { enumerable: false });
498 return ret;
499}
500function transformVariable(variable, kind) {
501 const ret = {
502 id: variable.defs[0].name,
503 kind,
504 references: [],
505 };
506 Object.defineProperty(ret, "references", { enumerable: false });
507 return ret;
508}
509function getForScope(scope) {
510 const child = scope.childScopes[0];
511 return child.block === scope.block ? child.childScopes[0] : child;
512}
513function analyzeScope(ast, parserOptions) {
514 const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
515 const ecmaFeatures = parserOptions.ecmaFeatures || {};
516 const sourceType = parserOptions.sourceType || "script";
517 const result = getEslintScope().analyze(ast, {
518 ignoreEval: true,
519 nodejsScope: false,
520 impliedStrict: ecmaFeatures.impliedStrict,
521 ecmaVersion,
522 sourceType,
523 fallback: getFallbackKeys,
524 });
525 return result;
526}
527function analyze(parserResult, parserOptions) {
528 const scopeManager = parserResult.scopeManager ||
529 analyzeScope(parserResult.ast, parserOptions);
530 return scopeManager.globalScope;
531}
532function analyzeExternalReferences(parserResult, parserOptions) {
533 const scope = analyze(parserResult, parserOptions);
534 return scope.through.filter(isUnique).map(transformReference);
535}
536function analyzeVariablesAndExternalReferences(parserResult, kind, parserOptions) {
537 const scope = analyze(parserResult, parserOptions);
538 return {
539 variables: getForScope(scope)
540 .variables.filter(hasDefinition)
541 .map((v) => transformVariable(v, kind)),
542 references: scope.through.filter(isUnique).map(transformReference),
543 };
544}
545
546function fixLocations(result, locationCalculator) {
547 fixNodeLocations(result.ast, result.visitorKeys, locationCalculator);
548 for (const token of result.ast.tokens || []) {
549 fixLocation(token, locationCalculator);
550 }
551 for (const comment of result.ast.comments || []) {
552 fixLocation(comment, locationCalculator);
553 }
554}
555function fixNodeLocations(rootNode, visitorKeys, locationCalculator) {
556 const traversed = new Map();
557 traverseNodes(rootNode, {
558 visitorKeys,
559 enterNode(node, parent) {
560 if (!traversed.has(node)) {
561 traversed.set(node, node);
562 node.parent = parent;
563 if (traversed.has(node.range)) {
564 if (!traversed.has(node.loc)) {
565 node.loc.start = locationCalculator.getLocFromIndex(node.range[0]);
566 node.loc.end = locationCalculator.getLocFromIndex(node.range[1]);
567 traversed.set(node.loc, node);
568 }
569 else if (node.start != null || node.end != null) {
570 const traversedNode = traversed.get(node.range);
571 if (traversedNode.type === node.type) {
572 node.start = traversedNode.start;
573 node.end = traversedNode.end;
574 }
575 }
576 }
577 else {
578 fixLocation(node, locationCalculator);
579 traversed.set(node.range, node);
580 traversed.set(node.loc, node);
581 }
582 }
583 },
584 leaveNode() {
585 },
586 });
587}
588function fixLocation(node, locationCalculator) {
589 const range = node.range;
590 const loc = node.loc;
591 const d0 = locationCalculator.getFixOffset(range[0], "start");
592 const d1 = locationCalculator.getFixOffset(range[1], "end");
593 if (d0 !== 0) {
594 range[0] += d0;
595 if (node.start != null) {
596 node.start += d0;
597 }
598 loc.start = locationCalculator.getLocFromIndex(range[0]);
599 }
600 if (d1 !== 0) {
601 range[1] += d1;
602 if (node.end != null) {
603 node.end += d0;
604 }
605 loc.end = locationCalculator.getLocFromIndex(range[1]);
606 }
607 return node;
608}
609function fixErrorLocation(error, locationCalculator) {
610 const diff = locationCalculator.getFixOffset(error.index, "start");
611 error.index += diff;
612 const loc = locationCalculator.getLocFromIndex(error.index);
613 error.lineNumber = loc.line;
614 error.column = loc.column;
615}
616
617const DEFAULT_ECMA_VERSION = 2017;
618function getScriptSetupParserOptions(parserOptions) {
619 const espreeEcmaVersion = getEcmaVersionIfUseEspree(parserOptions, getDefaultEcmaVersion);
620 return Object.assign(Object.assign({}, parserOptions), { ecmaVersion: espreeEcmaVersion });
621}
622function getDefaultEcmaVersion(def) {
623 if (semver.lte("8.0.0", getEspreeFromUser().version)) {
624 return getEspreeFromUser().latestEcmaVersion;
625 }
626 return Math.max(def, DEFAULT_ECMA_VERSION);
627}
628
629function extractGeneric(element) {
630 const genericAttr = findGenericDirective(element);
631 if (!genericAttr) {
632 return null;
633 }
634 const genericNode = genericAttr.value.expression;
635 const defineTypes = genericNode.params.map((t, i) => ({
636 node: t,
637 define: `type ${t.name.name} = ${getConstraint(t, genericNode.rawParams[i])}`,
638 }));
639 return {
640 node: genericNode,
641 defineTypes,
642 postprocess({ result, getTypeBlock, isRemoveTarget, getTypeDefScope }) {
643 var _a;
644 const node = (_a = getTypeBlock === null || getTypeBlock === void 0 ? void 0 : getTypeBlock(result.ast)) !== null && _a !== void 0 ? _a : result.ast;
645 removeTypeDeclarations(node, isRemoveTarget);
646 if (result.ast.tokens) {
647 removeTypeDeclarationTokens(result.ast.tokens, isRemoveTarget);
648 }
649 if (result.ast.comments) {
650 removeTypeDeclarationTokens(result.ast.comments, isRemoveTarget);
651 }
652 if (result.scopeManager) {
653 const typeDefScope = getTypeDefScope(result.scopeManager);
654 restoreScope(result.scopeManager, typeDefScope, isRemoveTarget);
655 }
656 },
657 };
658 function removeTypeDeclarations(node, isRemoveTarget) {
659 for (let index = node.body.length - 1; index >= 0; index--) {
660 if (isRemoveTarget(node.body[index])) {
661 node.body.splice(index, 1);
662 }
663 }
664 }
665 function removeTypeDeclarationTokens(tokens, isRemoveTarget) {
666 for (let index = tokens.length - 1; index >= 0; index--) {
667 if (isRemoveTarget(tokens[index])) {
668 tokens.splice(index, 1);
669 }
670 }
671 }
672 function restoreScope(scopeManager, typeDefScope, isRemoveTarget) {
673 for (const variable of [...typeDefScope.variables]) {
674 let def = variable.defs.find((d) => isRemoveTarget(d.name));
675 while (def) {
676 removeVariableDef(variable, def, typeDefScope);
677 def = variable.defs.find((d) => isRemoveTarget(d.name));
678 }
679 }
680 for (const reference of [...typeDefScope.references]) {
681 if (isRemoveTarget(reference.identifier)) {
682 removeReference(reference, typeDefScope);
683 }
684 }
685 for (const scope of [...scopeManager.scopes]) {
686 if (isRemoveTarget(scope.block)) {
687 removeScope(scopeManager, scope);
688 }
689 }
690 }
691}
692function getConstraint(node, rawParam) {
693 if (!node.constraint) {
694 return "unknown";
695 }
696 let index = rawParam.indexOf(node.name.name) + node.name.name.length;
697 let startIndex = null;
698 while (index < rawParam.length) {
699 if (startIndex == null) {
700 if (rawParam.startsWith("extends", index)) {
701 startIndex = index = index + 7;
702 continue;
703 }
704 }
705 else if (rawParam[index] === "=") {
706 if (rawParam[index + 1] === ">") {
707 index += 2;
708 continue;
709 }
710 return rawParam.slice(startIndex, index);
711 }
712 if (rawParam.startsWith("//", index)) {
713 const lfIndex = rawParam.indexOf("\n", index);
714 if (lfIndex >= 0) {
715 index = lfIndex + 1;
716 continue;
717 }
718 return "unknown";
719 }
720 if (rawParam.startsWith("/*", index)) {
721 const endIndex = rawParam.indexOf("*/", index);
722 if (endIndex >= 0) {
723 index = endIndex + 2;
724 continue;
725 }
726 return "unknown";
727 }
728 index++;
729 }
730 if (startIndex == null) {
731 return "unknown";
732 }
733 return rawParam.slice(startIndex);
734}
735function removeVariableDef(variable, def, scope) {
736 const defIndex = variable.defs.indexOf(def);
737 if (defIndex < 0) {
738 return;
739 }
740 variable.defs.splice(defIndex, 1);
741 if (variable.defs.length === 0) {
742 referencesToThrough(variable.references, scope);
743 variable.references.forEach((r) => {
744 if (r.init) {
745 r.init = false;
746 }
747 r.resolved = null;
748 });
749 scope.variables.splice(scope.variables.indexOf(variable), 1);
750 const name = variable.name;
751 if (variable === scope.set.get(name)) {
752 scope.set.delete(name);
753 }
754 }
755 else {
756 const idIndex = variable.identifiers.indexOf(def.name);
757 if (idIndex >= 0) {
758 variable.identifiers.splice(idIndex, 1);
759 }
760 }
761}
762function referencesToThrough(references, baseScope) {
763 let scope = baseScope;
764 while (scope) {
765 addAllReferences(scope.through, references);
766 scope = scope.upper;
767 }
768}
769function addAllReferences(list, elements) {
770 list.push(...elements);
771 list.sort((a, b) => a.identifier.range[0] - b.identifier.range[0]);
772}
773function removeReference(reference, baseScope) {
774 if (reference.resolved) {
775 if (reference.resolved.defs.some((d) => d.name === reference.identifier)) {
776 const varIndex = baseScope.variables.indexOf(reference.resolved);
777 if (varIndex >= 0) {
778 baseScope.variables.splice(varIndex, 1);
779 }
780 const name = reference.identifier.name;
781 if (reference.resolved === baseScope.set.get(name)) {
782 baseScope.set.delete(name);
783 }
784 }
785 else {
786 const refIndex = reference.resolved.references.indexOf(reference);
787 if (refIndex >= 0) {
788 reference.resolved.references.splice(refIndex, 1);
789 }
790 }
791 }
792 let scope = baseScope;
793 while (scope) {
794 const refIndex = scope.references.indexOf(reference);
795 if (refIndex >= 0) {
796 scope.references.splice(refIndex, 1);
797 }
798 const throughIndex = scope.through.indexOf(reference);
799 if (throughIndex >= 0) {
800 scope.through.splice(throughIndex, 1);
801 }
802 scope = scope.upper;
803 }
804}
805function removeScope(scopeManager, scope) {
806 for (const childScope of scope.childScopes) {
807 removeScope(scopeManager, childScope);
808 }
809 while (scope.references[0]) {
810 removeReference(scope.references[0], scope);
811 }
812 const upper = scope.upper;
813 if (upper) {
814 const index = upper.childScopes.indexOf(scope);
815 if (index >= 0) {
816 upper.childScopes.splice(index, 1);
817 }
818 }
819 const index = scopeManager.scopes.indexOf(scope);
820 if (index >= 0) {
821 scopeManager.scopes.splice(index, 1);
822 }
823}
824
825const ALIAS_ITERATOR = /^([\s\S]*?(?:\s|\)))(\bin\b|\bof\b)([\s\S]*)$/u;
826const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u;
827const DUMMY_PARENT$2 = {};
828const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u;
829const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u;
830function processVForAliasAndIterator(code) {
831 const match = ALIAS_ITERATOR.exec(code);
832 if (match != null) {
833 const aliases = match[1];
834 const parenMatch = PARENS.exec(aliases);
835 return {
836 aliases,
837 hasParens: Boolean(parenMatch),
838 aliasesWithBrackets: parenMatch
839 ? `${parenMatch[1].slice(0, -1)}[${parenMatch[2]}]${parenMatch[3].slice(1)}`
840 : `[${aliases.slice(0, -1)}]`,
841 delimiter: match[2] || "",
842 iterator: match[3],
843 };
844 }
845 return {
846 aliases: "",
847 hasParens: false,
848 aliasesWithBrackets: "",
849 delimiter: "",
850 iterator: code,
851 };
852}
853function getCommaTokenBeforeNode(tokens, node) {
854 let tokenIndex = sortedIndexBy__default["default"](tokens, { range: node.range }, (t) => t.range[0]);
855 while (tokenIndex >= 0) {
856 const token = tokens[tokenIndex];
857 if (token.type === "Punctuator" && token.value === ",") {
858 return token;
859 }
860 tokenIndex -= 1;
861 }
862 return null;
863}
864function throwEmptyError(locationCalculator, expected) {
865 const loc = locationCalculator.getLocation(0);
866 const err = new ParseError(`Expected to be ${expected}, but got empty.`, undefined, 0, loc.line, loc.column);
867 fixErrorLocation(err, locationCalculator);
868 throw err;
869}
870function throwUnexpectedTokenError(name, token) {
871 const err = new ParseError(`Unexpected token '${name}'.`, undefined, token.range[0], token.loc.start.line, token.loc.start.column);
872 throw err;
873}
874function throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator) {
875 if (ParseError.isParseError(err)) {
876 const endOffset = locationCalculator.getOffsetWithGap(code.length);
877 if (err.index >= endOffset) {
878 err.message = "Unexpected end of expression.";
879 }
880 }
881 throw err;
882}
883function parseScriptFragment(code, locationCalculator, parserOptions) {
884 return parseScriptFragmentWithOption(code, locationCalculator, parserOptions);
885}
886function parseScriptFragmentWithOption(code, locationCalculator, parserOptions, processOptions) {
887 var _a;
888 try {
889 const result = parseScript$1(code, parserOptions);
890 (_a = processOptions === null || processOptions === void 0 ? void 0 : processOptions.preFixLocationProcess) === null || _a === void 0 ? void 0 : _a.call(processOptions, result);
891 fixLocations(result, locationCalculator);
892 return result;
893 }
894 catch (err) {
895 const perr = ParseError.normalize(err);
896 if (perr) {
897 fixErrorLocation(perr, locationCalculator);
898 throw perr;
899 }
900 throw err;
901 }
902}
903const validDivisionCharRE = /[\w).+\-_$\]]/u;
904function splitFilters(exp) {
905 const result = [];
906 let inSingle = false;
907 let inDouble = false;
908 let inTemplateString = false;
909 let inRegex = false;
910 let curly = 0;
911 let square = 0;
912 let paren = 0;
913 let lastFilterIndex = 0;
914 let c = 0;
915 let prev = 0;
916 for (let i = 0; i < exp.length; i++) {
917 prev = c;
918 c = exp.charCodeAt(i);
919 if (inSingle) {
920 if (c === 0x27 && prev !== 0x5c) {
921 inSingle = false;
922 }
923 }
924 else if (inDouble) {
925 if (c === 0x22 && prev !== 0x5c) {
926 inDouble = false;
927 }
928 }
929 else if (inTemplateString) {
930 if (c === 0x60 && prev !== 0x5c) {
931 inTemplateString = false;
932 }
933 }
934 else if (inRegex) {
935 if (c === 0x2f && prev !== 0x5c) {
936 inRegex = false;
937 }
938 }
939 else if (c === 0x7c &&
940 exp.charCodeAt(i + 1) !== 0x7c &&
941 exp.charCodeAt(i - 1) !== 0x7c &&
942 !curly &&
943 !square &&
944 !paren) {
945 result.push(exp.slice(lastFilterIndex, i));
946 lastFilterIndex = i + 1;
947 }
948 else {
949 switch (c) {
950 case 0x22:
951 inDouble = true;
952 break;
953 case 0x27:
954 inSingle = true;
955 break;
956 case 0x60:
957 inTemplateString = true;
958 break;
959 case 0x28:
960 paren++;
961 break;
962 case 0x29:
963 paren--;
964 break;
965 case 0x5b:
966 square++;
967 break;
968 case 0x5d:
969 square--;
970 break;
971 case 0x7b:
972 curly++;
973 break;
974 case 0x7d:
975 curly--;
976 break;
977 }
978 if (c === 0x2f) {
979 let j = i - 1;
980 let p;
981 for (; j >= 0; j--) {
982 p = exp.charAt(j);
983 if (p !== " ") {
984 break;
985 }
986 }
987 if (!p || !validDivisionCharRE.test(p)) {
988 inRegex = true;
989 }
990 }
991 }
992 }
993 result.push(exp.slice(lastFilterIndex));
994 return result;
995}
996function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) {
997 debug('[script] parse expression: "0(%s)"', code);
998 try {
999 const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
1000 const { ast } = result;
1001 const tokens = ast.tokens || [];
1002 const comments = ast.comments || [];
1003 const references = analyzeExternalReferences(result, parserOptions);
1004 const statement = ast.body[0];
1005 const callExpression = statement.expression;
1006 const expression = callExpression.arguments[0];
1007 if (!allowEmpty && !expression) {
1008 return throwEmptyError(locationCalculator, "an expression");
1009 }
1010 if (expression && expression.type === "SpreadElement") {
1011 return throwUnexpectedTokenError("...", expression);
1012 }
1013 if (callExpression.arguments[1]) {
1014 const node = callExpression.arguments[1];
1015 return throwUnexpectedTokenError(",", getCommaTokenBeforeNode(tokens, node) || node);
1016 }
1017 tokens.shift();
1018 tokens.shift();
1019 tokens.pop();
1020 return { expression, tokens, comments, references, variables: [] };
1021 }
1022 catch (err) {
1023 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1024 }
1025}
1026function parseFilter(code, locationCalculator, parserOptions) {
1027 debug('[script] parse filter: "%s"', code);
1028 try {
1029 const expression = {
1030 type: "VFilter",
1031 parent: null,
1032 range: [0, 0],
1033 loc: {},
1034 callee: null,
1035 arguments: [],
1036 };
1037 const tokens = [];
1038 const comments = [];
1039 const references = [];
1040 const paren = code.indexOf("(");
1041 const calleeCode = paren === -1 ? code : code.slice(0, paren);
1042 const argsCode = paren === -1 ? null : code.slice(paren);
1043 if (calleeCode.trim()) {
1044 const spaces = /^\s*/u.exec(calleeCode)[0];
1045 const subCalculator = locationCalculator.getSubCalculatorShift(spaces.length);
1046 const { ast } = parseScriptFragment(`"${calleeCode.trim()}"`, subCalculator, parserOptions);
1047 const statement = ast.body[0];
1048 const callee = statement.expression;
1049 if (callee.type !== "Literal") {
1050 const { loc, range } = ast.tokens[0];
1051 return throwUnexpectedTokenError('"', {
1052 range: [range[1] - 1, range[1]],
1053 loc: {
1054 start: {
1055 line: loc.end.line,
1056 column: loc.end.column - 1,
1057 },
1058 end: loc.end,
1059 },
1060 });
1061 }
1062 expression.callee = {
1063 type: "Identifier",
1064 parent: expression,
1065 range: [
1066 callee.range[0],
1067 subCalculator.getOffsetWithGap(calleeCode.trim().length),
1068 ],
1069 loc: {
1070 start: callee.loc.start,
1071 end: subCalculator.getLocation(calleeCode.trim().length),
1072 },
1073 name: String(callee.value),
1074 };
1075 tokens.push({
1076 type: "Identifier",
1077 value: calleeCode.trim(),
1078 range: expression.callee.range,
1079 loc: expression.callee.loc,
1080 });
1081 }
1082 else {
1083 return throwEmptyError(locationCalculator, "a filter name");
1084 }
1085 if (argsCode != null) {
1086 const result = parseScriptFragment(`0${argsCode}`, locationCalculator
1087 .getSubCalculatorAfter(paren)
1088 .getSubCalculatorShift(-1), parserOptions);
1089 const { ast } = result;
1090 const statement = ast.body[0];
1091 const callExpression = statement.expression;
1092 ast.tokens.shift();
1093 if (callExpression.type !== "CallExpression" ||
1094 callExpression.callee.type !== "Literal") {
1095 let nestCount = 1;
1096 for (const token of ast.tokens.slice(1)) {
1097 if (nestCount === 0) {
1098 return throwUnexpectedTokenError(token.value, token);
1099 }
1100 if (token.type === "Punctuator" && token.value === "(") {
1101 nestCount += 1;
1102 }
1103 if (token.type === "Punctuator" && token.value === ")") {
1104 nestCount -= 1;
1105 }
1106 }
1107 const token = last__default["default"](ast.tokens);
1108 return throwUnexpectedTokenError(token.value, token);
1109 }
1110 for (const argument of callExpression.arguments) {
1111 argument.parent = expression;
1112 expression.arguments.push(argument);
1113 }
1114 tokens.push(...ast.tokens);
1115 comments.push(...ast.comments);
1116 references.push(...analyzeExternalReferences(result, parserOptions));
1117 }
1118 const firstToken = tokens[0];
1119 const lastToken = last__default["default"](tokens);
1120 expression.range = [firstToken.range[0], lastToken.range[1]];
1121 expression.loc = { start: firstToken.loc.start, end: lastToken.loc.end };
1122 return { expression, tokens, comments, references, variables: [] };
1123 }
1124 catch (err) {
1125 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1126 }
1127}
1128function loadParser(parser) {
1129 if (parser !== "espree") {
1130 return require(parser);
1131 }
1132 return getEspreeFromUser();
1133}
1134function parseScript$1(code, parserOptions) {
1135 const parser = typeof parserOptions.parser === "string"
1136 ? loadParser(parserOptions.parser)
1137 : isParserObject(parserOptions.parser)
1138 ? parserOptions.parser
1139 : getEspreeFromEcmaVersion(parserOptions.ecmaVersion);
1140 const result = isEnhancedParserObject(parser)
1141 ? parser.parseForESLint(code, parserOptions)
1142 : parser.parse(code, parserOptions);
1143 if (result.ast != null) {
1144 return result;
1145 }
1146 return { ast: result };
1147}
1148function parseScriptElement(node, sfcCode, linesAndColumns, originalParserOptions) {
1149 var _a, _b;
1150 const parserOptions = isScriptSetupElement(node)
1151 ? getScriptSetupParserOptions(originalParserOptions)
1152 : Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
1153 let generic = null;
1154 let code;
1155 let offset;
1156 const textNode = node.children[0];
1157 if (textNode != null && textNode.type === "VText") {
1158 const [scriptStartOffset, scriptEndOffset] = textNode.range;
1159 code = sfcCode.slice(scriptStartOffset, scriptEndOffset);
1160 offset = scriptStartOffset;
1161 generic = extractGeneric(node);
1162 if (generic) {
1163 const defineTypesCode = `${generic.defineTypes
1164 .map((e) => e.define)
1165 .join(";")};\n`;
1166 code = defineTypesCode + code;
1167 offset -= defineTypesCode.length;
1168 }
1169 }
1170 else {
1171 code = "";
1172 offset = node.startTag.range[1];
1173 }
1174 const locationCalculator = linesAndColumns.createOffsetLocationCalculator(offset);
1175 const result = parseScriptFragment(code, locationCalculator, parserOptions);
1176 if (generic) {
1177 generic.postprocess({
1178 result,
1179 isRemoveTarget(nodeOrToken) {
1180 return nodeOrToken.range[1] <= textNode.range[0];
1181 },
1182 getTypeDefScope(scopeManager) {
1183 var _a;
1184 return ((_a = scopeManager.globalScope.childScopes.find((s) => s.type === "module")) !== null && _a !== void 0 ? _a : scopeManager.globalScope);
1185 },
1186 });
1187 const startToken = [
1188 result.ast.body[0],
1189 (_a = result.ast.tokens) === null || _a === void 0 ? void 0 : _a[0],
1190 (_b = result.ast.comments) === null || _b === void 0 ? void 0 : _b[0],
1191 ]
1192 .filter((e) => Boolean(e))
1193 .sort((a, b) => a.range[0] - b.range[0])
1194 .find((t) => Boolean(t));
1195 if (startToken && result.ast.range[0] !== startToken.range[0]) {
1196 result.ast.range[0] = startToken.range[0];
1197 if (result.ast.start != null) {
1198 result.ast.start = startToken.start;
1199 }
1200 result.ast.loc.start = Object.assign({}, startToken.loc.start);
1201 }
1202 }
1203 if (result.ast.tokens != null) {
1204 const startTag = node.startTag;
1205 const endTag = node.endTag;
1206 result.ast.tokens.unshift({
1207 type: "Punctuator",
1208 range: startTag.range,
1209 loc: startTag.loc,
1210 value: "<script>",
1211 });
1212 if (endTag != null) {
1213 result.ast.tokens.push({
1214 type: "Punctuator",
1215 range: endTag.range,
1216 loc: endTag.loc,
1217 value: "</script>",
1218 });
1219 }
1220 }
1221 return result;
1222}
1223function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = false, allowFilters = false } = {}) {
1224 var _a, _b;
1225 debug('[script] parse expression: "%s"', code);
1226 const [mainCode, ...filterCodes] = allowFilters && ((_b = (_a = parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.filter) !== null && _b !== void 0 ? _b : true)
1227 ? splitFilters(code)
1228 : [code];
1229 if (filterCodes.length === 0) {
1230 return parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty);
1231 }
1232 const retB = parseExpressionBody(mainCode, locationCalculator, parserOptions);
1233 if (!retB.expression) {
1234 return retB;
1235 }
1236 const ret = retB;
1237 ret.expression = {
1238 type: "VFilterSequenceExpression",
1239 parent: null,
1240 expression: retB.expression,
1241 filters: [],
1242 range: retB.expression.range.slice(0),
1243 loc: Object.assign({}, retB.expression.loc),
1244 };
1245 ret.expression.expression.parent = ret.expression;
1246 let prevLoc = mainCode.length;
1247 for (const filterCode of filterCodes) {
1248 ret.tokens.push(fixLocation({
1249 type: "Punctuator",
1250 value: "|",
1251 range: [prevLoc, prevLoc + 1],
1252 loc: {},
1253 }, locationCalculator));
1254 const retF = parseFilter(filterCode, locationCalculator.getSubCalculatorShift(prevLoc + 1), parserOptions);
1255 if (retF) {
1256 if (retF.expression) {
1257 ret.expression.filters.push(retF.expression);
1258 retF.expression.parent = ret.expression;
1259 }
1260 ret.tokens.push(...retF.tokens);
1261 ret.comments.push(...retF.comments);
1262 ret.references.push(...retF.references);
1263 }
1264 prevLoc += 1 + filterCode.length;
1265 }
1266 const lastToken = last__default["default"](ret.tokens);
1267 ret.expression.range[1] = lastToken.range[1];
1268 ret.expression.loc.end = lastToken.loc.end;
1269 return ret;
1270}
1271function parseVForExpression(code, locationCalculator, parserOptions) {
1272 if (code.trim() === "") {
1273 throwEmptyError(locationCalculator, "'<alias> in <expression>'");
1274 }
1275 if (isEcmaVersion5(parserOptions)) {
1276 return parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions);
1277 }
1278 const processed = processVForAliasAndIterator(code);
1279 if (!processed.aliases.trim()) {
1280 return throwEmptyError(locationCalculator, "an alias");
1281 }
1282 try {
1283 debug('[script] parse v-for expression: "for(%s%s%s);"', processed.aliasesWithBrackets, processed.delimiter, processed.iterator);
1284 const result = parseScriptFragment(`for(let ${processed.aliasesWithBrackets}${processed.delimiter}${processed.iterator});`, locationCalculator.getSubCalculatorShift(processed.hasParens ? -8 : -9), parserOptions);
1285 const { ast } = result;
1286 const tokens = ast.tokens || [];
1287 const comments = ast.comments || [];
1288 const scope = analyzeVariablesAndExternalReferences(result, "v-for", parserOptions);
1289 const references = scope.references;
1290 const variables = scope.variables;
1291 const statement = ast.body[0];
1292 const varDecl = statement.left;
1293 const id = varDecl.declarations[0].id;
1294 const left = id.elements;
1295 const right = statement.right;
1296 if (!processed.hasParens && !left.length) {
1297 return throwEmptyError(locationCalculator, "an alias");
1298 }
1299 tokens.shift();
1300 tokens.shift();
1301 tokens.shift();
1302 tokens.pop();
1303 tokens.pop();
1304 const closeOffset = statement.left.range[1] - 1;
1305 const closeIndex = tokens.findIndex((t) => t.range[0] === closeOffset);
1306 if (processed.hasParens) {
1307 const open = tokens[0];
1308 if (open != null) {
1309 open.value = "(";
1310 }
1311 const close = tokens[closeIndex];
1312 if (close != null) {
1313 close.value = ")";
1314 }
1315 }
1316 else {
1317 tokens.splice(closeIndex, 1);
1318 tokens.shift();
1319 }
1320 const firstToken = tokens[0] || statement.left;
1321 const lastToken = tokens[tokens.length - 1] || statement.right;
1322 const expression = {
1323 type: "VForExpression",
1324 range: [firstToken.range[0], lastToken.range[1]],
1325 loc: { start: firstToken.loc.start, end: lastToken.loc.end },
1326 parent: DUMMY_PARENT$2,
1327 left,
1328 right,
1329 };
1330 for (const l of left) {
1331 if (l != null) {
1332 l.parent = expression;
1333 }
1334 }
1335 right.parent = expression;
1336 return { expression, tokens, comments, references, variables };
1337 }
1338 catch (err) {
1339 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1340 }
1341}
1342function isEcmaVersion5(parserOptions) {
1343 const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions);
1344 return ecmaVersion != null && ecmaVersion <= 5;
1345}
1346function parseVForExpressionForEcmaVersion5(code, locationCalculator, parserOptions) {
1347 const processed = processVForAliasAndIterator(code);
1348 if (!processed.aliases.trim()) {
1349 return throwEmptyError(locationCalculator, "an alias");
1350 }
1351 try {
1352 const tokens = [];
1353 const comments = [];
1354 const parsedAliases = parseVForAliasesForEcmaVersion5(processed.aliasesWithBrackets, locationCalculator.getSubCalculatorShift(processed.hasParens ? 0 : -1), parserOptions);
1355 if (processed.hasParens) {
1356 const open = parsedAliases.tokens[0];
1357 if (open != null) {
1358 open.value = "(";
1359 }
1360 const close = last__default["default"](parsedAliases.tokens);
1361 if (close != null) {
1362 close.value = ")";
1363 }
1364 }
1365 else {
1366 parsedAliases.tokens.shift();
1367 parsedAliases.tokens.pop();
1368 }
1369 tokens.push(...parsedAliases.tokens);
1370 comments.push(...parsedAliases.comments);
1371 const { left, variables } = parsedAliases;
1372 if (!processed.hasParens && !left.length) {
1373 return throwEmptyError(locationCalculator, "an alias");
1374 }
1375 const delimiterStart = processed.aliases.length;
1376 const delimiterEnd = delimiterStart + processed.delimiter.length;
1377 tokens.push(fixLocation({
1378 type: processed.delimiter === "in" ? "Keyword" : "Identifier",
1379 value: processed.delimiter,
1380 start: delimiterStart,
1381 end: delimiterEnd,
1382 loc: {},
1383 range: [delimiterStart, delimiterEnd],
1384 }, locationCalculator));
1385 const parsedIterator = parseVForIteratorForEcmaVersion5(processed.iterator, locationCalculator.getSubCalculatorShift(delimiterEnd), parserOptions);
1386 tokens.push(...parsedIterator.tokens);
1387 comments.push(...parsedIterator.comments);
1388 const { right, references } = parsedIterator;
1389 const firstToken = tokens[0];
1390 const lastToken = last__default["default"](tokens) || firstToken;
1391 const expression = {
1392 type: "VForExpression",
1393 range: [firstToken.range[0], lastToken.range[1]],
1394 loc: { start: firstToken.loc.start, end: lastToken.loc.end },
1395 parent: DUMMY_PARENT$2,
1396 left,
1397 right,
1398 };
1399 for (const l of left) {
1400 if (l != null) {
1401 l.parent = expression;
1402 }
1403 }
1404 right.parent = expression;
1405 return { expression, tokens, comments, references, variables };
1406 }
1407 catch (err) {
1408 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1409 }
1410}
1411function parseVForAliasesForEcmaVersion5(code, locationCalculator, parserOptions) {
1412 const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
1413 const { ast } = result;
1414 const tokens = ast.tokens || [];
1415 const comments = ast.comments || [];
1416 const variables = analyzeExternalReferences(result, parserOptions).map(transformVariable);
1417 const statement = ast.body[0];
1418 const callExpression = statement.expression;
1419 const expression = callExpression.arguments[0];
1420 const left = expression.elements.filter((e) => {
1421 if (e == null || e.type === "Identifier") {
1422 return true;
1423 }
1424 const errorToken = tokens.find((t) => e.range[0] <= t.range[0] && t.range[1] <= e.range[1]);
1425 return throwUnexpectedTokenError(errorToken.value, errorToken);
1426 });
1427 tokens.shift();
1428 tokens.shift();
1429 tokens.pop();
1430 return { left, tokens, comments, variables };
1431 function transformVariable(reference) {
1432 const ret = {
1433 id: reference.id,
1434 kind: "v-for",
1435 references: [],
1436 };
1437 Object.defineProperty(ret, "references", { enumerable: false });
1438 return ret;
1439 }
1440}
1441function parseVForIteratorForEcmaVersion5(code, locationCalculator, parserOptions) {
1442 const result = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions);
1443 const { ast } = result;
1444 const tokens = ast.tokens || [];
1445 const comments = ast.comments || [];
1446 const references = analyzeExternalReferences(result, parserOptions);
1447 const statement = ast.body[0];
1448 const callExpression = statement.expression;
1449 const expression = callExpression.arguments[0];
1450 if (!expression) {
1451 return throwEmptyError(locationCalculator, "an expression");
1452 }
1453 if (expression && expression.type === "SpreadElement") {
1454 return throwUnexpectedTokenError("...", expression);
1455 }
1456 const right = expression;
1457 tokens.shift();
1458 tokens.shift();
1459 tokens.pop();
1460 return { right, tokens, comments, references };
1461}
1462function parseVOnExpression(code, locationCalculator, parserOptions) {
1463 if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) {
1464 return parseExpressionBody(code, locationCalculator, parserOptions);
1465 }
1466 return parseVOnExpressionBody(code, locationCalculator, parserOptions);
1467}
1468function parseVOnExpressionBody(code, locationCalculator, parserOptions) {
1469 debug('[script] parse v-on expression: "void function($event){%s}"', code);
1470 if (code.trim() === "") {
1471 throwEmptyError(locationCalculator, "statements");
1472 }
1473 try {
1474 const result = parseScriptFragment(`void function($event){${code}}`, locationCalculator.getSubCalculatorShift(-22), parserOptions);
1475 const { ast } = result;
1476 const references = analyzeExternalReferences(result, parserOptions);
1477 const outermostStatement = ast.body[0];
1478 const functionDecl = outermostStatement.expression.argument;
1479 const block = functionDecl.body;
1480 const body = block.body;
1481 const firstStatement = first__default["default"](body);
1482 const lastStatement = last__default["default"](body);
1483 const expression = {
1484 type: "VOnExpression",
1485 range: [
1486 firstStatement != null
1487 ? firstStatement.range[0]
1488 : block.range[0] + 1,
1489 lastStatement != null
1490 ? lastStatement.range[1]
1491 : block.range[1] - 1,
1492 ],
1493 loc: {
1494 start: firstStatement != null
1495 ? firstStatement.loc.start
1496 : locationCalculator.getLocation(1),
1497 end: lastStatement != null
1498 ? lastStatement.loc.end
1499 : locationCalculator.getLocation(code.length + 1),
1500 },
1501 parent: DUMMY_PARENT$2,
1502 body,
1503 };
1504 const tokens = ast.tokens || [];
1505 const comments = ast.comments || [];
1506 for (const b of body) {
1507 b.parent = expression;
1508 }
1509 tokens.splice(0, 6);
1510 tokens.pop();
1511 return { expression, tokens, comments, references, variables: [] };
1512 }
1513 catch (err) {
1514 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1515 }
1516}
1517function parseSlotScopeExpression(code, locationCalculator, parserOptions) {
1518 debug('[script] parse slot-scope expression: "void function(%s) {}"', code);
1519 if (code.trim() === "") {
1520 throwEmptyError(locationCalculator, "an identifier or an array/object pattern");
1521 }
1522 try {
1523 const result = parseScriptFragment(`void function(${code}) {}`, locationCalculator.getSubCalculatorShift(-14), parserOptions);
1524 const { ast } = result;
1525 const statement = ast.body[0];
1526 const rawExpression = statement.expression;
1527 const functionDecl = rawExpression.argument;
1528 const params = functionDecl.params;
1529 if (params.length === 0) {
1530 return {
1531 expression: null,
1532 tokens: [],
1533 comments: [],
1534 references: [],
1535 variables: [],
1536 };
1537 }
1538 const tokens = ast.tokens || [];
1539 const comments = ast.comments || [];
1540 const scope = analyzeVariablesAndExternalReferences(result, "scope", parserOptions);
1541 const references = scope.references;
1542 const variables = scope.variables;
1543 const firstParam = first__default["default"](params);
1544 const lastParam = last__default["default"](params);
1545 const expression = {
1546 type: "VSlotScopeExpression",
1547 range: [firstParam.range[0], lastParam.range[1]],
1548 loc: { start: firstParam.loc.start, end: lastParam.loc.end },
1549 parent: DUMMY_PARENT$2,
1550 params: functionDecl.params,
1551 };
1552 for (const param of params) {
1553 param.parent = expression;
1554 }
1555 tokens.shift();
1556 tokens.shift();
1557 tokens.shift();
1558 tokens.pop();
1559 tokens.pop();
1560 tokens.pop();
1561 return { expression, tokens, comments, references, variables };
1562 }
1563 catch (err) {
1564 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1565 }
1566}
1567function parseGenericExpression(code, locationCalculator, parserOptions) {
1568 debug('[script] parse generic definition: "void function<%s>() {}"', code);
1569 if (code.trim() === "") {
1570 throwEmptyError(locationCalculator, "a type parameter");
1571 }
1572 function getParams(result) {
1573 const { ast } = result;
1574 const statement = ast.body[0];
1575 const rawExpression = statement.expression;
1576 const classDecl = rawExpression.argument;
1577 const typeParameters = classDecl
1578 .typeParameters;
1579 return typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.params;
1580 }
1581 try {
1582 const rawParams = [];
1583 const scriptLet = `void function<${code}>(){}`;
1584 const result = parseScriptFragmentWithOption(scriptLet, locationCalculator.getSubCalculatorShift(-14), Object.assign(Object.assign({}, parserOptions), { project: undefined }), {
1585 preFixLocationProcess(preResult) {
1586 const params = getParams(preResult);
1587 if (params) {
1588 for (const param of params) {
1589 rawParams.push(scriptLet.slice(param.range[0], param.range[1]));
1590 }
1591 }
1592 },
1593 });
1594 const { ast } = result;
1595 const params = getParams(result);
1596 if (!params || params.length === 0) {
1597 return {
1598 expression: null,
1599 tokens: [],
1600 comments: [],
1601 references: [],
1602 variables: [],
1603 };
1604 }
1605 const tokens = ast.tokens || [];
1606 const comments = ast.comments || [];
1607 const scope = analyzeVariablesAndExternalReferences(result, "generic", parserOptions);
1608 const references = scope.references;
1609 const variables = scope.variables;
1610 const firstParam = first__default["default"](params);
1611 const lastParam = last__default["default"](params);
1612 const expression = {
1613 type: "VGenericExpression",
1614 range: [firstParam.range[0], lastParam.range[1]],
1615 loc: { start: firstParam.loc.start, end: lastParam.loc.end },
1616 parent: DUMMY_PARENT$2,
1617 params,
1618 rawParams,
1619 };
1620 for (const param of params) {
1621 ;
1622 param.parent = expression;
1623 }
1624 tokens.shift();
1625 tokens.shift();
1626 tokens.shift();
1627 tokens.pop();
1628 tokens.pop();
1629 tokens.pop();
1630 tokens.pop();
1631 tokens.pop();
1632 return { expression, tokens, comments, references, variables };
1633 }
1634 catch (err) {
1635 return throwErrorAsAdjustingOutsideOfCode(err, code, locationCalculator);
1636 }
1637}
1638
1639function replaceTokens(document, node, newTokens) {
1640 if (document == null) {
1641 return;
1642 }
1643 const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
1644 const count = sortedLastIndexBy__default["default"](document.tokens, node, byRange1) - index;
1645 document.tokens.splice(index, count, ...newTokens);
1646}
1647function replaceAndSplitTokens(document, node, newTokens) {
1648 if (document == null) {
1649 return;
1650 }
1651 const index = sortedIndexBy__default["default"](document.tokens, node, byRange0);
1652 if (document.tokens.length === index ||
1653 node.range[0] < document.tokens[index].range[0]) {
1654 const beforeToken = document.tokens[index - 1];
1655 const value = beforeToken.value;
1656 const splitOffset = node.range[0] - beforeToken.range[0];
1657 const afterToken = {
1658 type: beforeToken.type,
1659 range: [node.range[0], beforeToken.range[1]],
1660 loc: {
1661 start: Object.assign({}, node.loc.start),
1662 end: Object.assign({}, beforeToken.loc.end),
1663 },
1664 value: value.slice(splitOffset),
1665 };
1666 beforeToken.range[1] = node.range[0];
1667 beforeToken.loc.end = Object.assign({}, node.loc.start);
1668 beforeToken.value = value.slice(0, splitOffset);
1669 document.tokens.splice(index, 0, afterToken);
1670 }
1671 let lastIndex = sortedLastIndexBy__default["default"](document.tokens, node, byRange1);
1672 if (lastIndex === 0 ||
1673 node.range[1] < document.tokens[lastIndex].range[1]) {
1674 const beforeToken = document.tokens[lastIndex];
1675 const value = beforeToken.value;
1676 const splitOffset = beforeToken.range[1] -
1677 beforeToken.range[0] -
1678 (beforeToken.range[1] - node.range[1]);
1679 const afterToken = {
1680 type: beforeToken.type,
1681 range: [node.range[1], beforeToken.range[1]],
1682 loc: {
1683 start: Object.assign({}, node.loc.end),
1684 end: Object.assign({}, beforeToken.loc.end),
1685 },
1686 value: value.slice(splitOffset),
1687 };
1688 beforeToken.range[1] = node.range[1];
1689 beforeToken.loc.end = Object.assign({}, node.loc.end);
1690 beforeToken.value = value.slice(0, splitOffset);
1691 document.tokens.splice(lastIndex + 1, 0, afterToken);
1692 lastIndex++;
1693 }
1694 const count = lastIndex - index;
1695 document.tokens.splice(index, count, ...newTokens);
1696}
1697function insertComments(document, newComments) {
1698 if (document == null || newComments.length === 0) {
1699 return;
1700 }
1701 const index = sortedIndexBy__default["default"](document.comments, newComments[0], byRange0);
1702 document.comments.splice(index, 0, ...newComments);
1703}
1704function createSimpleToken(type, start, end, value, linesAndColumns) {
1705 return {
1706 type,
1707 range: [start, end],
1708 loc: {
1709 start: linesAndColumns.getLocFromIndex(start),
1710 end: linesAndColumns.getLocFromIndex(end),
1711 },
1712 value,
1713 };
1714}
1715function byRange0(x) {
1716 return x.range[0];
1717}
1718function byRange1(x) {
1719 return x.range[1];
1720}
1721
1722function insertError(document, error) {
1723 if (document == null) {
1724 return;
1725 }
1726 const index = sortedIndexBy__default["default"](document.errors, error, byIndex);
1727 document.errors.splice(index, 0, error);
1728}
1729function byIndex(x) {
1730 return x.index;
1731}
1732
1733function camelize(str) {
1734 return str.replace(/-(\w)/gu, (_, c) => (c ? c.toUpperCase() : ""));
1735}
1736
1737const shorthandSign = /^[.:@#]/u;
1738const shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" };
1739const invalidDynamicArgumentNextChar = /^[\s\r\n=/>]$/u;
1740function getTagName$1(startTagOrElement, isSFC) {
1741 return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
1742}
1743function parseDirectiveKeyStatically(node, document) {
1744 const { name: text, rawName: rawText, range: [offset], loc: { start: { column, line }, }, } = node;
1745 const directiveKey = {
1746 type: "VDirectiveKey",
1747 range: node.range,
1748 loc: node.loc,
1749 parent: node.parent,
1750 name: null,
1751 argument: null,
1752 modifiers: [],
1753 };
1754 let i = 0;
1755 function createIdentifier(start, end, name) {
1756 return {
1757 type: "VIdentifier",
1758 parent: directiveKey,
1759 range: [offset + start, offset + end],
1760 loc: {
1761 start: { column: column + start, line },
1762 end: { column: column + end, line },
1763 },
1764 name: name || text.slice(start, end),
1765 rawName: rawText.slice(start, end),
1766 };
1767 }
1768 if (shorthandSign.test(text)) {
1769 const sign = text[0];
1770 directiveKey.name = createIdentifier(0, 1, shorthandNameMap[sign]);
1771 i = 1;
1772 }
1773 else {
1774 const colon = text.indexOf(":");
1775 if (colon !== -1) {
1776 directiveKey.name = createIdentifier(0, colon);
1777 i = colon + 1;
1778 }
1779 }
1780 if (directiveKey.name != null && text[i] === "[") {
1781 const len = text.slice(i).lastIndexOf("]");
1782 if (len !== -1) {
1783 directiveKey.argument = createIdentifier(i, i + len + 1);
1784 i = i + len + 1 + (text[i + len + 1] === "." ? 1 : 0);
1785 }
1786 }
1787 const modifiers = text
1788 .slice(i)
1789 .split(".")
1790 .map((modifierName) => {
1791 const modifier = createIdentifier(i, i + modifierName.length);
1792 if (modifierName === "" && i < text.length) {
1793 insertError(document, new ParseError(`Unexpected token '${text[i]}'`, undefined, offset + i, line, column + i));
1794 }
1795 i += modifierName.length + 1;
1796 return modifier;
1797 });
1798 if (directiveKey.name == null) {
1799 directiveKey.name = modifiers.shift();
1800 }
1801 else if (directiveKey.argument == null && modifiers[0].name !== "") {
1802 directiveKey.argument = modifiers.shift() || null;
1803 }
1804 directiveKey.modifiers = modifiers.filter(isNotEmptyModifier);
1805 if (directiveKey.name.name === "v-") {
1806 insertError(document, new ParseError(`Unexpected token '${text[directiveKey.name.range[1] - offset]}'`, undefined, directiveKey.name.range[1], directiveKey.name.loc.end.line, directiveKey.name.loc.end.column));
1807 }
1808 if (directiveKey.name.rawName === "." &&
1809 !directiveKey.modifiers.some(isPropModifier)) {
1810 const pos = (directiveKey.argument || directiveKey.name).range[1] - offset;
1811 const propModifier = createIdentifier(pos, pos, "prop");
1812 directiveKey.modifiers.unshift(propModifier);
1813 }
1814 return directiveKey;
1815}
1816function isPropModifier(node) {
1817 return node.name === "prop";
1818}
1819function isNotEmptyModifier(node) {
1820 return node.name !== "";
1821}
1822function parseDirectiveKeyTokens(node) {
1823 const { name, argument, modifiers } = node;
1824 const shorthand = name.range[1] - name.range[0] === 1;
1825 const tokens = [];
1826 if (shorthand) {
1827 tokens.push({
1828 type: "Punctuator",
1829 range: name.range,
1830 loc: name.loc,
1831 value: name.rawName,
1832 });
1833 }
1834 else {
1835 tokens.push({
1836 type: "HTMLIdentifier",
1837 range: name.range,
1838 loc: name.loc,
1839 value: name.rawName,
1840 });
1841 if (argument) {
1842 tokens.push({
1843 type: "Punctuator",
1844 range: [name.range[1], argument.range[0]],
1845 loc: { start: name.loc.end, end: argument.loc.start },
1846 value: ":",
1847 });
1848 }
1849 }
1850 if (argument) {
1851 tokens.push({
1852 type: "HTMLIdentifier",
1853 range: argument.range,
1854 loc: argument.loc,
1855 value: argument.rawName,
1856 });
1857 }
1858 let lastNode = argument || name;
1859 for (const modifier of modifiers) {
1860 if (modifier.rawName === "") {
1861 continue;
1862 }
1863 tokens.push({
1864 type: "Punctuator",
1865 range: [lastNode.range[1], modifier.range[0]],
1866 loc: { start: lastNode.loc.end, end: modifier.loc.start },
1867 value: ".",
1868 }, {
1869 type: "HTMLIdentifier",
1870 range: modifier.range,
1871 loc: modifier.loc,
1872 value: modifier.rawName,
1873 });
1874 lastNode = modifier;
1875 }
1876 return tokens;
1877}
1878function convertDynamicArgument(node, document, parserOptions, locationCalculator) {
1879 const { argument } = node;
1880 if (!(argument != null &&
1881 argument.type === "VIdentifier" &&
1882 argument.name.startsWith("[") &&
1883 argument.name.endsWith("]"))) {
1884 return;
1885 }
1886 const { rawName, range, loc } = argument;
1887 try {
1888 const { comments, expression, references, tokens } = parseExpression(rawName.slice(1, -1), locationCalculator.getSubCalculatorAfter(range[0] + 1), parserOptions);
1889 node.argument = {
1890 type: "VExpressionContainer",
1891 range,
1892 loc,
1893 parent: node,
1894 expression,
1895 references,
1896 };
1897 if (expression != null) {
1898 expression.parent = node.argument;
1899 }
1900 tokens.unshift(createSimpleToken("Punctuator", range[0], range[0] + 1, "[", locationCalculator));
1901 tokens.push(createSimpleToken("Punctuator", range[1] - 1, range[1], "]", locationCalculator));
1902 replaceTokens(document, node.argument, tokens);
1903 insertComments(document, comments);
1904 }
1905 catch (error) {
1906 debug("[template] Parse error: %s", error);
1907 if (ParseError.isParseError(error)) {
1908 node.argument = {
1909 type: "VExpressionContainer",
1910 range,
1911 loc,
1912 parent: node,
1913 expression: null,
1914 references: [],
1915 };
1916 insertError(document, error);
1917 }
1918 else {
1919 throw error;
1920 }
1921 }
1922}
1923function createDirectiveKey(node, document, parserOptions, locationCalculator) {
1924 const directiveKey = parseDirectiveKeyStatically(node, document);
1925 const tokens = parseDirectiveKeyTokens(directiveKey);
1926 replaceTokens(document, directiveKey, tokens);
1927 if (directiveKey.name.name.startsWith("v-")) {
1928 directiveKey.name.name = directiveKey.name.name.slice(2);
1929 }
1930 if (directiveKey.name.rawName.startsWith("v-")) {
1931 directiveKey.name.rawName = directiveKey.name.rawName.slice(2);
1932 }
1933 convertDynamicArgument(directiveKey, document, parserOptions, locationCalculator);
1934 return directiveKey;
1935}
1936function parseAttributeValue(code, parserOptions, scriptParserOptions, globalLocationCalculator, node, element, directiveKey) {
1937 const firstChar = code[node.range[0]];
1938 const quoted = firstChar === '"' || firstChar === "'";
1939 const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(node.range[0] + (quoted ? 1 : 0));
1940 const directiveKind = getStandardDirectiveKind(parserOptions, element, directiveKey);
1941 let result;
1942 if (quoted && node.value === "") {
1943 result = {
1944 expression: null,
1945 tokens: [],
1946 comments: [],
1947 variables: [],
1948 references: [],
1949 };
1950 }
1951 else if (directiveKind === "for") {
1952 result = parseVForExpression(node.value, locationCalculator, parserOptions);
1953 }
1954 else if (directiveKind === "on" && directiveKey.argument != null) {
1955 result = parseVOnExpression(node.value, locationCalculator, parserOptions);
1956 }
1957 else if (directiveKind === "slot") {
1958 result = parseSlotScopeExpression(node.value, locationCalculator, parserOptions);
1959 }
1960 else if (directiveKind === "bind") {
1961 result = parseExpression(node.value, locationCalculator, parserOptions, { allowFilters: true });
1962 }
1963 else if (directiveKind === "generic") {
1964 result = parseGenericExpression(node.value, locationCalculator, scriptParserOptions);
1965 }
1966 else {
1967 result = parseExpression(node.value, locationCalculator, parserOptions);
1968 }
1969 if (quoted) {
1970 result.tokens.unshift(createSimpleToken("Punctuator", node.range[0], node.range[0] + 1, firstChar, globalLocationCalculator));
1971 result.tokens.push(createSimpleToken("Punctuator", node.range[1] - 1, node.range[1], firstChar, globalLocationCalculator));
1972 }
1973 return result;
1974}
1975function getStandardDirectiveKind(parserOptions, element, directiveKey) {
1976 const directiveName = directiveKey.name.name;
1977 if (directiveName === "for") {
1978 return "for";
1979 }
1980 else if (directiveName === "on") {
1981 return "on";
1982 }
1983 else if (directiveName === "slot" ||
1984 directiveName === "slot-scope" ||
1985 (directiveName === "scope" &&
1986 getTagName$1(element, isSFCFile(parserOptions)) === "template")) {
1987 return "slot";
1988 }
1989 else if (directiveName === "bind") {
1990 return "bind";
1991 }
1992 else if (directiveName === "generic" &&
1993 element.parent.type === "VDocumentFragment" &&
1994 getTagName$1(element, isSFCFile(parserOptions)) === "script" &&
1995 isScriptSetupElement(element) &&
1996 isTSLang(element)) {
1997 return "generic";
1998 }
1999 return null;
2000}
2001function resolveReference(referene, element) {
2002 let node = element;
2003 while (node != null && node.type === "VElement") {
2004 for (const variable of node.variables) {
2005 if (variable.id.name === referene.id.name) {
2006 referene.variable = variable;
2007 variable.references.push(referene);
2008 return;
2009 }
2010 }
2011 node = node.parent;
2012 }
2013}
2014function convertToDirective(code, parserOptions, scriptParserOptions, locationCalculator, node) {
2015 debug('[template] convert to directive: %s="%s" %j', node.key.name, node.value && node.value.value, node.range);
2016 const document = getOwnerDocument(node);
2017 const directive = node;
2018 directive.directive = true;
2019 directive.key = createDirectiveKey(node.key, document, parserOptions, locationCalculator);
2020 const { argument } = directive.key;
2021 if (argument &&
2022 argument.type === "VIdentifier" &&
2023 argument.name.startsWith("[")) {
2024 const nextChar = code[argument.range[1]];
2025 if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) {
2026 const char = nextChar == null ? "EOF" : JSON.stringify(nextChar).slice(1, -1);
2027 insertError(document, new ParseError(`Dynamic argument cannot contain the '${char}' character.`, undefined, argument.range[1], argument.loc.end.line, argument.loc.end.column));
2028 }
2029 }
2030 if (node.value == null) {
2031 if (directive.key.name.name === "bind") {
2032 convertForVBindSameNameShorthandValue(directive, parserOptions, locationCalculator);
2033 }
2034 return;
2035 }
2036 try {
2037 const ret = parseAttributeValue(code, parserOptions, scriptParserOptions, locationCalculator, node.value, node.parent.parent, directive.key);
2038 directive.value = {
2039 type: "VExpressionContainer",
2040 range: node.value.range,
2041 loc: node.value.loc,
2042 parent: directive,
2043 expression: ret.expression,
2044 references: ret.references,
2045 };
2046 if (ret.expression != null) {
2047 ret.expression.parent = directive.value;
2048 }
2049 for (const variable of ret.variables) {
2050 node.parent.parent.variables.push(variable);
2051 }
2052 replaceTokens(document, node.value, ret.tokens);
2053 insertComments(document, ret.comments);
2054 }
2055 catch (err) {
2056 debug("[template] Parse error: %s", err);
2057 if (ParseError.isParseError(err)) {
2058 directive.value = {
2059 type: "VExpressionContainer",
2060 range: node.value.range,
2061 loc: node.value.loc,
2062 parent: directive,
2063 expression: null,
2064 references: [],
2065 };
2066 insertError(document, err);
2067 }
2068 else {
2069 throw err;
2070 }
2071 }
2072}
2073function convertForVBindSameNameShorthandValue(directive, parserOptions, locationCalculator) {
2074 if (directive.key.name.name !== "bind" ||
2075 directive.key.argument == null ||
2076 directive.key.argument.type !== "VIdentifier") {
2077 return;
2078 }
2079 const vId = directive.key.argument;
2080 const camelName = camelize(vId.rawName);
2081 let result = null;
2082 try {
2083 result = parseScriptFragment(camelName, locationCalculator.getSubCalculatorAfter(vId.range[0]), parserOptions);
2084 }
2085 catch (err) {
2086 debug("[template] Parse error: %s", err);
2087 }
2088 if (result == null ||
2089 result.ast.body.length !== 1 ||
2090 result.ast.body[0].type !== "ExpressionStatement" ||
2091 result.ast.body[0].expression.type !== "Identifier") {
2092 return;
2093 }
2094 const id = result.ast.body[0].expression;
2095 id.range[1] = vId.range[1];
2096 id.loc.end = Object.assign({}, vId.loc.end);
2097 if (id.end != null) {
2098 id.end = vId.end;
2099 }
2100 directive.value = {
2101 type: "VExpressionContainer",
2102 range: [...vId.range],
2103 loc: {
2104 start: Object.assign({}, vId.loc.start),
2105 end: Object.assign({}, vId.loc.end),
2106 },
2107 parent: directive,
2108 expression: id,
2109 references: [
2110 {
2111 id,
2112 mode: "r",
2113 variable: null,
2114 },
2115 ],
2116 };
2117 id.parent = directive.value;
2118}
2119function processMustache(parserOptions, globalLocationCalculator, node, mustache) {
2120 const range = [
2121 mustache.startToken.range[1],
2122 mustache.endToken.range[0],
2123 ];
2124 debug("[template] convert mustache {{%s}} %j", mustache.value, range);
2125 const document = getOwnerDocument(node);
2126 try {
2127 const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
2128 const ret = parseExpression(mustache.value, locationCalculator, parserOptions, { allowEmpty: true, allowFilters: true });
2129 node.expression = ret.expression || null;
2130 node.references = ret.references;
2131 if (ret.expression != null) {
2132 ret.expression.parent = node;
2133 }
2134 replaceTokens(document, { range }, ret.tokens);
2135 insertComments(document, ret.comments);
2136 }
2137 catch (err) {
2138 debug("[template] Parse error: %s", err);
2139 if (ParseError.isParseError(err)) {
2140 insertError(document, err);
2141 }
2142 else {
2143 throw err;
2144 }
2145 }
2146}
2147function resolveReferences(container) {
2148 let element = container.parent;
2149 while (element != null && element.type !== "VElement") {
2150 element = element.parent;
2151 }
2152 if (element != null) {
2153 for (const reference of container.references) {
2154 resolveReference(reference, element);
2155 }
2156 }
2157}
2158
2159const SVG_ATTRIBUTE_NAME_MAP = new Map([
2160 ["attributename", "attributeName"],
2161 ["attributetype", "attributeType"],
2162 ["basefrequency", "baseFrequency"],
2163 ["baseprofile", "baseProfile"],
2164 ["calcmode", "calcMode"],
2165 ["clippathunits", "clipPathUnits"],
2166 ["diffuseconstant", "diffuseConstant"],
2167 ["edgemode", "edgeMode"],
2168 ["filterunits", "filterUnits"],
2169 ["glyphref", "glyphRef"],
2170 ["gradienttransform", "gradientTransform"],
2171 ["gradientunits", "gradientUnits"],
2172 ["kernelmatrix", "kernelMatrix"],
2173 ["kernelunitlength", "kernelUnitLength"],
2174 ["keypoints", "keyPoints"],
2175 ["keysplines", "keySplines"],
2176 ["keytimes", "keyTimes"],
2177 ["lengthadjust", "lengthAdjust"],
2178 ["limitingconeangle", "limitingConeAngle"],
2179 ["markerheight", "markerHeight"],
2180 ["markerunits", "markerUnits"],
2181 ["markerwidth", "markerWidth"],
2182 ["maskcontentunits", "maskContentUnits"],
2183 ["maskunits", "maskUnits"],
2184 ["numoctaves", "numOctaves"],
2185 ["pathlength", "pathLength"],
2186 ["patterncontentunits", "patternContentUnits"],
2187 ["patterntransform", "patternTransform"],
2188 ["patternunits", "patternUnits"],
2189 ["pointsatx", "pointsAtX"],
2190 ["pointsaty", "pointsAtY"],
2191 ["pointsatz", "pointsAtZ"],
2192 ["preservealpha", "preserveAlpha"],
2193 ["preserveaspectratio", "preserveAspectRatio"],
2194 ["primitiveunits", "primitiveUnits"],
2195 ["refx", "refX"],
2196 ["refy", "refY"],
2197 ["repeatcount", "repeatCount"],
2198 ["repeatdur", "repeatDur"],
2199 ["requiredextensions", "requiredExtensions"],
2200 ["requiredfeatures", "requiredFeatures"],
2201 ["specularconstant", "specularConstant"],
2202 ["specularexponent", "specularExponent"],
2203 ["spreadmethod", "spreadMethod"],
2204 ["startoffset", "startOffset"],
2205 ["stddeviation", "stdDeviation"],
2206 ["stitchtiles", "stitchTiles"],
2207 ["surfacescale", "surfaceScale"],
2208 ["systemlanguage", "systemLanguage"],
2209 ["tablevalues", "tableValues"],
2210 ["targetx", "targetX"],
2211 ["targety", "targetY"],
2212 ["textlength", "textLength"],
2213 ["viewbox", "viewBox"],
2214 ["viewtarget", "viewTarget"],
2215 ["xchannelselector", "xChannelSelector"],
2216 ["ychannelselector", "yChannelSelector"],
2217 ["zoomandpan", "zoomAndPan"],
2218]);
2219const MATHML_ATTRIBUTE_NAME_MAP = new Map([
2220 ["definitionurl", "definitionUrl"]
2221]);
2222
2223const HTML_VOID_ELEMENT_TAGS = new Set([
2224 "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta",
2225 "param", "source", "track", "wbr",
2226]);
2227const HTML_CAN_BE_LEFT_OPEN_TAGS = new Set([
2228 "colgroup", "li", "options", "p", "td", "tfoot", "th", "thead",
2229 "tr", "source",
2230]);
2231const HTML_NON_FHRASING_TAGS = new Set([
2232 "address", "article", "aside", "base", "blockquote", "body", "caption",
2233 "col", "colgroup", "dd", "details", "dialog", "div", "dl", "dt", "fieldset",
2234 "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5",
2235 "h6", "head", "header", "hgroup", "hr", "html", "legend", "li", "menuitem",
2236 "meta", "optgroup", "option", "param", "rp", "rt", "source", "style",
2237 "summary", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track",
2238]);
2239const HTML_RCDATA_TAGS = new Set([
2240 "title", "textarea",
2241]);
2242const HTML_RAWTEXT_TAGS = new Set([
2243 "style", "xmp", "iframe", "noembed", "noframes", "noscript", "script",
2244]);
2245const SVG_TAGS$1 = new Set([
2246 "a", "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor",
2247 "animateMotion", "animateTransform", "animation", "audio", "canvas",
2248 "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "discard",
2249 "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite",
2250 "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap",
2251 "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB",
2252 "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode",
2253 "feMorphology", "feOffset", "fePointLight", "feSpecularLighting",
2254 "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face",
2255 "font-face-format", "font-face-name", "font-face-src", "font-face-uri",
2256 "foreignObject", "g", "glyph", "glyphRef", "handler", "hatch", "hatchpath",
2257 "hkern", "iframe", "image", "line", "linearGradient", "listener", "marker",
2258 "mask", "mesh", "meshgradient", "meshpatch", "meshrow", "metadata",
2259 "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline",
2260 "prefetch", "radialGradient", "rect", "script", "set", "solidColor",
2261 "solidcolor", "stop", "style", "svg", "switch", "symbol", "tbreak", "text",
2262 "textArea", "textPath", "title", "tref", "tspan", "unknown", "use", "video",
2263 "view", "vkern",
2264]);
2265const SVG_ELEMENT_NAME_MAP = new Map();
2266for (const name of SVG_TAGS$1) {
2267 if (/[A-Z]/.test(name)) {
2268 SVG_ELEMENT_NAME_MAP.set(name.toLowerCase(), name);
2269 }
2270}
2271
2272const DUMMY_PARENT$1 = Object.freeze({});
2273function concat(text, token) {
2274 return text + token.value;
2275}
2276class IntermediateTokenizer {
2277 constructor(tokenizer) {
2278 this.tokenizer = tokenizer;
2279 this.currentToken = null;
2280 this.attribute = null;
2281 this.attributeNames = new Set();
2282 this.expressionStartToken = null;
2283 this.expressionTokens = [];
2284 this.tokens = [];
2285 this.comments = [];
2286 }
2287 get text() {
2288 return this.tokenizer.text;
2289 }
2290 get errors() {
2291 return this.tokenizer.errors;
2292 }
2293 get state() {
2294 return this.tokenizer.state;
2295 }
2296 set state(value) {
2297 this.tokenizer.state = value;
2298 }
2299 get namespace() {
2300 return this.tokenizer.namespace;
2301 }
2302 set namespace(value) {
2303 this.tokenizer.namespace = value;
2304 }
2305 get expressionEnabled() {
2306 return this.tokenizer.expressionEnabled;
2307 }
2308 set expressionEnabled(value) {
2309 this.tokenizer.expressionEnabled = value;
2310 }
2311 nextToken() {
2312 let token = null;
2313 let result = null;
2314 while (result == null && (token = this.tokenizer.nextToken()) != null) {
2315 result = this[token.type](token);
2316 }
2317 if (result == null && token == null && this.currentToken != null) {
2318 result = this.commit();
2319 }
2320 return result;
2321 }
2322 commit() {
2323 assert__default["default"](this.currentToken != null || this.expressionStartToken != null);
2324 let token = this.currentToken;
2325 this.currentToken = null;
2326 this.attribute = null;
2327 if (this.expressionStartToken != null) {
2328 const start = this.expressionStartToken;
2329 const end = last__default["default"](this.expressionTokens) || start;
2330 const value = this.expressionTokens.reduce(concat, start.value);
2331 this.expressionStartToken = null;
2332 this.expressionTokens = [];
2333 if (token == null) {
2334 token = {
2335 type: "Text",
2336 range: [start.range[0], end.range[1]],
2337 loc: { start: start.loc.start, end: end.loc.end },
2338 value,
2339 };
2340 }
2341 else if (token.type === "Text") {
2342 token.range[1] = end.range[1];
2343 token.loc.end = end.loc.end;
2344 token.value += value;
2345 }
2346 else {
2347 throw new Error("unreachable");
2348 }
2349 }
2350 return token;
2351 }
2352 reportParseError(token, code) {
2353 const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
2354 this.errors.push(error);
2355 debug("[html] syntax error:", error.message);
2356 }
2357 processComment(token) {
2358 this.comments.push(token);
2359 if (this.currentToken != null && this.currentToken.type === "Text") {
2360 return this.commit();
2361 }
2362 return null;
2363 }
2364 processText(token) {
2365 this.tokens.push(token);
2366 let result = null;
2367 if (this.expressionStartToken != null) {
2368 const lastToken = last__default["default"](this.expressionTokens) || this.expressionStartToken;
2369 if (lastToken.range[1] === token.range[0]) {
2370 this.expressionTokens.push(token);
2371 return null;
2372 }
2373 result = this.commit();
2374 }
2375 else if (this.currentToken != null) {
2376 if (this.currentToken.type === "Text" &&
2377 this.currentToken.range[1] === token.range[0]) {
2378 this.currentToken.value += token.value;
2379 this.currentToken.range[1] = token.range[1];
2380 this.currentToken.loc.end = token.loc.end;
2381 return null;
2382 }
2383 result = this.commit();
2384 }
2385 assert__default["default"](this.currentToken == null);
2386 this.currentToken = {
2387 type: "Text",
2388 range: [token.range[0], token.range[1]],
2389 loc: { start: token.loc.start, end: token.loc.end },
2390 value: token.value,
2391 };
2392 return result;
2393 }
2394 HTMLAssociation(token) {
2395 this.tokens.push(token);
2396 if (this.attribute != null) {
2397 this.attribute.range[1] = token.range[1];
2398 this.attribute.loc.end = token.loc.end;
2399 if (this.currentToken == null ||
2400 this.currentToken.type !== "StartTag") {
2401 throw new Error("unreachable");
2402 }
2403 this.currentToken.range[1] = token.range[1];
2404 this.currentToken.loc.end = token.loc.end;
2405 }
2406 return null;
2407 }
2408 HTMLBogusComment(token) {
2409 return this.processComment(token);
2410 }
2411 HTMLCDataText(token) {
2412 return this.processText(token);
2413 }
2414 HTMLComment(token) {
2415 return this.processComment(token);
2416 }
2417 HTMLEndTagOpen(token) {
2418 this.tokens.push(token);
2419 let result = null;
2420 if (this.currentToken != null || this.expressionStartToken != null) {
2421 result = this.commit();
2422 }
2423 this.currentToken = {
2424 type: "EndTag",
2425 range: [token.range[0], token.range[1]],
2426 loc: { start: token.loc.start, end: token.loc.end },
2427 name: token.value,
2428 };
2429 return result;
2430 }
2431 HTMLIdentifier(token) {
2432 this.tokens.push(token);
2433 if (this.currentToken == null ||
2434 this.currentToken.type === "Text" ||
2435 this.currentToken.type === "Mustache") {
2436 throw new Error("unreachable");
2437 }
2438 if (this.currentToken.type === "EndTag") {
2439 this.reportParseError(token, "end-tag-with-attributes");
2440 return null;
2441 }
2442 if (this.attributeNames.has(token.value)) {
2443 this.reportParseError(token, "duplicate-attribute");
2444 }
2445 this.attributeNames.add(token.value);
2446 this.attribute = {
2447 type: "VAttribute",
2448 range: [token.range[0], token.range[1]],
2449 loc: { start: token.loc.start, end: token.loc.end },
2450 parent: DUMMY_PARENT$1,
2451 directive: false,
2452 key: {
2453 type: "VIdentifier",
2454 range: [token.range[0], token.range[1]],
2455 loc: { start: token.loc.start, end: token.loc.end },
2456 parent: DUMMY_PARENT$1,
2457 name: token.value,
2458 rawName: this.text.slice(token.range[0], token.range[1]),
2459 },
2460 value: null,
2461 };
2462 this.attribute.key.parent = this.attribute;
2463 this.currentToken.range[1] = token.range[1];
2464 this.currentToken.loc.end = token.loc.end;
2465 this.currentToken.attributes.push(this.attribute);
2466 return null;
2467 }
2468 HTMLLiteral(token) {
2469 this.tokens.push(token);
2470 if (this.attribute != null) {
2471 this.attribute.range[1] = token.range[1];
2472 this.attribute.loc.end = token.loc.end;
2473 this.attribute.value = {
2474 type: "VLiteral",
2475 range: [token.range[0], token.range[1]],
2476 loc: { start: token.loc.start, end: token.loc.end },
2477 parent: this.attribute,
2478 value: token.value,
2479 };
2480 if (this.currentToken == null ||
2481 this.currentToken.type !== "StartTag") {
2482 throw new Error("unreachable");
2483 }
2484 this.currentToken.range[1] = token.range[1];
2485 this.currentToken.loc.end = token.loc.end;
2486 }
2487 return null;
2488 }
2489 HTMLRCDataText(token) {
2490 return this.processText(token);
2491 }
2492 HTMLRawText(token) {
2493 return this.processText(token);
2494 }
2495 HTMLSelfClosingTagClose(token) {
2496 this.tokens.push(token);
2497 if (this.currentToken == null || this.currentToken.type === "Text") {
2498 throw new Error("unreachable");
2499 }
2500 if (this.currentToken.type === "StartTag") {
2501 this.currentToken.selfClosing = true;
2502 }
2503 else {
2504 this.reportParseError(token, "end-tag-with-trailing-solidus");
2505 }
2506 this.currentToken.range[1] = token.range[1];
2507 this.currentToken.loc.end = token.loc.end;
2508 return this.commit();
2509 }
2510 HTMLTagClose(token) {
2511 this.tokens.push(token);
2512 if (this.currentToken == null || this.currentToken.type === "Text") {
2513 throw new Error("unreachable");
2514 }
2515 this.currentToken.range[1] = token.range[1];
2516 this.currentToken.loc.end = token.loc.end;
2517 return this.commit();
2518 }
2519 HTMLTagOpen(token) {
2520 this.tokens.push(token);
2521 let result = null;
2522 if (this.currentToken != null || this.expressionStartToken != null) {
2523 result = this.commit();
2524 }
2525 this.currentToken = {
2526 type: "StartTag",
2527 range: [token.range[0], token.range[1]],
2528 loc: { start: token.loc.start, end: token.loc.end },
2529 name: token.value,
2530 rawName: this.text.slice(token.range[0] + 1, token.range[1]),
2531 selfClosing: false,
2532 attributes: [],
2533 };
2534 this.attribute = null;
2535 this.attributeNames.clear();
2536 return result;
2537 }
2538 HTMLText(token) {
2539 return this.processText(token);
2540 }
2541 HTMLWhitespace(token) {
2542 return this.processText(token);
2543 }
2544 VExpressionStart(token) {
2545 if (this.expressionStartToken != null) {
2546 return this.processText(token);
2547 }
2548 const separated = this.currentToken != null &&
2549 this.currentToken.range[1] !== token.range[0];
2550 const result = separated ? this.commit() : null;
2551 this.tokens.push(token);
2552 this.expressionStartToken = token;
2553 return result;
2554 }
2555 VExpressionEnd(token) {
2556 if (this.expressionStartToken == null) {
2557 return this.processText(token);
2558 }
2559 const start = this.expressionStartToken;
2560 const end = last__default["default"](this.expressionTokens) || start;
2561 if (token.range[0] === start.range[1]) {
2562 this.tokens.pop();
2563 this.expressionStartToken = null;
2564 const result = this.processText(start);
2565 this.processText(token);
2566 return result;
2567 }
2568 if (end.range[1] !== token.range[0]) {
2569 const result = this.commit();
2570 this.processText(token);
2571 return result;
2572 }
2573 const value = this.expressionTokens.reduce(concat, "");
2574 this.tokens.push(token);
2575 this.expressionStartToken = null;
2576 this.expressionTokens = [];
2577 const result = this.currentToken != null ? this.commit() : null;
2578 this.currentToken = {
2579 type: "Mustache",
2580 range: [start.range[0], token.range[1]],
2581 loc: { start: start.loc.start, end: token.loc.end },
2582 value,
2583 startToken: start,
2584 endToken: token,
2585 };
2586 return result || this.commit();
2587 }
2588}
2589
2590const DIRECTIVE_NAME = /^(?:v-|[.:@#]).*[^.:@#]$/u;
2591const DT_DD = /^d[dt]$/u;
2592const DUMMY_PARENT = Object.freeze({});
2593function getTagName(startTagOrElement, isSFC) {
2594 return isSFC ? startTagOrElement.rawName : startTagOrElement.name;
2595}
2596function isMathMLIntegrationPoint(element, isSFC) {
2597 if (element.namespace === NS.MathML) {
2598 const name = getTagName(element, isSFC);
2599 return (name === "mi" ||
2600 name === "mo" ||
2601 name === "mn" ||
2602 name === "ms" ||
2603 name === "mtext");
2604 }
2605 return false;
2606}
2607function isHTMLIntegrationPoint(element, isSFC) {
2608 if (element.namespace === NS.MathML) {
2609 return (getTagName(element, isSFC) === "annotation-xml" &&
2610 element.startTag.attributes.some((a) => a.directive === false &&
2611 a.key.name === "encoding" &&
2612 a.value != null &&
2613 (a.value.value === "text/html" ||
2614 a.value.value === "application/xhtml+xml")));
2615 }
2616 if (element.namespace === NS.SVG) {
2617 const name = getTagName(element, isSFC);
2618 return name === "foreignObject" || name === "desc" || name === "title";
2619 }
2620 return false;
2621}
2622function adjustElementName(name, namespace) {
2623 if (namespace === NS.SVG) {
2624 return SVG_ELEMENT_NAME_MAP.get(name) || name;
2625 }
2626 return name;
2627}
2628function adjustAttributeName(name, namespace) {
2629 if (namespace === NS.SVG) {
2630 return SVG_ATTRIBUTE_NAME_MAP.get(name) || name;
2631 }
2632 if (namespace === NS.MathML) {
2633 return MATHML_ATTRIBUTE_NAME_MAP.get(name) || name;
2634 }
2635 return name;
2636}
2637function propagateEndLocation(node) {
2638 const lastChild = (node.type === "VElement" ? node.endTag : null) || last__default["default"](node.children);
2639 if (lastChild != null) {
2640 node.range[1] = lastChild.range[1];
2641 node.loc.end = lastChild.loc.end;
2642 }
2643}
2644class Parser {
2645 constructor(tokenizer, parserOptions) {
2646 this.postProcessesForScript = [];
2647 this.tokenizer = new IntermediateTokenizer(tokenizer);
2648 this.locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
2649 this.baseParserOptions = parserOptions;
2650 this.isSFC = isSFCFile(parserOptions);
2651 this.document = {
2652 type: "VDocumentFragment",
2653 range: [0, 0],
2654 loc: {
2655 start: { line: 1, column: 0 },
2656 end: { line: 1, column: 0 },
2657 },
2658 parent: null,
2659 children: [],
2660 tokens: this.tokens,
2661 comments: this.comments,
2662 errors: this.errors,
2663 };
2664 this.elementStack = [];
2665 this.vPreElement = null;
2666 this.postProcessesForScript = [];
2667 }
2668 get text() {
2669 return this.tokenizer.text;
2670 }
2671 get tokens() {
2672 return this.tokenizer.tokens;
2673 }
2674 get comments() {
2675 return this.tokenizer.comments;
2676 }
2677 get errors() {
2678 return this.tokenizer.errors;
2679 }
2680 get namespace() {
2681 return this.tokenizer.namespace;
2682 }
2683 set namespace(value) {
2684 this.tokenizer.namespace = value;
2685 }
2686 get expressionEnabled() {
2687 return this.tokenizer.expressionEnabled;
2688 }
2689 set expressionEnabled(value) {
2690 this.tokenizer.expressionEnabled = value;
2691 }
2692 get currentNode() {
2693 return last__default["default"](this.elementStack) || this.document;
2694 }
2695 get isInVPreElement() {
2696 return this.vPreElement != null;
2697 }
2698 parse() {
2699 let token = null;
2700 while ((token = this.tokenizer.nextToken()) != null) {
2701 this[token.type](token);
2702 }
2703 this.popElementStackUntil(0);
2704 propagateEndLocation(this.document);
2705 const doc = this.document;
2706 const htmlParserOptions = Object.assign(Object.assign({}, this.baseParserOptions), { parser: getScriptParser(this.baseParserOptions.parser, function* () {
2707 yield "<template>";
2708 yield getParserLangFromSFC(doc);
2709 }) });
2710 const scriptParserOptions = Object.assign(Object.assign({}, this.baseParserOptions), { parser: getScriptParser(this.baseParserOptions.parser, () => getParserLangFromSFC(doc)) });
2711 for (const proc of this.postProcessesForScript) {
2712 proc(htmlParserOptions, scriptParserOptions);
2713 }
2714 this.postProcessesForScript = [];
2715 return doc;
2716 }
2717 reportParseError(token, code) {
2718 const error = ParseError.fromCode(code, token.range[0], token.loc.start.line, token.loc.start.column);
2719 this.errors.push(error);
2720 debug("[html] syntax error:", error.message);
2721 }
2722 popElementStack() {
2723 assert__default["default"](this.elementStack.length >= 1);
2724 const element = this.elementStack.pop();
2725 propagateEndLocation(element);
2726 const current = this.currentNode;
2727 this.namespace =
2728 current.type === "VElement" ? current.namespace : NS.HTML;
2729 if (this.vPreElement === element) {
2730 this.vPreElement = null;
2731 this.expressionEnabled = true;
2732 }
2733 if (this.elementStack.length === 0) {
2734 this.expressionEnabled = false;
2735 }
2736 }
2737 popElementStackUntil(index) {
2738 while (this.elementStack.length > index) {
2739 this.popElementStack();
2740 }
2741 }
2742 getTagName(startTagOrElement) {
2743 return getTagName(startTagOrElement, this.isSFC);
2744 }
2745 detectNamespace(token) {
2746 const name = this.getTagName(token);
2747 let ns = this.namespace;
2748 if (ns === NS.MathML || ns === NS.SVG) {
2749 const element = this.currentNode;
2750 if (element.type === "VElement") {
2751 if (element.namespace === NS.MathML &&
2752 this.getTagName(element) === "annotation-xml" &&
2753 name === "svg") {
2754 return NS.SVG;
2755 }
2756 if (isHTMLIntegrationPoint(element, this.isSFC) ||
2757 (isMathMLIntegrationPoint(element, this.isSFC) &&
2758 name !== "mglyph" &&
2759 name !== "malignmark")) {
2760 ns = NS.HTML;
2761 }
2762 }
2763 }
2764 if (ns === NS.HTML) {
2765 if (name === "svg") {
2766 return NS.SVG;
2767 }
2768 if (name === "math") {
2769 return NS.MathML;
2770 }
2771 }
2772 if (name === "template") {
2773 const xmlns = token.attributes.find((a) => a.key.name === "xmlns");
2774 const value = xmlns && xmlns.value && xmlns.value.value;
2775 if (value === NS.HTML || value === NS.MathML || value === NS.SVG) {
2776 return value;
2777 }
2778 }
2779 return ns;
2780 }
2781 closeCurrentElementIfNecessary(token) {
2782 const element = this.currentNode;
2783 if (element.type !== "VElement") {
2784 return;
2785 }
2786 const name = this.getTagName(token);
2787 const elementName = this.getTagName(element);
2788 if (elementName === "p" && HTML_NON_FHRASING_TAGS.has(name)) {
2789 this.popElementStack();
2790 }
2791 if (elementName === name && HTML_CAN_BE_LEFT_OPEN_TAGS.has(name)) {
2792 this.popElementStack();
2793 }
2794 if (DT_DD.test(elementName) && DT_DD.test(name)) {
2795 this.popElementStack();
2796 }
2797 }
2798 processAttribute(node, namespace) {
2799 if (this.needConvertToDirective(node)) {
2800 this.postProcessesForScript.push((parserOptions, scriptParserOptions) => {
2801 convertToDirective(this.text, parserOptions, scriptParserOptions, this.locationCalculator, node);
2802 });
2803 return;
2804 }
2805 node.key.name = adjustAttributeName(node.key.name, namespace);
2806 const key = this.getTagName(node.key);
2807 const value = node.value && node.value.value;
2808 if (key === "xmlns" && value !== namespace) {
2809 this.reportParseError(node, "x-invalid-namespace");
2810 }
2811 else if (key === "xmlns:xlink" && value !== NS.XLink) {
2812 this.reportParseError(node, "x-invalid-namespace");
2813 }
2814 }
2815 needConvertToDirective(node) {
2816 const element = node.parent.parent;
2817 const tagName = this.getTagName(element);
2818 const attrName = this.getTagName(node.key);
2819 if (attrName === "generic" &&
2820 element.parent.type === "VDocumentFragment" &&
2821 isScriptSetupElement(element) &&
2822 isTSLang(element)) {
2823 return true;
2824 }
2825 const expressionEnabled = this.expressionEnabled ||
2826 (attrName === "v-pre" && !this.isInVPreElement);
2827 if (!expressionEnabled) {
2828 return false;
2829 }
2830 return (DIRECTIVE_NAME.test(attrName) ||
2831 attrName === "slot-scope" ||
2832 (tagName === "template" && attrName === "scope"));
2833 }
2834 processTemplateText(token, templateTokenizerOption) {
2835 const TemplateTokenizer = typeof templateTokenizerOption === "function"
2836 ? templateTokenizerOption
2837 :
2838 require(templateTokenizerOption);
2839 const templateTokenizer = new TemplateTokenizer(token.value, this.text, {
2840 startingLine: token.loc.start.line,
2841 startingColumn: token.loc.start.column,
2842 });
2843 const rootTokenizer = this.tokenizer;
2844 this.tokenizer = templateTokenizer;
2845 let templateToken = null;
2846 while ((templateToken = templateTokenizer.nextToken()) != null) {
2847 this[templateToken.type](templateToken);
2848 }
2849 this.tokenizer = rootTokenizer;
2850 const index = sortedIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[0]);
2851 const count = sortedLastIndexBy__default["default"](this.tokenizer.tokens, token, (x) => x.range[1]) -
2852 index;
2853 this.tokenizer.tokens.splice(index, count, ...templateTokenizer.tokens);
2854 this.tokenizer.comments.push(...templateTokenizer.comments);
2855 this.tokenizer.errors.push(...templateTokenizer.errors);
2856 }
2857 StartTag(token) {
2858 var _a;
2859 debug("[html] StartTag %j", token);
2860 this.closeCurrentElementIfNecessary(token);
2861 const parent = this.currentNode;
2862 const namespace = this.detectNamespace(token);
2863 const element = {
2864 type: "VElement",
2865 range: [token.range[0], token.range[1]],
2866 loc: { start: token.loc.start, end: token.loc.end },
2867 parent,
2868 name: adjustElementName(token.name, namespace),
2869 rawName: token.rawName,
2870 namespace,
2871 startTag: {
2872 type: "VStartTag",
2873 range: token.range,
2874 loc: token.loc,
2875 parent: DUMMY_PARENT,
2876 selfClosing: token.selfClosing,
2877 attributes: token.attributes,
2878 },
2879 children: [],
2880 endTag: null,
2881 variables: [],
2882 };
2883 const hasVPre = !this.isInVPreElement &&
2884 token.attributes.some((a) => this.getTagName(a.key) === "v-pre");
2885 if (hasVPre) {
2886 this.expressionEnabled = false;
2887 }
2888 parent.children.push(element);
2889 element.startTag.parent = element;
2890 for (const attribute of token.attributes) {
2891 attribute.parent = element.startTag;
2892 this.processAttribute(attribute, namespace);
2893 }
2894 this.postProcessesForScript.push(() => {
2895 for (const attribute of element.startTag.attributes) {
2896 if (attribute.directive) {
2897 if (attribute.key.argument != null &&
2898 attribute.key.argument.type === "VExpressionContainer") {
2899 resolveReferences(attribute.key.argument);
2900 }
2901 if (attribute.value != null) {
2902 resolveReferences(attribute.value);
2903 }
2904 }
2905 }
2906 });
2907 const isVoid = namespace === NS.HTML &&
2908 HTML_VOID_ELEMENT_TAGS.has(this.getTagName(element));
2909 if (token.selfClosing && !isVoid && namespace === NS.HTML) {
2910 this.reportParseError(token, "non-void-html-element-start-tag-with-trailing-solidus");
2911 }
2912 if (token.selfClosing || isVoid) {
2913 this.expressionEnabled = !this.isInVPreElement;
2914 return;
2915 }
2916 this.elementStack.push(element);
2917 if (hasVPre) {
2918 assert__default["default"](this.vPreElement === null);
2919 this.vPreElement = element;
2920 }
2921 this.namespace = namespace;
2922 if (namespace === NS.HTML) {
2923 const elementName = this.getTagName(element);
2924 if (element.parent.type === "VDocumentFragment") {
2925 const langAttr = element.startTag.attributes.find((a) => !a.directive && a.key.name === "lang");
2926 const lang = (_a = langAttr === null || langAttr === void 0 ? void 0 : langAttr.value) === null || _a === void 0 ? void 0 : _a.value;
2927 if (elementName === "template") {
2928 this.expressionEnabled = true;
2929 if (lang && lang !== "html") {
2930 this.tokenizer.state = "RAWTEXT";
2931 this.expressionEnabled = false;
2932 }
2933 }
2934 else if (this.isSFC) {
2935 if (!lang || lang !== "html") {
2936 this.tokenizer.state = "RAWTEXT";
2937 }
2938 }
2939 else {
2940 if (HTML_RCDATA_TAGS.has(elementName)) {
2941 this.tokenizer.state = "RCDATA";
2942 }
2943 if (HTML_RAWTEXT_TAGS.has(elementName)) {
2944 this.tokenizer.state = "RAWTEXT";
2945 }
2946 }
2947 }
2948 else {
2949 if (HTML_RCDATA_TAGS.has(elementName)) {
2950 this.tokenizer.state = "RCDATA";
2951 }
2952 if (HTML_RAWTEXT_TAGS.has(elementName)) {
2953 this.tokenizer.state = "RAWTEXT";
2954 }
2955 }
2956 }
2957 }
2958 EndTag(token) {
2959 debug("[html] EndTag %j", token);
2960 const i = findLastIndex__default["default"](this.elementStack, (el) => el.name.toLowerCase() === token.name);
2961 if (i === -1) {
2962 this.reportParseError(token, "x-invalid-end-tag");
2963 return;
2964 }
2965 const element = this.elementStack[i];
2966 element.endTag = {
2967 type: "VEndTag",
2968 range: token.range,
2969 loc: token.loc,
2970 parent: element,
2971 };
2972 this.popElementStackUntil(i);
2973 }
2974 Text(token) {
2975 var _a, _b;
2976 debug("[html] Text %j", token);
2977 const parent = this.currentNode;
2978 if (token.value &&
2979 parent.type === "VElement" &&
2980 parent.name === "template" &&
2981 parent.parent.type === "VDocumentFragment") {
2982 const langAttribute = parent.startTag.attributes.find((a) => a.key.name === "lang");
2983 const lang = (_a = langAttribute === null || langAttribute === void 0 ? void 0 : langAttribute.value) === null || _a === void 0 ? void 0 : _a.value;
2984 if (lang && lang !== "html") {
2985 const templateTokenizerOption = (_b = this.baseParserOptions.templateTokenizer) === null || _b === void 0 ? void 0 : _b[lang];
2986 if (templateTokenizerOption) {
2987 this.processTemplateText(token, templateTokenizerOption);
2988 return;
2989 }
2990 }
2991 }
2992 parent.children.push({
2993 type: "VText",
2994 range: token.range,
2995 loc: token.loc,
2996 parent,
2997 value: token.value,
2998 });
2999 }
3000 Mustache(token) {
3001 debug("[html] Mustache %j", token);
3002 const parent = this.currentNode;
3003 const container = {
3004 type: "VExpressionContainer",
3005 range: token.range,
3006 loc: token.loc,
3007 parent,
3008 expression: null,
3009 references: [],
3010 };
3011 parent.children.push(container);
3012 this.postProcessesForScript.push((parserOptions) => {
3013 processMustache(parserOptions, this.locationCalculator, container, token);
3014 resolveReferences(container);
3015 });
3016 }
3017}
3018
3019const alternativeCR = new Map([[128, 8364], [130, 8218], [131, 402], [132, 8222], [133, 8230], [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249], [140, 338], [142, 381], [145, 8216], [146, 8217], [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], [153, 8482], [154, 353], [155, 8250], [156, 339], [158, 382], [159, 376]]);
3020
3021const entitySets = [{ "length": 32, "entities": { "CounterClockwiseContourIntegral;": [8755] } }, { "length": 25, "entities": { "ClockwiseContourIntegral;": [8754], "DoubleLongLeftRightArrow;": [10234] } }, { "length": 24, "entities": { "NotNestedGreaterGreater;": [10914, 824] } }, { "length": 23, "entities": { "DiacriticalDoubleAcute;": [733], "NotSquareSupersetEqual;": [8931] } }, { "length": 22, "entities": { "CloseCurlyDoubleQuote;": [8221], "DoubleContourIntegral;": [8751], "FilledVerySmallSquare;": [9642], "NegativeVeryThinSpace;": [8203], "NotPrecedesSlantEqual;": [8928], "NotRightTriangleEqual;": [8941], "NotSucceedsSlantEqual;": [8929] } }, { "length": 21, "entities": { "CapitalDifferentialD;": [8517], "DoubleLeftRightArrow;": [8660], "DoubleLongRightArrow;": [10233], "EmptyVerySmallSquare;": [9643], "NestedGreaterGreater;": [8811], "NotDoubleVerticalBar;": [8742], "NotGreaterSlantEqual;": [10878, 824], "NotLeftTriangleEqual;": [8940], "NotSquareSubsetEqual;": [8930], "OpenCurlyDoubleQuote;": [8220], "ReverseUpEquilibrium;": [10607] } }, { "length": 20, "entities": { "DoubleLongLeftArrow;": [10232], "DownLeftRightVector;": [10576], "LeftArrowRightArrow;": [8646], "NegativeMediumSpace;": [8203], "NotGreaterFullEqual;": [8807, 824], "NotRightTriangleBar;": [10704, 824], "RightArrowLeftArrow;": [8644], "SquareSupersetEqual;": [8850], "leftrightsquigarrow;": [8621] } }, { "length": 19, "entities": { "DownRightTeeVector;": [10591], "DownRightVectorBar;": [10583], "LongLeftRightArrow;": [10231], "Longleftrightarrow;": [10234], "NegativeThickSpace;": [8203], "NotLeftTriangleBar;": [10703, 824], "PrecedesSlantEqual;": [8828], "ReverseEquilibrium;": [8651], "RightDoubleBracket;": [10215], "RightDownTeeVector;": [10589], "RightDownVectorBar;": [10581], "RightTriangleEqual;": [8885], "SquareIntersection;": [8851], "SucceedsSlantEqual;": [8829], "blacktriangleright;": [9656], "longleftrightarrow;": [10231] } }, { "length": 18, "entities": { "DoubleUpDownArrow;": [8661], "DoubleVerticalBar;": [8741], "DownLeftTeeVector;": [10590], "DownLeftVectorBar;": [10582], "FilledSmallSquare;": [9724], "GreaterSlantEqual;": [10878], "LeftDoubleBracket;": [10214], "LeftDownTeeVector;": [10593], "LeftDownVectorBar;": [10585], "LeftTriangleEqual;": [8884], "NegativeThinSpace;": [8203], "NotGreaterGreater;": [8811, 824], "NotLessSlantEqual;": [10877, 824], "NotNestedLessLess;": [10913, 824], "NotReverseElement;": [8716], "NotSquareSuperset;": [8848, 824], "NotTildeFullEqual;": [8775], "RightAngleBracket;": [10217], "RightUpDownVector;": [10575], "SquareSubsetEqual;": [8849], "VerticalSeparator;": [10072], "blacktriangledown;": [9662], "blacktriangleleft;": [9666], "leftrightharpoons;": [8651], "rightleftharpoons;": [8652], "twoheadrightarrow;": [8608] } }, { "length": 17, "entities": { "DiacriticalAcute;": [180], "DiacriticalGrave;": [96], "DiacriticalTilde;": [732], "DoubleRightArrow;": [8658], "DownArrowUpArrow;": [8693], "EmptySmallSquare;": [9723], "GreaterEqualLess;": [8923], "GreaterFullEqual;": [8807], "LeftAngleBracket;": [10216], "LeftUpDownVector;": [10577], "LessEqualGreater;": [8922], "NonBreakingSpace;": [160], "NotPrecedesEqual;": [10927, 824], "NotRightTriangle;": [8939], "NotSucceedsEqual;": [10928, 824], "NotSucceedsTilde;": [8831, 824], "NotSupersetEqual;": [8841], "RightTriangleBar;": [10704], "RightUpTeeVector;": [10588], "RightUpVectorBar;": [10580], "UnderParenthesis;": [9181], "UpArrowDownArrow;": [8645], "circlearrowright;": [8635], "downharpoonright;": [8642], "ntrianglerighteq;": [8941], "rightharpoondown;": [8641], "rightrightarrows;": [8649], "twoheadleftarrow;": [8606], "vartriangleright;": [8883] } }, { "length": 16, "entities": { "CloseCurlyQuote;": [8217], "ContourIntegral;": [8750], "DoubleDownArrow;": [8659], "DoubleLeftArrow;": [8656], "DownRightVector;": [8641], "LeftRightVector;": [10574], "LeftTriangleBar;": [10703], "LeftUpTeeVector;": [10592], "LeftUpVectorBar;": [10584], "LowerRightArrow;": [8600], "NotGreaterEqual;": [8817], "NotGreaterTilde;": [8821], "NotHumpDownHump;": [8782, 824], "NotLeftTriangle;": [8938], "NotSquareSubset;": [8847, 824], "OverParenthesis;": [9180], "RightDownVector;": [8642], "ShortRightArrow;": [8594], "UpperRightArrow;": [8599], "bigtriangledown;": [9661], "circlearrowleft;": [8634], "curvearrowright;": [8631], "downharpoonleft;": [8643], "leftharpoondown;": [8637], "leftrightarrows;": [8646], "nLeftrightarrow;": [8654], "nleftrightarrow;": [8622], "ntrianglelefteq;": [8940], "rightleftarrows;": [8644], "rightsquigarrow;": [8605], "rightthreetimes;": [8908], "straightepsilon;": [1013], "trianglerighteq;": [8885], "vartriangleleft;": [8882] } }, { "length": 15, "entities": { "DiacriticalDot;": [729], "DoubleRightTee;": [8872], "DownLeftVector;": [8637], "GreaterGreater;": [10914], "HorizontalLine;": [9472], "InvisibleComma;": [8291], "InvisibleTimes;": [8290], "LeftDownVector;": [8643], "LeftRightArrow;": [8596], "Leftrightarrow;": [8660], "LessSlantEqual;": [10877], "LongRightArrow;": [10230], "Longrightarrow;": [10233], "LowerLeftArrow;": [8601], "NestedLessLess;": [8810], "NotGreaterLess;": [8825], "NotLessGreater;": [8824], "NotSubsetEqual;": [8840], "NotVerticalBar;": [8740], "OpenCurlyQuote;": [8216], "ReverseElement;": [8715], "RightTeeVector;": [10587], "RightVectorBar;": [10579], "ShortDownArrow;": [8595], "ShortLeftArrow;": [8592], "SquareSuperset;": [8848], "TildeFullEqual;": [8773], "UpperLeftArrow;": [8598], "ZeroWidthSpace;": [8203], "curvearrowleft;": [8630], "doublebarwedge;": [8966], "downdownarrows;": [8650], "hookrightarrow;": [8618], "leftleftarrows;": [8647], "leftrightarrow;": [8596], "leftthreetimes;": [8907], "longrightarrow;": [10230], "looparrowright;": [8620], "nshortparallel;": [8742], "ntriangleright;": [8939], "rightarrowtail;": [8611], "rightharpoonup;": [8640], "trianglelefteq;": [8884], "upharpoonright;": [8638] } }, { "length": 14, "entities": { "ApplyFunction;": [8289], "DifferentialD;": [8518], "DoubleLeftTee;": [10980], "DoubleUpArrow;": [8657], "LeftTeeVector;": [10586], "LeftVectorBar;": [10578], "LessFullEqual;": [8806], "LongLeftArrow;": [10229], "Longleftarrow;": [10232], "NotEqualTilde;": [8770, 824], "NotTildeEqual;": [8772], "NotTildeTilde;": [8777], "Poincareplane;": [8460], "PrecedesEqual;": [10927], "PrecedesTilde;": [8830], "RightArrowBar;": [8677], "RightTeeArrow;": [8614], "RightTriangle;": [8883], "RightUpVector;": [8638], "SucceedsEqual;": [10928], "SucceedsTilde;": [8831], "SupersetEqual;": [8839], "UpEquilibrium;": [10606], "VerticalTilde;": [8768], "VeryThinSpace;": [8202], "bigtriangleup;": [9651], "blacktriangle;": [9652], "divideontimes;": [8903], "fallingdotseq;": [8786], "hookleftarrow;": [8617], "leftarrowtail;": [8610], "leftharpoonup;": [8636], "longleftarrow;": [10229], "looparrowleft;": [8619], "measuredangle;": [8737], "ntriangleleft;": [8938], "shortparallel;": [8741], "smallsetminus;": [8726], "triangleright;": [9657], "upharpoonleft;": [8639], "varsubsetneqq;": [10955, 65024], "varsupsetneqq;": [10956, 65024] } }, { "length": 13, "entities": { "DownArrowBar;": [10515], "DownTeeArrow;": [8615], "ExponentialE;": [8519], "GreaterEqual;": [8805], "GreaterTilde;": [8819], "HilbertSpace;": [8459], "HumpDownHump;": [8782], "Intersection;": [8898], "LeftArrowBar;": [8676], "LeftTeeArrow;": [8612], "LeftTriangle;": [8882], "LeftUpVector;": [8639], "NotCongruent;": [8802], "NotHumpEqual;": [8783, 824], "NotLessEqual;": [8816], "NotLessTilde;": [8820], "Proportional;": [8733], "RightCeiling;": [8969], "RoundImplies;": [10608], "ShortUpArrow;": [8593], "SquareSubset;": [8847], "UnderBracket;": [9141], "VerticalLine;": [124], "blacklozenge;": [10731], "exponentiale;": [8519], "risingdotseq;": [8787], "triangledown;": [9663], "triangleleft;": [9667], "varsubsetneq;": [8842, 65024], "varsupsetneq;": [8843, 65024] } }, { "length": 12, "entities": { "CircleMinus;": [8854], "CircleTimes;": [8855], "Equilibrium;": [8652], "GreaterLess;": [8823], "LeftCeiling;": [8968], "LessGreater;": [8822], "MediumSpace;": [8287], "NotLessLess;": [8810, 824], "NotPrecedes;": [8832], "NotSucceeds;": [8833], "NotSuperset;": [8835, 8402], "OverBracket;": [9140], "RightVector;": [8640], "Rrightarrow;": [8667], "RuleDelayed;": [10740], "SmallCircle;": [8728], "SquareUnion;": [8852], "SubsetEqual;": [8838], "UpDownArrow;": [8597], "Updownarrow;": [8661], "VerticalBar;": [8739], "backepsilon;": [1014], "blacksquare;": [9642], "circledcirc;": [8858], "circleddash;": [8861], "curlyeqprec;": [8926], "curlyeqsucc;": [8927], "diamondsuit;": [9830], "eqslantless;": [10901], "expectation;": [8496], "nRightarrow;": [8655], "nrightarrow;": [8603], "preccurlyeq;": [8828], "precnapprox;": [10937], "quaternions;": [8461], "straightphi;": [981], "succcurlyeq;": [8829], "succnapprox;": [10938], "thickapprox;": [8776], "updownarrow;": [8597] } }, { "length": 11, "entities": { "Bernoullis;": [8492], "CirclePlus;": [8853], "EqualTilde;": [8770], "Fouriertrf;": [8497], "ImaginaryI;": [8520], "Laplacetrf;": [8466], "LeftVector;": [8636], "Lleftarrow;": [8666], "NotElement;": [8713], "NotGreater;": [8815], "Proportion;": [8759], "RightArrow;": [8594], "RightFloor;": [8971], "Rightarrow;": [8658], "ThickSpace;": [8287, 8202], "TildeEqual;": [8771], "TildeTilde;": [8776], "UnderBrace;": [9183], "UpArrowBar;": [10514], "UpTeeArrow;": [8613], "circledast;": [8859], "complement;": [8705], "curlywedge;": [8911], "eqslantgtr;": [10902], "gtreqqless;": [10892], "lessapprox;": [10885], "lesseqqgtr;": [10891], "lmoustache;": [9136], "longmapsto;": [10236], "mapstodown;": [8615], "mapstoleft;": [8612], "nLeftarrow;": [8653], "nleftarrow;": [8602], "nsubseteqq;": [10949, 824], "nsupseteqq;": [10950, 824], "precapprox;": [10935], "rightarrow;": [8594], "rmoustache;": [9137], "sqsubseteq;": [8849], "sqsupseteq;": [8850], "subsetneqq;": [10955], "succapprox;": [10936], "supsetneqq;": [10956], "upuparrows;": [8648], "varepsilon;": [1013], "varnothing;": [8709] } }, { "length": 10, "entities": { "Backslash;": [8726], "CenterDot;": [183], "CircleDot;": [8857], "Congruent;": [8801], "Coproduct;": [8720], "DoubleDot;": [168], "DownArrow;": [8595], "DownBreve;": [785], "Downarrow;": [8659], "HumpEqual;": [8783], "LeftArrow;": [8592], "LeftFloor;": [8970], "Leftarrow;": [8656], "LessTilde;": [8818], "Mellintrf;": [8499], "MinusPlus;": [8723], "NotCupCap;": [8813], "NotExists;": [8708], "NotSubset;": [8834, 8402], "OverBrace;": [9182], "PlusMinus;": [177], "Therefore;": [8756], "ThinSpace;": [8201], "TripleDot;": [8411], "UnionPlus;": [8846], "backprime;": [8245], "backsimeq;": [8909], "bigotimes;": [10754], "centerdot;": [183], "checkmark;": [10003], "complexes;": [8450], "dotsquare;": [8865], "downarrow;": [8595], "gtrapprox;": [10886], "gtreqless;": [8923], "gvertneqq;": [8809, 65024], "heartsuit;": [9829], "leftarrow;": [8592], "lesseqgtr;": [8922], "lvertneqq;": [8808, 65024], "ngeqslant;": [10878, 824], "nleqslant;": [10877, 824], "nparallel;": [8742], "nshortmid;": [8740], "nsubseteq;": [8840], "nsupseteq;": [8841], "pitchfork;": [8916], "rationals;": [8474], "spadesuit;": [9824], "subseteqq;": [10949], "subsetneq;": [8842], "supseteqq;": [10950], "supsetneq;": [8843], "therefore;": [8756], "triangleq;": [8796], "varpropto;": [8733] } }, { "length": 9, "entities": { "DDotrahd;": [10513], "DotEqual;": [8784], "Integral;": [8747], "LessLess;": [10913], "NotEqual;": [8800], "NotTilde;": [8769], "PartialD;": [8706], "Precedes;": [8826], "RightTee;": [8866], "Succeeds;": [8827], "SuchThat;": [8715], "Superset;": [8835], "Uarrocir;": [10569], "UnderBar;": [95], "andslope;": [10840], "angmsdaa;": [10664], "angmsdab;": [10665], "angmsdac;": [10666], "angmsdad;": [10667], "angmsdae;": [10668], "angmsdaf;": [10669], "angmsdag;": [10670], "angmsdah;": [10671], "angrtvbd;": [10653], "approxeq;": [8778], "awconint;": [8755], "backcong;": [8780], "barwedge;": [8965], "bbrktbrk;": [9142], "bigoplus;": [10753], "bigsqcup;": [10758], "biguplus;": [10756], "bigwedge;": [8896], "boxminus;": [8863], "boxtimes;": [8864], "bsolhsub;": [10184], "capbrcup;": [10825], "circledR;": [174], "circledS;": [9416], "cirfnint;": [10768], "clubsuit;": [9827], "cupbrcap;": [10824], "curlyvee;": [8910], "cwconint;": [8754], "doteqdot;": [8785], "dotminus;": [8760], "drbkarow;": [10512], "dzigrarr;": [10239], "elinters;": [9191], "emptyset;": [8709], "eqvparsl;": [10725], "fpartint;": [10765], "geqslant;": [10878], "gesdotol;": [10884], "gnapprox;": [10890], "hksearow;": [10533], "hkswarow;": [10534], "imagline;": [8464], "imagpart;": [8465], "infintie;": [10717], "integers;": [8484], "intercal;": [8890], "intlarhk;": [10775], "laemptyv;": [10676], "ldrushar;": [10571], "leqslant;": [10877], "lesdotor;": [10883], "llcorner;": [8990], "lnapprox;": [10889], "lrcorner;": [8991], "lurdshar;": [10570], "mapstoup;": [8613], "multimap;": [8888], "naturals;": [8469], "ncongdot;": [10861, 824], "notindot;": [8949, 824], "otimesas;": [10806], "parallel;": [8741], "plusacir;": [10787], "pointint;": [10773], "precneqq;": [10933], "precnsim;": [8936], "profalar;": [9006], "profline;": [8978], "profsurf;": [8979], "raemptyv;": [10675], "realpart;": [8476], "rppolint;": [10770], "rtriltri;": [10702], "scpolint;": [10771], "setminus;": [8726], "shortmid;": [8739], "smeparsl;": [10724], "sqsubset;": [8847], "sqsupset;": [8848], "subseteq;": [8838], "succneqq;": [10934], "succnsim;": [8937], "supseteq;": [8839], "thetasym;": [977], "thicksim;": [8764], "timesbar;": [10801], "triangle;": [9653], "triminus;": [10810], "trpezium;": [9186], "ulcorner;": [8988], "urcorner;": [8989], "varkappa;": [1008], "varsigma;": [962], "vartheta;": [977] } }, { "length": 8, "entities": { "Because;": [8757], "Cayleys;": [8493], "Cconint;": [8752], "Cedilla;": [184], "Diamond;": [8900], "DownTee;": [8868], "Element;": [8712], "Epsilon;": [917], "Implies;": [8658], "LeftTee;": [8867], "NewLine;": [10], "NoBreak;": [8288], "NotLess;": [8814], "Omicron;": [927], "OverBar;": [8254], "Product;": [8719], "UpArrow;": [8593], "Uparrow;": [8657], "Upsilon;": [933], "alefsym;": [8501], "angrtvb;": [8894], "angzarr;": [9084], "asympeq;": [8781], "backsim;": [8765], "because;": [8757], "bemptyv;": [10672], "between;": [8812], "bigcirc;": [9711], "bigodot;": [10752], "bigstar;": [9733], "bnequiv;": [8801, 8421], "boxplus;": [8862], "ccupssm;": [10832], "cemptyv;": [10674], "cirscir;": [10690], "coloneq;": [8788], "congdot;": [10861], "cudarrl;": [10552], "cudarrr;": [10549], "cularrp;": [10557], "curarrm;": [10556], "dbkarow;": [10511], "ddagger;": [8225], "ddotseq;": [10871], "demptyv;": [10673], "diamond;": [8900], "digamma;": [989], "dotplus;": [8724], "dwangle;": [10662], "epsilon;": [949], "eqcolon;": [8789], "equivDD;": [10872], "gesdoto;": [10882], "gtquest;": [10876], "gtrless;": [8823], "harrcir;": [10568], "intprod;": [10812], "isindot;": [8949], "larrbfs;": [10527], "larrsim;": [10611], "lbrksld;": [10639], "lbrkslu;": [10637], "ldrdhar;": [10599], "lesdoto;": [10881], "lessdot;": [8918], "lessgtr;": [8822], "lesssim;": [8818], "lotimes;": [10804], "lozenge;": [9674], "ltquest;": [10875], "luruhar;": [10598], "maltese;": [10016], "minusdu;": [10794], "napprox;": [8777], "natural;": [9838], "nearrow;": [8599], "nexists;": [8708], "notinva;": [8713], "notinvb;": [8951], "notinvc;": [8950], "notniva;": [8716], "notnivb;": [8958], "notnivc;": [8957], "npolint;": [10772], "npreceq;": [10927, 824], "nsqsube;": [8930], "nsqsupe;": [8931], "nsubset;": [8834, 8402], "nsucceq;": [10928, 824], "nsupset;": [8835, 8402], "nvinfin;": [10718], "nvltrie;": [8884, 8402], "nvrtrie;": [8885, 8402], "nwarrow;": [8598], "olcross;": [10683], "omicron;": [959], "orderof;": [8500], "orslope;": [10839], "pertenk;": [8241], "planckh;": [8462], "pluscir;": [10786], "plussim;": [10790], "plustwo;": [10791], "precsim;": [8830], "quatint;": [10774], "questeq;": [8799], "rarrbfs;": [10528], "rarrsim;": [10612], "rbrksld;": [10638], "rbrkslu;": [10640], "rdldhar;": [10601], "realine;": [8475], "rotimes;": [10805], "ruluhar;": [10600], "searrow;": [8600], "simplus;": [10788], "simrarr;": [10610], "subedot;": [10947], "submult;": [10945], "subplus;": [10943], "subrarr;": [10617], "succsim;": [8831], "supdsub;": [10968], "supedot;": [10948], "suphsol;": [10185], "suphsub;": [10967], "suplarr;": [10619], "supmult;": [10946], "supplus;": [10944], "swarrow;": [8601], "topfork;": [10970], "triplus;": [10809], "tritime;": [10811], "uparrow;": [8593], "upsilon;": [965], "uwangle;": [10663], "vzigzag;": [10650], "zigrarr;": [8669] } }, { "length": 7, "entities": { "Aacute;": [193], "Abreve;": [258], "Agrave;": [192], "Assign;": [8788], "Atilde;": [195], "Barwed;": [8966], "Bumpeq;": [8782], "Cacute;": [262], "Ccaron;": [268], "Ccedil;": [199], "Colone;": [10868], "Conint;": [8751], "CupCap;": [8781], "Dagger;": [8225], "Dcaron;": [270], "DotDot;": [8412], "Dstrok;": [272], "Eacute;": [201], "Ecaron;": [282], "Egrave;": [200], "Exists;": [8707], "ForAll;": [8704], "Gammad;": [988], "Gbreve;": [286], "Gcedil;": [290], "HARDcy;": [1066], "Hstrok;": [294], "Iacute;": [205], "Igrave;": [204], "Itilde;": [296], "Jsercy;": [1032], "Kcedil;": [310], "Lacute;": [313], "Lambda;": [923], "Lcaron;": [317], "Lcedil;": [315], "Lmidot;": [319], "Lstrok;": [321], "Nacute;": [323], "Ncaron;": [327], "Ncedil;": [325], "Ntilde;": [209], "Oacute;": [211], "Odblac;": [336], "Ograve;": [210], "Oslash;": [216], "Otilde;": [213], "Otimes;": [10807], "Racute;": [340], "Rarrtl;": [10518], "Rcaron;": [344], "Rcedil;": [342], "SHCHcy;": [1065], "SOFTcy;": [1068], "Sacute;": [346], "Scaron;": [352], "Scedil;": [350], "Square;": [9633], "Subset;": [8912], "Supset;": [8913], "Tcaron;": [356], "Tcedil;": [354], "Tstrok;": [358], "Uacute;": [218], "Ubreve;": [364], "Udblac;": [368], "Ugrave;": [217], "Utilde;": [360], "Vdashl;": [10982], "Verbar;": [8214], "Vvdash;": [8874], "Yacute;": [221], "Zacute;": [377], "Zcaron;": [381], "aacute;": [225], "abreve;": [259], "agrave;": [224], "andand;": [10837], "angmsd;": [8737], "angsph;": [8738], "apacir;": [10863], "approx;": [8776], "atilde;": [227], "barvee;": [8893], "barwed;": [8965], "becaus;": [8757], "bernou;": [8492], "bigcap;": [8898], "bigcup;": [8899], "bigvee;": [8897], "bkarow;": [10509], "bottom;": [8869], "bowtie;": [8904], "boxbox;": [10697], "bprime;": [8245], "brvbar;": [166], "bullet;": [8226], "bumpeq;": [8783], "cacute;": [263], "capand;": [10820], "capcap;": [10827], "capcup;": [10823], "capdot;": [10816], "ccaron;": [269], "ccedil;": [231], "circeq;": [8791], "cirmid;": [10991], "colone;": [8788], "commat;": [64], "compfn;": [8728], "conint;": [8750], "coprod;": [8720], "copysr;": [8471], "cularr;": [8630], "cupcap;": [10822], "cupcup;": [10826], "cupdot;": [8845], "curarr;": [8631], "curren;": [164], "cylcty;": [9005], "dagger;": [8224], "daleth;": [8504], "dcaron;": [271], "dfisht;": [10623], "divide;": [247], "divonx;": [8903], "dlcorn;": [8990], "dlcrop;": [8973], "dollar;": [36], "drcorn;": [8991], "drcrop;": [8972], "dstrok;": [273], "eacute;": [233], "easter;": [10862], "ecaron;": [283], "ecolon;": [8789], "egrave;": [232], "egsdot;": [10904], "elsdot;": [10903], "emptyv;": [8709], "emsp13;": [8196], "emsp14;": [8197], "eparsl;": [10723], "eqcirc;": [8790], "equals;": [61], "equest;": [8799], "female;": [9792], "ffilig;": [64259], "ffllig;": [64260], "forall;": [8704], "frac12;": [189], "frac13;": [8531], "frac14;": [188], "frac15;": [8533], "frac16;": [8537], "frac18;": [8539], "frac23;": [8532], "frac25;": [8534], "frac34;": [190], "frac35;": [8535], "frac38;": [8540], "frac45;": [8536], "frac56;": [8538], "frac58;": [8541], "frac78;": [8542], "gacute;": [501], "gammad;": [989], "gbreve;": [287], "gesdot;": [10880], "gesles;": [10900], "gtlPar;": [10645], "gtrarr;": [10616], "gtrdot;": [8919], "gtrsim;": [8819], "hairsp;": [8202], "hamilt;": [8459], "hardcy;": [1098], "hearts;": [9829], "hellip;": [8230], "hercon;": [8889], "homtht;": [8763], "horbar;": [8213], "hslash;": [8463], "hstrok;": [295], "hybull;": [8259], "hyphen;": [8208], "iacute;": [237], "igrave;": [236], "iiiint;": [10764], "iinfin;": [10716], "incare;": [8453], "inodot;": [305], "intcal;": [8890], "iquest;": [191], "isinsv;": [8947], "itilde;": [297], "jsercy;": [1112], "kappav;": [1008], "kcedil;": [311], "kgreen;": [312], "lAtail;": [10523], "lacute;": [314], "lagran;": [8466], "lambda;": [955], "langle;": [10216], "larrfs;": [10525], "larrhk;": [8617], "larrlp;": [8619], "larrpl;": [10553], "larrtl;": [8610], "latail;": [10521], "lbrace;": [123], "lbrack;": [91], "lcaron;": [318], "lcedil;": [316], "ldquor;": [8222], "lesdot;": [10879], "lesges;": [10899], "lfisht;": [10620], "lfloor;": [8970], "lharul;": [10602], "llhard;": [10603], "lmidot;": [320], "lmoust;": [9136], "loplus;": [10797], "lowast;": [8727], "lowbar;": [95], "lparlt;": [10643], "lrhard;": [10605], "lsaquo;": [8249], "lsquor;": [8218], "lstrok;": [322], "lthree;": [8907], "ltimes;": [8905], "ltlarr;": [10614], "ltrPar;": [10646], "mapsto;": [8614], "marker;": [9646], "mcomma;": [10793], "midast;": [42], "midcir;": [10992], "middot;": [183], "minusb;": [8863], "minusd;": [8760], "mnplus;": [8723], "models;": [8871], "mstpos;": [8766], "nVDash;": [8879], "nVdash;": [8878], "nacute;": [324], "nbumpe;": [8783, 824], "ncaron;": [328], "ncedil;": [326], "nearhk;": [10532], "nequiv;": [8802], "nesear;": [10536], "nexist;": [8708], "nltrie;": [8940], "notinE;": [8953, 824], "nparsl;": [11005, 8421], "nprcue;": [8928], "nrarrc;": [10547, 824], "nrarrw;": [8605, 824], "nrtrie;": [8941], "nsccue;": [8929], "nsimeq;": [8772], "ntilde;": [241], "numero;": [8470], "nvDash;": [8877], "nvHarr;": [10500], "nvdash;": [8876], "nvlArr;": [10498], "nvrArr;": [10499], "nwarhk;": [10531], "nwnear;": [10535], "oacute;": [243], "odblac;": [337], "odsold;": [10684], "ograve;": [242], "ominus;": [8854], "origof;": [8886], "oslash;": [248], "otilde;": [245], "otimes;": [8855], "parsim;": [10995], "percnt;": [37], "period;": [46], "permil;": [8240], "phmmat;": [8499], "planck;": [8463], "plankv;": [8463], "plusdo;": [8724], "plusdu;": [10789], "plusmn;": [177], "preceq;": [10927], "primes;": [8473], "prnsim;": [8936], "propto;": [8733], "prurel;": [8880], "puncsp;": [8200], "qprime;": [8279], "rAtail;": [10524], "racute;": [341], "rangle;": [10217], "rarrap;": [10613], "rarrfs;": [10526], "rarrhk;": [8618], "rarrlp;": [8620], "rarrpl;": [10565], "rarrtl;": [8611], "ratail;": [10522], "rbrace;": [125], "rbrack;": [93], "rcaron;": [345], "rcedil;": [343], "rdquor;": [8221], "rfisht;": [10621], "rfloor;": [8971], "rharul;": [10604], "rmoust;": [9137], "roplus;": [10798], "rpargt;": [10644], "rsaquo;": [8250], "rsquor;": [8217], "rthree;": [8908], "rtimes;": [8906], "sacute;": [347], "scaron;": [353], "scedil;": [351], "scnsim;": [8937], "searhk;": [10533], "seswar;": [10537], "sfrown;": [8994], "shchcy;": [1097], "sigmaf;": [962], "sigmav;": [962], "simdot;": [10858], "smashp;": [10803], "softcy;": [1100], "solbar;": [9023], "spades;": [9824], "sqcaps;": [8851, 65024], "sqcups;": [8852, 65024], "sqsube;": [8849], "sqsupe;": [8850], "square;": [9633], "squarf;": [9642], "ssetmn;": [8726], "ssmile;": [8995], "sstarf;": [8902], "subdot;": [10941], "subset;": [8834], "subsim;": [10951], "subsub;": [10965], "subsup;": [10963], "succeq;": [10928], "supdot;": [10942], "supset;": [8835], "supsim;": [10952], "supsub;": [10964], "supsup;": [10966], "swarhk;": [10534], "swnwar;": [10538], "target;": [8982], "tcaron;": [357], "tcedil;": [355], "telrec;": [8981], "there4;": [8756], "thetav;": [977], "thinsp;": [8201], "thksim;": [8764], "timesb;": [8864], "timesd;": [10800], "topbot;": [9014], "topcir;": [10993], "tprime;": [8244], "tridot;": [9708], "tstrok;": [359], "uacute;": [250], "ubreve;": [365], "udblac;": [369], "ufisht;": [10622], "ugrave;": [249], "ulcorn;": [8988], "ulcrop;": [8975], "urcorn;": [8989], "urcrop;": [8974], "utilde;": [361], "vangrt;": [10652], "varphi;": [981], "varrho;": [1009], "veebar;": [8891], "vellip;": [8942], "verbar;": [124], "vsubnE;": [10955, 65024], "vsubne;": [8842, 65024], "vsupnE;": [10956, 65024], "vsupne;": [8843, 65024], "wedbar;": [10847], "wedgeq;": [8793], "weierp;": [8472], "wreath;": [8768], "xoplus;": [10753], "xotime;": [10754], "xsqcup;": [10758], "xuplus;": [10756], "xwedge;": [8896], "yacute;": [253], "zacute;": [378], "zcaron;": [382], "zeetrf;": [8488] } }, { "length": 6, "entities": { "AElig;": [198], "Aacute": [193], "Acirc;": [194], "Agrave": [192], "Alpha;": [913], "Amacr;": [256], "Aogon;": [260], "Aring;": [197], "Atilde": [195], "Breve;": [728], "Ccedil": [199], "Ccirc;": [264], "Colon;": [8759], "Cross;": [10799], "Dashv;": [10980], "Delta;": [916], "Eacute": [201], "Ecirc;": [202], "Egrave": [200], "Emacr;": [274], "Eogon;": [280], "Equal;": [10869], "Gamma;": [915], "Gcirc;": [284], "Hacek;": [711], "Hcirc;": [292], "IJlig;": [306], "Iacute": [205], "Icirc;": [206], "Igrave": [204], "Imacr;": [298], "Iogon;": [302], "Iukcy;": [1030], "Jcirc;": [308], "Jukcy;": [1028], "Kappa;": [922], "Ntilde": [209], "OElig;": [338], "Oacute": [211], "Ocirc;": [212], "Ograve": [210], "Omacr;": [332], "Omega;": [937], "Oslash": [216], "Otilde": [213], "Prime;": [8243], "RBarr;": [10512], "Scirc;": [348], "Sigma;": [931], "THORN;": [222], "TRADE;": [8482], "TSHcy;": [1035], "Theta;": [920], "Tilde;": [8764], "Uacute": [218], "Ubrcy;": [1038], "Ucirc;": [219], "Ugrave": [217], "Umacr;": [362], "Union;": [8899], "Uogon;": [370], "UpTee;": [8869], "Uring;": [366], "VDash;": [8875], "Vdash;": [8873], "Wcirc;": [372], "Wedge;": [8896], "Yacute": [221], "Ycirc;": [374], "aacute": [225], "acirc;": [226], "acute;": [180], "aelig;": [230], "agrave": [224], "aleph;": [8501], "alpha;": [945], "amacr;": [257], "amalg;": [10815], "angle;": [8736], "angrt;": [8735], "angst;": [197], "aogon;": [261], "aring;": [229], "asymp;": [8776], "atilde": [227], "awint;": [10769], "bcong;": [8780], "bdquo;": [8222], "bepsi;": [1014], "blank;": [9251], "blk12;": [9618], "blk14;": [9617], "blk34;": [9619], "block;": [9608], "boxDL;": [9559], "boxDR;": [9556], "boxDl;": [9558], "boxDr;": [9555], "boxHD;": [9574], "boxHU;": [9577], "boxHd;": [9572], "boxHu;": [9575], "boxUL;": [9565], "boxUR;": [9562], "boxUl;": [9564], "boxUr;": [9561], "boxVH;": [9580], "boxVL;": [9571], "boxVR;": [9568], "boxVh;": [9579], "boxVl;": [9570], "boxVr;": [9567], "boxdL;": [9557], "boxdR;": [9554], "boxdl;": [9488], "boxdr;": [9484], "boxhD;": [9573], "boxhU;": [9576], "boxhd;": [9516], "boxhu;": [9524], "boxuL;": [9563], "boxuR;": [9560], "boxul;": [9496], "boxur;": [9492], "boxvH;": [9578], "boxvL;": [9569], "boxvR;": [9566], "boxvh;": [9532], "boxvl;": [9508], "boxvr;": [9500], "breve;": [728], "brvbar": [166], "bsemi;": [8271], "bsime;": [8909], "bsolb;": [10693], "bumpE;": [10926], "bumpe;": [8783], "caret;": [8257], "caron;": [711], "ccaps;": [10829], "ccedil": [231], "ccirc;": [265], "ccups;": [10828], "cedil;": [184], "check;": [10003], "clubs;": [9827], "colon;": [58], "comma;": [44], "crarr;": [8629], "cross;": [10007], "csube;": [10961], "csupe;": [10962], "ctdot;": [8943], "cuepr;": [8926], "cuesc;": [8927], "cupor;": [10821], "curren": [164], "cuvee;": [8910], "cuwed;": [8911], "cwint;": [8753], "dashv;": [8867], "dblac;": [733], "ddarr;": [8650], "delta;": [948], "dharl;": [8643], "dharr;": [8642], "diams;": [9830], "disin;": [8946], "divide": [247], "doteq;": [8784], "dtdot;": [8945], "dtrif;": [9662], "duarr;": [8693], "duhar;": [10607], "eDDot;": [10871], "eacute": [233], "ecirc;": [234], "efDot;": [8786], "egrave": [232], "emacr;": [275], "empty;": [8709], "eogon;": [281], "eplus;": [10865], "epsiv;": [1013], "eqsim;": [8770], "equiv;": [8801], "erDot;": [8787], "erarr;": [10609], "esdot;": [8784], "exist;": [8707], "fflig;": [64256], "filig;": [64257], "fjlig;": [102, 106], "fllig;": [64258], "fltns;": [9649], "forkv;": [10969], "frac12": [189], "frac14": [188], "frac34": [190], "frasl;": [8260], "frown;": [8994], "gamma;": [947], "gcirc;": [285], "gescc;": [10921], "gimel;": [8503], "gneqq;": [8809], "gnsim;": [8935], "grave;": [96], "gsime;": [10894], "gsiml;": [10896], "gtcir;": [10874], "gtdot;": [8919], "harrw;": [8621], "hcirc;": [293], "hoarr;": [8703], "iacute": [237], "icirc;": [238], "iexcl;": [161], "igrave": [236], "iiint;": [8749], "iiota;": [8489], "ijlig;": [307], "imacr;": [299], "image;": [8465], "imath;": [305], "imped;": [437], "infin;": [8734], "iogon;": [303], "iprod;": [10812], "iquest": [191], "isinE;": [8953], "isins;": [8948], "isinv;": [8712], "iukcy;": [1110], "jcirc;": [309], "jmath;": [567], "jukcy;": [1108], "kappa;": [954], "lAarr;": [8666], "lBarr;": [10510], "langd;": [10641], "laquo;": [171], "larrb;": [8676], "lates;": [10925, 65024], "lbarr;": [10508], "lbbrk;": [10098], "lbrke;": [10635], "lceil;": [8968], "ldquo;": [8220], "lescc;": [10920], "lhard;": [8637], "lharu;": [8636], "lhblk;": [9604], "llarr;": [8647], "lltri;": [9722], "lneqq;": [8808], "lnsim;": [8934], "loang;": [10220], "loarr;": [8701], "lobrk;": [10214], "lopar;": [10629], "lrarr;": [8646], "lrhar;": [8651], "lrtri;": [8895], "lsime;": [10893], "lsimg;": [10895], "lsquo;": [8216], "ltcir;": [10873], "ltdot;": [8918], "ltrie;": [8884], "ltrif;": [9666], "mDDot;": [8762], "mdash;": [8212], "micro;": [181], "middot": [183], "minus;": [8722], "mumap;": [8888], "nabla;": [8711], "napid;": [8779, 824], "napos;": [329], "natur;": [9838], "nbump;": [8782, 824], "ncong;": [8775], "ndash;": [8211], "neArr;": [8663], "nearr;": [8599], "nedot;": [8784, 824], "nesim;": [8770, 824], "ngeqq;": [8807, 824], "ngsim;": [8821], "nhArr;": [8654], "nharr;": [8622], "nhpar;": [10994], "nlArr;": [8653], "nlarr;": [8602], "nleqq;": [8806, 824], "nless;": [8814], "nlsim;": [8820], "nltri;": [8938], "notin;": [8713], "notni;": [8716], "npart;": [8706, 824], "nprec;": [8832], "nrArr;": [8655], "nrarr;": [8603], "nrtri;": [8939], "nsime;": [8772], "nsmid;": [8740], "nspar;": [8742], "nsubE;": [10949, 824], "nsube;": [8840], "nsucc;": [8833], "nsupE;": [10950, 824], "nsupe;": [8841], "ntilde": [241], "numsp;": [8199], "nvsim;": [8764, 8402], "nwArr;": [8662], "nwarr;": [8598], "oacute": [243], "ocirc;": [244], "odash;": [8861], "oelig;": [339], "ofcir;": [10687], "ograve": [242], "ohbar;": [10677], "olarr;": [8634], "olcir;": [10686], "oline;": [8254], "omacr;": [333], "omega;": [969], "operp;": [10681], "oplus;": [8853], "orarr;": [8635], "order;": [8500], "oslash": [248], "otilde": [245], "ovbar;": [9021], "parsl;": [11005], "phone;": [9742], "plusb;": [8862], "pluse;": [10866], "plusmn": [177], "pound;": [163], "prcue;": [8828], "prime;": [8242], "prnap;": [10937], "prsim;": [8830], "quest;": [63], "rAarr;": [8667], "rBarr;": [10511], "radic;": [8730], "rangd;": [10642], "range;": [10661], "raquo;": [187], "rarrb;": [8677], "rarrc;": [10547], "rarrw;": [8605], "ratio;": [8758], "rbarr;": [10509], "rbbrk;": [10099], "rbrke;": [10636], "rceil;": [8969], "rdquo;": [8221], "reals;": [8477], "rhard;": [8641], "rharu;": [8640], "rlarr;": [8644], "rlhar;": [8652], "rnmid;": [10990], "roang;": [10221], "roarr;": [8702], "robrk;": [10215], "ropar;": [10630], "rrarr;": [8649], "rsquo;": [8217], "rtrie;": [8885], "rtrif;": [9656], "sbquo;": [8218], "sccue;": [8829], "scirc;": [349], "scnap;": [10938], "scsim;": [8831], "sdotb;": [8865], "sdote;": [10854], "seArr;": [8664], "searr;": [8600], "setmn;": [8726], "sharp;": [9839], "sigma;": [963], "simeq;": [8771], "simgE;": [10912], "simlE;": [10911], "simne;": [8774], "slarr;": [8592], "smile;": [8995], "smtes;": [10924, 65024], "sqcap;": [8851], "sqcup;": [8852], "sqsub;": [8847], "sqsup;": [8848], "srarr;": [8594], "starf;": [9733], "strns;": [175], "subnE;": [10955], "subne;": [8842], "supnE;": [10956], "supne;": [8843], "swArr;": [8665], "swarr;": [8601], "szlig;": [223], "theta;": [952], "thkap;": [8776], "thorn;": [254], "tilde;": [732], "times;": [215], "trade;": [8482], "trisb;": [10701], "tshcy;": [1115], "twixt;": [8812], "uacute": [250], "ubrcy;": [1118], "ucirc;": [251], "udarr;": [8645], "udhar;": [10606], "ugrave": [249], "uharl;": [8639], "uharr;": [8638], "uhblk;": [9600], "ultri;": [9720], "umacr;": [363], "uogon;": [371], "uplus;": [8846], "upsih;": [978], "uring;": [367], "urtri;": [9721], "utdot;": [8944], "utrif;": [9652], "uuarr;": [8648], "vBarv;": [10985], "vDash;": [8872], "varpi;": [982], "vdash;": [8866], "veeeq;": [8794], "vltri;": [8882], "vnsub;": [8834, 8402], "vnsup;": [8835, 8402], "vprop;": [8733], "vrtri;": [8883], "wcirc;": [373], "wedge;": [8743], "xcirc;": [9711], "xdtri;": [9661], "xhArr;": [10234], "xharr;": [10231], "xlArr;": [10232], "xlarr;": [10229], "xodot;": [10752], "xrArr;": [10233], "xrarr;": [10230], "xutri;": [9651], "yacute": [253], "ycirc;": [375] } }, { "length": 5, "entities": { "AElig": [198], "Acirc": [194], "Aopf;": [120120], "Aring": [197], "Ascr;": [119964], "Auml;": [196], "Barv;": [10983], "Beta;": [914], "Bopf;": [120121], "Bscr;": [8492], "CHcy;": [1063], "COPY;": [169], "Cdot;": [266], "Copf;": [8450], "Cscr;": [119966], "DJcy;": [1026], "DScy;": [1029], "DZcy;": [1039], "Darr;": [8609], "Dopf;": [120123], "Dscr;": [119967], "Ecirc": [202], "Edot;": [278], "Eopf;": [120124], "Escr;": [8496], "Esim;": [10867], "Euml;": [203], "Fopf;": [120125], "Fscr;": [8497], "GJcy;": [1027], "Gdot;": [288], "Gopf;": [120126], "Gscr;": [119970], "Hopf;": [8461], "Hscr;": [8459], "IEcy;": [1045], "IOcy;": [1025], "Icirc": [206], "Idot;": [304], "Iopf;": [120128], "Iota;": [921], "Iscr;": [8464], "Iuml;": [207], "Jopf;": [120129], "Jscr;": [119973], "KHcy;": [1061], "KJcy;": [1036], "Kopf;": [120130], "Kscr;": [119974], "LJcy;": [1033], "Lang;": [10218], "Larr;": [8606], "Lopf;": [120131], "Lscr;": [8466], "Mopf;": [120132], "Mscr;": [8499], "NJcy;": [1034], "Nopf;": [8469], "Nscr;": [119977], "Ocirc": [212], "Oopf;": [120134], "Oscr;": [119978], "Ouml;": [214], "Popf;": [8473], "Pscr;": [119979], "QUOT;": [34], "Qopf;": [8474], "Qscr;": [119980], "Rang;": [10219], "Rarr;": [8608], "Ropf;": [8477], "Rscr;": [8475], "SHcy;": [1064], "Sopf;": [120138], "Sqrt;": [8730], "Sscr;": [119982], "Star;": [8902], "THORN": [222], "TScy;": [1062], "Topf;": [120139], "Tscr;": [119983], "Uarr;": [8607], "Ucirc": [219], "Uopf;": [120140], "Upsi;": [978], "Uscr;": [119984], "Uuml;": [220], "Vbar;": [10987], "Vert;": [8214], "Vopf;": [120141], "Vscr;": [119985], "Wopf;": [120142], "Wscr;": [119986], "Xopf;": [120143], "Xscr;": [119987], "YAcy;": [1071], "YIcy;": [1031], "YUcy;": [1070], "Yopf;": [120144], "Yscr;": [119988], "Yuml;": [376], "ZHcy;": [1046], "Zdot;": [379], "Zeta;": [918], "Zopf;": [8484], "Zscr;": [119989], "acirc": [226], "acute": [180], "aelig": [230], "andd;": [10844], "andv;": [10842], "ange;": [10660], "aopf;": [120146], "apid;": [8779], "apos;": [39], "aring": [229], "ascr;": [119990], "auml;": [228], "bNot;": [10989], "bbrk;": [9141], "beta;": [946], "beth;": [8502], "bnot;": [8976], "bopf;": [120147], "boxH;": [9552], "boxV;": [9553], "boxh;": [9472], "boxv;": [9474], "bscr;": [119991], "bsim;": [8765], "bsol;": [92], "bull;": [8226], "bump;": [8782], "caps;": [8745, 65024], "cdot;": [267], "cedil": [184], "cent;": [162], "chcy;": [1095], "cirE;": [10691], "circ;": [710], "cire;": [8791], "comp;": [8705], "cong;": [8773], "copf;": [120148], "copy;": [169], "cscr;": [119992], "csub;": [10959], "csup;": [10960], "cups;": [8746, 65024], "dArr;": [8659], "dHar;": [10597], "darr;": [8595], "dash;": [8208], "diam;": [8900], "djcy;": [1106], "dopf;": [120149], "dscr;": [119993], "dscy;": [1109], "dsol;": [10742], "dtri;": [9663], "dzcy;": [1119], "eDot;": [8785], "ecir;": [8790], "ecirc": [234], "edot;": [279], "emsp;": [8195], "ensp;": [8194], "eopf;": [120150], "epar;": [8917], "epsi;": [949], "escr;": [8495], "esim;": [8770], "euml;": [235], "euro;": [8364], "excl;": [33], "flat;": [9837], "fnof;": [402], "fopf;": [120151], "fork;": [8916], "fscr;": [119995], "gdot;": [289], "geqq;": [8807], "gesl;": [8923, 65024], "gjcy;": [1107], "gnap;": [10890], "gneq;": [10888], "gopf;": [120152], "gscr;": [8458], "gsim;": [8819], "gtcc;": [10919], "gvnE;": [8809, 65024], "hArr;": [8660], "half;": [189], "harr;": [8596], "hbar;": [8463], "hopf;": [120153], "hscr;": [119997], "icirc": [238], "iecy;": [1077], "iexcl": [161], "imof;": [8887], "iocy;": [1105], "iopf;": [120154], "iota;": [953], "iscr;": [119998], "isin;": [8712], "iuml;": [239], "jopf;": [120155], "jscr;": [119999], "khcy;": [1093], "kjcy;": [1116], "kopf;": [120156], "kscr;": [120000], "lArr;": [8656], "lHar;": [10594], "lang;": [10216], "laquo": [171], "larr;": [8592], "late;": [10925], "lcub;": [123], "ldca;": [10550], "ldsh;": [8626], "leqq;": [8806], "lesg;": [8922, 65024], "ljcy;": [1113], "lnap;": [10889], "lneq;": [10887], "lopf;": [120157], "lozf;": [10731], "lpar;": [40], "lscr;": [120001], "lsim;": [8818], "lsqb;": [91], "ltcc;": [10918], "ltri;": [9667], "lvnE;": [8808, 65024], "macr;": [175], "male;": [9794], "malt;": [10016], "micro": [181], "mlcp;": [10971], "mldr;": [8230], "mopf;": [120158], "mscr;": [120002], "nGtv;": [8811, 824], "nLtv;": [8810, 824], "nang;": [8736, 8402], "napE;": [10864, 824], "nbsp;": [160], "ncap;": [10819], "ncup;": [10818], "ngeq;": [8817], "nges;": [10878, 824], "ngtr;": [8815], "nisd;": [8954], "njcy;": [1114], "nldr;": [8229], "nleq;": [8816], "nles;": [10877, 824], "nmid;": [8740], "nopf;": [120159], "npar;": [8742], "npre;": [10927, 824], "nsce;": [10928, 824], "nscr;": [120003], "nsim;": [8769], "nsub;": [8836], "nsup;": [8837], "ntgl;": [8825], "ntlg;": [8824], "nvap;": [8781, 8402], "nvge;": [8805, 8402], "nvgt;": [62, 8402], "nvle;": [8804, 8402], "nvlt;": [60, 8402], "oast;": [8859], "ocir;": [8858], "ocirc": [244], "odiv;": [10808], "odot;": [8857], "ogon;": [731], "oint;": [8750], "omid;": [10678], "oopf;": [120160], "opar;": [10679], "ordf;": [170], "ordm;": [186], "oror;": [10838], "oscr;": [8500], "osol;": [8856], "ouml;": [246], "para;": [182], "part;": [8706], "perp;": [8869], "phiv;": [981], "plus;": [43], "popf;": [120161], "pound": [163], "prap;": [10935], "prec;": [8826], "prnE;": [10933], "prod;": [8719], "prop;": [8733], "pscr;": [120005], "qint;": [10764], "qopf;": [120162], "qscr;": [120006], "quot;": [34], "rArr;": [8658], "rHar;": [10596], "race;": [8765, 817], "rang;": [10217], "raquo": [187], "rarr;": [8594], "rcub;": [125], "rdca;": [10551], "rdsh;": [8627], "real;": [8476], "rect;": [9645], "rhov;": [1009], "ring;": [730], "ropf;": [120163], "rpar;": [41], "rscr;": [120007], "rsqb;": [93], "rtri;": [9657], "scap;": [10936], "scnE;": [10934], "sdot;": [8901], "sect;": [167], "semi;": [59], "sext;": [10038], "shcy;": [1096], "sime;": [8771], "simg;": [10910], "siml;": [10909], "smid;": [8739], "smte;": [10924], "solb;": [10692], "sopf;": [120164], "spar;": [8741], "squf;": [9642], "sscr;": [120008], "star;": [9734], "subE;": [10949], "sube;": [8838], "succ;": [8827], "sung;": [9834], "sup1;": [185], "sup2;": [178], "sup3;": [179], "supE;": [10950], "supe;": [8839], "szlig": [223], "tbrk;": [9140], "tdot;": [8411], "thorn": [254], "times": [215], "tint;": [8749], "toea;": [10536], "topf;": [120165], "tosa;": [10537], "trie;": [8796], "tscr;": [120009], "tscy;": [1094], "uArr;": [8657], "uHar;": [10595], "uarr;": [8593], "ucirc": [251], "uopf;": [120166], "upsi;": [965], "uscr;": [120010], "utri;": [9653], "uuml;": [252], "vArr;": [8661], "vBar;": [10984], "varr;": [8597], "vert;": [124], "vopf;": [120167], "vscr;": [120011], "wopf;": [120168], "wscr;": [120012], "xcap;": [8898], "xcup;": [8899], "xmap;": [10236], "xnis;": [8955], "xopf;": [120169], "xscr;": [120013], "xvee;": [8897], "yacy;": [1103], "yicy;": [1111], "yopf;": [120170], "yscr;": [120014], "yucy;": [1102], "yuml;": [255], "zdot;": [380], "zeta;": [950], "zhcy;": [1078], "zopf;": [120171], "zscr;": [120015], "zwnj;": [8204] } }, { "length": 4, "entities": { "AMP;": [38], "Acy;": [1040], "Afr;": [120068], "And;": [10835], "Auml": [196], "Bcy;": [1041], "Bfr;": [120069], "COPY": [169], "Cap;": [8914], "Cfr;": [8493], "Chi;": [935], "Cup;": [8915], "Dcy;": [1044], "Del;": [8711], "Dfr;": [120071], "Dot;": [168], "ENG;": [330], "ETH;": [208], "Ecy;": [1069], "Efr;": [120072], "Eta;": [919], "Euml": [203], "Fcy;": [1060], "Ffr;": [120073], "Gcy;": [1043], "Gfr;": [120074], "Hat;": [94], "Hfr;": [8460], "Icy;": [1048], "Ifr;": [8465], "Int;": [8748], "Iuml": [207], "Jcy;": [1049], "Jfr;": [120077], "Kcy;": [1050], "Kfr;": [120078], "Lcy;": [1051], "Lfr;": [120079], "Lsh;": [8624], "Map;": [10501], "Mcy;": [1052], "Mfr;": [120080], "Ncy;": [1053], "Nfr;": [120081], "Not;": [10988], "Ocy;": [1054], "Ofr;": [120082], "Ouml": [214], "Pcy;": [1055], "Pfr;": [120083], "Phi;": [934], "Psi;": [936], "QUOT": [34], "Qfr;": [120084], "REG;": [174], "Rcy;": [1056], "Rfr;": [8476], "Rho;": [929], "Rsh;": [8625], "Scy;": [1057], "Sfr;": [120086], "Sub;": [8912], "Sum;": [8721], "Sup;": [8913], "Tab;": [9], "Tau;": [932], "Tcy;": [1058], "Tfr;": [120087], "Ucy;": [1059], "Ufr;": [120088], "Uuml": [220], "Vcy;": [1042], "Vee;": [8897], "Vfr;": [120089], "Wfr;": [120090], "Xfr;": [120091], "Ycy;": [1067], "Yfr;": [120092], "Zcy;": [1047], "Zfr;": [8488], "acE;": [8766, 819], "acd;": [8767], "acy;": [1072], "afr;": [120094], "amp;": [38], "and;": [8743], "ang;": [8736], "apE;": [10864], "ape;": [8778], "ast;": [42], "auml": [228], "bcy;": [1073], "bfr;": [120095], "bne;": [61, 8421], "bot;": [8869], "cap;": [8745], "cent": [162], "cfr;": [120096], "chi;": [967], "cir;": [9675], "copy": [169], "cup;": [8746], "dcy;": [1076], "deg;": [176], "dfr;": [120097], "die;": [168], "div;": [247], "dot;": [729], "ecy;": [1101], "efr;": [120098], "egs;": [10902], "ell;": [8467], "els;": [10901], "eng;": [331], "eta;": [951], "eth;": [240], "euml": [235], "fcy;": [1092], "ffr;": [120099], "gEl;": [10892], "gap;": [10886], "gcy;": [1075], "gel;": [8923], "geq;": [8805], "ges;": [10878], "gfr;": [120100], "ggg;": [8921], "glE;": [10898], "gla;": [10917], "glj;": [10916], "gnE;": [8809], "gne;": [10888], "hfr;": [120101], "icy;": [1080], "iff;": [8660], "ifr;": [120102], "int;": [8747], "iuml": [239], "jcy;": [1081], "jfr;": [120103], "kcy;": [1082], "kfr;": [120104], "lEg;": [10891], "lap;": [10885], "lat;": [10923], "lcy;": [1083], "leg;": [8922], "leq;": [8804], "les;": [10877], "lfr;": [120105], "lgE;": [10897], "lnE;": [8808], "lne;": [10887], "loz;": [9674], "lrm;": [8206], "lsh;": [8624], "macr": [175], "map;": [8614], "mcy;": [1084], "mfr;": [120106], "mho;": [8487], "mid;": [8739], "nGg;": [8921, 824], "nGt;": [8811, 8402], "nLl;": [8920, 824], "nLt;": [8810, 8402], "nap;": [8777], "nbsp": [160], "ncy;": [1085], "nfr;": [120107], "ngE;": [8807, 824], "nge;": [8817], "ngt;": [8815], "nis;": [8956], "niv;": [8715], "nlE;": [8806, 824], "nle;": [8816], "nlt;": [8814], "not;": [172], "npr;": [8832], "nsc;": [8833], "num;": [35], "ocy;": [1086], "ofr;": [120108], "ogt;": [10689], "ohm;": [937], "olt;": [10688], "ord;": [10845], "ordf": [170], "ordm": [186], "orv;": [10843], "ouml": [246], "par;": [8741], "para": [182], "pcy;": [1087], "pfr;": [120109], "phi;": [966], "piv;": [982], "prE;": [10931], "pre;": [10927], "psi;": [968], "qfr;": [120110], "quot": [34], "rcy;": [1088], "reg;": [174], "rfr;": [120111], "rho;": [961], "rlm;": [8207], "rsh;": [8625], "scE;": [10932], "sce;": [10928], "scy;": [1089], "sect": [167], "sfr;": [120112], "shy;": [173], "sim;": [8764], "smt;": [10922], "sol;": [47], "squ;": [9633], "sub;": [8834], "sum;": [8721], "sup1": [185], "sup2": [178], "sup3": [179], "sup;": [8835], "tau;": [964], "tcy;": [1090], "tfr;": [120113], "top;": [8868], "ucy;": [1091], "ufr;": [120114], "uml;": [168], "uuml": [252], "vcy;": [1074], "vee;": [8744], "vfr;": [120115], "wfr;": [120116], "xfr;": [120117], "ycy;": [1099], "yen;": [165], "yfr;": [120118], "yuml": [255], "zcy;": [1079], "zfr;": [120119], "zwj;": [8205] } }, { "length": 3, "entities": { "AMP": [38], "DD;": [8517], "ETH": [208], "GT;": [62], "Gg;": [8921], "Gt;": [8811], "Im;": [8465], "LT;": [60], "Ll;": [8920], "Lt;": [8810], "Mu;": [924], "Nu;": [925], "Or;": [10836], "Pi;": [928], "Pr;": [10939], "REG": [174], "Re;": [8476], "Sc;": [10940], "Xi;": [926], "ac;": [8766], "af;": [8289], "amp": [38], "ap;": [8776], "dd;": [8518], "deg": [176], "ee;": [8519], "eg;": [10906], "el;": [10905], "eth": [240], "gE;": [8807], "ge;": [8805], "gg;": [8811], "gl;": [8823], "gt;": [62], "ic;": [8291], "ii;": [8520], "in;": [8712], "it;": [8290], "lE;": [8806], "le;": [8804], "lg;": [8822], "ll;": [8810], "lt;": [60], "mp;": [8723], "mu;": [956], "ne;": [8800], "ni;": [8715], "not": [172], "nu;": [957], "oS;": [9416], "or;": [8744], "pi;": [960], "pm;": [177], "pr;": [8826], "reg": [174], "rx;": [8478], "sc;": [8827], "shy": [173], "uml": [168], "wp;": [8472], "wr;": [8768], "xi;": [958], "yen": [165] } }, { "length": 2, "entities": { "GT": [62], "LT": [60], "gt": [62], "lt": [60] } }];
3022
3023const EOF = -1;
3024const NULL = 0x00;
3025const TABULATION = 0x09;
3026const CARRIAGE_RETURN = 0x0D;
3027const LINE_FEED = 0x0A;
3028const FORM_FEED = 0x0C;
3029const SPACE = 0x20;
3030const EXCLAMATION_MARK = 0x21;
3031const QUOTATION_MARK = 0x22;
3032const NUMBER_SIGN = 0x23;
3033const AMPERSAND = 0x26;
3034const APOSTROPHE = 0x27;
3035const LEFT_PARENTHESIS = 0x28;
3036const RIGHT_PARENTHESIS = 0x29;
3037const ASTERISK = 0x2A;
3038const HYPHEN_MINUS = 0x2D;
3039const SOLIDUS = 0x2F;
3040const DIGIT_0 = 0x30;
3041const DIGIT_9 = 0x39;
3042const COLON = 0x3a;
3043const SEMICOLON = 0x3B;
3044const LESS_THAN_SIGN = 0x3C;
3045const EQUALS_SIGN = 0x3D;
3046const GREATER_THAN_SIGN = 0x3E;
3047const QUESTION_MARK = 0x3F;
3048const LATIN_CAPITAL_A = 0x41;
3049const LATIN_CAPITAL_D = 0x44;
3050const LATIN_CAPITAL_F = 0x46;
3051const LATIN_CAPITAL_X = 0x58;
3052const LATIN_CAPITAL_Z = 0x5A;
3053const LEFT_SQUARE_BRACKET = 0x5B;
3054const REVERSE_SOLIDUS = 0x5C;
3055const RIGHT_SQUARE_BRACKET = 0x5D;
3056const GRAVE_ACCENT = 0x60;
3057const LATIN_SMALL_A = 0x61;
3058const LATIN_SMALL_F = 0x66;
3059const LATIN_SMALL_X = 0x78;
3060const LATIN_SMALL_Z = 0x7A;
3061const LEFT_CURLY_BRACKET = 0x7B;
3062const RIGHT_CURLY_BRACKET = 0x7D;
3063const NULL_REPLACEMENT = 0xFFFD;
3064function isWhitespace(cp) {
3065 return cp === TABULATION || cp === LINE_FEED || cp === FORM_FEED || cp === CARRIAGE_RETURN || cp === SPACE;
3066}
3067function isUpperLetter(cp) {
3068 return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_Z;
3069}
3070function isLowerLetter(cp) {
3071 return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_Z;
3072}
3073function isLetter(cp) {
3074 return isLowerLetter(cp) || isUpperLetter(cp);
3075}
3076function isDigit(cp) {
3077 return cp >= DIGIT_0 && cp <= DIGIT_9;
3078}
3079function isUpperHexDigit(cp) {
3080 return cp >= LATIN_CAPITAL_A && cp <= LATIN_CAPITAL_F;
3081}
3082function isLowerHexDigit(cp) {
3083 return cp >= LATIN_SMALL_A && cp <= LATIN_SMALL_F;
3084}
3085function isHexDigit(cp) {
3086 return isDigit(cp) || isUpperHexDigit(cp) || isLowerHexDigit(cp);
3087}
3088function isControl(cp) {
3089 return (cp >= 0 && cp <= 0x1F) || (cp >= 0x7F && cp <= 0x9F);
3090}
3091function isSurrogate(cp) {
3092 return cp >= 0xD800 && cp <= 0xDFFF;
3093}
3094function isSurrogatePair(cp) {
3095 return cp >= 0xDC00 && cp <= 0xDFFF;
3096}
3097function isNonCharacter(cp) {
3098 return ((cp >= 0xFDD0 && cp <= 0xFDEF) ||
3099 ((cp & 0xFFFE) === 0xFFFE && cp <= 0x10FFFF));
3100}
3101function toLowerCodePoint(cp) {
3102 return cp + 0x0020;
3103}
3104
3105class Tokenizer {
3106 constructor(text, parserOptions) {
3107 this.vExpressionScriptState = null;
3108 debug("[html] the source code length: %d", text.length);
3109 this.text = text;
3110 this.gaps = [];
3111 this.lineTerminators = [];
3112 this.parserOptions = parserOptions || {};
3113 this.lastCodePoint = this.lastCodePointRaw = NULL;
3114 this.offset = -1;
3115 this.column = -1;
3116 this.line = 1;
3117 this.state = "DATA";
3118 this.returnState = "DATA";
3119 this.reconsuming = false;
3120 this.buffer = [];
3121 this.crStartOffset = -1;
3122 this.crCode = 0;
3123 this.errors = [];
3124 this.committedToken = null;
3125 this.provisionalToken = null;
3126 this.currentToken = null;
3127 this.lastTagOpenToken = null;
3128 this.tokenStartOffset = -1;
3129 this.tokenStartColumn = -1;
3130 this.tokenStartLine = 1;
3131 this.namespace = NS.HTML;
3132 this.expressionEnabled = false;
3133 }
3134 nextToken() {
3135 let cp = this.lastCodePoint;
3136 while (this.committedToken == null &&
3137 (cp !== EOF || this.reconsuming)) {
3138 if (this.provisionalToken != null && !this.isProvisionalState()) {
3139 this.commitProvisionalToken();
3140 if (this.committedToken != null) {
3141 break;
3142 }
3143 }
3144 if (this.reconsuming) {
3145 this.reconsuming = false;
3146 cp = this.lastCodePoint;
3147 }
3148 else {
3149 cp = this.consumeNextCodePoint();
3150 }
3151 debug("[html] parse", cp, this.state);
3152 this.state = this[this.state](cp);
3153 }
3154 {
3155 const token = this.consumeCommittedToken();
3156 if (token != null) {
3157 return token;
3158 }
3159 }
3160 assert__default["default"](cp === EOF);
3161 if (this.currentToken != null) {
3162 this.endToken();
3163 const token = this.consumeCommittedToken();
3164 if (token != null) {
3165 return token;
3166 }
3167 }
3168 return this.currentToken;
3169 }
3170 consumeCommittedToken() {
3171 const token = this.committedToken;
3172 this.committedToken = null;
3173 return token;
3174 }
3175 consumeNextCodePoint() {
3176 if (this.offset >= this.text.length) {
3177 this.lastCodePoint = this.lastCodePointRaw = EOF;
3178 return EOF;
3179 }
3180 this.offset += this.lastCodePoint >= 0x10000 ? 2 : 1;
3181 if (this.offset >= this.text.length) {
3182 this.advanceLocation();
3183 this.lastCodePoint = this.lastCodePointRaw = EOF;
3184 return EOF;
3185 }
3186 const cp = this.text.codePointAt(this.offset);
3187 if (isSurrogate(this.text.charCodeAt(this.offset)) &&
3188 !isSurrogatePair(this.text.charCodeAt(this.offset + 1))) {
3189 this.reportParseError("surrogate-in-input-stream");
3190 }
3191 if (isNonCharacter(cp)) {
3192 this.reportParseError("noncharacter-in-input-stream");
3193 }
3194 if (isControl(cp) && !isWhitespace(cp) && cp !== NULL) {
3195 this.reportParseError("control-character-in-input-stream");
3196 }
3197 if (this.lastCodePointRaw === CARRIAGE_RETURN && cp === LINE_FEED) {
3198 this.lastCodePoint = this.lastCodePointRaw = LINE_FEED;
3199 this.gaps.push(this.offset);
3200 return this.consumeNextCodePoint();
3201 }
3202 this.advanceLocation();
3203 this.lastCodePoint = this.lastCodePointRaw = cp;
3204 if (cp === CARRIAGE_RETURN) {
3205 this.lastCodePoint = LINE_FEED;
3206 return LINE_FEED;
3207 }
3208 return cp;
3209 }
3210 advanceLocation() {
3211 if (this.lastCodePointRaw === LINE_FEED) {
3212 this.lineTerminators.push(this.offset);
3213 this.line += 1;
3214 this.column = 0;
3215 }
3216 else {
3217 this.column += this.lastCodePoint >= 0x10000 ? 2 : 1;
3218 }
3219 }
3220 reconsumeAs(state) {
3221 this.reconsuming = true;
3222 return state;
3223 }
3224 reportParseError(code) {
3225 const error = ParseError.fromCode(code, this.offset, this.line, this.column);
3226 this.errors.push(error);
3227 debug("[html] syntax error:", error.message);
3228 }
3229 setStartTokenMark() {
3230 this.tokenStartOffset = this.offset;
3231 this.tokenStartLine = this.line;
3232 this.tokenStartColumn = this.column;
3233 }
3234 clearStartTokenMark() {
3235 this.tokenStartOffset = -1;
3236 }
3237 startToken(type) {
3238 if (this.tokenStartOffset === -1) {
3239 this.setStartTokenMark();
3240 }
3241 const offset = this.tokenStartOffset;
3242 const line = this.tokenStartLine;
3243 const column = this.tokenStartColumn;
3244 if (this.currentToken != null) {
3245 this.endToken();
3246 }
3247 this.tokenStartOffset = -1;
3248 const token = (this.currentToken = {
3249 type,
3250 range: [offset, -1],
3251 loc: {
3252 start: { line, column },
3253 end: { line: -1, column: -1 },
3254 },
3255 value: "",
3256 });
3257 debug("[html] start token: %d %s", offset, token.type);
3258 return this.currentToken;
3259 }
3260 endToken() {
3261 if (this.currentToken == null) {
3262 throw new Error("Invalid state");
3263 }
3264 if (this.tokenStartOffset === -1) {
3265 this.setStartTokenMark();
3266 }
3267 const token = this.currentToken;
3268 const offset = this.tokenStartOffset;
3269 const line = this.tokenStartLine;
3270 const column = this.tokenStartColumn;
3271 const provisional = this.isProvisionalState();
3272 this.currentToken = null;
3273 this.tokenStartOffset = -1;
3274 token.range[1] = offset;
3275 token.loc.end.line = line;
3276 token.loc.end.column = column;
3277 if (token.range[0] === offset && !provisional) {
3278 debug("[html] abandon token: %j %s %j", token.range, token.type, token.value);
3279 return null;
3280 }
3281 if (provisional) {
3282 if (this.provisionalToken != null) {
3283 this.commitProvisionalToken();
3284 }
3285 this.provisionalToken = token;
3286 debug("[html] provisional-commit token: %j %s %j", token.range, token.type, token.value);
3287 }
3288 else {
3289 this.commitToken(token);
3290 }
3291 return token;
3292 }
3293 commitToken(token) {
3294 assert__default["default"](this.committedToken == null, "Invalid state: the commited token existed already.");
3295 debug("[html] commit token: %j %j %s %j", token.range, token.loc, token.type, token.value);
3296 this.committedToken = token;
3297 if (token.type === "HTMLTagOpen") {
3298 this.lastTagOpenToken = token;
3299 }
3300 }
3301 isProvisionalState() {
3302 return (this.state.startsWith("RCDATA_") ||
3303 this.state.startsWith("RAWTEXT_"));
3304 }
3305 commitProvisionalToken() {
3306 assert__default["default"](this.provisionalToken != null, "Invalid state: the provisional token was not found.");
3307 const token = this.provisionalToken;
3308 this.provisionalToken = null;
3309 if (token.range[0] < token.range[1]) {
3310 this.commitToken(token);
3311 }
3312 }
3313 rollbackProvisionalToken() {
3314 assert__default["default"](this.currentToken != null);
3315 assert__default["default"](this.provisionalToken != null);
3316 const token = this.currentToken;
3317 debug("[html] rollback token: %d %s", token.range[0], token.type);
3318 this.currentToken = this.provisionalToken;
3319 this.provisionalToken = null;
3320 }
3321 appendTokenValue(cp, expected) {
3322 const token = this.currentToken;
3323 if (token == null || (expected != null && token.type !== expected)) {
3324 const msg1 = expected ? `"${expected}" type` : "any token";
3325 const msg2 = token ? `"${token.type}" type` : "no token";
3326 throw new Error(`Tokenizer: Invalid state. Expected ${msg1}, but got ${msg2}.`);
3327 }
3328 token.value += String.fromCodePoint(cp);
3329 }
3330 isAppropriateEndTagOpen() {
3331 return (this.currentToken != null &&
3332 this.lastTagOpenToken != null &&
3333 this.currentToken.type === "HTMLEndTagOpen" &&
3334 this.currentToken.value === this.lastTagOpenToken.value);
3335 }
3336 DATA(cp) {
3337 this.clearStartTokenMark();
3338 while (true) {
3339 const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLText";
3340 if (this.currentToken != null && this.currentToken.type !== type) {
3341 this.endToken();
3342 return this.reconsumeAs(this.state);
3343 }
3344 if (this.currentToken == null) {
3345 this.startToken(type);
3346 }
3347 if (cp === AMPERSAND) {
3348 this.returnState = "DATA";
3349 return "CHARACTER_REFERENCE";
3350 }
3351 if (cp === LESS_THAN_SIGN) {
3352 this.setStartTokenMark();
3353 return "TAG_OPEN";
3354 }
3355 if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
3356 this.setStartTokenMark();
3357 this.returnState = "DATA";
3358 return "V_EXPRESSION_START";
3359 }
3360 if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
3361 this.setStartTokenMark();
3362 this.returnState = "DATA";
3363 return "V_EXPRESSION_END";
3364 }
3365 if (cp === EOF) {
3366 return "DATA";
3367 }
3368 if (cp === NULL) {
3369 this.reportParseError("unexpected-null-character");
3370 }
3371 this.appendTokenValue(cp, type);
3372 cp = this.consumeNextCodePoint();
3373 }
3374 }
3375 RCDATA(cp) {
3376 this.clearStartTokenMark();
3377 while (true) {
3378 const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRCDataText";
3379 if (this.currentToken != null && this.currentToken.type !== type) {
3380 this.endToken();
3381 return this.reconsumeAs(this.state);
3382 }
3383 if (this.currentToken == null) {
3384 this.startToken(type);
3385 }
3386 if (cp === AMPERSAND) {
3387 this.returnState = "RCDATA";
3388 return "CHARACTER_REFERENCE";
3389 }
3390 if (cp === LESS_THAN_SIGN) {
3391 this.setStartTokenMark();
3392 return "RCDATA_LESS_THAN_SIGN";
3393 }
3394 if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
3395 this.setStartTokenMark();
3396 this.returnState = "RCDATA";
3397 return "V_EXPRESSION_START";
3398 }
3399 if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
3400 this.setStartTokenMark();
3401 this.returnState = "RCDATA";
3402 return "V_EXPRESSION_END";
3403 }
3404 if (cp === EOF) {
3405 return "DATA";
3406 }
3407 if (cp === NULL) {
3408 this.reportParseError("unexpected-null-character");
3409 cp = NULL_REPLACEMENT;
3410 }
3411 this.appendTokenValue(cp, type);
3412 cp = this.consumeNextCodePoint();
3413 }
3414 }
3415 RAWTEXT(cp) {
3416 this.clearStartTokenMark();
3417 while (true) {
3418 const type = isWhitespace(cp) ? "HTMLWhitespace" : "HTMLRawText";
3419 if (this.currentToken != null && this.currentToken.type !== type) {
3420 this.endToken();
3421 return this.reconsumeAs(this.state);
3422 }
3423 if (this.currentToken == null) {
3424 this.startToken(type);
3425 }
3426 if (cp === LESS_THAN_SIGN) {
3427 this.setStartTokenMark();
3428 return "RAWTEXT_LESS_THAN_SIGN";
3429 }
3430 if (cp === LEFT_CURLY_BRACKET && this.expressionEnabled) {
3431 this.setStartTokenMark();
3432 this.returnState = "RAWTEXT";
3433 return "V_EXPRESSION_START";
3434 }
3435 if (cp === RIGHT_CURLY_BRACKET && this.expressionEnabled) {
3436 this.setStartTokenMark();
3437 this.returnState = "RAWTEXT";
3438 return "V_EXPRESSION_END";
3439 }
3440 if (cp === EOF) {
3441 return "DATA";
3442 }
3443 if (cp === NULL) {
3444 this.reportParseError("unexpected-null-character");
3445 cp = NULL_REPLACEMENT;
3446 }
3447 this.appendTokenValue(cp, type);
3448 cp = this.consumeNextCodePoint();
3449 }
3450 }
3451 TAG_OPEN(cp) {
3452 if (cp === EXCLAMATION_MARK) {
3453 return "MARKUP_DECLARATION_OPEN";
3454 }
3455 if (cp === SOLIDUS) {
3456 return "END_TAG_OPEN";
3457 }
3458 if (isLetter(cp)) {
3459 this.startToken("HTMLTagOpen");
3460 return this.reconsumeAs("TAG_NAME");
3461 }
3462 if (cp === QUESTION_MARK) {
3463 this.reportParseError("unexpected-question-mark-instead-of-tag-name");
3464 this.startToken("HTMLBogusComment");
3465 return this.reconsumeAs("BOGUS_COMMENT");
3466 }
3467 if (cp === EOF) {
3468 this.clearStartTokenMark();
3469 this.reportParseError("eof-before-tag-name");
3470 this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
3471 return "DATA";
3472 }
3473 this.reportParseError("invalid-first-character-of-tag-name");
3474 this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
3475 return this.reconsumeAs("DATA");
3476 }
3477 END_TAG_OPEN(cp) {
3478 if (isLetter(cp)) {
3479 this.startToken("HTMLEndTagOpen");
3480 return this.reconsumeAs("TAG_NAME");
3481 }
3482 if (cp === GREATER_THAN_SIGN) {
3483 this.endToken();
3484 this.reportParseError("missing-end-tag-name");
3485 return "DATA";
3486 }
3487 if (cp === EOF) {
3488 this.clearStartTokenMark();
3489 this.reportParseError("eof-before-tag-name");
3490 this.appendTokenValue(LESS_THAN_SIGN, "HTMLText");
3491 this.appendTokenValue(SOLIDUS, "HTMLText");
3492 return "DATA";
3493 }
3494 this.reportParseError("invalid-first-character-of-tag-name");
3495 this.startToken("HTMLBogusComment");
3496 return this.reconsumeAs("BOGUS_COMMENT");
3497 }
3498 TAG_NAME(cp) {
3499 while (true) {
3500 if (isWhitespace(cp)) {
3501 this.endToken();
3502 return "BEFORE_ATTRIBUTE_NAME";
3503 }
3504 if (cp === SOLIDUS) {
3505 this.endToken();
3506 this.setStartTokenMark();
3507 return "SELF_CLOSING_START_TAG";
3508 }
3509 if (cp === GREATER_THAN_SIGN) {
3510 this.startToken("HTMLTagClose");
3511 return "DATA";
3512 }
3513 if (cp === EOF) {
3514 this.reportParseError("eof-in-tag");
3515 return "DATA";
3516 }
3517 if (cp === NULL) {
3518 this.reportParseError("unexpected-null-character");
3519 cp = NULL_REPLACEMENT;
3520 }
3521 this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, null);
3522 cp = this.consumeNextCodePoint();
3523 }
3524 }
3525 RCDATA_LESS_THAN_SIGN(cp) {
3526 if (cp === SOLIDUS) {
3527 this.buffer = [];
3528 return "RCDATA_END_TAG_OPEN";
3529 }
3530 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
3531 return this.reconsumeAs("RCDATA");
3532 }
3533 RCDATA_END_TAG_OPEN(cp) {
3534 if (isLetter(cp)) {
3535 this.startToken("HTMLEndTagOpen");
3536 return this.reconsumeAs("RCDATA_END_TAG_NAME");
3537 }
3538 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
3539 this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
3540 return this.reconsumeAs("RCDATA");
3541 }
3542 RCDATA_END_TAG_NAME(cp) {
3543 while (true) {
3544 if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
3545 this.endToken();
3546 return "BEFORE_ATTRIBUTE_NAME";
3547 }
3548 if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
3549 this.endToken();
3550 this.setStartTokenMark();
3551 return "SELF_CLOSING_START_TAG";
3552 }
3553 if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
3554 this.startToken("HTMLTagClose");
3555 return "DATA";
3556 }
3557 if (!isLetter(cp)) {
3558 this.rollbackProvisionalToken();
3559 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRCDataText");
3560 this.appendTokenValue(SOLIDUS, "HTMLRCDataText");
3561 for (const cp1 of this.buffer) {
3562 this.appendTokenValue(cp1, "HTMLRCDataText");
3563 }
3564 return this.reconsumeAs("RCDATA");
3565 }
3566 this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
3567 this.buffer.push(cp);
3568 cp = this.consumeNextCodePoint();
3569 }
3570 }
3571 RAWTEXT_LESS_THAN_SIGN(cp) {
3572 if (cp === SOLIDUS) {
3573 this.buffer = [];
3574 return "RAWTEXT_END_TAG_OPEN";
3575 }
3576 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
3577 return this.reconsumeAs("RAWTEXT");
3578 }
3579 RAWTEXT_END_TAG_OPEN(cp) {
3580 if (isLetter(cp)) {
3581 this.startToken("HTMLEndTagOpen");
3582 return this.reconsumeAs("RAWTEXT_END_TAG_NAME");
3583 }
3584 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
3585 this.appendTokenValue(SOLIDUS, "HTMLRawText");
3586 return this.reconsumeAs("RAWTEXT");
3587 }
3588 RAWTEXT_END_TAG_NAME(cp) {
3589 while (true) {
3590 if (cp === SOLIDUS && this.isAppropriateEndTagOpen()) {
3591 this.endToken();
3592 this.setStartTokenMark();
3593 return "SELF_CLOSING_START_TAG";
3594 }
3595 if (cp === GREATER_THAN_SIGN && this.isAppropriateEndTagOpen()) {
3596 this.startToken("HTMLTagClose");
3597 return "DATA";
3598 }
3599 if (isWhitespace(cp) && this.isAppropriateEndTagOpen()) {
3600 this.endToken();
3601 return "BEFORE_ATTRIBUTE_NAME";
3602 }
3603 if (!isLetter(cp) && !maybeValidCustomBlock.call(this, cp)) {
3604 this.rollbackProvisionalToken();
3605 this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText");
3606 this.appendTokenValue(SOLIDUS, "HTMLRawText");
3607 for (const cp1 of this.buffer) {
3608 this.appendTokenValue(cp1, "HTMLRawText");
3609 }
3610 return this.reconsumeAs("RAWTEXT");
3611 }
3612 this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLEndTagOpen");
3613 this.buffer.push(cp);
3614 cp = this.consumeNextCodePoint();
3615 }
3616 function maybeValidCustomBlock(nextCp) {
3617 return (this.currentToken &&
3618 this.lastTagOpenToken &&
3619 this.lastTagOpenToken.value.startsWith(this.currentToken.value + String.fromCodePoint(nextCp)));
3620 }
3621 }
3622 BEFORE_ATTRIBUTE_NAME(cp) {
3623 while (isWhitespace(cp)) {
3624 cp = this.consumeNextCodePoint();
3625 }
3626 if (cp === SOLIDUS || cp === GREATER_THAN_SIGN || cp === EOF) {
3627 return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
3628 }
3629 if (cp === EQUALS_SIGN) {
3630 this.reportParseError("unexpected-equals-sign-before-attribute-name");
3631 this.startToken("HTMLIdentifier");
3632 this.appendTokenValue(cp, "HTMLIdentifier");
3633 return "ATTRIBUTE_NAME";
3634 }
3635 this.startToken("HTMLIdentifier");
3636 return this.reconsumeAs("ATTRIBUTE_NAME");
3637 }
3638 ATTRIBUTE_NAME(cp) {
3639 while (true) {
3640 if (isWhitespace(cp) ||
3641 cp === SOLIDUS ||
3642 cp === GREATER_THAN_SIGN ||
3643 cp === EOF) {
3644 this.endToken();
3645 return this.reconsumeAs("AFTER_ATTRIBUTE_NAME");
3646 }
3647 if (cp === EQUALS_SIGN) {
3648 this.startToken("HTMLAssociation");
3649 return "BEFORE_ATTRIBUTE_VALUE";
3650 }
3651 if (cp === NULL) {
3652 this.reportParseError("unexpected-null-character");
3653 cp = NULL_REPLACEMENT;
3654 }
3655 if (cp === QUOTATION_MARK ||
3656 cp === APOSTROPHE ||
3657 cp === LESS_THAN_SIGN) {
3658 this.reportParseError("unexpected-character-in-attribute-name");
3659 }
3660 this.appendTokenValue(isUpperLetter(cp) ? toLowerCodePoint(cp) : cp, "HTMLIdentifier");
3661 cp = this.consumeNextCodePoint();
3662 }
3663 }
3664 AFTER_ATTRIBUTE_NAME(cp) {
3665 while (isWhitespace(cp)) {
3666 cp = this.consumeNextCodePoint();
3667 }
3668 if (cp === SOLIDUS) {
3669 this.setStartTokenMark();
3670 return "SELF_CLOSING_START_TAG";
3671 }
3672 if (cp === EQUALS_SIGN) {
3673 this.startToken("HTMLAssociation");
3674 return "BEFORE_ATTRIBUTE_VALUE";
3675 }
3676 if (cp === GREATER_THAN_SIGN) {
3677 this.startToken("HTMLTagClose");
3678 return "DATA";
3679 }
3680 if (cp === EOF) {
3681 this.reportParseError("eof-in-tag");
3682 return "DATA";
3683 }
3684 this.startToken("HTMLIdentifier");
3685 return this.reconsumeAs("ATTRIBUTE_NAME");
3686 }
3687 BEFORE_ATTRIBUTE_VALUE(cp) {
3688 this.endToken();
3689 while (isWhitespace(cp)) {
3690 cp = this.consumeNextCodePoint();
3691 }
3692 if (cp === GREATER_THAN_SIGN) {
3693 this.reportParseError("missing-attribute-value");
3694 this.startToken("HTMLTagClose");
3695 return "DATA";
3696 }
3697 this.startToken("HTMLLiteral");
3698 if (cp === QUOTATION_MARK) {
3699 return "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
3700 }
3701 if (cp === APOSTROPHE) {
3702 return "ATTRIBUTE_VALUE_SINGLE_QUOTED";
3703 }
3704 return this.reconsumeAs("ATTRIBUTE_VALUE_UNQUOTED");
3705 }
3706 ATTRIBUTE_VALUE_DOUBLE_QUOTED(cp) {
3707 while (true) {
3708 if (cp === QUOTATION_MARK) {
3709 return "AFTER_ATTRIBUTE_VALUE_QUOTED";
3710 }
3711 if (cp === AMPERSAND) {
3712 this.returnState = "ATTRIBUTE_VALUE_DOUBLE_QUOTED";
3713 return "CHARACTER_REFERENCE";
3714 }
3715 if (cp === NULL) {
3716 this.reportParseError("unexpected-null-character");
3717 cp = NULL_REPLACEMENT;
3718 }
3719 if (cp === EOF) {
3720 this.reportParseError("eof-in-tag");
3721 return "DATA";
3722 }
3723 this.appendTokenValue(cp, "HTMLLiteral");
3724 cp = this.consumeNextCodePoint();
3725 }
3726 }
3727 ATTRIBUTE_VALUE_SINGLE_QUOTED(cp) {
3728 while (true) {
3729 if (cp === APOSTROPHE) {
3730 return "AFTER_ATTRIBUTE_VALUE_QUOTED";
3731 }
3732 if (cp === AMPERSAND) {
3733 this.returnState = "ATTRIBUTE_VALUE_SINGLE_QUOTED";
3734 return "CHARACTER_REFERENCE";
3735 }
3736 if (cp === NULL) {
3737 this.reportParseError("unexpected-null-character");
3738 cp = NULL_REPLACEMENT;
3739 }
3740 if (cp === EOF) {
3741 this.reportParseError("eof-in-tag");
3742 return "DATA";
3743 }
3744 this.appendTokenValue(cp, "HTMLLiteral");
3745 cp = this.consumeNextCodePoint();
3746 }
3747 }
3748 ATTRIBUTE_VALUE_UNQUOTED(cp) {
3749 while (true) {
3750 if (isWhitespace(cp)) {
3751 this.endToken();
3752 return "BEFORE_ATTRIBUTE_NAME";
3753 }
3754 if (cp === AMPERSAND) {
3755 this.returnState = "ATTRIBUTE_VALUE_UNQUOTED";
3756 return "CHARACTER_REFERENCE";
3757 }
3758 if (cp === GREATER_THAN_SIGN) {
3759 this.startToken("HTMLTagClose");
3760 return "DATA";
3761 }
3762 if (cp === NULL) {
3763 this.reportParseError("unexpected-null-character");
3764 cp = NULL_REPLACEMENT;
3765 }
3766 if (cp === QUOTATION_MARK ||
3767 cp === APOSTROPHE ||
3768 cp === LESS_THAN_SIGN ||
3769 cp === EQUALS_SIGN ||
3770 cp === GRAVE_ACCENT) {
3771 this.reportParseError("unexpected-character-in-unquoted-attribute-value");
3772 }
3773 if (cp === EOF) {
3774 this.reportParseError("eof-in-tag");
3775 return "DATA";
3776 }
3777 this.appendTokenValue(cp, "HTMLLiteral");
3778 cp = this.consumeNextCodePoint();
3779 }
3780 }
3781 AFTER_ATTRIBUTE_VALUE_QUOTED(cp) {
3782 this.endToken();
3783 if (isWhitespace(cp)) {
3784 return "BEFORE_ATTRIBUTE_NAME";
3785 }
3786 if (cp === SOLIDUS) {
3787 this.setStartTokenMark();
3788 return "SELF_CLOSING_START_TAG";
3789 }
3790 if (cp === GREATER_THAN_SIGN) {
3791 this.startToken("HTMLTagClose");
3792 return "DATA";
3793 }
3794 if (cp === EOF) {
3795 this.reportParseError("eof-in-tag");
3796 return "DATA";
3797 }
3798 this.reportParseError("missing-whitespace-between-attributes");
3799 return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
3800 }
3801 SELF_CLOSING_START_TAG(cp) {
3802 if (cp === GREATER_THAN_SIGN) {
3803 this.startToken("HTMLSelfClosingTagClose");
3804 return "DATA";
3805 }
3806 if (cp === EOF) {
3807 this.reportParseError("eof-in-tag");
3808 return "DATA";
3809 }
3810 this.reportParseError("unexpected-solidus-in-tag");
3811 this.clearStartTokenMark();
3812 return this.reconsumeAs("BEFORE_ATTRIBUTE_NAME");
3813 }
3814 BOGUS_COMMENT(cp) {
3815 while (true) {
3816 if (cp === GREATER_THAN_SIGN) {
3817 return "DATA";
3818 }
3819 if (cp === EOF) {
3820 return "DATA";
3821 }
3822 if (cp === NULL) {
3823 cp = NULL_REPLACEMENT;
3824 }
3825 this.appendTokenValue(cp, null);
3826 cp = this.consumeNextCodePoint();
3827 }
3828 }
3829 MARKUP_DECLARATION_OPEN(cp) {
3830 if (cp === HYPHEN_MINUS && this.text[this.offset + 1] === "-") {
3831 this.offset += 1;
3832 this.column += 1;
3833 this.startToken("HTMLComment");
3834 return "COMMENT_START";
3835 }
3836 if (cp === LATIN_CAPITAL_D &&
3837 this.text.slice(this.offset + 1, this.offset + 7) === "OCTYPE") {
3838 this.startToken("HTMLBogusComment");
3839 this.appendTokenValue(cp, "HTMLBogusComment");
3840 return "BOGUS_COMMENT";
3841 }
3842 if (cp === LEFT_SQUARE_BRACKET &&
3843 this.text.slice(this.offset + 1, this.offset + 7) === "CDATA[") {
3844 this.offset += 6;
3845 this.column += 6;
3846 if (this.namespace === NS.HTML) {
3847 this.reportParseError("cdata-in-html-content");
3848 this.startToken("HTMLBogusComment").value = "[CDATA[";
3849 return "BOGUS_COMMENT";
3850 }
3851 this.startToken("HTMLCDataText");
3852 return "CDATA_SECTION";
3853 }
3854 this.reportParseError("incorrectly-opened-comment");
3855 this.startToken("HTMLBogusComment");
3856 return this.reconsumeAs("BOGUS_COMMENT");
3857 }
3858 COMMENT_START(cp) {
3859 if (cp === HYPHEN_MINUS) {
3860 return "COMMENT_START_DASH";
3861 }
3862 if (cp === GREATER_THAN_SIGN) {
3863 this.reportParseError("abrupt-closing-of-empty-comment");
3864 return "DATA";
3865 }
3866 return this.reconsumeAs("COMMENT");
3867 }
3868 COMMENT_START_DASH(cp) {
3869 if (cp === HYPHEN_MINUS) {
3870 return "COMMENT_END";
3871 }
3872 if (cp === GREATER_THAN_SIGN) {
3873 this.reportParseError("abrupt-closing-of-empty-comment");
3874 return "DATA";
3875 }
3876 if (cp === EOF) {
3877 this.reportParseError("eof-in-comment");
3878 return "DATA";
3879 }
3880 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3881 return this.reconsumeAs("COMMENT");
3882 }
3883 COMMENT(cp) {
3884 while (true) {
3885 if (cp === LESS_THAN_SIGN) {
3886 this.appendTokenValue(LESS_THAN_SIGN, "HTMLComment");
3887 return "COMMENT_LESS_THAN_SIGN";
3888 }
3889 if (cp === HYPHEN_MINUS) {
3890 return "COMMENT_END_DASH";
3891 }
3892 if (cp === NULL) {
3893 this.reportParseError("unexpected-null-character");
3894 cp = NULL_REPLACEMENT;
3895 }
3896 if (cp === EOF) {
3897 this.reportParseError("eof-in-comment");
3898 return "DATA";
3899 }
3900 this.appendTokenValue(cp, "HTMLComment");
3901 cp = this.consumeNextCodePoint();
3902 }
3903 }
3904 COMMENT_LESS_THAN_SIGN(cp) {
3905 while (true) {
3906 if (cp === EXCLAMATION_MARK) {
3907 this.appendTokenValue(cp, "HTMLComment");
3908 return "COMMENT_LESS_THAN_SIGN_BANG";
3909 }
3910 if (cp !== LESS_THAN_SIGN) {
3911 return this.reconsumeAs("COMMENT");
3912 }
3913 this.appendTokenValue(cp, "HTMLComment");
3914 cp = this.consumeNextCodePoint();
3915 }
3916 }
3917 COMMENT_LESS_THAN_SIGN_BANG(cp) {
3918 if (cp === HYPHEN_MINUS) {
3919 return "COMMENT_LESS_THAN_SIGN_BANG_DASH";
3920 }
3921 return this.reconsumeAs("COMMENT");
3922 }
3923 COMMENT_LESS_THAN_SIGN_BANG_DASH(cp) {
3924 if (cp === HYPHEN_MINUS) {
3925 return "COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH";
3926 }
3927 return this.reconsumeAs("COMMENT_END_DASH");
3928 }
3929 COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH(cp) {
3930 if (cp !== GREATER_THAN_SIGN && cp !== EOF) {
3931 this.reportParseError("nested-comment");
3932 }
3933 return this.reconsumeAs("COMMENT_END");
3934 }
3935 COMMENT_END_DASH(cp) {
3936 if (cp === HYPHEN_MINUS) {
3937 return "COMMENT_END";
3938 }
3939 if (cp === EOF) {
3940 this.reportParseError("eof-in-comment");
3941 return "DATA";
3942 }
3943 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3944 return this.reconsumeAs("COMMENT");
3945 }
3946 COMMENT_END(cp) {
3947 while (true) {
3948 if (cp === GREATER_THAN_SIGN) {
3949 return "DATA";
3950 }
3951 if (cp === EXCLAMATION_MARK) {
3952 return "COMMENT_END_BANG";
3953 }
3954 if (cp === EOF) {
3955 this.reportParseError("eof-in-comment");
3956 return "DATA";
3957 }
3958 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3959 if (cp !== HYPHEN_MINUS) {
3960 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3961 return this.reconsumeAs("COMMENT");
3962 }
3963 cp = this.consumeNextCodePoint();
3964 }
3965 }
3966 COMMENT_END_BANG(cp) {
3967 if (cp === HYPHEN_MINUS) {
3968 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3969 this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
3970 return "COMMENT_END_DASH";
3971 }
3972 if (cp === GREATER_THAN_SIGN) {
3973 this.reportParseError("incorrectly-closed-comment");
3974 return "DATA";
3975 }
3976 if (cp === EOF) {
3977 this.reportParseError("eof-in-comment");
3978 return "DATA";
3979 }
3980 this.appendTokenValue(HYPHEN_MINUS, "HTMLComment");
3981 this.appendTokenValue(EXCLAMATION_MARK, "HTMLComment");
3982 return this.reconsumeAs("COMMENT");
3983 }
3984 CDATA_SECTION(cp) {
3985 while (true) {
3986 if (cp === RIGHT_SQUARE_BRACKET) {
3987 return "CDATA_SECTION_BRACKET";
3988 }
3989 if (cp === EOF) {
3990 this.reportParseError("eof-in-cdata");
3991 return "DATA";
3992 }
3993 this.appendTokenValue(cp, "HTMLCDataText");
3994 cp = this.consumeNextCodePoint();
3995 }
3996 }
3997 CDATA_SECTION_BRACKET(cp) {
3998 if (cp === RIGHT_SQUARE_BRACKET) {
3999 return "CDATA_SECTION_END";
4000 }
4001 this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
4002 return this.reconsumeAs("CDATA_SECTION");
4003 }
4004 CDATA_SECTION_END(cp) {
4005 while (true) {
4006 if (cp === GREATER_THAN_SIGN) {
4007 return "DATA";
4008 }
4009 if (cp !== RIGHT_SQUARE_BRACKET) {
4010 this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
4011 this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
4012 return this.reconsumeAs("CDATA_SECTION");
4013 }
4014 this.appendTokenValue(RIGHT_SQUARE_BRACKET, "HTMLCDataText");
4015 cp = this.consumeNextCodePoint();
4016 }
4017 }
4018 CHARACTER_REFERENCE(cp) {
4019 this.crStartOffset = this.offset - 1;
4020 this.buffer = [AMPERSAND];
4021 if (isDigit(cp) || isLetter(cp)) {
4022 return this.reconsumeAs("NAMED_CHARACTER_REFERENCE");
4023 }
4024 if (cp === NUMBER_SIGN) {
4025 this.buffer.push(cp);
4026 return "NUMERIC_CHARACTER_REFERENCE";
4027 }
4028 return this.reconsumeAs("CHARACTER_REFERENCE_END");
4029 }
4030 NAMED_CHARACTER_REFERENCE(cp) {
4031 for (const entitySet of entitySets) {
4032 const length = entitySet.length;
4033 const entities = entitySet.entities;
4034 const text = this.text.slice(this.offset, this.offset + length);
4035 const codepoints = entities[text];
4036 if (codepoints == null) {
4037 continue;
4038 }
4039 const semi = text.endsWith(";");
4040 const next = this.text.codePointAt(this.offset + 1);
4041 this.offset += length - 1;
4042 this.column += length - 1;
4043 if (this.returnState.startsWith("ATTR") &&
4044 !semi &&
4045 next != null &&
4046 (next === EQUALS_SIGN || isLetter(next) || isDigit(next))) {
4047 for (const cp1 of text) {
4048 this.buffer.push(cp1.codePointAt(0));
4049 }
4050 }
4051 else {
4052 if (!semi) {
4053 this.reportParseError("missing-semicolon-after-character-reference");
4054 }
4055 this.buffer = codepoints;
4056 }
4057 return "CHARACTER_REFERENCE_END";
4058 }
4059 for (const cp0 of this.buffer) {
4060 this.appendTokenValue(cp0, null);
4061 }
4062 this.appendTokenValue(cp, null);
4063 return "AMBIGUOUS_AMPERSAND";
4064 }
4065 AMBIGUOUS_AMPERSAND(cp) {
4066 while (isDigit(cp) || isLetter(cp)) {
4067 this.appendTokenValue(cp, null);
4068 cp = this.consumeNextCodePoint();
4069 }
4070 if (cp === SEMICOLON) {
4071 this.reportParseError("unknown-named-character-reference");
4072 }
4073 return this.reconsumeAs(this.returnState);
4074 }
4075 NUMERIC_CHARACTER_REFERENCE(cp) {
4076 this.crCode = 0;
4077 if (cp === LATIN_SMALL_X || cp === LATIN_CAPITAL_X) {
4078 this.buffer.push(cp);
4079 return "HEXADEMICAL_CHARACTER_REFERENCE_START";
4080 }
4081 return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE_START");
4082 }
4083 HEXADEMICAL_CHARACTER_REFERENCE_START(cp) {
4084 if (isHexDigit(cp)) {
4085 return this.reconsumeAs("HEXADEMICAL_CHARACTER_REFERENCE");
4086 }
4087 this.reportParseError("absence-of-digits-in-numeric-character-reference");
4088 return this.reconsumeAs("CHARACTER_REFERENCE_END");
4089 }
4090 DECIMAL_CHARACTER_REFERENCE_START(cp) {
4091 if (isDigit(cp)) {
4092 return this.reconsumeAs("DECIMAL_CHARACTER_REFERENCE");
4093 }
4094 this.reportParseError("absence-of-digits-in-numeric-character-reference");
4095 return this.reconsumeAs("CHARACTER_REFERENCE_END");
4096 }
4097 HEXADEMICAL_CHARACTER_REFERENCE(cp) {
4098 while (true) {
4099 if (isDigit(cp)) {
4100 this.crCode = 16 * this.crCode + (cp - 0x30);
4101 }
4102 else if (isUpperHexDigit(cp)) {
4103 this.crCode = 16 * this.crCode + (cp - 0x37);
4104 }
4105 else if (isLowerHexDigit(cp)) {
4106 this.crCode = 16 * this.crCode + (cp - 0x57);
4107 }
4108 else {
4109 if (cp === SEMICOLON) {
4110 return "NUMERIC_CHARACTER_REFERENCE_END";
4111 }
4112 this.reportParseError("missing-semicolon-after-character-reference");
4113 return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
4114 }
4115 cp = this.consumeNextCodePoint();
4116 }
4117 }
4118 DECIMAL_CHARACTER_REFERENCE(cp) {
4119 while (true) {
4120 if (isDigit(cp)) {
4121 this.crCode = 10 * this.crCode + (cp - 0x30);
4122 }
4123 else {
4124 if (cp === SEMICOLON) {
4125 return "NUMERIC_CHARACTER_REFERENCE_END";
4126 }
4127 this.reportParseError("missing-semicolon-after-character-reference");
4128 return this.reconsumeAs("NUMERIC_CHARACTER_REFERENCE_END");
4129 }
4130 cp = this.consumeNextCodePoint();
4131 }
4132 }
4133 NUMERIC_CHARACTER_REFERENCE_END(_cp) {
4134 let code = this.crCode;
4135 if (code === 0) {
4136 this.reportParseError("null-character-reference");
4137 code = NULL_REPLACEMENT;
4138 }
4139 else if (code > 0x10ffff) {
4140 this.reportParseError("character-reference-outside-unicode-range");
4141 code = NULL_REPLACEMENT;
4142 }
4143 else if (isSurrogate(code)) {
4144 this.reportParseError("surrogate-character-reference");
4145 code = NULL_REPLACEMENT;
4146 }
4147 else if (isNonCharacter(code)) {
4148 this.reportParseError("noncharacter-character-reference");
4149 }
4150 else if (code === 0x0d || (isControl(code) && !isWhitespace(code))) {
4151 this.reportParseError("control-character-reference");
4152 code = alternativeCR.get(code) || code;
4153 }
4154 this.buffer = [code];
4155 return this.reconsumeAs("CHARACTER_REFERENCE_END");
4156 }
4157 CHARACTER_REFERENCE_END(_cp) {
4158 assert__default["default"](this.currentToken != null);
4159 const token = this.currentToken;
4160 const len0 = token.value.length;
4161 for (const cp1 of this.buffer) {
4162 this.appendTokenValue(cp1, null);
4163 }
4164 const newLength = token.value.length - len0;
4165 for (let i = this.crStartOffset + newLength; i < this.offset; ++i) {
4166 this.gaps.push(i);
4167 }
4168 return this.reconsumeAs(this.returnState);
4169 }
4170 V_EXPRESSION_START(cp) {
4171 var _a, _b;
4172 if (cp === LEFT_CURLY_BRACKET) {
4173 this.startToken("VExpressionStart");
4174 this.appendTokenValue(LEFT_CURLY_BRACKET, null);
4175 this.appendTokenValue(LEFT_CURLY_BRACKET, null);
4176 if (!((_b = (_a = this.parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.interpolationAsNonHTML) !== null && _b !== void 0 ? _b : true)) {
4177 return this.returnState;
4178 }
4179 const closeIndex = this.text.indexOf("}}", this.offset + 1);
4180 if (closeIndex === -1) {
4181 this.reportParseError("x-missing-interpolation-end");
4182 return this.returnState;
4183 }
4184 this.vExpressionScriptState = {
4185 state: this.returnState,
4186 };
4187 return "V_EXPRESSION_DATA";
4188 }
4189 this.appendTokenValue(LEFT_CURLY_BRACKET, null);
4190 return this.reconsumeAs(this.returnState);
4191 }
4192 V_EXPRESSION_DATA(cp) {
4193 this.clearStartTokenMark();
4194 const state = this.vExpressionScriptState.state;
4195 while (true) {
4196 const type = isWhitespace(cp)
4197 ? "HTMLWhitespace"
4198 : state === "RCDATA"
4199 ? "HTMLRawText"
4200 : state === "RAWTEXT"
4201 ? "HTMLRCDataText"
4202 : "HTMLText";
4203 if (this.currentToken != null && this.currentToken.type !== type) {
4204 this.endToken();
4205 return this.reconsumeAs(this.state);
4206 }
4207 if (this.currentToken == null) {
4208 this.startToken(type);
4209 }
4210 if (cp === AMPERSAND && state !== "RAWTEXT") {
4211 this.returnState = "V_EXPRESSION_DATA";
4212 return "CHARACTER_REFERENCE";
4213 }
4214 if (cp === RIGHT_CURLY_BRACKET) {
4215 this.setStartTokenMark();
4216 this.returnState = "V_EXPRESSION_DATA";
4217 return "V_EXPRESSION_END";
4218 }
4219 if (cp === EOF) {
4220 this.reportParseError("x-missing-interpolation-end");
4221 return "DATA";
4222 }
4223 if (cp === NULL) {
4224 this.reportParseError("unexpected-null-character");
4225 }
4226 this.appendTokenValue(cp, type);
4227 cp = this.consumeNextCodePoint();
4228 }
4229 }
4230 V_EXPRESSION_END(cp) {
4231 if (cp === RIGHT_CURLY_BRACKET) {
4232 this.startToken("VExpressionEnd");
4233 this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
4234 this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
4235 return this.vExpressionScriptState
4236 ? this.vExpressionScriptState.state
4237 : this.returnState;
4238 }
4239 this.appendTokenValue(RIGHT_CURLY_BRACKET, null);
4240 return this.reconsumeAs(this.returnState);
4241 }
4242}
4243
4244function getPossibleTypes(parsedSelector) {
4245 switch (parsedSelector.type) {
4246 case "identifier":
4247 return [parsedSelector.value];
4248 case "matches": {
4249 const typesForComponents = parsedSelector.selectors.map(getPossibleTypes);
4250 if (typesForComponents.every(Boolean)) {
4251 return union__default["default"](...typesForComponents);
4252 }
4253 return null;
4254 }
4255 case "compound": {
4256 const typesForComponents = parsedSelector.selectors.map(getPossibleTypes).filter(Boolean);
4257 if (!typesForComponents.length) {
4258 return null;
4259 }
4260 return intersection__default["default"](...typesForComponents);
4261 }
4262 case "child":
4263 case "descendant":
4264 case "sibling":
4265 case "adjacent":
4266 return getPossibleTypes(parsedSelector.right);
4267 default:
4268 return null;
4269 }
4270}
4271function countClassAttributes(parsedSelector) {
4272 switch (parsedSelector.type) {
4273 case "child":
4274 case "descendant":
4275 case "sibling":
4276 case "adjacent":
4277 return countClassAttributes(parsedSelector.left) + countClassAttributes(parsedSelector.right);
4278 case "compound":
4279 case "not":
4280 case "matches":
4281 return parsedSelector.selectors.reduce((sum, childSelector) => sum + countClassAttributes(childSelector), 0);
4282 case "attribute":
4283 case "field":
4284 case "nth-child":
4285 case "nth-last-child":
4286 return 1;
4287 default:
4288 return 0;
4289 }
4290}
4291function countIdentifiers(parsedSelector) {
4292 switch (parsedSelector.type) {
4293 case "child":
4294 case "descendant":
4295 case "sibling":
4296 case "adjacent":
4297 return countIdentifiers(parsedSelector.left) + countIdentifiers(parsedSelector.right);
4298 case "compound":
4299 case "not":
4300 case "matches":
4301 return parsedSelector.selectors.reduce((sum, childSelector) => sum + countIdentifiers(childSelector), 0);
4302 case "identifier":
4303 return 1;
4304 default:
4305 return 0;
4306 }
4307}
4308function compareSpecificity(selectorA, selectorB) {
4309 return selectorA.attributeCount - selectorB.attributeCount ||
4310 selectorA.identifierCount - selectorB.identifierCount ||
4311 (selectorA.rawSelector <= selectorB.rawSelector ? -1 : 1);
4312}
4313function tryParseSelector(rawSelector) {
4314 try {
4315 return esquery__default["default"].parse(rawSelector.replace(/:exit$/, ""));
4316 }
4317 catch (err) {
4318 if (typeof err.offset === "number") {
4319 throw new Error(`Syntax error in selector "${rawSelector}" at position ${err.offset}: ${err.message}`);
4320 }
4321 throw err;
4322 }
4323}
4324const parseSelector = memoize__default["default"](rawSelector => {
4325 const parsedSelector = tryParseSelector(rawSelector);
4326 return {
4327 rawSelector,
4328 isExit: rawSelector.endsWith(":exit"),
4329 parsedSelector,
4330 listenerTypes: getPossibleTypes(parsedSelector),
4331 attributeCount: countClassAttributes(parsedSelector),
4332 identifierCount: countIdentifiers(parsedSelector),
4333 };
4334});
4335class NodeEventGenerator {
4336 constructor(emitter, esqueryOptions) {
4337 this.emitter = emitter;
4338 this.esqueryOptions = esqueryOptions;
4339 this.currentAncestry = [];
4340 this.enterSelectorsByNodeType = new Map();
4341 this.exitSelectorsByNodeType = new Map();
4342 this.anyTypeEnterSelectors = [];
4343 this.anyTypeExitSelectors = [];
4344 const eventNames = typeof emitter.eventNames === "function"
4345 ? emitter.eventNames()
4346 : Object.keys(emitter._events);
4347 for (const rawSelector of eventNames) {
4348 if (typeof rawSelector === "symbol") {
4349 continue;
4350 }
4351 const selector = parseSelector(rawSelector);
4352 if (selector.listenerTypes) {
4353 for (const nodeType of selector.listenerTypes) {
4354 const typeMap = selector.isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType;
4355 let selectors = typeMap.get(nodeType);
4356 if (selectors == null) {
4357 typeMap.set(nodeType, (selectors = []));
4358 }
4359 selectors.push(selector);
4360 }
4361 }
4362 else {
4363 (selector.isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors).push(selector);
4364 }
4365 }
4366 this.anyTypeEnterSelectors.sort(compareSpecificity);
4367 this.anyTypeExitSelectors.sort(compareSpecificity);
4368 for (const selectorList of this.enterSelectorsByNodeType.values()) {
4369 selectorList.sort(compareSpecificity);
4370 }
4371 for (const selectorList of this.exitSelectorsByNodeType.values()) {
4372 selectorList.sort(compareSpecificity);
4373 }
4374 }
4375 applySelector(node, selector) {
4376 if (esquery__default["default"].matches(node, selector.parsedSelector, this.currentAncestry, this.esqueryOptions)) {
4377 this.emitter.emit(selector.rawSelector, node);
4378 }
4379 }
4380 applySelectors(node, isExit) {
4381 const selectorsByNodeType = (isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType).get(node.type) || [];
4382 const anyTypeSelectors = isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors;
4383 let selectorsByTypeIndex = 0;
4384 let anyTypeSelectorsIndex = 0;
4385 while (selectorsByTypeIndex < selectorsByNodeType.length || anyTypeSelectorsIndex < anyTypeSelectors.length) {
4386 if (selectorsByTypeIndex >= selectorsByNodeType.length ||
4387 (anyTypeSelectorsIndex < anyTypeSelectors.length && compareSpecificity(anyTypeSelectors[anyTypeSelectorsIndex], selectorsByNodeType[selectorsByTypeIndex]) < 0)) {
4388 this.applySelector(node, anyTypeSelectors[anyTypeSelectorsIndex++]);
4389 }
4390 else {
4391 this.applySelector(node, selectorsByNodeType[selectorsByTypeIndex++]);
4392 }
4393 }
4394 }
4395 enterNode(node) {
4396 if (node.parent) {
4397 this.currentAncestry.unshift(node.parent);
4398 }
4399 this.applySelectors(node, false);
4400 }
4401 leaveNode(node) {
4402 this.applySelectors(node, true);
4403 this.currentAncestry.shift();
4404 }
4405}
4406
4407function getStartLocation(token) {
4408 return token.range[0];
4409}
4410function search(tokens, location) {
4411 return sortedIndexBy__default["default"](tokens, { range: [location] }, getStartLocation);
4412}
4413function getFirstIndex(tokens, indexMap, startLoc) {
4414 if (startLoc in indexMap) {
4415 return indexMap[startLoc];
4416 }
4417 if ((startLoc - 1) in indexMap) {
4418 const index = indexMap[startLoc - 1];
4419 const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
4420 if (token && token.range[0] >= startLoc) {
4421 return index;
4422 }
4423 return index + 1;
4424 }
4425 return 0;
4426}
4427function getLastIndex(tokens, indexMap, endLoc) {
4428 if (endLoc in indexMap) {
4429 return indexMap[endLoc] - 1;
4430 }
4431 if ((endLoc - 1) in indexMap) {
4432 const index = indexMap[endLoc - 1];
4433 const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
4434 if (token && token.range[1] > endLoc) {
4435 return index - 1;
4436 }
4437 return index;
4438 }
4439 return tokens.length - 1;
4440}
4441
4442class Cursor {
4443 constructor() {
4444 this.current = null;
4445 }
4446 getOneToken() {
4447 return this.moveNext() ? this.current : null;
4448 }
4449 getAllTokens() {
4450 const tokens = [];
4451 while (this.moveNext()) {
4452 tokens.push(this.current);
4453 }
4454 return tokens;
4455 }
4456}
4457
4458class BackwardTokenCommentCursor extends Cursor {
4459 constructor(tokens, comments, indexMap, startLoc, endLoc) {
4460 super();
4461 this.tokens = tokens;
4462 this.comments = comments;
4463 this.tokenIndex = getLastIndex(tokens, indexMap, endLoc);
4464 this.commentIndex = search(comments, endLoc) - 1;
4465 this.border = startLoc;
4466 }
4467 moveNext() {
4468 const token = (this.tokenIndex >= 0) ? this.tokens[this.tokenIndex] : null;
4469 const comment = (this.commentIndex >= 0) ? this.comments[this.commentIndex] : null;
4470 if (token && (!comment || token.range[1] > comment.range[1])) {
4471 this.current = token;
4472 this.tokenIndex -= 1;
4473 }
4474 else if (comment) {
4475 this.current = comment;
4476 this.commentIndex -= 1;
4477 }
4478 else {
4479 this.current = null;
4480 }
4481 return this.current != null && (this.border === -1 || this.current.range[0] >= this.border);
4482 }
4483}
4484
4485class BackwardTokenCursor extends Cursor {
4486 constructor(tokens, _comments, indexMap, startLoc, endLoc) {
4487 super();
4488 this.tokens = tokens;
4489 this.index = getLastIndex(tokens, indexMap, endLoc);
4490 this.indexEnd = getFirstIndex(tokens, indexMap, startLoc);
4491 }
4492 moveNext() {
4493 if (this.index >= this.indexEnd) {
4494 this.current = this.tokens[this.index];
4495 this.index -= 1;
4496 return true;
4497 }
4498 return false;
4499 }
4500 getOneToken() {
4501 return (this.index >= this.indexEnd) ? this.tokens[this.index] : null;
4502 }
4503}
4504
4505class DecorativeCursor extends Cursor {
4506 constructor(cursor) {
4507 super();
4508 this.cursor = cursor;
4509 }
4510 moveNext() {
4511 const retv = this.cursor.moveNext();
4512 this.current = this.cursor.current;
4513 return retv;
4514 }
4515}
4516
4517class FilterCursor extends DecorativeCursor {
4518 constructor(cursor, predicate) {
4519 super(cursor);
4520 this.predicate = predicate;
4521 }
4522 moveNext() {
4523 const predicate = this.predicate;
4524 while (super.moveNext()) {
4525 if (predicate(this.current)) {
4526 return true;
4527 }
4528 }
4529 return false;
4530 }
4531}
4532
4533class ForwardTokenCommentCursor extends Cursor {
4534 constructor(tokens, comments, indexMap, startLoc, endLoc) {
4535 super();
4536 this.tokens = tokens;
4537 this.comments = comments;
4538 this.tokenIndex = getFirstIndex(tokens, indexMap, startLoc);
4539 this.commentIndex = search(comments, startLoc);
4540 this.border = endLoc;
4541 }
4542 moveNext() {
4543 const token = (this.tokenIndex < this.tokens.length) ? this.tokens[this.tokenIndex] : null;
4544 const comment = (this.commentIndex < this.comments.length) ? this.comments[this.commentIndex] : null;
4545 if (token && (!comment || token.range[0] < comment.range[0])) {
4546 this.current = token;
4547 this.tokenIndex += 1;
4548 }
4549 else if (comment) {
4550 this.current = comment;
4551 this.commentIndex += 1;
4552 }
4553 else {
4554 this.current = null;
4555 }
4556 return this.current != null && (this.border === -1 || this.current.range[1] <= this.border);
4557 }
4558}
4559
4560class ForwardTokenCursor extends Cursor {
4561 constructor(tokens, _comments, indexMap, startLoc, endLoc) {
4562 super();
4563 this.tokens = tokens;
4564 this.index = getFirstIndex(tokens, indexMap, startLoc);
4565 this.indexEnd = getLastIndex(tokens, indexMap, endLoc);
4566 }
4567 moveNext() {
4568 if (this.index <= this.indexEnd) {
4569 this.current = this.tokens[this.index];
4570 this.index += 1;
4571 return true;
4572 }
4573 return false;
4574 }
4575 getOneToken() {
4576 return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
4577 }
4578 getAllTokens() {
4579 return this.tokens.slice(this.index, this.indexEnd + 1);
4580 }
4581}
4582
4583class LimitCursor extends DecorativeCursor {
4584 constructor(cursor, count) {
4585 super(cursor);
4586 this.count = count;
4587 }
4588 moveNext() {
4589 if (this.count > 0) {
4590 this.count -= 1;
4591 return super.moveNext();
4592 }
4593 return false;
4594 }
4595}
4596
4597class SkipCursor extends DecorativeCursor {
4598 constructor(cursor, count) {
4599 super(cursor);
4600 this.count = count;
4601 }
4602 moveNext() {
4603 while (this.count > 0) {
4604 this.count -= 1;
4605 if (!super.moveNext()) {
4606 return false;
4607 }
4608 }
4609 return super.moveNext();
4610 }
4611}
4612
4613class CursorFactory {
4614 constructor(TokenCursor, TokenCommentCursor) {
4615 this.TokenCursor = TokenCursor;
4616 this.TokenCommentCursor = TokenCommentCursor;
4617 }
4618 createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
4619 const TokenCursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
4620 return new TokenCursor(tokens, comments, indexMap, startLoc, endLoc);
4621 }
4622 createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
4623 let cursor = this.createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments);
4624 if (filter) {
4625 cursor = new FilterCursor(cursor, filter);
4626 }
4627 if (skip >= 1) {
4628 cursor = new SkipCursor(cursor, skip);
4629 }
4630 if (count >= 0) {
4631 cursor = new LimitCursor(cursor, count);
4632 }
4633 return cursor;
4634 }
4635}
4636const forward = new CursorFactory(ForwardTokenCursor, ForwardTokenCommentCursor);
4637const backward = new CursorFactory(BackwardTokenCursor, BackwardTokenCommentCursor);
4638
4639class PaddedTokenCursor extends ForwardTokenCursor {
4640 constructor(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
4641 super(tokens, comments, indexMap, startLoc, endLoc);
4642 this.index = Math.max(0, this.index - beforeCount);
4643 this.indexEnd = Math.min(tokens.length - 1, this.indexEnd + afterCount);
4644 }
4645}
4646
4647function isCommentToken(token) {
4648 return token.type === "Line" || token.type === "Block" || token.type === "Shebang";
4649}
4650function createIndexMap(tokens, comments) {
4651 const map = Object.create(null);
4652 let tokenIndex = 0;
4653 let commentIndex = 0;
4654 let nextStart = 0;
4655 let range = null;
4656 while (tokenIndex < tokens.length || commentIndex < comments.length) {
4657 nextStart = (commentIndex < comments.length) ? comments[commentIndex].range[0] : Number.MAX_SAFE_INTEGER;
4658 while (tokenIndex < tokens.length && (range = tokens[tokenIndex].range)[0] < nextStart) {
4659 map[range[0]] = tokenIndex;
4660 map[range[1] - 1] = tokenIndex;
4661 tokenIndex += 1;
4662 }
4663 nextStart = (tokenIndex < tokens.length) ? tokens[tokenIndex].range[0] : Number.MAX_SAFE_INTEGER;
4664 while (commentIndex < comments.length && (range = comments[commentIndex].range)[0] < nextStart) {
4665 map[range[0]] = tokenIndex;
4666 map[range[1] - 1] = tokenIndex;
4667 commentIndex += 1;
4668 }
4669 }
4670 return map;
4671}
4672function createCursorWithSkip(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
4673 let includeComments = false;
4674 let skip = 0;
4675 let filter = null;
4676 if (typeof opts === "number") {
4677 skip = opts | 0;
4678 }
4679 else if (typeof opts === "function") {
4680 filter = opts;
4681 }
4682 else if (opts) {
4683 includeComments = Boolean(opts.includeComments);
4684 skip = opts.skip || 0;
4685 filter = opts.filter || null;
4686 }
4687 assert__default["default"](skip >= 0, "options.skip should be zero or a positive integer.");
4688 assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
4689 return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, -1);
4690}
4691function createCursorWithCount(factory, tokens, comments, indexMap, startLoc, endLoc, opts) {
4692 let includeComments = false;
4693 let count = 0;
4694 let countExists = false;
4695 let filter = null;
4696 if (typeof opts === "number") {
4697 count = opts | 0;
4698 countExists = true;
4699 }
4700 else if (typeof opts === "function") {
4701 filter = opts;
4702 }
4703 else if (opts) {
4704 includeComments = Boolean(opts.includeComments);
4705 count = opts.count || 0;
4706 countExists = typeof opts.count === "number";
4707 filter = opts.filter || null;
4708 }
4709 assert__default["default"](count >= 0, "options.count should be zero or a positive integer.");
4710 assert__default["default"](!filter || typeof filter === "function", "options.filter should be a function.");
4711 return factory.createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, 0, countExists ? count : -1);
4712}
4713function createCursorWithPadding(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
4714 if (typeof beforeCount === "undefined" && typeof afterCount === "undefined") {
4715 return new ForwardTokenCursor(tokens, comments, indexMap, startLoc, endLoc);
4716 }
4717 if (typeof beforeCount === "number" || typeof beforeCount === "undefined") {
4718 return new PaddedTokenCursor(tokens, comments, indexMap, startLoc, endLoc, beforeCount || 0, afterCount || 0);
4719 }
4720 return createCursorWithCount(forward, tokens, comments, indexMap, startLoc, endLoc, beforeCount);
4721}
4722function getAdjacentCommentTokensFromCursor(cursor) {
4723 const tokens = [];
4724 let currentToken = cursor.getOneToken();
4725 while (currentToken && isCommentToken(currentToken)) {
4726 tokens.push(currentToken);
4727 currentToken = cursor.getOneToken();
4728 }
4729 return tokens;
4730}
4731class TokenStore {
4732 constructor(tokens, comments) {
4733 this._tokens = tokens;
4734 this._comments = comments;
4735 this._indexMap = createIndexMap(tokens, comments);
4736 }
4737 getTokenByRangeStart(offset, options) {
4738 const includeComments = Boolean(options && options.includeComments);
4739 const token = forward.createBaseCursor(this._tokens, this._comments, this._indexMap, offset, -1, includeComments).getOneToken();
4740 if (token && token.range[0] === offset) {
4741 return token;
4742 }
4743 return null;
4744 }
4745 getFirstToken(node, options) {
4746 return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
4747 }
4748 getLastToken(node, options) {
4749 return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getOneToken();
4750 }
4751 getTokenBefore(node, options) {
4752 return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getOneToken();
4753 }
4754 getTokenAfter(node, options) {
4755 return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getOneToken();
4756 }
4757 getFirstTokenBetween(left, right, options) {
4758 return createCursorWithSkip(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
4759 }
4760 getLastTokenBetween(left, right, options) {
4761 return createCursorWithSkip(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getOneToken();
4762 }
4763 getTokenOrCommentBefore(node, skip) {
4764 return this.getTokenBefore(node, { includeComments: true, skip });
4765 }
4766 getTokenOrCommentAfter(node, skip) {
4767 return this.getTokenAfter(node, { includeComments: true, skip });
4768 }
4769 getFirstTokens(node, options) {
4770 return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens();
4771 }
4772 getLastTokens(node, options) {
4773 return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], options).getAllTokens().reverse();
4774 }
4775 getTokensBefore(node, options) {
4776 return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, node.range[0], options).getAllTokens().reverse();
4777 }
4778 getTokensAfter(node, options) {
4779 return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, node.range[1], -1, options).getAllTokens();
4780 }
4781 getFirstTokensBetween(left, right, options) {
4782 return createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens();
4783 }
4784 getLastTokensBetween(left, right, options) {
4785 return createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], options).getAllTokens().reverse();
4786 }
4787 getTokens(node, beforeCount, afterCount) {
4788 return createCursorWithPadding(this._tokens, this._comments, this._indexMap, node.range[0], node.range[1], beforeCount, afterCount).getAllTokens();
4789 }
4790 getTokensBetween(left, right, padding) {
4791 return createCursorWithPadding(this._tokens, this._comments, this._indexMap, left.range[1], right.range[0], padding, typeof padding === "number" ? padding : undefined).getAllTokens();
4792 }
4793 commentsExistBetween(left, right) {
4794 const index = search(this._comments, left.range[1]);
4795 return (index < this._comments.length &&
4796 this._comments[index].range[1] <= right.range[0]);
4797 }
4798 getCommentsBefore(nodeOrToken) {
4799 const cursor = createCursorWithCount(backward, this._tokens, this._comments, this._indexMap, -1, nodeOrToken.range[0], { includeComments: true });
4800 return getAdjacentCommentTokensFromCursor(cursor).reverse();
4801 }
4802 getCommentsAfter(nodeOrToken) {
4803 const cursor = createCursorWithCount(forward, this._tokens, this._comments, this._indexMap, nodeOrToken.range[1], -1, { includeComments: true });
4804 return getAdjacentCommentTokensFromCursor(cursor);
4805 }
4806 getCommentsInside(node) {
4807 return this.getTokens(node, {
4808 includeComments: true,
4809 filter: isCommentToken,
4810 });
4811 }
4812}
4813
4814function isVElement(node) {
4815 return node.type === "VElement";
4816}
4817function getCustomBlocks(document) {
4818 return document
4819 ? document.children
4820 .filter(isVElement)
4821 .filter((block) => block.name !== "script" &&
4822 block.name !== "template" &&
4823 block.name !== "style")
4824 : [];
4825}
4826function parseCustomBlockElement(node, parser, globalLocationCalculator, parserOptions) {
4827 const text = node.children[0];
4828 const { code, range, loc } = text != null && text.type === "VText"
4829 ? {
4830 code: text.value,
4831 range: text.range,
4832 loc: text.loc,
4833 }
4834 : {
4835 code: "",
4836 range: [
4837 node.startTag.range[1],
4838 node.endTag.range[0],
4839 ],
4840 loc: {
4841 start: node.startTag.loc.end,
4842 end: node.endTag.loc.start,
4843 },
4844 };
4845 const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(range[0]);
4846 try {
4847 return parseCustomBlockFragment(code, parser, locationCalculator, parserOptions);
4848 }
4849 catch (e) {
4850 if (!(e instanceof Error)) {
4851 throw e;
4852 }
4853 return {
4854 error: e,
4855 ast: {
4856 type: "Program",
4857 sourceType: "module",
4858 loc: {
4859 start: Object.assign({}, loc.start),
4860 end: Object.assign({}, loc.end),
4861 },
4862 range: [...range],
4863 body: [],
4864 tokens: [],
4865 comments: [],
4866 },
4867 };
4868 }
4869}
4870function parseCustomBlockFragment(code, parser, locationCalculator, parserOptions) {
4871 try {
4872 const result = parseBlock(code, parser, Object.assign({ ecmaVersion: DEFAULT_ECMA_VERSION, loc: true, range: true, raw: true, tokens: true, comment: true, eslintVisitorKeys: true, eslintScopeManager: true }, parserOptions));
4873 fixLocations(result, locationCalculator);
4874 return result;
4875 }
4876 catch (err) {
4877 const perr = ParseError.normalize(err);
4878 if (perr) {
4879 fixErrorLocation(perr, locationCalculator);
4880 throw perr;
4881 }
4882 throw err;
4883 }
4884}
4885function parseBlock(code, parser, parserOptions) {
4886 const result = isEnhancedParserObject(parser)
4887 ? parser.parseForESLint(code, parserOptions)
4888 : parser.parse(code, parserOptions);
4889 if (result.ast != null) {
4890 return result;
4891 }
4892 return { ast: result };
4893}
4894function createCustomBlockSharedContext({ text, customBlock, parsedResult, globalLocationCalculator, parserOptions, }) {
4895 let sourceCode;
4896 let currentNode;
4897 return {
4898 serCurrentNode(node) {
4899 currentNode = node;
4900 },
4901 context: {
4902 getAncestors: () => getSourceCode().getAncestors(currentNode),
4903 getDeclaredVariables: (...args) => getSourceCode().getDeclaredVariables(...args),
4904 getScope: () => getSourceCode().getScope(currentNode),
4905 markVariableAsUsed: (name) => getSourceCode().markVariableAsUsed(name, currentNode),
4906 get parserServices() {
4907 return getSourceCode().parserServices;
4908 },
4909 getSourceCode,
4910 get sourceCode() {
4911 return getSourceCode();
4912 },
4913 },
4914 };
4915 function getSourceCode() {
4916 if (sourceCode) {
4917 return sourceCode;
4918 }
4919 const scopeManager = getScopeManager();
4920 const originalSourceCode = new (require("eslint").SourceCode)({
4921 text,
4922 ast: parsedResult.ast,
4923 parserServices: Object.assign(Object.assign({ customBlock,
4924 parseCustomBlockElement(parser, options) {
4925 return parseCustomBlockElement(customBlock, parser, globalLocationCalculator, Object.assign(Object.assign({}, parserOptions), options));
4926 } }, (parsedResult.services || {})), (parsedResult.error
4927 ? { parseError: parsedResult.error }
4928 : {})),
4929 scopeManager,
4930 visitorKeys: parsedResult.visitorKeys,
4931 });
4932 const polyfills = {
4933 markVariableAsUsed: (name, node) => markVariableAsUsed(scopeManager, node, parsedResult.ast, name),
4934 getScope: (node) => getScope(scopeManager, node),
4935 getAncestors: (node) => getAncestors(node),
4936 getDeclaredVariables: (...args) => scopeManager.getDeclaredVariables(...args),
4937 };
4938 return (sourceCode = new Proxy(originalSourceCode, {
4939 get(_target, prop) {
4940 return originalSourceCode[prop] || polyfills[prop];
4941 },
4942 }));
4943 }
4944 function getScopeManager() {
4945 if (parsedResult.scopeManager) {
4946 return parsedResult.scopeManager;
4947 }
4948 const ecmaVersion = getEcmaVersionIfUseEspree(parserOptions) || 2022;
4949 const ecmaFeatures = parserOptions.ecmaFeatures || {};
4950 const sourceType = parserOptions.sourceType || "script";
4951 return getEslintScope().analyze(parsedResult.ast, {
4952 ignoreEval: true,
4953 nodejsScope: false,
4954 impliedStrict: ecmaFeatures.impliedStrict,
4955 ecmaVersion,
4956 sourceType,
4957 fallback: getFallbackKeys,
4958 });
4959 }
4960}
4961function getAncestors(node) {
4962 const ancestorsStartingAtParent = [];
4963 for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
4964 ancestorsStartingAtParent.push(ancestor);
4965 }
4966 return ancestorsStartingAtParent.reverse();
4967}
4968function getScope(scopeManager, currentNode) {
4969 const inner = currentNode.type !== "Program";
4970 for (let node = currentNode; node; node = node.parent || null) {
4971 const scope = scopeManager.acquire(node, inner);
4972 if (scope) {
4973 if (scope.type === "function-expression-name") {
4974 return scope.childScopes[0];
4975 }
4976 return scope;
4977 }
4978 }
4979 return scopeManager.scopes[0];
4980}
4981function markVariableAsUsed(scopeManager, currentNode, program, name) {
4982 const currentScope = getScope(scopeManager, currentNode);
4983 let initialScope = currentScope;
4984 if (currentScope.type === "global" &&
4985 currentScope.childScopes.length > 0 &&
4986 currentScope.childScopes[0].block === program) {
4987 initialScope = currentScope.childScopes[0];
4988 }
4989 for (let scope = initialScope; scope; scope = scope.upper) {
4990 const variable = scope.variables.find((scopeVar) => scopeVar.name === name);
4991 if (variable) {
4992 variable.eslintUsed = true;
4993 return true;
4994 }
4995 }
4996 return false;
4997}
4998
4999function define(sourceText, rootAST, document, globalLocationCalculator, { parserOptions }) {
5000 const templateBodyEmitters = new Map();
5001 const stores = new WeakMap();
5002 const documentEmitters = new Map();
5003 const customBlocksEmitters = new Map();
5004 const isSFC = isSFCFile(parserOptions);
5005 return {
5006 defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor, options) {
5007 var _a;
5008 if (scriptVisitor == null) {
5009 scriptVisitor = {};
5010 }
5011 if (rootAST.templateBody == null) {
5012 return scriptVisitor;
5013 }
5014 const templateBodyTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.templateBodyTriggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
5015 let emitter = templateBodyEmitters.get(templateBodyTriggerSelector);
5016 if (emitter == null) {
5017 emitter = new EventEmitter__default["default"]();
5018 emitter.setMaxListeners(0);
5019 templateBodyEmitters.set(templateBodyTriggerSelector, emitter);
5020 const programExitHandler = scriptVisitor[templateBodyTriggerSelector];
5021 scriptVisitor[templateBodyTriggerSelector] = (node) => {
5022 try {
5023 if (typeof programExitHandler === "function") {
5024 programExitHandler(node);
5025 }
5026 const generator = new NodeEventGenerator(emitter, {
5027 visitorKeys: KEYS,
5028 fallback: getFallbackKeys,
5029 });
5030 traverseNodes(rootAST.templateBody, generator);
5031 }
5032 finally {
5033 scriptVisitor[templateBodyTriggerSelector] =
5034 programExitHandler;
5035 templateBodyEmitters.delete(templateBodyTriggerSelector);
5036 }
5037 };
5038 }
5039 for (const selector of Object.keys(templateBodyVisitor)) {
5040 emitter.on(selector, templateBodyVisitor[selector]);
5041 }
5042 return scriptVisitor;
5043 },
5044 defineDocumentVisitor(documentVisitor, options) {
5045 var _a;
5046 const scriptVisitor = {};
5047 if (!document) {
5048 return scriptVisitor;
5049 }
5050 const documentTriggerSelector = (_a = options === null || options === void 0 ? void 0 : options.triggerSelector) !== null && _a !== void 0 ? _a : "Program:exit";
5051 let emitter = documentEmitters.get(documentTriggerSelector);
5052 if (emitter == null) {
5053 emitter = new EventEmitter__default["default"]();
5054 emitter.setMaxListeners(0);
5055 documentEmitters.set(documentTriggerSelector, emitter);
5056 const programExitHandler = scriptVisitor[documentTriggerSelector];
5057 scriptVisitor[documentTriggerSelector] = (node) => {
5058 try {
5059 if (typeof programExitHandler === "function") {
5060 programExitHandler(node);
5061 }
5062 const generator = new NodeEventGenerator(emitter, {
5063 visitorKeys: KEYS,
5064 fallback: getFallbackKeys,
5065 });
5066 traverseNodes(document, generator);
5067 }
5068 finally {
5069 scriptVisitor[documentTriggerSelector] =
5070 programExitHandler;
5071 documentEmitters.delete(documentTriggerSelector);
5072 }
5073 };
5074 }
5075 for (const selector of Object.keys(documentVisitor)) {
5076 emitter.on(selector, documentVisitor[selector]);
5077 }
5078 return scriptVisitor;
5079 },
5080 defineCustomBlocksVisitor(context, parser, rule, scriptVisitor) {
5081 var _a;
5082 if (scriptVisitor == null) {
5083 scriptVisitor = {};
5084 }
5085 if (!isSFC) {
5086 return scriptVisitor;
5087 }
5088 parserOptions = Object.assign({}, parserOptions);
5089 const customBlocks = getCustomBlocks(document).filter((block) => block.endTag &&
5090 !block.startTag.attributes.some((attr) => !attr.directive && attr.key.name === "src"));
5091 if (!customBlocks.length || globalLocationCalculator == null) {
5092 return {};
5093 }
5094 const key = (_a = parser.parseForESLint) !== null && _a !== void 0 ? _a : parser.parse;
5095 let factories = customBlocksEmitters.get(key);
5096 if (factories == null) {
5097 factories = [];
5098 customBlocksEmitters.set(key, factories);
5099 const visitorFactories = factories;
5100 const programExitHandler = scriptVisitor["Program:exit"];
5101 scriptVisitor["Program:exit"] = (node) => {
5102 try {
5103 if (typeof programExitHandler === "function") {
5104 programExitHandler(node);
5105 }
5106 for (const customBlock of customBlocks) {
5107 const lang = getLang(customBlock);
5108 const activeVisitorFactories = visitorFactories.filter((f) => f.test(lang, customBlock));
5109 if (!activeVisitorFactories.length) {
5110 continue;
5111 }
5112 const parsedResult = parseCustomBlockElement(customBlock, parser, globalLocationCalculator, parserOptions);
5113 const { serCurrentNode, context: customBlockContext, } = createCustomBlockSharedContext({
5114 text: sourceText,
5115 customBlock,
5116 parsedResult,
5117 globalLocationCalculator,
5118 parserOptions,
5119 });
5120 const emitter = new EventEmitter__default["default"]();
5121 emitter.setMaxListeners(0);
5122 for (const factory of activeVisitorFactories) {
5123 const ctx = Object.assign({}, customBlockContext);
5124 ctx.__proto__ = factory.context;
5125 const visitor = factory.create(ctx);
5126 for (const selector of Object.keys(visitor || {})) {
5127 emitter.on(selector, visitor[selector]);
5128 }
5129 }
5130 const generator = new NodeEventGenerator(emitter, {
5131 visitorKeys: parsedResult.visitorKeys,
5132 fallback: getFallbackKeys,
5133 });
5134 traverseNodes(parsedResult.ast, {
5135 visitorKeys: parsedResult.visitorKeys,
5136 enterNode(n) {
5137 serCurrentNode(n);
5138 generator.enterNode(n);
5139 },
5140 leaveNode(n) {
5141 serCurrentNode(n);
5142 generator.leaveNode(n);
5143 },
5144 });
5145 }
5146 }
5147 finally {
5148 scriptVisitor["Program:exit"] = programExitHandler;
5149 customBlocksEmitters.delete(key);
5150 }
5151 };
5152 }
5153 const target = rule.target;
5154 const test = typeof target === "function"
5155 ? target
5156 : Array.isArray(target)
5157 ? (lang) => Boolean(lang && target.includes(lang))
5158 : (lang) => target === lang;
5159 factories.push({
5160 context,
5161 test,
5162 create: rule.create,
5163 });
5164 return scriptVisitor;
5165 },
5166 getTemplateBodyTokenStore() {
5167 const key = document || stores;
5168 let store = stores.get(key);
5169 if (!store) {
5170 store =
5171 document != null
5172 ? new TokenStore(document.tokens, document.comments)
5173 : new TokenStore([], []);
5174 stores.set(key, store);
5175 }
5176 return store;
5177 },
5178 getDocumentFragment() {
5179 return document;
5180 },
5181 };
5182}
5183
5184class CodeBlocks {
5185 constructor() {
5186 this.remapBlocks = [];
5187 this.splitPunctuators = [];
5188 this.code = "";
5189 }
5190 get length() {
5191 return this.code.length;
5192 }
5193 append(codeLet, originalOffset) {
5194 const rangeStart = this.code.length;
5195 this.code += codeLet.trimEnd();
5196 this.remapBlocks.push({
5197 range: [rangeStart, this.code.length],
5198 offset: originalOffset - rangeStart,
5199 });
5200 }
5201 appendSplitPunctuators(punctuator) {
5202 this.splitPunctuators.push(this.code.length, this.code.length + 1);
5203 this.code += `\n${punctuator}\n`;
5204 }
5205 appendCodeBlocks(codeBlocks) {
5206 const start = this.code.length;
5207 this.code += codeBlocks.code;
5208 this.remapBlocks.push(...codeBlocks.remapBlocks.map((b) => ({
5209 range: [b.range[0] + start, b.range[1] + start],
5210 offset: b.offset - start,
5211 })));
5212 this.splitPunctuators.push(...codeBlocks.splitPunctuators.map((s) => s + start));
5213 }
5214}
5215class RestoreASTCallbacks {
5216 constructor() {
5217 this.callbacks = [];
5218 }
5219 addCallback(originalOffsetStart, range, callback) {
5220 this.callbacks.push({
5221 range: [
5222 originalOffsetStart + range[0],
5223 originalOffsetStart + range[1],
5224 ],
5225 callback,
5226 });
5227 }
5228 restore(program, scriptSetupStatements, linesAndColumns) {
5229 if (this.callbacks.length === 0) {
5230 return;
5231 }
5232 const callbacks = new Set(this.callbacks);
5233 for (const statement of scriptSetupStatements) {
5234 for (const cb of callbacks) {
5235 if (cb.range[0] <= statement.range[0] &&
5236 statement.range[1] <= cb.range[1]) {
5237 const restored = cb.callback(statement);
5238 if (restored) {
5239 const removeIndex = program.body.indexOf(statement);
5240 if (removeIndex >= 0) {
5241 program.body.splice(removeIndex, 1);
5242 program.body.push(restored.statement);
5243 program.tokens.push(...restored.tokens);
5244 restored.statement.parent = program;
5245 callbacks.delete(cb);
5246 break;
5247 }
5248 }
5249 }
5250 }
5251 }
5252 if (callbacks.size) {
5253 const [cb] = callbacks;
5254 const loc = linesAndColumns.getLocFromIndex(cb.range[0]);
5255 throw new ParseError("Could not parse <script setup>. Failed to restore ExportNamedDeclaration.", undefined, cb.range[0], loc.line, loc.column);
5256 }
5257 }
5258}
5259function parseScript(code, parserOptions, locationCalculatorForError) {
5260 try {
5261 return parseScript$1(code, parserOptions);
5262 }
5263 catch (err) {
5264 const perr = ParseError.normalize(err);
5265 if (perr) {
5266 fixErrorLocation(perr, locationCalculatorForError);
5267 throw perr;
5268 }
5269 throw err;
5270 }
5271}
5272function parseScriptSetupElements(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, originalParserOptions) {
5273 const parserOptions = getScriptSetupParserOptions(originalParserOptions);
5274 const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions);
5275 if (!scriptSetupModuleCodeBlocks) {
5276 return parseScriptFragment("", linesAndColumns.createOffsetLocationCalculator(scriptSetupElement.startTag.range[1]), parserOptions);
5277 }
5278 const locationCalculator = {
5279 getFixOffset(offset, kind) {
5280 const test = kind === "start"
5281 ? (block) => block.range[0] <= offset && offset < block.range[1]
5282 : (block) => block.range[0] < offset && offset <= block.range[1];
5283 for (const block of scriptSetupModuleCodeBlocks.codeBlocks
5284 .remapBlocks) {
5285 if (test(block)) {
5286 return block.offset;
5287 }
5288 }
5289 return offset;
5290 },
5291 getLocFromIndex: linesAndColumns.getLocFromIndex.bind(linesAndColumns),
5292 };
5293 const result = parseScript(scriptSetupModuleCodeBlocks.codeBlocks.code, parserOptions, locationCalculator);
5294 if (scriptSetupModuleCodeBlocks.postprocess) {
5295 scriptSetupModuleCodeBlocks.postprocess(result, {
5296 scriptSetupBlockRange: scriptSetupModuleCodeBlocks.scriptSetupBlockRange,
5297 });
5298 }
5299 const scriptSetupStatements = remapAST(result, scriptSetupModuleCodeBlocks);
5300 remapLocationAndTokens(result, scriptSetupModuleCodeBlocks, locationCalculator);
5301 if (scriptSetupModuleCodeBlocks.restoreASTCallbacks) {
5302 scriptSetupModuleCodeBlocks.restoreASTCallbacks.restore(result.ast, scriptSetupStatements, linesAndColumns);
5303 }
5304 if (result.ast.tokens != null) {
5305 for (const node of [scriptSetupElement, scriptElement]) {
5306 const startTag = node.startTag;
5307 const endTag = node.endTag;
5308 result.ast.tokens.unshift({
5309 type: "Punctuator",
5310 range: startTag.range,
5311 loc: startTag.loc,
5312 value: "<script>",
5313 });
5314 if (endTag != null) {
5315 result.ast.tokens.push({
5316 type: "Punctuator",
5317 range: endTag.range,
5318 loc: endTag.loc,
5319 value: "</script>",
5320 });
5321 }
5322 }
5323 result.ast.tokens.sort((a, b) => a.range[0] - b.range[0]);
5324 }
5325 result.ast.body.sort((a, b) => a.range[0] - b.range[0]);
5326 const programStartOffset = result.ast.body.reduce((start, node) => Math.min(start, node.range[0]), result.ast.range[0]);
5327 result.ast.range[0] = programStartOffset;
5328 result.ast.loc.start =
5329 locationCalculator.getLocFromIndex(programStartOffset);
5330 if (result.ast.start != null) {
5331 result.ast.start = [scriptSetupElement, scriptElement].reduce((start, node) => {
5332 const textNode = node.children[0];
5333 return Math.min(start, textNode != null && textNode.type === "VText"
5334 ? textNode.range[0]
5335 : node.startTag.range[1]);
5336 }, result.ast.start);
5337 }
5338 const programEndOffset = result.ast.body.reduce((end, node) => Math.max(end, node.range[1]), 0);
5339 result.ast.range[1] = programEndOffset;
5340 result.ast.loc.end = locationCalculator.getLocFromIndex(programEndOffset);
5341 if (result.ast.end != null) {
5342 result.ast.end = [scriptSetupElement, scriptElement].reduce((end, node) => {
5343 var _a, _b;
5344 const textNode = node.children[0];
5345 return Math.max(end, textNode != null && textNode.type === "VText"
5346 ? textNode.range[1]
5347 : (_b = (_a = node.endTag) === null || _a === void 0 ? void 0 : _a.range[0]) !== null && _b !== void 0 ? _b : node.range[1]);
5348 }, 0);
5349 }
5350 return result;
5351}
5352function getScriptSetupModuleCodeBlocks(scriptSetupElement, scriptElement, sfcCode, linesAndColumns, parserOptions) {
5353 const scriptSetupCodeBlocks = getScriptSetupCodeBlocks(scriptSetupElement, sfcCode, linesAndColumns, parserOptions);
5354 const textNode = scriptElement.children[0];
5355 if (textNode == null || textNode.type !== "VText") {
5356 return scriptSetupCodeBlocks;
5357 }
5358 const [scriptStartOffset, scriptEndOffset] = textNode.range;
5359 const codeBlocks = new CodeBlocks();
5360 codeBlocks.append(sfcCode.slice(scriptStartOffset, scriptEndOffset), scriptStartOffset);
5361 if (scriptSetupCodeBlocks == null) {
5362 return { codeBlocks };
5363 }
5364 codeBlocks.appendSplitPunctuators(";");
5365 const scriptSetupOffset = codeBlocks.length;
5366 codeBlocks.appendCodeBlocks(scriptSetupCodeBlocks.codeBlocks);
5367 return {
5368 codeBlocks,
5369 scriptSetupBlockRange: [
5370 scriptSetupCodeBlocks.scriptSetupBlockRange[0] + scriptSetupOffset,
5371 scriptSetupCodeBlocks.scriptSetupBlockRange[1] + scriptSetupOffset,
5372 ],
5373 postprocess: scriptSetupCodeBlocks.postprocess,
5374 restoreASTCallbacks: scriptSetupCodeBlocks.restoreASTCallbacks,
5375 };
5376}
5377function getScriptSetupCodeBlocks(node, sfcCode, linesAndColumns, parserOptions) {
5378 const textNode = node.children[0];
5379 if (textNode == null || textNode.type !== "VText") {
5380 return null;
5381 }
5382 const [scriptSetupStartOffset, scriptSetupEndOffset] = textNode.range;
5383 const scriptCode = sfcCode.slice(scriptSetupStartOffset, scriptSetupEndOffset);
5384 const offsetLocationCalculator = linesAndColumns.createOffsetLocationCalculator(scriptSetupStartOffset);
5385 const result = parseScript(scriptCode, parserOptions, offsetLocationCalculator);
5386 const { ast } = result;
5387 const importCodeBlocks = new CodeBlocks();
5388 const statementCodeBlocks = new CodeBlocks();
5389 const exportDefaultCodeBlocks = new CodeBlocks();
5390 const restoreASTCallbacks = new RestoreASTCallbacks();
5391 let usedOffset = 0;
5392 function append(codeBlocks, start, end) {
5393 if (start < end) {
5394 codeBlocks.append(scriptCode.slice(start, end), scriptSetupStartOffset + start);
5395 usedOffset = end;
5396 return true;
5397 }
5398 return false;
5399 }
5400 function appendRangeAsStatement(codeBlocks, start, end) {
5401 if (append(codeBlocks, start, end)) {
5402 codeBlocks.appendSplitPunctuators(";");
5403 }
5404 }
5405 function transformExportNamed(body) {
5406 const [start, end] = getNodeFullRange(body);
5407 appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
5408 const tokens = ast.tokens;
5409 const exportTokenIndex = tokens.findIndex((t) => t.range[0] === body.range[0]);
5410 const exportToken = tokens[exportTokenIndex];
5411 if (exportToken && exportToken.value === "export") {
5412 append(statementCodeBlocks, usedOffset, exportToken.range[0]);
5413 if (body.declaration) {
5414 appendRangeAsStatement(statementCodeBlocks, exportToken.range[1], end);
5415 restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
5416 if (statement.type !== body.declaration.type) {
5417 return null;
5418 }
5419 fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
5420 fixLocation(exportToken, offsetLocationCalculator);
5421 body.declaration = statement;
5422 statement.parent = body;
5423 return {
5424 statement: body,
5425 tokens: [exportToken],
5426 };
5427 });
5428 }
5429 else {
5430 statementCodeBlocks.appendSplitPunctuators("(");
5431 const restoreTokens = [exportToken];
5432 let startOffset = exportToken.range[1];
5433 for (const spec of body.specifiers) {
5434 if (spec.local.range[0] < spec.exported.range[0]) {
5435 const localTokenIndex = tokens.findIndex((t) => t.range[0] === spec.local.range[0], exportTokenIndex);
5436 checkToken(tokens[localTokenIndex], spec.local.name);
5437 const asToken = tokens[localTokenIndex + 1];
5438 checkToken(asToken, "as");
5439 restoreTokens.push(asToken);
5440 const exportedToken = tokens[localTokenIndex + 2];
5441 checkToken(exportedToken, spec.exported.type === "Identifier"
5442 ? spec.exported.name
5443 : spec.exported.raw);
5444 restoreTokens.push(exportedToken);
5445 append(statementCodeBlocks, startOffset, asToken.range[0]);
5446 append(statementCodeBlocks, asToken.range[1], exportedToken.range[0]);
5447 startOffset = exportedToken.range[1];
5448 }
5449 }
5450 append(statementCodeBlocks, startOffset, end);
5451 statementCodeBlocks.appendSplitPunctuators(")");
5452 statementCodeBlocks.appendSplitPunctuators(";");
5453 restoreASTCallbacks.addCallback(scriptSetupStartOffset, [start, end], (statement) => {
5454 if (statement.type !== "ExpressionStatement" ||
5455 statement.expression.type !== "ObjectExpression") {
5456 return null;
5457 }
5458 const locals = [];
5459 for (const prop of statement.expression.properties) {
5460 if (prop.type !== "Property" ||
5461 prop.value.type !== "Identifier") {
5462 return null;
5463 }
5464 locals.push(prop.value);
5465 }
5466 if (body.specifiers.length !== locals.length) {
5467 return null;
5468 }
5469 const map = new Map();
5470 for (let index = 0; index < body.specifiers.length; index++) {
5471 const spec = body.specifiers[index];
5472 const local = locals[index];
5473 map.set(spec, local);
5474 }
5475 fixNodeLocations(body, result.visitorKeys, offsetLocationCalculator);
5476 for (const token of restoreTokens) {
5477 fixLocation(token, offsetLocationCalculator);
5478 }
5479 for (const [spec, local] of map) {
5480 spec.local = local;
5481 local.parent = spec;
5482 }
5483 return {
5484 statement: body,
5485 tokens: restoreTokens,
5486 };
5487 });
5488 }
5489 }
5490 else {
5491 appendRangeAsStatement(statementCodeBlocks, usedOffset, end);
5492 }
5493 }
5494 for (const body of ast.body) {
5495 if (body.type === "ImportDeclaration" ||
5496 body.type === "ExportAllDeclaration" ||
5497 (body.type === "ExportNamedDeclaration" && body.source != null)) {
5498 const [start, end] = getNodeFullRange(body);
5499 appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
5500 appendRangeAsStatement(importCodeBlocks, start, end);
5501 }
5502 else if (body.type === "ExportDefaultDeclaration") {
5503 const [start, end] = getNodeFullRange(body);
5504 appendRangeAsStatement(statementCodeBlocks, usedOffset, start);
5505 appendRangeAsStatement(exportDefaultCodeBlocks, start, end);
5506 }
5507 else if (body.type === "ExportNamedDeclaration") {
5508 transformExportNamed(body);
5509 }
5510 }
5511 appendRangeAsStatement(statementCodeBlocks, usedOffset, scriptSetupEndOffset);
5512 const codeBlocks = new CodeBlocks();
5513 let postprocess = () => {
5514 };
5515 codeBlocks.appendCodeBlocks(importCodeBlocks);
5516 const scriptSetupBlockRangeStart = codeBlocks.length;
5517 codeBlocks.appendSplitPunctuators("{");
5518 const generic = extractGeneric(node);
5519 if (generic) {
5520 const defineGenericTypeRangeStart = codeBlocks.length;
5521 for (const defineType of generic.defineTypes) {
5522 codeBlocks.append(defineType.define, defineType.node.range[0]);
5523 codeBlocks.appendSplitPunctuators(";");
5524 }
5525 const defineGenericTypeRangeEnd = codeBlocks.length;
5526 postprocess = (eslintResult, context) => {
5527 const diffOffset = context.scriptSetupBlockRange[0] - scriptSetupBlockRangeStart;
5528 const defineGenericTypeRange = [
5529 defineGenericTypeRangeStart + diffOffset,
5530 defineGenericTypeRangeEnd + diffOffset,
5531 ];
5532 function isTypeBlock(block) {
5533 return (block.type === "BlockStatement" &&
5534 context.scriptSetupBlockRange[0] <= block.range[0] &&
5535 block.range[1] <= context.scriptSetupBlockRange[1]);
5536 }
5537 generic.postprocess({
5538 result: eslintResult,
5539 getTypeBlock: (program) => program.body.find(isTypeBlock),
5540 isRemoveTarget(nodeOrToken) {
5541 return (defineGenericTypeRange[0] <= nodeOrToken.range[0] &&
5542 nodeOrToken.range[1] <= defineGenericTypeRange[1]);
5543 },
5544 getTypeDefScope(scopeManager) {
5545 var _a;
5546 const moduleScope = (_a = scopeManager.globalScope.childScopes.find((s) => s.type === "module")) !== null && _a !== void 0 ? _a : scopeManager.globalScope;
5547 return moduleScope.childScopes.find((scope) => isTypeBlock(scope.block));
5548 },
5549 });
5550 };
5551 }
5552 codeBlocks.appendCodeBlocks(statementCodeBlocks);
5553 codeBlocks.appendSplitPunctuators("}");
5554 const scriptSetupBlockRangeEnd = codeBlocks.length;
5555 codeBlocks.appendCodeBlocks(exportDefaultCodeBlocks);
5556 return {
5557 codeBlocks,
5558 scriptSetupBlockRange: [
5559 scriptSetupBlockRangeStart,
5560 scriptSetupBlockRangeEnd,
5561 ],
5562 postprocess,
5563 restoreASTCallbacks,
5564 };
5565 function getNodeFullRange(n) {
5566 let start = n.range[0];
5567 let end = n.range[1];
5568 traverseNodes(n, {
5569 visitorKeys: result.visitorKeys,
5570 enterNode(c) {
5571 start = Math.min(start, c.range[0]);
5572 end = Math.max(end, c.range[1]);
5573 },
5574 leaveNode() {
5575 },
5576 });
5577 return [start, end];
5578 }
5579 function checkToken(token, value) {
5580 if (token.value === value) {
5581 return;
5582 }
5583 const perr = new ParseError(`Could not parse <script setup>. Expected "${value}", but it was "${token.value}".`, undefined, token.range[0], token.loc.start.line, token.loc.start.column);
5584 fixErrorLocation(perr, offsetLocationCalculator);
5585 throw perr;
5586 }
5587}
5588function remapAST(result, { scriptSetupBlockRange, codeBlocks }) {
5589 if (!scriptSetupBlockRange) {
5590 return [];
5591 }
5592 let scriptSetupBlock = null;
5593 const scriptSetupStatements = [];
5594 for (let index = result.ast.body.length - 1; index >= 0; index--) {
5595 const body = result.ast.body[index];
5596 if (body.type === "BlockStatement") {
5597 if (scriptSetupBlockRange[0] <= body.range[0] &&
5598 body.range[1] <= scriptSetupBlockRange[1]) {
5599 if (scriptSetupBlock) {
5600 throw new Error(`Unexpected state error: An unexpected block statement was found. ${JSON.stringify(body.loc)}`);
5601 }
5602 scriptSetupBlock = body;
5603 scriptSetupStatements.push(...body.body.filter((b) => !isSplitPunctuatorsEmptyStatement(b)));
5604 result.ast.body.splice(index, 1, ...scriptSetupStatements);
5605 }
5606 }
5607 else if (body.type === "EmptyStatement") {
5608 if (isSplitPunctuatorsEmptyStatement(body)) {
5609 result.ast.body.splice(index, 1);
5610 }
5611 }
5612 }
5613 if (result.scopeManager && scriptSetupBlock) {
5614 const blockScope = result.scopeManager.acquire(scriptSetupBlock, true);
5615 remapScope(result.scopeManager, blockScope);
5616 }
5617 return scriptSetupStatements;
5618 function isSplitPunctuatorsEmptyStatement(body) {
5619 return (body.type === "EmptyStatement" &&
5620 codeBlocks.splitPunctuators.includes(body.range[1] - 1));
5621 }
5622 function remapScope(scopeManager, blockScope) {
5623 const moduleScope = blockScope.upper;
5624 for (const reference of blockScope.references) {
5625 reference.from = moduleScope;
5626 moduleScope.references.push(reference);
5627 }
5628 for (const variable of blockScope.variables) {
5629 variable.scope = moduleScope;
5630 const alreadyVariable = moduleScope.variables.find((v) => v.name === variable.name);
5631 if (alreadyVariable) {
5632 alreadyVariable.defs.push(...variable.defs);
5633 alreadyVariable.identifiers.push(...variable.identifiers);
5634 alreadyVariable.references.push(...variable.references);
5635 for (const reference of variable.references) {
5636 reference.resolved = alreadyVariable;
5637 }
5638 }
5639 else {
5640 moduleScope.variables.push(variable);
5641 moduleScope.set.set(variable.name, variable);
5642 }
5643 }
5644 const upper = blockScope.upper;
5645 if (upper) {
5646 const index = upper.childScopes.indexOf(blockScope);
5647 if (index >= 0) {
5648 upper.childScopes.splice(index, 1);
5649 }
5650 }
5651 const index = scopeManager.scopes.indexOf(blockScope);
5652 if (index >= 0) {
5653 scopeManager.scopes.splice(index, 1);
5654 }
5655 }
5656}
5657function remapLocationAndTokens(result, { codeBlocks }, locationCalculator) {
5658 const tokens = result.ast.tokens || [];
5659 const endMap = new Map();
5660 const buffer = [];
5661 for (let index = tokens.length - 1; index >= 0; index--) {
5662 const token = tokens[index];
5663 if (token.range[0] + 1 === token.range[1] &&
5664 codeBlocks.splitPunctuators.includes(token.range[0])) {
5665 tokens.splice(index, 1);
5666 buffer.push(token.range[1]);
5667 continue;
5668 }
5669 else {
5670 for (const end of buffer) {
5671 endMap.set(end, token.range[1]);
5672 }
5673 buffer.length = 0;
5674 }
5675 }
5676 traverseNodes(result.ast, {
5677 visitorKeys: result.visitorKeys,
5678 enterNode(node) {
5679 const rangeEnd = endMap.get(node.range[1]);
5680 if (rangeEnd != null) {
5681 node.range[1] = rangeEnd;
5682 }
5683 if (node.end) {
5684 const end = endMap.get(node.end);
5685 if (end != null) {
5686 node.end = rangeEnd;
5687 }
5688 }
5689 },
5690 leaveNode() {
5691 },
5692 });
5693 fixLocations(result, locationCalculator);
5694}
5695
5696class CSSTokenizer {
5697 constructor(text, startOffset, options) {
5698 var _a;
5699 debug("[css] the source code length: %d", text.length);
5700 this.text = text;
5701 this.options = {
5702 inlineComment: (_a = options === null || options === void 0 ? void 0 : options.inlineComment) !== null && _a !== void 0 ? _a : false,
5703 };
5704 this.cp = NULL;
5705 this.offset = startOffset - 1;
5706 this.nextOffset = startOffset;
5707 this.reconsuming = false;
5708 }
5709 nextToken() {
5710 let cp;
5711 if (this.reconsuming) {
5712 cp = this.cp;
5713 this.reconsuming = false;
5714 }
5715 else {
5716 cp = this.consumeNextCodePoint();
5717 }
5718 while (isWhitespace(cp)) {
5719 cp = this.consumeNextCodePoint();
5720 }
5721 if (cp === EOF) {
5722 return null;
5723 }
5724 const start = this.offset;
5725 return this.consumeNextToken(cp, start);
5726 }
5727 nextCodePoint() {
5728 if (this.nextOffset >= this.text.length) {
5729 return EOF;
5730 }
5731 return this.text.codePointAt(this.nextOffset);
5732 }
5733 consumeNextCodePoint() {
5734 if (this.offset >= this.text.length) {
5735 this.cp = EOF;
5736 return EOF;
5737 }
5738 this.offset = this.nextOffset;
5739 if (this.offset >= this.text.length) {
5740 this.cp = EOF;
5741 return EOF;
5742 }
5743 let cp = this.text.codePointAt(this.offset);
5744 if (cp === CARRIAGE_RETURN) {
5745 this.nextOffset = this.offset + 1;
5746 if (this.text.codePointAt(this.nextOffset) === LINE_FEED) {
5747 this.nextOffset++;
5748 }
5749 cp = LINE_FEED;
5750 }
5751 else {
5752 this.nextOffset = this.offset + (cp >= 0x10000 ? 2 : 1);
5753 }
5754 this.cp = cp;
5755 return cp;
5756 }
5757 consumeNextToken(cp, start) {
5758 if (cp === SOLIDUS) {
5759 const nextCp = this.nextCodePoint();
5760 if (nextCp === ASTERISK) {
5761 return this.consumeComment(start);
5762 }
5763 if (nextCp === SOLIDUS && this.options.inlineComment) {
5764 return this.consumeInlineComment(start);
5765 }
5766 }
5767 if (isQuote(cp)) {
5768 return this.consumeString(start, cp);
5769 }
5770 if (isPunctuator(cp)) {
5771 return {
5772 type: "Punctuator",
5773 range: [start, start + 1],
5774 value: String.fromCodePoint(cp),
5775 };
5776 }
5777 return this.consumeWord(start);
5778 }
5779 consumeWord(start) {
5780 let cp = this.consumeNextCodePoint();
5781 while (!isWhitespace(cp) && !isPunctuator(cp) && !isQuote(cp)) {
5782 cp = this.consumeNextCodePoint();
5783 }
5784 this.reconsuming = true;
5785 const range = [start, this.offset];
5786 const text = this.text;
5787 let value;
5788 return {
5789 type: "Word",
5790 range,
5791 get value() {
5792 return (value !== null && value !== void 0 ? value : (value = text.slice(...range)));
5793 },
5794 };
5795 }
5796 consumeString(start, quote) {
5797 let valueEndOffset = null;
5798 let cp = this.consumeNextCodePoint();
5799 while (cp !== EOF) {
5800 if (cp === quote) {
5801 valueEndOffset = this.offset;
5802 break;
5803 }
5804 if (cp === REVERSE_SOLIDUS) {
5805 this.consumeNextCodePoint();
5806 }
5807 cp = this.consumeNextCodePoint();
5808 }
5809 const text = this.text;
5810 let value;
5811 const valueRange = [
5812 start + 1,
5813 valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
5814 ];
5815 return {
5816 type: "Quoted",
5817 range: [start, this.nextOffset],
5818 valueRange,
5819 get value() {
5820 return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
5821 },
5822 quote: String.fromCodePoint(quote),
5823 };
5824 }
5825 consumeComment(start) {
5826 this.consumeNextCodePoint();
5827 let valueEndOffset = null;
5828 let cp = this.consumeNextCodePoint();
5829 while (cp !== EOF) {
5830 if (cp === ASTERISK) {
5831 cp = this.consumeNextCodePoint();
5832 if (cp === SOLIDUS) {
5833 valueEndOffset = this.offset - 1;
5834 break;
5835 }
5836 }
5837 cp = this.consumeNextCodePoint();
5838 }
5839 const valueRange = [
5840 start + 2,
5841 valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
5842 ];
5843 const text = this.text;
5844 let value;
5845 return {
5846 type: "Block",
5847 range: [start, this.nextOffset],
5848 valueRange,
5849 get value() {
5850 return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
5851 },
5852 };
5853 }
5854 consumeInlineComment(start) {
5855 this.consumeNextCodePoint();
5856 let valueEndOffset = null;
5857 let cp = this.consumeNextCodePoint();
5858 while (cp !== EOF) {
5859 if (cp === LINE_FEED) {
5860 valueEndOffset = this.offset - 1;
5861 break;
5862 }
5863 cp = this.consumeNextCodePoint();
5864 }
5865 const valueRange = [
5866 start + 2,
5867 valueEndOffset !== null && valueEndOffset !== void 0 ? valueEndOffset : this.nextOffset,
5868 ];
5869 const text = this.text;
5870 let value;
5871 return {
5872 type: "Line",
5873 range: [start, this.nextOffset],
5874 valueRange,
5875 get value() {
5876 return (value !== null && value !== void 0 ? value : (value = text.slice(...valueRange)));
5877 },
5878 };
5879 }
5880}
5881function isPunctuator(cp) {
5882 return (cp === COLON ||
5883 cp === SEMICOLON ||
5884 cp === LEFT_PARENTHESIS ||
5885 cp === RIGHT_PARENTHESIS ||
5886 cp === LEFT_CURLY_BRACKET ||
5887 cp === RIGHT_CURLY_BRACKET ||
5888 cp === LEFT_SQUARE_BRACKET ||
5889 cp === RIGHT_SQUARE_BRACKET ||
5890 cp === SOLIDUS ||
5891 cp === ASTERISK);
5892}
5893function isQuote(cp) {
5894 return cp === APOSTROPHE || cp === QUOTATION_MARK;
5895}
5896
5897class CSSTokenScanner {
5898 constructor(text, options) {
5899 this.reconsuming = [];
5900 this.tokenizer = new CSSTokenizer(text, 0, options);
5901 }
5902 nextToken() {
5903 return this.reconsuming.shift() || this.tokenizer.nextToken();
5904 }
5905 reconsume(...tokens) {
5906 this.reconsuming.push(...tokens);
5907 }
5908}
5909function parseStyleElements(elements, globalLocationCalculator, originalParserOptions) {
5910 const parserOptions = Object.assign(Object.assign({}, originalParserOptions), { ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION });
5911 for (const style of elements) {
5912 style.style = true;
5913 parseStyleElement(style, globalLocationCalculator, parserOptions, {
5914 inlineComment: (getLang(style) || "css") !== "css",
5915 });
5916 }
5917}
5918function parseStyleElement(style, globalLocationCalculator, parserOptions, cssOptions) {
5919 if (style.children.length !== 1) {
5920 return;
5921 }
5922 const textNode = style.children[0];
5923 if (textNode.type !== "VText") {
5924 return;
5925 }
5926 const code = textNode.value;
5927 if (!/v-bind\s*(?:\(|\/)/u.test(code)) {
5928 return;
5929 }
5930 const locationCalculator = globalLocationCalculator.getSubCalculatorAfter(textNode.range[0]);
5931 const document = getOwnerDocument(style);
5932 parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions);
5933}
5934function parseStyle(document, style, code, locationCalculator, parserOptions, cssOptions) {
5935 let textStart = 0;
5936 for (const { range, exprRange, quote, openingParenOffset, comments, } of iterateVBind(code, cssOptions)) {
5937 insertComments(document, comments.map((c) => createSimpleToken(c.type, locationCalculator.getOffsetWithGap(c.range[0]), locationCalculator.getOffsetWithGap(c.range[1]), c.value, locationCalculator)));
5938 const container = {
5939 type: "VExpressionContainer",
5940 range: [
5941 locationCalculator.getOffsetWithGap(range[0]),
5942 locationCalculator.getOffsetWithGap(range[1]),
5943 ],
5944 loc: {
5945 start: locationCalculator.getLocation(range[0]),
5946 end: locationCalculator.getLocation(range[1]),
5947 },
5948 parent: style,
5949 expression: null,
5950 references: [],
5951 };
5952 const openingParenStart = locationCalculator.getOffsetWithGap(openingParenOffset);
5953 const beforeTokens = [
5954 createSimpleToken("HTMLRawText", container.range[0], container.range[0] + 6, "v-bind", locationCalculator),
5955 createSimpleToken("Punctuator", openingParenStart, openingParenStart + 1, "(", locationCalculator),
5956 ];
5957 const afterTokens = [
5958 createSimpleToken("Punctuator", container.range[1] - 1, container.range[1], ")", locationCalculator),
5959 ];
5960 if (quote) {
5961 const openStart = locationCalculator.getOffsetWithGap(exprRange[0] - 1);
5962 beforeTokens.push(createSimpleToken("Punctuator", openStart, openStart + 1, quote, locationCalculator));
5963 const closeStart = locationCalculator.getOffsetWithGap(exprRange[1]);
5964 afterTokens.unshift(createSimpleToken("Punctuator", closeStart, closeStart + 1, quote, locationCalculator));
5965 }
5966 const beforeLast = beforeTokens[beforeTokens.length - 1];
5967 replaceAndSplitTokens(document, {
5968 range: [container.range[0], beforeLast.range[1]],
5969 loc: { start: container.loc.start, end: beforeLast.loc.end },
5970 }, beforeTokens);
5971 const afterFirst = afterTokens[0];
5972 replaceAndSplitTokens(document, {
5973 range: [afterFirst.range[0], container.range[1]],
5974 loc: { start: afterFirst.loc.start, end: container.loc.end },
5975 }, afterTokens);
5976 const lastChild = style.children[style.children.length - 1];
5977 style.children.push(container);
5978 if (lastChild.type === "VText") {
5979 const newTextNode = {
5980 type: "VText",
5981 range: [container.range[1], lastChild.range[1]],
5982 loc: {
5983 start: Object.assign({}, container.loc.end),
5984 end: Object.assign({}, lastChild.loc.end),
5985 },
5986 parent: style,
5987 value: code.slice(range[1]),
5988 };
5989 style.children.push(newTextNode);
5990 lastChild.range[1] = container.range[0];
5991 lastChild.loc.end = Object.assign({}, container.loc.start);
5992 lastChild.value = code.slice(textStart, range[0]);
5993 textStart = range[1];
5994 }
5995 try {
5996 const ret = parseExpression(code.slice(...exprRange), locationCalculator.getSubCalculatorShift(exprRange[0]), parserOptions, { allowEmpty: false, allowFilters: false });
5997 if (ret.expression) {
5998 ret.expression.parent = container;
5999 container.expression = ret.expression;
6000 container.references = ret.references;
6001 }
6002 replaceAndSplitTokens(document, {
6003 range: [beforeLast.range[1], afterFirst.range[0]],
6004 loc: {
6005 start: beforeLast.loc.end,
6006 end: afterFirst.loc.start,
6007 },
6008 }, ret.tokens);
6009 insertComments(document, ret.comments);
6010 for (const variable of ret.variables) {
6011 style.variables.push(variable);
6012 }
6013 resolveReferences(container);
6014 }
6015 catch (err) {
6016 debug("[style] Parse error: %s", err);
6017 if (ParseError.isParseError(err)) {
6018 insertError(document, err);
6019 }
6020 else {
6021 throw err;
6022 }
6023 }
6024 }
6025}
6026function* iterateVBind(code, cssOptions) {
6027 const tokenizer = new CSSTokenScanner(code, cssOptions);
6028 let token;
6029 while ((token = tokenizer.nextToken())) {
6030 if (token.type !== "Word" || token.value !== "v-bind") {
6031 continue;
6032 }
6033 const openingParen = findVBindOpeningParen(tokenizer);
6034 if (!openingParen) {
6035 continue;
6036 }
6037 const arg = parseVBindArg(tokenizer);
6038 if (!arg) {
6039 continue;
6040 }
6041 yield {
6042 range: [token.range[0], arg.closingParen.range[1]],
6043 exprRange: arg.exprRange,
6044 quote: arg.quote,
6045 openingParenOffset: openingParen.openingParen.range[0],
6046 comments: [...openingParen.comments, ...arg.comments],
6047 };
6048 }
6049}
6050function findVBindOpeningParen(tokenizer) {
6051 const comments = [];
6052 let token;
6053 while ((token = tokenizer.nextToken())) {
6054 if (token.type === "Punctuator" && token.value === "(") {
6055 return {
6056 openingParen: token,
6057 comments,
6058 };
6059 }
6060 else if (isComment(token)) {
6061 comments.push(token);
6062 continue;
6063 }
6064 tokenizer.reconsume(...comments, token);
6065 return null;
6066 }
6067 return null;
6068}
6069function parseVBindArg(tokenizer) {
6070 const tokensBuffer = [];
6071 const comments = [];
6072 const tokens = [];
6073 const closeTokenStack = [];
6074 let token;
6075 while ((token = tokenizer.nextToken())) {
6076 if (token.type === "Punctuator") {
6077 if (token.value === ")" && !closeTokenStack.length) {
6078 if (tokens.length === 1 &&
6079 tokens[0].type === "Quoted") {
6080 const quotedToken = tokens[0];
6081 return {
6082 exprRange: quotedToken.valueRange,
6083 quote: quotedToken.quote,
6084 closingParen: token,
6085 comments,
6086 };
6087 }
6088 const startToken = tokensBuffer[0] || token;
6089 return {
6090 exprRange: [startToken.range[0], token.range[0]],
6091 quote: null,
6092 closingParen: token,
6093 comments: [],
6094 };
6095 }
6096 if (token.value === closeTokenStack[0]) {
6097 closeTokenStack.shift();
6098 }
6099 else if (token.value === "(") {
6100 closeTokenStack.unshift(")");
6101 }
6102 }
6103 tokensBuffer.push(token);
6104 if (isComment(token)) {
6105 comments.push(token);
6106 }
6107 else {
6108 tokens.push(token);
6109 }
6110 }
6111 tokenizer.reconsume(...tokensBuffer);
6112 return null;
6113}
6114function isComment(token) {
6115 return token.type === "Block" || token.type === "Line";
6116}
6117
6118const BUILTIN_COMPONENTS = new Set([
6119 "template",
6120 "slot",
6121 "component",
6122 "Component",
6123 "transition",
6124 "Transition",
6125 "transition-group",
6126 "TransitionGroup",
6127 "keep-alive",
6128 "KeepAlive",
6129 "teleport",
6130 "Teleport",
6131 "suspense",
6132 "Suspense",
6133]);
6134const BUILTIN_DIRECTIVES = new Set([
6135 "bind",
6136 "on",
6137 "text",
6138 "html",
6139 "show",
6140 "if",
6141 "else",
6142 "else-if",
6143 "for",
6144 "model",
6145 "slot",
6146 "pre",
6147 "cloak",
6148 "once",
6149 "memo",
6150 "is",
6151]);
6152const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer," +
6153 "header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption," +
6154 "figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code," +
6155 "data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup," +
6156 "time,u,var,wbr,area,audio,map,track,video,embed,object,param,source," +
6157 "canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td," +
6158 "th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup," +
6159 "option,output,progress,select,textarea,details,dialog,menu," +
6160 "summary,template,blockquote,iframe,tfoot";
6161const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile," +
6162 "defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer," +
6163 "feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap," +
6164 "feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR," +
6165 "feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset," +
6166 "fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter," +
6167 "foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask," +
6168 "mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern," +
6169 "polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol," +
6170 "text,textPath,title,tspan,unknown,use,view";
6171const NATIVE_TAGS = new Set([...HTML_TAGS.split(","), ...SVG_TAGS.split(",")]);
6172const COMPILER_MACROS_AT_ROOT = new Set([
6173 "defineProps",
6174 "defineEmits",
6175 "defineExpose",
6176 "withDefaults",
6177 "defineOptions",
6178 "defineSlots",
6179 "defineModel",
6180]);
6181function capitalize(str) {
6182 return str[0].toUpperCase() + str.slice(1);
6183}
6184function analyzeScriptSetupScope(scopeManager, templateBody, df, parserOptions) {
6185 analyzeUsedInTemplateVariables(scopeManager, templateBody, df);
6186 analyzeScriptSetupVariables(scopeManager, df, parserOptions);
6187}
6188function extractVariables(scopeManager) {
6189 const scriptVariables = new Map();
6190 const globalScope = scopeManager.globalScope;
6191 if (!globalScope) {
6192 return scriptVariables;
6193 }
6194 for (const variable of globalScope.variables) {
6195 scriptVariables.set(variable.name, variable);
6196 }
6197 const moduleScope = globalScope.childScopes.find((scope) => scope.type === "module");
6198 for (const variable of (moduleScope && moduleScope.variables) || []) {
6199 scriptVariables.set(variable.name, variable);
6200 }
6201 return scriptVariables;
6202}
6203function analyzeUsedInTemplateVariables(scopeManager, templateBody, df) {
6204 const scriptVariables = extractVariables(scopeManager);
6205 const markedVariables = new Set();
6206 function markSetupReferenceVariableAsUsed(name) {
6207 if (scriptVariables.has(name)) {
6208 markVariableAsUsed(name);
6209 return true;
6210 }
6211 const camelName = camelize(name);
6212 if (scriptVariables.has(camelName)) {
6213 markVariableAsUsed(camelName);
6214 return true;
6215 }
6216 const pascalName = capitalize(camelName);
6217 if (scriptVariables.has(pascalName)) {
6218 markVariableAsUsed(pascalName);
6219 return true;
6220 }
6221 return false;
6222 }
6223 function markVariableAsUsed(nameOrRef) {
6224 let name;
6225 let isValueReference;
6226 let isTypeReference;
6227 if (typeof nameOrRef === "string") {
6228 name = nameOrRef;
6229 }
6230 else {
6231 name = nameOrRef.id.name;
6232 isValueReference = nameOrRef.isValueReference;
6233 isTypeReference = nameOrRef.isTypeReference;
6234 }
6235 const variable = scriptVariables.get(name);
6236 if (!variable || variable.identifiers.length === 0) {
6237 return;
6238 }
6239 if (markedVariables.has(name)) {
6240 return;
6241 }
6242 markedVariables.add(name);
6243 const reference = new (getEslintScope().Reference)();
6244 reference.vueUsedInTemplate = true;
6245 reference.from = variable.scope;
6246 reference.identifier = variable.identifiers[0];
6247 reference.isWrite = () => false;
6248 reference.isWriteOnly = () => false;
6249 reference.isRead = () => true;
6250 reference.isReadOnly = () => true;
6251 reference.isReadWrite = () => false;
6252 reference.isValueReference = isValueReference;
6253 reference.isTypeReference = isTypeReference;
6254 variable.references.push(reference);
6255 reference.resolved = variable;
6256 if (reference.isTypeReference) {
6257 variable.eslintUsed = true;
6258 }
6259 }
6260 function processVExpressionContainer(node) {
6261 for (const reference of node.references.filter((ref) => ref.variable == null)) {
6262 markVariableAsUsed(reference);
6263 }
6264 }
6265 function processVElement(node) {
6266 if ((node.rawName === node.name && NATIVE_TAGS.has(node.rawName)) ||
6267 BUILTIN_COMPONENTS.has(node.rawName)) {
6268 return;
6269 }
6270 if (!markSetupReferenceVariableAsUsed(node.rawName)) {
6271 const dotIndex = node.rawName.indexOf(".");
6272 if (dotIndex > 0) {
6273 markSetupReferenceVariableAsUsed(node.rawName.slice(0, dotIndex));
6274 }
6275 }
6276 }
6277 function processVAttribute(node) {
6278 if (node.directive) {
6279 if (BUILTIN_DIRECTIVES.has(node.key.name.name)) {
6280 return;
6281 }
6282 markSetupReferenceVariableAsUsed(`v-${node.key.name.rawName}`);
6283 }
6284 else if (node.key.name === "ref" && node.value) {
6285 markVariableAsUsed(node.value.value);
6286 }
6287 }
6288 if (templateBody) {
6289 traverseNodes(templateBody, {
6290 enterNode(node) {
6291 if (node.type === "VExpressionContainer") {
6292 processVExpressionContainer(node);
6293 }
6294 else if (node.type === "VElement") {
6295 processVElement(node);
6296 }
6297 else if (node.type === "VAttribute") {
6298 processVAttribute(node);
6299 }
6300 },
6301 leaveNode() {
6302 },
6303 });
6304 }
6305 for (const child of df.children) {
6306 if (child.type === "VElement") {
6307 if (isScriptSetupElement(child)) {
6308 const generic = findGenericDirective(child);
6309 if (generic) {
6310 processVExpressionContainer(generic.value);
6311 }
6312 }
6313 else if (child.name === "style") {
6314 for (const node of child.children) {
6315 if (node.type === "VExpressionContainer") {
6316 processVExpressionContainer(node);
6317 }
6318 }
6319 }
6320 }
6321 }
6322}
6323function analyzeScriptSetupVariables(scopeManager, df, parserOptions) {
6324 var _a;
6325 const globalScope = scopeManager.globalScope;
6326 if (!globalScope) {
6327 return;
6328 }
6329 const customMacros = new Set(((_a = parserOptions.vueFeatures) === null || _a === void 0 ? void 0 : _a.customMacros) &&
6330 Array.isArray(parserOptions.vueFeatures.customMacros)
6331 ? parserOptions.vueFeatures.customMacros
6332 : []);
6333 const genericDefineNames = new Set();
6334 const scriptElements = df.children.filter(isScriptElement);
6335 const scriptSetupElement = scriptElements.find(isScriptSetupElement);
6336 if (scriptSetupElement && findGenericDirective(scriptSetupElement)) {
6337 for (const variable of scriptSetupElement.variables) {
6338 if (variable.kind === "generic") {
6339 genericDefineNames.add(variable.id.name);
6340 }
6341 }
6342 }
6343 const newThrough = [];
6344 for (const reference of globalScope.through) {
6345 if (COMPILER_MACROS_AT_ROOT.has(reference.identifier.name) ||
6346 customMacros.has(reference.identifier.name)) {
6347 if (reference.from.type === "global" ||
6348 reference.from.type === "module") {
6349 addCompilerMacroVariable(reference);
6350 continue;
6351 }
6352 }
6353 if (genericDefineNames.has(reference.identifier.name)) {
6354 addGenericVariable(reference);
6355 continue;
6356 }
6357 newThrough.push(reference);
6358 }
6359 globalScope.through = newThrough;
6360 function addCompilerMacroVariable(reference) {
6361 addVariable(globalScope, reference);
6362 }
6363 function addGenericVariable(reference) {
6364 addVariable(globalScope, reference);
6365 }
6366}
6367function addVariable(scope, reference) {
6368 const name = reference.identifier.name;
6369 let variable = scope.set.get(name);
6370 if (!variable) {
6371 variable = new (getEslintScope().Variable)();
6372 variable.name = name;
6373 variable.scope = scope;
6374 scope.variables.push(variable);
6375 scope.set.set(name, variable);
6376 }
6377 reference.resolved = variable;
6378 variable.references.push(reference);
6379}
6380
6381const STARTS_WITH_LT = /^\s*</u;
6382function isVueFile(code, options) {
6383 const filePath = options.filePath || "unknown.js";
6384 return path__namespace.extname(filePath) === ".vue" || STARTS_WITH_LT.test(code);
6385}
6386function parseForESLint(code, parserOptions) {
6387 const options = Object.assign({
6388 comment: true,
6389 loc: true,
6390 range: true,
6391 tokens: true,
6392 }, parserOptions || {});
6393 let result;
6394 let document;
6395 let locationCalculator;
6396 if (!isVueFile(code, options)) {
6397 result = parseAsScript(code, options);
6398 document = null;
6399 locationCalculator = null;
6400 }
6401 else {
6402 ({ result, document, locationCalculator } = parseAsSFC(code, options));
6403 }
6404 result.services = Object.assign(result.services || {}, define(code, result.ast, document, locationCalculator, {
6405 parserOptions: options,
6406 }));
6407 return result;
6408}
6409function parse(code, options) {
6410 return parseForESLint(code, options).ast;
6411}
6412function parseAsSFC(code, options) {
6413 var _a, _b, _c;
6414 const optionsForTemplate = Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION });
6415 const skipParsingScript = options.parser === false;
6416 const tokenizer = new Tokenizer(code, optionsForTemplate);
6417 const rootAST = new Parser(tokenizer, optionsForTemplate).parse();
6418 const locationCalculator = new LocationCalculatorForHtml(tokenizer.gaps, tokenizer.lineTerminators);
6419 const scripts = rootAST.children.filter(isScriptElement);
6420 const template = rootAST.children.find(isTemplateElement);
6421 const templateLang = getLang(template) || "html";
6422 const hasTemplateTokenizer = (_a = options === null || options === void 0 ? void 0 : options.templateTokenizer) === null || _a === void 0 ? void 0 : _a[templateLang];
6423 const concreteInfo = {
6424 tokens: rootAST.tokens,
6425 comments: rootAST.comments,
6426 errors: rootAST.errors,
6427 };
6428 const templateBody = template != null && (templateLang === "html" || hasTemplateTokenizer)
6429 ? Object.assign(template, concreteInfo)
6430 : undefined;
6431 const scriptParser = getScriptParser(options.parser, () => getParserLangFromSFC(rootAST));
6432 let result;
6433 let scriptSetup;
6434 if (skipParsingScript || !scripts.length) {
6435 result = parseScript$1("", Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: scriptParser }));
6436 }
6437 else if (scripts.length === 2 &&
6438 (scriptSetup = scripts.find(isScriptSetupElement))) {
6439 result = parseScriptSetupElements(scriptSetup, scripts.find((e) => e !== scriptSetup), code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
6440 }
6441 else {
6442 result = parseScriptElement(scripts[0], code, new LinesAndColumns(tokenizer.lineTerminators), Object.assign(Object.assign({}, options), { parser: scriptParser }));
6443 }
6444 if ((_c = (_b = options.vueFeatures) === null || _b === void 0 ? void 0 : _b.styleCSSVariableInjection) !== null && _c !== void 0 ? _c : true) {
6445 const styles = rootAST.children.filter(isStyleElement);
6446 parseStyleElements(styles, locationCalculator, Object.assign(Object.assign({}, options), { parser: getScriptParser(options.parser, function* () {
6447 yield "<template>";
6448 yield getParserLangFromSFC(rootAST);
6449 }) }));
6450 }
6451 result.ast.templateBody = templateBody;
6452 if (options.eslintScopeManager) {
6453 if (scripts.some(isScriptSetupElement)) {
6454 if (!result.scopeManager) {
6455 result.scopeManager = analyzeScope(result.ast, options);
6456 }
6457 analyzeScriptSetupScope(result.scopeManager, templateBody, rootAST, options);
6458 }
6459 }
6460 return {
6461 result,
6462 locationCalculator,
6463 document: rootAST,
6464 };
6465}
6466function parseAsScript(code, options) {
6467 return parseScript$1(code, Object.assign(Object.assign({}, options), { ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, parser: getScriptParser(options.parser, () => {
6468 const ext = (path__namespace.extname(options.filePath || "unknown.js").toLowerCase() ||
6469 "")
6470 .slice(1);
6471 if (/^[jt]sx$/u.test(ext)) {
6472 return [ext, ext.slice(0, -1)];
6473 }
6474 return ext;
6475 }) }));
6476}
6477const meta = {
6478 name: "vue-eslint-parser",
6479 version: "9.4.3",
6480};
6481
6482exports.AST = index;
6483exports.meta = meta;
6484exports.parse = parse;
6485exports.parseForESLint = parseForESLint;
6486//# sourceMappingURL=index.js.map