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