source: node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js

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

Initial commit

  • Property mode set to 100644
File size: 192.2 KB
Line 
1/**
2* @vue/compiler-core 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 shared = require('@vue/shared');
11var decode_js = require('entities/lib/decode.js');
12var parser = require('@babel/parser');
13var estreeWalker = require('estree-walker');
14var sourceMapJs = require('source-map-js');
15
16const FRAGMENT = Symbol(``);
17const TELEPORT = Symbol(``);
18const SUSPENSE = Symbol(``);
19const KEEP_ALIVE = Symbol(``);
20const BASE_TRANSITION = Symbol(
21 ``
22);
23const OPEN_BLOCK = Symbol(``);
24const CREATE_BLOCK = Symbol(``);
25const CREATE_ELEMENT_BLOCK = Symbol(
26 ``
27);
28const CREATE_VNODE = Symbol(``);
29const CREATE_ELEMENT_VNODE = Symbol(
30 ``
31);
32const CREATE_COMMENT = Symbol(
33 ``
34);
35const CREATE_TEXT = Symbol(
36 ``
37);
38const CREATE_STATIC = Symbol(
39 ``
40);
41const RESOLVE_COMPONENT = Symbol(
42 ``
43);
44const RESOLVE_DYNAMIC_COMPONENT = Symbol(
45 ``
46);
47const RESOLVE_DIRECTIVE = Symbol(
48 ``
49);
50const RESOLVE_FILTER = Symbol(
51 ``
52);
53const WITH_DIRECTIVES = Symbol(
54 ``
55);
56const RENDER_LIST = Symbol(``);
57const RENDER_SLOT = Symbol(``);
58const CREATE_SLOTS = Symbol(``);
59const TO_DISPLAY_STRING = Symbol(
60 ``
61);
62const MERGE_PROPS = Symbol(``);
63const NORMALIZE_CLASS = Symbol(
64 ``
65);
66const NORMALIZE_STYLE = Symbol(
67 ``
68);
69const NORMALIZE_PROPS = Symbol(
70 ``
71);
72const GUARD_REACTIVE_PROPS = Symbol(
73 ``
74);
75const TO_HANDLERS = Symbol(``);
76const CAMELIZE = Symbol(``);
77const CAPITALIZE = Symbol(``);
78const TO_HANDLER_KEY = Symbol(
79 ``
80);
81const SET_BLOCK_TRACKING = Symbol(
82 ``
83);
84const PUSH_SCOPE_ID = Symbol(``);
85const POP_SCOPE_ID = Symbol(``);
86const WITH_CTX = Symbol(``);
87const UNREF = Symbol(``);
88const IS_REF = Symbol(``);
89const WITH_MEMO = Symbol(``);
90const IS_MEMO_SAME = Symbol(``);
91const helperNameMap = {
92 [FRAGMENT]: `Fragment`,
93 [TELEPORT]: `Teleport`,
94 [SUSPENSE]: `Suspense`,
95 [KEEP_ALIVE]: `KeepAlive`,
96 [BASE_TRANSITION]: `BaseTransition`,
97 [OPEN_BLOCK]: `openBlock`,
98 [CREATE_BLOCK]: `createBlock`,
99 [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
100 [CREATE_VNODE]: `createVNode`,
101 [CREATE_ELEMENT_VNODE]: `createElementVNode`,
102 [CREATE_COMMENT]: `createCommentVNode`,
103 [CREATE_TEXT]: `createTextVNode`,
104 [CREATE_STATIC]: `createStaticVNode`,
105 [RESOLVE_COMPONENT]: `resolveComponent`,
106 [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
107 [RESOLVE_DIRECTIVE]: `resolveDirective`,
108 [RESOLVE_FILTER]: `resolveFilter`,
109 [WITH_DIRECTIVES]: `withDirectives`,
110 [RENDER_LIST]: `renderList`,
111 [RENDER_SLOT]: `renderSlot`,
112 [CREATE_SLOTS]: `createSlots`,
113 [TO_DISPLAY_STRING]: `toDisplayString`,
114 [MERGE_PROPS]: `mergeProps`,
115 [NORMALIZE_CLASS]: `normalizeClass`,
116 [NORMALIZE_STYLE]: `normalizeStyle`,
117 [NORMALIZE_PROPS]: `normalizeProps`,
118 [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
119 [TO_HANDLERS]: `toHandlers`,
120 [CAMELIZE]: `camelize`,
121 [CAPITALIZE]: `capitalize`,
122 [TO_HANDLER_KEY]: `toHandlerKey`,
123 [SET_BLOCK_TRACKING]: `setBlockTracking`,
124 [PUSH_SCOPE_ID]: `pushScopeId`,
125 [POP_SCOPE_ID]: `popScopeId`,
126 [WITH_CTX]: `withCtx`,
127 [UNREF]: `unref`,
128 [IS_REF]: `isRef`,
129 [WITH_MEMO]: `withMemo`,
130 [IS_MEMO_SAME]: `isMemoSame`
131};
132function registerRuntimeHelpers(helpers) {
133 Object.getOwnPropertySymbols(helpers).forEach((s) => {
134 helperNameMap[s] = helpers[s];
135 });
136}
137
138const Namespaces = {
139 "HTML": 0,
140 "0": "HTML",
141 "SVG": 1,
142 "1": "SVG",
143 "MATH_ML": 2,
144 "2": "MATH_ML"
145};
146const NodeTypes = {
147 "ROOT": 0,
148 "0": "ROOT",
149 "ELEMENT": 1,
150 "1": "ELEMENT",
151 "TEXT": 2,
152 "2": "TEXT",
153 "COMMENT": 3,
154 "3": "COMMENT",
155 "SIMPLE_EXPRESSION": 4,
156 "4": "SIMPLE_EXPRESSION",
157 "INTERPOLATION": 5,
158 "5": "INTERPOLATION",
159 "ATTRIBUTE": 6,
160 "6": "ATTRIBUTE",
161 "DIRECTIVE": 7,
162 "7": "DIRECTIVE",
163 "COMPOUND_EXPRESSION": 8,
164 "8": "COMPOUND_EXPRESSION",
165 "IF": 9,
166 "9": "IF",
167 "IF_BRANCH": 10,
168 "10": "IF_BRANCH",
169 "FOR": 11,
170 "11": "FOR",
171 "TEXT_CALL": 12,
172 "12": "TEXT_CALL",
173 "VNODE_CALL": 13,
174 "13": "VNODE_CALL",
175 "JS_CALL_EXPRESSION": 14,
176 "14": "JS_CALL_EXPRESSION",
177 "JS_OBJECT_EXPRESSION": 15,
178 "15": "JS_OBJECT_EXPRESSION",
179 "JS_PROPERTY": 16,
180 "16": "JS_PROPERTY",
181 "JS_ARRAY_EXPRESSION": 17,
182 "17": "JS_ARRAY_EXPRESSION",
183 "JS_FUNCTION_EXPRESSION": 18,
184 "18": "JS_FUNCTION_EXPRESSION",
185 "JS_CONDITIONAL_EXPRESSION": 19,
186 "19": "JS_CONDITIONAL_EXPRESSION",
187 "JS_CACHE_EXPRESSION": 20,
188 "20": "JS_CACHE_EXPRESSION",
189 "JS_BLOCK_STATEMENT": 21,
190 "21": "JS_BLOCK_STATEMENT",
191 "JS_TEMPLATE_LITERAL": 22,
192 "22": "JS_TEMPLATE_LITERAL",
193 "JS_IF_STATEMENT": 23,
194 "23": "JS_IF_STATEMENT",
195 "JS_ASSIGNMENT_EXPRESSION": 24,
196 "24": "JS_ASSIGNMENT_EXPRESSION",
197 "JS_SEQUENCE_EXPRESSION": 25,
198 "25": "JS_SEQUENCE_EXPRESSION",
199 "JS_RETURN_STATEMENT": 26,
200 "26": "JS_RETURN_STATEMENT"
201};
202const ElementTypes = {
203 "ELEMENT": 0,
204 "0": "ELEMENT",
205 "COMPONENT": 1,
206 "1": "COMPONENT",
207 "SLOT": 2,
208 "2": "SLOT",
209 "TEMPLATE": 3,
210 "3": "TEMPLATE"
211};
212const ConstantTypes = {
213 "NOT_CONSTANT": 0,
214 "0": "NOT_CONSTANT",
215 "CAN_SKIP_PATCH": 1,
216 "1": "CAN_SKIP_PATCH",
217 "CAN_CACHE": 2,
218 "2": "CAN_CACHE",
219 "CAN_STRINGIFY": 3,
220 "3": "CAN_STRINGIFY"
221};
222const locStub = {
223 start: { line: 1, column: 1, offset: 0 },
224 end: { line: 1, column: 1, offset: 0 },
225 source: ""
226};
227function createRoot(children, source = "") {
228 return {
229 type: 0,
230 source,
231 children,
232 helpers: /* @__PURE__ */ new Set(),
233 components: [],
234 directives: [],
235 hoists: [],
236 imports: [],
237 cached: [],
238 temps: 0,
239 codegenNode: void 0,
240 loc: locStub
241 };
242}
243function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
244 if (context) {
245 if (isBlock) {
246 context.helper(OPEN_BLOCK);
247 context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
248 } else {
249 context.helper(getVNodeHelper(context.inSSR, isComponent));
250 }
251 if (directives) {
252 context.helper(WITH_DIRECTIVES);
253 }
254 }
255 return {
256 type: 13,
257 tag,
258 props,
259 children,
260 patchFlag,
261 dynamicProps,
262 directives,
263 isBlock,
264 disableTracking,
265 isComponent,
266 loc
267 };
268}
269function createArrayExpression(elements, loc = locStub) {
270 return {
271 type: 17,
272 loc,
273 elements
274 };
275}
276function createObjectExpression(properties, loc = locStub) {
277 return {
278 type: 15,
279 loc,
280 properties
281 };
282}
283function createObjectProperty(key, value) {
284 return {
285 type: 16,
286 loc: locStub,
287 key: shared.isString(key) ? createSimpleExpression(key, true) : key,
288 value
289 };
290}
291function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
292 return {
293 type: 4,
294 loc,
295 content,
296 isStatic,
297 constType: isStatic ? 3 : constType
298 };
299}
300function createInterpolation(content, loc) {
301 return {
302 type: 5,
303 loc,
304 content: shared.isString(content) ? createSimpleExpression(content, false, loc) : content
305 };
306}
307function createCompoundExpression(children, loc = locStub) {
308 return {
309 type: 8,
310 loc,
311 children
312 };
313}
314function createCallExpression(callee, args = [], loc = locStub) {
315 return {
316 type: 14,
317 loc,
318 callee,
319 arguments: args
320 };
321}
322function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
323 return {
324 type: 18,
325 params,
326 returns,
327 newline,
328 isSlot,
329 loc
330 };
331}
332function createConditionalExpression(test, consequent, alternate, newline = true) {
333 return {
334 type: 19,
335 test,
336 consequent,
337 alternate,
338 newline,
339 loc: locStub
340 };
341}
342function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
343 return {
344 type: 20,
345 index,
346 value,
347 needPauseTracking,
348 inVOnce,
349 needArraySpread: false,
350 loc: locStub
351 };
352}
353function createBlockStatement(body) {
354 return {
355 type: 21,
356 body,
357 loc: locStub
358 };
359}
360function createTemplateLiteral(elements) {
361 return {
362 type: 22,
363 elements,
364 loc: locStub
365 };
366}
367function createIfStatement(test, consequent, alternate) {
368 return {
369 type: 23,
370 test,
371 consequent,
372 alternate,
373 loc: locStub
374 };
375}
376function createAssignmentExpression(left, right) {
377 return {
378 type: 24,
379 left,
380 right,
381 loc: locStub
382 };
383}
384function createSequenceExpression(expressions) {
385 return {
386 type: 25,
387 expressions,
388 loc: locStub
389 };
390}
391function createReturnStatement(returns) {
392 return {
393 type: 26,
394 returns,
395 loc: locStub
396 };
397}
398function getVNodeHelper(ssr, isComponent) {
399 return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
400}
401function getVNodeBlockHelper(ssr, isComponent) {
402 return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
403}
404function convertToBlock(node, { helper, removeHelper, inSSR }) {
405 if (!node.isBlock) {
406 node.isBlock = true;
407 removeHelper(getVNodeHelper(inSSR, node.isComponent));
408 helper(OPEN_BLOCK);
409 helper(getVNodeBlockHelper(inSSR, node.isComponent));
410 }
411}
412
413const defaultDelimitersOpen = new Uint8Array([123, 123]);
414const defaultDelimitersClose = new Uint8Array([125, 125]);
415function isTagStartChar(c) {
416 return c >= 97 && c <= 122 || c >= 65 && c <= 90;
417}
418function isWhitespace(c) {
419 return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
420}
421function isEndOfTagSection(c) {
422 return c === 47 || c === 62 || isWhitespace(c);
423}
424function toCharCodes(str) {
425 const ret = new Uint8Array(str.length);
426 for (let i = 0; i < str.length; i++) {
427 ret[i] = str.charCodeAt(i);
428 }
429 return ret;
430}
431const Sequences = {
432 Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
433 // CDATA[
434 CdataEnd: new Uint8Array([93, 93, 62]),
435 // ]]>
436 CommentEnd: new Uint8Array([45, 45, 62]),
437 // `-->`
438 ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
439 // `<\/script`
440 StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
441 // `</style`
442 TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
443 // `</title`
444 TextareaEnd: new Uint8Array([
445 60,
446 47,
447 116,
448 101,
449 120,
450 116,
451 97,
452 114,
453 101,
454 97
455 ])
456 // `</textarea
457};
458class Tokenizer {
459 constructor(stack, cbs) {
460 this.stack = stack;
461 this.cbs = cbs;
462 /** The current state the tokenizer is in. */
463 this.state = 1;
464 /** The read buffer. */
465 this.buffer = "";
466 /** The beginning of the section that is currently being read. */
467 this.sectionStart = 0;
468 /** The index within the buffer that we are currently looking at. */
469 this.index = 0;
470 /** The start of the last entity. */
471 this.entityStart = 0;
472 /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
473 this.baseState = 1;
474 /** For special parsing behavior inside of script and style tags. */
475 this.inRCDATA = false;
476 /** For disabling RCDATA tags handling */
477 this.inXML = false;
478 /** For disabling interpolation parsing in v-pre */
479 this.inVPre = false;
480 /** Record newline positions for fast line / column calculation */
481 this.newlines = [];
482 this.mode = 0;
483 this.delimiterOpen = defaultDelimitersOpen;
484 this.delimiterClose = defaultDelimitersClose;
485 this.delimiterIndex = -1;
486 this.currentSequence = void 0;
487 this.sequenceIndex = 0;
488 {
489 this.entityDecoder = new decode_js.EntityDecoder(
490 decode_js.htmlDecodeTree,
491 (cp, consumed) => this.emitCodePoint(cp, consumed)
492 );
493 }
494 }
495 get inSFCRoot() {
496 return this.mode === 2 && this.stack.length === 0;
497 }
498 reset() {
499 this.state = 1;
500 this.mode = 0;
501 this.buffer = "";
502 this.sectionStart = 0;
503 this.index = 0;
504 this.baseState = 1;
505 this.inRCDATA = false;
506 this.currentSequence = void 0;
507 this.newlines.length = 0;
508 this.delimiterOpen = defaultDelimitersOpen;
509 this.delimiterClose = defaultDelimitersClose;
510 }
511 /**
512 * Generate Position object with line / column information using recorded
513 * newline positions. We know the index is always going to be an already
514 * processed index, so all the newlines up to this index should have been
515 * recorded.
516 */
517 getPos(index) {
518 let line = 1;
519 let column = index + 1;
520 for (let i = this.newlines.length - 1; i >= 0; i--) {
521 const newlineIndex = this.newlines[i];
522 if (index > newlineIndex) {
523 line = i + 2;
524 column = index - newlineIndex;
525 break;
526 }
527 }
528 return {
529 column,
530 line,
531 offset: index
532 };
533 }
534 peek() {
535 return this.buffer.charCodeAt(this.index + 1);
536 }
537 stateText(c) {
538 if (c === 60) {
539 if (this.index > this.sectionStart) {
540 this.cbs.ontext(this.sectionStart, this.index);
541 }
542 this.state = 5;
543 this.sectionStart = this.index;
544 } else if (c === 38) {
545 this.startEntity();
546 } else if (!this.inVPre && c === this.delimiterOpen[0]) {
547 this.state = 2;
548 this.delimiterIndex = 0;
549 this.stateInterpolationOpen(c);
550 }
551 }
552 stateInterpolationOpen(c) {
553 if (c === this.delimiterOpen[this.delimiterIndex]) {
554 if (this.delimiterIndex === this.delimiterOpen.length - 1) {
555 const start = this.index + 1 - this.delimiterOpen.length;
556 if (start > this.sectionStart) {
557 this.cbs.ontext(this.sectionStart, start);
558 }
559 this.state = 3;
560 this.sectionStart = start;
561 } else {
562 this.delimiterIndex++;
563 }
564 } else if (this.inRCDATA) {
565 this.state = 32;
566 this.stateInRCDATA(c);
567 } else {
568 this.state = 1;
569 this.stateText(c);
570 }
571 }
572 stateInterpolation(c) {
573 if (c === this.delimiterClose[0]) {
574 this.state = 4;
575 this.delimiterIndex = 0;
576 this.stateInterpolationClose(c);
577 }
578 }
579 stateInterpolationClose(c) {
580 if (c === this.delimiterClose[this.delimiterIndex]) {
581 if (this.delimiterIndex === this.delimiterClose.length - 1) {
582 this.cbs.oninterpolation(this.sectionStart, this.index + 1);
583 if (this.inRCDATA) {
584 this.state = 32;
585 } else {
586 this.state = 1;
587 }
588 this.sectionStart = this.index + 1;
589 } else {
590 this.delimiterIndex++;
591 }
592 } else {
593 this.state = 3;
594 this.stateInterpolation(c);
595 }
596 }
597 stateSpecialStartSequence(c) {
598 const isEnd = this.sequenceIndex === this.currentSequence.length;
599 const isMatch = isEnd ? (
600 // If we are at the end of the sequence, make sure the tag name has ended
601 isEndOfTagSection(c)
602 ) : (
603 // Otherwise, do a case-insensitive comparison
604 (c | 32) === this.currentSequence[this.sequenceIndex]
605 );
606 if (!isMatch) {
607 this.inRCDATA = false;
608 } else if (!isEnd) {
609 this.sequenceIndex++;
610 return;
611 }
612 this.sequenceIndex = 0;
613 this.state = 6;
614 this.stateInTagName(c);
615 }
616 /** Look for an end tag. For <title> and <textarea>, also decode entities. */
617 stateInRCDATA(c) {
618 if (this.sequenceIndex === this.currentSequence.length) {
619 if (c === 62 || isWhitespace(c)) {
620 const endOfText = this.index - this.currentSequence.length;
621 if (this.sectionStart < endOfText) {
622 const actualIndex = this.index;
623 this.index = endOfText;
624 this.cbs.ontext(this.sectionStart, endOfText);
625 this.index = actualIndex;
626 }
627 this.sectionStart = endOfText + 2;
628 this.stateInClosingTagName(c);
629 this.inRCDATA = false;
630 return;
631 }
632 this.sequenceIndex = 0;
633 }
634 if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
635 this.sequenceIndex += 1;
636 } else if (this.sequenceIndex === 0) {
637 if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
638 if (c === 38) {
639 this.startEntity();
640 } else if (!this.inVPre && c === this.delimiterOpen[0]) {
641 this.state = 2;
642 this.delimiterIndex = 0;
643 this.stateInterpolationOpen(c);
644 }
645 } else if (this.fastForwardTo(60)) {
646 this.sequenceIndex = 1;
647 }
648 } else {
649 this.sequenceIndex = Number(c === 60);
650 }
651 }
652 stateCDATASequence(c) {
653 if (c === Sequences.Cdata[this.sequenceIndex]) {
654 if (++this.sequenceIndex === Sequences.Cdata.length) {
655 this.state = 28;
656 this.currentSequence = Sequences.CdataEnd;
657 this.sequenceIndex = 0;
658 this.sectionStart = this.index + 1;
659 }
660 } else {
661 this.sequenceIndex = 0;
662 this.state = 23;
663 this.stateInDeclaration(c);
664 }
665 }
666 /**
667 * When we wait for one specific character, we can speed things up
668 * by skipping through the buffer until we find it.
669 *
670 * @returns Whether the character was found.
671 */
672 fastForwardTo(c) {
673 while (++this.index < this.buffer.length) {
674 const cc = this.buffer.charCodeAt(this.index);
675 if (cc === 10) {
676 this.newlines.push(this.index);
677 }
678 if (cc === c) {
679 return true;
680 }
681 }
682 this.index = this.buffer.length - 1;
683 return false;
684 }
685 /**
686 * Comments and CDATA end with `-->` and `]]>`.
687 *
688 * Their common qualities are:
689 * - Their end sequences have a distinct character they start with.
690 * - That character is then repeated, so we have to check multiple repeats.
691 * - All characters but the start character of the sequence can be skipped.
692 */
693 stateInCommentLike(c) {
694 if (c === this.currentSequence[this.sequenceIndex]) {
695 if (++this.sequenceIndex === this.currentSequence.length) {
696 if (this.currentSequence === Sequences.CdataEnd) {
697 this.cbs.oncdata(this.sectionStart, this.index - 2);
698 } else {
699 this.cbs.oncomment(this.sectionStart, this.index - 2);
700 }
701 this.sequenceIndex = 0;
702 this.sectionStart = this.index + 1;
703 this.state = 1;
704 }
705 } else if (this.sequenceIndex === 0) {
706 if (this.fastForwardTo(this.currentSequence[0])) {
707 this.sequenceIndex = 1;
708 }
709 } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
710 this.sequenceIndex = 0;
711 }
712 }
713 startSpecial(sequence, offset) {
714 this.enterRCDATA(sequence, offset);
715 this.state = 31;
716 }
717 enterRCDATA(sequence, offset) {
718 this.inRCDATA = true;
719 this.currentSequence = sequence;
720 this.sequenceIndex = offset;
721 }
722 stateBeforeTagName(c) {
723 if (c === 33) {
724 this.state = 22;
725 this.sectionStart = this.index + 1;
726 } else if (c === 63) {
727 this.state = 24;
728 this.sectionStart = this.index + 1;
729 } else if (isTagStartChar(c)) {
730 this.sectionStart = this.index;
731 if (this.mode === 0) {
732 this.state = 6;
733 } else if (this.inSFCRoot) {
734 this.state = 34;
735 } else if (!this.inXML) {
736 if (c === 116) {
737 this.state = 30;
738 } else {
739 this.state = c === 115 ? 29 : 6;
740 }
741 } else {
742 this.state = 6;
743 }
744 } else if (c === 47) {
745 this.state = 8;
746 } else {
747 this.state = 1;
748 this.stateText(c);
749 }
750 }
751 stateInTagName(c) {
752 if (isEndOfTagSection(c)) {
753 this.handleTagName(c);
754 }
755 }
756 stateInSFCRootTagName(c) {
757 if (isEndOfTagSection(c)) {
758 const tag = this.buffer.slice(this.sectionStart, this.index);
759 if (tag !== "template") {
760 this.enterRCDATA(toCharCodes(`</` + tag), 0);
761 }
762 this.handleTagName(c);
763 }
764 }
765 handleTagName(c) {
766 this.cbs.onopentagname(this.sectionStart, this.index);
767 this.sectionStart = -1;
768 this.state = 11;
769 this.stateBeforeAttrName(c);
770 }
771 stateBeforeClosingTagName(c) {
772 if (isWhitespace(c)) ; else if (c === 62) {
773 {
774 this.cbs.onerr(14, this.index);
775 }
776 this.state = 1;
777 this.sectionStart = this.index + 1;
778 } else {
779 this.state = isTagStartChar(c) ? 9 : 27;
780 this.sectionStart = this.index;
781 }
782 }
783 stateInClosingTagName(c) {
784 if (c === 62 || isWhitespace(c)) {
785 this.cbs.onclosetag(this.sectionStart, this.index);
786 this.sectionStart = -1;
787 this.state = 10;
788 this.stateAfterClosingTagName(c);
789 }
790 }
791 stateAfterClosingTagName(c) {
792 if (c === 62) {
793 this.state = 1;
794 this.sectionStart = this.index + 1;
795 }
796 }
797 stateBeforeAttrName(c) {
798 if (c === 62) {
799 this.cbs.onopentagend(this.index);
800 if (this.inRCDATA) {
801 this.state = 32;
802 } else {
803 this.state = 1;
804 }
805 this.sectionStart = this.index + 1;
806 } else if (c === 47) {
807 this.state = 7;
808 if (this.peek() !== 62) {
809 this.cbs.onerr(22, this.index);
810 }
811 } else if (c === 60 && this.peek() === 47) {
812 this.cbs.onopentagend(this.index);
813 this.state = 5;
814 this.sectionStart = this.index;
815 } else if (!isWhitespace(c)) {
816 if (c === 61) {
817 this.cbs.onerr(
818 19,
819 this.index
820 );
821 }
822 this.handleAttrStart(c);
823 }
824 }
825 handleAttrStart(c) {
826 if (c === 118 && this.peek() === 45) {
827 this.state = 13;
828 this.sectionStart = this.index;
829 } else if (c === 46 || c === 58 || c === 64 || c === 35) {
830 this.cbs.ondirname(this.index, this.index + 1);
831 this.state = 14;
832 this.sectionStart = this.index + 1;
833 } else {
834 this.state = 12;
835 this.sectionStart = this.index;
836 }
837 }
838 stateInSelfClosingTag(c) {
839 if (c === 62) {
840 this.cbs.onselfclosingtag(this.index);
841 this.state = 1;
842 this.sectionStart = this.index + 1;
843 this.inRCDATA = false;
844 } else if (!isWhitespace(c)) {
845 this.state = 11;
846 this.stateBeforeAttrName(c);
847 }
848 }
849 stateInAttrName(c) {
850 if (c === 61 || isEndOfTagSection(c)) {
851 this.cbs.onattribname(this.sectionStart, this.index);
852 this.handleAttrNameEnd(c);
853 } else if (c === 34 || c === 39 || c === 60) {
854 this.cbs.onerr(
855 17,
856 this.index
857 );
858 }
859 }
860 stateInDirName(c) {
861 if (c === 61 || isEndOfTagSection(c)) {
862 this.cbs.ondirname(this.sectionStart, this.index);
863 this.handleAttrNameEnd(c);
864 } else if (c === 58) {
865 this.cbs.ondirname(this.sectionStart, this.index);
866 this.state = 14;
867 this.sectionStart = this.index + 1;
868 } else if (c === 46) {
869 this.cbs.ondirname(this.sectionStart, this.index);
870 this.state = 16;
871 this.sectionStart = this.index + 1;
872 }
873 }
874 stateInDirArg(c) {
875 if (c === 61 || isEndOfTagSection(c)) {
876 this.cbs.ondirarg(this.sectionStart, this.index);
877 this.handleAttrNameEnd(c);
878 } else if (c === 91) {
879 this.state = 15;
880 } else if (c === 46) {
881 this.cbs.ondirarg(this.sectionStart, this.index);
882 this.state = 16;
883 this.sectionStart = this.index + 1;
884 }
885 }
886 stateInDynamicDirArg(c) {
887 if (c === 93) {
888 this.state = 14;
889 } else if (c === 61 || isEndOfTagSection(c)) {
890 this.cbs.ondirarg(this.sectionStart, this.index + 1);
891 this.handleAttrNameEnd(c);
892 {
893 this.cbs.onerr(
894 27,
895 this.index
896 );
897 }
898 }
899 }
900 stateInDirModifier(c) {
901 if (c === 61 || isEndOfTagSection(c)) {
902 this.cbs.ondirmodifier(this.sectionStart, this.index);
903 this.handleAttrNameEnd(c);
904 } else if (c === 46) {
905 this.cbs.ondirmodifier(this.sectionStart, this.index);
906 this.sectionStart = this.index + 1;
907 }
908 }
909 handleAttrNameEnd(c) {
910 this.sectionStart = this.index;
911 this.state = 17;
912 this.cbs.onattribnameend(this.index);
913 this.stateAfterAttrName(c);
914 }
915 stateAfterAttrName(c) {
916 if (c === 61) {
917 this.state = 18;
918 } else if (c === 47 || c === 62) {
919 this.cbs.onattribend(0, this.sectionStart);
920 this.sectionStart = -1;
921 this.state = 11;
922 this.stateBeforeAttrName(c);
923 } else if (!isWhitespace(c)) {
924 this.cbs.onattribend(0, this.sectionStart);
925 this.handleAttrStart(c);
926 }
927 }
928 stateBeforeAttrValue(c) {
929 if (c === 34) {
930 this.state = 19;
931 this.sectionStart = this.index + 1;
932 } else if (c === 39) {
933 this.state = 20;
934 this.sectionStart = this.index + 1;
935 } else if (!isWhitespace(c)) {
936 this.sectionStart = this.index;
937 this.state = 21;
938 this.stateInAttrValueNoQuotes(c);
939 }
940 }
941 handleInAttrValue(c, quote) {
942 if (c === quote || false) {
943 this.cbs.onattribdata(this.sectionStart, this.index);
944 this.sectionStart = -1;
945 this.cbs.onattribend(
946 quote === 34 ? 3 : 2,
947 this.index + 1
948 );
949 this.state = 11;
950 } else if (c === 38) {
951 this.startEntity();
952 }
953 }
954 stateInAttrValueDoubleQuotes(c) {
955 this.handleInAttrValue(c, 34);
956 }
957 stateInAttrValueSingleQuotes(c) {
958 this.handleInAttrValue(c, 39);
959 }
960 stateInAttrValueNoQuotes(c) {
961 if (isWhitespace(c) || c === 62) {
962 this.cbs.onattribdata(this.sectionStart, this.index);
963 this.sectionStart = -1;
964 this.cbs.onattribend(1, this.index);
965 this.state = 11;
966 this.stateBeforeAttrName(c);
967 } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
968 this.cbs.onerr(
969 18,
970 this.index
971 );
972 } else if (c === 38) {
973 this.startEntity();
974 }
975 }
976 stateBeforeDeclaration(c) {
977 if (c === 91) {
978 this.state = 26;
979 this.sequenceIndex = 0;
980 } else {
981 this.state = c === 45 ? 25 : 23;
982 }
983 }
984 stateInDeclaration(c) {
985 if (c === 62 || this.fastForwardTo(62)) {
986 this.state = 1;
987 this.sectionStart = this.index + 1;
988 }
989 }
990 stateInProcessingInstruction(c) {
991 if (c === 62 || this.fastForwardTo(62)) {
992 this.cbs.onprocessinginstruction(this.sectionStart, this.index);
993 this.state = 1;
994 this.sectionStart = this.index + 1;
995 }
996 }
997 stateBeforeComment(c) {
998 if (c === 45) {
999 this.state = 28;
1000 this.currentSequence = Sequences.CommentEnd;
1001 this.sequenceIndex = 2;
1002 this.sectionStart = this.index + 1;
1003 } else {
1004 this.state = 23;
1005 }
1006 }
1007 stateInSpecialComment(c) {
1008 if (c === 62 || this.fastForwardTo(62)) {
1009 this.cbs.oncomment(this.sectionStart, this.index);
1010 this.state = 1;
1011 this.sectionStart = this.index + 1;
1012 }
1013 }
1014 stateBeforeSpecialS(c) {
1015 if (c === Sequences.ScriptEnd[3]) {
1016 this.startSpecial(Sequences.ScriptEnd, 4);
1017 } else if (c === Sequences.StyleEnd[3]) {
1018 this.startSpecial(Sequences.StyleEnd, 4);
1019 } else {
1020 this.state = 6;
1021 this.stateInTagName(c);
1022 }
1023 }
1024 stateBeforeSpecialT(c) {
1025 if (c === Sequences.TitleEnd[3]) {
1026 this.startSpecial(Sequences.TitleEnd, 4);
1027 } else if (c === Sequences.TextareaEnd[3]) {
1028 this.startSpecial(Sequences.TextareaEnd, 4);
1029 } else {
1030 this.state = 6;
1031 this.stateInTagName(c);
1032 }
1033 }
1034 startEntity() {
1035 {
1036 this.baseState = this.state;
1037 this.state = 33;
1038 this.entityStart = this.index;
1039 this.entityDecoder.startEntity(
1040 this.baseState === 1 || this.baseState === 32 ? decode_js.DecodingMode.Legacy : decode_js.DecodingMode.Attribute
1041 );
1042 }
1043 }
1044 stateInEntity() {
1045 {
1046 const length = this.entityDecoder.write(this.buffer, this.index);
1047 if (length >= 0) {
1048 this.state = this.baseState;
1049 if (length === 0) {
1050 this.index = this.entityStart;
1051 }
1052 } else {
1053 this.index = this.buffer.length - 1;
1054 }
1055 }
1056 }
1057 /**
1058 * Iterates through the buffer, calling the function corresponding to the current state.
1059 *
1060 * States that are more likely to be hit are higher up, as a performance improvement.
1061 */
1062 parse(input) {
1063 this.buffer = input;
1064 while (this.index < this.buffer.length) {
1065 const c = this.buffer.charCodeAt(this.index);
1066 if (c === 10) {
1067 this.newlines.push(this.index);
1068 }
1069 switch (this.state) {
1070 case 1: {
1071 this.stateText(c);
1072 break;
1073 }
1074 case 2: {
1075 this.stateInterpolationOpen(c);
1076 break;
1077 }
1078 case 3: {
1079 this.stateInterpolation(c);
1080 break;
1081 }
1082 case 4: {
1083 this.stateInterpolationClose(c);
1084 break;
1085 }
1086 case 31: {
1087 this.stateSpecialStartSequence(c);
1088 break;
1089 }
1090 case 32: {
1091 this.stateInRCDATA(c);
1092 break;
1093 }
1094 case 26: {
1095 this.stateCDATASequence(c);
1096 break;
1097 }
1098 case 19: {
1099 this.stateInAttrValueDoubleQuotes(c);
1100 break;
1101 }
1102 case 12: {
1103 this.stateInAttrName(c);
1104 break;
1105 }
1106 case 13: {
1107 this.stateInDirName(c);
1108 break;
1109 }
1110 case 14: {
1111 this.stateInDirArg(c);
1112 break;
1113 }
1114 case 15: {
1115 this.stateInDynamicDirArg(c);
1116 break;
1117 }
1118 case 16: {
1119 this.stateInDirModifier(c);
1120 break;
1121 }
1122 case 28: {
1123 this.stateInCommentLike(c);
1124 break;
1125 }
1126 case 27: {
1127 this.stateInSpecialComment(c);
1128 break;
1129 }
1130 case 11: {
1131 this.stateBeforeAttrName(c);
1132 break;
1133 }
1134 case 6: {
1135 this.stateInTagName(c);
1136 break;
1137 }
1138 case 34: {
1139 this.stateInSFCRootTagName(c);
1140 break;
1141 }
1142 case 9: {
1143 this.stateInClosingTagName(c);
1144 break;
1145 }
1146 case 5: {
1147 this.stateBeforeTagName(c);
1148 break;
1149 }
1150 case 17: {
1151 this.stateAfterAttrName(c);
1152 break;
1153 }
1154 case 20: {
1155 this.stateInAttrValueSingleQuotes(c);
1156 break;
1157 }
1158 case 18: {
1159 this.stateBeforeAttrValue(c);
1160 break;
1161 }
1162 case 8: {
1163 this.stateBeforeClosingTagName(c);
1164 break;
1165 }
1166 case 10: {
1167 this.stateAfterClosingTagName(c);
1168 break;
1169 }
1170 case 29: {
1171 this.stateBeforeSpecialS(c);
1172 break;
1173 }
1174 case 30: {
1175 this.stateBeforeSpecialT(c);
1176 break;
1177 }
1178 case 21: {
1179 this.stateInAttrValueNoQuotes(c);
1180 break;
1181 }
1182 case 7: {
1183 this.stateInSelfClosingTag(c);
1184 break;
1185 }
1186 case 23: {
1187 this.stateInDeclaration(c);
1188 break;
1189 }
1190 case 22: {
1191 this.stateBeforeDeclaration(c);
1192 break;
1193 }
1194 case 25: {
1195 this.stateBeforeComment(c);
1196 break;
1197 }
1198 case 24: {
1199 this.stateInProcessingInstruction(c);
1200 break;
1201 }
1202 case 33: {
1203 this.stateInEntity();
1204 break;
1205 }
1206 }
1207 this.index++;
1208 }
1209 this.cleanup();
1210 this.finish();
1211 }
1212 /**
1213 * Remove data that has already been consumed from the buffer.
1214 */
1215 cleanup() {
1216 if (this.sectionStart !== this.index) {
1217 if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
1218 this.cbs.ontext(this.sectionStart, this.index);
1219 this.sectionStart = this.index;
1220 } else if (this.state === 19 || this.state === 20 || this.state === 21) {
1221 this.cbs.onattribdata(this.sectionStart, this.index);
1222 this.sectionStart = this.index;
1223 }
1224 }
1225 }
1226 finish() {
1227 if (this.state === 33) {
1228 this.entityDecoder.end();
1229 this.state = this.baseState;
1230 }
1231 this.handleTrailingData();
1232 this.cbs.onend();
1233 }
1234 /** Handle any trailing data. */
1235 handleTrailingData() {
1236 const endIndex = this.buffer.length;
1237 if (this.sectionStart >= endIndex) {
1238 return;
1239 }
1240 if (this.state === 28) {
1241 if (this.currentSequence === Sequences.CdataEnd) {
1242 this.cbs.oncdata(this.sectionStart, endIndex);
1243 } else {
1244 this.cbs.oncomment(this.sectionStart, endIndex);
1245 }
1246 } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
1247 this.cbs.ontext(this.sectionStart, endIndex);
1248 }
1249 }
1250 emitCodePoint(cp, consumed) {
1251 {
1252 if (this.baseState !== 1 && this.baseState !== 32) {
1253 if (this.sectionStart < this.entityStart) {
1254 this.cbs.onattribdata(this.sectionStart, this.entityStart);
1255 }
1256 this.sectionStart = this.entityStart + consumed;
1257 this.index = this.sectionStart - 1;
1258 this.cbs.onattribentity(
1259 decode_js.fromCodePoint(cp),
1260 this.entityStart,
1261 this.sectionStart
1262 );
1263 } else {
1264 if (this.sectionStart < this.entityStart) {
1265 this.cbs.ontext(this.sectionStart, this.entityStart);
1266 }
1267 this.sectionStart = this.entityStart + consumed;
1268 this.index = this.sectionStart - 1;
1269 this.cbs.ontextentity(
1270 decode_js.fromCodePoint(cp),
1271 this.entityStart,
1272 this.sectionStart
1273 );
1274 }
1275 }
1276 }
1277}
1278
1279const CompilerDeprecationTypes = {
1280 "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
1281 "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
1282 "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
1283 "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
1284 "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
1285 "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
1286 "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
1287 "COMPILER_FILTERS": "COMPILER_FILTERS"
1288};
1289const deprecationData = {
1290 ["COMPILER_IS_ON_ELEMENT"]: {
1291 message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
1292 link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
1293 },
1294 ["COMPILER_V_BIND_SYNC"]: {
1295 message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
1296 link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
1297 },
1298 ["COMPILER_V_BIND_OBJECT_ORDER"]: {
1299 message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
1300 link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
1301 },
1302 ["COMPILER_V_ON_NATIVE"]: {
1303 message: `.native modifier for v-on has been removed as is no longer necessary.`,
1304 link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
1305 },
1306 ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
1307 message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
1308 link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
1309 },
1310 ["COMPILER_NATIVE_TEMPLATE"]: {
1311 message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
1312 },
1313 ["COMPILER_INLINE_TEMPLATE"]: {
1314 message: `"inline-template" has been removed in Vue 3.`,
1315 link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
1316 },
1317 ["COMPILER_FILTERS"]: {
1318 message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
1319 link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
1320 }
1321};
1322function getCompatValue(key, { compatConfig }) {
1323 const value = compatConfig && compatConfig[key];
1324 if (key === "MODE") {
1325 return value || 3;
1326 } else {
1327 return value;
1328 }
1329}
1330function isCompatEnabled(key, context) {
1331 const mode = getCompatValue("MODE", context);
1332 const value = getCompatValue(key, context);
1333 return mode === 3 ? value === true : value !== false;
1334}
1335function checkCompatEnabled(key, context, loc, ...args) {
1336 const enabled = isCompatEnabled(key, context);
1337 return enabled;
1338}
1339function warnDeprecation(key, context, loc, ...args) {
1340 const val = getCompatValue(key, context);
1341 if (val === "suppress-warning") {
1342 return;
1343 }
1344 const { message, link } = deprecationData[key];
1345 const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
1346 Details: ${link}` : ``}`;
1347 const err = new SyntaxError(msg);
1348 err.code = key;
1349 if (loc) err.loc = loc;
1350 context.onWarn(err);
1351}
1352
1353function defaultOnError(error) {
1354 throw error;
1355}
1356function defaultOnWarn(msg) {
1357}
1358function createCompilerError(code, loc, messages, additionalMessage) {
1359 const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
1360 const error = new SyntaxError(String(msg));
1361 error.code = code;
1362 error.loc = loc;
1363 return error;
1364}
1365const ErrorCodes = {
1366 "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
1367 "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
1368 "CDATA_IN_HTML_CONTENT": 1,
1369 "1": "CDATA_IN_HTML_CONTENT",
1370 "DUPLICATE_ATTRIBUTE": 2,
1371 "2": "DUPLICATE_ATTRIBUTE",
1372 "END_TAG_WITH_ATTRIBUTES": 3,
1373 "3": "END_TAG_WITH_ATTRIBUTES",
1374 "END_TAG_WITH_TRAILING_SOLIDUS": 4,
1375 "4": "END_TAG_WITH_TRAILING_SOLIDUS",
1376 "EOF_BEFORE_TAG_NAME": 5,
1377 "5": "EOF_BEFORE_TAG_NAME",
1378 "EOF_IN_CDATA": 6,
1379 "6": "EOF_IN_CDATA",
1380 "EOF_IN_COMMENT": 7,
1381 "7": "EOF_IN_COMMENT",
1382 "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
1383 "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
1384 "EOF_IN_TAG": 9,
1385 "9": "EOF_IN_TAG",
1386 "INCORRECTLY_CLOSED_COMMENT": 10,
1387 "10": "INCORRECTLY_CLOSED_COMMENT",
1388 "INCORRECTLY_OPENED_COMMENT": 11,
1389 "11": "INCORRECTLY_OPENED_COMMENT",
1390 "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
1391 "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
1392 "MISSING_ATTRIBUTE_VALUE": 13,
1393 "13": "MISSING_ATTRIBUTE_VALUE",
1394 "MISSING_END_TAG_NAME": 14,
1395 "14": "MISSING_END_TAG_NAME",
1396 "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
1397 "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
1398 "NESTED_COMMENT": 16,
1399 "16": "NESTED_COMMENT",
1400 "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
1401 "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
1402 "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
1403 "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
1404 "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
1405 "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
1406 "UNEXPECTED_NULL_CHARACTER": 20,
1407 "20": "UNEXPECTED_NULL_CHARACTER",
1408 "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
1409 "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
1410 "UNEXPECTED_SOLIDUS_IN_TAG": 22,
1411 "22": "UNEXPECTED_SOLIDUS_IN_TAG",
1412 "X_INVALID_END_TAG": 23,
1413 "23": "X_INVALID_END_TAG",
1414 "X_MISSING_END_TAG": 24,
1415 "24": "X_MISSING_END_TAG",
1416 "X_MISSING_INTERPOLATION_END": 25,
1417 "25": "X_MISSING_INTERPOLATION_END",
1418 "X_MISSING_DIRECTIVE_NAME": 26,
1419 "26": "X_MISSING_DIRECTIVE_NAME",
1420 "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
1421 "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
1422 "X_V_IF_NO_EXPRESSION": 28,
1423 "28": "X_V_IF_NO_EXPRESSION",
1424 "X_V_IF_SAME_KEY": 29,
1425 "29": "X_V_IF_SAME_KEY",
1426 "X_V_ELSE_NO_ADJACENT_IF": 30,
1427 "30": "X_V_ELSE_NO_ADJACENT_IF",
1428 "X_V_FOR_NO_EXPRESSION": 31,
1429 "31": "X_V_FOR_NO_EXPRESSION",
1430 "X_V_FOR_MALFORMED_EXPRESSION": 32,
1431 "32": "X_V_FOR_MALFORMED_EXPRESSION",
1432 "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
1433 "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
1434 "X_V_BIND_NO_EXPRESSION": 34,
1435 "34": "X_V_BIND_NO_EXPRESSION",
1436 "X_V_ON_NO_EXPRESSION": 35,
1437 "35": "X_V_ON_NO_EXPRESSION",
1438 "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
1439 "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
1440 "X_V_SLOT_MIXED_SLOT_USAGE": 37,
1441 "37": "X_V_SLOT_MIXED_SLOT_USAGE",
1442 "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
1443 "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
1444 "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
1445 "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
1446 "X_V_SLOT_MISPLACED": 40,
1447 "40": "X_V_SLOT_MISPLACED",
1448 "X_V_MODEL_NO_EXPRESSION": 41,
1449 "41": "X_V_MODEL_NO_EXPRESSION",
1450 "X_V_MODEL_MALFORMED_EXPRESSION": 42,
1451 "42": "X_V_MODEL_MALFORMED_EXPRESSION",
1452 "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
1453 "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
1454 "X_V_MODEL_ON_PROPS": 44,
1455 "44": "X_V_MODEL_ON_PROPS",
1456 "X_INVALID_EXPRESSION": 45,
1457 "45": "X_INVALID_EXPRESSION",
1458 "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
1459 "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
1460 "X_PREFIX_ID_NOT_SUPPORTED": 47,
1461 "47": "X_PREFIX_ID_NOT_SUPPORTED",
1462 "X_MODULE_MODE_NOT_SUPPORTED": 48,
1463 "48": "X_MODULE_MODE_NOT_SUPPORTED",
1464 "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
1465 "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
1466 "X_SCOPE_ID_NOT_SUPPORTED": 50,
1467 "50": "X_SCOPE_ID_NOT_SUPPORTED",
1468 "X_VNODE_HOOKS": 51,
1469 "51": "X_VNODE_HOOKS",
1470 "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
1471 "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
1472 "__EXTEND_POINT__": 53,
1473 "53": "__EXTEND_POINT__"
1474};
1475const errorMessages = {
1476 // parse errors
1477 [0]: "Illegal comment.",
1478 [1]: "CDATA section is allowed only in XML context.",
1479 [2]: "Duplicate attribute.",
1480 [3]: "End tag cannot have attributes.",
1481 [4]: "Illegal '/' in tags.",
1482 [5]: "Unexpected EOF in tag.",
1483 [6]: "Unexpected EOF in CDATA section.",
1484 [7]: "Unexpected EOF in comment.",
1485 [8]: "Unexpected EOF in script.",
1486 [9]: "Unexpected EOF in tag.",
1487 [10]: "Incorrectly closed comment.",
1488 [11]: "Incorrectly opened comment.",
1489 [12]: "Illegal tag name. Use '&lt;' to print '<'.",
1490 [13]: "Attribute value was expected.",
1491 [14]: "End tag name was expected.",
1492 [15]: "Whitespace was expected.",
1493 [16]: "Unexpected '<!--' in comment.",
1494 [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
1495 [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
1496 [19]: "Attribute name cannot start with '='.",
1497 [21]: "'<?' is allowed only in XML context.",
1498 [20]: `Unexpected null character.`,
1499 [22]: "Illegal '/' in tags.",
1500 // Vue-specific parse errors
1501 [23]: "Invalid end tag.",
1502 [24]: "Element is missing end tag.",
1503 [25]: "Interpolation end sign was not found.",
1504 [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
1505 [26]: "Legal directive name was expected.",
1506 // transform errors
1507 [28]: `v-if/v-else-if is missing expression.`,
1508 [29]: `v-if/else branches must use unique keys.`,
1509 [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
1510 [31]: `v-for is missing expression.`,
1511 [32]: `v-for has invalid expression.`,
1512 [33]: `<template v-for> key should be placed on the <template> tag.`,
1513 [34]: `v-bind is missing expression.`,
1514 [52]: `v-bind with same-name shorthand only allows static argument.`,
1515 [35]: `v-on is missing expression.`,
1516 [36]: `Unexpected custom directive on <slot> outlet.`,
1517 [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
1518 [38]: `Duplicate slot names found. `,
1519 [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
1520 [40]: `v-slot can only be used on components or <template> tags.`,
1521 [41]: `v-model is missing expression.`,
1522 [42]: `v-model value must be a valid JavaScript member expression.`,
1523 [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
1524 [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
1525Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1526 [45]: `Error parsing JavaScript expression: `,
1527 [46]: `<KeepAlive> expects exactly one child component.`,
1528 [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
1529 // generic errors
1530 [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1531 [48]: `ES module mode is not supported in this build of compiler.`,
1532 [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1533 [50]: `"scopeId" option is only supported in module mode.`,
1534 // just to fulfill types
1535 [53]: ``
1536};
1537
1538function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
1539 const rootExp = root.type === "Program" ? root.body[0].type === "ExpressionStatement" && root.body[0].expression : root;
1540 estreeWalker.walk(root, {
1541 enter(node, parent) {
1542 parent && parentStack.push(parent);
1543 if (parent && parent.type.startsWith("TS") && !TS_NODE_TYPES.includes(parent.type)) {
1544 return this.skip();
1545 }
1546 if (node.type === "Identifier") {
1547 const isLocal = !!knownIds[node.name];
1548 const isRefed = isReferencedIdentifier(node, parent, parentStack);
1549 if (includeAll || isRefed && !isLocal) {
1550 onIdentifier(node, parent, parentStack, isRefed, isLocal);
1551 }
1552 } else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
1553 (parent == null ? void 0 : parent.type) === "ObjectPattern") {
1554 node.inPattern = true;
1555 } else if (isFunctionType(node)) {
1556 if (node.scopeIds) {
1557 node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
1558 } else {
1559 walkFunctionParams(
1560 node,
1561 (id) => markScopeIdentifier(node, id, knownIds)
1562 );
1563 }
1564 } else if (node.type === "BlockStatement") {
1565 if (node.scopeIds) {
1566 node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
1567 } else {
1568 walkBlockDeclarations(
1569 node,
1570 (id) => markScopeIdentifier(node, id, knownIds)
1571 );
1572 }
1573 } else if (node.type === "CatchClause" && node.param) {
1574 for (const id of extractIdentifiers(node.param)) {
1575 markScopeIdentifier(node, id, knownIds);
1576 }
1577 } else if (isForStatement(node)) {
1578 walkForStatement(
1579 node,
1580 false,
1581 (id) => markScopeIdentifier(node, id, knownIds)
1582 );
1583 }
1584 },
1585 leave(node, parent) {
1586 parent && parentStack.pop();
1587 if (node !== rootExp && node.scopeIds) {
1588 for (const id of node.scopeIds) {
1589 knownIds[id]--;
1590 if (knownIds[id] === 0) {
1591 delete knownIds[id];
1592 }
1593 }
1594 }
1595 }
1596 });
1597}
1598function isReferencedIdentifier(id, parent, parentStack) {
1599 if (!parent) {
1600 return true;
1601 }
1602 if (id.name === "arguments") {
1603 return false;
1604 }
1605 if (isReferenced(id, parent)) {
1606 return true;
1607 }
1608 switch (parent.type) {
1609 case "AssignmentExpression":
1610 case "AssignmentPattern":
1611 return true;
1612 case "ObjectPattern":
1613 case "ArrayPattern":
1614 return isInDestructureAssignment(parent, parentStack);
1615 }
1616 return false;
1617}
1618function isInDestructureAssignment(parent, parentStack) {
1619 if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
1620 let i = parentStack.length;
1621 while (i--) {
1622 const p = parentStack[i];
1623 if (p.type === "AssignmentExpression") {
1624 return true;
1625 } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
1626 break;
1627 }
1628 }
1629 }
1630 return false;
1631}
1632function isInNewExpression(parentStack) {
1633 let i = parentStack.length;
1634 while (i--) {
1635 const p = parentStack[i];
1636 if (p.type === "NewExpression") {
1637 return true;
1638 } else if (p.type !== "MemberExpression") {
1639 break;
1640 }
1641 }
1642 return false;
1643}
1644function walkFunctionParams(node, onIdent) {
1645 for (const p of node.params) {
1646 for (const id of extractIdentifiers(p)) {
1647 onIdent(id);
1648 }
1649 }
1650}
1651function walkBlockDeclarations(block, onIdent) {
1652 for (const stmt of block.body) {
1653 if (stmt.type === "VariableDeclaration") {
1654 if (stmt.declare) continue;
1655 for (const decl of stmt.declarations) {
1656 for (const id of extractIdentifiers(decl.id)) {
1657 onIdent(id);
1658 }
1659 }
1660 } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
1661 if (stmt.declare || !stmt.id) continue;
1662 onIdent(stmt.id);
1663 } else if (isForStatement(stmt)) {
1664 walkForStatement(stmt, true, onIdent);
1665 }
1666 }
1667}
1668function isForStatement(stmt) {
1669 return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
1670}
1671function walkForStatement(stmt, isVar, onIdent) {
1672 const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
1673 if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
1674 for (const decl of variable.declarations) {
1675 for (const id of extractIdentifiers(decl.id)) {
1676 onIdent(id);
1677 }
1678 }
1679 }
1680}
1681function extractIdentifiers(param, nodes = []) {
1682 switch (param.type) {
1683 case "Identifier":
1684 nodes.push(param);
1685 break;
1686 case "MemberExpression":
1687 let object = param;
1688 while (object.type === "MemberExpression") {
1689 object = object.object;
1690 }
1691 nodes.push(object);
1692 break;
1693 case "ObjectPattern":
1694 for (const prop of param.properties) {
1695 if (prop.type === "RestElement") {
1696 extractIdentifiers(prop.argument, nodes);
1697 } else {
1698 extractIdentifiers(prop.value, nodes);
1699 }
1700 }
1701 break;
1702 case "ArrayPattern":
1703 param.elements.forEach((element) => {
1704 if (element) extractIdentifiers(element, nodes);
1705 });
1706 break;
1707 case "RestElement":
1708 extractIdentifiers(param.argument, nodes);
1709 break;
1710 case "AssignmentPattern":
1711 extractIdentifiers(param.left, nodes);
1712 break;
1713 }
1714 return nodes;
1715}
1716function markKnownIds(name, knownIds) {
1717 if (name in knownIds) {
1718 knownIds[name]++;
1719 } else {
1720 knownIds[name] = 1;
1721 }
1722}
1723function markScopeIdentifier(node, child, knownIds) {
1724 const { name } = child;
1725 if (node.scopeIds && node.scopeIds.has(name)) {
1726 return;
1727 }
1728 markKnownIds(name, knownIds);
1729 (node.scopeIds || (node.scopeIds = /* @__PURE__ */ new Set())).add(name);
1730}
1731const isFunctionType = (node) => {
1732 return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
1733};
1734const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
1735const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
1736function isReferenced(node, parent, grandparent) {
1737 switch (parent.type) {
1738 // yes: PARENT[NODE]
1739 // yes: NODE.child
1740 // no: parent.NODE
1741 case "MemberExpression":
1742 case "OptionalMemberExpression":
1743 if (parent.property === node) {
1744 return !!parent.computed;
1745 }
1746 return parent.object === node;
1747 case "JSXMemberExpression":
1748 return parent.object === node;
1749 // no: let NODE = init;
1750 // yes: let id = NODE;
1751 case "VariableDeclarator":
1752 return parent.init === node;
1753 // yes: () => NODE
1754 // no: (NODE) => {}
1755 case "ArrowFunctionExpression":
1756 return parent.body === node;
1757 // no: class { #NODE; }
1758 // no: class { get #NODE() {} }
1759 // no: class { #NODE() {} }
1760 // no: class { fn() { return this.#NODE; } }
1761 case "PrivateName":
1762 return false;
1763 // no: class { NODE() {} }
1764 // yes: class { [NODE]() {} }
1765 // no: class { foo(NODE) {} }
1766 case "ClassMethod":
1767 case "ClassPrivateMethod":
1768 case "ObjectMethod":
1769 if (parent.key === node) {
1770 return !!parent.computed;
1771 }
1772 return false;
1773 // yes: { [NODE]: "" }
1774 // no: { NODE: "" }
1775 // depends: { NODE }
1776 // depends: { key: NODE }
1777 case "ObjectProperty":
1778 if (parent.key === node) {
1779 return !!parent.computed;
1780 }
1781 return !grandparent;
1782 // no: class { NODE = value; }
1783 // yes: class { [NODE] = value; }
1784 // yes: class { key = NODE; }
1785 case "ClassProperty":
1786 if (parent.key === node) {
1787 return !!parent.computed;
1788 }
1789 return true;
1790 case "ClassPrivateProperty":
1791 return parent.key !== node;
1792 // no: class NODE {}
1793 // yes: class Foo extends NODE {}
1794 case "ClassDeclaration":
1795 case "ClassExpression":
1796 return parent.superClass === node;
1797 // yes: left = NODE;
1798 // no: NODE = right;
1799 case "AssignmentExpression":
1800 return parent.right === node;
1801 // no: [NODE = foo] = [];
1802 // yes: [foo = NODE] = [];
1803 case "AssignmentPattern":
1804 return parent.right === node;
1805 // no: NODE: for (;;) {}
1806 case "LabeledStatement":
1807 return false;
1808 // no: try {} catch (NODE) {}
1809 case "CatchClause":
1810 return false;
1811 // no: function foo(...NODE) {}
1812 case "RestElement":
1813 return false;
1814 case "BreakStatement":
1815 case "ContinueStatement":
1816 return false;
1817 // no: function NODE() {}
1818 // no: function foo(NODE) {}
1819 case "FunctionDeclaration":
1820 case "FunctionExpression":
1821 return false;
1822 // no: export NODE from "foo";
1823 // no: export * as NODE from "foo";
1824 case "ExportNamespaceSpecifier":
1825 case "ExportDefaultSpecifier":
1826 return false;
1827 // no: export { foo as NODE };
1828 // yes: export { NODE as foo };
1829 // no: export { NODE as foo } from "foo";
1830 case "ExportSpecifier":
1831 return parent.local === node;
1832 // no: import NODE from "foo";
1833 // no: import * as NODE from "foo";
1834 // no: import { NODE as foo } from "foo";
1835 // no: import { foo as NODE } from "foo";
1836 // no: import NODE from "bar";
1837 case "ImportDefaultSpecifier":
1838 case "ImportNamespaceSpecifier":
1839 case "ImportSpecifier":
1840 return false;
1841 // no: import "foo" assert { NODE: "json" }
1842 case "ImportAttribute":
1843 return false;
1844 // no: <div NODE="foo" />
1845 case "JSXAttribute":
1846 return false;
1847 // no: [NODE] = [];
1848 // no: ({ NODE }) = [];
1849 case "ObjectPattern":
1850 case "ArrayPattern":
1851 return false;
1852 // no: new.NODE
1853 // no: NODE.target
1854 case "MetaProperty":
1855 return false;
1856 // yes: type X = { someProperty: NODE }
1857 // no: type X = { NODE: OtherType }
1858 case "ObjectTypeProperty":
1859 return parent.key !== node;
1860 // yes: enum X { Foo = NODE }
1861 // no: enum X { NODE }
1862 case "TSEnumMember":
1863 return parent.id !== node;
1864 // yes: { [NODE]: value }
1865 // no: { NODE: value }
1866 case "TSPropertySignature":
1867 if (parent.key === node) {
1868 return !!parent.computed;
1869 }
1870 return true;
1871 }
1872 return true;
1873}
1874const TS_NODE_TYPES = [
1875 "TSAsExpression",
1876 // foo as number
1877 "TSTypeAssertion",
1878 // (<number>foo)
1879 "TSNonNullExpression",
1880 // foo!
1881 "TSInstantiationExpression",
1882 // foo<string>
1883 "TSSatisfiesExpression"
1884 // foo satisfies T
1885];
1886function unwrapTSNode(node) {
1887 if (TS_NODE_TYPES.includes(node.type)) {
1888 return unwrapTSNode(node.expression);
1889 } else {
1890 return node;
1891 }
1892}
1893
1894const isStaticExp = (p) => p.type === 4 && p.isStatic;
1895function isCoreComponent(tag) {
1896 switch (tag) {
1897 case "Teleport":
1898 case "teleport":
1899 return TELEPORT;
1900 case "Suspense":
1901 case "suspense":
1902 return SUSPENSE;
1903 case "KeepAlive":
1904 case "keep-alive":
1905 return KEEP_ALIVE;
1906 case "BaseTransition":
1907 case "base-transition":
1908 return BASE_TRANSITION;
1909 }
1910}
1911const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
1912const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
1913const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
1914const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
1915const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
1916const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
1917const isMemberExpressionBrowser = (exp) => {
1918 const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
1919 let state = 0 /* inMemberExp */;
1920 let stateStack = [];
1921 let currentOpenBracketCount = 0;
1922 let currentOpenParensCount = 0;
1923 let currentStringType = null;
1924 for (let i = 0; i < path.length; i++) {
1925 const char = path.charAt(i);
1926 switch (state) {
1927 case 0 /* inMemberExp */:
1928 if (char === "[") {
1929 stateStack.push(state);
1930 state = 1 /* inBrackets */;
1931 currentOpenBracketCount++;
1932 } else if (char === "(") {
1933 stateStack.push(state);
1934 state = 2 /* inParens */;
1935 currentOpenParensCount++;
1936 } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
1937 return false;
1938 }
1939 break;
1940 case 1 /* inBrackets */:
1941 if (char === `'` || char === `"` || char === "`") {
1942 stateStack.push(state);
1943 state = 3 /* inString */;
1944 currentStringType = char;
1945 } else if (char === `[`) {
1946 currentOpenBracketCount++;
1947 } else if (char === `]`) {
1948 if (!--currentOpenBracketCount) {
1949 state = stateStack.pop();
1950 }
1951 }
1952 break;
1953 case 2 /* inParens */:
1954 if (char === `'` || char === `"` || char === "`") {
1955 stateStack.push(state);
1956 state = 3 /* inString */;
1957 currentStringType = char;
1958 } else if (char === `(`) {
1959 currentOpenParensCount++;
1960 } else if (char === `)`) {
1961 if (i === path.length - 1) {
1962 return false;
1963 }
1964 if (!--currentOpenParensCount) {
1965 state = stateStack.pop();
1966 }
1967 }
1968 break;
1969 case 3 /* inString */:
1970 if (char === currentStringType) {
1971 state = stateStack.pop();
1972 currentStringType = null;
1973 }
1974 break;
1975 }
1976 }
1977 return !currentOpenBracketCount && !currentOpenParensCount;
1978};
1979const isMemberExpressionNode = (exp, context) => {
1980 try {
1981 let ret = exp.ast || parser.parseExpression(getExpSource(exp), {
1982 plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
1983 });
1984 ret = unwrapTSNode(ret);
1985 return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
1986 } catch (e) {
1987 return false;
1988 }
1989};
1990const isMemberExpression = isMemberExpressionNode;
1991const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
1992const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
1993const isFnExpressionNode = (exp, context) => {
1994 try {
1995 let ret = exp.ast || parser.parseExpression(getExpSource(exp), {
1996 plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
1997 });
1998 if (ret.type === "Program") {
1999 ret = ret.body[0];
2000 if (ret.type === "ExpressionStatement") {
2001 ret = ret.expression;
2002 }
2003 }
2004 ret = unwrapTSNode(ret);
2005 return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
2006 } catch (e) {
2007 return false;
2008 }
2009};
2010const isFnExpression = isFnExpressionNode;
2011function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
2012 return advancePositionWithMutation(
2013 {
2014 offset: pos.offset,
2015 line: pos.line,
2016 column: pos.column
2017 },
2018 source,
2019 numberOfCharacters
2020 );
2021}
2022function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
2023 let linesCount = 0;
2024 let lastNewLinePos = -1;
2025 for (let i = 0; i < numberOfCharacters; i++) {
2026 if (source.charCodeAt(i) === 10) {
2027 linesCount++;
2028 lastNewLinePos = i;
2029 }
2030 }
2031 pos.offset += numberOfCharacters;
2032 pos.line += linesCount;
2033 pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
2034 return pos;
2035}
2036function assert(condition, msg) {
2037 if (!condition) {
2038 throw new Error(msg || `unexpected compiler condition`);
2039 }
2040}
2041function findDir(node, name, allowEmpty = false) {
2042 for (let i = 0; i < node.props.length; i++) {
2043 const p = node.props[i];
2044 if (p.type === 7 && (allowEmpty || p.exp) && (shared.isString(name) ? p.name === name : name.test(p.name))) {
2045 return p;
2046 }
2047 }
2048}
2049function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
2050 for (let i = 0; i < node.props.length; i++) {
2051 const p = node.props[i];
2052 if (p.type === 6) {
2053 if (dynamicOnly) continue;
2054 if (p.name === name && (p.value || allowEmpty)) {
2055 return p;
2056 }
2057 } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
2058 return p;
2059 }
2060 }
2061}
2062function isStaticArgOf(arg, name) {
2063 return !!(arg && isStaticExp(arg) && arg.content === name);
2064}
2065function hasDynamicKeyVBind(node) {
2066 return node.props.some(
2067 (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
2068 p.arg.type !== 4 || // v-bind:[_ctx.foo]
2069 !p.arg.isStatic)
2070 // v-bind:[foo]
2071 );
2072}
2073function isText$1(node) {
2074 return node.type === 5 || node.type === 2;
2075}
2076function isVSlot(p) {
2077 return p.type === 7 && p.name === "slot";
2078}
2079function isTemplateNode(node) {
2080 return node.type === 1 && node.tagType === 3;
2081}
2082function isSlotOutlet(node) {
2083 return node.type === 1 && node.tagType === 2;
2084}
2085const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
2086function getUnnormalizedProps(props, callPath = []) {
2087 if (props && !shared.isString(props) && props.type === 14) {
2088 const callee = props.callee;
2089 if (!shared.isString(callee) && propsHelperSet.has(callee)) {
2090 return getUnnormalizedProps(
2091 props.arguments[0],
2092 callPath.concat(props)
2093 );
2094 }
2095 }
2096 return [props, callPath];
2097}
2098function injectProp(node, prop, context) {
2099 let propsWithInjection;
2100 let props = node.type === 13 ? node.props : node.arguments[2];
2101 let callPath = [];
2102 let parentCall;
2103 if (props && !shared.isString(props) && props.type === 14) {
2104 const ret = getUnnormalizedProps(props);
2105 props = ret[0];
2106 callPath = ret[1];
2107 parentCall = callPath[callPath.length - 1];
2108 }
2109 if (props == null || shared.isString(props)) {
2110 propsWithInjection = createObjectExpression([prop]);
2111 } else if (props.type === 14) {
2112 const first = props.arguments[0];
2113 if (!shared.isString(first) && first.type === 15) {
2114 if (!hasProp(prop, first)) {
2115 first.properties.unshift(prop);
2116 }
2117 } else {
2118 if (props.callee === TO_HANDLERS) {
2119 propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
2120 createObjectExpression([prop]),
2121 props
2122 ]);
2123 } else {
2124 props.arguments.unshift(createObjectExpression([prop]));
2125 }
2126 }
2127 !propsWithInjection && (propsWithInjection = props);
2128 } else if (props.type === 15) {
2129 if (!hasProp(prop, props)) {
2130 props.properties.unshift(prop);
2131 }
2132 propsWithInjection = props;
2133 } else {
2134 propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
2135 createObjectExpression([prop]),
2136 props
2137 ]);
2138 if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
2139 parentCall = callPath[callPath.length - 2];
2140 }
2141 }
2142 if (node.type === 13) {
2143 if (parentCall) {
2144 parentCall.arguments[0] = propsWithInjection;
2145 } else {
2146 node.props = propsWithInjection;
2147 }
2148 } else {
2149 if (parentCall) {
2150 parentCall.arguments[0] = propsWithInjection;
2151 } else {
2152 node.arguments[2] = propsWithInjection;
2153 }
2154 }
2155}
2156function hasProp(prop, props) {
2157 let result = false;
2158 if (prop.key.type === 4) {
2159 const propKeyName = prop.key.content;
2160 result = props.properties.some(
2161 (p) => p.key.type === 4 && p.key.content === propKeyName
2162 );
2163 }
2164 return result;
2165}
2166function toValidAssetId(name, type) {
2167 return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
2168 return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
2169 })}`;
2170}
2171function hasScopeRef(node, ids) {
2172 if (!node || Object.keys(ids).length === 0) {
2173 return false;
2174 }
2175 switch (node.type) {
2176 case 1:
2177 for (let i = 0; i < node.props.length; i++) {
2178 const p = node.props[i];
2179 if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
2180 return true;
2181 }
2182 }
2183 return node.children.some((c) => hasScopeRef(c, ids));
2184 case 11:
2185 if (hasScopeRef(node.source, ids)) {
2186 return true;
2187 }
2188 return node.children.some((c) => hasScopeRef(c, ids));
2189 case 9:
2190 return node.branches.some((b) => hasScopeRef(b, ids));
2191 case 10:
2192 if (hasScopeRef(node.condition, ids)) {
2193 return true;
2194 }
2195 return node.children.some((c) => hasScopeRef(c, ids));
2196 case 4:
2197 return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
2198 case 8:
2199 return node.children.some((c) => shared.isObject(c) && hasScopeRef(c, ids));
2200 case 5:
2201 case 12:
2202 return hasScopeRef(node.content, ids);
2203 case 2:
2204 case 3:
2205 case 20:
2206 return false;
2207 default:
2208 return false;
2209 }
2210}
2211function getMemoedVNodeCall(node) {
2212 if (node.type === 14 && node.callee === WITH_MEMO) {
2213 return node.arguments[1].returns;
2214 } else {
2215 return node;
2216 }
2217}
2218const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
2219
2220const defaultParserOptions = {
2221 parseMode: "base",
2222 ns: 0,
2223 delimiters: [`{{`, `}}`],
2224 getNamespace: () => 0,
2225 isVoidTag: shared.NO,
2226 isPreTag: shared.NO,
2227 isIgnoreNewlineTag: shared.NO,
2228 isCustomElement: shared.NO,
2229 onError: defaultOnError,
2230 onWarn: defaultOnWarn,
2231 comments: false,
2232 prefixIdentifiers: false
2233};
2234let currentOptions = defaultParserOptions;
2235let currentRoot = null;
2236let currentInput = "";
2237let currentOpenTag = null;
2238let currentProp = null;
2239let currentAttrValue = "";
2240let currentAttrStartIndex = -1;
2241let currentAttrEndIndex = -1;
2242let inPre = 0;
2243let inVPre = false;
2244let currentVPreBoundary = null;
2245const stack = [];
2246const tokenizer = new Tokenizer(stack, {
2247 onerr: emitError,
2248 ontext(start, end) {
2249 onText(getSlice(start, end), start, end);
2250 },
2251 ontextentity(char, start, end) {
2252 onText(char, start, end);
2253 },
2254 oninterpolation(start, end) {
2255 if (inVPre) {
2256 return onText(getSlice(start, end), start, end);
2257 }
2258 let innerStart = start + tokenizer.delimiterOpen.length;
2259 let innerEnd = end - tokenizer.delimiterClose.length;
2260 while (isWhitespace(currentInput.charCodeAt(innerStart))) {
2261 innerStart++;
2262 }
2263 while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
2264 innerEnd--;
2265 }
2266 let exp = getSlice(innerStart, innerEnd);
2267 if (exp.includes("&")) {
2268 {
2269 exp = decode_js.decodeHTML(exp);
2270 }
2271 }
2272 addNode({
2273 type: 5,
2274 content: createExp(exp, false, getLoc(innerStart, innerEnd)),
2275 loc: getLoc(start, end)
2276 });
2277 },
2278 onopentagname(start, end) {
2279 const name = getSlice(start, end);
2280 currentOpenTag = {
2281 type: 1,
2282 tag: name,
2283 ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
2284 tagType: 0,
2285 // will be refined on tag close
2286 props: [],
2287 children: [],
2288 loc: getLoc(start - 1, end),
2289 codegenNode: void 0
2290 };
2291 },
2292 onopentagend(end) {
2293 endOpenTag(end);
2294 },
2295 onclosetag(start, end) {
2296 const name = getSlice(start, end);
2297 if (!currentOptions.isVoidTag(name)) {
2298 let found = false;
2299 for (let i = 0; i < stack.length; i++) {
2300 const e = stack[i];
2301 if (e.tag.toLowerCase() === name.toLowerCase()) {
2302 found = true;
2303 if (i > 0) {
2304 emitError(24, stack[0].loc.start.offset);
2305 }
2306 for (let j = 0; j <= i; j++) {
2307 const el = stack.shift();
2308 onCloseTag(el, end, j < i);
2309 }
2310 break;
2311 }
2312 }
2313 if (!found) {
2314 emitError(23, backTrack(start, 60));
2315 }
2316 }
2317 },
2318 onselfclosingtag(end) {
2319 const name = currentOpenTag.tag;
2320 currentOpenTag.isSelfClosing = true;
2321 endOpenTag(end);
2322 if (stack[0] && stack[0].tag === name) {
2323 onCloseTag(stack.shift(), end);
2324 }
2325 },
2326 onattribname(start, end) {
2327 currentProp = {
2328 type: 6,
2329 name: getSlice(start, end),
2330 nameLoc: getLoc(start, end),
2331 value: void 0,
2332 loc: getLoc(start)
2333 };
2334 },
2335 ondirname(start, end) {
2336 const raw = getSlice(start, end);
2337 const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
2338 if (!inVPre && name === "") {
2339 emitError(26, start);
2340 }
2341 if (inVPre || name === "") {
2342 currentProp = {
2343 type: 6,
2344 name: raw,
2345 nameLoc: getLoc(start, end),
2346 value: void 0,
2347 loc: getLoc(start)
2348 };
2349 } else {
2350 currentProp = {
2351 type: 7,
2352 name,
2353 rawName: raw,
2354 exp: void 0,
2355 arg: void 0,
2356 modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
2357 loc: getLoc(start)
2358 };
2359 if (name === "pre") {
2360 inVPre = tokenizer.inVPre = true;
2361 currentVPreBoundary = currentOpenTag;
2362 const props = currentOpenTag.props;
2363 for (let i = 0; i < props.length; i++) {
2364 if (props[i].type === 7) {
2365 props[i] = dirToAttr(props[i]);
2366 }
2367 }
2368 }
2369 }
2370 },
2371 ondirarg(start, end) {
2372 if (start === end) return;
2373 const arg = getSlice(start, end);
2374 if (inVPre) {
2375 currentProp.name += arg;
2376 setLocEnd(currentProp.nameLoc, end);
2377 } else {
2378 const isStatic = arg[0] !== `[`;
2379 currentProp.arg = createExp(
2380 isStatic ? arg : arg.slice(1, -1),
2381 isStatic,
2382 getLoc(start, end),
2383 isStatic ? 3 : 0
2384 );
2385 }
2386 },
2387 ondirmodifier(start, end) {
2388 const mod = getSlice(start, end);
2389 if (inVPre) {
2390 currentProp.name += "." + mod;
2391 setLocEnd(currentProp.nameLoc, end);
2392 } else if (currentProp.name === "slot") {
2393 const arg = currentProp.arg;
2394 if (arg) {
2395 arg.content += "." + mod;
2396 setLocEnd(arg.loc, end);
2397 }
2398 } else {
2399 const exp = createSimpleExpression(mod, true, getLoc(start, end));
2400 currentProp.modifiers.push(exp);
2401 }
2402 },
2403 onattribdata(start, end) {
2404 currentAttrValue += getSlice(start, end);
2405 if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2406 currentAttrEndIndex = end;
2407 },
2408 onattribentity(char, start, end) {
2409 currentAttrValue += char;
2410 if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
2411 currentAttrEndIndex = end;
2412 },
2413 onattribnameend(end) {
2414 const start = currentProp.loc.start.offset;
2415 const name = getSlice(start, end);
2416 if (currentProp.type === 7) {
2417 currentProp.rawName = name;
2418 }
2419 if (currentOpenTag.props.some(
2420 (p) => (p.type === 7 ? p.rawName : p.name) === name
2421 )) {
2422 emitError(2, start);
2423 }
2424 },
2425 onattribend(quote, end) {
2426 if (currentOpenTag && currentProp) {
2427 setLocEnd(currentProp.loc, end);
2428 if (quote !== 0) {
2429 if (currentProp.type === 6) {
2430 if (currentProp.name === "class") {
2431 currentAttrValue = condense(currentAttrValue).trim();
2432 }
2433 if (quote === 1 && !currentAttrValue) {
2434 emitError(13, end);
2435 }
2436 currentProp.value = {
2437 type: 2,
2438 content: currentAttrValue,
2439 loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
2440 };
2441 if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
2442 tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
2443 }
2444 } else {
2445 let expParseMode = 0 /* Normal */;
2446 {
2447 if (currentProp.name === "for") {
2448 expParseMode = 3 /* Skip */;
2449 } else if (currentProp.name === "slot") {
2450 expParseMode = 1 /* Params */;
2451 } else if (currentProp.name === "on" && currentAttrValue.includes(";")) {
2452 expParseMode = 2 /* Statements */;
2453 }
2454 }
2455 currentProp.exp = createExp(
2456 currentAttrValue,
2457 false,
2458 getLoc(currentAttrStartIndex, currentAttrEndIndex),
2459 0,
2460 expParseMode
2461 );
2462 if (currentProp.name === "for") {
2463 currentProp.forParseResult = parseForExpression(currentProp.exp);
2464 }
2465 let syncIndex = -1;
2466 if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
2467 (mod) => mod.content === "sync"
2468 )) > -1 && checkCompatEnabled(
2469 "COMPILER_V_BIND_SYNC",
2470 currentOptions,
2471 currentProp.loc,
2472 currentProp.rawName
2473 )) {
2474 currentProp.name = "model";
2475 currentProp.modifiers.splice(syncIndex, 1);
2476 }
2477 }
2478 }
2479 if (currentProp.type !== 7 || currentProp.name !== "pre") {
2480 currentOpenTag.props.push(currentProp);
2481 }
2482 }
2483 currentAttrValue = "";
2484 currentAttrStartIndex = currentAttrEndIndex = -1;
2485 },
2486 oncomment(start, end) {
2487 if (currentOptions.comments) {
2488 addNode({
2489 type: 3,
2490 content: getSlice(start, end),
2491 loc: getLoc(start - 4, end + 3)
2492 });
2493 }
2494 },
2495 onend() {
2496 const end = currentInput.length;
2497 if (tokenizer.state !== 1) {
2498 switch (tokenizer.state) {
2499 case 5:
2500 case 8:
2501 emitError(5, end);
2502 break;
2503 case 3:
2504 case 4:
2505 emitError(
2506 25,
2507 tokenizer.sectionStart
2508 );
2509 break;
2510 case 28:
2511 if (tokenizer.currentSequence === Sequences.CdataEnd) {
2512 emitError(6, end);
2513 } else {
2514 emitError(7, end);
2515 }
2516 break;
2517 case 6:
2518 case 7:
2519 case 9:
2520 case 11:
2521 case 12:
2522 case 13:
2523 case 14:
2524 case 15:
2525 case 16:
2526 case 17:
2527 case 18:
2528 case 19:
2529 // "
2530 case 20:
2531 // '
2532 case 21:
2533 emitError(9, end);
2534 break;
2535 }
2536 }
2537 for (let index = 0; index < stack.length; index++) {
2538 onCloseTag(stack[index], end - 1);
2539 emitError(24, stack[index].loc.start.offset);
2540 }
2541 },
2542 oncdata(start, end) {
2543 if (stack[0].ns !== 0) {
2544 onText(getSlice(start, end), start, end);
2545 } else {
2546 emitError(1, start - 9);
2547 }
2548 },
2549 onprocessinginstruction(start) {
2550 if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2551 emitError(
2552 21,
2553 start - 1
2554 );
2555 }
2556 }
2557});
2558const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
2559const stripParensRE = /^\(|\)$/g;
2560function parseForExpression(input) {
2561 const loc = input.loc;
2562 const exp = input.content;
2563 const inMatch = exp.match(forAliasRE);
2564 if (!inMatch) return;
2565 const [, LHS, RHS] = inMatch;
2566 const createAliasExpression = (content, offset, asParam = false) => {
2567 const start = loc.start.offset + offset;
2568 const end = start + content.length;
2569 return createExp(
2570 content,
2571 false,
2572 getLoc(start, end),
2573 0,
2574 asParam ? 1 /* Params */ : 0 /* Normal */
2575 );
2576 };
2577 const result = {
2578 source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
2579 value: void 0,
2580 key: void 0,
2581 index: void 0,
2582 finalized: false
2583 };
2584 let valueContent = LHS.trim().replace(stripParensRE, "").trim();
2585 const trimmedOffset = LHS.indexOf(valueContent);
2586 const iteratorMatch = valueContent.match(forIteratorRE);
2587 if (iteratorMatch) {
2588 valueContent = valueContent.replace(forIteratorRE, "").trim();
2589 const keyContent = iteratorMatch[1].trim();
2590 let keyOffset;
2591 if (keyContent) {
2592 keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
2593 result.key = createAliasExpression(keyContent, keyOffset, true);
2594 }
2595 if (iteratorMatch[2]) {
2596 const indexContent = iteratorMatch[2].trim();
2597 if (indexContent) {
2598 result.index = createAliasExpression(
2599 indexContent,
2600 exp.indexOf(
2601 indexContent,
2602 result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
2603 ),
2604 true
2605 );
2606 }
2607 }
2608 }
2609 if (valueContent) {
2610 result.value = createAliasExpression(valueContent, trimmedOffset, true);
2611 }
2612 return result;
2613}
2614function getSlice(start, end) {
2615 return currentInput.slice(start, end);
2616}
2617function endOpenTag(end) {
2618 if (tokenizer.inSFCRoot) {
2619 currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
2620 }
2621 addNode(currentOpenTag);
2622 const { tag, ns } = currentOpenTag;
2623 if (ns === 0 && currentOptions.isPreTag(tag)) {
2624 inPre++;
2625 }
2626 if (currentOptions.isVoidTag(tag)) {
2627 onCloseTag(currentOpenTag, end);
2628 } else {
2629 stack.unshift(currentOpenTag);
2630 if (ns === 1 || ns === 2) {
2631 tokenizer.inXML = true;
2632 }
2633 }
2634 currentOpenTag = null;
2635}
2636function onText(content, start, end) {
2637 const parent = stack[0] || currentRoot;
2638 const lastNode = parent.children[parent.children.length - 1];
2639 if (lastNode && lastNode.type === 2) {
2640 lastNode.content += content;
2641 setLocEnd(lastNode.loc, end);
2642 } else {
2643 parent.children.push({
2644 type: 2,
2645 content,
2646 loc: getLoc(start, end)
2647 });
2648 }
2649}
2650function onCloseTag(el, end, isImplied = false) {
2651 if (isImplied) {
2652 setLocEnd(el.loc, backTrack(end, 60));
2653 } else {
2654 setLocEnd(el.loc, lookAhead(end, 62) + 1);
2655 }
2656 if (tokenizer.inSFCRoot) {
2657 if (el.children.length) {
2658 el.innerLoc.end = shared.extend({}, el.children[el.children.length - 1].loc.end);
2659 } else {
2660 el.innerLoc.end = shared.extend({}, el.innerLoc.start);
2661 }
2662 el.innerLoc.source = getSlice(
2663 el.innerLoc.start.offset,
2664 el.innerLoc.end.offset
2665 );
2666 }
2667 const { tag, ns, children } = el;
2668 if (!inVPre) {
2669 if (tag === "slot") {
2670 el.tagType = 2;
2671 } else if (isFragmentTemplate(el)) {
2672 el.tagType = 3;
2673 } else if (isComponent(el)) {
2674 el.tagType = 1;
2675 }
2676 }
2677 if (!tokenizer.inRCDATA) {
2678 el.children = condenseWhitespace(children);
2679 }
2680 if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
2681 const first = children[0];
2682 if (first && first.type === 2) {
2683 first.content = first.content.replace(/^\r?\n/, "");
2684 }
2685 }
2686 if (ns === 0 && currentOptions.isPreTag(tag)) {
2687 inPre--;
2688 }
2689 if (currentVPreBoundary === el) {
2690 inVPre = tokenizer.inVPre = false;
2691 currentVPreBoundary = null;
2692 }
2693 if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2694 tokenizer.inXML = false;
2695 }
2696 {
2697 const props = el.props;
2698 if (!tokenizer.inSFCRoot && isCompatEnabled(
2699 "COMPILER_NATIVE_TEMPLATE",
2700 currentOptions
2701 ) && el.tag === "template" && !isFragmentTemplate(el)) {
2702 const parent = stack[0] || currentRoot;
2703 const index = parent.children.indexOf(el);
2704 parent.children.splice(index, 1, ...el.children);
2705 }
2706 const inlineTemplateProp = props.find(
2707 (p) => p.type === 6 && p.name === "inline-template"
2708 );
2709 if (inlineTemplateProp && checkCompatEnabled(
2710 "COMPILER_INLINE_TEMPLATE",
2711 currentOptions,
2712 inlineTemplateProp.loc
2713 ) && el.children.length) {
2714 inlineTemplateProp.value = {
2715 type: 2,
2716 content: getSlice(
2717 el.children[0].loc.start.offset,
2718 el.children[el.children.length - 1].loc.end.offset
2719 ),
2720 loc: inlineTemplateProp.loc
2721 };
2722 }
2723 }
2724}
2725function lookAhead(index, c) {
2726 let i = index;
2727 while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
2728 return i;
2729}
2730function backTrack(index, c) {
2731 let i = index;
2732 while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
2733 return i;
2734}
2735const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
2736function isFragmentTemplate({ tag, props }) {
2737 if (tag === "template") {
2738 for (let i = 0; i < props.length; i++) {
2739 if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
2740 return true;
2741 }
2742 }
2743 }
2744 return false;
2745}
2746function isComponent({ tag, props }) {
2747 if (currentOptions.isCustomElement(tag)) {
2748 return false;
2749 }
2750 if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
2751 return true;
2752 }
2753 for (let i = 0; i < props.length; i++) {
2754 const p = props[i];
2755 if (p.type === 6) {
2756 if (p.name === "is" && p.value) {
2757 if (p.value.content.startsWith("vue:")) {
2758 return true;
2759 } else if (checkCompatEnabled(
2760 "COMPILER_IS_ON_ELEMENT",
2761 currentOptions,
2762 p.loc
2763 )) {
2764 return true;
2765 }
2766 }
2767 } else if (// :is on plain element - only treat as component in compat mode
2768 p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
2769 "COMPILER_IS_ON_ELEMENT",
2770 currentOptions,
2771 p.loc
2772 )) {
2773 return true;
2774 }
2775 }
2776 return false;
2777}
2778function isUpperCase(c) {
2779 return c > 64 && c < 91;
2780}
2781const windowsNewlineRE = /\r\n/g;
2782function condenseWhitespace(nodes, tag) {
2783 const shouldCondense = currentOptions.whitespace !== "preserve";
2784 let removedWhitespace = false;
2785 for (let i = 0; i < nodes.length; i++) {
2786 const node = nodes[i];
2787 if (node.type === 2) {
2788 if (!inPre) {
2789 if (isAllWhitespace(node.content)) {
2790 const prev = nodes[i - 1] && nodes[i - 1].type;
2791 const next = nodes[i + 1] && nodes[i + 1].type;
2792 if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2793 removedWhitespace = true;
2794 nodes[i] = null;
2795 } else {
2796 node.content = " ";
2797 }
2798 } else if (shouldCondense) {
2799 node.content = condense(node.content);
2800 }
2801 } else {
2802 node.content = node.content.replace(windowsNewlineRE, "\n");
2803 }
2804 }
2805 }
2806 return removedWhitespace ? nodes.filter(Boolean) : nodes;
2807}
2808function isAllWhitespace(str) {
2809 for (let i = 0; i < str.length; i++) {
2810 if (!isWhitespace(str.charCodeAt(i))) {
2811 return false;
2812 }
2813 }
2814 return true;
2815}
2816function hasNewlineChar(str) {
2817 for (let i = 0; i < str.length; i++) {
2818 const c = str.charCodeAt(i);
2819 if (c === 10 || c === 13) {
2820 return true;
2821 }
2822 }
2823 return false;
2824}
2825function condense(str) {
2826 let ret = "";
2827 let prevCharIsWhitespace = false;
2828 for (let i = 0; i < str.length; i++) {
2829 if (isWhitespace(str.charCodeAt(i))) {
2830 if (!prevCharIsWhitespace) {
2831 ret += " ";
2832 prevCharIsWhitespace = true;
2833 }
2834 } else {
2835 ret += str[i];
2836 prevCharIsWhitespace = false;
2837 }
2838 }
2839 return ret;
2840}
2841function addNode(node) {
2842 (stack[0] || currentRoot).children.push(node);
2843}
2844function getLoc(start, end) {
2845 return {
2846 start: tokenizer.getPos(start),
2847 // @ts-expect-error allow late attachment
2848 end: end == null ? end : tokenizer.getPos(end),
2849 // @ts-expect-error allow late attachment
2850 source: end == null ? end : getSlice(start, end)
2851 };
2852}
2853function cloneLoc(loc) {
2854 return getLoc(loc.start.offset, loc.end.offset);
2855}
2856function setLocEnd(loc, end) {
2857 loc.end = tokenizer.getPos(end);
2858 loc.source = getSlice(loc.start.offset, end);
2859}
2860function dirToAttr(dir) {
2861 const attr = {
2862 type: 6,
2863 name: dir.rawName,
2864 nameLoc: getLoc(
2865 dir.loc.start.offset,
2866 dir.loc.start.offset + dir.rawName.length
2867 ),
2868 value: void 0,
2869 loc: dir.loc
2870 };
2871 if (dir.exp) {
2872 const loc = dir.exp.loc;
2873 if (loc.end.offset < dir.loc.end.offset) {
2874 loc.start.offset--;
2875 loc.start.column--;
2876 loc.end.offset++;
2877 loc.end.column++;
2878 }
2879 attr.value = {
2880 type: 2,
2881 content: dir.exp.content,
2882 loc
2883 };
2884 }
2885 return attr;
2886}
2887function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
2888 const exp = createSimpleExpression(content, isStatic, loc, constType);
2889 if (!isStatic && currentOptions.prefixIdentifiers && parseMode !== 3 /* Skip */ && content.trim()) {
2890 if (isSimpleIdentifier(content)) {
2891 exp.ast = null;
2892 return exp;
2893 }
2894 try {
2895 const plugins = currentOptions.expressionPlugins;
2896 const options = {
2897 plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
2898 };
2899 if (parseMode === 2 /* Statements */) {
2900 exp.ast = parser.parse(` ${content} `, options).program;
2901 } else if (parseMode === 1 /* Params */) {
2902 exp.ast = parser.parseExpression(`(${content})=>{}`, options);
2903 } else {
2904 exp.ast = parser.parseExpression(`(${content})`, options);
2905 }
2906 } catch (e) {
2907 exp.ast = false;
2908 emitError(45, loc.start.offset, e.message);
2909 }
2910 }
2911 return exp;
2912}
2913function emitError(code, index, message) {
2914 currentOptions.onError(
2915 createCompilerError(code, getLoc(index, index), void 0, message)
2916 );
2917}
2918function reset() {
2919 tokenizer.reset();
2920 currentOpenTag = null;
2921 currentProp = null;
2922 currentAttrValue = "";
2923 currentAttrStartIndex = -1;
2924 currentAttrEndIndex = -1;
2925 stack.length = 0;
2926}
2927function baseParse(input, options) {
2928 reset();
2929 currentInput = input;
2930 currentOptions = shared.extend({}, defaultParserOptions);
2931 if (options) {
2932 let key;
2933 for (key in options) {
2934 if (options[key] != null) {
2935 currentOptions[key] = options[key];
2936 }
2937 }
2938 }
2939 tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2940 tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
2941 const delimiters = options && options.delimiters;
2942 if (delimiters) {
2943 tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2944 tokenizer.delimiterClose = toCharCodes(delimiters[1]);
2945 }
2946 const root = currentRoot = createRoot([], input);
2947 tokenizer.parse(currentInput);
2948 root.loc = getLoc(0, input.length);
2949 root.children = condenseWhitespace(root.children);
2950 currentRoot = null;
2951 return root;
2952}
2953
2954function cacheStatic(root, context) {
2955 walk(
2956 root,
2957 void 0,
2958 context,
2959 // Root node is unfortunately non-hoistable due to potential parent
2960 // fallthrough attributes.
2961 isSingleElementRoot(root, root.children[0])
2962 );
2963}
2964function isSingleElementRoot(root, child) {
2965 const { children } = root;
2966 return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
2967}
2968function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
2969 const { children } = node;
2970 const toCache = [];
2971 for (let i = 0; i < children.length; i++) {
2972 const child = children[i];
2973 if (child.type === 1 && child.tagType === 0) {
2974 const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2975 if (constantType > 0) {
2976 if (constantType >= 2) {
2977 child.codegenNode.patchFlag = -1;
2978 toCache.push(child);
2979 continue;
2980 }
2981 } else {
2982 const codegenNode = child.codegenNode;
2983 if (codegenNode.type === 13) {
2984 const flag = codegenNode.patchFlag;
2985 if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
2986 const props = getNodeProps(child);
2987 if (props) {
2988 codegenNode.props = context.hoist(props);
2989 }
2990 }
2991 if (codegenNode.dynamicProps) {
2992 codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
2993 }
2994 }
2995 }
2996 } else if (child.type === 12) {
2997 const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
2998 if (constantType >= 2) {
2999 toCache.push(child);
3000 continue;
3001 }
3002 }
3003 if (child.type === 1) {
3004 const isComponent = child.tagType === 1;
3005 if (isComponent) {
3006 context.scopes.vSlot++;
3007 }
3008 walk(child, node, context, false, inFor);
3009 if (isComponent) {
3010 context.scopes.vSlot--;
3011 }
3012 } else if (child.type === 11) {
3013 walk(child, node, context, child.children.length === 1, true);
3014 } else if (child.type === 9) {
3015 for (let i2 = 0; i2 < child.branches.length; i2++) {
3016 walk(
3017 child.branches[i2],
3018 node,
3019 context,
3020 child.branches[i2].children.length === 1,
3021 inFor
3022 );
3023 }
3024 }
3025 }
3026 let cachedAsArray = false;
3027 if (toCache.length === children.length && node.type === 1) {
3028 if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
3029 node.codegenNode.children = getCacheExpression(
3030 createArrayExpression(node.codegenNode.children)
3031 );
3032 cachedAsArray = true;
3033 } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
3034 const slot = getSlotNode(node.codegenNode, "default");
3035 if (slot) {
3036 slot.returns = getCacheExpression(
3037 createArrayExpression(slot.returns)
3038 );
3039 cachedAsArray = true;
3040 }
3041 } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
3042 const slotName = findDir(node, "slot", true);
3043 const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
3044 if (slot) {
3045 slot.returns = getCacheExpression(
3046 createArrayExpression(slot.returns)
3047 );
3048 cachedAsArray = true;
3049 }
3050 }
3051 }
3052 if (!cachedAsArray) {
3053 for (const child of toCache) {
3054 child.codegenNode = context.cache(child.codegenNode);
3055 }
3056 }
3057 function getCacheExpression(value) {
3058 const exp = context.cache(value);
3059 if (inFor && context.hmr) {
3060 exp.needArraySpread = true;
3061 }
3062 return exp;
3063 }
3064 function getSlotNode(node2, name) {
3065 if (node2.children && !shared.isArray(node2.children) && node2.children.type === 15) {
3066 const slot = node2.children.properties.find(
3067 (p) => p.key === name || p.key.content === name
3068 );
3069 return slot && slot.value;
3070 }
3071 }
3072 if (toCache.length && context.transformHoist) {
3073 context.transformHoist(children, context, node);
3074 }
3075}
3076function getConstantType(node, context) {
3077 const { constantCache } = context;
3078 switch (node.type) {
3079 case 1:
3080 if (node.tagType !== 0) {
3081 return 0;
3082 }
3083 const cached = constantCache.get(node);
3084 if (cached !== void 0) {
3085 return cached;
3086 }
3087 const codegenNode = node.codegenNode;
3088 if (codegenNode.type !== 13) {
3089 return 0;
3090 }
3091 if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
3092 return 0;
3093 }
3094 if (codegenNode.patchFlag === void 0) {
3095 let returnType2 = 3;
3096 const generatedPropsType = getGeneratedPropsConstantType(node, context);
3097 if (generatedPropsType === 0) {
3098 constantCache.set(node, 0);
3099 return 0;
3100 }
3101 if (generatedPropsType < returnType2) {
3102 returnType2 = generatedPropsType;
3103 }
3104 for (let i = 0; i < node.children.length; i++) {
3105 const childType = getConstantType(node.children[i], context);
3106 if (childType === 0) {
3107 constantCache.set(node, 0);
3108 return 0;
3109 }
3110 if (childType < returnType2) {
3111 returnType2 = childType;
3112 }
3113 }
3114 if (returnType2 > 1) {
3115 for (let i = 0; i < node.props.length; i++) {
3116 const p = node.props[i];
3117 if (p.type === 7 && p.name === "bind" && p.exp) {
3118 const expType = getConstantType(p.exp, context);
3119 if (expType === 0) {
3120 constantCache.set(node, 0);
3121 return 0;
3122 }
3123 if (expType < returnType2) {
3124 returnType2 = expType;
3125 }
3126 }
3127 }
3128 }
3129 if (codegenNode.isBlock) {
3130 for (let i = 0; i < node.props.length; i++) {
3131 const p = node.props[i];
3132 if (p.type === 7) {
3133 constantCache.set(node, 0);
3134 return 0;
3135 }
3136 }
3137 context.removeHelper(OPEN_BLOCK);
3138 context.removeHelper(
3139 getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
3140 );
3141 codegenNode.isBlock = false;
3142 context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
3143 }
3144 constantCache.set(node, returnType2);
3145 return returnType2;
3146 } else {
3147 constantCache.set(node, 0);
3148 return 0;
3149 }
3150 case 2:
3151 case 3:
3152 return 3;
3153 case 9:
3154 case 11:
3155 case 10:
3156 return 0;
3157 case 5:
3158 case 12:
3159 return getConstantType(node.content, context);
3160 case 4:
3161 return node.constType;
3162 case 8:
3163 let returnType = 3;
3164 for (let i = 0; i < node.children.length; i++) {
3165 const child = node.children[i];
3166 if (shared.isString(child) || shared.isSymbol(child)) {
3167 continue;
3168 }
3169 const childType = getConstantType(child, context);
3170 if (childType === 0) {
3171 return 0;
3172 } else if (childType < returnType) {
3173 returnType = childType;
3174 }
3175 }
3176 return returnType;
3177 case 20:
3178 return 2;
3179 default:
3180 return 0;
3181 }
3182}
3183const allowHoistedHelperSet = /* @__PURE__ */ new Set([
3184 NORMALIZE_CLASS,
3185 NORMALIZE_STYLE,
3186 NORMALIZE_PROPS,
3187 GUARD_REACTIVE_PROPS
3188]);
3189function getConstantTypeOfHelperCall(value, context) {
3190 if (value.type === 14 && !shared.isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
3191 const arg = value.arguments[0];
3192 if (arg.type === 4) {
3193 return getConstantType(arg, context);
3194 } else if (arg.type === 14) {
3195 return getConstantTypeOfHelperCall(arg, context);
3196 }
3197 }
3198 return 0;
3199}
3200function getGeneratedPropsConstantType(node, context) {
3201 let returnType = 3;
3202 const props = getNodeProps(node);
3203 if (props && props.type === 15) {
3204 const { properties } = props;
3205 for (let i = 0; i < properties.length; i++) {
3206 const { key, value } = properties[i];
3207 const keyType = getConstantType(key, context);
3208 if (keyType === 0) {
3209 return keyType;
3210 }
3211 if (keyType < returnType) {
3212 returnType = keyType;
3213 }
3214 let valueType;
3215 if (value.type === 4) {
3216 valueType = getConstantType(value, context);
3217 } else if (value.type === 14) {
3218 valueType = getConstantTypeOfHelperCall(value, context);
3219 } else {
3220 valueType = 0;
3221 }
3222 if (valueType === 0) {
3223 return valueType;
3224 }
3225 if (valueType < returnType) {
3226 returnType = valueType;
3227 }
3228 }
3229 }
3230 return returnType;
3231}
3232function getNodeProps(node) {
3233 const codegenNode = node.codegenNode;
3234 if (codegenNode.type === 13) {
3235 return codegenNode.props;
3236 }
3237}
3238
3239function createTransformContext(root, {
3240 filename = "",
3241 prefixIdentifiers = false,
3242 hoistStatic = false,
3243 hmr = false,
3244 cacheHandlers = false,
3245 nodeTransforms = [],
3246 directiveTransforms = {},
3247 transformHoist = null,
3248 isBuiltInComponent = shared.NOOP,
3249 isCustomElement = shared.NOOP,
3250 expressionPlugins = [],
3251 scopeId = null,
3252 slotted = true,
3253 ssr = false,
3254 inSSR = false,
3255 ssrCssVars = ``,
3256 bindingMetadata = shared.EMPTY_OBJ,
3257 inline = false,
3258 isTS = false,
3259 onError = defaultOnError,
3260 onWarn = defaultOnWarn,
3261 compatConfig
3262}) {
3263 const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
3264 const context = {
3265 // options
3266 filename,
3267 selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
3268 prefixIdentifiers,
3269 hoistStatic,
3270 hmr,
3271 cacheHandlers,
3272 nodeTransforms,
3273 directiveTransforms,
3274 transformHoist,
3275 isBuiltInComponent,
3276 isCustomElement,
3277 expressionPlugins,
3278 scopeId,
3279 slotted,
3280 ssr,
3281 inSSR,
3282 ssrCssVars,
3283 bindingMetadata,
3284 inline,
3285 isTS,
3286 onError,
3287 onWarn,
3288 compatConfig,
3289 // state
3290 root,
3291 helpers: /* @__PURE__ */ new Map(),
3292 components: /* @__PURE__ */ new Set(),
3293 directives: /* @__PURE__ */ new Set(),
3294 hoists: [],
3295 imports: [],
3296 cached: [],
3297 constantCache: /* @__PURE__ */ new WeakMap(),
3298 temps: 0,
3299 identifiers: /* @__PURE__ */ Object.create(null),
3300 scopes: {
3301 vFor: 0,
3302 vSlot: 0,
3303 vPre: 0,
3304 vOnce: 0
3305 },
3306 parent: null,
3307 grandParent: null,
3308 currentNode: root,
3309 childIndex: 0,
3310 inVOnce: false,
3311 // methods
3312 helper(name) {
3313 const count = context.helpers.get(name) || 0;
3314 context.helpers.set(name, count + 1);
3315 return name;
3316 },
3317 removeHelper(name) {
3318 const count = context.helpers.get(name);
3319 if (count) {
3320 const currentCount = count - 1;
3321 if (!currentCount) {
3322 context.helpers.delete(name);
3323 } else {
3324 context.helpers.set(name, currentCount);
3325 }
3326 }
3327 },
3328 helperString(name) {
3329 return `_${helperNameMap[context.helper(name)]}`;
3330 },
3331 replaceNode(node) {
3332 context.parent.children[context.childIndex] = context.currentNode = node;
3333 },
3334 removeNode(node) {
3335 const list = context.parent.children;
3336 const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
3337 if (!node || node === context.currentNode) {
3338 context.currentNode = null;
3339 context.onNodeRemoved();
3340 } else {
3341 if (context.childIndex > removalIndex) {
3342 context.childIndex--;
3343 context.onNodeRemoved();
3344 }
3345 }
3346 context.parent.children.splice(removalIndex, 1);
3347 },
3348 onNodeRemoved: shared.NOOP,
3349 addIdentifiers(exp) {
3350 {
3351 if (shared.isString(exp)) {
3352 addId(exp);
3353 } else if (exp.identifiers) {
3354 exp.identifiers.forEach(addId);
3355 } else if (exp.type === 4) {
3356 addId(exp.content);
3357 }
3358 }
3359 },
3360 removeIdentifiers(exp) {
3361 {
3362 if (shared.isString(exp)) {
3363 removeId(exp);
3364 } else if (exp.identifiers) {
3365 exp.identifiers.forEach(removeId);
3366 } else if (exp.type === 4) {
3367 removeId(exp.content);
3368 }
3369 }
3370 },
3371 hoist(exp) {
3372 if (shared.isString(exp)) exp = createSimpleExpression(exp);
3373 context.hoists.push(exp);
3374 const identifier = createSimpleExpression(
3375 `_hoisted_${context.hoists.length}`,
3376 false,
3377 exp.loc,
3378 2
3379 );
3380 identifier.hoisted = exp;
3381 return identifier;
3382 },
3383 cache(exp, isVNode = false, inVOnce = false) {
3384 const cacheExp = createCacheExpression(
3385 context.cached.length,
3386 exp,
3387 isVNode,
3388 inVOnce
3389 );
3390 context.cached.push(cacheExp);
3391 return cacheExp;
3392 }
3393 };
3394 {
3395 context.filters = /* @__PURE__ */ new Set();
3396 }
3397 function addId(id) {
3398 const { identifiers } = context;
3399 if (identifiers[id] === void 0) {
3400 identifiers[id] = 0;
3401 }
3402 identifiers[id]++;
3403 }
3404 function removeId(id) {
3405 context.identifiers[id]--;
3406 }
3407 return context;
3408}
3409function transform(root, options) {
3410 const context = createTransformContext(root, options);
3411 traverseNode(root, context);
3412 if (options.hoistStatic) {
3413 cacheStatic(root, context);
3414 }
3415 if (!options.ssr) {
3416 createRootCodegen(root, context);
3417 }
3418 root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
3419 root.components = [...context.components];
3420 root.directives = [...context.directives];
3421 root.imports = context.imports;
3422 root.hoists = context.hoists;
3423 root.temps = context.temps;
3424 root.cached = context.cached;
3425 root.transformed = true;
3426 {
3427 root.filters = [...context.filters];
3428 }
3429}
3430function createRootCodegen(root, context) {
3431 const { helper } = context;
3432 const { children } = root;
3433 if (children.length === 1) {
3434 const child = children[0];
3435 if (isSingleElementRoot(root, child) && child.codegenNode) {
3436 const codegenNode = child.codegenNode;
3437 if (codegenNode.type === 13) {
3438 convertToBlock(codegenNode, context);
3439 }
3440 root.codegenNode = codegenNode;
3441 } else {
3442 root.codegenNode = child;
3443 }
3444 } else if (children.length > 1) {
3445 let patchFlag = 64;
3446 root.codegenNode = createVNodeCall(
3447 context,
3448 helper(FRAGMENT),
3449 void 0,
3450 root.children,
3451 patchFlag,
3452 void 0,
3453 void 0,
3454 true,
3455 void 0,
3456 false
3457 );
3458 } else ;
3459}
3460function traverseChildren(parent, context) {
3461 let i = 0;
3462 const nodeRemoved = () => {
3463 i--;
3464 };
3465 for (; i < parent.children.length; i++) {
3466 const child = parent.children[i];
3467 if (shared.isString(child)) continue;
3468 context.grandParent = context.parent;
3469 context.parent = parent;
3470 context.childIndex = i;
3471 context.onNodeRemoved = nodeRemoved;
3472 traverseNode(child, context);
3473 }
3474}
3475function traverseNode(node, context) {
3476 context.currentNode = node;
3477 const { nodeTransforms } = context;
3478 const exitFns = [];
3479 for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
3480 const onExit = nodeTransforms[i2](node, context);
3481 if (onExit) {
3482 if (shared.isArray(onExit)) {
3483 exitFns.push(...onExit);
3484 } else {
3485 exitFns.push(onExit);
3486 }
3487 }
3488 if (!context.currentNode) {
3489 return;
3490 } else {
3491 node = context.currentNode;
3492 }
3493 }
3494 switch (node.type) {
3495 case 3:
3496 if (!context.ssr) {
3497 context.helper(CREATE_COMMENT);
3498 }
3499 break;
3500 case 5:
3501 if (!context.ssr) {
3502 context.helper(TO_DISPLAY_STRING);
3503 }
3504 break;
3505 // for container types, further traverse downwards
3506 case 9:
3507 for (let i2 = 0; i2 < node.branches.length; i2++) {
3508 traverseNode(node.branches[i2], context);
3509 }
3510 break;
3511 case 10:
3512 case 11:
3513 case 1:
3514 case 0:
3515 traverseChildren(node, context);
3516 break;
3517 }
3518 context.currentNode = node;
3519 let i = exitFns.length;
3520 while (i--) {
3521 exitFns[i]();
3522 }
3523}
3524function createStructuralDirectiveTransform(name, fn) {
3525 const matches = shared.isString(name) ? (n) => n === name : (n) => name.test(n);
3526 return (node, context) => {
3527 if (node.type === 1) {
3528 const { props } = node;
3529 if (node.tagType === 3 && props.some(isVSlot)) {
3530 return;
3531 }
3532 const exitFns = [];
3533 for (let i = 0; i < props.length; i++) {
3534 const prop = props[i];
3535 if (prop.type === 7 && matches(prop.name)) {
3536 props.splice(i, 1);
3537 i--;
3538 const onExit = fn(node, prop, context);
3539 if (onExit) exitFns.push(onExit);
3540 }
3541 }
3542 return exitFns;
3543 }
3544 };
3545}
3546
3547const PURE_ANNOTATION = `/*@__PURE__*/`;
3548const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
3549function createCodegenContext(ast, {
3550 mode = "function",
3551 prefixIdentifiers = mode === "module",
3552 sourceMap = false,
3553 filename = `template.vue.html`,
3554 scopeId = null,
3555 optimizeImports = false,
3556 runtimeGlobalName = `Vue`,
3557 runtimeModuleName = `vue`,
3558 ssrRuntimeModuleName = "vue/server-renderer",
3559 ssr = false,
3560 isTS = false,
3561 inSSR = false
3562}) {
3563 const context = {
3564 mode,
3565 prefixIdentifiers,
3566 sourceMap,
3567 filename,
3568 scopeId,
3569 optimizeImports,
3570 runtimeGlobalName,
3571 runtimeModuleName,
3572 ssrRuntimeModuleName,
3573 ssr,
3574 isTS,
3575 inSSR,
3576 source: ast.source,
3577 code: ``,
3578 column: 1,
3579 line: 1,
3580 offset: 0,
3581 indentLevel: 0,
3582 pure: false,
3583 map: void 0,
3584 helper(key) {
3585 return `_${helperNameMap[key]}`;
3586 },
3587 push(code, newlineIndex = -2 /* None */, node) {
3588 context.code += code;
3589 if (context.map) {
3590 if (node) {
3591 let name;
3592 if (node.type === 4 && !node.isStatic) {
3593 const content = node.content.replace(/^_ctx\./, "");
3594 if (content !== node.content && isSimpleIdentifier(content)) {
3595 name = content;
3596 }
3597 }
3598 addMapping(node.loc.start, name);
3599 }
3600 if (newlineIndex === -3 /* Unknown */) {
3601 advancePositionWithMutation(context, code);
3602 } else {
3603 context.offset += code.length;
3604 if (newlineIndex === -2 /* None */) {
3605 context.column += code.length;
3606 } else {
3607 if (newlineIndex === -1 /* End */) {
3608 newlineIndex = code.length - 1;
3609 }
3610 context.line++;
3611 context.column = code.length - newlineIndex;
3612 }
3613 }
3614 if (node && node.loc !== locStub) {
3615 addMapping(node.loc.end);
3616 }
3617 }
3618 },
3619 indent() {
3620 newline(++context.indentLevel);
3621 },
3622 deindent(withoutNewLine = false) {
3623 if (withoutNewLine) {
3624 --context.indentLevel;
3625 } else {
3626 newline(--context.indentLevel);
3627 }
3628 },
3629 newline() {
3630 newline(context.indentLevel);
3631 }
3632 };
3633 function newline(n) {
3634 context.push("\n" + ` `.repeat(n), 0 /* Start */);
3635 }
3636 function addMapping(loc, name = null) {
3637 const { _names, _mappings } = context.map;
3638 if (name !== null && !_names.has(name)) _names.add(name);
3639 _mappings.add({
3640 originalLine: loc.line,
3641 originalColumn: loc.column - 1,
3642 // source-map column is 0 based
3643 generatedLine: context.line,
3644 generatedColumn: context.column - 1,
3645 source: filename,
3646 name
3647 });
3648 }
3649 if (sourceMap) {
3650 context.map = new sourceMapJs.SourceMapGenerator();
3651 context.map.setSourceContent(filename, context.source);
3652 context.map._sources.add(filename);
3653 }
3654 return context;
3655}
3656function generate(ast, options = {}) {
3657 const context = createCodegenContext(ast, options);
3658 if (options.onContextCreated) options.onContextCreated(context);
3659 const {
3660 mode,
3661 push,
3662 prefixIdentifiers,
3663 indent,
3664 deindent,
3665 newline,
3666 scopeId,
3667 ssr
3668 } = context;
3669 const helpers = Array.from(ast.helpers);
3670 const hasHelpers = helpers.length > 0;
3671 const useWithBlock = !prefixIdentifiers && mode !== "module";
3672 const genScopeId = scopeId != null && mode === "module";
3673 const isSetupInlined = !!options.inline;
3674 const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
3675 if (mode === "module") {
3676 genModulePreamble(ast, preambleContext, genScopeId, isSetupInlined);
3677 } else {
3678 genFunctionPreamble(ast, preambleContext);
3679 }
3680 const functionName = ssr ? `ssrRender` : `render`;
3681 const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
3682 if (options.bindingMetadata && !options.inline) {
3683 args.push("$props", "$setup", "$data", "$options");
3684 }
3685 const signature = options.isTS ? args.map((arg) => `${arg}: any`).join(",") : args.join(", ");
3686 if (isSetupInlined) {
3687 push(`(${signature}) => {`);
3688 } else {
3689 push(`function ${functionName}(${signature}) {`);
3690 }
3691 indent();
3692 if (useWithBlock) {
3693 push(`with (_ctx) {`);
3694 indent();
3695 if (hasHelpers) {
3696 push(
3697 `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3698`,
3699 -1 /* End */
3700 );
3701 newline();
3702 }
3703 }
3704 if (ast.components.length) {
3705 genAssets(ast.components, "component", context);
3706 if (ast.directives.length || ast.temps > 0) {
3707 newline();
3708 }
3709 }
3710 if (ast.directives.length) {
3711 genAssets(ast.directives, "directive", context);
3712 if (ast.temps > 0) {
3713 newline();
3714 }
3715 }
3716 if (ast.filters && ast.filters.length) {
3717 newline();
3718 genAssets(ast.filters, "filter", context);
3719 newline();
3720 }
3721 if (ast.temps > 0) {
3722 push(`let `);
3723 for (let i = 0; i < ast.temps; i++) {
3724 push(`${i > 0 ? `, ` : ``}_temp${i}`);
3725 }
3726 }
3727 if (ast.components.length || ast.directives.length || ast.temps) {
3728 push(`
3729`, 0 /* Start */);
3730 newline();
3731 }
3732 if (!ssr) {
3733 push(`return `);
3734 }
3735 if (ast.codegenNode) {
3736 genNode(ast.codegenNode, context);
3737 } else {
3738 push(`null`);
3739 }
3740 if (useWithBlock) {
3741 deindent();
3742 push(`}`);
3743 }
3744 deindent();
3745 push(`}`);
3746 return {
3747 ast,
3748 code: context.code,
3749 preamble: isSetupInlined ? preambleContext.code : ``,
3750 map: context.map ? context.map.toJSON() : void 0
3751 };
3752}
3753function genFunctionPreamble(ast, context) {
3754 const {
3755 ssr,
3756 prefixIdentifiers,
3757 push,
3758 newline,
3759 runtimeModuleName,
3760 runtimeGlobalName,
3761 ssrRuntimeModuleName
3762 } = context;
3763 const VueBinding = ssr ? `require(${JSON.stringify(runtimeModuleName)})` : runtimeGlobalName;
3764 const helpers = Array.from(ast.helpers);
3765 if (helpers.length > 0) {
3766 if (prefixIdentifiers) {
3767 push(
3768 `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
3769`,
3770 -1 /* End */
3771 );
3772 } else {
3773 push(`const _Vue = ${VueBinding}
3774`, -1 /* End */);
3775 if (ast.hoists.length) {
3776 const staticHelpers = [
3777 CREATE_VNODE,
3778 CREATE_ELEMENT_VNODE,
3779 CREATE_COMMENT,
3780 CREATE_TEXT,
3781 CREATE_STATIC
3782 ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
3783 push(`const { ${staticHelpers} } = _Vue
3784`, -1 /* End */);
3785 }
3786 }
3787 }
3788 if (ast.ssrHelpers && ast.ssrHelpers.length) {
3789 push(
3790 `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
3791`,
3792 -1 /* End */
3793 );
3794 }
3795 genHoists(ast.hoists, context);
3796 newline();
3797 push(`return `);
3798}
3799function genModulePreamble(ast, context, genScopeId, inline) {
3800 const {
3801 push,
3802 newline,
3803 optimizeImports,
3804 runtimeModuleName,
3805 ssrRuntimeModuleName
3806 } = context;
3807 if (ast.helpers.size) {
3808 const helpers = Array.from(ast.helpers);
3809 if (optimizeImports) {
3810 push(
3811 `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
3812`,
3813 -1 /* End */
3814 );
3815 push(
3816 `
3817// Binding optimization for webpack code-split
3818const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
3819`,
3820 -1 /* End */
3821 );
3822 } else {
3823 push(
3824 `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
3825`,
3826 -1 /* End */
3827 );
3828 }
3829 }
3830 if (ast.ssrHelpers && ast.ssrHelpers.length) {
3831 push(
3832 `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
3833`,
3834 -1 /* End */
3835 );
3836 }
3837 if (ast.imports.length) {
3838 genImports(ast.imports, context);
3839 newline();
3840 }
3841 genHoists(ast.hoists, context);
3842 newline();
3843 if (!inline) {
3844 push(`export `);
3845 }
3846}
3847function genAssets(assets, type, { helper, push, newline, isTS }) {
3848 const resolver = helper(
3849 type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
3850 );
3851 for (let i = 0; i < assets.length; i++) {
3852 let id = assets[i];
3853 const maybeSelfReference = id.endsWith("__self");
3854 if (maybeSelfReference) {
3855 id = id.slice(0, -6);
3856 }
3857 push(
3858 `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
3859 );
3860 if (i < assets.length - 1) {
3861 newline();
3862 }
3863 }
3864}
3865function genHoists(hoists, context) {
3866 if (!hoists.length) {
3867 return;
3868 }
3869 context.pure = true;
3870 const { push, newline } = context;
3871 newline();
3872 for (let i = 0; i < hoists.length; i++) {
3873 const exp = hoists[i];
3874 if (exp) {
3875 push(`const _hoisted_${i + 1} = `);
3876 genNode(exp, context);
3877 newline();
3878 }
3879 }
3880 context.pure = false;
3881}
3882function genImports(importsOptions, context) {
3883 if (!importsOptions.length) {
3884 return;
3885 }
3886 importsOptions.forEach((imports) => {
3887 context.push(`import `);
3888 genNode(imports.exp, context);
3889 context.push(` from '${imports.path}'`);
3890 context.newline();
3891 });
3892}
3893function isText(n) {
3894 return shared.isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
3895}
3896function genNodeListAsArray(nodes, context) {
3897 const multilines = nodes.length > 3 || nodes.some((n) => shared.isArray(n) || !isText(n));
3898 context.push(`[`);
3899 multilines && context.indent();
3900 genNodeList(nodes, context, multilines);
3901 multilines && context.deindent();
3902 context.push(`]`);
3903}
3904function genNodeList(nodes, context, multilines = false, comma = true) {
3905 const { push, newline } = context;
3906 for (let i = 0; i < nodes.length; i++) {
3907 const node = nodes[i];
3908 if (shared.isString(node)) {
3909 push(node, -3 /* Unknown */);
3910 } else if (shared.isArray(node)) {
3911 genNodeListAsArray(node, context);
3912 } else {
3913 genNode(node, context);
3914 }
3915 if (i < nodes.length - 1) {
3916 if (multilines) {
3917 comma && push(",");
3918 newline();
3919 } else {
3920 comma && push(", ");
3921 }
3922 }
3923 }
3924}
3925function genNode(node, context) {
3926 if (shared.isString(node)) {
3927 context.push(node, -3 /* Unknown */);
3928 return;
3929 }
3930 if (shared.isSymbol(node)) {
3931 context.push(context.helper(node));
3932 return;
3933 }
3934 switch (node.type) {
3935 case 1:
3936 case 9:
3937 case 11:
3938 genNode(node.codegenNode, context);
3939 break;
3940 case 2:
3941 genText(node, context);
3942 break;
3943 case 4:
3944 genExpression(node, context);
3945 break;
3946 case 5:
3947 genInterpolation(node, context);
3948 break;
3949 case 12:
3950 genNode(node.codegenNode, context);
3951 break;
3952 case 8:
3953 genCompoundExpression(node, context);
3954 break;
3955 case 3:
3956 genComment(node, context);
3957 break;
3958 case 13:
3959 genVNodeCall(node, context);
3960 break;
3961 case 14:
3962 genCallExpression(node, context);
3963 break;
3964 case 15:
3965 genObjectExpression(node, context);
3966 break;
3967 case 17:
3968 genArrayExpression(node, context);
3969 break;
3970 case 18:
3971 genFunctionExpression(node, context);
3972 break;
3973 case 19:
3974 genConditionalExpression(node, context);
3975 break;
3976 case 20:
3977 genCacheExpression(node, context);
3978 break;
3979 case 21:
3980 genNodeList(node.body, context, true, false);
3981 break;
3982 // SSR only types
3983 case 22:
3984 genTemplateLiteral(node, context);
3985 break;
3986 case 23:
3987 genIfStatement(node, context);
3988 break;
3989 case 24:
3990 genAssignmentExpression(node, context);
3991 break;
3992 case 25:
3993 genSequenceExpression(node, context);
3994 break;
3995 case 26:
3996 genReturnStatement(node, context);
3997 break;
3998 }
3999}
4000function genText(node, context) {
4001 context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
4002}
4003function genExpression(node, context) {
4004 const { content, isStatic } = node;
4005 context.push(
4006 isStatic ? JSON.stringify(content) : content,
4007 -3 /* Unknown */,
4008 node
4009 );
4010}
4011function genInterpolation(node, context) {
4012 const { push, helper, pure } = context;
4013 if (pure) push(PURE_ANNOTATION);
4014 push(`${helper(TO_DISPLAY_STRING)}(`);
4015 genNode(node.content, context);
4016 push(`)`);
4017}
4018function genCompoundExpression(node, context) {
4019 for (let i = 0; i < node.children.length; i++) {
4020 const child = node.children[i];
4021 if (shared.isString(child)) {
4022 context.push(child, -3 /* Unknown */);
4023 } else {
4024 genNode(child, context);
4025 }
4026 }
4027}
4028function genExpressionAsPropertyKey(node, context) {
4029 const { push } = context;
4030 if (node.type === 8) {
4031 push(`[`);
4032 genCompoundExpression(node, context);
4033 push(`]`);
4034 } else if (node.isStatic) {
4035 const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
4036 push(text, -2 /* None */, node);
4037 } else {
4038 push(`[${node.content}]`, -3 /* Unknown */, node);
4039 }
4040}
4041function genComment(node, context) {
4042 const { push, helper, pure } = context;
4043 if (pure) {
4044 push(PURE_ANNOTATION);
4045 }
4046 push(
4047 `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
4048 -3 /* Unknown */,
4049 node
4050 );
4051}
4052function genVNodeCall(node, context) {
4053 const { push, helper, pure } = context;
4054 const {
4055 tag,
4056 props,
4057 children,
4058 patchFlag,
4059 dynamicProps,
4060 directives,
4061 isBlock,
4062 disableTracking,
4063 isComponent
4064 } = node;
4065 let patchFlagString;
4066 if (patchFlag) {
4067 {
4068 patchFlagString = String(patchFlag);
4069 }
4070 }
4071 if (directives) {
4072 push(helper(WITH_DIRECTIVES) + `(`);
4073 }
4074 if (isBlock) {
4075 push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
4076 }
4077 if (pure) {
4078 push(PURE_ANNOTATION);
4079 }
4080 const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
4081 push(helper(callHelper) + `(`, -2 /* None */, node);
4082 genNodeList(
4083 genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
4084 context
4085 );
4086 push(`)`);
4087 if (isBlock) {
4088 push(`)`);
4089 }
4090 if (directives) {
4091 push(`, `);
4092 genNode(directives, context);
4093 push(`)`);
4094 }
4095}
4096function genNullableArgs(args) {
4097 let i = args.length;
4098 while (i--) {
4099 if (args[i] != null) break;
4100 }
4101 return args.slice(0, i + 1).map((arg) => arg || `null`);
4102}
4103function genCallExpression(node, context) {
4104 const { push, helper, pure } = context;
4105 const callee = shared.isString(node.callee) ? node.callee : helper(node.callee);
4106 if (pure) {
4107 push(PURE_ANNOTATION);
4108 }
4109 push(callee + `(`, -2 /* None */, node);
4110 genNodeList(node.arguments, context);
4111 push(`)`);
4112}
4113function genObjectExpression(node, context) {
4114 const { push, indent, deindent, newline } = context;
4115 const { properties } = node;
4116 if (!properties.length) {
4117 push(`{}`, -2 /* None */, node);
4118 return;
4119 }
4120 const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
4121 push(multilines ? `{` : `{ `);
4122 multilines && indent();
4123 for (let i = 0; i < properties.length; i++) {
4124 const { key, value } = properties[i];
4125 genExpressionAsPropertyKey(key, context);
4126 push(`: `);
4127 genNode(value, context);
4128 if (i < properties.length - 1) {
4129 push(`,`);
4130 newline();
4131 }
4132 }
4133 multilines && deindent();
4134 push(multilines ? `}` : ` }`);
4135}
4136function genArrayExpression(node, context) {
4137 genNodeListAsArray(node.elements, context);
4138}
4139function genFunctionExpression(node, context) {
4140 const { push, indent, deindent } = context;
4141 const { params, returns, body, newline, isSlot } = node;
4142 if (isSlot) {
4143 push(`_${helperNameMap[WITH_CTX]}(`);
4144 }
4145 push(`(`, -2 /* None */, node);
4146 if (shared.isArray(params)) {
4147 genNodeList(params, context);
4148 } else if (params) {
4149 genNode(params, context);
4150 }
4151 push(`) => `);
4152 if (newline || body) {
4153 push(`{`);
4154 indent();
4155 }
4156 if (returns) {
4157 if (newline) {
4158 push(`return `);
4159 }
4160 if (shared.isArray(returns)) {
4161 genNodeListAsArray(returns, context);
4162 } else {
4163 genNode(returns, context);
4164 }
4165 } else if (body) {
4166 genNode(body, context);
4167 }
4168 if (newline || body) {
4169 deindent();
4170 push(`}`);
4171 }
4172 if (isSlot) {
4173 if (node.isNonScopedSlot) {
4174 push(`, undefined, true`);
4175 }
4176 push(`)`);
4177 }
4178}
4179function genConditionalExpression(node, context) {
4180 const { test, consequent, alternate, newline: needNewline } = node;
4181 const { push, indent, deindent, newline } = context;
4182 if (test.type === 4) {
4183 const needsParens = !isSimpleIdentifier(test.content);
4184 needsParens && push(`(`);
4185 genExpression(test, context);
4186 needsParens && push(`)`);
4187 } else {
4188 push(`(`);
4189 genNode(test, context);
4190 push(`)`);
4191 }
4192 needNewline && indent();
4193 context.indentLevel++;
4194 needNewline || push(` `);
4195 push(`? `);
4196 genNode(consequent, context);
4197 context.indentLevel--;
4198 needNewline && newline();
4199 needNewline || push(` `);
4200 push(`: `);
4201 const isNested = alternate.type === 19;
4202 if (!isNested) {
4203 context.indentLevel++;
4204 }
4205 genNode(alternate, context);
4206 if (!isNested) {
4207 context.indentLevel--;
4208 }
4209 needNewline && deindent(
4210 true
4211 /* without newline */
4212 );
4213}
4214function genCacheExpression(node, context) {
4215 const { push, helper, indent, deindent, newline } = context;
4216 const { needPauseTracking, needArraySpread } = node;
4217 if (needArraySpread) {
4218 push(`[...(`);
4219 }
4220 push(`_cache[${node.index}] || (`);
4221 if (needPauseTracking) {
4222 indent();
4223 push(`${helper(SET_BLOCK_TRACKING)}(-1`);
4224 if (node.inVOnce) push(`, true`);
4225 push(`),`);
4226 newline();
4227 push(`(`);
4228 }
4229 push(`_cache[${node.index}] = `);
4230 genNode(node.value, context);
4231 if (needPauseTracking) {
4232 push(`).cacheIndex = ${node.index},`);
4233 newline();
4234 push(`${helper(SET_BLOCK_TRACKING)}(1),`);
4235 newline();
4236 push(`_cache[${node.index}]`);
4237 deindent();
4238 }
4239 push(`)`);
4240 if (needArraySpread) {
4241 push(`)]`);
4242 }
4243}
4244function genTemplateLiteral(node, context) {
4245 const { push, indent, deindent } = context;
4246 push("`");
4247 const l = node.elements.length;
4248 const multilines = l > 3;
4249 for (let i = 0; i < l; i++) {
4250 const e = node.elements[i];
4251 if (shared.isString(e)) {
4252 push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
4253 } else {
4254 push("${");
4255 if (multilines) indent();
4256 genNode(e, context);
4257 if (multilines) deindent();
4258 push("}");
4259 }
4260 }
4261 push("`");
4262}
4263function genIfStatement(node, context) {
4264 const { push, indent, deindent } = context;
4265 const { test, consequent, alternate } = node;
4266 push(`if (`);
4267 genNode(test, context);
4268 push(`) {`);
4269 indent();
4270 genNode(consequent, context);
4271 deindent();
4272 push(`}`);
4273 if (alternate) {
4274 push(` else `);
4275 if (alternate.type === 23) {
4276 genIfStatement(alternate, context);
4277 } else {
4278 push(`{`);
4279 indent();
4280 genNode(alternate, context);
4281 deindent();
4282 push(`}`);
4283 }
4284 }
4285}
4286function genAssignmentExpression(node, context) {
4287 genNode(node.left, context);
4288 context.push(` = `);
4289 genNode(node.right, context);
4290}
4291function genSequenceExpression(node, context) {
4292 context.push(`(`);
4293 genNodeList(node.expressions, context);
4294 context.push(`)`);
4295}
4296function genReturnStatement({ returns }, context) {
4297 context.push(`return `);
4298 if (shared.isArray(returns)) {
4299 genNodeListAsArray(returns, context);
4300 } else {
4301 genNode(returns, context);
4302 }
4303}
4304
4305const isLiteralWhitelisted = /* @__PURE__ */ shared.makeMap("true,false,null,this");
4306const transformExpression = (node, context) => {
4307 if (node.type === 5) {
4308 node.content = processExpression(
4309 node.content,
4310 context
4311 );
4312 } else if (node.type === 1) {
4313 const memo = findDir(node, "memo");
4314 for (let i = 0; i < node.props.length; i++) {
4315 const dir = node.props[i];
4316 if (dir.type === 7 && dir.name !== "for") {
4317 const exp = dir.exp;
4318 const arg = dir.arg;
4319 if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
4320 !(memo && arg && arg.type === 4 && arg.content === "key")) {
4321 dir.exp = processExpression(
4322 exp,
4323 context,
4324 // slot args must be processed as function params
4325 dir.name === "slot"
4326 );
4327 }
4328 if (arg && arg.type === 4 && !arg.isStatic) {
4329 dir.arg = processExpression(arg, context);
4330 }
4331 }
4332 }
4333 }
4334};
4335function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
4336 if (!context.prefixIdentifiers || !node.content.trim()) {
4337 return node;
4338 }
4339 const { inline, bindingMetadata } = context;
4340 const rewriteIdentifier = (raw, parent, id) => {
4341 const type = shared.hasOwn(bindingMetadata, raw) && bindingMetadata[raw];
4342 if (inline) {
4343 const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
4344 const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
4345 const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
4346 const isNewExpression = parent && isInNewExpression(parentStack);
4347 const wrapWithUnref = (raw2) => {
4348 const wrapped = `${context.helperString(UNREF)}(${raw2})`;
4349 return isNewExpression ? `(${wrapped})` : wrapped;
4350 };
4351 if (isConst(type) || type === "setup-reactive-const" || localVars[raw]) {
4352 return raw;
4353 } else if (type === "setup-ref") {
4354 return `${raw}.value`;
4355 } else if (type === "setup-maybe-ref") {
4356 return isAssignmentLVal || isUpdateArg || isDestructureAssignment ? `${raw}.value` : wrapWithUnref(raw);
4357 } else if (type === "setup-let") {
4358 if (isAssignmentLVal) {
4359 const { right: rVal, operator } = parent;
4360 const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
4361 const rExpString = stringifyExpression(
4362 processExpression(
4363 createSimpleExpression(rExp, false),
4364 context,
4365 false,
4366 false,
4367 knownIds
4368 )
4369 );
4370 return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
4371` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
4372 } else if (isUpdateArg) {
4373 id.start = parent.start;
4374 id.end = parent.end;
4375 const { prefix: isPrefix, operator } = parent;
4376 const prefix = isPrefix ? operator : ``;
4377 const postfix = isPrefix ? `` : operator;
4378 return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore
4379` : ``} ? ${prefix}${raw}.value${postfix} : ${prefix}${raw}${postfix}`;
4380 } else if (isDestructureAssignment) {
4381 return raw;
4382 } else {
4383 return wrapWithUnref(raw);
4384 }
4385 } else if (type === "props") {
4386 return shared.genPropsAccessExp(raw);
4387 } else if (type === "props-aliased") {
4388 return shared.genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
4389 }
4390 } else {
4391 if (type && type.startsWith("setup") || type === "literal-const") {
4392 return `$setup.${raw}`;
4393 } else if (type === "props-aliased") {
4394 return `$props['${bindingMetadata.__propsAliases[raw]}']`;
4395 } else if (type) {
4396 return `$${type}.${raw}`;
4397 }
4398 }
4399 return `_ctx.${raw}`;
4400 };
4401 const rawExp = node.content;
4402 let ast = node.ast;
4403 if (ast === false) {
4404 return node;
4405 }
4406 if (ast === null || !ast && isSimpleIdentifier(rawExp)) {
4407 const isScopeVarReference = context.identifiers[rawExp];
4408 const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
4409 const isLiteral = isLiteralWhitelisted(rawExp);
4410 if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
4411 if (isConst(bindingMetadata[rawExp])) {
4412 node.constType = 1;
4413 }
4414 node.content = rewriteIdentifier(rawExp);
4415 } else if (!isScopeVarReference) {
4416 if (isLiteral) {
4417 node.constType = 3;
4418 } else {
4419 node.constType = 2;
4420 }
4421 }
4422 return node;
4423 }
4424 if (!ast) {
4425 const source = asRawStatements ? ` ${rawExp} ` : `(${rawExp})${asParams ? `=>{}` : ``}`;
4426 try {
4427 ast = parser.parseExpression(source, {
4428 sourceType: "module",
4429 plugins: context.expressionPlugins
4430 });
4431 } catch (e) {
4432 context.onError(
4433 createCompilerError(
4434 45,
4435 node.loc,
4436 void 0,
4437 e.message
4438 )
4439 );
4440 return node;
4441 }
4442 }
4443 const ids = [];
4444 const parentStack = [];
4445 const knownIds = Object.create(context.identifiers);
4446 walkIdentifiers(
4447 ast,
4448 (node2, parent, _, isReferenced, isLocal) => {
4449 if (isStaticPropertyKey(node2, parent)) {
4450 return;
4451 }
4452 if (node2.name.startsWith("_filter_")) {
4453 return;
4454 }
4455 const needPrefix = isReferenced && canPrefix(node2);
4456 if (needPrefix && !isLocal) {
4457 if (isStaticProperty(parent) && parent.shorthand) {
4458 node2.prefix = `${node2.name}: `;
4459 }
4460 node2.name = rewriteIdentifier(node2.name, parent, node2);
4461 ids.push(node2);
4462 } else {
4463 if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
4464 node2.isConstant = true;
4465 }
4466 ids.push(node2);
4467 }
4468 },
4469 true,
4470 // invoke on ALL identifiers
4471 parentStack,
4472 knownIds
4473 );
4474 const children = [];
4475 ids.sort((a, b) => a.start - b.start);
4476 ids.forEach((id, i) => {
4477 const start = id.start - 1;
4478 const end = id.end - 1;
4479 const last = ids[i - 1];
4480 const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
4481 if (leadingText.length || id.prefix) {
4482 children.push(leadingText + (id.prefix || ``));
4483 }
4484 const source = rawExp.slice(start, end);
4485 children.push(
4486 createSimpleExpression(
4487 id.name,
4488 false,
4489 {
4490 start: advancePositionWithClone(node.loc.start, source, start),
4491 end: advancePositionWithClone(node.loc.start, source, end),
4492 source
4493 },
4494 id.isConstant ? 3 : 0
4495 )
4496 );
4497 if (i === ids.length - 1 && end < rawExp.length) {
4498 children.push(rawExp.slice(end));
4499 }
4500 });
4501 let ret;
4502 if (children.length) {
4503 ret = createCompoundExpression(children, node.loc);
4504 ret.ast = ast;
4505 } else {
4506 ret = node;
4507 ret.constType = 3;
4508 }
4509 ret.identifiers = Object.keys(knownIds);
4510 return ret;
4511}
4512function canPrefix(id) {
4513 if (shared.isGloballyAllowed(id.name)) {
4514 return false;
4515 }
4516 if (id.name === "require") {
4517 return false;
4518 }
4519 return true;
4520}
4521function stringifyExpression(exp) {
4522 if (shared.isString(exp)) {
4523 return exp;
4524 } else if (exp.type === 4) {
4525 return exp.content;
4526 } else {
4527 return exp.children.map(stringifyExpression).join("");
4528 }
4529}
4530function isConst(type) {
4531 return type === "setup-const" || type === "literal-const";
4532}
4533
4534const transformIf = createStructuralDirectiveTransform(
4535 /^(if|else|else-if)$/,
4536 (node, dir, context) => {
4537 return processIf(node, dir, context, (ifNode, branch, isRoot) => {
4538 const siblings = context.parent.children;
4539 let i = siblings.indexOf(ifNode);
4540 let key = 0;
4541 while (i-- >= 0) {
4542 const sibling = siblings[i];
4543 if (sibling && sibling.type === 9) {
4544 key += sibling.branches.length;
4545 }
4546 }
4547 return () => {
4548 if (isRoot) {
4549 ifNode.codegenNode = createCodegenNodeForBranch(
4550 branch,
4551 key,
4552 context
4553 );
4554 } else {
4555 const parentCondition = getParentCondition(ifNode.codegenNode);
4556 parentCondition.alternate = createCodegenNodeForBranch(
4557 branch,
4558 key + ifNode.branches.length - 1,
4559 context
4560 );
4561 }
4562 };
4563 });
4564 }
4565);
4566function processIf(node, dir, context, processCodegen) {
4567 if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
4568 const loc = dir.exp ? dir.exp.loc : node.loc;
4569 context.onError(
4570 createCompilerError(28, dir.loc)
4571 );
4572 dir.exp = createSimpleExpression(`true`, false, loc);
4573 }
4574 if (context.prefixIdentifiers && dir.exp) {
4575 dir.exp = processExpression(dir.exp, context);
4576 }
4577 if (dir.name === "if") {
4578 const branch = createIfBranch(node, dir);
4579 const ifNode = {
4580 type: 9,
4581 loc: cloneLoc(node.loc),
4582 branches: [branch]
4583 };
4584 context.replaceNode(ifNode);
4585 if (processCodegen) {
4586 return processCodegen(ifNode, branch, true);
4587 }
4588 } else {
4589 const siblings = context.parent.children;
4590 let i = siblings.indexOf(node);
4591 while (i-- >= -1) {
4592 const sibling = siblings[i];
4593 if (sibling && sibling.type === 3) {
4594 context.removeNode(sibling);
4595 continue;
4596 }
4597 if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
4598 context.removeNode(sibling);
4599 continue;
4600 }
4601 if (sibling && sibling.type === 9) {
4602 if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
4603 context.onError(
4604 createCompilerError(30, node.loc)
4605 );
4606 }
4607 context.removeNode();
4608 const branch = createIfBranch(node, dir);
4609 {
4610 const key = branch.userKey;
4611 if (key) {
4612 sibling.branches.forEach(({ userKey }) => {
4613 if (isSameKey(userKey, key)) {
4614 context.onError(
4615 createCompilerError(
4616 29,
4617 branch.userKey.loc
4618 )
4619 );
4620 }
4621 });
4622 }
4623 }
4624 sibling.branches.push(branch);
4625 const onExit = processCodegen && processCodegen(sibling, branch, false);
4626 traverseNode(branch, context);
4627 if (onExit) onExit();
4628 context.currentNode = null;
4629 } else {
4630 context.onError(
4631 createCompilerError(30, node.loc)
4632 );
4633 }
4634 break;
4635 }
4636 }
4637}
4638function createIfBranch(node, dir) {
4639 const isTemplateIf = node.tagType === 3;
4640 return {
4641 type: 10,
4642 loc: node.loc,
4643 condition: dir.name === "else" ? void 0 : dir.exp,
4644 children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
4645 userKey: findProp(node, `key`),
4646 isTemplateIf
4647 };
4648}
4649function createCodegenNodeForBranch(branch, keyIndex, context) {
4650 if (branch.condition) {
4651 return createConditionalExpression(
4652 branch.condition,
4653 createChildrenCodegenNode(branch, keyIndex, context),
4654 // make sure to pass in asBlock: true so that the comment node call
4655 // closes the current block.
4656 createCallExpression(context.helper(CREATE_COMMENT), [
4657 '""',
4658 "true"
4659 ])
4660 );
4661 } else {
4662 return createChildrenCodegenNode(branch, keyIndex, context);
4663 }
4664}
4665function createChildrenCodegenNode(branch, keyIndex, context) {
4666 const { helper } = context;
4667 const keyProperty = createObjectProperty(
4668 `key`,
4669 createSimpleExpression(
4670 `${keyIndex}`,
4671 false,
4672 locStub,
4673 2
4674 )
4675 );
4676 const { children } = branch;
4677 const firstChild = children[0];
4678 const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
4679 if (needFragmentWrapper) {
4680 if (children.length === 1 && firstChild.type === 11) {
4681 const vnodeCall = firstChild.codegenNode;
4682 injectProp(vnodeCall, keyProperty, context);
4683 return vnodeCall;
4684 } else {
4685 let patchFlag = 64;
4686 return createVNodeCall(
4687 context,
4688 helper(FRAGMENT),
4689 createObjectExpression([keyProperty]),
4690 children,
4691 patchFlag,
4692 void 0,
4693 void 0,
4694 true,
4695 false,
4696 false,
4697 branch.loc
4698 );
4699 }
4700 } else {
4701 const ret = firstChild.codegenNode;
4702 const vnodeCall = getMemoedVNodeCall(ret);
4703 if (vnodeCall.type === 13) {
4704 convertToBlock(vnodeCall, context);
4705 }
4706 injectProp(vnodeCall, keyProperty, context);
4707 return ret;
4708 }
4709}
4710function isSameKey(a, b) {
4711 if (!a || a.type !== b.type) {
4712 return false;
4713 }
4714 if (a.type === 6) {
4715 if (a.value.content !== b.value.content) {
4716 return false;
4717 }
4718 } else {
4719 const exp = a.exp;
4720 const branchExp = b.exp;
4721 if (exp.type !== branchExp.type) {
4722 return false;
4723 }
4724 if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
4725 return false;
4726 }
4727 }
4728 return true;
4729}
4730function getParentCondition(node) {
4731 while (true) {
4732 if (node.type === 19) {
4733 if (node.alternate.type === 19) {
4734 node = node.alternate;
4735 } else {
4736 return node;
4737 }
4738 } else if (node.type === 20) {
4739 node = node.value;
4740 }
4741 }
4742}
4743
4744const transformBind = (dir, _node, context) => {
4745 const { modifiers, loc } = dir;
4746 const arg = dir.arg;
4747 let { exp } = dir;
4748 if (exp && exp.type === 4 && !exp.content.trim()) {
4749 {
4750 context.onError(
4751 createCompilerError(34, loc)
4752 );
4753 return {
4754 props: [
4755 createObjectProperty(arg, createSimpleExpression("", true, loc))
4756 ]
4757 };
4758 }
4759 }
4760 if (!exp) {
4761 if (arg.type !== 4 || !arg.isStatic) {
4762 context.onError(
4763 createCompilerError(
4764 52,
4765 arg.loc
4766 )
4767 );
4768 return {
4769 props: [
4770 createObjectProperty(arg, createSimpleExpression("", true, loc))
4771 ]
4772 };
4773 }
4774 transformBindShorthand(dir, context);
4775 exp = dir.exp;
4776 }
4777 if (arg.type !== 4) {
4778 arg.children.unshift(`(`);
4779 arg.children.push(`) || ""`);
4780 } else if (!arg.isStatic) {
4781 arg.content = `${arg.content} || ""`;
4782 }
4783 if (modifiers.some((mod) => mod.content === "camel")) {
4784 if (arg.type === 4) {
4785 if (arg.isStatic) {
4786 arg.content = shared.camelize(arg.content);
4787 } else {
4788 arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
4789 }
4790 } else {
4791 arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
4792 arg.children.push(`)`);
4793 }
4794 }
4795 if (!context.inSSR) {
4796 if (modifiers.some((mod) => mod.content === "prop")) {
4797 injectPrefix(arg, ".");
4798 }
4799 if (modifiers.some((mod) => mod.content === "attr")) {
4800 injectPrefix(arg, "^");
4801 }
4802 }
4803 return {
4804 props: [createObjectProperty(arg, exp)]
4805 };
4806};
4807const transformBindShorthand = (dir, context) => {
4808 const arg = dir.arg;
4809 const propName = shared.camelize(arg.content);
4810 dir.exp = createSimpleExpression(propName, false, arg.loc);
4811 {
4812 dir.exp = processExpression(dir.exp, context);
4813 }
4814};
4815const injectPrefix = (arg, prefix) => {
4816 if (arg.type === 4) {
4817 if (arg.isStatic) {
4818 arg.content = prefix + arg.content;
4819 } else {
4820 arg.content = `\`${prefix}\${${arg.content}}\``;
4821 }
4822 } else {
4823 arg.children.unshift(`'${prefix}' + (`);
4824 arg.children.push(`)`);
4825 }
4826};
4827
4828const transformFor = createStructuralDirectiveTransform(
4829 "for",
4830 (node, dir, context) => {
4831 const { helper, removeHelper } = context;
4832 return processFor(node, dir, context, (forNode) => {
4833 const renderExp = createCallExpression(helper(RENDER_LIST), [
4834 forNode.source
4835 ]);
4836 const isTemplate = isTemplateNode(node);
4837 const memo = findDir(node, "memo");
4838 const keyProp = findProp(node, `key`, false, true);
4839 const isDirKey = keyProp && keyProp.type === 7;
4840 if (isDirKey && !keyProp.exp) {
4841 transformBindShorthand(keyProp, context);
4842 }
4843 let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
4844 if (memo && keyExp && isDirKey) {
4845 {
4846 keyProp.exp = keyExp = processExpression(
4847 keyExp,
4848 context
4849 );
4850 }
4851 }
4852 const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
4853 if (isTemplate) {
4854 if (memo) {
4855 memo.exp = processExpression(
4856 memo.exp,
4857 context
4858 );
4859 }
4860 if (keyProperty && keyProp.type !== 6) {
4861 keyProperty.value = processExpression(
4862 keyProperty.value,
4863 context
4864 );
4865 }
4866 }
4867 const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
4868 const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
4869 forNode.codegenNode = createVNodeCall(
4870 context,
4871 helper(FRAGMENT),
4872 void 0,
4873 renderExp,
4874 fragmentFlag,
4875 void 0,
4876 void 0,
4877 true,
4878 !isStableFragment,
4879 false,
4880 node.loc
4881 );
4882 return () => {
4883 let childBlock;
4884 const { children } = forNode;
4885 if (isTemplate) {
4886 node.children.some((c) => {
4887 if (c.type === 1) {
4888 const key = findProp(c, "key");
4889 if (key) {
4890 context.onError(
4891 createCompilerError(
4892 33,
4893 key.loc
4894 )
4895 );
4896 return true;
4897 }
4898 }
4899 });
4900 }
4901 const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
4902 const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
4903 if (slotOutlet) {
4904 childBlock = slotOutlet.codegenNode;
4905 if (isTemplate && keyProperty) {
4906 injectProp(childBlock, keyProperty, context);
4907 }
4908 } else if (needFragmentWrapper) {
4909 childBlock = createVNodeCall(
4910 context,
4911 helper(FRAGMENT),
4912 keyProperty ? createObjectExpression([keyProperty]) : void 0,
4913 node.children,
4914 64,
4915 void 0,
4916 void 0,
4917 true,
4918 void 0,
4919 false
4920 );
4921 } else {
4922 childBlock = children[0].codegenNode;
4923 if (isTemplate && keyProperty) {
4924 injectProp(childBlock, keyProperty, context);
4925 }
4926 if (childBlock.isBlock !== !isStableFragment) {
4927 if (childBlock.isBlock) {
4928 removeHelper(OPEN_BLOCK);
4929 removeHelper(
4930 getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
4931 );
4932 } else {
4933 removeHelper(
4934 getVNodeHelper(context.inSSR, childBlock.isComponent)
4935 );
4936 }
4937 }
4938 childBlock.isBlock = !isStableFragment;
4939 if (childBlock.isBlock) {
4940 helper(OPEN_BLOCK);
4941 helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
4942 } else {
4943 helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
4944 }
4945 }
4946 if (memo) {
4947 const loop = createFunctionExpression(
4948 createForLoopParams(forNode.parseResult, [
4949 createSimpleExpression(`_cached`)
4950 ])
4951 );
4952 loop.body = createBlockStatement([
4953 createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
4954 createCompoundExpression([
4955 `if (_cached`,
4956 ...keyExp ? [` && _cached.key === `, keyExp] : [],
4957 ` && ${context.helperString(
4958 IS_MEMO_SAME
4959 )}(_cached, _memo)) return _cached`
4960 ]),
4961 createCompoundExpression([`const _item = `, childBlock]),
4962 createSimpleExpression(`_item.memo = _memo`),
4963 createSimpleExpression(`return _item`)
4964 ]);
4965 renderExp.arguments.push(
4966 loop,
4967 createSimpleExpression(`_cache`),
4968 createSimpleExpression(String(context.cached.length))
4969 );
4970 context.cached.push(null);
4971 } else {
4972 renderExp.arguments.push(
4973 createFunctionExpression(
4974 createForLoopParams(forNode.parseResult),
4975 childBlock,
4976 true
4977 )
4978 );
4979 }
4980 };
4981 });
4982 }
4983);
4984function processFor(node, dir, context, processCodegen) {
4985 if (!dir.exp) {
4986 context.onError(
4987 createCompilerError(31, dir.loc)
4988 );
4989 return;
4990 }
4991 const parseResult = dir.forParseResult;
4992 if (!parseResult) {
4993 context.onError(
4994 createCompilerError(32, dir.loc)
4995 );
4996 return;
4997 }
4998 finalizeForParseResult(parseResult, context);
4999 const { addIdentifiers, removeIdentifiers, scopes } = context;
5000 const { source, value, key, index } = parseResult;
5001 const forNode = {
5002 type: 11,
5003 loc: dir.loc,
5004 source,
5005 valueAlias: value,
5006 keyAlias: key,
5007 objectIndexAlias: index,
5008 parseResult,
5009 children: isTemplateNode(node) ? node.children : [node]
5010 };
5011 context.replaceNode(forNode);
5012 scopes.vFor++;
5013 if (context.prefixIdentifiers) {
5014 value && addIdentifiers(value);
5015 key && addIdentifiers(key);
5016 index && addIdentifiers(index);
5017 }
5018 const onExit = processCodegen && processCodegen(forNode);
5019 return () => {
5020 scopes.vFor--;
5021 if (context.prefixIdentifiers) {
5022 value && removeIdentifiers(value);
5023 key && removeIdentifiers(key);
5024 index && removeIdentifiers(index);
5025 }
5026 if (onExit) onExit();
5027 };
5028}
5029function finalizeForParseResult(result, context) {
5030 if (result.finalized) return;
5031 if (context.prefixIdentifiers) {
5032 result.source = processExpression(
5033 result.source,
5034 context
5035 );
5036 if (result.key) {
5037 result.key = processExpression(
5038 result.key,
5039 context,
5040 true
5041 );
5042 }
5043 if (result.index) {
5044 result.index = processExpression(
5045 result.index,
5046 context,
5047 true
5048 );
5049 }
5050 if (result.value) {
5051 result.value = processExpression(
5052 result.value,
5053 context,
5054 true
5055 );
5056 }
5057 }
5058 result.finalized = true;
5059}
5060function createForLoopParams({ value, key, index }, memoArgs = []) {
5061 return createParamsList([value, key, index, ...memoArgs]);
5062}
5063function createParamsList(args) {
5064 let i = args.length;
5065 while (i--) {
5066 if (args[i]) break;
5067 }
5068 return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
5069}
5070
5071const defaultFallback = createSimpleExpression(`undefined`, false);
5072const trackSlotScopes = (node, context) => {
5073 if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
5074 const vSlot = findDir(node, "slot");
5075 if (vSlot) {
5076 const slotProps = vSlot.exp;
5077 if (context.prefixIdentifiers) {
5078 slotProps && context.addIdentifiers(slotProps);
5079 }
5080 context.scopes.vSlot++;
5081 return () => {
5082 if (context.prefixIdentifiers) {
5083 slotProps && context.removeIdentifiers(slotProps);
5084 }
5085 context.scopes.vSlot--;
5086 };
5087 }
5088 }
5089};
5090const trackVForSlotScopes = (node, context) => {
5091 let vFor;
5092 if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
5093 const result = vFor.forParseResult;
5094 if (result) {
5095 finalizeForParseResult(result, context);
5096 const { value, key, index } = result;
5097 const { addIdentifiers, removeIdentifiers } = context;
5098 value && addIdentifiers(value);
5099 key && addIdentifiers(key);
5100 index && addIdentifiers(index);
5101 return () => {
5102 value && removeIdentifiers(value);
5103 key && removeIdentifiers(key);
5104 index && removeIdentifiers(index);
5105 };
5106 }
5107 }
5108};
5109const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
5110 props,
5111 children,
5112 false,
5113 true,
5114 children.length ? children[0].loc : loc
5115);
5116function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
5117 context.helper(WITH_CTX);
5118 const { children, loc } = node;
5119 const slotsProperties = [];
5120 const dynamicSlots = [];
5121 let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
5122 if (!context.ssr && context.prefixIdentifiers) {
5123 hasDynamicSlots = hasScopeRef(node, context.identifiers);
5124 }
5125 const onComponentSlot = findDir(node, "slot", true);
5126 if (onComponentSlot) {
5127 const { arg, exp } = onComponentSlot;
5128 if (arg && !isStaticExp(arg)) {
5129 hasDynamicSlots = true;
5130 }
5131 slotsProperties.push(
5132 createObjectProperty(
5133 arg || createSimpleExpression("default", true),
5134 buildSlotFn(exp, void 0, children, loc)
5135 )
5136 );
5137 }
5138 let hasTemplateSlots = false;
5139 let hasNamedDefaultSlot = false;
5140 const implicitDefaultChildren = [];
5141 const seenSlotNames = /* @__PURE__ */ new Set();
5142 let conditionalBranchIndex = 0;
5143 for (let i = 0; i < children.length; i++) {
5144 const slotElement = children[i];
5145 let slotDir;
5146 if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
5147 if (slotElement.type !== 3) {
5148 implicitDefaultChildren.push(slotElement);
5149 }
5150 continue;
5151 }
5152 if (onComponentSlot) {
5153 context.onError(
5154 createCompilerError(37, slotDir.loc)
5155 );
5156 break;
5157 }
5158 hasTemplateSlots = true;
5159 const { children: slotChildren, loc: slotLoc } = slotElement;
5160 const {
5161 arg: slotName = createSimpleExpression(`default`, true),
5162 exp: slotProps,
5163 loc: dirLoc
5164 } = slotDir;
5165 let staticSlotName;
5166 if (isStaticExp(slotName)) {
5167 staticSlotName = slotName ? slotName.content : `default`;
5168 } else {
5169 hasDynamicSlots = true;
5170 }
5171 const vFor = findDir(slotElement, "for");
5172 const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
5173 let vIf;
5174 let vElse;
5175 if (vIf = findDir(slotElement, "if")) {
5176 hasDynamicSlots = true;
5177 dynamicSlots.push(
5178 createConditionalExpression(
5179 vIf.exp,
5180 buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
5181 defaultFallback
5182 )
5183 );
5184 } else if (vElse = findDir(
5185 slotElement,
5186 /^else(-if)?$/,
5187 true
5188 /* allowEmpty */
5189 )) {
5190 let j = i;
5191 let prev;
5192 while (j--) {
5193 prev = children[j];
5194 if (prev.type !== 3) {
5195 break;
5196 }
5197 }
5198 if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
5199 let conditional = dynamicSlots[dynamicSlots.length - 1];
5200 while (conditional.alternate.type === 19) {
5201 conditional = conditional.alternate;
5202 }
5203 conditional.alternate = vElse.exp ? createConditionalExpression(
5204 vElse.exp,
5205 buildDynamicSlot(
5206 slotName,
5207 slotFunction,
5208 conditionalBranchIndex++
5209 ),
5210 defaultFallback
5211 ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
5212 } else {
5213 context.onError(
5214 createCompilerError(30, vElse.loc)
5215 );
5216 }
5217 } else if (vFor) {
5218 hasDynamicSlots = true;
5219 const parseResult = vFor.forParseResult;
5220 if (parseResult) {
5221 finalizeForParseResult(parseResult, context);
5222 dynamicSlots.push(
5223 createCallExpression(context.helper(RENDER_LIST), [
5224 parseResult.source,
5225 createFunctionExpression(
5226 createForLoopParams(parseResult),
5227 buildDynamicSlot(slotName, slotFunction),
5228 true
5229 )
5230 ])
5231 );
5232 } else {
5233 context.onError(
5234 createCompilerError(
5235 32,
5236 vFor.loc
5237 )
5238 );
5239 }
5240 } else {
5241 if (staticSlotName) {
5242 if (seenSlotNames.has(staticSlotName)) {
5243 context.onError(
5244 createCompilerError(
5245 38,
5246 dirLoc
5247 )
5248 );
5249 continue;
5250 }
5251 seenSlotNames.add(staticSlotName);
5252 if (staticSlotName === "default") {
5253 hasNamedDefaultSlot = true;
5254 }
5255 }
5256 slotsProperties.push(createObjectProperty(slotName, slotFunction));
5257 }
5258 }
5259 if (!onComponentSlot) {
5260 const buildDefaultSlotProperty = (props, children2) => {
5261 const fn = buildSlotFn(props, void 0, children2, loc);
5262 if (context.compatConfig) {
5263 fn.isNonScopedSlot = true;
5264 }
5265 return createObjectProperty(`default`, fn);
5266 };
5267 if (!hasTemplateSlots) {
5268 slotsProperties.push(buildDefaultSlotProperty(void 0, children));
5269 } else if (implicitDefaultChildren.length && // #3766
5270 // with whitespace: 'preserve', whitespaces between slots will end up in
5271 // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
5272 implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
5273 if (hasNamedDefaultSlot) {
5274 context.onError(
5275 createCompilerError(
5276 39,
5277 implicitDefaultChildren[0].loc
5278 )
5279 );
5280 } else {
5281 slotsProperties.push(
5282 buildDefaultSlotProperty(void 0, implicitDefaultChildren)
5283 );
5284 }
5285 }
5286 }
5287 const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
5288 let slots = createObjectExpression(
5289 slotsProperties.concat(
5290 createObjectProperty(
5291 `_`,
5292 // 2 = compiled but dynamic = can skip normalization, but must run diff
5293 // 1 = compiled and static = can skip normalization AND diff as optimized
5294 createSimpleExpression(
5295 slotFlag + (``),
5296 false
5297 )
5298 )
5299 ),
5300 loc
5301 );
5302 if (dynamicSlots.length) {
5303 slots = createCallExpression(context.helper(CREATE_SLOTS), [
5304 slots,
5305 createArrayExpression(dynamicSlots)
5306 ]);
5307 }
5308 return {
5309 slots,
5310 hasDynamicSlots
5311 };
5312}
5313function buildDynamicSlot(name, fn, index) {
5314 const props = [
5315 createObjectProperty(`name`, name),
5316 createObjectProperty(`fn`, fn)
5317 ];
5318 if (index != null) {
5319 props.push(
5320 createObjectProperty(`key`, createSimpleExpression(String(index), true))
5321 );
5322 }
5323 return createObjectExpression(props);
5324}
5325function hasForwardedSlots(children) {
5326 for (let i = 0; i < children.length; i++) {
5327 const child = children[i];
5328 switch (child.type) {
5329 case 1:
5330 if (child.tagType === 2 || hasForwardedSlots(child.children)) {
5331 return true;
5332 }
5333 break;
5334 case 9:
5335 if (hasForwardedSlots(child.branches)) return true;
5336 break;
5337 case 10:
5338 case 11:
5339 if (hasForwardedSlots(child.children)) return true;
5340 break;
5341 }
5342 }
5343 return false;
5344}
5345function isNonWhitespaceContent(node) {
5346 if (node.type !== 2 && node.type !== 12)
5347 return true;
5348 return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
5349}
5350
5351const directiveImportMap = /* @__PURE__ */ new WeakMap();
5352const transformElement = (node, context) => {
5353 return function postTransformElement() {
5354 node = context.currentNode;
5355 if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
5356 return;
5357 }
5358 const { tag, props } = node;
5359 const isComponent = node.tagType === 1;
5360 let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
5361 const isDynamicComponent = shared.isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
5362 let vnodeProps;
5363 let vnodeChildren;
5364 let patchFlag = 0;
5365 let vnodeDynamicProps;
5366 let dynamicPropNames;
5367 let vnodeDirectives;
5368 let shouldUseBlock = (
5369 // dynamic component may resolve to plain elements
5370 isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
5371 // updates inside get proper isSVG flag at runtime. (#639, #643)
5372 // This is technically web-specific, but splitting the logic out of core
5373 // leads to too much unnecessary complexity.
5374 (tag === "svg" || tag === "foreignObject" || tag === "math")
5375 );
5376 if (props.length > 0) {
5377 const propsBuildResult = buildProps(
5378 node,
5379 context,
5380 void 0,
5381 isComponent,
5382 isDynamicComponent
5383 );
5384 vnodeProps = propsBuildResult.props;
5385 patchFlag = propsBuildResult.patchFlag;
5386 dynamicPropNames = propsBuildResult.dynamicPropNames;
5387 const directives = propsBuildResult.directives;
5388 vnodeDirectives = directives && directives.length ? createArrayExpression(
5389 directives.map((dir) => buildDirectiveArgs(dir, context))
5390 ) : void 0;
5391 if (propsBuildResult.shouldUseBlock) {
5392 shouldUseBlock = true;
5393 }
5394 }
5395 if (node.children.length > 0) {
5396 if (vnodeTag === KEEP_ALIVE) {
5397 shouldUseBlock = true;
5398 patchFlag |= 1024;
5399 }
5400 const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
5401 vnodeTag !== TELEPORT && // explained above.
5402 vnodeTag !== KEEP_ALIVE;
5403 if (shouldBuildAsSlots) {
5404 const { slots, hasDynamicSlots } = buildSlots(node, context);
5405 vnodeChildren = slots;
5406 if (hasDynamicSlots) {
5407 patchFlag |= 1024;
5408 }
5409 } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
5410 const child = node.children[0];
5411 const type = child.type;
5412 const hasDynamicTextChild = type === 5 || type === 8;
5413 if (hasDynamicTextChild && getConstantType(child, context) === 0) {
5414 patchFlag |= 1;
5415 }
5416 if (hasDynamicTextChild || type === 2) {
5417 vnodeChildren = child;
5418 } else {
5419 vnodeChildren = node.children;
5420 }
5421 } else {
5422 vnodeChildren = node.children;
5423 }
5424 }
5425 if (dynamicPropNames && dynamicPropNames.length) {
5426 vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
5427 }
5428 node.codegenNode = createVNodeCall(
5429 context,
5430 vnodeTag,
5431 vnodeProps,
5432 vnodeChildren,
5433 patchFlag === 0 ? void 0 : patchFlag,
5434 vnodeDynamicProps,
5435 vnodeDirectives,
5436 !!shouldUseBlock,
5437 false,
5438 isComponent,
5439 node.loc
5440 );
5441 };
5442};
5443function resolveComponentType(node, context, ssr = false) {
5444 let { tag } = node;
5445 const isExplicitDynamic = isComponentTag(tag);
5446 const isProp = findProp(
5447 node,
5448 "is",
5449 false,
5450 true
5451 /* allow empty */
5452 );
5453 if (isProp) {
5454 if (isExplicitDynamic || isCompatEnabled(
5455 "COMPILER_IS_ON_ELEMENT",
5456 context
5457 )) {
5458 let exp;
5459 if (isProp.type === 6) {
5460 exp = isProp.value && createSimpleExpression(isProp.value.content, true);
5461 } else {
5462 exp = isProp.exp;
5463 if (!exp) {
5464 exp = createSimpleExpression(`is`, false, isProp.arg.loc);
5465 {
5466 exp = isProp.exp = processExpression(exp, context);
5467 }
5468 }
5469 }
5470 if (exp) {
5471 return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
5472 exp
5473 ]);
5474 }
5475 } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
5476 tag = isProp.value.content.slice(4);
5477 }
5478 }
5479 const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
5480 if (builtIn) {
5481 if (!ssr) context.helper(builtIn);
5482 return builtIn;
5483 }
5484 {
5485 const fromSetup = resolveSetupReference(tag, context);
5486 if (fromSetup) {
5487 return fromSetup;
5488 }
5489 const dotIndex = tag.indexOf(".");
5490 if (dotIndex > 0) {
5491 const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
5492 if (ns) {
5493 return ns + tag.slice(dotIndex);
5494 }
5495 }
5496 }
5497 if (context.selfName && shared.capitalize(shared.camelize(tag)) === context.selfName) {
5498 context.helper(RESOLVE_COMPONENT);
5499 context.components.add(tag + `__self`);
5500 return toValidAssetId(tag, `component`);
5501 }
5502 context.helper(RESOLVE_COMPONENT);
5503 context.components.add(tag);
5504 return toValidAssetId(tag, `component`);
5505}
5506function resolveSetupReference(name, context) {
5507 const bindings = context.bindingMetadata;
5508 if (!bindings || bindings.__isScriptSetup === false) {
5509 return;
5510 }
5511 const camelName = shared.camelize(name);
5512 const PascalName = shared.capitalize(camelName);
5513 const checkType = (type) => {
5514 if (bindings[name] === type) {
5515 return name;
5516 }
5517 if (bindings[camelName] === type) {
5518 return camelName;
5519 }
5520 if (bindings[PascalName] === type) {
5521 return PascalName;
5522 }
5523 };
5524 const fromConst = checkType("setup-const") || checkType("setup-reactive-const") || checkType("literal-const");
5525 if (fromConst) {
5526 return context.inline ? (
5527 // in inline mode, const setup bindings (e.g. imports) can be used as-is
5528 fromConst
5529 ) : `$setup[${JSON.stringify(fromConst)}]`;
5530 }
5531 const fromMaybeRef = checkType("setup-let") || checkType("setup-ref") || checkType("setup-maybe-ref");
5532 if (fromMaybeRef) {
5533 return context.inline ? (
5534 // setup scope bindings that may be refs need to be unrefed
5535 `${context.helperString(UNREF)}(${fromMaybeRef})`
5536 ) : `$setup[${JSON.stringify(fromMaybeRef)}]`;
5537 }
5538 const fromProps = checkType("props");
5539 if (fromProps) {
5540 return `${context.helperString(UNREF)}(${context.inline ? "__props" : "$props"}[${JSON.stringify(fromProps)}])`;
5541 }
5542}
5543function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
5544 const { tag, loc: elementLoc, children } = node;
5545 let properties = [];
5546 const mergeArgs = [];
5547 const runtimeDirectives = [];
5548 const hasChildren = children.length > 0;
5549 let shouldUseBlock = false;
5550 let patchFlag = 0;
5551 let hasRef = false;
5552 let hasClassBinding = false;
5553 let hasStyleBinding = false;
5554 let hasHydrationEventBinding = false;
5555 let hasDynamicKeys = false;
5556 let hasVnodeHook = false;
5557 const dynamicPropNames = [];
5558 const pushMergeArg = (arg) => {
5559 if (properties.length) {
5560 mergeArgs.push(
5561 createObjectExpression(dedupeProperties(properties), elementLoc)
5562 );
5563 properties = [];
5564 }
5565 if (arg) mergeArgs.push(arg);
5566 };
5567 const pushRefVForMarker = () => {
5568 if (context.scopes.vFor > 0) {
5569 properties.push(
5570 createObjectProperty(
5571 createSimpleExpression("ref_for", true),
5572 createSimpleExpression("true")
5573 )
5574 );
5575 }
5576 };
5577 const analyzePatchFlag = ({ key, value }) => {
5578 if (isStaticExp(key)) {
5579 const name = key.content;
5580 const isEventHandler = shared.isOn(name);
5581 if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
5582 // dedicated fast path.
5583 name.toLowerCase() !== "onclick" && // omit v-model handlers
5584 name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
5585 !shared.isReservedProp(name)) {
5586 hasHydrationEventBinding = true;
5587 }
5588 if (isEventHandler && shared.isReservedProp(name)) {
5589 hasVnodeHook = true;
5590 }
5591 if (isEventHandler && value.type === 14) {
5592 value = value.arguments[0];
5593 }
5594 if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
5595 return;
5596 }
5597 if (name === "ref") {
5598 hasRef = true;
5599 } else if (name === "class") {
5600 hasClassBinding = true;
5601 } else if (name === "style") {
5602 hasStyleBinding = true;
5603 } else if (name !== "key" && !dynamicPropNames.includes(name)) {
5604 dynamicPropNames.push(name);
5605 }
5606 if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
5607 dynamicPropNames.push(name);
5608 }
5609 } else {
5610 hasDynamicKeys = true;
5611 }
5612 };
5613 for (let i = 0; i < props.length; i++) {
5614 const prop = props[i];
5615 if (prop.type === 6) {
5616 const { loc, name, nameLoc, value } = prop;
5617 let isStatic = true;
5618 if (name === "ref") {
5619 hasRef = true;
5620 pushRefVForMarker();
5621 if (value && context.inline) {
5622 const binding = context.bindingMetadata[value.content];
5623 if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
5624 isStatic = false;
5625 properties.push(
5626 createObjectProperty(
5627 createSimpleExpression("ref_key", true),
5628 createSimpleExpression(value.content, true, value.loc)
5629 )
5630 );
5631 }
5632 }
5633 }
5634 if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
5635 "COMPILER_IS_ON_ELEMENT",
5636 context
5637 ))) {
5638 continue;
5639 }
5640 properties.push(
5641 createObjectProperty(
5642 createSimpleExpression(name, true, nameLoc),
5643 createSimpleExpression(
5644 value ? value.content : "",
5645 isStatic,
5646 value ? value.loc : loc
5647 )
5648 )
5649 );
5650 } else {
5651 const { name, arg, exp, loc, modifiers } = prop;
5652 const isVBind = name === "bind";
5653 const isVOn = name === "on";
5654 if (name === "slot") {
5655 if (!isComponent) {
5656 context.onError(
5657 createCompilerError(40, loc)
5658 );
5659 }
5660 continue;
5661 }
5662 if (name === "once" || name === "memo") {
5663 continue;
5664 }
5665 if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
5666 "COMPILER_IS_ON_ELEMENT",
5667 context
5668 ))) {
5669 continue;
5670 }
5671 if (isVOn && ssr) {
5672 continue;
5673 }
5674 if (
5675 // #938: elements with dynamic keys should be forced into blocks
5676 isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
5677 // before children
5678 isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
5679 ) {
5680 shouldUseBlock = true;
5681 }
5682 if (isVBind && isStaticArgOf(arg, "ref")) {
5683 pushRefVForMarker();
5684 }
5685 if (!arg && (isVBind || isVOn)) {
5686 hasDynamicKeys = true;
5687 if (exp) {
5688 if (isVBind) {
5689 pushRefVForMarker();
5690 pushMergeArg();
5691 {
5692 if (isCompatEnabled(
5693 "COMPILER_V_BIND_OBJECT_ORDER",
5694 context
5695 )) {
5696 mergeArgs.unshift(exp);
5697 continue;
5698 }
5699 }
5700 mergeArgs.push(exp);
5701 } else {
5702 pushMergeArg({
5703 type: 14,
5704 loc,
5705 callee: context.helper(TO_HANDLERS),
5706 arguments: isComponent ? [exp] : [exp, `true`]
5707 });
5708 }
5709 } else {
5710 context.onError(
5711 createCompilerError(
5712 isVBind ? 34 : 35,
5713 loc
5714 )
5715 );
5716 }
5717 continue;
5718 }
5719 if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
5720 patchFlag |= 32;
5721 }
5722 const directiveTransform = context.directiveTransforms[name];
5723 if (directiveTransform) {
5724 const { props: props2, needRuntime } = directiveTransform(prop, node, context);
5725 !ssr && props2.forEach(analyzePatchFlag);
5726 if (isVOn && arg && !isStaticExp(arg)) {
5727 pushMergeArg(createObjectExpression(props2, elementLoc));
5728 } else {
5729 properties.push(...props2);
5730 }
5731 if (needRuntime) {
5732 runtimeDirectives.push(prop);
5733 if (shared.isSymbol(needRuntime)) {
5734 directiveImportMap.set(prop, needRuntime);
5735 }
5736 }
5737 } else if (!shared.isBuiltInDirective(name)) {
5738 runtimeDirectives.push(prop);
5739 if (hasChildren) {
5740 shouldUseBlock = true;
5741 }
5742 }
5743 }
5744 }
5745 let propsExpression = void 0;
5746 if (mergeArgs.length) {
5747 pushMergeArg();
5748 if (mergeArgs.length > 1) {
5749 propsExpression = createCallExpression(
5750 context.helper(MERGE_PROPS),
5751 mergeArgs,
5752 elementLoc
5753 );
5754 } else {
5755 propsExpression = mergeArgs[0];
5756 }
5757 } else if (properties.length) {
5758 propsExpression = createObjectExpression(
5759 dedupeProperties(properties),
5760 elementLoc
5761 );
5762 }
5763 if (hasDynamicKeys) {
5764 patchFlag |= 16;
5765 } else {
5766 if (hasClassBinding && !isComponent) {
5767 patchFlag |= 2;
5768 }
5769 if (hasStyleBinding && !isComponent) {
5770 patchFlag |= 4;
5771 }
5772 if (dynamicPropNames.length) {
5773 patchFlag |= 8;
5774 }
5775 if (hasHydrationEventBinding) {
5776 patchFlag |= 32;
5777 }
5778 }
5779 if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
5780 patchFlag |= 512;
5781 }
5782 if (!context.inSSR && propsExpression) {
5783 switch (propsExpression.type) {
5784 case 15:
5785 let classKeyIndex = -1;
5786 let styleKeyIndex = -1;
5787 let hasDynamicKey = false;
5788 for (let i = 0; i < propsExpression.properties.length; i++) {
5789 const key = propsExpression.properties[i].key;
5790 if (isStaticExp(key)) {
5791 if (key.content === "class") {
5792 classKeyIndex = i;
5793 } else if (key.content === "style") {
5794 styleKeyIndex = i;
5795 }
5796 } else if (!key.isHandlerKey) {
5797 hasDynamicKey = true;
5798 }
5799 }
5800 const classProp = propsExpression.properties[classKeyIndex];
5801 const styleProp = propsExpression.properties[styleKeyIndex];
5802 if (!hasDynamicKey) {
5803 if (classProp && !isStaticExp(classProp.value)) {
5804 classProp.value = createCallExpression(
5805 context.helper(NORMALIZE_CLASS),
5806 [classProp.value]
5807 );
5808 }
5809 if (styleProp && // the static style is compiled into an object,
5810 // so use `hasStyleBinding` to ensure that it is a dynamic style binding
5811 (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
5812 // v-bind:style with static literal object
5813 styleProp.value.type === 17)) {
5814 styleProp.value = createCallExpression(
5815 context.helper(NORMALIZE_STYLE),
5816 [styleProp.value]
5817 );
5818 }
5819 } else {
5820 propsExpression = createCallExpression(
5821 context.helper(NORMALIZE_PROPS),
5822 [propsExpression]
5823 );
5824 }
5825 break;
5826 case 14:
5827 break;
5828 default:
5829 propsExpression = createCallExpression(
5830 context.helper(NORMALIZE_PROPS),
5831 [
5832 createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
5833 propsExpression
5834 ])
5835 ]
5836 );
5837 break;
5838 }
5839 }
5840 return {
5841 props: propsExpression,
5842 directives: runtimeDirectives,
5843 patchFlag,
5844 dynamicPropNames,
5845 shouldUseBlock
5846 };
5847}
5848function dedupeProperties(properties) {
5849 const knownProps = /* @__PURE__ */ new Map();
5850 const deduped = [];
5851 for (let i = 0; i < properties.length; i++) {
5852 const prop = properties[i];
5853 if (prop.key.type === 8 || !prop.key.isStatic) {
5854 deduped.push(prop);
5855 continue;
5856 }
5857 const name = prop.key.content;
5858 const existing = knownProps.get(name);
5859 if (existing) {
5860 if (name === "style" || name === "class" || shared.isOn(name)) {
5861 mergeAsArray(existing, prop);
5862 }
5863 } else {
5864 knownProps.set(name, prop);
5865 deduped.push(prop);
5866 }
5867 }
5868 return deduped;
5869}
5870function mergeAsArray(existing, incoming) {
5871 if (existing.value.type === 17) {
5872 existing.value.elements.push(incoming.value);
5873 } else {
5874 existing.value = createArrayExpression(
5875 [existing.value, incoming.value],
5876 existing.loc
5877 );
5878 }
5879}
5880function buildDirectiveArgs(dir, context) {
5881 const dirArgs = [];
5882 const runtime = directiveImportMap.get(dir);
5883 if (runtime) {
5884 dirArgs.push(context.helperString(runtime));
5885 } else {
5886 const fromSetup = resolveSetupReference("v-" + dir.name, context);
5887 if (fromSetup) {
5888 dirArgs.push(fromSetup);
5889 } else {
5890 context.helper(RESOLVE_DIRECTIVE);
5891 context.directives.add(dir.name);
5892 dirArgs.push(toValidAssetId(dir.name, `directive`));
5893 }
5894 }
5895 const { loc } = dir;
5896 if (dir.exp) dirArgs.push(dir.exp);
5897 if (dir.arg) {
5898 if (!dir.exp) {
5899 dirArgs.push(`void 0`);
5900 }
5901 dirArgs.push(dir.arg);
5902 }
5903 if (Object.keys(dir.modifiers).length) {
5904 if (!dir.arg) {
5905 if (!dir.exp) {
5906 dirArgs.push(`void 0`);
5907 }
5908 dirArgs.push(`void 0`);
5909 }
5910 const trueExpression = createSimpleExpression(`true`, false, loc);
5911 dirArgs.push(
5912 createObjectExpression(
5913 dir.modifiers.map(
5914 (modifier) => createObjectProperty(modifier, trueExpression)
5915 ),
5916 loc
5917 )
5918 );
5919 }
5920 return createArrayExpression(dirArgs, dir.loc);
5921}
5922function stringifyDynamicPropNames(props) {
5923 let propsNamesString = `[`;
5924 for (let i = 0, l = props.length; i < l; i++) {
5925 propsNamesString += JSON.stringify(props[i]);
5926 if (i < l - 1) propsNamesString += ", ";
5927 }
5928 return propsNamesString + `]`;
5929}
5930function isComponentTag(tag) {
5931 return tag === "component" || tag === "Component";
5932}
5933
5934const transformSlotOutlet = (node, context) => {
5935 if (isSlotOutlet(node)) {
5936 const { children, loc } = node;
5937 const { slotName, slotProps } = processSlotOutlet(node, context);
5938 const slotArgs = [
5939 context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
5940 slotName,
5941 "{}",
5942 "undefined",
5943 "true"
5944 ];
5945 let expectedLen = 2;
5946 if (slotProps) {
5947 slotArgs[2] = slotProps;
5948 expectedLen = 3;
5949 }
5950 if (children.length) {
5951 slotArgs[3] = createFunctionExpression([], children, false, false, loc);
5952 expectedLen = 4;
5953 }
5954 if (context.scopeId && !context.slotted) {
5955 expectedLen = 5;
5956 }
5957 slotArgs.splice(expectedLen);
5958 node.codegenNode = createCallExpression(
5959 context.helper(RENDER_SLOT),
5960 slotArgs,
5961 loc
5962 );
5963 }
5964};
5965function processSlotOutlet(node, context) {
5966 let slotName = `"default"`;
5967 let slotProps = void 0;
5968 const nonNameProps = [];
5969 for (let i = 0; i < node.props.length; i++) {
5970 const p = node.props[i];
5971 if (p.type === 6) {
5972 if (p.value) {
5973 if (p.name === "name") {
5974 slotName = JSON.stringify(p.value.content);
5975 } else {
5976 p.name = shared.camelize(p.name);
5977 nonNameProps.push(p);
5978 }
5979 }
5980 } else {
5981 if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
5982 if (p.exp) {
5983 slotName = p.exp;
5984 } else if (p.arg && p.arg.type === 4) {
5985 const name = shared.camelize(p.arg.content);
5986 slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
5987 {
5988 slotName = p.exp = processExpression(p.exp, context);
5989 }
5990 }
5991 } else {
5992 if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
5993 p.arg.content = shared.camelize(p.arg.content);
5994 }
5995 nonNameProps.push(p);
5996 }
5997 }
5998 }
5999 if (nonNameProps.length > 0) {
6000 const { props, directives } = buildProps(
6001 node,
6002 context,
6003 nonNameProps,
6004 false,
6005 false
6006 );
6007 slotProps = props;
6008 if (directives.length) {
6009 context.onError(
6010 createCompilerError(
6011 36,
6012 directives[0].loc
6013 )
6014 );
6015 }
6016 }
6017 return {
6018 slotName,
6019 slotProps
6020 };
6021}
6022
6023const transformOn = (dir, node, context, augmentor) => {
6024 const { loc, modifiers, arg } = dir;
6025 if (!dir.exp && !modifiers.length) {
6026 context.onError(createCompilerError(35, loc));
6027 }
6028 let eventName;
6029 if (arg.type === 4) {
6030 if (arg.isStatic) {
6031 let rawName = arg.content;
6032 if (rawName.startsWith("vue:")) {
6033 rawName = `vnode-${rawName.slice(4)}`;
6034 }
6035 const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
6036 // for non-element and vnode lifecycle event listeners, auto convert
6037 // it to camelCase. See issue #2249
6038 shared.toHandlerKey(shared.camelize(rawName))
6039 ) : (
6040 // preserve case for plain element listeners that have uppercase
6041 // letters, as these may be custom elements' custom events
6042 `on:${rawName}`
6043 );
6044 eventName = createSimpleExpression(eventString, true, arg.loc);
6045 } else {
6046 eventName = createCompoundExpression([
6047 `${context.helperString(TO_HANDLER_KEY)}(`,
6048 arg,
6049 `)`
6050 ]);
6051 }
6052 } else {
6053 eventName = arg;
6054 eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
6055 eventName.children.push(`)`);
6056 }
6057 let exp = dir.exp;
6058 if (exp && !exp.content.trim()) {
6059 exp = void 0;
6060 }
6061 let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
6062 if (exp) {
6063 const isMemberExp = isMemberExpression(exp, context);
6064 const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
6065 const hasMultipleStatements = exp.content.includes(`;`);
6066 if (context.prefixIdentifiers) {
6067 isInlineStatement && context.addIdentifiers(`$event`);
6068 exp = dir.exp = processExpression(
6069 exp,
6070 context,
6071 false,
6072 hasMultipleStatements
6073 );
6074 isInlineStatement && context.removeIdentifiers(`$event`);
6075 shouldCache = context.cacheHandlers && // unnecessary to cache inside v-once
6076 !context.inVOnce && // runtime constants don't need to be cached
6077 // (this is analyzed by compileScript in SFC <script setup>)
6078 !(exp.type === 4 && exp.constType > 0) && // #1541 bail if this is a member exp handler passed to a component -
6079 // we need to use the original function to preserve arity,
6080 // e.g. <transition> relies on checking cb.length to determine
6081 // transition end handling. Inline function is ok since its arity
6082 // is preserved even when cached.
6083 !(isMemberExp && node.tagType === 1) && // bail if the function references closure variables (v-for, v-slot)
6084 // it must be passed fresh to avoid stale values.
6085 !hasScopeRef(exp, context.identifiers);
6086 if (shouldCache && isMemberExp) {
6087 if (exp.type === 4) {
6088 exp.content = `${exp.content} && ${exp.content}(...args)`;
6089 } else {
6090 exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
6091 }
6092 }
6093 }
6094 if (isInlineStatement || shouldCache && isMemberExp) {
6095 exp = createCompoundExpression([
6096 `${isInlineStatement ? context.isTS ? `($event: any)` : `$event` : `${context.isTS ? `
6097//@ts-ignore
6098` : ``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
6099 exp,
6100 hasMultipleStatements ? `}` : `)`
6101 ]);
6102 }
6103 }
6104 let ret = {
6105 props: [
6106 createObjectProperty(
6107 eventName,
6108 exp || createSimpleExpression(`() => {}`, false, loc)
6109 )
6110 ]
6111 };
6112 if (augmentor) {
6113 ret = augmentor(ret);
6114 }
6115 if (shouldCache) {
6116 ret.props[0].value = context.cache(ret.props[0].value);
6117 }
6118 ret.props.forEach((p) => p.key.isHandlerKey = true);
6119 return ret;
6120};
6121
6122const transformText = (node, context) => {
6123 if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
6124 return () => {
6125 const children = node.children;
6126 let currentContainer = void 0;
6127 let hasText = false;
6128 for (let i = 0; i < children.length; i++) {
6129 const child = children[i];
6130 if (isText$1(child)) {
6131 hasText = true;
6132 for (let j = i + 1; j < children.length; j++) {
6133 const next = children[j];
6134 if (isText$1(next)) {
6135 if (!currentContainer) {
6136 currentContainer = children[i] = createCompoundExpression(
6137 [child],
6138 child.loc
6139 );
6140 }
6141 currentContainer.children.push(` + `, next);
6142 children.splice(j, 1);
6143 j--;
6144 } else {
6145 currentContainer = void 0;
6146 break;
6147 }
6148 }
6149 }
6150 }
6151 if (!hasText || // if this is a plain element with a single text child, leave it
6152 // as-is since the runtime has dedicated fast path for this by directly
6153 // setting textContent of the element.
6154 // for component root it's always normalized anyway.
6155 children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
6156 // custom directives can potentially add DOM elements arbitrarily,
6157 // we need to avoid setting textContent of the element at runtime
6158 // to avoid accidentally overwriting the DOM elements added
6159 // by the user through custom directives.
6160 !node.props.find(
6161 (p) => p.type === 7 && !context.directiveTransforms[p.name]
6162 ) && // in compat mode, <template> tags with no special directives
6163 // will be rendered as a fragment so its children must be
6164 // converted into vnodes.
6165 !(node.tag === "template"))) {
6166 return;
6167 }
6168 for (let i = 0; i < children.length; i++) {
6169 const child = children[i];
6170 if (isText$1(child) || child.type === 8) {
6171 const callArgs = [];
6172 if (child.type !== 2 || child.content !== " ") {
6173 callArgs.push(child);
6174 }
6175 if (!context.ssr && getConstantType(child, context) === 0) {
6176 callArgs.push(
6177 1 + (``)
6178 );
6179 }
6180 children[i] = {
6181 type: 12,
6182 content: child,
6183 loc: child.loc,
6184 codegenNode: createCallExpression(
6185 context.helper(CREATE_TEXT),
6186 callArgs
6187 )
6188 };
6189 }
6190 }
6191 };
6192 }
6193};
6194
6195const seen$1 = /* @__PURE__ */ new WeakSet();
6196const transformOnce = (node, context) => {
6197 if (node.type === 1 && findDir(node, "once", true)) {
6198 if (seen$1.has(node) || context.inVOnce || context.inSSR) {
6199 return;
6200 }
6201 seen$1.add(node);
6202 context.inVOnce = true;
6203 context.helper(SET_BLOCK_TRACKING);
6204 return () => {
6205 context.inVOnce = false;
6206 const cur = context.currentNode;
6207 if (cur.codegenNode) {
6208 cur.codegenNode = context.cache(
6209 cur.codegenNode,
6210 true,
6211 true
6212 );
6213 }
6214 };
6215 }
6216};
6217
6218const transformModel = (dir, node, context) => {
6219 const { exp, arg } = dir;
6220 if (!exp) {
6221 context.onError(
6222 createCompilerError(41, dir.loc)
6223 );
6224 return createTransformProps();
6225 }
6226 const rawExp = exp.loc.source.trim();
6227 const expString = exp.type === 4 ? exp.content : rawExp;
6228 const bindingType = context.bindingMetadata[rawExp];
6229 if (bindingType === "props" || bindingType === "props-aliased") {
6230 context.onError(createCompilerError(44, exp.loc));
6231 return createTransformProps();
6232 }
6233 const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
6234 if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
6235 context.onError(
6236 createCompilerError(42, exp.loc)
6237 );
6238 return createTransformProps();
6239 }
6240 if (context.prefixIdentifiers && isSimpleIdentifier(expString) && context.identifiers[expString]) {
6241 context.onError(
6242 createCompilerError(43, exp.loc)
6243 );
6244 return createTransformProps();
6245 }
6246 const propName = arg ? arg : createSimpleExpression("modelValue", true);
6247 const eventName = arg ? isStaticExp(arg) ? `onUpdate:${shared.camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
6248 let assignmentExp;
6249 const eventArg = context.isTS ? `($event: any)` : `$event`;
6250 if (maybeRef) {
6251 if (bindingType === "setup-ref") {
6252 assignmentExp = createCompoundExpression([
6253 `${eventArg} => ((`,
6254 createSimpleExpression(rawExp, false, exp.loc),
6255 `).value = $event)`
6256 ]);
6257 } else {
6258 const altAssignment = bindingType === "setup-let" ? `${rawExp} = $event` : `null`;
6259 assignmentExp = createCompoundExpression([
6260 `${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
6261 createSimpleExpression(rawExp, false, exp.loc),
6262 `).value = $event : ${altAssignment})`
6263 ]);
6264 }
6265 } else {
6266 assignmentExp = createCompoundExpression([
6267 `${eventArg} => ((`,
6268 exp,
6269 `) = $event)`
6270 ]);
6271 }
6272 const props = [
6273 // modelValue: foo
6274 createObjectProperty(propName, dir.exp),
6275 // "onUpdate:modelValue": $event => (foo = $event)
6276 createObjectProperty(eventName, assignmentExp)
6277 ];
6278 if (context.prefixIdentifiers && !context.inVOnce && context.cacheHandlers && !hasScopeRef(exp, context.identifiers)) {
6279 props[1].value = context.cache(props[1].value);
6280 }
6281 if (dir.modifiers.length && node.tagType === 1) {
6282 const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
6283 const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
6284 props.push(
6285 createObjectProperty(
6286 modifiersKey,
6287 createSimpleExpression(
6288 `{ ${modifiers} }`,
6289 false,
6290 dir.loc,
6291 2
6292 )
6293 )
6294 );
6295 }
6296 return createTransformProps(props);
6297};
6298function createTransformProps(props = []) {
6299 return { props };
6300}
6301
6302const validDivisionCharRE = /[\w).+\-_$\]]/;
6303const transformFilter = (node, context) => {
6304 if (!isCompatEnabled("COMPILER_FILTERS", context)) {
6305 return;
6306 }
6307 if (node.type === 5) {
6308 rewriteFilter(node.content, context);
6309 } else if (node.type === 1) {
6310 node.props.forEach((prop) => {
6311 if (prop.type === 7 && prop.name !== "for" && prop.exp) {
6312 rewriteFilter(prop.exp, context);
6313 }
6314 });
6315 }
6316};
6317function rewriteFilter(node, context) {
6318 if (node.type === 4) {
6319 parseFilter(node, context);
6320 } else {
6321 for (let i = 0; i < node.children.length; i++) {
6322 const child = node.children[i];
6323 if (typeof child !== "object") continue;
6324 if (child.type === 4) {
6325 parseFilter(child, context);
6326 } else if (child.type === 8) {
6327 rewriteFilter(node, context);
6328 } else if (child.type === 5) {
6329 rewriteFilter(child.content, context);
6330 }
6331 }
6332 }
6333}
6334function parseFilter(node, context) {
6335 const exp = node.content;
6336 let inSingle = false;
6337 let inDouble = false;
6338 let inTemplateString = false;
6339 let inRegex = false;
6340 let curly = 0;
6341 let square = 0;
6342 let paren = 0;
6343 let lastFilterIndex = 0;
6344 let c, prev, i, expression, filters = [];
6345 for (i = 0; i < exp.length; i++) {
6346 prev = c;
6347 c = exp.charCodeAt(i);
6348 if (inSingle) {
6349 if (c === 39 && prev !== 92) inSingle = false;
6350 } else if (inDouble) {
6351 if (c === 34 && prev !== 92) inDouble = false;
6352 } else if (inTemplateString) {
6353 if (c === 96 && prev !== 92) inTemplateString = false;
6354 } else if (inRegex) {
6355 if (c === 47 && prev !== 92) inRegex = false;
6356 } else if (c === 124 && // pipe
6357 exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
6358 if (expression === void 0) {
6359 lastFilterIndex = i + 1;
6360 expression = exp.slice(0, i).trim();
6361 } else {
6362 pushFilter();
6363 }
6364 } else {
6365 switch (c) {
6366 case 34:
6367 inDouble = true;
6368 break;
6369 // "
6370 case 39:
6371 inSingle = true;
6372 break;
6373 // '
6374 case 96:
6375 inTemplateString = true;
6376 break;
6377 // `
6378 case 40:
6379 paren++;
6380 break;
6381 // (
6382 case 41:
6383 paren--;
6384 break;
6385 // )
6386 case 91:
6387 square++;
6388 break;
6389 // [
6390 case 93:
6391 square--;
6392 break;
6393 // ]
6394 case 123:
6395 curly++;
6396 break;
6397 // {
6398 case 125:
6399 curly--;
6400 break;
6401 }
6402 if (c === 47) {
6403 let j = i - 1;
6404 let p;
6405 for (; j >= 0; j--) {
6406 p = exp.charAt(j);
6407 if (p !== " ") break;
6408 }
6409 if (!p || !validDivisionCharRE.test(p)) {
6410 inRegex = true;
6411 }
6412 }
6413 }
6414 }
6415 if (expression === void 0) {
6416 expression = exp.slice(0, i).trim();
6417 } else if (lastFilterIndex !== 0) {
6418 pushFilter();
6419 }
6420 function pushFilter() {
6421 filters.push(exp.slice(lastFilterIndex, i).trim());
6422 lastFilterIndex = i + 1;
6423 }
6424 if (filters.length) {
6425 for (i = 0; i < filters.length; i++) {
6426 expression = wrapFilter(expression, filters[i], context);
6427 }
6428 node.content = expression;
6429 node.ast = void 0;
6430 }
6431}
6432function wrapFilter(exp, filter, context) {
6433 context.helper(RESOLVE_FILTER);
6434 const i = filter.indexOf("(");
6435 if (i < 0) {
6436 context.filters.add(filter);
6437 return `${toValidAssetId(filter, "filter")}(${exp})`;
6438 } else {
6439 const name = filter.slice(0, i);
6440 const args = filter.slice(i + 1);
6441 context.filters.add(name);
6442 return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
6443 }
6444}
6445
6446const seen = /* @__PURE__ */ new WeakSet();
6447const transformMemo = (node, context) => {
6448 if (node.type === 1) {
6449 const dir = findDir(node, "memo");
6450 if (!dir || seen.has(node)) {
6451 return;
6452 }
6453 seen.add(node);
6454 return () => {
6455 const codegenNode = node.codegenNode || context.currentNode.codegenNode;
6456 if (codegenNode && codegenNode.type === 13) {
6457 if (node.tagType !== 1) {
6458 convertToBlock(codegenNode, context);
6459 }
6460 node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
6461 dir.exp,
6462 createFunctionExpression(void 0, codegenNode),
6463 `_cache`,
6464 String(context.cached.length)
6465 ]);
6466 context.cached.push(null);
6467 }
6468 };
6469 }
6470};
6471
6472function getBaseTransformPreset(prefixIdentifiers) {
6473 return [
6474 [
6475 transformOnce,
6476 transformIf,
6477 transformMemo,
6478 transformFor,
6479 ...[transformFilter] ,
6480 ...prefixIdentifiers ? [
6481 // order is important
6482 trackVForSlotScopes,
6483 transformExpression
6484 ] : [],
6485 transformSlotOutlet,
6486 transformElement,
6487 trackSlotScopes,
6488 transformText
6489 ],
6490 {
6491 on: transformOn,
6492 bind: transformBind,
6493 model: transformModel
6494 }
6495 ];
6496}
6497function baseCompile(source, options = {}) {
6498 const onError = options.onError || defaultOnError;
6499 const isModuleMode = options.mode === "module";
6500 const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
6501 if (!prefixIdentifiers && options.cacheHandlers) {
6502 onError(createCompilerError(49));
6503 }
6504 if (options.scopeId && !isModuleMode) {
6505 onError(createCompilerError(50));
6506 }
6507 const resolvedOptions = shared.extend({}, options, {
6508 prefixIdentifiers
6509 });
6510 const ast = shared.isString(source) ? baseParse(source, resolvedOptions) : source;
6511 const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
6512 if (options.isTS) {
6513 const { expressionPlugins } = options;
6514 if (!expressionPlugins || !expressionPlugins.includes("typescript")) {
6515 options.expressionPlugins = [...expressionPlugins || [], "typescript"];
6516 }
6517 }
6518 transform(
6519 ast,
6520 shared.extend({}, resolvedOptions, {
6521 nodeTransforms: [
6522 ...nodeTransforms,
6523 ...options.nodeTransforms || []
6524 // user transforms
6525 ],
6526 directiveTransforms: shared.extend(
6527 {},
6528 directiveTransforms,
6529 options.directiveTransforms || {}
6530 // user transforms
6531 )
6532 })
6533 );
6534 return generate(ast, resolvedOptions);
6535}
6536
6537const BindingTypes = {
6538 "DATA": "data",
6539 "PROPS": "props",
6540 "PROPS_ALIASED": "props-aliased",
6541 "SETUP_LET": "setup-let",
6542 "SETUP_CONST": "setup-const",
6543 "SETUP_REACTIVE_CONST": "setup-reactive-const",
6544 "SETUP_MAYBE_REF": "setup-maybe-ref",
6545 "SETUP_REF": "setup-ref",
6546 "OPTIONS": "options",
6547 "LITERAL_CONST": "literal-const"
6548};
6549
6550const noopDirectiveTransform = () => ({ props: [] });
6551
6552exports.generateCodeFrame = shared.generateCodeFrame;
6553exports.BASE_TRANSITION = BASE_TRANSITION;
6554exports.BindingTypes = BindingTypes;
6555exports.CAMELIZE = CAMELIZE;
6556exports.CAPITALIZE = CAPITALIZE;
6557exports.CREATE_BLOCK = CREATE_BLOCK;
6558exports.CREATE_COMMENT = CREATE_COMMENT;
6559exports.CREATE_ELEMENT_BLOCK = CREATE_ELEMENT_BLOCK;
6560exports.CREATE_ELEMENT_VNODE = CREATE_ELEMENT_VNODE;
6561exports.CREATE_SLOTS = CREATE_SLOTS;
6562exports.CREATE_STATIC = CREATE_STATIC;
6563exports.CREATE_TEXT = CREATE_TEXT;
6564exports.CREATE_VNODE = CREATE_VNODE;
6565exports.CompilerDeprecationTypes = CompilerDeprecationTypes;
6566exports.ConstantTypes = ConstantTypes;
6567exports.ElementTypes = ElementTypes;
6568exports.ErrorCodes = ErrorCodes;
6569exports.FRAGMENT = FRAGMENT;
6570exports.GUARD_REACTIVE_PROPS = GUARD_REACTIVE_PROPS;
6571exports.IS_MEMO_SAME = IS_MEMO_SAME;
6572exports.IS_REF = IS_REF;
6573exports.KEEP_ALIVE = KEEP_ALIVE;
6574exports.MERGE_PROPS = MERGE_PROPS;
6575exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
6576exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
6577exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
6578exports.Namespaces = Namespaces;
6579exports.NodeTypes = NodeTypes;
6580exports.OPEN_BLOCK = OPEN_BLOCK;
6581exports.POP_SCOPE_ID = POP_SCOPE_ID;
6582exports.PUSH_SCOPE_ID = PUSH_SCOPE_ID;
6583exports.RENDER_LIST = RENDER_LIST;
6584exports.RENDER_SLOT = RENDER_SLOT;
6585exports.RESOLVE_COMPONENT = RESOLVE_COMPONENT;
6586exports.RESOLVE_DIRECTIVE = RESOLVE_DIRECTIVE;
6587exports.RESOLVE_DYNAMIC_COMPONENT = RESOLVE_DYNAMIC_COMPONENT;
6588exports.RESOLVE_FILTER = RESOLVE_FILTER;
6589exports.SET_BLOCK_TRACKING = SET_BLOCK_TRACKING;
6590exports.SUSPENSE = SUSPENSE;
6591exports.TELEPORT = TELEPORT;
6592exports.TO_DISPLAY_STRING = TO_DISPLAY_STRING;
6593exports.TO_HANDLERS = TO_HANDLERS;
6594exports.TO_HANDLER_KEY = TO_HANDLER_KEY;
6595exports.TS_NODE_TYPES = TS_NODE_TYPES;
6596exports.UNREF = UNREF;
6597exports.WITH_CTX = WITH_CTX;
6598exports.WITH_DIRECTIVES = WITH_DIRECTIVES;
6599exports.WITH_MEMO = WITH_MEMO;
6600exports.advancePositionWithClone = advancePositionWithClone;
6601exports.advancePositionWithMutation = advancePositionWithMutation;
6602exports.assert = assert;
6603exports.baseCompile = baseCompile;
6604exports.baseParse = baseParse;
6605exports.buildDirectiveArgs = buildDirectiveArgs;
6606exports.buildProps = buildProps;
6607exports.buildSlots = buildSlots;
6608exports.checkCompatEnabled = checkCompatEnabled;
6609exports.convertToBlock = convertToBlock;
6610exports.createArrayExpression = createArrayExpression;
6611exports.createAssignmentExpression = createAssignmentExpression;
6612exports.createBlockStatement = createBlockStatement;
6613exports.createCacheExpression = createCacheExpression;
6614exports.createCallExpression = createCallExpression;
6615exports.createCompilerError = createCompilerError;
6616exports.createCompoundExpression = createCompoundExpression;
6617exports.createConditionalExpression = createConditionalExpression;
6618exports.createForLoopParams = createForLoopParams;
6619exports.createFunctionExpression = createFunctionExpression;
6620exports.createIfStatement = createIfStatement;
6621exports.createInterpolation = createInterpolation;
6622exports.createObjectExpression = createObjectExpression;
6623exports.createObjectProperty = createObjectProperty;
6624exports.createReturnStatement = createReturnStatement;
6625exports.createRoot = createRoot;
6626exports.createSequenceExpression = createSequenceExpression;
6627exports.createSimpleExpression = createSimpleExpression;
6628exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
6629exports.createTemplateLiteral = createTemplateLiteral;
6630exports.createTransformContext = createTransformContext;
6631exports.createVNodeCall = createVNodeCall;
6632exports.errorMessages = errorMessages;
6633exports.extractIdentifiers = extractIdentifiers;
6634exports.findDir = findDir;
6635exports.findProp = findProp;
6636exports.forAliasRE = forAliasRE;
6637exports.generate = generate;
6638exports.getBaseTransformPreset = getBaseTransformPreset;
6639exports.getConstantType = getConstantType;
6640exports.getMemoedVNodeCall = getMemoedVNodeCall;
6641exports.getVNodeBlockHelper = getVNodeBlockHelper;
6642exports.getVNodeHelper = getVNodeHelper;
6643exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
6644exports.hasScopeRef = hasScopeRef;
6645exports.helperNameMap = helperNameMap;
6646exports.injectProp = injectProp;
6647exports.isCoreComponent = isCoreComponent;
6648exports.isFnExpression = isFnExpression;
6649exports.isFnExpressionBrowser = isFnExpressionBrowser;
6650exports.isFnExpressionNode = isFnExpressionNode;
6651exports.isFunctionType = isFunctionType;
6652exports.isInDestructureAssignment = isInDestructureAssignment;
6653exports.isInNewExpression = isInNewExpression;
6654exports.isMemberExpression = isMemberExpression;
6655exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
6656exports.isMemberExpressionNode = isMemberExpressionNode;
6657exports.isReferencedIdentifier = isReferencedIdentifier;
6658exports.isSimpleIdentifier = isSimpleIdentifier;
6659exports.isSlotOutlet = isSlotOutlet;
6660exports.isStaticArgOf = isStaticArgOf;
6661exports.isStaticExp = isStaticExp;
6662exports.isStaticProperty = isStaticProperty;
6663exports.isStaticPropertyKey = isStaticPropertyKey;
6664exports.isTemplateNode = isTemplateNode;
6665exports.isText = isText$1;
6666exports.isVSlot = isVSlot;
6667exports.locStub = locStub;
6668exports.noopDirectiveTransform = noopDirectiveTransform;
6669exports.processExpression = processExpression;
6670exports.processFor = processFor;
6671exports.processIf = processIf;
6672exports.processSlotOutlet = processSlotOutlet;
6673exports.registerRuntimeHelpers = registerRuntimeHelpers;
6674exports.resolveComponentType = resolveComponentType;
6675exports.stringifyExpression = stringifyExpression;
6676exports.toValidAssetId = toValidAssetId;
6677exports.trackSlotScopes = trackSlotScopes;
6678exports.trackVForSlotScopes = trackVForSlotScopes;
6679exports.transform = transform;
6680exports.transformBind = transformBind;
6681exports.transformElement = transformElement;
6682exports.transformExpression = transformExpression;
6683exports.transformModel = transformModel;
6684exports.transformOn = transformOn;
6685exports.traverseNode = traverseNode;
6686exports.unwrapTSNode = unwrapTSNode;
6687exports.walkBlockDeclarations = walkBlockDeclarations;
6688exports.walkFunctionParams = walkFunctionParams;
6689exports.walkIdentifiers = walkIdentifiers;
6690exports.warnDeprecation = warnDeprecation;
Note: See TracBrowser for help on using the repository browser.