source: node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js@ 57e58a3

Last change on this file since 57e58a3 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 26.4 KB
RevLine 
[57e58a3]1/**
2* @vue/compiler-dom v3.5.13
3* (c) 2018-present Yuxi (Evan) You and Vue contributors
4* @license MIT
5**/
6'use strict';
7
8Object.defineProperty(exports, '__esModule', { value: true });
9
10var compilerCore = require('@vue/compiler-core');
11var shared = require('@vue/shared');
12
13const V_MODEL_RADIO = Symbol(`vModelRadio` );
14const V_MODEL_CHECKBOX = Symbol(
15 `vModelCheckbox`
16);
17const V_MODEL_TEXT = Symbol(`vModelText` );
18const V_MODEL_SELECT = Symbol(
19 `vModelSelect`
20);
21const V_MODEL_DYNAMIC = Symbol(
22 `vModelDynamic`
23);
24const V_ON_WITH_MODIFIERS = Symbol(
25 `vOnModifiersGuard`
26);
27const V_ON_WITH_KEYS = Symbol(
28 `vOnKeysGuard`
29);
30const V_SHOW = Symbol(`vShow` );
31const TRANSITION = Symbol(`Transition` );
32const TRANSITION_GROUP = Symbol(
33 `TransitionGroup`
34);
35compilerCore.registerRuntimeHelpers({
36 [V_MODEL_RADIO]: `vModelRadio`,
37 [V_MODEL_CHECKBOX]: `vModelCheckbox`,
38 [V_MODEL_TEXT]: `vModelText`,
39 [V_MODEL_SELECT]: `vModelSelect`,
40 [V_MODEL_DYNAMIC]: `vModelDynamic`,
41 [V_ON_WITH_MODIFIERS]: `withModifiers`,
42 [V_ON_WITH_KEYS]: `withKeys`,
43 [V_SHOW]: `vShow`,
44 [TRANSITION]: `Transition`,
45 [TRANSITION_GROUP]: `TransitionGroup`
46});
47
48const parserOptions = {
49 parseMode: "html",
50 isVoidTag: shared.isVoidTag,
51 isNativeTag: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag) || shared.isMathMLTag(tag),
52 isPreTag: (tag) => tag === "pre",
53 isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
54 decodeEntities: void 0,
55 isBuiltInComponent: (tag) => {
56 if (tag === "Transition" || tag === "transition") {
57 return TRANSITION;
58 } else if (tag === "TransitionGroup" || tag === "transition-group") {
59 return TRANSITION_GROUP;
60 }
61 },
62 // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
63 getNamespace(tag, parent, rootNamespace) {
64 let ns = parent ? parent.ns : rootNamespace;
65 if (parent && ns === 2) {
66 if (parent.tag === "annotation-xml") {
67 if (tag === "svg") {
68 return 1;
69 }
70 if (parent.props.some(
71 (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
72 )) {
73 ns = 0;
74 }
75 } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
76 ns = 0;
77 }
78 } else if (parent && ns === 1) {
79 if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
80 ns = 0;
81 }
82 }
83 if (ns === 0) {
84 if (tag === "svg") {
85 return 1;
86 }
87 if (tag === "math") {
88 return 2;
89 }
90 }
91 return ns;
92 }
93};
94
95const transformStyle = (node) => {
96 if (node.type === 1) {
97 node.props.forEach((p, i) => {
98 if (p.type === 6 && p.name === "style" && p.value) {
99 node.props[i] = {
100 type: 7,
101 name: `bind`,
102 arg: compilerCore.createSimpleExpression(`style`, true, p.loc),
103 exp: parseInlineCSS(p.value.content, p.loc),
104 modifiers: [],
105 loc: p.loc
106 };
107 }
108 });
109 }
110};
111const parseInlineCSS = (cssText, loc) => {
112 const normalized = shared.parseStringStyle(cssText);
113 return compilerCore.createSimpleExpression(
114 JSON.stringify(normalized),
115 false,
116 loc,
117 3
118 );
119};
120
121function createDOMCompilerError(code, loc) {
122 return compilerCore.createCompilerError(
123 code,
124 loc,
125 DOMErrorMessages
126 );
127}
128const DOMErrorCodes = {
129 "X_V_HTML_NO_EXPRESSION": 53,
130 "53": "X_V_HTML_NO_EXPRESSION",
131 "X_V_HTML_WITH_CHILDREN": 54,
132 "54": "X_V_HTML_WITH_CHILDREN",
133 "X_V_TEXT_NO_EXPRESSION": 55,
134 "55": "X_V_TEXT_NO_EXPRESSION",
135 "X_V_TEXT_WITH_CHILDREN": 56,
136 "56": "X_V_TEXT_WITH_CHILDREN",
137 "X_V_MODEL_ON_INVALID_ELEMENT": 57,
138 "57": "X_V_MODEL_ON_INVALID_ELEMENT",
139 "X_V_MODEL_ARG_ON_ELEMENT": 58,
140 "58": "X_V_MODEL_ARG_ON_ELEMENT",
141 "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
142 "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
143 "X_V_MODEL_UNNECESSARY_VALUE": 60,
144 "60": "X_V_MODEL_UNNECESSARY_VALUE",
145 "X_V_SHOW_NO_EXPRESSION": 61,
146 "61": "X_V_SHOW_NO_EXPRESSION",
147 "X_TRANSITION_INVALID_CHILDREN": 62,
148 "62": "X_TRANSITION_INVALID_CHILDREN",
149 "X_IGNORED_SIDE_EFFECT_TAG": 63,
150 "63": "X_IGNORED_SIDE_EFFECT_TAG",
151 "__EXTEND_POINT__": 64,
152 "64": "__EXTEND_POINT__"
153};
154const DOMErrorMessages = {
155 [53]: `v-html is missing expression.`,
156 [54]: `v-html will override element children.`,
157 [55]: `v-text is missing expression.`,
158 [56]: `v-text will override element children.`,
159 [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
160 [58]: `v-model argument is not supported on plain elements.`,
161 [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
162 [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
163 [61]: `v-show is missing expression.`,
164 [62]: `<Transition> expects exactly one child element or component.`,
165 [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
166};
167
168const transformVHtml = (dir, node, context) => {
169 const { exp, loc } = dir;
170 if (!exp) {
171 context.onError(
172 createDOMCompilerError(53, loc)
173 );
174 }
175 if (node.children.length) {
176 context.onError(
177 createDOMCompilerError(54, loc)
178 );
179 node.children.length = 0;
180 }
181 return {
182 props: [
183 compilerCore.createObjectProperty(
184 compilerCore.createSimpleExpression(`innerHTML`, true, loc),
185 exp || compilerCore.createSimpleExpression("", true)
186 )
187 ]
188 };
189};
190
191const transformVText = (dir, node, context) => {
192 const { exp, loc } = dir;
193 if (!exp) {
194 context.onError(
195 createDOMCompilerError(55, loc)
196 );
197 }
198 if (node.children.length) {
199 context.onError(
200 createDOMCompilerError(56, loc)
201 );
202 node.children.length = 0;
203 }
204 return {
205 props: [
206 compilerCore.createObjectProperty(
207 compilerCore.createSimpleExpression(`textContent`, true),
208 exp ? compilerCore.getConstantType(exp, context) > 0 ? exp : compilerCore.createCallExpression(
209 context.helperString(compilerCore.TO_DISPLAY_STRING),
210 [exp],
211 loc
212 ) : compilerCore.createSimpleExpression("", true)
213 )
214 ]
215 };
216};
217
218const transformModel = (dir, node, context) => {
219 const baseResult = compilerCore.transformModel(dir, node, context);
220 if (!baseResult.props.length || node.tagType === 1) {
221 return baseResult;
222 }
223 if (dir.arg) {
224 context.onError(
225 createDOMCompilerError(
226 58,
227 dir.arg.loc
228 )
229 );
230 }
231 function checkDuplicatedValue() {
232 const value = compilerCore.findDir(node, "bind");
233 if (value && compilerCore.isStaticArgOf(value.arg, "value")) {
234 context.onError(
235 createDOMCompilerError(
236 60,
237 value.loc
238 )
239 );
240 }
241 }
242 const { tag } = node;
243 const isCustomElement = context.isCustomElement(tag);
244 if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
245 let directiveToUse = V_MODEL_TEXT;
246 let isInvalidType = false;
247 if (tag === "input" || isCustomElement) {
248 const type = compilerCore.findProp(node, `type`);
249 if (type) {
250 if (type.type === 7) {
251 directiveToUse = V_MODEL_DYNAMIC;
252 } else if (type.value) {
253 switch (type.value.content) {
254 case "radio":
255 directiveToUse = V_MODEL_RADIO;
256 break;
257 case "checkbox":
258 directiveToUse = V_MODEL_CHECKBOX;
259 break;
260 case "file":
261 isInvalidType = true;
262 context.onError(
263 createDOMCompilerError(
264 59,
265 dir.loc
266 )
267 );
268 break;
269 default:
270 checkDuplicatedValue();
271 break;
272 }
273 }
274 } else if (compilerCore.hasDynamicKeyVBind(node)) {
275 directiveToUse = V_MODEL_DYNAMIC;
276 } else {
277 checkDuplicatedValue();
278 }
279 } else if (tag === "select") {
280 directiveToUse = V_MODEL_SELECT;
281 } else {
282 checkDuplicatedValue();
283 }
284 if (!isInvalidType) {
285 baseResult.needRuntime = context.helper(directiveToUse);
286 }
287 } else {
288 context.onError(
289 createDOMCompilerError(
290 57,
291 dir.loc
292 )
293 );
294 }
295 baseResult.props = baseResult.props.filter(
296 (p) => !(p.key.type === 4 && p.key.content === "modelValue")
297 );
298 return baseResult;
299};
300
301const isEventOptionModifier = /* @__PURE__ */ shared.makeMap(`passive,once,capture`);
302const isNonKeyModifier = /* @__PURE__ */ shared.makeMap(
303 // event propagation management
304 `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
305);
306const maybeKeyModifier = /* @__PURE__ */ shared.makeMap("left,right");
307const isKeyboardEvent = /* @__PURE__ */ shared.makeMap(`onkeyup,onkeydown,onkeypress`);
308const resolveModifiers = (key, modifiers, context, loc) => {
309 const keyModifiers = [];
310 const nonKeyModifiers = [];
311 const eventOptionModifiers = [];
312 for (let i = 0; i < modifiers.length; i++) {
313 const modifier = modifiers[i].content;
314 if (modifier === "native" && compilerCore.checkCompatEnabled(
315 "COMPILER_V_ON_NATIVE",
316 context,
317 loc
318 )) {
319 eventOptionModifiers.push(modifier);
320 } else if (isEventOptionModifier(modifier)) {
321 eventOptionModifiers.push(modifier);
322 } else {
323 if (maybeKeyModifier(modifier)) {
324 if (compilerCore.isStaticExp(key)) {
325 if (isKeyboardEvent(key.content.toLowerCase())) {
326 keyModifiers.push(modifier);
327 } else {
328 nonKeyModifiers.push(modifier);
329 }
330 } else {
331 keyModifiers.push(modifier);
332 nonKeyModifiers.push(modifier);
333 }
334 } else {
335 if (isNonKeyModifier(modifier)) {
336 nonKeyModifiers.push(modifier);
337 } else {
338 keyModifiers.push(modifier);
339 }
340 }
341 }
342 }
343 return {
344 keyModifiers,
345 nonKeyModifiers,
346 eventOptionModifiers
347 };
348};
349const transformClick = (key, event) => {
350 const isStaticClick = compilerCore.isStaticExp(key) && key.content.toLowerCase() === "onclick";
351 return isStaticClick ? compilerCore.createSimpleExpression(event, true) : key.type !== 4 ? compilerCore.createCompoundExpression([
352 `(`,
353 key,
354 `) === "onClick" ? "${event}" : (`,
355 key,
356 `)`
357 ]) : key;
358};
359const transformOn = (dir, node, context) => {
360 return compilerCore.transformOn(dir, node, context, (baseResult) => {
361 const { modifiers } = dir;
362 if (!modifiers.length) return baseResult;
363 let { key, value: handlerExp } = baseResult.props[0];
364 const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
365 if (nonKeyModifiers.includes("right")) {
366 key = transformClick(key, `onContextmenu`);
367 }
368 if (nonKeyModifiers.includes("middle")) {
369 key = transformClick(key, `onMouseup`);
370 }
371 if (nonKeyModifiers.length) {
372 handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
373 handlerExp,
374 JSON.stringify(nonKeyModifiers)
375 ]);
376 }
377 if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
378 (!compilerCore.isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
379 handlerExp = compilerCore.createCallExpression(context.helper(V_ON_WITH_KEYS), [
380 handlerExp,
381 JSON.stringify(keyModifiers)
382 ]);
383 }
384 if (eventOptionModifiers.length) {
385 const modifierPostfix = eventOptionModifiers.map(shared.capitalize).join("");
386 key = compilerCore.isStaticExp(key) ? compilerCore.createSimpleExpression(`${key.content}${modifierPostfix}`, true) : compilerCore.createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
387 }
388 return {
389 props: [compilerCore.createObjectProperty(key, handlerExp)]
390 };
391 });
392};
393
394const transformShow = (dir, node, context) => {
395 const { exp, loc } = dir;
396 if (!exp) {
397 context.onError(
398 createDOMCompilerError(61, loc)
399 );
400 }
401 return {
402 props: [],
403 needRuntime: context.helper(V_SHOW)
404 };
405};
406
407const transformTransition = (node, context) => {
408 if (node.type === 1 && node.tagType === 1) {
409 const component = context.isBuiltInComponent(node.tag);
410 if (component === TRANSITION) {
411 return () => {
412 if (!node.children.length) {
413 return;
414 }
415 if (hasMultipleChildren(node)) {
416 context.onError(
417 createDOMCompilerError(
418 62,
419 {
420 start: node.children[0].loc.start,
421 end: node.children[node.children.length - 1].loc.end,
422 source: ""
423 }
424 )
425 );
426 }
427 const child = node.children[0];
428 if (child.type === 1) {
429 for (const p of child.props) {
430 if (p.type === 7 && p.name === "show") {
431 node.props.push({
432 type: 6,
433 name: "persisted",
434 nameLoc: node.loc,
435 value: void 0,
436 loc: node.loc
437 });
438 }
439 }
440 }
441 };
442 }
443 }
444};
445function hasMultipleChildren(node) {
446 const children = node.children = node.children.filter(
447 (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
448 );
449 const child = children[0];
450 return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
451}
452
453const expReplaceRE = /__VUE_EXP_START__(.*?)__VUE_EXP_END__/g;
454const stringifyStatic = (children, context, parent) => {
455 if (context.scopes.vSlot > 0) {
456 return;
457 }
458 const isParentCached = parent.type === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 20;
459 let nc = 0;
460 let ec = 0;
461 const currentChunk = [];
462 const stringifyCurrentChunk = (currentIndex) => {
463 if (nc >= 20 || ec >= 5) {
464 const staticCall = compilerCore.createCallExpression(context.helper(compilerCore.CREATE_STATIC), [
465 JSON.stringify(
466 currentChunk.map((node) => stringifyNode(node, context)).join("")
467 ).replace(expReplaceRE, `" + $1 + "`),
468 // the 2nd argument indicates the number of DOM nodes this static vnode
469 // will insert / hydrate
470 String(currentChunk.length)
471 ]);
472 const deleteCount = currentChunk.length - 1;
473 if (isParentCached) {
474 children.splice(
475 currentIndex - currentChunk.length,
476 currentChunk.length,
477 // @ts-expect-error
478 staticCall
479 );
480 } else {
481 currentChunk[0].codegenNode.value = staticCall;
482 if (currentChunk.length > 1) {
483 children.splice(currentIndex - currentChunk.length + 1, deleteCount);
484 const cacheIndex = context.cached.indexOf(
485 currentChunk[currentChunk.length - 1].codegenNode
486 );
487 if (cacheIndex > -1) {
488 for (let i2 = cacheIndex; i2 < context.cached.length; i2++) {
489 const c = context.cached[i2];
490 if (c) c.index -= deleteCount;
491 }
492 context.cached.splice(cacheIndex - deleteCount + 1, deleteCount);
493 }
494 }
495 }
496 return deleteCount;
497 }
498 return 0;
499 };
500 let i = 0;
501 for (; i < children.length; i++) {
502 const child = children[i];
503 const isCached = isParentCached || getCachedNode(child);
504 if (isCached) {
505 const result = analyzeNode(child);
506 if (result) {
507 nc += result[0];
508 ec += result[1];
509 currentChunk.push(child);
510 continue;
511 }
512 }
513 i -= stringifyCurrentChunk(i);
514 nc = 0;
515 ec = 0;
516 currentChunk.length = 0;
517 }
518 stringifyCurrentChunk(i);
519};
520const getCachedNode = (node) => {
521 if ((node.type === 1 && node.tagType === 0 || node.type === 12) && node.codegenNode && node.codegenNode.type === 20) {
522 return node.codegenNode;
523 }
524};
525const dataAriaRE = /^(data|aria)-/;
526const isStringifiableAttr = (name, ns) => {
527 return (ns === 0 ? shared.isKnownHtmlAttr(name) : ns === 1 ? shared.isKnownSvgAttr(name) : ns === 2 ? shared.isKnownMathMLAttr(name) : false) || dataAriaRE.test(name);
528};
529const isNonStringifiable = /* @__PURE__ */ shared.makeMap(
530 `caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
531);
532function analyzeNode(node) {
533 if (node.type === 1 && isNonStringifiable(node.tag)) {
534 return false;
535 }
536 if (node.type === 12) {
537 return [1, 0];
538 }
539 let nc = 1;
540 let ec = node.props.length > 0 ? 1 : 0;
541 let bailed = false;
542 const bail = () => {
543 bailed = true;
544 return false;
545 };
546 function walk(node2) {
547 const isOptionTag = node2.tag === "option" && node2.ns === 0;
548 for (let i = 0; i < node2.props.length; i++) {
549 const p = node2.props[i];
550 if (p.type === 6 && !isStringifiableAttr(p.name, node2.ns)) {
551 return bail();
552 }
553 if (p.type === 7 && p.name === "bind") {
554 if (p.arg && (p.arg.type === 8 || p.arg.isStatic && !isStringifiableAttr(p.arg.content, node2.ns))) {
555 return bail();
556 }
557 if (p.exp && (p.exp.type === 8 || p.exp.constType < 3)) {
558 return bail();
559 }
560 if (isOptionTag && compilerCore.isStaticArgOf(p.arg, "value") && p.exp && !p.exp.isStatic) {
561 return bail();
562 }
563 }
564 }
565 for (let i = 0; i < node2.children.length; i++) {
566 nc++;
567 const child = node2.children[i];
568 if (child.type === 1) {
569 if (child.props.length > 0) {
570 ec++;
571 }
572 walk(child);
573 if (bailed) {
574 return false;
575 }
576 }
577 }
578 return true;
579 }
580 return walk(node) ? [nc, ec] : false;
581}
582function stringifyNode(node, context) {
583 if (shared.isString(node)) {
584 return node;
585 }
586 if (shared.isSymbol(node)) {
587 return ``;
588 }
589 switch (node.type) {
590 case 1:
591 return stringifyElement(node, context);
592 case 2:
593 return shared.escapeHtml(node.content);
594 case 3:
595 return `<!--${shared.escapeHtml(node.content)}-->`;
596 case 5:
597 return shared.escapeHtml(shared.toDisplayString(evaluateConstant(node.content)));
598 case 8:
599 return shared.escapeHtml(evaluateConstant(node));
600 case 12:
601 return stringifyNode(node.content, context);
602 default:
603 return "";
604 }
605}
606function stringifyElement(node, context) {
607 let res = `<${node.tag}`;
608 let innerHTML = "";
609 for (let i = 0; i < node.props.length; i++) {
610 const p = node.props[i];
611 if (p.type === 6) {
612 res += ` ${p.name}`;
613 if (p.value) {
614 res += `="${shared.escapeHtml(p.value.content)}"`;
615 }
616 } else if (p.type === 7) {
617 if (p.name === "bind") {
618 const exp = p.exp;
619 if (exp.content[0] === "_") {
620 res += ` ${p.arg.content}="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"`;
621 continue;
622 }
623 if (shared.isBooleanAttr(p.arg.content) && exp.content === "false") {
624 continue;
625 }
626 let evaluated = evaluateConstant(exp);
627 if (evaluated != null) {
628 const arg = p.arg && p.arg.content;
629 if (arg === "class") {
630 evaluated = shared.normalizeClass(evaluated);
631 } else if (arg === "style") {
632 evaluated = shared.stringifyStyle(shared.normalizeStyle(evaluated));
633 }
634 res += ` ${p.arg.content}="${shared.escapeHtml(
635 evaluated
636 )}"`;
637 }
638 } else if (p.name === "html") {
639 innerHTML = evaluateConstant(p.exp);
640 } else if (p.name === "text") {
641 innerHTML = shared.escapeHtml(
642 shared.toDisplayString(evaluateConstant(p.exp))
643 );
644 }
645 }
646 }
647 if (context.scopeId) {
648 res += ` ${context.scopeId}`;
649 }
650 res += `>`;
651 if (innerHTML) {
652 res += innerHTML;
653 } else {
654 for (let i = 0; i < node.children.length; i++) {
655 res += stringifyNode(node.children[i], context);
656 }
657 }
658 if (!shared.isVoidTag(node.tag)) {
659 res += `</${node.tag}>`;
660 }
661 return res;
662}
663function evaluateConstant(exp) {
664 if (exp.type === 4) {
665 return new Function(`return (${exp.content})`)();
666 } else {
667 let res = ``;
668 exp.children.forEach((c) => {
669 if (shared.isString(c) || shared.isSymbol(c)) {
670 return;
671 }
672 if (c.type === 2) {
673 res += c.content;
674 } else if (c.type === 5) {
675 res += shared.toDisplayString(evaluateConstant(c.content));
676 } else {
677 res += evaluateConstant(c);
678 }
679 });
680 return res;
681 }
682}
683
684const ignoreSideEffectTags = (node, context) => {
685 if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
686 context.onError(
687 createDOMCompilerError(
688 63,
689 node.loc
690 )
691 );
692 context.removeNode();
693 }
694};
695
696function isValidHTMLNesting(parent, child) {
697 if (parent in onlyValidChildren) {
698 return onlyValidChildren[parent].has(child);
699 }
700 if (child in onlyValidParents) {
701 return onlyValidParents[child].has(parent);
702 }
703 if (parent in knownInvalidChildren) {
704 if (knownInvalidChildren[parent].has(child)) return false;
705 }
706 if (child in knownInvalidParents) {
707 if (knownInvalidParents[child].has(parent)) return false;
708 }
709 return true;
710}
711const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
712const emptySet = /* @__PURE__ */ new Set([]);
713const onlyValidChildren = {
714 head: /* @__PURE__ */ new Set([
715 "base",
716 "basefront",
717 "bgsound",
718 "link",
719 "meta",
720 "title",
721 "noscript",
722 "noframes",
723 "style",
724 "script",
725 "template"
726 ]),
727 optgroup: /* @__PURE__ */ new Set(["option"]),
728 select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
729 // table
730 table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
731 tr: /* @__PURE__ */ new Set(["td", "th"]),
732 colgroup: /* @__PURE__ */ new Set(["col"]),
733 tbody: /* @__PURE__ */ new Set(["tr"]),
734 thead: /* @__PURE__ */ new Set(["tr"]),
735 tfoot: /* @__PURE__ */ new Set(["tr"]),
736 // these elements can not have any children elements
737 script: emptySet,
738 iframe: emptySet,
739 option: emptySet,
740 textarea: emptySet,
741 style: emptySet,
742 title: emptySet
743};
744const onlyValidParents = {
745 // sections
746 html: emptySet,
747 body: /* @__PURE__ */ new Set(["html"]),
748 head: /* @__PURE__ */ new Set(["html"]),
749 // table
750 td: /* @__PURE__ */ new Set(["tr"]),
751 colgroup: /* @__PURE__ */ new Set(["table"]),
752 caption: /* @__PURE__ */ new Set(["table"]),
753 tbody: /* @__PURE__ */ new Set(["table"]),
754 tfoot: /* @__PURE__ */ new Set(["table"]),
755 col: /* @__PURE__ */ new Set(["colgroup"]),
756 th: /* @__PURE__ */ new Set(["tr"]),
757 thead: /* @__PURE__ */ new Set(["table"]),
758 tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
759 // data list
760 dd: /* @__PURE__ */ new Set(["dl", "div"]),
761 dt: /* @__PURE__ */ new Set(["dl", "div"]),
762 // other
763 figcaption: /* @__PURE__ */ new Set(["figure"]),
764 // li: new Set(["ul", "ol"]),
765 summary: /* @__PURE__ */ new Set(["details"]),
766 area: /* @__PURE__ */ new Set(["map"])
767};
768const knownInvalidChildren = {
769 p: /* @__PURE__ */ new Set([
770 "address",
771 "article",
772 "aside",
773 "blockquote",
774 "center",
775 "details",
776 "dialog",
777 "dir",
778 "div",
779 "dl",
780 "fieldset",
781 "figure",
782 "footer",
783 "form",
784 "h1",
785 "h2",
786 "h3",
787 "h4",
788 "h5",
789 "h6",
790 "header",
791 "hgroup",
792 "hr",
793 "li",
794 "main",
795 "nav",
796 "menu",
797 "ol",
798 "p",
799 "pre",
800 "section",
801 "table",
802 "ul"
803 ]),
804 svg: /* @__PURE__ */ new Set([
805 "b",
806 "blockquote",
807 "br",
808 "code",
809 "dd",
810 "div",
811 "dl",
812 "dt",
813 "em",
814 "embed",
815 "h1",
816 "h2",
817 "h3",
818 "h4",
819 "h5",
820 "h6",
821 "hr",
822 "i",
823 "img",
824 "li",
825 "menu",
826 "meta",
827 "ol",
828 "p",
829 "pre",
830 "ruby",
831 "s",
832 "small",
833 "span",
834 "strong",
835 "sub",
836 "sup",
837 "table",
838 "u",
839 "ul",
840 "var"
841 ])
842};
843const knownInvalidParents = {
844 a: /* @__PURE__ */ new Set(["a"]),
845 button: /* @__PURE__ */ new Set(["button"]),
846 dd: /* @__PURE__ */ new Set(["dd", "dt"]),
847 dt: /* @__PURE__ */ new Set(["dd", "dt"]),
848 form: /* @__PURE__ */ new Set(["form"]),
849 li: /* @__PURE__ */ new Set(["li"]),
850 h1: headings,
851 h2: headings,
852 h3: headings,
853 h4: headings,
854 h5: headings,
855 h6: headings
856};
857
858const validateHtmlNesting = (node, context) => {
859 if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
860 const error = new SyntaxError(
861 `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
862 );
863 error.loc = node.loc;
864 context.onWarn(error);
865 }
866};
867
868const DOMNodeTransforms = [
869 transformStyle,
870 ...[transformTransition, validateHtmlNesting]
871];
872const DOMDirectiveTransforms = {
873 cloak: compilerCore.noopDirectiveTransform,
874 html: transformVHtml,
875 text: transformVText,
876 model: transformModel,
877 // override compiler-core
878 on: transformOn,
879 // override compiler-core
880 show: transformShow
881};
882function compile(src, options = {}) {
883 return compilerCore.baseCompile(
884 src,
885 shared.extend({}, parserOptions, options, {
886 nodeTransforms: [
887 // ignore <script> and <tag>
888 // this is not put inside DOMNodeTransforms because that list is used
889 // by compiler-ssr to generate vnode fallback branches
890 ignoreSideEffectTags,
891 ...DOMNodeTransforms,
892 ...options.nodeTransforms || []
893 ],
894 directiveTransforms: shared.extend(
895 {},
896 DOMDirectiveTransforms,
897 options.directiveTransforms || {}
898 ),
899 transformHoist: stringifyStatic
900 })
901 );
902}
903function parse(template, options = {}) {
904 return compilerCore.baseParse(template, shared.extend({}, parserOptions, options));
905}
906
907exports.DOMDirectiveTransforms = DOMDirectiveTransforms;
908exports.DOMErrorCodes = DOMErrorCodes;
909exports.DOMErrorMessages = DOMErrorMessages;
910exports.DOMNodeTransforms = DOMNodeTransforms;
911exports.TRANSITION = TRANSITION;
912exports.TRANSITION_GROUP = TRANSITION_GROUP;
913exports.V_MODEL_CHECKBOX = V_MODEL_CHECKBOX;
914exports.V_MODEL_DYNAMIC = V_MODEL_DYNAMIC;
915exports.V_MODEL_RADIO = V_MODEL_RADIO;
916exports.V_MODEL_SELECT = V_MODEL_SELECT;
917exports.V_MODEL_TEXT = V_MODEL_TEXT;
918exports.V_ON_WITH_KEYS = V_ON_WITH_KEYS;
919exports.V_ON_WITH_MODIFIERS = V_ON_WITH_MODIFIERS;
920exports.V_SHOW = V_SHOW;
921exports.compile = compile;
922exports.createDOMCompilerError = createDOMCompilerError;
923exports.parse = parse;
924exports.parserOptions = parserOptions;
925exports.transformStyle = transformStyle;
926Object.keys(compilerCore).forEach(function (k) {
927 if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = compilerCore[k];
928});
Note: See TracBrowser for help on using the repository browser.