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