UNPKG

228 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var deindent = require('de-indent');
6var he = require('he');
7
8function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10var deindent__default = /*#__PURE__*/_interopDefaultLegacy(deindent);
11var he__default = /*#__PURE__*/_interopDefaultLegacy(he);
12
13const emptyObject = Object.freeze({});
14const isArray = Array.isArray;
15// These helpers produce better VM code in JS engines due to their
16// explicitness and function inlining.
17function isUndef(v) {
18 return v === undefined || v === null;
19}
20function isDef(v) {
21 return v !== undefined && v !== null;
22}
23function isTrue(v) {
24 return v === true;
25}
26function isFalse(v) {
27 return v === false;
28}
29/**
30 * Check if value is primitive.
31 */
32function isPrimitive(value) {
33 return (typeof value === 'string' ||
34 typeof value === 'number' ||
35 // $flow-disable-line
36 typeof value === 'symbol' ||
37 typeof value === 'boolean');
38}
39function isFunction(value) {
40 return typeof value === 'function';
41}
42/**
43 * Quick object check - this is primarily used to tell
44 * objects from primitive values when we know the value
45 * is a JSON-compliant type.
46 */
47function isObject(obj) {
48 return obj !== null && typeof obj === 'object';
49}
50/**
51 * Get the raw type string of a value, e.g., [object Object].
52 */
53const _toString = Object.prototype.toString;
54function toRawType(value) {
55 return _toString.call(value).slice(8, -1);
56}
57/**
58 * Strict object type check. Only returns true
59 * for plain JavaScript objects.
60 */
61function isPlainObject(obj) {
62 return _toString.call(obj) === '[object Object]';
63}
64/**
65 * Check if val is a valid array index.
66 */
67function isValidArrayIndex(val) {
68 const n = parseFloat(String(val));
69 return n >= 0 && Math.floor(n) === n && isFinite(val);
70}
71function isPromise(val) {
72 return (isDef(val) &&
73 typeof val.then === 'function' &&
74 typeof val.catch === 'function');
75}
76/**
77 * Convert a value to a string that is actually rendered.
78 */
79function toString(val) {
80 return val == null
81 ? ''
82 : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString)
83 ? JSON.stringify(val, replacer, 2)
84 : String(val);
85}
86function replacer(_key, val) {
87 // avoid circular deps from v3
88 if (val && val.__v_isRef) {
89 return val.value;
90 }
91 return val;
92}
93/**
94 * Convert an input value to a number for persistence.
95 * If the conversion fails, return original string.
96 */
97function toNumber(val) {
98 const n = parseFloat(val);
99 return isNaN(n) ? val : n;
100}
101/**
102 * Make a map and return a function for checking if a key
103 * is in that map.
104 */
105function makeMap(str, expectsLowerCase) {
106 const map = Object.create(null);
107 const list = str.split(',');
108 for (let i = 0; i < list.length; i++) {
109 map[list[i]] = true;
110 }
111 return expectsLowerCase ? val => map[val.toLowerCase()] : val => map[val];
112}
113/**
114 * Check if a tag is a built-in tag.
115 */
116const isBuiltInTag = makeMap('slot,component', true);
117/**
118 * Check if an attribute is a reserved attribute.
119 */
120const isReservedAttribute = makeMap('key,ref,slot,slot-scope,is');
121/**
122 * Check whether an object has the property.
123 */
124const hasOwnProperty = Object.prototype.hasOwnProperty;
125function hasOwn(obj, key) {
126 return hasOwnProperty.call(obj, key);
127}
128/**
129 * Create a cached version of a pure function.
130 */
131function cached(fn) {
132 const cache = Object.create(null);
133 return function cachedFn(str) {
134 const hit = cache[str];
135 return hit || (cache[str] = fn(str));
136 };
137}
138/**
139 * Camelize a hyphen-delimited string.
140 */
141const camelizeRE = /-(\w)/g;
142const camelize = cached((str) => {
143 return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
144});
145/**
146 * Capitalize a string.
147 */
148const capitalize = cached((str) => {
149 return str.charAt(0).toUpperCase() + str.slice(1);
150});
151/**
152 * Hyphenate a camelCase string.
153 */
154const hyphenateRE = /\B([A-Z])/g;
155const hyphenate = cached((str) => {
156 return str.replace(hyphenateRE, '-$1').toLowerCase();
157});
158/**
159 * Mix properties into target object.
160 */
161function extend(to, _from) {
162 for (const key in _from) {
163 to[key] = _from[key];
164 }
165 return to;
166}
167/**
168 * Merge an Array of Objects into a single Object.
169 */
170function toObject(arr) {
171 const res = {};
172 for (let i = 0; i < arr.length; i++) {
173 if (arr[i]) {
174 extend(res, arr[i]);
175 }
176 }
177 return res;
178}
179/* eslint-disable no-unused-vars */
180/**
181 * Perform no operation.
182 * Stubbing args to make Flow happy without leaving useless transpiled code
183 * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/).
184 */
185function noop(a, b, c) { }
186/**
187 * Always return false.
188 */
189const no = (a, b, c) => false;
190/* eslint-enable no-unused-vars */
191/**
192 * Return the same value.
193 */
194const identity = (_) => _;
195/**
196 * Generate a string containing static keys from compiler modules.
197 */
198function genStaticKeys$1(modules) {
199 return modules
200 .reduce((keys, m) => keys.concat(m.staticKeys || []), [])
201 .join(',');
202}
203/**
204 * Check if two values are loosely equal - that is,
205 * if they are plain objects, do they have the same shape?
206 */
207function looseEqual(a, b) {
208 if (a === b)
209 return true;
210 const isObjectA = isObject(a);
211 const isObjectB = isObject(b);
212 if (isObjectA && isObjectB) {
213 try {
214 const isArrayA = Array.isArray(a);
215 const isArrayB = Array.isArray(b);
216 if (isArrayA && isArrayB) {
217 return (a.length === b.length &&
218 a.every((e, i) => {
219 return looseEqual(e, b[i]);
220 }));
221 }
222 else if (a instanceof Date && b instanceof Date) {
223 return a.getTime() === b.getTime();
224 }
225 else if (!isArrayA && !isArrayB) {
226 const keysA = Object.keys(a);
227 const keysB = Object.keys(b);
228 return (keysA.length === keysB.length &&
229 keysA.every(key => {
230 return looseEqual(a[key], b[key]);
231 }));
232 }
233 else {
234 /* istanbul ignore next */
235 return false;
236 }
237 }
238 catch (e) {
239 /* istanbul ignore next */
240 return false;
241 }
242 }
243 else if (!isObjectA && !isObjectB) {
244 return String(a) === String(b);
245 }
246 else {
247 return false;
248 }
249}
250/**
251 * Return the first index at which a loosely equal value can be
252 * found in the array (if value is a plain object, the array must
253 * contain an object of the same shape), or -1 if it is not present.
254 */
255function looseIndexOf(arr, val) {
256 for (let i = 0; i < arr.length; i++) {
257 if (looseEqual(arr[i], val))
258 return i;
259 }
260 return -1;
261}
262// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#polyfill
263function hasChanged(x, y) {
264 if (x === y) {
265 return x === 0 && 1 / x !== 1 / y;
266 }
267 else {
268 return x === x || y === y;
269 }
270}
271
272const isUnaryTag = makeMap('area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
273 'link,meta,param,source,track,wbr');
274// Elements that you can, intentionally, leave open
275// (and which close themselves)
276const canBeLeftOpenTag = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source');
277// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
278// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
279const isNonPhrasingTag = makeMap('address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
280 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
281 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
282 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
283 'title,tr,track');
284
285/**
286 * unicode letters used for parsing html tags, component names and property paths.
287 * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
288 * skipping \u10000-\uEFFFF due to it freezing up PhantomJS
289 */
290const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/;
291/**
292 * Define a property.
293 */
294function def(obj, key, val, enumerable) {
295 Object.defineProperty(obj, key, {
296 value: val,
297 enumerable: !!enumerable,
298 writable: true,
299 configurable: true
300 });
301}
302
303/**
304 * Not type-checking this file because it's mostly vendor code.
305 */
306// Regular Expressions for parsing tags and attributes
307const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/;
308const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+?\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/;
309const ncname = `[a-zA-Z_][\\-\\.0-9_a-zA-Z${unicodeRegExp.source}]*`;
310const qnameCapture = `((?:${ncname}\\:)?${ncname})`;
311const startTagOpen = new RegExp(`^<${qnameCapture}`);
312const startTagClose = /^\s*(\/?)>/;
313const endTag = new RegExp(`^<\\/${qnameCapture}[^>]*>`);
314const doctype = /^<!DOCTYPE [^>]+>/i;
315// #7298: escape - to avoid being passed as HTML comment when inlined in page
316const comment = /^<!\--/;
317const conditionalComment = /^<!\[/;
318// Special Elements (can contain anything)
319const isPlainTextElement = makeMap('script,style,textarea', true);
320const reCache = {};
321const decodingMap = {
322 '&lt;': '<',
323 '&gt;': '>',
324 '&quot;': '"',
325 '&amp;': '&',
326 '&#10;': '\n',
327 '&#9;': '\t',
328 '&#39;': "'"
329};
330const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g;
331const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g;
332// #5992
333const isIgnoreNewlineTag = makeMap('pre,textarea', true);
334const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n';
335function decodeAttr(value, shouldDecodeNewlines) {
336 const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;
337 return value.replace(re, match => decodingMap[match]);
338}
339function parseHTML(html, options) {
340 const stack = [];
341 const expectHTML = options.expectHTML;
342 const isUnaryTag = options.isUnaryTag || no;
343 const canBeLeftOpenTag = options.canBeLeftOpenTag || no;
344 let index = 0;
345 let last, lastTag;
346 while (html) {
347 last = html;
348 // Make sure we're not in a plaintext content element like script/style
349 if (!lastTag || !isPlainTextElement(lastTag)) {
350 let textEnd = html.indexOf('<');
351 if (textEnd === 0) {
352 // Comment:
353 if (comment.test(html)) {
354 const commentEnd = html.indexOf('-->');
355 if (commentEnd >= 0) {
356 if (options.shouldKeepComment && options.comment) {
357 options.comment(html.substring(4, commentEnd), index, index + commentEnd + 3);
358 }
359 advance(commentEnd + 3);
360 continue;
361 }
362 }
363 // https://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
364 if (conditionalComment.test(html)) {
365 const conditionalEnd = html.indexOf(']>');
366 if (conditionalEnd >= 0) {
367 advance(conditionalEnd + 2);
368 continue;
369 }
370 }
371 // Doctype:
372 const doctypeMatch = html.match(doctype);
373 if (doctypeMatch) {
374 advance(doctypeMatch[0].length);
375 continue;
376 }
377 // End tag:
378 const endTagMatch = html.match(endTag);
379 if (endTagMatch) {
380 const curIndex = index;
381 advance(endTagMatch[0].length);
382 parseEndTag(endTagMatch[1], curIndex, index);
383 continue;
384 }
385 // Start tag:
386 const startTagMatch = parseStartTag();
387 if (startTagMatch) {
388 handleStartTag(startTagMatch);
389 if (shouldIgnoreFirstNewline(startTagMatch.tagName, html)) {
390 advance(1);
391 }
392 continue;
393 }
394 }
395 let text, rest, next;
396 if (textEnd >= 0) {
397 rest = html.slice(textEnd);
398 while (!endTag.test(rest) &&
399 !startTagOpen.test(rest) &&
400 !comment.test(rest) &&
401 !conditionalComment.test(rest)) {
402 // < in plain text, be forgiving and treat it as text
403 next = rest.indexOf('<', 1);
404 if (next < 0)
405 break;
406 textEnd += next;
407 rest = html.slice(textEnd);
408 }
409 text = html.substring(0, textEnd);
410 }
411 if (textEnd < 0) {
412 text = html;
413 }
414 if (text) {
415 advance(text.length);
416 }
417 if (options.chars && text) {
418 options.chars(text, index - text.length, index);
419 }
420 }
421 else {
422 let endTagLength = 0;
423 const stackedTag = lastTag.toLowerCase();
424 const reStackedTag = reCache[stackedTag] ||
425 (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));
426 const rest = html.replace(reStackedTag, function (all, text, endTag) {
427 endTagLength = endTag.length;
428 if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {
429 text = text
430 .replace(/<!\--([\s\S]*?)-->/g, '$1') // #7298
431 .replace(/<!\[CDATA\[([\s\S]*?)]]>/g, '$1');
432 }
433 if (shouldIgnoreFirstNewline(stackedTag, text)) {
434 text = text.slice(1);
435 }
436 if (options.chars) {
437 options.chars(text);
438 }
439 return '';
440 });
441 index += html.length - rest.length;
442 html = rest;
443 parseEndTag(stackedTag, index - endTagLength, index);
444 }
445 if (html === last) {
446 options.chars && options.chars(html);
447 if (process.env.NODE_ENV !== 'production' && !stack.length && options.warn) {
448 options.warn(`Mal-formatted tag at end of template: "${html}"`, {
449 start: index + html.length
450 });
451 }
452 break;
453 }
454 }
455 // Clean up any remaining tags
456 parseEndTag();
457 function advance(n) {
458 index += n;
459 html = html.substring(n);
460 }
461 function parseStartTag() {
462 const start = html.match(startTagOpen);
463 if (start) {
464 const match = {
465 tagName: start[1],
466 attrs: [],
467 start: index
468 };
469 advance(start[0].length);
470 let end, attr;
471 while (!(end = html.match(startTagClose)) &&
472 (attr = html.match(dynamicArgAttribute) || html.match(attribute))) {
473 attr.start = index;
474 advance(attr[0].length);
475 attr.end = index;
476 match.attrs.push(attr);
477 }
478 if (end) {
479 match.unarySlash = end[1];
480 advance(end[0].length);
481 match.end = index;
482 return match;
483 }
484 }
485 }
486 function handleStartTag(match) {
487 const tagName = match.tagName;
488 const unarySlash = match.unarySlash;
489 if (expectHTML) {
490 if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
491 parseEndTag(lastTag);
492 }
493 if (canBeLeftOpenTag(tagName) && lastTag === tagName) {
494 parseEndTag(tagName);
495 }
496 }
497 const unary = isUnaryTag(tagName) || !!unarySlash;
498 const l = match.attrs.length;
499 const attrs = new Array(l);
500 for (let i = 0; i < l; i++) {
501 const args = match.attrs[i];
502 const value = args[3] || args[4] || args[5] || '';
503 const shouldDecodeNewlines = tagName === 'a' && args[1] === 'href'
504 ? options.shouldDecodeNewlinesForHref
505 : options.shouldDecodeNewlines;
506 attrs[i] = {
507 name: args[1],
508 value: decodeAttr(value, shouldDecodeNewlines)
509 };
510 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
511 attrs[i].start = args.start + args[0].match(/^\s*/).length;
512 attrs[i].end = args.end;
513 }
514 }
515 if (!unary) {
516 stack.push({
517 tag: tagName,
518 lowerCasedTag: tagName.toLowerCase(),
519 attrs: attrs,
520 start: match.start,
521 end: match.end
522 });
523 lastTag = tagName;
524 }
525 if (options.start) {
526 options.start(tagName, attrs, unary, match.start, match.end);
527 }
528 }
529 function parseEndTag(tagName, start, end) {
530 let pos, lowerCasedTagName;
531 if (start == null)
532 start = index;
533 if (end == null)
534 end = index;
535 // Find the closest opened tag of the same type
536 if (tagName) {
537 lowerCasedTagName = tagName.toLowerCase();
538 for (pos = stack.length - 1; pos >= 0; pos--) {
539 if (stack[pos].lowerCasedTag === lowerCasedTagName) {
540 break;
541 }
542 }
543 }
544 else {
545 // If no tag name is provided, clean shop
546 pos = 0;
547 }
548 if (pos >= 0) {
549 // Close all the open elements, up the stack
550 for (let i = stack.length - 1; i >= pos; i--) {
551 if (process.env.NODE_ENV !== 'production' && (i > pos || !tagName) && options.warn) {
552 options.warn(`tag <${stack[i].tag}> has no matching end tag.`, {
553 start: stack[i].start,
554 end: stack[i].end
555 });
556 }
557 if (options.end) {
558 options.end(stack[i].tag, start, end);
559 }
560 }
561 // Remove the open elements from the stack
562 stack.length = pos;
563 lastTag = pos && stack[pos - 1].tag;
564 }
565 else if (lowerCasedTagName === 'br') {
566 if (options.start) {
567 options.start(tagName, [], true, start, end);
568 }
569 }
570 else if (lowerCasedTagName === 'p') {
571 if (options.start) {
572 options.start(tagName, [], false, start, end);
573 }
574 if (options.end) {
575 options.end(tagName, start, end);
576 }
577 }
578 }
579}
580
581const DEFAULT_FILENAME = 'anonymous.vue';
582const splitRE = /\r?\n/g;
583const replaceRE = /./g;
584const isSpecialTag = makeMap('script,style,template', true);
585/**
586 * Parse a single-file component (*.vue) file into an SFC Descriptor Object.
587 */
588function parseComponent(source, options = {}) {
589 const sfc = {
590 source,
591 filename: DEFAULT_FILENAME,
592 template: null,
593 script: null,
594 scriptSetup: null,
595 styles: [],
596 customBlocks: [],
597 cssVars: [],
598 errors: [],
599 shouldForceReload: null // attached in parse() by compiler-sfc
600 };
601 let depth = 0;
602 let currentBlock = null;
603 let warn = msg => {
604 sfc.errors.push(msg);
605 };
606 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
607 warn = (msg, range) => {
608 const data = { msg };
609 if (range.start != null) {
610 data.start = range.start;
611 }
612 if (range.end != null) {
613 data.end = range.end;
614 }
615 sfc.errors.push(data);
616 };
617 }
618 function start(tag, attrs, unary, start, end) {
619 if (depth === 0) {
620 currentBlock = {
621 type: tag,
622 content: '',
623 start: end,
624 end: 0,
625 attrs: attrs.reduce((cumulated, { name, value }) => {
626 cumulated[name] = value || true;
627 return cumulated;
628 }, {})
629 };
630 if (typeof currentBlock.attrs.src === 'string') {
631 currentBlock.src = currentBlock.attrs.src;
632 }
633 if (isSpecialTag(tag)) {
634 checkAttrs(currentBlock, attrs);
635 if (tag === 'script') {
636 const block = currentBlock;
637 if (block.attrs.setup) {
638 block.setup = currentBlock.attrs.setup;
639 sfc.scriptSetup = block;
640 }
641 else {
642 sfc.script = block;
643 }
644 }
645 else if (tag === 'style') {
646 sfc.styles.push(currentBlock);
647 }
648 else {
649 sfc[tag] = currentBlock;
650 }
651 }
652 else {
653 // custom blocks
654 sfc.customBlocks.push(currentBlock);
655 }
656 }
657 if (!unary) {
658 depth++;
659 }
660 }
661 function checkAttrs(block, attrs) {
662 for (let i = 0; i < attrs.length; i++) {
663 const attr = attrs[i];
664 if (attr.name === 'lang') {
665 block.lang = attr.value;
666 }
667 if (attr.name === 'scoped') {
668 block.scoped = true;
669 }
670 if (attr.name === 'module') {
671 block.module = attr.value || true;
672 }
673 }
674 }
675 function end(tag, start) {
676 if (depth === 1 && currentBlock) {
677 currentBlock.end = start;
678 let text = source.slice(currentBlock.start, currentBlock.end);
679 if (options.deindent === true ||
680 // by default, deindent unless it's script with default lang or (j/t)sx?
681 (options.deindent !== false &&
682 !(currentBlock.type === 'script' &&
683 (!currentBlock.lang || /^(j|t)sx?$/.test(currentBlock.lang))))) {
684 text = deindent__default["default"](text);
685 }
686 // pad content so that linters and pre-processors can output correct
687 // line numbers in errors and warnings
688 if (currentBlock.type !== 'template' && options.pad) {
689 text = padContent(currentBlock, options.pad) + text;
690 }
691 currentBlock.content = text;
692 currentBlock = null;
693 }
694 depth--;
695 }
696 function padContent(block, pad) {
697 if (pad === 'space') {
698 return source.slice(0, block.start).replace(replaceRE, ' ');
699 }
700 else {
701 const offset = source.slice(0, block.start).split(splitRE).length;
702 const padChar = block.type === 'script' && !block.lang ? '//\n' : '\n';
703 return Array(offset).join(padChar);
704 }
705 }
706 parseHTML(source, {
707 warn,
708 start,
709 end,
710 outputSourceRange: options.outputSourceRange
711 });
712 return sfc;
713}
714
715// can we use __proto__?
716const hasProto = '__proto__' in {};
717// Browser environment sniffing
718const inBrowser = typeof window !== 'undefined';
719const UA = inBrowser && window.navigator.userAgent.toLowerCase();
720const isIE = UA && /msie|trident/.test(UA);
721UA && UA.indexOf('msie 9.0') > 0;
722const isEdge = UA && UA.indexOf('edge/') > 0;
723UA && UA.indexOf('android') > 0;
724UA && /iphone|ipad|ipod|ios/.test(UA);
725UA && /chrome\/\d+/.test(UA) && !isEdge;
726UA && /phantomjs/.test(UA);
727UA && UA.match(/firefox\/(\d+)/);
728// Firefox has a "watch" function on Object.prototype...
729// @ts-expect-error firebox support
730const nativeWatch = {}.watch;
731let supportsPassive = false;
732if (inBrowser) {
733 try {
734 const opts = {};
735 Object.defineProperty(opts, 'passive', {
736 get() {
737 /* istanbul ignore next */
738 supportsPassive = true;
739 }
740 }); // https://github.com/facebook/flow/issues/285
741 window.addEventListener('test-passive', null, opts);
742 }
743 catch (e) { }
744}
745// this needs to be lazy-evaled because vue may be required before
746// vue-server-renderer can set VUE_ENV
747let _isServer;
748const isServerRendering = () => {
749 if (_isServer === undefined) {
750 /* istanbul ignore if */
751 if (!inBrowser && typeof global !== 'undefined') {
752 // detect presence of vue-server-renderer and avoid
753 // Webpack shimming the process
754 _isServer =
755 global['process'] && global['process'].env.VUE_ENV === 'server';
756 }
757 else {
758 _isServer = false;
759 }
760 }
761 return _isServer;
762};
763/* istanbul ignore next */
764function isNative(Ctor) {
765 return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
766}
767const hasSymbol = typeof Symbol !== 'undefined' &&
768 isNative(Symbol) &&
769 typeof Reflect !== 'undefined' &&
770 isNative(Reflect.ownKeys);
771let _Set; // $flow-disable-line
772/* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) {
773 // use native Set when available.
774 _Set = Set;
775}
776else {
777 // a non-standard Set polyfill that only works with primitive keys.
778 _Set = class Set {
779 constructor() {
780 this.set = Object.create(null);
781 }
782 has(key) {
783 return this.set[key] === true;
784 }
785 add(key) {
786 this.set[key] = true;
787 }
788 clear() {
789 this.set = Object.create(null);
790 }
791 };
792}
793
794const ASSET_TYPES = ['component', 'directive', 'filter'];
795const LIFECYCLE_HOOKS = [
796 'beforeCreate',
797 'created',
798 'beforeMount',
799 'mounted',
800 'beforeUpdate',
801 'updated',
802 'beforeDestroy',
803 'destroyed',
804 'activated',
805 'deactivated',
806 'errorCaptured',
807 'serverPrefetch',
808 'renderTracked',
809 'renderTriggered'
810];
811
812var config = {
813 /**
814 * Option merge strategies (used in core/util/options)
815 */
816 // $flow-disable-line
817 optionMergeStrategies: Object.create(null),
818 /**
819 * Whether to suppress warnings.
820 */
821 silent: false,
822 /**
823 * Show production mode tip message on boot?
824 */
825 productionTip: process.env.NODE_ENV !== 'production',
826 /**
827 * Whether to enable devtools
828 */
829 devtools: process.env.NODE_ENV !== 'production',
830 /**
831 * Whether to record perf
832 */
833 performance: false,
834 /**
835 * Error handler for watcher errors
836 */
837 errorHandler: null,
838 /**
839 * Warn handler for watcher warns
840 */
841 warnHandler: null,
842 /**
843 * Ignore certain custom elements
844 */
845 ignoredElements: [],
846 /**
847 * Custom user key aliases for v-on
848 */
849 // $flow-disable-line
850 keyCodes: Object.create(null),
851 /**
852 * Check if a tag is reserved so that it cannot be registered as a
853 * component. This is platform-dependent and may be overwritten.
854 */
855 isReservedTag: no,
856 /**
857 * Check if an attribute is reserved so that it cannot be used as a component
858 * prop. This is platform-dependent and may be overwritten.
859 */
860 isReservedAttr: no,
861 /**
862 * Check if a tag is an unknown element.
863 * Platform-dependent.
864 */
865 isUnknownElement: no,
866 /**
867 * Get the namespace of an element
868 */
869 getTagNamespace: noop,
870 /**
871 * Parse the real tag name for the specific platform.
872 */
873 parsePlatformTagName: identity,
874 /**
875 * Check if an attribute must be bound using property, e.g. value
876 * Platform-dependent.
877 */
878 mustUseProp: no,
879 /**
880 * Perform updates asynchronously. Intended to be used by Vue Test Utils
881 * This will significantly reduce performance if set to false.
882 */
883 async: true,
884 /**
885 * Exposed for legacy reasons
886 */
887 _lifecycleHooks: LIFECYCLE_HOOKS
888};
889
890let currentInstance = null;
891/**
892 * @internal
893 */
894function setCurrentInstance(vm = null) {
895 if (!vm)
896 currentInstance && currentInstance._scope.off();
897 currentInstance = vm;
898 vm && vm._scope.on();
899}
900
901/**
902 * @internal
903 */
904class VNode {
905 constructor(tag, data, children, text, elm, context, componentOptions, asyncFactory) {
906 this.tag = tag;
907 this.data = data;
908 this.children = children;
909 this.text = text;
910 this.elm = elm;
911 this.ns = undefined;
912 this.context = context;
913 this.fnContext = undefined;
914 this.fnOptions = undefined;
915 this.fnScopeId = undefined;
916 this.key = data && data.key;
917 this.componentOptions = componentOptions;
918 this.componentInstance = undefined;
919 this.parent = undefined;
920 this.raw = false;
921 this.isStatic = false;
922 this.isRootInsert = true;
923 this.isComment = false;
924 this.isCloned = false;
925 this.isOnce = false;
926 this.asyncFactory = asyncFactory;
927 this.asyncMeta = undefined;
928 this.isAsyncPlaceholder = false;
929 }
930 // DEPRECATED: alias for componentInstance for backwards compat.
931 /* istanbul ignore next */
932 get child() {
933 return this.componentInstance;
934 }
935}
936const createEmptyVNode = (text = '') => {
937 const node = new VNode();
938 node.text = text;
939 node.isComment = true;
940 return node;
941};
942function createTextVNode(val) {
943 return new VNode(undefined, undefined, undefined, String(val));
944}
945// optimized shallow clone
946// used for static nodes and slot nodes because they may be reused across
947// multiple renders, cloning them avoids errors when DOM manipulations rely
948// on their elm reference.
949function cloneVNode(vnode) {
950 const cloned = new VNode(vnode.tag, vnode.data,
951 // #7975
952 // clone children array to avoid mutating original in case of cloning
953 // a child.
954 vnode.children && vnode.children.slice(), vnode.text, vnode.elm, vnode.context, vnode.componentOptions, vnode.asyncFactory);
955 cloned.ns = vnode.ns;
956 cloned.isStatic = vnode.isStatic;
957 cloned.key = vnode.key;
958 cloned.isComment = vnode.isComment;
959 cloned.fnContext = vnode.fnContext;
960 cloned.fnOptions = vnode.fnOptions;
961 cloned.fnScopeId = vnode.fnScopeId;
962 cloned.asyncMeta = vnode.asyncMeta;
963 cloned.isCloned = true;
964 return cloned;
965}
966
967/* not type checking this file because flow doesn't play well with Proxy */
968if (process.env.NODE_ENV !== 'production') {
969 makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
970 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
971 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,' +
972 'require' // for Webpack/Browserify
973 );
974 const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
975 if (hasProxy) {
976 const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact');
977 config.keyCodes = new Proxy(config.keyCodes, {
978 set(target, key, value) {
979 if (isBuiltInModifier(key)) {
980 warn$2(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`);
981 return false;
982 }
983 else {
984 target[key] = value;
985 return true;
986 }
987 }
988 });
989 }
990}
991
992let uid = 0;
993/**
994 * A dep is an observable that can have multiple
995 * directives subscribing to it.
996 * @internal
997 */
998class Dep {
999 constructor() {
1000 // pending subs cleanup
1001 this._pending = false;
1002 this.id = uid++;
1003 this.subs = [];
1004 }
1005 addSub(sub) {
1006 this.subs.push(sub);
1007 }
1008 removeSub(sub) {
1009 // #12696 deps with massive amount of subscribers are extremely slow to
1010 // clean up in Chromium
1011 // to workaround this, we unset the sub for now, and clear them on
1012 // next scheduler flush.
1013 this.subs[this.subs.indexOf(sub)] = null;
1014 if (!this._pending) {
1015 this._pending = true;
1016 }
1017 }
1018 depend(info) {
1019 if (Dep.target) {
1020 Dep.target.addDep(this);
1021 if (process.env.NODE_ENV !== 'production' && info && Dep.target.onTrack) {
1022 Dep.target.onTrack(Object.assign({ effect: Dep.target }, info));
1023 }
1024 }
1025 }
1026 notify(info) {
1027 // stabilize the subscriber list first
1028 const subs = this.subs.filter(s => s);
1029 if (process.env.NODE_ENV !== 'production' && !config.async) {
1030 // subs aren't sorted in scheduler if not running async
1031 // we need to sort them now to make sure they fire in correct
1032 // order
1033 subs.sort((a, b) => a.id - b.id);
1034 }
1035 for (let i = 0, l = subs.length; i < l; i++) {
1036 const sub = subs[i];
1037 if (process.env.NODE_ENV !== 'production' && info) {
1038 sub.onTrigger &&
1039 sub.onTrigger(Object.assign({ effect: subs[i] }, info));
1040 }
1041 sub.update();
1042 }
1043 }
1044}
1045// The current target watcher being evaluated.
1046// This is globally unique because only one watcher
1047// can be evaluated at a time.
1048Dep.target = null;
1049const targetStack = [];
1050function pushTarget(target) {
1051 targetStack.push(target);
1052 Dep.target = target;
1053}
1054function popTarget() {
1055 targetStack.pop();
1056 Dep.target = targetStack[targetStack.length - 1];
1057}
1058
1059/*
1060 * not type checking this file because flow doesn't play well with
1061 * dynamically accessing methods on Array prototype
1062 */
1063const arrayProto = Array.prototype;
1064const arrayMethods = Object.create(arrayProto);
1065const methodsToPatch = [
1066 'push',
1067 'pop',
1068 'shift',
1069 'unshift',
1070 'splice',
1071 'sort',
1072 'reverse'
1073];
1074/**
1075 * Intercept mutating methods and emit events
1076 */
1077methodsToPatch.forEach(function (method) {
1078 // cache original method
1079 const original = arrayProto[method];
1080 def(arrayMethods, method, function mutator(...args) {
1081 const result = original.apply(this, args);
1082 const ob = this.__ob__;
1083 let inserted;
1084 switch (method) {
1085 case 'push':
1086 case 'unshift':
1087 inserted = args;
1088 break;
1089 case 'splice':
1090 inserted = args.slice(2);
1091 break;
1092 }
1093 if (inserted)
1094 ob.observeArray(inserted);
1095 // notify change
1096 if (process.env.NODE_ENV !== 'production') {
1097 ob.dep.notify({
1098 type: "array mutation" /* TriggerOpTypes.ARRAY_MUTATION */,
1099 target: this,
1100 key: method
1101 });
1102 }
1103 else {
1104 ob.dep.notify();
1105 }
1106 return result;
1107 });
1108});
1109
1110const arrayKeys = Object.getOwnPropertyNames(arrayMethods);
1111const NO_INITIAL_VALUE = {};
1112/**
1113 * In some cases we may want to disable observation inside a component's
1114 * update computation.
1115 */
1116let shouldObserve = true;
1117function toggleObserving(value) {
1118 shouldObserve = value;
1119}
1120// ssr mock dep
1121const mockDep = {
1122 notify: noop,
1123 depend: noop,
1124 addSub: noop,
1125 removeSub: noop
1126};
1127/**
1128 * Observer class that is attached to each observed
1129 * object. Once attached, the observer converts the target
1130 * object's property keys into getter/setters that
1131 * collect dependencies and dispatch updates.
1132 */
1133class Observer {
1134 constructor(value, shallow = false, mock = false) {
1135 this.value = value;
1136 this.shallow = shallow;
1137 this.mock = mock;
1138 // this.value = value
1139 this.dep = mock ? mockDep : new Dep();
1140 this.vmCount = 0;
1141 def(value, '__ob__', this);
1142 if (isArray(value)) {
1143 if (!mock) {
1144 if (hasProto) {
1145 value.__proto__ = arrayMethods;
1146 /* eslint-enable no-proto */
1147 }
1148 else {
1149 for (let i = 0, l = arrayKeys.length; i < l; i++) {
1150 const key = arrayKeys[i];
1151 def(value, key, arrayMethods[key]);
1152 }
1153 }
1154 }
1155 if (!shallow) {
1156 this.observeArray(value);
1157 }
1158 }
1159 else {
1160 /**
1161 * Walk through all properties and convert them into
1162 * getter/setters. This method should only be called when
1163 * value type is Object.
1164 */
1165 const keys = Object.keys(value);
1166 for (let i = 0; i < keys.length; i++) {
1167 const key = keys[i];
1168 defineReactive(value, key, NO_INITIAL_VALUE, undefined, shallow, mock);
1169 }
1170 }
1171 }
1172 /**
1173 * Observe a list of Array items.
1174 */
1175 observeArray(value) {
1176 for (let i = 0, l = value.length; i < l; i++) {
1177 observe(value[i], false, this.mock);
1178 }
1179 }
1180}
1181// helpers
1182/**
1183 * Attempt to create an observer instance for a value,
1184 * returns the new observer if successfully observed,
1185 * or the existing observer if the value already has one.
1186 */
1187function observe(value, shallow, ssrMockReactivity) {
1188 if (value && hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
1189 return value.__ob__;
1190 }
1191 if (shouldObserve &&
1192 (ssrMockReactivity || !isServerRendering()) &&
1193 (isArray(value) || isPlainObject(value)) &&
1194 Object.isExtensible(value) &&
1195 !value.__v_skip /* ReactiveFlags.SKIP */ &&
1196 !isRef(value) &&
1197 !(value instanceof VNode)) {
1198 return new Observer(value, shallow, ssrMockReactivity);
1199 }
1200}
1201/**
1202 * Define a reactive property on an Object.
1203 */
1204function defineReactive(obj, key, val, customSetter, shallow, mock, observeEvenIfShallow = false) {
1205 const dep = new Dep();
1206 const property = Object.getOwnPropertyDescriptor(obj, key);
1207 if (property && property.configurable === false) {
1208 return;
1209 }
1210 // cater for pre-defined getter/setters
1211 const getter = property && property.get;
1212 const setter = property && property.set;
1213 if ((!getter || setter) &&
1214 (val === NO_INITIAL_VALUE || arguments.length === 2)) {
1215 val = obj[key];
1216 }
1217 let childOb = shallow ? val && val.__ob__ : observe(val, false, mock);
1218 Object.defineProperty(obj, key, {
1219 enumerable: true,
1220 configurable: true,
1221 get: function reactiveGetter() {
1222 const value = getter ? getter.call(obj) : val;
1223 if (Dep.target) {
1224 if (process.env.NODE_ENV !== 'production') {
1225 dep.depend({
1226 target: obj,
1227 type: "get" /* TrackOpTypes.GET */,
1228 key
1229 });
1230 }
1231 else {
1232 dep.depend();
1233 }
1234 if (childOb) {
1235 childOb.dep.depend();
1236 if (isArray(value)) {
1237 dependArray(value);
1238 }
1239 }
1240 }
1241 return isRef(value) && !shallow ? value.value : value;
1242 },
1243 set: function reactiveSetter(newVal) {
1244 const value = getter ? getter.call(obj) : val;
1245 if (!hasChanged(value, newVal)) {
1246 return;
1247 }
1248 if (process.env.NODE_ENV !== 'production' && customSetter) {
1249 customSetter();
1250 }
1251 if (setter) {
1252 setter.call(obj, newVal);
1253 }
1254 else if (getter) {
1255 // #7981: for accessor properties without setter
1256 return;
1257 }
1258 else if (!shallow && isRef(value) && !isRef(newVal)) {
1259 value.value = newVal;
1260 return;
1261 }
1262 else {
1263 val = newVal;
1264 }
1265 childOb = shallow ? newVal && newVal.__ob__ : observe(newVal, false, mock);
1266 if (process.env.NODE_ENV !== 'production') {
1267 dep.notify({
1268 type: "set" /* TriggerOpTypes.SET */,
1269 target: obj,
1270 key,
1271 newValue: newVal,
1272 oldValue: value
1273 });
1274 }
1275 else {
1276 dep.notify();
1277 }
1278 }
1279 });
1280 return dep;
1281}
1282function set(target, key, val) {
1283 if (process.env.NODE_ENV !== 'production' && (isUndef(target) || isPrimitive(target))) {
1284 warn$2(`Cannot set reactive property on undefined, null, or primitive value: ${target}`);
1285 }
1286 if (isReadonly(target)) {
1287 process.env.NODE_ENV !== 'production' && warn$2(`Set operation on key "${key}" failed: target is readonly.`);
1288 return;
1289 }
1290 const ob = target.__ob__;
1291 if (isArray(target) && isValidArrayIndex(key)) {
1292 target.length = Math.max(target.length, key);
1293 target.splice(key, 1, val);
1294 // when mocking for SSR, array methods are not hijacked
1295 if (ob && !ob.shallow && ob.mock) {
1296 observe(val, false, true);
1297 }
1298 return val;
1299 }
1300 if (key in target && !(key in Object.prototype)) {
1301 target[key] = val;
1302 return val;
1303 }
1304 if (target._isVue || (ob && ob.vmCount)) {
1305 process.env.NODE_ENV !== 'production' &&
1306 warn$2('Avoid adding reactive properties to a Vue instance or its root $data ' +
1307 'at runtime - declare it upfront in the data option.');
1308 return val;
1309 }
1310 if (!ob) {
1311 target[key] = val;
1312 return val;
1313 }
1314 defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
1315 if (process.env.NODE_ENV !== 'production') {
1316 ob.dep.notify({
1317 type: "add" /* TriggerOpTypes.ADD */,
1318 target: target,
1319 key,
1320 newValue: val,
1321 oldValue: undefined
1322 });
1323 }
1324 else {
1325 ob.dep.notify();
1326 }
1327 return val;
1328}
1329/**
1330 * Collect dependencies on array elements when the array is touched, since
1331 * we cannot intercept array element access like property getters.
1332 */
1333function dependArray(value) {
1334 for (let e, i = 0, l = value.length; i < l; i++) {
1335 e = value[i];
1336 if (e && e.__ob__) {
1337 e.__ob__.dep.depend();
1338 }
1339 if (isArray(e)) {
1340 dependArray(e);
1341 }
1342 }
1343}
1344
1345function isReadonly(value) {
1346 return !!(value && value.__v_isReadonly);
1347}
1348
1349function isRef(r) {
1350 return !!(r && r.__v_isRef === true);
1351}
1352
1353if (process.env.NODE_ENV !== 'production') ;
1354
1355const normalizeEvent = cached((name) => {
1356 const passive = name.charAt(0) === '&';
1357 name = passive ? name.slice(1) : name;
1358 const once = name.charAt(0) === '~'; // Prefixed last, checked first
1359 name = once ? name.slice(1) : name;
1360 const capture = name.charAt(0) === '!';
1361 name = capture ? name.slice(1) : name;
1362 return {
1363 name,
1364 once,
1365 capture,
1366 passive
1367 };
1368});
1369function createFnInvoker(fns, vm) {
1370 function invoker() {
1371 const fns = invoker.fns;
1372 if (isArray(fns)) {
1373 const cloned = fns.slice();
1374 for (let i = 0; i < cloned.length; i++) {
1375 invokeWithErrorHandling(cloned[i], null, arguments, vm, `v-on handler`);
1376 }
1377 }
1378 else {
1379 // return handler return value for single handlers
1380 return invokeWithErrorHandling(fns, null, arguments, vm, `v-on handler`);
1381 }
1382 }
1383 invoker.fns = fns;
1384 return invoker;
1385}
1386function updateListeners(on, oldOn, add, remove, createOnceHandler, vm) {
1387 let name, cur, old, event;
1388 for (name in on) {
1389 cur = on[name];
1390 old = oldOn[name];
1391 event = normalizeEvent(name);
1392 if (isUndef(cur)) {
1393 process.env.NODE_ENV !== 'production' &&
1394 warn$2(`Invalid handler for event "${event.name}": got ` + String(cur), vm);
1395 }
1396 else if (isUndef(old)) {
1397 if (isUndef(cur.fns)) {
1398 cur = on[name] = createFnInvoker(cur, vm);
1399 }
1400 if (isTrue(event.once)) {
1401 cur = on[name] = createOnceHandler(event.name, cur, event.capture);
1402 }
1403 add(event.name, cur, event.capture, event.passive, event.params);
1404 }
1405 else if (cur !== old) {
1406 old.fns = cur;
1407 on[name] = old;
1408 }
1409 }
1410 for (name in oldOn) {
1411 if (isUndef(on[name])) {
1412 event = normalizeEvent(name);
1413 remove(event.name, oldOn[name], event.capture);
1414 }
1415 }
1416}
1417
1418function extractPropsFromVNodeData(data, Ctor, tag) {
1419 // we are only extracting raw values here.
1420 // validation and default values are handled in the child
1421 // component itself.
1422 const propOptions = Ctor.options.props;
1423 if (isUndef(propOptions)) {
1424 return;
1425 }
1426 const res = {};
1427 const { attrs, props } = data;
1428 if (isDef(attrs) || isDef(props)) {
1429 for (const key in propOptions) {
1430 const altKey = hyphenate(key);
1431 if (process.env.NODE_ENV !== 'production') {
1432 const keyInLowerCase = key.toLowerCase();
1433 if (key !== keyInLowerCase && attrs && hasOwn(attrs, keyInLowerCase)) {
1434 tip(`Prop "${keyInLowerCase}" is passed to component ` +
1435 `${formatComponentName(
1436 // @ts-expect-error tag is string
1437 tag || Ctor)}, but the declared prop name is` +
1438 ` "${key}". ` +
1439 `Note that HTML attributes are case-insensitive and camelCased ` +
1440 `props need to use their kebab-case equivalents when using in-DOM ` +
1441 `templates. You should probably use "${altKey}" instead of "${key}".`);
1442 }
1443 }
1444 checkProp(res, props, key, altKey, true) ||
1445 checkProp(res, attrs, key, altKey, false);
1446 }
1447 }
1448 return res;
1449}
1450function checkProp(res, hash, key, altKey, preserve) {
1451 if (isDef(hash)) {
1452 if (hasOwn(hash, key)) {
1453 res[key] = hash[key];
1454 if (!preserve) {
1455 delete hash[key];
1456 }
1457 return true;
1458 }
1459 else if (hasOwn(hash, altKey)) {
1460 res[key] = hash[altKey];
1461 if (!preserve) {
1462 delete hash[altKey];
1463 }
1464 return true;
1465 }
1466 }
1467 return false;
1468}
1469
1470// The template compiler attempts to minimize the need for normalization by
1471// statically analyzing the template at compile time.
1472//
1473// For plain HTML markup, normalization can be completely skipped because the
1474// generated render function is guaranteed to return Array<VNode>. There are
1475// two cases where extra normalization is needed:
1476// 1. When the children contains components - because a functional component
1477// may return an Array instead of a single root. In this case, just a simple
1478// normalization is needed - if any child is an Array, we flatten the whole
1479// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
1480// because functional components already normalize their own children.
1481function simpleNormalizeChildren(children) {
1482 for (let i = 0; i < children.length; i++) {
1483 if (isArray(children[i])) {
1484 return Array.prototype.concat.apply([], children);
1485 }
1486 }
1487 return children;
1488}
1489// 2. When the children contains constructs that always generated nested Arrays,
1490// e.g. <template>, <slot>, v-for, or when the children is provided by user
1491// with hand-written render functions / JSX. In such cases a full normalization
1492// is needed to cater to all possible types of children values.
1493function normalizeChildren(children) {
1494 return isPrimitive(children)
1495 ? [createTextVNode(children)]
1496 : isArray(children)
1497 ? normalizeArrayChildren(children)
1498 : undefined;
1499}
1500function isTextNode(node) {
1501 return isDef(node) && isDef(node.text) && isFalse(node.isComment);
1502}
1503function normalizeArrayChildren(children, nestedIndex) {
1504 const res = [];
1505 let i, c, lastIndex, last;
1506 for (i = 0; i < children.length; i++) {
1507 c = children[i];
1508 if (isUndef(c) || typeof c === 'boolean')
1509 continue;
1510 lastIndex = res.length - 1;
1511 last = res[lastIndex];
1512 // nested
1513 if (isArray(c)) {
1514 if (c.length > 0) {
1515 c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`);
1516 // merge adjacent text nodes
1517 if (isTextNode(c[0]) && isTextNode(last)) {
1518 res[lastIndex] = createTextVNode(last.text + c[0].text);
1519 c.shift();
1520 }
1521 res.push.apply(res, c);
1522 }
1523 }
1524 else if (isPrimitive(c)) {
1525 if (isTextNode(last)) {
1526 // merge adjacent text nodes
1527 // this is necessary for SSR hydration because text nodes are
1528 // essentially merged when rendered to HTML strings
1529 res[lastIndex] = createTextVNode(last.text + c);
1530 }
1531 else if (c !== '') {
1532 // convert primitive to vnode
1533 res.push(createTextVNode(c));
1534 }
1535 }
1536 else {
1537 if (isTextNode(c) && isTextNode(last)) {
1538 // merge adjacent text nodes
1539 res[lastIndex] = createTextVNode(last.text + c.text);
1540 }
1541 else {
1542 // default key for nested array children (likely generated by v-for)
1543 if (isTrue(children._isVList) &&
1544 isDef(c.tag) &&
1545 isUndef(c.key) &&
1546 isDef(nestedIndex)) {
1547 c.key = `__vlist${nestedIndex}_${i}__`;
1548 }
1549 res.push(c);
1550 }
1551 }
1552 }
1553 return res;
1554}
1555
1556const SIMPLE_NORMALIZE = 1;
1557const ALWAYS_NORMALIZE = 2;
1558// wrapper function for providing a more flexible interface
1559// without getting yelled at by flow
1560function createElement(context, tag, data, children, normalizationType, alwaysNormalize) {
1561 if (isArray(data) || isPrimitive(data)) {
1562 normalizationType = children;
1563 children = data;
1564 data = undefined;
1565 }
1566 if (isTrue(alwaysNormalize)) {
1567 normalizationType = ALWAYS_NORMALIZE;
1568 }
1569 return _createElement(context, tag, data, children, normalizationType);
1570}
1571function _createElement(context, tag, data, children, normalizationType) {
1572 if (isDef(data) && isDef(data.__ob__)) {
1573 process.env.NODE_ENV !== 'production' &&
1574 warn$2(`Avoid using observed data object as vnode data: ${JSON.stringify(data)}\n` + 'Always create fresh vnode data objects in each render!', context);
1575 return createEmptyVNode();
1576 }
1577 // object syntax in v-bind
1578 if (isDef(data) && isDef(data.is)) {
1579 tag = data.is;
1580 }
1581 if (!tag) {
1582 // in case of component :is set to falsy value
1583 return createEmptyVNode();
1584 }
1585 // warn against non-primitive key
1586 if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.key) && !isPrimitive(data.key)) {
1587 warn$2('Avoid using non-primitive value as key, ' +
1588 'use string/number value instead.', context);
1589 }
1590 // support single function children as default scoped slot
1591 if (isArray(children) && isFunction(children[0])) {
1592 data = data || {};
1593 data.scopedSlots = { default: children[0] };
1594 children.length = 0;
1595 }
1596 if (normalizationType === ALWAYS_NORMALIZE) {
1597 children = normalizeChildren(children);
1598 }
1599 else if (normalizationType === SIMPLE_NORMALIZE) {
1600 children = simpleNormalizeChildren(children);
1601 }
1602 let vnode, ns;
1603 if (typeof tag === 'string') {
1604 let Ctor;
1605 ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
1606 if ((!data || !data.pre) &&
1607 isDef((Ctor = resolveAsset(context.$options, 'components', tag)))) {
1608 // component
1609 vnode = createComponent(Ctor, data, context, children, tag);
1610 }
1611 else {
1612 // unknown or unlisted namespaced elements
1613 // check at runtime because it may get assigned a namespace when its
1614 // parent normalizes children
1615 vnode = new VNode(tag, data, children, undefined, undefined, context);
1616 }
1617 }
1618 else {
1619 // direct component options / constructor
1620 vnode = createComponent(tag, data, context, children);
1621 }
1622 if (isArray(vnode)) {
1623 return vnode;
1624 }
1625 else if (isDef(vnode)) {
1626 if (isDef(ns))
1627 applyNS(vnode, ns);
1628 if (isDef(data))
1629 registerDeepBindings(data);
1630 return vnode;
1631 }
1632 else {
1633 return createEmptyVNode();
1634 }
1635}
1636function applyNS(vnode, ns, force) {
1637 vnode.ns = ns;
1638 if (vnode.tag === 'foreignObject') {
1639 // use default namespace inside foreignObject
1640 ns = undefined;
1641 force = true;
1642 }
1643 if (isDef(vnode.children)) {
1644 for (let i = 0, l = vnode.children.length; i < l; i++) {
1645 const child = vnode.children[i];
1646 if (isDef(child.tag) &&
1647 (isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
1648 applyNS(child, ns, force);
1649 }
1650 }
1651 }
1652}
1653// ref #5318
1654// necessary to ensure parent re-render when deep bindings like :style and
1655// :class are used on slot nodes
1656function registerDeepBindings(data) {
1657 if (isObject(data.style)) {
1658 traverse(data.style);
1659 }
1660 if (isObject(data.class)) {
1661 traverse(data.class);
1662 }
1663}
1664
1665/**
1666 * Runtime helper for rendering v-for lists.
1667 */
1668function renderList(val, render) {
1669 let ret = null, i, l, keys, key;
1670 if (isArray(val) || typeof val === 'string') {
1671 ret = new Array(val.length);
1672 for (i = 0, l = val.length; i < l; i++) {
1673 ret[i] = render(val[i], i);
1674 }
1675 }
1676 else if (typeof val === 'number') {
1677 ret = new Array(val);
1678 for (i = 0; i < val; i++) {
1679 ret[i] = render(i + 1, i);
1680 }
1681 }
1682 else if (isObject(val)) {
1683 if (hasSymbol && val[Symbol.iterator]) {
1684 ret = [];
1685 const iterator = val[Symbol.iterator]();
1686 let result = iterator.next();
1687 while (!result.done) {
1688 ret.push(render(result.value, ret.length));
1689 result = iterator.next();
1690 }
1691 }
1692 else {
1693 keys = Object.keys(val);
1694 ret = new Array(keys.length);
1695 for (i = 0, l = keys.length; i < l; i++) {
1696 key = keys[i];
1697 ret[i] = render(val[key], key, i);
1698 }
1699 }
1700 }
1701 if (!isDef(ret)) {
1702 ret = [];
1703 }
1704 ret._isVList = true;
1705 return ret;
1706}
1707
1708/**
1709 * Runtime helper for rendering <slot>
1710 */
1711function renderSlot(name, fallbackRender, props, bindObject) {
1712 const scopedSlotFn = this.$scopedSlots[name];
1713 let nodes;
1714 if (scopedSlotFn) {
1715 // scoped slot
1716 props = props || {};
1717 if (bindObject) {
1718 if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
1719 warn$2('slot v-bind without argument expects an Object', this);
1720 }
1721 props = extend(extend({}, bindObject), props);
1722 }
1723 nodes =
1724 scopedSlotFn(props) ||
1725 (isFunction(fallbackRender) ? fallbackRender() : fallbackRender);
1726 }
1727 else {
1728 nodes =
1729 this.$slots[name] ||
1730 (isFunction(fallbackRender) ? fallbackRender() : fallbackRender);
1731 }
1732 const target = props && props.slot;
1733 if (target) {
1734 return this.$createElement('template', { slot: target }, nodes);
1735 }
1736 else {
1737 return nodes;
1738 }
1739}
1740
1741/**
1742 * Runtime helper for resolving filters
1743 */
1744function resolveFilter(id) {
1745 return resolveAsset(this.$options, 'filters', id, true) || identity;
1746}
1747
1748function isKeyNotMatch(expect, actual) {
1749 if (isArray(expect)) {
1750 return expect.indexOf(actual) === -1;
1751 }
1752 else {
1753 return expect !== actual;
1754 }
1755}
1756/**
1757 * Runtime helper for checking keyCodes from config.
1758 * exposed as Vue.prototype._k
1759 * passing in eventKeyName as last argument separately for backwards compat
1760 */
1761function checkKeyCodes(eventKeyCode, key, builtInKeyCode, eventKeyName, builtInKeyName) {
1762 const mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
1763 if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
1764 return isKeyNotMatch(builtInKeyName, eventKeyName);
1765 }
1766 else if (mappedKeyCode) {
1767 return isKeyNotMatch(mappedKeyCode, eventKeyCode);
1768 }
1769 else if (eventKeyName) {
1770 return hyphenate(eventKeyName) !== key;
1771 }
1772 return eventKeyCode === undefined;
1773}
1774
1775/**
1776 * Runtime helper for merging v-bind="object" into a VNode's data.
1777 */
1778function bindObjectProps(data, tag, value, asProp, isSync) {
1779 if (value) {
1780 if (!isObject(value)) {
1781 process.env.NODE_ENV !== 'production' &&
1782 warn$2('v-bind without argument expects an Object or Array value', this);
1783 }
1784 else {
1785 if (isArray(value)) {
1786 value = toObject(value);
1787 }
1788 let hash;
1789 for (const key in value) {
1790 if (key === 'class' || key === 'style' || isReservedAttribute(key)) {
1791 hash = data;
1792 }
1793 else {
1794 const type = data.attrs && data.attrs.type;
1795 hash =
1796 asProp || config.mustUseProp(tag, type, key)
1797 ? data.domProps || (data.domProps = {})
1798 : data.attrs || (data.attrs = {});
1799 }
1800 const camelizedKey = camelize(key);
1801 const hyphenatedKey = hyphenate(key);
1802 if (!(camelizedKey in hash) && !(hyphenatedKey in hash)) {
1803 hash[key] = value[key];
1804 if (isSync) {
1805 const on = data.on || (data.on = {});
1806 on[`update:${key}`] = function ($event) {
1807 value[key] = $event;
1808 };
1809 }
1810 }
1811 }
1812 }
1813 }
1814 return data;
1815}
1816
1817/**
1818 * Runtime helper for rendering static trees.
1819 */
1820function renderStatic(index, isInFor) {
1821 const cached = this._staticTrees || (this._staticTrees = []);
1822 let tree = cached[index];
1823 // if has already-rendered static tree and not inside v-for,
1824 // we can reuse the same tree.
1825 if (tree && !isInFor) {
1826 return tree;
1827 }
1828 // otherwise, render a fresh tree.
1829 tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
1830 );
1831 markStatic$1(tree, `__static__${index}`, false);
1832 return tree;
1833}
1834/**
1835 * Runtime helper for v-once.
1836 * Effectively it means marking the node as static with a unique key.
1837 */
1838function markOnce(tree, index, key) {
1839 markStatic$1(tree, `__once__${index}${key ? `_${key}` : ``}`, true);
1840 return tree;
1841}
1842function markStatic$1(tree, key, isOnce) {
1843 if (isArray(tree)) {
1844 for (let i = 0; i < tree.length; i++) {
1845 if (tree[i] && typeof tree[i] !== 'string') {
1846 markStaticNode(tree[i], `${key}_${i}`, isOnce);
1847 }
1848 }
1849 }
1850 else {
1851 markStaticNode(tree, key, isOnce);
1852 }
1853}
1854function markStaticNode(node, key, isOnce) {
1855 node.isStatic = true;
1856 node.key = key;
1857 node.isOnce = isOnce;
1858}
1859
1860function bindObjectListeners(data, value) {
1861 if (value) {
1862 if (!isPlainObject(value)) {
1863 process.env.NODE_ENV !== 'production' && warn$2('v-on without argument expects an Object value', this);
1864 }
1865 else {
1866 const on = (data.on = data.on ? extend({}, data.on) : {});
1867 for (const key in value) {
1868 const existing = on[key];
1869 const ours = value[key];
1870 on[key] = existing ? [].concat(existing, ours) : ours;
1871 }
1872 }
1873 }
1874 return data;
1875}
1876
1877function resolveScopedSlots(fns, res,
1878// the following are added in 2.6
1879hasDynamicKeys, contentHashKey) {
1880 res = res || { $stable: !hasDynamicKeys };
1881 for (let i = 0; i < fns.length; i++) {
1882 const slot = fns[i];
1883 if (isArray(slot)) {
1884 resolveScopedSlots(slot, res, hasDynamicKeys);
1885 }
1886 else if (slot) {
1887 // marker for reverse proxying v-slot without scope on this.$slots
1888 // @ts-expect-error
1889 if (slot.proxy) {
1890 // @ts-expect-error
1891 slot.fn.proxy = true;
1892 }
1893 res[slot.key] = slot.fn;
1894 }
1895 }
1896 if (contentHashKey) {
1897 res.$key = contentHashKey;
1898 }
1899 return res;
1900}
1901
1902// helper to process dynamic keys for dynamic arguments in v-bind and v-on.
1903function bindDynamicKeys(baseObj, values) {
1904 for (let i = 0; i < values.length; i += 2) {
1905 const key = values[i];
1906 if (typeof key === 'string' && key) {
1907 baseObj[values[i]] = values[i + 1];
1908 }
1909 else if (process.env.NODE_ENV !== 'production' && key !== '' && key !== null) {
1910 // null is a special value for explicitly removing a binding
1911 warn$2(`Invalid value for dynamic directive argument (expected string or null): ${key}`, this);
1912 }
1913 }
1914 return baseObj;
1915}
1916// helper to dynamically append modifier runtime markers to event names.
1917// ensure only append when value is already string, otherwise it will be cast
1918// to string and cause the type check to miss.
1919function prependModifier(value, symbol) {
1920 return typeof value === 'string' ? symbol + value : value;
1921}
1922
1923function installRenderHelpers(target) {
1924 target._o = markOnce;
1925 target._n = toNumber;
1926 target._s = toString;
1927 target._l = renderList;
1928 target._t = renderSlot;
1929 target._q = looseEqual;
1930 target._i = looseIndexOf;
1931 target._m = renderStatic;
1932 target._f = resolveFilter;
1933 target._k = checkKeyCodes;
1934 target._b = bindObjectProps;
1935 target._v = createTextVNode;
1936 target._e = createEmptyVNode;
1937 target._u = resolveScopedSlots;
1938 target._g = bindObjectListeners;
1939 target._d = bindDynamicKeys;
1940 target._p = prependModifier;
1941}
1942
1943/**
1944 * Runtime helper for resolving raw children VNodes into a slot object.
1945 */
1946function resolveSlots(children, context) {
1947 if (!children || !children.length) {
1948 return {};
1949 }
1950 const slots = {};
1951 for (let i = 0, l = children.length; i < l; i++) {
1952 const child = children[i];
1953 const data = child.data;
1954 // remove slot attribute if the node is resolved as a Vue slot node
1955 if (data && data.attrs && data.attrs.slot) {
1956 delete data.attrs.slot;
1957 }
1958 // named slots should only be respected if the vnode was rendered in the
1959 // same context.
1960 if ((child.context === context || child.fnContext === context) &&
1961 data &&
1962 data.slot != null) {
1963 const name = data.slot;
1964 const slot = slots[name] || (slots[name] = []);
1965 if (child.tag === 'template') {
1966 slot.push.apply(slot, child.children || []);
1967 }
1968 else {
1969 slot.push(child);
1970 }
1971 }
1972 else {
1973 (slots.default || (slots.default = [])).push(child);
1974 }
1975 }
1976 // ignore slots that contains only whitespace
1977 for (const name in slots) {
1978 if (slots[name].every(isWhitespace)) {
1979 delete slots[name];
1980 }
1981 }
1982 return slots;
1983}
1984function isWhitespace(node) {
1985 return (node.isComment && !node.asyncFactory) || node.text === ' ';
1986}
1987
1988function isAsyncPlaceholder(node) {
1989 // @ts-expect-error not really boolean type
1990 return node.isComment && node.asyncFactory;
1991}
1992
1993function normalizeScopedSlots(ownerVm, scopedSlots, normalSlots, prevScopedSlots) {
1994 let res;
1995 const hasNormalSlots = Object.keys(normalSlots).length > 0;
1996 const isStable = scopedSlots ? !!scopedSlots.$stable : !hasNormalSlots;
1997 const key = scopedSlots && scopedSlots.$key;
1998 if (!scopedSlots) {
1999 res = {};
2000 }
2001 else if (scopedSlots._normalized) {
2002 // fast path 1: child component re-render only, parent did not change
2003 return scopedSlots._normalized;
2004 }
2005 else if (isStable &&
2006 prevScopedSlots &&
2007 prevScopedSlots !== emptyObject &&
2008 key === prevScopedSlots.$key &&
2009 !hasNormalSlots &&
2010 !prevScopedSlots.$hasNormal) {
2011 // fast path 2: stable scoped slots w/ no normal slots to proxy,
2012 // only need to normalize once
2013 return prevScopedSlots;
2014 }
2015 else {
2016 res = {};
2017 for (const key in scopedSlots) {
2018 if (scopedSlots[key] && key[0] !== '$') {
2019 res[key] = normalizeScopedSlot(ownerVm, normalSlots, key, scopedSlots[key]);
2020 }
2021 }
2022 }
2023 // expose normal slots on scopedSlots
2024 for (const key in normalSlots) {
2025 if (!(key in res)) {
2026 res[key] = proxyNormalSlot(normalSlots, key);
2027 }
2028 }
2029 // avoriaz seems to mock a non-extensible $scopedSlots object
2030 // and when that is passed down this would cause an error
2031 if (scopedSlots && Object.isExtensible(scopedSlots)) {
2032 scopedSlots._normalized = res;
2033 }
2034 def(res, '$stable', isStable);
2035 def(res, '$key', key);
2036 def(res, '$hasNormal', hasNormalSlots);
2037 return res;
2038}
2039function normalizeScopedSlot(vm, normalSlots, key, fn) {
2040 const normalized = function () {
2041 const cur = currentInstance;
2042 setCurrentInstance(vm);
2043 let res = arguments.length ? fn.apply(null, arguments) : fn({});
2044 res =
2045 res && typeof res === 'object' && !isArray(res)
2046 ? [res] // single vnode
2047 : normalizeChildren(res);
2048 const vnode = res && res[0];
2049 setCurrentInstance(cur);
2050 return res &&
2051 (!vnode ||
2052 (res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
2053 ? undefined
2054 : res;
2055 };
2056 // this is a slot using the new v-slot syntax without scope. although it is
2057 // compiled as a scoped slot, render fn users would expect it to be present
2058 // on this.$slots because the usage is semantically a normal slot.
2059 if (fn.proxy) {
2060 Object.defineProperty(normalSlots, key, {
2061 get: normalized,
2062 enumerable: true,
2063 configurable: true
2064 });
2065 }
2066 return normalized;
2067}
2068function proxyNormalSlot(slots, key) {
2069 return () => slots[key];
2070}
2071
2072function syncSetupProxy(to, from, prev, instance, type) {
2073 let changed = false;
2074 for (const key in from) {
2075 if (!(key in to)) {
2076 changed = true;
2077 defineProxyAttr(to, key, instance, type);
2078 }
2079 else if (from[key] !== prev[key]) {
2080 changed = true;
2081 }
2082 }
2083 for (const key in to) {
2084 if (!(key in from)) {
2085 changed = true;
2086 delete to[key];
2087 }
2088 }
2089 return changed;
2090}
2091function defineProxyAttr(proxy, key, instance, type) {
2092 Object.defineProperty(proxy, key, {
2093 enumerable: true,
2094 configurable: true,
2095 get() {
2096 return instance[type][key];
2097 }
2098 });
2099}
2100
2101function createAsyncPlaceholder(factory, data, context, children, tag) {
2102 const node = createEmptyVNode();
2103 node.asyncFactory = factory;
2104 node.asyncMeta = { data, context, children, tag };
2105 return node;
2106}
2107function resolveAsyncComponent(factory, baseCtor) {
2108 if (isTrue(factory.error) && isDef(factory.errorComp)) {
2109 return factory.errorComp;
2110 }
2111 if (isDef(factory.resolved)) {
2112 return factory.resolved;
2113 }
2114 if (isTrue(factory.loading) && isDef(factory.loadingComp)) {
2115 return factory.loadingComp;
2116 }
2117}
2118
2119let target;
2120function add(event, fn) {
2121 target.$on(event, fn);
2122}
2123function remove(event, fn) {
2124 target.$off(event, fn);
2125}
2126function createOnceHandler(event, fn) {
2127 const _target = target;
2128 return function onceHandler() {
2129 const res = fn.apply(null, arguments);
2130 if (res !== null) {
2131 _target.$off(event, onceHandler);
2132 }
2133 };
2134}
2135function updateComponentListeners(vm, listeners, oldListeners) {
2136 target = vm;
2137 updateListeners(listeners, oldListeners || {}, add, remove, createOnceHandler, vm);
2138 target = undefined;
2139}
2140
2141let activeInstance = null;
2142function updateChildComponent(vm, propsData, listeners, parentVnode, renderChildren) {
2143 if (process.env.NODE_ENV !== 'production') ;
2144 // determine whether component has slot children
2145 // we need to do this before overwriting $options._renderChildren.
2146 // check if there are dynamic scopedSlots (hand-written or compiled but with
2147 // dynamic slot names). Static scoped slots compiled from template has the
2148 // "$stable" marker.
2149 const newScopedSlots = parentVnode.data.scopedSlots;
2150 const oldScopedSlots = vm.$scopedSlots;
2151 const hasDynamicScopedSlot = !!((newScopedSlots && !newScopedSlots.$stable) ||
2152 (oldScopedSlots !== emptyObject && !oldScopedSlots.$stable) ||
2153 (newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key) ||
2154 (!newScopedSlots && vm.$scopedSlots.$key));
2155 // Any static slot children from the parent may have changed during parent's
2156 // update. Dynamic scoped slots may also have changed. In such cases, a forced
2157 // update is necessary to ensure correctness.
2158 let needsForceUpdate = !!(renderChildren || // has new static slots
2159 vm.$options._renderChildren || // has old static slots
2160 hasDynamicScopedSlot);
2161 const prevVNode = vm.$vnode;
2162 vm.$options._parentVnode = parentVnode;
2163 vm.$vnode = parentVnode; // update vm's placeholder node without re-render
2164 if (vm._vnode) {
2165 // update child tree's parent
2166 vm._vnode.parent = parentVnode;
2167 }
2168 vm.$options._renderChildren = renderChildren;
2169 // update $attrs and $listeners hash
2170 // these are also reactive so they may trigger child update if the child
2171 // used them during render
2172 const attrs = parentVnode.data.attrs || emptyObject;
2173 if (vm._attrsProxy) {
2174 // force update if attrs are accessed and has changed since it may be
2175 // passed to a child component.
2176 if (syncSetupProxy(vm._attrsProxy, attrs, (prevVNode.data && prevVNode.data.attrs) || emptyObject, vm, '$attrs')) {
2177 needsForceUpdate = true;
2178 }
2179 }
2180 vm.$attrs = attrs;
2181 // update listeners
2182 listeners = listeners || emptyObject;
2183 const prevListeners = vm.$options._parentListeners;
2184 if (vm._listenersProxy) {
2185 syncSetupProxy(vm._listenersProxy, listeners, prevListeners || emptyObject, vm, '$listeners');
2186 }
2187 vm.$listeners = vm.$options._parentListeners = listeners;
2188 updateComponentListeners(vm, listeners, prevListeners);
2189 // update props
2190 if (propsData && vm.$options.props) {
2191 toggleObserving(false);
2192 const props = vm._props;
2193 const propKeys = vm.$options._propKeys || [];
2194 for (let i = 0; i < propKeys.length; i++) {
2195 const key = propKeys[i];
2196 const propOptions = vm.$options.props; // wtf flow?
2197 props[key] = validateProp(key, propOptions, propsData, vm);
2198 }
2199 toggleObserving(true);
2200 // keep a copy of raw propsData
2201 vm.$options.propsData = propsData;
2202 }
2203 // resolve slots + force update if has children
2204 if (needsForceUpdate) {
2205 vm.$slots = resolveSlots(renderChildren, parentVnode.context);
2206 vm.$forceUpdate();
2207 }
2208 if (process.env.NODE_ENV !== 'production') ;
2209}
2210function isInInactiveTree(vm) {
2211 while (vm && (vm = vm.$parent)) {
2212 if (vm._inactive)
2213 return true;
2214 }
2215 return false;
2216}
2217function activateChildComponent(vm, direct) {
2218 if (direct) {
2219 vm._directInactive = false;
2220 if (isInInactiveTree(vm)) {
2221 return;
2222 }
2223 }
2224 else if (vm._directInactive) {
2225 return;
2226 }
2227 if (vm._inactive || vm._inactive === null) {
2228 vm._inactive = false;
2229 for (let i = 0; i < vm.$children.length; i++) {
2230 activateChildComponent(vm.$children[i]);
2231 }
2232 callHook(vm, 'activated');
2233 }
2234}
2235function deactivateChildComponent(vm, direct) {
2236 if (direct) {
2237 vm._directInactive = true;
2238 if (isInInactiveTree(vm)) {
2239 return;
2240 }
2241 }
2242 if (!vm._inactive) {
2243 vm._inactive = true;
2244 for (let i = 0; i < vm.$children.length; i++) {
2245 deactivateChildComponent(vm.$children[i]);
2246 }
2247 callHook(vm, 'deactivated');
2248 }
2249}
2250function callHook(vm, hook, args, setContext = true) {
2251 // #7573 disable dep collection when invoking lifecycle hooks
2252 pushTarget();
2253 const prevInst = currentInstance;
2254 setContext && setCurrentInstance(vm);
2255 const handlers = vm.$options[hook];
2256 const info = `${hook} hook`;
2257 if (handlers) {
2258 for (let i = 0, j = handlers.length; i < j; i++) {
2259 invokeWithErrorHandling(handlers[i], vm, args || null, vm, info);
2260 }
2261 }
2262 if (vm._hasHookEvent) {
2263 vm.$emit('hook:' + hook);
2264 }
2265 if (setContext) {
2266 setCurrentInstance(prevInst);
2267 }
2268 popTarget();
2269}
2270
2271// Async edge case fix requires storing an event listener's attach timestamp.
2272let getNow = Date.now;
2273// Determine what event timestamp the browser is using. Annoyingly, the
2274// timestamp can either be hi-res (relative to page load) or low-res
2275// (relative to UNIX epoch), so in order to compare time we have to use the
2276// same timestamp type when saving the flush timestamp.
2277// All IE versions use low-res event timestamps, and have problematic clock
2278// implementations (#9632)
2279if (inBrowser && !isIE) {
2280 const performance = window.performance;
2281 if (performance &&
2282 typeof performance.now === 'function' &&
2283 getNow() > document.createEvent('Event').timeStamp) {
2284 // if the event timestamp, although evaluated AFTER the Date.now(), is
2285 // smaller than it, it means the event is using a hi-res timestamp,
2286 // and we need to use the hi-res version for event listener timestamps as
2287 // well.
2288 getNow = () => performance.now();
2289 }
2290}
2291/**
2292 * Queue a kept-alive component that was activated during patch.
2293 * The queue will be processed after the entire tree has been patched.
2294 */
2295function queueActivatedComponent(vm) {
2296 // setting _inactive to false here so that a render function can
2297 // rely on checking whether it's in an inactive tree (e.g. router-view)
2298 vm._inactive = false;
2299}
2300
2301function handleError(err, vm, info) {
2302 // Deactivate deps tracking while processing error handler to avoid possible infinite rendering.
2303 // See: https://github.com/vuejs/vuex/issues/1505
2304 pushTarget();
2305 try {
2306 if (vm) {
2307 let cur = vm;
2308 while ((cur = cur.$parent)) {
2309 const hooks = cur.$options.errorCaptured;
2310 if (hooks) {
2311 for (let i = 0; i < hooks.length; i++) {
2312 try {
2313 const capture = hooks[i].call(cur, err, vm, info) === false;
2314 if (capture)
2315 return;
2316 }
2317 catch (e) {
2318 globalHandleError(e, cur, 'errorCaptured hook');
2319 }
2320 }
2321 }
2322 }
2323 }
2324 globalHandleError(err, vm, info);
2325 }
2326 finally {
2327 popTarget();
2328 }
2329}
2330function invokeWithErrorHandling(handler, context, args, vm, info) {
2331 let res;
2332 try {
2333 res = args ? handler.apply(context, args) : handler.call(context);
2334 if (res && !res._isVue && isPromise(res) && !res._handled) {
2335 res.catch(e => handleError(e, vm, info + ` (Promise/async)`));
2336 res._handled = true;
2337 }
2338 }
2339 catch (e) {
2340 handleError(e, vm, info);
2341 }
2342 return res;
2343}
2344function globalHandleError(err, vm, info) {
2345 logError(err, vm, info);
2346}
2347function logError(err, vm, info) {
2348 if (process.env.NODE_ENV !== 'production') {
2349 warn$2(`Error in ${info}: "${err.toString()}"`, vm);
2350 }
2351 /* istanbul ignore else */
2352 if (inBrowser && typeof console !== 'undefined') {
2353 console.error(err);
2354 }
2355 else {
2356 throw err;
2357 }
2358}
2359
2360/* globals MutationObserver */
2361const callbacks = [];
2362function flushCallbacks() {
2363 const copies = callbacks.slice(0);
2364 callbacks.length = 0;
2365 for (let i = 0; i < copies.length; i++) {
2366 copies[i]();
2367 }
2368}
2369// The nextTick behavior leverages the microtask queue, which can be accessed
2370// via either native Promise.then or MutationObserver.
2371// MutationObserver has wider support, however it is seriously bugged in
2372// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
2373// completely stops working after triggering a few times... so, if native
2374// Promise is available, we will use it:
2375/* istanbul ignore next, $flow-disable-line */
2376if (typeof Promise !== 'undefined' && isNative(Promise)) {
2377 Promise.resolve();
2378}
2379else if (!isIE &&
2380 typeof MutationObserver !== 'undefined' &&
2381 (isNative(MutationObserver) ||
2382 // PhantomJS and iOS 7.x
2383 MutationObserver.toString() === '[object MutationObserverConstructor]')) {
2384 // Use MutationObserver where native Promise is not available,
2385 // e.g. PhantomJS, iOS7, Android 4.4
2386 // (#6466 MutationObserver is unreliable in IE11)
2387 let counter = 1;
2388 const observer = new MutationObserver(flushCallbacks);
2389 const textNode = document.createTextNode(String(counter));
2390 observer.observe(textNode, {
2391 characterData: true
2392 });
2393}
2394else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) ;
2395else ;
2396
2397const seenObjects = new _Set();
2398/**
2399 * Recursively traverse an object to evoke all converted
2400 * getters, so that every nested property inside the object
2401 * is collected as a "deep" dependency.
2402 */
2403function traverse(val) {
2404 _traverse(val, seenObjects);
2405 seenObjects.clear();
2406 return val;
2407}
2408function _traverse(val, seen) {
2409 let i, keys;
2410 const isA = isArray(val);
2411 if ((!isA && !isObject(val)) ||
2412 val.__v_skip /* ReactiveFlags.SKIP */ ||
2413 Object.isFrozen(val) ||
2414 val instanceof VNode) {
2415 return;
2416 }
2417 if (val.__ob__) {
2418 const depId = val.__ob__.dep.id;
2419 if (seen.has(depId)) {
2420 return;
2421 }
2422 seen.add(depId);
2423 }
2424 if (isA) {
2425 i = val.length;
2426 while (i--)
2427 _traverse(val[i], seen);
2428 }
2429 else if (isRef(val)) {
2430 _traverse(val.value, seen);
2431 }
2432 else {
2433 keys = Object.keys(val);
2434 i = keys.length;
2435 while (i--)
2436 _traverse(val[keys[i]], seen);
2437 }
2438}
2439
2440function resolveInject(inject, vm) {
2441 if (inject) {
2442 // inject is :any because flow is not smart enough to figure out cached
2443 const result = Object.create(null);
2444 const keys = hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject);
2445 for (let i = 0; i < keys.length; i++) {
2446 const key = keys[i];
2447 // #6574 in case the inject object is observed...
2448 if (key === '__ob__')
2449 continue;
2450 const provideKey = inject[key].from;
2451 if (provideKey in vm._provided) {
2452 result[key] = vm._provided[provideKey];
2453 }
2454 else if ('default' in inject[key]) {
2455 const provideDefault = inject[key].default;
2456 result[key] = isFunction(provideDefault)
2457 ? provideDefault.call(vm)
2458 : provideDefault;
2459 }
2460 else if (process.env.NODE_ENV !== 'production') {
2461 warn$2(`Injection "${key}" not found`, vm);
2462 }
2463 }
2464 return result;
2465 }
2466}
2467
2468function resolveConstructorOptions(Ctor) {
2469 let options = Ctor.options;
2470 if (Ctor.super) {
2471 const superOptions = resolveConstructorOptions(Ctor.super);
2472 const cachedSuperOptions = Ctor.superOptions;
2473 if (superOptions !== cachedSuperOptions) {
2474 // super option changed,
2475 // need to resolve new options.
2476 Ctor.superOptions = superOptions;
2477 // check if there are any late-modified/attached options (#4976)
2478 const modifiedOptions = resolveModifiedOptions(Ctor);
2479 // update base extend options
2480 if (modifiedOptions) {
2481 extend(Ctor.extendOptions, modifiedOptions);
2482 }
2483 options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);
2484 if (options.name) {
2485 options.components[options.name] = Ctor;
2486 }
2487 }
2488 }
2489 return options;
2490}
2491function resolveModifiedOptions(Ctor) {
2492 let modified;
2493 const latest = Ctor.options;
2494 const sealed = Ctor.sealedOptions;
2495 for (const key in latest) {
2496 if (latest[key] !== sealed[key]) {
2497 if (!modified)
2498 modified = {};
2499 modified[key] = latest[key];
2500 }
2501 }
2502 return modified;
2503}
2504
2505function FunctionalRenderContext(data, props, children, parent, Ctor) {
2506 const options = Ctor.options;
2507 // ensure the createElement function in functional components
2508 // gets a unique context - this is necessary for correct named slot check
2509 let contextVm;
2510 if (hasOwn(parent, '_uid')) {
2511 contextVm = Object.create(parent);
2512 contextVm._original = parent;
2513 }
2514 else {
2515 // the context vm passed in is a functional context as well.
2516 // in this case we want to make sure we are able to get a hold to the
2517 // real context instance.
2518 contextVm = parent;
2519 // @ts-ignore
2520 parent = parent._original;
2521 }
2522 const isCompiled = isTrue(options._compiled);
2523 const needNormalization = !isCompiled;
2524 this.data = data;
2525 this.props = props;
2526 this.children = children;
2527 this.parent = parent;
2528 this.listeners = data.on || emptyObject;
2529 this.injections = resolveInject(options.inject, parent);
2530 this.slots = () => {
2531 if (!this.$slots) {
2532 normalizeScopedSlots(parent, data.scopedSlots, (this.$slots = resolveSlots(children, parent)));
2533 }
2534 return this.$slots;
2535 };
2536 Object.defineProperty(this, 'scopedSlots', {
2537 enumerable: true,
2538 get() {
2539 return normalizeScopedSlots(parent, data.scopedSlots, this.slots());
2540 }
2541 });
2542 // support for compiled functional template
2543 if (isCompiled) {
2544 // exposing $options for renderStatic()
2545 this.$options = options;
2546 // pre-resolve slots for renderSlot()
2547 this.$slots = this.slots();
2548 this.$scopedSlots = normalizeScopedSlots(parent, data.scopedSlots, this.$slots);
2549 }
2550 if (options._scopeId) {
2551 this._c = (a, b, c, d) => {
2552 const vnode = createElement(contextVm, a, b, c, d, needNormalization);
2553 if (vnode && !isArray(vnode)) {
2554 vnode.fnScopeId = options._scopeId;
2555 vnode.fnContext = parent;
2556 }
2557 return vnode;
2558 };
2559 }
2560 else {
2561 this._c = (a, b, c, d) => createElement(contextVm, a, b, c, d, needNormalization);
2562 }
2563}
2564installRenderHelpers(FunctionalRenderContext.prototype);
2565function createFunctionalComponent(Ctor, propsData, data, contextVm, children) {
2566 const options = Ctor.options;
2567 const props = {};
2568 const propOptions = options.props;
2569 if (isDef(propOptions)) {
2570 for (const key in propOptions) {
2571 props[key] = validateProp(key, propOptions, propsData || emptyObject);
2572 }
2573 }
2574 else {
2575 if (isDef(data.attrs))
2576 mergeProps(props, data.attrs);
2577 if (isDef(data.props))
2578 mergeProps(props, data.props);
2579 }
2580 const renderContext = new FunctionalRenderContext(data, props, children, contextVm, Ctor);
2581 const vnode = options.render.call(null, renderContext._c, renderContext);
2582 if (vnode instanceof VNode) {
2583 return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext);
2584 }
2585 else if (isArray(vnode)) {
2586 const vnodes = normalizeChildren(vnode) || [];
2587 const res = new Array(vnodes.length);
2588 for (let i = 0; i < vnodes.length; i++) {
2589 res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
2590 }
2591 return res;
2592 }
2593}
2594function cloneAndMarkFunctionalResult(vnode, data, contextVm, options, renderContext) {
2595 // #7817 clone node before setting fnContext, otherwise if the node is reused
2596 // (e.g. it was from a cached normal slot) the fnContext causes named slots
2597 // that should not be matched to match.
2598 const clone = cloneVNode(vnode);
2599 clone.fnContext = contextVm;
2600 clone.fnOptions = options;
2601 if (process.env.NODE_ENV !== 'production') {
2602 (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext =
2603 renderContext;
2604 }
2605 if (data.slot) {
2606 (clone.data || (clone.data = {})).slot = data.slot;
2607 }
2608 return clone;
2609}
2610function mergeProps(to, from) {
2611 for (const key in from) {
2612 to[camelize(key)] = from[key];
2613 }
2614}
2615
2616function getComponentName(options) {
2617 return options.name || options.__name || options._componentTag;
2618}
2619// inline hooks to be invoked on component VNodes during patch
2620const componentVNodeHooks = {
2621 init(vnode, hydrating) {
2622 if (vnode.componentInstance &&
2623 !vnode.componentInstance._isDestroyed &&
2624 vnode.data.keepAlive) {
2625 // kept-alive components, treat as a patch
2626 const mountedNode = vnode; // work around flow
2627 componentVNodeHooks.prepatch(mountedNode, mountedNode);
2628 }
2629 else {
2630 const child = (vnode.componentInstance = createComponentInstanceForVnode(vnode, activeInstance));
2631 child.$mount(hydrating ? vnode.elm : undefined, hydrating);
2632 }
2633 },
2634 prepatch(oldVnode, vnode) {
2635 const options = vnode.componentOptions;
2636 const child = (vnode.componentInstance = oldVnode.componentInstance);
2637 updateChildComponent(child, options.propsData, // updated props
2638 options.listeners, // updated listeners
2639 vnode, // new parent vnode
2640 options.children // new children
2641 );
2642 },
2643 insert(vnode) {
2644 const { context, componentInstance } = vnode;
2645 if (!componentInstance._isMounted) {
2646 componentInstance._isMounted = true;
2647 callHook(componentInstance, 'mounted');
2648 }
2649 if (vnode.data.keepAlive) {
2650 if (context._isMounted) {
2651 // vue-router#1212
2652 // During updates, a kept-alive component's child components may
2653 // change, so directly walking the tree here may call activated hooks
2654 // on incorrect children. Instead we push them into a queue which will
2655 // be processed after the whole patch process ended.
2656 queueActivatedComponent(componentInstance);
2657 }
2658 else {
2659 activateChildComponent(componentInstance, true /* direct */);
2660 }
2661 }
2662 },
2663 destroy(vnode) {
2664 const { componentInstance } = vnode;
2665 if (!componentInstance._isDestroyed) {
2666 if (!vnode.data.keepAlive) {
2667 componentInstance.$destroy();
2668 }
2669 else {
2670 deactivateChildComponent(componentInstance, true /* direct */);
2671 }
2672 }
2673 }
2674};
2675const hooksToMerge = Object.keys(componentVNodeHooks);
2676function createComponent(Ctor, data, context, children, tag) {
2677 if (isUndef(Ctor)) {
2678 return;
2679 }
2680 const baseCtor = context.$options._base;
2681 // plain options object: turn it into a constructor
2682 if (isObject(Ctor)) {
2683 Ctor = baseCtor.extend(Ctor);
2684 }
2685 // if at this stage it's not a constructor or an async component factory,
2686 // reject.
2687 if (typeof Ctor !== 'function') {
2688 if (process.env.NODE_ENV !== 'production') {
2689 warn$2(`Invalid Component definition: ${String(Ctor)}`, context);
2690 }
2691 return;
2692 }
2693 // async component
2694 let asyncFactory;
2695 // @ts-expect-error
2696 if (isUndef(Ctor.cid)) {
2697 asyncFactory = Ctor;
2698 Ctor = resolveAsyncComponent(asyncFactory);
2699 if (Ctor === undefined) {
2700 // return a placeholder node for async component, which is rendered
2701 // as a comment node but preserves all the raw information for the node.
2702 // the information will be used for async server-rendering and hydration.
2703 return createAsyncPlaceholder(asyncFactory, data, context, children, tag);
2704 }
2705 }
2706 data = data || {};
2707 // resolve constructor options in case global mixins are applied after
2708 // component constructor creation
2709 resolveConstructorOptions(Ctor);
2710 // transform component v-model data into props & events
2711 if (isDef(data.model)) {
2712 // @ts-expect-error
2713 transformModel(Ctor.options, data);
2714 }
2715 // extract props
2716 // @ts-expect-error
2717 const propsData = extractPropsFromVNodeData(data, Ctor, tag);
2718 // functional component
2719 // @ts-expect-error
2720 if (isTrue(Ctor.options.functional)) {
2721 return createFunctionalComponent(Ctor, propsData, data, context, children);
2722 }
2723 // extract listeners, since these needs to be treated as
2724 // child component listeners instead of DOM listeners
2725 const listeners = data.on;
2726 // replace with listeners with .native modifier
2727 // so it gets processed during parent component patch.
2728 data.on = data.nativeOn;
2729 // @ts-expect-error
2730 if (isTrue(Ctor.options.abstract)) {
2731 // abstract components do not keep anything
2732 // other than props & listeners & slot
2733 // work around flow
2734 const slot = data.slot;
2735 data = {};
2736 if (slot) {
2737 data.slot = slot;
2738 }
2739 }
2740 // install component management hooks onto the placeholder node
2741 installComponentHooks(data);
2742 // return a placeholder vnode
2743 // @ts-expect-error
2744 const name = getComponentName(Ctor.options) || tag;
2745 const vnode = new VNode(
2746 // @ts-expect-error
2747 `vue-component-${Ctor.cid}${name ? `-${name}` : ''}`, data, undefined, undefined, undefined, context,
2748 // @ts-expect-error
2749 { Ctor, propsData, listeners, tag, children }, asyncFactory);
2750 return vnode;
2751}
2752function createComponentInstanceForVnode(
2753// we know it's MountedComponentVNode but flow doesn't
2754vnode,
2755// activeInstance in lifecycle state
2756parent) {
2757 const options = {
2758 _isComponent: true,
2759 _parentVnode: vnode,
2760 parent
2761 };
2762 // check inline-template render functions
2763 const inlineTemplate = vnode.data.inlineTemplate;
2764 if (isDef(inlineTemplate)) {
2765 options.render = inlineTemplate.render;
2766 options.staticRenderFns = inlineTemplate.staticRenderFns;
2767 }
2768 return new vnode.componentOptions.Ctor(options);
2769}
2770function installComponentHooks(data) {
2771 const hooks = data.hook || (data.hook = {});
2772 for (let i = 0; i < hooksToMerge.length; i++) {
2773 const key = hooksToMerge[i];
2774 const existing = hooks[key];
2775 const toMerge = componentVNodeHooks[key];
2776 // @ts-expect-error
2777 if (existing !== toMerge && !(existing && existing._merged)) {
2778 hooks[key] = existing ? mergeHook(toMerge, existing) : toMerge;
2779 }
2780 }
2781}
2782function mergeHook(f1, f2) {
2783 const merged = (a, b) => {
2784 // flow complains about extra args which is why we use any
2785 f1(a, b);
2786 f2(a, b);
2787 };
2788 merged._merged = true;
2789 return merged;
2790}
2791// transform component v-model info (value and callback) into
2792// prop and event handler respectively.
2793function transformModel(options, data) {
2794 const prop = (options.model && options.model.prop) || 'value';
2795 const event = (options.model && options.model.event) || 'input';
2796 (data.attrs || (data.attrs = {}))[prop] = data.model.value;
2797 const on = data.on || (data.on = {});
2798 const existing = on[event];
2799 const callback = data.model.callback;
2800 if (isDef(existing)) {
2801 if (isArray(existing)
2802 ? existing.indexOf(callback) === -1
2803 : existing !== callback) {
2804 on[event] = [callback].concat(existing);
2805 }
2806 }
2807 else {
2808 on[event] = callback;
2809 }
2810}
2811
2812let warn$2 = noop;
2813let tip = noop;
2814let generateComponentTrace; // work around flow check
2815let formatComponentName;
2816if (process.env.NODE_ENV !== 'production') {
2817 const hasConsole = typeof console !== 'undefined';
2818 const classifyRE = /(?:^|[-_])(\w)/g;
2819 const classify = str => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
2820 warn$2 = (msg, vm = currentInstance) => {
2821 const trace = vm ? generateComponentTrace(vm) : '';
2822 if (hasConsole && !config.silent) {
2823 console.error(`[Vue warn]: ${msg}${trace}`);
2824 }
2825 };
2826 tip = (msg, vm) => {
2827 if (hasConsole && !config.silent) {
2828 console.warn(`[Vue tip]: ${msg}` + (vm ? generateComponentTrace(vm) : ''));
2829 }
2830 };
2831 formatComponentName = (vm, includeFile) => {
2832 if (vm.$root === vm) {
2833 return '<Root>';
2834 }
2835 const options = isFunction(vm) && vm.cid != null
2836 ? vm.options
2837 : vm._isVue
2838 ? vm.$options || vm.constructor.options
2839 : vm;
2840 let name = getComponentName(options);
2841 const file = options.__file;
2842 if (!name && file) {
2843 const match = file.match(/([^/\\]+)\.vue$/);
2844 name = match && match[1];
2845 }
2846 return ((name ? `<${classify(name)}>` : `<Anonymous>`) +
2847 (file && includeFile !== false ? ` at ${file}` : ''));
2848 };
2849 const repeat = (str, n) => {
2850 let res = '';
2851 while (n) {
2852 if (n % 2 === 1)
2853 res += str;
2854 if (n > 1)
2855 str += str;
2856 n >>= 1;
2857 }
2858 return res;
2859 };
2860 generateComponentTrace = (vm) => {
2861 if (vm._isVue && vm.$parent) {
2862 const tree = [];
2863 let currentRecursiveSequence = 0;
2864 while (vm) {
2865 if (tree.length > 0) {
2866 const last = tree[tree.length - 1];
2867 if (last.constructor === vm.constructor) {
2868 currentRecursiveSequence++;
2869 vm = vm.$parent;
2870 continue;
2871 }
2872 else if (currentRecursiveSequence > 0) {
2873 tree[tree.length - 1] = [last, currentRecursiveSequence];
2874 currentRecursiveSequence = 0;
2875 }
2876 }
2877 tree.push(vm);
2878 vm = vm.$parent;
2879 }
2880 return ('\n\nfound in\n\n' +
2881 tree
2882 .map((vm, i) => `${i === 0 ? '---> ' : repeat(' ', 5 + i * 2)}${isArray(vm)
2883 ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)`
2884 : formatComponentName(vm)}`)
2885 .join('\n'));
2886 }
2887 else {
2888 return `\n\n(found in ${formatComponentName(vm)})`;
2889 }
2890 };
2891}
2892
2893/**
2894 * Option overwriting strategies are functions that handle
2895 * how to merge a parent option value and a child option
2896 * value into the final value.
2897 */
2898const strats = config.optionMergeStrategies;
2899/**
2900 * Options with restrictions
2901 */
2902if (process.env.NODE_ENV !== 'production') {
2903 strats.el = strats.propsData = function (parent, child, vm, key) {
2904 if (!vm) {
2905 warn$2(`option "${key}" can only be used during instance ` +
2906 'creation with the `new` keyword.');
2907 }
2908 return defaultStrat(parent, child);
2909 };
2910}
2911/**
2912 * Helper that recursively merges two data objects together.
2913 */
2914function mergeData(to, from, recursive = true) {
2915 if (!from)
2916 return to;
2917 let key, toVal, fromVal;
2918 const keys = hasSymbol
2919 ? Reflect.ownKeys(from)
2920 : Object.keys(from);
2921 for (let i = 0; i < keys.length; i++) {
2922 key = keys[i];
2923 // in case the object is already observed...
2924 if (key === '__ob__')
2925 continue;
2926 toVal = to[key];
2927 fromVal = from[key];
2928 if (!recursive || !hasOwn(to, key)) {
2929 set(to, key, fromVal);
2930 }
2931 else if (toVal !== fromVal &&
2932 isPlainObject(toVal) &&
2933 isPlainObject(fromVal)) {
2934 mergeData(toVal, fromVal);
2935 }
2936 }
2937 return to;
2938}
2939/**
2940 * Data
2941 */
2942function mergeDataOrFn(parentVal, childVal, vm) {
2943 if (!vm) {
2944 // in a Vue.extend merge, both should be functions
2945 if (!childVal) {
2946 return parentVal;
2947 }
2948 if (!parentVal) {
2949 return childVal;
2950 }
2951 // when parentVal & childVal are both present,
2952 // we need to return a function that returns the
2953 // merged result of both functions... no need to
2954 // check if parentVal is a function here because
2955 // it has to be a function to pass previous merges.
2956 return function mergedDataFn() {
2957 return mergeData(isFunction(childVal) ? childVal.call(this, this) : childVal, isFunction(parentVal) ? parentVal.call(this, this) : parentVal);
2958 };
2959 }
2960 else {
2961 return function mergedInstanceDataFn() {
2962 // instance merge
2963 const instanceData = isFunction(childVal)
2964 ? childVal.call(vm, vm)
2965 : childVal;
2966 const defaultData = isFunction(parentVal)
2967 ? parentVal.call(vm, vm)
2968 : parentVal;
2969 if (instanceData) {
2970 return mergeData(instanceData, defaultData);
2971 }
2972 else {
2973 return defaultData;
2974 }
2975 };
2976 }
2977}
2978strats.data = function (parentVal, childVal, vm) {
2979 if (!vm) {
2980 if (childVal && typeof childVal !== 'function') {
2981 process.env.NODE_ENV !== 'production' &&
2982 warn$2('The "data" option should be a function ' +
2983 'that returns a per-instance value in component ' +
2984 'definitions.', vm);
2985 return parentVal;
2986 }
2987 return mergeDataOrFn(parentVal, childVal);
2988 }
2989 return mergeDataOrFn(parentVal, childVal, vm);
2990};
2991/**
2992 * Hooks and props are merged as arrays.
2993 */
2994function mergeLifecycleHook(parentVal, childVal) {
2995 const res = childVal
2996 ? parentVal
2997 ? parentVal.concat(childVal)
2998 : isArray(childVal)
2999 ? childVal
3000 : [childVal]
3001 : parentVal;
3002 return res ? dedupeHooks(res) : res;
3003}
3004function dedupeHooks(hooks) {
3005 const res = [];
3006 for (let i = 0; i < hooks.length; i++) {
3007 if (res.indexOf(hooks[i]) === -1) {
3008 res.push(hooks[i]);
3009 }
3010 }
3011 return res;
3012}
3013LIFECYCLE_HOOKS.forEach(hook => {
3014 strats[hook] = mergeLifecycleHook;
3015});
3016/**
3017 * Assets
3018 *
3019 * When a vm is present (instance creation), we need to do
3020 * a three-way merge between constructor options, instance
3021 * options and parent options.
3022 */
3023function mergeAssets(parentVal, childVal, vm, key) {
3024 const res = Object.create(parentVal || null);
3025 if (childVal) {
3026 process.env.NODE_ENV !== 'production' && assertObjectType(key, childVal, vm);
3027 return extend(res, childVal);
3028 }
3029 else {
3030 return res;
3031 }
3032}
3033ASSET_TYPES.forEach(function (type) {
3034 strats[type + 's'] = mergeAssets;
3035});
3036/**
3037 * Watchers.
3038 *
3039 * Watchers hashes should not overwrite one
3040 * another, so we merge them as arrays.
3041 */
3042strats.watch = function (parentVal, childVal, vm, key) {
3043 // work around Firefox's Object.prototype.watch...
3044 //@ts-expect-error work around
3045 if (parentVal === nativeWatch)
3046 parentVal = undefined;
3047 //@ts-expect-error work around
3048 if (childVal === nativeWatch)
3049 childVal = undefined;
3050 /* istanbul ignore if */
3051 if (!childVal)
3052 return Object.create(parentVal || null);
3053 if (process.env.NODE_ENV !== 'production') {
3054 assertObjectType(key, childVal, vm);
3055 }
3056 if (!parentVal)
3057 return childVal;
3058 const ret = {};
3059 extend(ret, parentVal);
3060 for (const key in childVal) {
3061 let parent = ret[key];
3062 const child = childVal[key];
3063 if (parent && !isArray(parent)) {
3064 parent = [parent];
3065 }
3066 ret[key] = parent ? parent.concat(child) : isArray(child) ? child : [child];
3067 }
3068 return ret;
3069};
3070/**
3071 * Other object hashes.
3072 */
3073strats.props =
3074 strats.methods =
3075 strats.inject =
3076 strats.computed =
3077 function (parentVal, childVal, vm, key) {
3078 if (childVal && process.env.NODE_ENV !== 'production') {
3079 assertObjectType(key, childVal, vm);
3080 }
3081 if (!parentVal)
3082 return childVal;
3083 const ret = Object.create(null);
3084 extend(ret, parentVal);
3085 if (childVal)
3086 extend(ret, childVal);
3087 return ret;
3088 };
3089strats.provide = function (parentVal, childVal) {
3090 if (!parentVal)
3091 return childVal;
3092 return function () {
3093 const ret = Object.create(null);
3094 mergeData(ret, isFunction(parentVal) ? parentVal.call(this) : parentVal);
3095 if (childVal) {
3096 mergeData(ret, isFunction(childVal) ? childVal.call(this) : childVal, false // non-recursive
3097 );
3098 }
3099 return ret;
3100 };
3101};
3102/**
3103 * Default strategy.
3104 */
3105const defaultStrat = function (parentVal, childVal) {
3106 return childVal === undefined ? parentVal : childVal;
3107};
3108/**
3109 * Validate component names
3110 */
3111function checkComponents(options) {
3112 for (const key in options.components) {
3113 validateComponentName(key);
3114 }
3115}
3116function validateComponentName(name) {
3117 if (!new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeRegExp.source}]*$`).test(name)) {
3118 warn$2('Invalid component name: "' +
3119 name +
3120 '". Component names ' +
3121 'should conform to valid custom element name in html5 specification.');
3122 }
3123 if (isBuiltInTag(name) || config.isReservedTag(name)) {
3124 warn$2('Do not use built-in or reserved HTML elements as component ' +
3125 'id: ' +
3126 name);
3127 }
3128}
3129/**
3130 * Ensure all props option syntax are normalized into the
3131 * Object-based format.
3132 */
3133function normalizeProps(options, vm) {
3134 const props = options.props;
3135 if (!props)
3136 return;
3137 const res = {};
3138 let i, val, name;
3139 if (isArray(props)) {
3140 i = props.length;
3141 while (i--) {
3142 val = props[i];
3143 if (typeof val === 'string') {
3144 name = camelize(val);
3145 res[name] = { type: null };
3146 }
3147 else if (process.env.NODE_ENV !== 'production') {
3148 warn$2('props must be strings when using array syntax.');
3149 }
3150 }
3151 }
3152 else if (isPlainObject(props)) {
3153 for (const key in props) {
3154 val = props[key];
3155 name = camelize(key);
3156 res[name] = isPlainObject(val) ? val : { type: val };
3157 }
3158 }
3159 else if (process.env.NODE_ENV !== 'production') {
3160 warn$2(`Invalid value for option "props": expected an Array or an Object, ` +
3161 `but got ${toRawType(props)}.`, vm);
3162 }
3163 options.props = res;
3164}
3165/**
3166 * Normalize all injections into Object-based format
3167 */
3168function normalizeInject(options, vm) {
3169 const inject = options.inject;
3170 if (!inject)
3171 return;
3172 const normalized = (options.inject = {});
3173 if (isArray(inject)) {
3174 for (let i = 0; i < inject.length; i++) {
3175 normalized[inject[i]] = { from: inject[i] };
3176 }
3177 }
3178 else if (isPlainObject(inject)) {
3179 for (const key in inject) {
3180 const val = inject[key];
3181 normalized[key] = isPlainObject(val)
3182 ? extend({ from: key }, val)
3183 : { from: val };
3184 }
3185 }
3186 else if (process.env.NODE_ENV !== 'production') {
3187 warn$2(`Invalid value for option "inject": expected an Array or an Object, ` +
3188 `but got ${toRawType(inject)}.`, vm);
3189 }
3190}
3191/**
3192 * Normalize raw function directives into object format.
3193 */
3194function normalizeDirectives(options) {
3195 const dirs = options.directives;
3196 if (dirs) {
3197 for (const key in dirs) {
3198 const def = dirs[key];
3199 if (isFunction(def)) {
3200 dirs[key] = { bind: def, update: def };
3201 }
3202 }
3203 }
3204}
3205function assertObjectType(name, value, vm) {
3206 if (!isPlainObject(value)) {
3207 warn$2(`Invalid value for option "${name}": expected an Object, ` +
3208 `but got ${toRawType(value)}.`, vm);
3209 }
3210}
3211/**
3212 * Merge two option objects into a new one.
3213 * Core utility used in both instantiation and inheritance.
3214 */
3215function mergeOptions(parent, child, vm) {
3216 if (process.env.NODE_ENV !== 'production') {
3217 checkComponents(child);
3218 }
3219 if (isFunction(child)) {
3220 // @ts-expect-error
3221 child = child.options;
3222 }
3223 normalizeProps(child, vm);
3224 normalizeInject(child, vm);
3225 normalizeDirectives(child);
3226 // Apply extends and mixins on the child options,
3227 // but only if it is a raw options object that isn't
3228 // the result of another mergeOptions call.
3229 // Only merged options has the _base property.
3230 if (!child._base) {
3231 if (child.extends) {
3232 parent = mergeOptions(parent, child.extends, vm);
3233 }
3234 if (child.mixins) {
3235 for (let i = 0, l = child.mixins.length; i < l; i++) {
3236 parent = mergeOptions(parent, child.mixins[i], vm);
3237 }
3238 }
3239 }
3240 const options = {};
3241 let key;
3242 for (key in parent) {
3243 mergeField(key);
3244 }
3245 for (key in child) {
3246 if (!hasOwn(parent, key)) {
3247 mergeField(key);
3248 }
3249 }
3250 function mergeField(key) {
3251 const strat = strats[key] || defaultStrat;
3252 options[key] = strat(parent[key], child[key], vm, key);
3253 }
3254 return options;
3255}
3256/**
3257 * Resolve an asset.
3258 * This function is used because child instances need access
3259 * to assets defined in its ancestor chain.
3260 */
3261function resolveAsset(options, type, id, warnMissing) {
3262 /* istanbul ignore if */
3263 if (typeof id !== 'string') {
3264 return;
3265 }
3266 const assets = options[type];
3267 // check local registration variations first
3268 if (hasOwn(assets, id))
3269 return assets[id];
3270 const camelizedId = camelize(id);
3271 if (hasOwn(assets, camelizedId))
3272 return assets[camelizedId];
3273 const PascalCaseId = capitalize(camelizedId);
3274 if (hasOwn(assets, PascalCaseId))
3275 return assets[PascalCaseId];
3276 // fallback to prototype chain
3277 const res = assets[id] || assets[camelizedId] || assets[PascalCaseId];
3278 if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
3279 warn$2('Failed to resolve ' + type.slice(0, -1) + ': ' + id);
3280 }
3281 return res;
3282}
3283
3284function validateProp(key, propOptions, propsData, vm) {
3285 const prop = propOptions[key];
3286 const absent = !hasOwn(propsData, key);
3287 let value = propsData[key];
3288 // boolean casting
3289 const booleanIndex = getTypeIndex(Boolean, prop.type);
3290 if (booleanIndex > -1) {
3291 if (absent && !hasOwn(prop, 'default')) {
3292 value = false;
3293 }
3294 else if (value === '' || value === hyphenate(key)) {
3295 // only cast empty string / same name to boolean if
3296 // boolean has higher priority
3297 const stringIndex = getTypeIndex(String, prop.type);
3298 if (stringIndex < 0 || booleanIndex < stringIndex) {
3299 value = true;
3300 }
3301 }
3302 }
3303 // check default value
3304 if (value === undefined) {
3305 value = getPropDefaultValue(vm, prop, key);
3306 // since the default value is a fresh copy,
3307 // make sure to observe it.
3308 const prevShouldObserve = shouldObserve;
3309 toggleObserving(true);
3310 observe(value);
3311 toggleObserving(prevShouldObserve);
3312 }
3313 if (process.env.NODE_ENV !== 'production') {
3314 assertProp(prop, key, value, vm, absent);
3315 }
3316 return value;
3317}
3318/**
3319 * Get the default value of a prop.
3320 */
3321function getPropDefaultValue(vm, prop, key) {
3322 // no default, return undefined
3323 if (!hasOwn(prop, 'default')) {
3324 return undefined;
3325 }
3326 const def = prop.default;
3327 // warn against non-factory defaults for Object & Array
3328 if (process.env.NODE_ENV !== 'production' && isObject(def)) {
3329 warn$2('Invalid default value for prop "' +
3330 key +
3331 '": ' +
3332 'Props with type Object/Array must use a factory function ' +
3333 'to return the default value.', vm);
3334 }
3335 // the raw prop value was also undefined from previous render,
3336 // return previous default value to avoid unnecessary watcher trigger
3337 if (vm &&
3338 vm.$options.propsData &&
3339 vm.$options.propsData[key] === undefined &&
3340 vm._props[key] !== undefined) {
3341 return vm._props[key];
3342 }
3343 // call factory function for non-Function types
3344 // a value is Function if its prototype is function even across different execution context
3345 return isFunction(def) && getType(prop.type) !== 'Function'
3346 ? def.call(vm)
3347 : def;
3348}
3349/**
3350 * Assert whether a prop is valid.
3351 */
3352function assertProp(prop, name, value, vm, absent) {
3353 if (prop.required && absent) {
3354 warn$2('Missing required prop: "' + name + '"', vm);
3355 return;
3356 }
3357 if (value == null && !prop.required) {
3358 return;
3359 }
3360 let type = prop.type;
3361 let valid = !type || type === true;
3362 const expectedTypes = [];
3363 if (type) {
3364 if (!isArray(type)) {
3365 type = [type];
3366 }
3367 for (let i = 0; i < type.length && !valid; i++) {
3368 const assertedType = assertType(value, type[i], vm);
3369 expectedTypes.push(assertedType.expectedType || '');
3370 valid = assertedType.valid;
3371 }
3372 }
3373 const haveExpectedTypes = expectedTypes.some(t => t);
3374 if (!valid && haveExpectedTypes) {
3375 warn$2(getInvalidTypeMessage(name, value, expectedTypes), vm);
3376 return;
3377 }
3378 const validator = prop.validator;
3379 if (validator) {
3380 if (!validator(value)) {
3381 warn$2('Invalid prop: custom validator check failed for prop "' + name + '".', vm);
3382 }
3383 }
3384}
3385const simpleCheckRE = /^(String|Number|Boolean|Function|Symbol|BigInt)$/;
3386function assertType(value, type, vm) {
3387 let valid;
3388 const expectedType = getType(type);
3389 if (simpleCheckRE.test(expectedType)) {
3390 const t = typeof value;
3391 valid = t === expectedType.toLowerCase();
3392 // for primitive wrapper objects
3393 if (!valid && t === 'object') {
3394 valid = value instanceof type;
3395 }
3396 }
3397 else if (expectedType === 'Object') {
3398 valid = isPlainObject(value);
3399 }
3400 else if (expectedType === 'Array') {
3401 valid = isArray(value);
3402 }
3403 else {
3404 try {
3405 valid = value instanceof type;
3406 }
3407 catch (e) {
3408 warn$2('Invalid prop type: "' + String(type) + '" is not a constructor', vm);
3409 valid = false;
3410 }
3411 }
3412 return {
3413 valid,
3414 expectedType
3415 };
3416}
3417const functionTypeCheckRE = /^\s*function (\w+)/;
3418/**
3419 * Use function string name to check built-in types,
3420 * because a simple equality check will fail when running
3421 * across different vms / iframes.
3422 */
3423function getType(fn) {
3424 const match = fn && fn.toString().match(functionTypeCheckRE);
3425 return match ? match[1] : '';
3426}
3427function isSameType(a, b) {
3428 return getType(a) === getType(b);
3429}
3430function getTypeIndex(type, expectedTypes) {
3431 if (!isArray(expectedTypes)) {
3432 return isSameType(expectedTypes, type) ? 0 : -1;
3433 }
3434 for (let i = 0, len = expectedTypes.length; i < len; i++) {
3435 if (isSameType(expectedTypes[i], type)) {
3436 return i;
3437 }
3438 }
3439 return -1;
3440}
3441function getInvalidTypeMessage(name, value, expectedTypes) {
3442 let message = `Invalid prop: type check failed for prop "${name}".` +
3443 ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
3444 const expectedType = expectedTypes[0];
3445 const receivedType = toRawType(value);
3446 // check if we need to specify expected value
3447 if (expectedTypes.length === 1 &&
3448 isExplicable(expectedType) &&
3449 isExplicable(typeof value) &&
3450 !isBoolean(expectedType, receivedType)) {
3451 message += ` with value ${styleValue(value, expectedType)}`;
3452 }
3453 message += `, got ${receivedType} `;
3454 // check if we need to specify received value
3455 if (isExplicable(receivedType)) {
3456 message += `with value ${styleValue(value, receivedType)}.`;
3457 }
3458 return message;
3459}
3460function styleValue(value, type) {
3461 if (type === 'String') {
3462 return `"${value}"`;
3463 }
3464 else if (type === 'Number') {
3465 return `${Number(value)}`;
3466 }
3467 else {
3468 return `${value}`;
3469 }
3470}
3471const EXPLICABLE_TYPES = ['string', 'number', 'boolean'];
3472function isExplicable(value) {
3473 return EXPLICABLE_TYPES.some(elem => value.toLowerCase() === elem);
3474}
3475function isBoolean(...args) {
3476 return args.some(elem => elem.toLowerCase() === 'boolean');
3477}
3478
3479// these are reserved for web because they are directly compiled away
3480// during template compilation
3481makeMap('style,class');
3482// attributes that should be using props for binding
3483const acceptValue = makeMap('input,textarea,option,select,progress');
3484const mustUseProp = (tag, type, attr) => {
3485 return ((attr === 'value' && acceptValue(tag) && type !== 'button') ||
3486 (attr === 'selected' && tag === 'option') ||
3487 (attr === 'checked' && tag === 'input') ||
3488 (attr === 'muted' && tag === 'video'));
3489};
3490const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck');
3491makeMap('events,caret,typing,plaintext-only');
3492const isBooleanAttr = makeMap('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
3493 'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
3494 'enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,' +
3495 'muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,' +
3496 'required,reversed,scoped,seamless,selected,sortable,' +
3497 'truespeed,typemustmatch,visible');
3498
3499const isHTMLTag = makeMap('html,body,base,head,link,meta,style,title,' +
3500 'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
3501 'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
3502 'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
3503 's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +
3504 'embed,object,param,source,canvas,script,noscript,del,ins,' +
3505 'caption,col,colgroup,table,thead,tbody,td,th,tr,' +
3506 'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
3507 'output,progress,select,textarea,' +
3508 'details,dialog,menu,menuitem,summary,' +
3509 'content,element,shadow,template,blockquote,iframe,tfoot');
3510// this map is intentionally selective, only covering SVG elements that may
3511// contain child elements.
3512const isSVG = makeMap('svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +
3513 'foreignobject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
3514 'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view', true);
3515const isPreTag = (tag) => tag === 'pre';
3516const isReservedTag = (tag) => {
3517 return isHTMLTag(tag) || isSVG(tag);
3518};
3519function getTagNamespace(tag) {
3520 if (isSVG(tag)) {
3521 return 'svg';
3522 }
3523 // basic support for MathML
3524 // note it doesn't support other MathML elements being component roots
3525 if (tag === 'math') {
3526 return 'math';
3527 }
3528}
3529makeMap('text,number,password,search,email,tel,url');
3530
3531const validDivisionCharRE = /[\w).+\-_$\]]/;
3532function parseFilters(exp) {
3533 let inSingle = false;
3534 let inDouble = false;
3535 let inTemplateString = false;
3536 let inRegex = false;
3537 let curly = 0;
3538 let square = 0;
3539 let paren = 0;
3540 let lastFilterIndex = 0;
3541 let c, prev, i, expression, filters;
3542 for (i = 0; i < exp.length; i++) {
3543 prev = c;
3544 c = exp.charCodeAt(i);
3545 if (inSingle) {
3546 if (c === 0x27 && prev !== 0x5c)
3547 inSingle = false;
3548 }
3549 else if (inDouble) {
3550 if (c === 0x22 && prev !== 0x5c)
3551 inDouble = false;
3552 }
3553 else if (inTemplateString) {
3554 if (c === 0x60 && prev !== 0x5c)
3555 inTemplateString = false;
3556 }
3557 else if (inRegex) {
3558 if (c === 0x2f && prev !== 0x5c)
3559 inRegex = false;
3560 }
3561 else if (c === 0x7c && // pipe
3562 exp.charCodeAt(i + 1) !== 0x7c &&
3563 exp.charCodeAt(i - 1) !== 0x7c &&
3564 !curly &&
3565 !square &&
3566 !paren) {
3567 if (expression === undefined) {
3568 // first filter, end of expression
3569 lastFilterIndex = i + 1;
3570 expression = exp.slice(0, i).trim();
3571 }
3572 else {
3573 pushFilter();
3574 }
3575 }
3576 else {
3577 switch (c) {
3578 case 0x22:
3579 inDouble = true;
3580 break; // "
3581 case 0x27:
3582 inSingle = true;
3583 break; // '
3584 case 0x60:
3585 inTemplateString = true;
3586 break; // `
3587 case 0x28:
3588 paren++;
3589 break; // (
3590 case 0x29:
3591 paren--;
3592 break; // )
3593 case 0x5b:
3594 square++;
3595 break; // [
3596 case 0x5d:
3597 square--;
3598 break; // ]
3599 case 0x7b:
3600 curly++;
3601 break; // {
3602 case 0x7d:
3603 curly--;
3604 break; // }
3605 }
3606 if (c === 0x2f) {
3607 // /
3608 let j = i - 1;
3609 let p;
3610 // find first non-whitespace prev char
3611 for (; j >= 0; j--) {
3612 p = exp.charAt(j);
3613 if (p !== ' ')
3614 break;
3615 }
3616 if (!p || !validDivisionCharRE.test(p)) {
3617 inRegex = true;
3618 }
3619 }
3620 }
3621 }
3622 if (expression === undefined) {
3623 expression = exp.slice(0, i).trim();
3624 }
3625 else if (lastFilterIndex !== 0) {
3626 pushFilter();
3627 }
3628 function pushFilter() {
3629 (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());
3630 lastFilterIndex = i + 1;
3631 }
3632 if (filters) {
3633 for (i = 0; i < filters.length; i++) {
3634 expression = wrapFilter(expression, filters[i]);
3635 }
3636 }
3637 return expression;
3638}
3639function wrapFilter(exp, filter) {
3640 const i = filter.indexOf('(');
3641 if (i < 0) {
3642 // _f: resolveFilter
3643 return `_f("${filter}")(${exp})`;
3644 }
3645 else {
3646 const name = filter.slice(0, i);
3647 const args = filter.slice(i + 1);
3648 return `_f("${name}")(${exp}${args !== ')' ? ',' + args : args}`;
3649 }
3650}
3651
3652const defaultTagRE = /\{\{((?:.|\r?\n)+?)\}\}/g;
3653const regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
3654const buildRegex = cached(delimiters => {
3655 const open = delimiters[0].replace(regexEscapeRE, '\\$&');
3656 const close = delimiters[1].replace(regexEscapeRE, '\\$&');
3657 return new RegExp(open + '((?:.|\\n)+?)' + close, 'g');
3658});
3659function parseText(text, delimiters) {
3660 //@ts-expect-error
3661 const tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;
3662 if (!tagRE.test(text)) {
3663 return;
3664 }
3665 const tokens = [];
3666 const rawTokens = [];
3667 let lastIndex = (tagRE.lastIndex = 0);
3668 let match, index, tokenValue;
3669 while ((match = tagRE.exec(text))) {
3670 index = match.index;
3671 // push text token
3672 if (index > lastIndex) {
3673 rawTokens.push((tokenValue = text.slice(lastIndex, index)));
3674 tokens.push(JSON.stringify(tokenValue));
3675 }
3676 // tag token
3677 const exp = parseFilters(match[1].trim());
3678 tokens.push(`_s(${exp})`);
3679 rawTokens.push({ '@binding': exp });
3680 lastIndex = index + match[0].length;
3681 }
3682 if (lastIndex < text.length) {
3683 rawTokens.push((tokenValue = text.slice(lastIndex)));
3684 tokens.push(JSON.stringify(tokenValue));
3685 }
3686 return {
3687 expression: tokens.join('+'),
3688 tokens: rawTokens
3689 };
3690}
3691
3692/* eslint-disable no-unused-vars */
3693function baseWarn(msg, range) {
3694 console.error(`[Vue compiler]: ${msg}`);
3695}
3696/* eslint-enable no-unused-vars */
3697function pluckModuleFunction(modules, key) {
3698 return modules ? modules.map(m => m[key]).filter(_ => _) : [];
3699}
3700function addProp(el, name, value, range, dynamic) {
3701 (el.props || (el.props = [])).push(rangeSetItem({ name, value, dynamic }, range));
3702 el.plain = false;
3703}
3704function addAttr(el, name, value, range, dynamic) {
3705 const attrs = dynamic
3706 ? el.dynamicAttrs || (el.dynamicAttrs = [])
3707 : el.attrs || (el.attrs = []);
3708 attrs.push(rangeSetItem({ name, value, dynamic }, range));
3709 el.plain = false;
3710}
3711// add a raw attr (use this in preTransforms)
3712function addRawAttr(el, name, value, range) {
3713 el.attrsMap[name] = value;
3714 el.attrsList.push(rangeSetItem({ name, value }, range));
3715}
3716function addDirective(el, name, rawName, value, arg, isDynamicArg, modifiers, range) {
3717 (el.directives || (el.directives = [])).push(rangeSetItem({
3718 name,
3719 rawName,
3720 value,
3721 arg,
3722 isDynamicArg,
3723 modifiers
3724 }, range));
3725 el.plain = false;
3726}
3727function prependModifierMarker(symbol, name, dynamic) {
3728 return dynamic ? `_p(${name},"${symbol}")` : symbol + name; // mark the event as captured
3729}
3730function addHandler(el, name, value, modifiers, important, warn, range, dynamic) {
3731 modifiers = modifiers || emptyObject;
3732 // warn prevent and passive modifier
3733 /* istanbul ignore if */
3734 if (process.env.NODE_ENV !== 'production' && warn && modifiers.prevent && modifiers.passive) {
3735 warn("passive and prevent can't be used together. " +
3736 "Passive handler can't prevent default event.", range);
3737 }
3738 // normalize click.right and click.middle since they don't actually fire
3739 // this is technically browser-specific, but at least for now browsers are
3740 // the only target envs that have right/middle clicks.
3741 if (modifiers.right) {
3742 if (dynamic) {
3743 name = `(${name})==='click'?'contextmenu':(${name})`;
3744 }
3745 else if (name === 'click') {
3746 name = 'contextmenu';
3747 delete modifiers.right;
3748 }
3749 }
3750 else if (modifiers.middle) {
3751 if (dynamic) {
3752 name = `(${name})==='click'?'mouseup':(${name})`;
3753 }
3754 else if (name === 'click') {
3755 name = 'mouseup';
3756 }
3757 }
3758 // check capture modifier
3759 if (modifiers.capture) {
3760 delete modifiers.capture;
3761 name = prependModifierMarker('!', name, dynamic);
3762 }
3763 if (modifiers.once) {
3764 delete modifiers.once;
3765 name = prependModifierMarker('~', name, dynamic);
3766 }
3767 /* istanbul ignore if */
3768 if (modifiers.passive) {
3769 delete modifiers.passive;
3770 name = prependModifierMarker('&', name, dynamic);
3771 }
3772 let events;
3773 if (modifiers.native) {
3774 delete modifiers.native;
3775 events = el.nativeEvents || (el.nativeEvents = {});
3776 }
3777 else {
3778 events = el.events || (el.events = {});
3779 }
3780 const newHandler = rangeSetItem({ value: value.trim(), dynamic }, range);
3781 if (modifiers !== emptyObject) {
3782 newHandler.modifiers = modifiers;
3783 }
3784 const handlers = events[name];
3785 /* istanbul ignore if */
3786 if (Array.isArray(handlers)) {
3787 important ? handlers.unshift(newHandler) : handlers.push(newHandler);
3788 }
3789 else if (handlers) {
3790 events[name] = important ? [newHandler, handlers] : [handlers, newHandler];
3791 }
3792 else {
3793 events[name] = newHandler;
3794 }
3795 el.plain = false;
3796}
3797function getRawBindingAttr(el, name) {
3798 return (el.rawAttrsMap[':' + name] ||
3799 el.rawAttrsMap['v-bind:' + name] ||
3800 el.rawAttrsMap[name]);
3801}
3802function getBindingAttr(el, name, getStatic) {
3803 const dynamicValue = getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name);
3804 if (dynamicValue != null) {
3805 return parseFilters(dynamicValue);
3806 }
3807 else if (getStatic !== false) {
3808 const staticValue = getAndRemoveAttr(el, name);
3809 if (staticValue != null) {
3810 return JSON.stringify(staticValue);
3811 }
3812 }
3813}
3814// note: this only removes the attr from the Array (attrsList) so that it
3815// doesn't get processed by processAttrs.
3816// By default it does NOT remove it from the map (attrsMap) because the map is
3817// needed during codegen.
3818function getAndRemoveAttr(el, name, removeFromMap) {
3819 let val;
3820 if ((val = el.attrsMap[name]) != null) {
3821 const list = el.attrsList;
3822 for (let i = 0, l = list.length; i < l; i++) {
3823 if (list[i].name === name) {
3824 list.splice(i, 1);
3825 break;
3826 }
3827 }
3828 }
3829 if (removeFromMap) {
3830 delete el.attrsMap[name];
3831 }
3832 return val;
3833}
3834function getAndRemoveAttrByRegex(el, name) {
3835 const list = el.attrsList;
3836 for (let i = 0, l = list.length; i < l; i++) {
3837 const attr = list[i];
3838 if (name.test(attr.name)) {
3839 list.splice(i, 1);
3840 return attr;
3841 }
3842 }
3843}
3844function rangeSetItem(item, range) {
3845 if (range) {
3846 if (range.start != null) {
3847 item.start = range.start;
3848 }
3849 if (range.end != null) {
3850 item.end = range.end;
3851 }
3852 }
3853 return item;
3854}
3855
3856function transformNode$1(el, options) {
3857 const warn = options.warn || baseWarn;
3858 const staticClass = getAndRemoveAttr(el, 'class');
3859 if (process.env.NODE_ENV !== 'production' && staticClass) {
3860 const res = parseText(staticClass, options.delimiters);
3861 if (res) {
3862 warn(`class="${staticClass}": ` +
3863 'Interpolation inside attributes has been removed. ' +
3864 'Use v-bind or the colon shorthand instead. For example, ' +
3865 'instead of <div class="{{ val }}">, use <div :class="val">.', el.rawAttrsMap['class']);
3866 }
3867 }
3868 if (staticClass) {
3869 el.staticClass = JSON.stringify(staticClass.replace(/\s+/g, ' ').trim());
3870 }
3871 const classBinding = getBindingAttr(el, 'class', false /* getStatic */);
3872 if (classBinding) {
3873 el.classBinding = classBinding;
3874 }
3875}
3876function genData$2(el) {
3877 let data = '';
3878 if (el.staticClass) {
3879 data += `staticClass:${el.staticClass},`;
3880 }
3881 if (el.classBinding) {
3882 data += `class:${el.classBinding},`;
3883 }
3884 return data;
3885}
3886var klass = {
3887 staticKeys: ['staticClass'],
3888 transformNode: transformNode$1,
3889 genData: genData$2
3890};
3891
3892const parseStyleText = cached(function (cssText) {
3893 const res = {};
3894 const listDelimiter = /;(?![^(]*\))/g;
3895 const propertyDelimiter = /:(.+)/;
3896 cssText.split(listDelimiter).forEach(function (item) {
3897 if (item) {
3898 const tmp = item.split(propertyDelimiter);
3899 tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
3900 }
3901 });
3902 return res;
3903});
3904
3905function transformNode(el, options) {
3906 const warn = options.warn || baseWarn;
3907 const staticStyle = getAndRemoveAttr(el, 'style');
3908 if (staticStyle) {
3909 /* istanbul ignore if */
3910 if (process.env.NODE_ENV !== 'production') {
3911 const res = parseText(staticStyle, options.delimiters);
3912 if (res) {
3913 warn(`style="${staticStyle}": ` +
3914 'Interpolation inside attributes has been removed. ' +
3915 'Use v-bind or the colon shorthand instead. For example, ' +
3916 'instead of <div style="{{ val }}">, use <div :style="val">.', el.rawAttrsMap['style']);
3917 }
3918 }
3919 el.staticStyle = JSON.stringify(parseStyleText(staticStyle));
3920 }
3921 const styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
3922 if (styleBinding) {
3923 el.styleBinding = styleBinding;
3924 }
3925}
3926function genData$1(el) {
3927 let data = '';
3928 if (el.staticStyle) {
3929 data += `staticStyle:${el.staticStyle},`;
3930 }
3931 if (el.styleBinding) {
3932 data += `style:(${el.styleBinding}),`;
3933 }
3934 return data;
3935}
3936var style = {
3937 staticKeys: ['staticStyle'],
3938 transformNode,
3939 genData: genData$1
3940};
3941
3942/**
3943 * Cross-platform code generation for component v-model
3944 */
3945function genComponentModel(el, value, modifiers) {
3946 const { number, trim } = modifiers || {};
3947 const baseValueExpression = '$$v';
3948 let valueExpression = baseValueExpression;
3949 if (trim) {
3950 valueExpression =
3951 `(typeof ${baseValueExpression} === 'string'` +
3952 `? ${baseValueExpression}.trim()` +
3953 `: ${baseValueExpression})`;
3954 }
3955 if (number) {
3956 valueExpression = `_n(${valueExpression})`;
3957 }
3958 const assignment = genAssignmentCode(value, valueExpression);
3959 el.model = {
3960 value: `(${value})`,
3961 expression: JSON.stringify(value),
3962 callback: `function (${baseValueExpression}) {${assignment}}`
3963 };
3964}
3965/**
3966 * Cross-platform codegen helper for generating v-model value assignment code.
3967 */
3968function genAssignmentCode(value, assignment) {
3969 const res = parseModel(value);
3970 if (res.key === null) {
3971 return `${value}=${assignment}`;
3972 }
3973 else {
3974 return `$set(${res.exp}, ${res.key}, ${assignment})`;
3975 }
3976}
3977/**
3978 * Parse a v-model expression into a base path and a final key segment.
3979 * Handles both dot-path and possible square brackets.
3980 *
3981 * Possible cases:
3982 *
3983 * - test
3984 * - test[key]
3985 * - test[test1[key]]
3986 * - test["a"][key]
3987 * - xxx.test[a[a].test1[key]]
3988 * - test.xxx.a["asa"][test1[key]]
3989 *
3990 */
3991let len, str, chr, index, expressionPos, expressionEndPos;
3992function parseModel(val) {
3993 // Fix https://github.com/vuejs/vue/pull/7730
3994 // allow v-model="obj.val " (trailing whitespace)
3995 val = val.trim();
3996 len = val.length;
3997 if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
3998 index = val.lastIndexOf('.');
3999 if (index > -1) {
4000 return {
4001 exp: val.slice(0, index),
4002 key: '"' + val.slice(index + 1) + '"'
4003 };
4004 }
4005 else {
4006 return {
4007 exp: val,
4008 key: null
4009 };
4010 }
4011 }
4012 str = val;
4013 index = expressionPos = expressionEndPos = 0;
4014 while (!eof()) {
4015 chr = next();
4016 /* istanbul ignore if */
4017 if (isStringStart(chr)) {
4018 parseString(chr);
4019 }
4020 else if (chr === 0x5b) {
4021 parseBracket(chr);
4022 }
4023 }
4024 return {
4025 exp: val.slice(0, expressionPos),
4026 key: val.slice(expressionPos + 1, expressionEndPos)
4027 };
4028}
4029function next() {
4030 return str.charCodeAt(++index);
4031}
4032function eof() {
4033 return index >= len;
4034}
4035function isStringStart(chr) {
4036 return chr === 0x22 || chr === 0x27;
4037}
4038function parseBracket(chr) {
4039 let inBracket = 1;
4040 expressionPos = index;
4041 while (!eof()) {
4042 chr = next();
4043 if (isStringStart(chr)) {
4044 parseString(chr);
4045 continue;
4046 }
4047 if (chr === 0x5b)
4048 inBracket++;
4049 if (chr === 0x5d)
4050 inBracket--;
4051 if (inBracket === 0) {
4052 expressionEndPos = index;
4053 break;
4054 }
4055 }
4056}
4057function parseString(chr) {
4058 const stringQuote = chr;
4059 while (!eof()) {
4060 chr = next();
4061 if (chr === stringQuote) {
4062 break;
4063 }
4064 }
4065}
4066
4067const onRE = /^@|^v-on:/;
4068const dirRE = /^v-|^@|^:|^#/;
4069const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
4070const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
4071const stripParensRE = /^\(|\)$/g;
4072const dynamicArgRE = /^\[.*\]$/;
4073const argRE = /:(.*)$/;
4074const bindRE = /^:|^\.|^v-bind:/;
4075const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g;
4076const slotRE = /^v-slot(:|$)|^#/;
4077const lineBreakRE = /[\r\n]/;
4078const whitespaceRE = /[ \f\t\r\n]+/g;
4079const invalidAttributeRE = /[\s"'<>\/=]/;
4080const decodeHTMLCached = cached(he__default["default"].decode);
4081const emptySlotScopeToken = `_empty_`;
4082// configurable state
4083let warn$1;
4084let delimiters;
4085let transforms;
4086let preTransforms;
4087let postTransforms;
4088let platformIsPreTag;
4089let platformMustUseProp;
4090let platformGetTagNamespace;
4091let maybeComponent;
4092function createASTElement(tag, attrs, parent) {
4093 return {
4094 type: 1,
4095 tag,
4096 attrsList: attrs,
4097 attrsMap: makeAttrsMap(attrs),
4098 rawAttrsMap: {},
4099 parent,
4100 children: []
4101 };
4102}
4103/**
4104 * Convert HTML string to AST.
4105 */
4106function parse(template, options) {
4107 warn$1 = options.warn || baseWarn;
4108 platformIsPreTag = options.isPreTag || no;
4109 platformMustUseProp = options.mustUseProp || no;
4110 platformGetTagNamespace = options.getTagNamespace || no;
4111 const isReservedTag = options.isReservedTag || no;
4112 maybeComponent = (el) => !!(el.component ||
4113 el.attrsMap[':is'] ||
4114 el.attrsMap['v-bind:is'] ||
4115 !(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag)));
4116 transforms = pluckModuleFunction(options.modules, 'transformNode');
4117 preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');
4118 postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');
4119 delimiters = options.delimiters;
4120 const stack = [];
4121 const preserveWhitespace = options.preserveWhitespace !== false;
4122 const whitespaceOption = options.whitespace;
4123 let root;
4124 let currentParent;
4125 let inVPre = false;
4126 let inPre = false;
4127 let warned = false;
4128 function warnOnce(msg, range) {
4129 if (!warned) {
4130 warned = true;
4131 warn$1(msg, range);
4132 }
4133 }
4134 function closeElement(element) {
4135 trimEndingWhitespace(element);
4136 if (!inVPre && !element.processed) {
4137 element = processElement(element, options);
4138 }
4139 // tree management
4140 if (!stack.length && element !== root) {
4141 // allow root elements with v-if, v-else-if and v-else
4142 if (root.if && (element.elseif || element.else)) {
4143 if (process.env.NODE_ENV !== 'production') {
4144 checkRootConstraints(element);
4145 }
4146 addIfCondition(root, {
4147 exp: element.elseif,
4148 block: element
4149 });
4150 }
4151 else if (process.env.NODE_ENV !== 'production') {
4152 warnOnce(`Component template should contain exactly one root element. ` +
4153 `If you are using v-if on multiple elements, ` +
4154 `use v-else-if to chain them instead.`, { start: element.start });
4155 }
4156 }
4157 if (currentParent && !element.forbidden) {
4158 if (element.elseif || element.else) {
4159 processIfConditions(element, currentParent);
4160 }
4161 else {
4162 if (element.slotScope) {
4163 // scoped slot
4164 // keep it in the children list so that v-else(-if) conditions can
4165 // find it as the prev node.
4166 const name = element.slotTarget || '"default"';
4167 (currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;
4168 }
4169 currentParent.children.push(element);
4170 element.parent = currentParent;
4171 }
4172 }
4173 // final children cleanup
4174 // filter out scoped slots
4175 element.children = element.children.filter(c => !c.slotScope);
4176 // remove trailing whitespace node again
4177 trimEndingWhitespace(element);
4178 // check pre state
4179 if (element.pre) {
4180 inVPre = false;
4181 }
4182 if (platformIsPreTag(element.tag)) {
4183 inPre = false;
4184 }
4185 // apply post-transforms
4186 for (let i = 0; i < postTransforms.length; i++) {
4187 postTransforms[i](element, options);
4188 }
4189 }
4190 function trimEndingWhitespace(el) {
4191 // remove trailing whitespace node
4192 if (!inPre) {
4193 let lastNode;
4194 while ((lastNode = el.children[el.children.length - 1]) &&
4195 lastNode.type === 3 &&
4196 lastNode.text === ' ') {
4197 el.children.pop();
4198 }
4199 }
4200 }
4201 function checkRootConstraints(el) {
4202 if (el.tag === 'slot' || el.tag === 'template') {
4203 warnOnce(`Cannot use <${el.tag}> as component root element because it may ` +
4204 'contain multiple nodes.', { start: el.start });
4205 }
4206 if (el.attrsMap.hasOwnProperty('v-for')) {
4207 warnOnce('Cannot use v-for on stateful component root element because ' +
4208 'it renders multiple elements.', el.rawAttrsMap['v-for']);
4209 }
4210 }
4211 parseHTML(template, {
4212 warn: warn$1,
4213 expectHTML: options.expectHTML,
4214 isUnaryTag: options.isUnaryTag,
4215 canBeLeftOpenTag: options.canBeLeftOpenTag,
4216 shouldDecodeNewlines: options.shouldDecodeNewlines,
4217 shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
4218 shouldKeepComment: options.comments,
4219 outputSourceRange: options.outputSourceRange,
4220 start(tag, attrs, unary, start, end) {
4221 // check namespace.
4222 // inherit parent ns if there is one
4223 const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);
4224 // handle IE svg bug
4225 /* istanbul ignore if */
4226 if (isIE && ns === 'svg') {
4227 attrs = guardIESVGBug(attrs);
4228 }
4229 let element = createASTElement(tag, attrs, currentParent);
4230 if (ns) {
4231 element.ns = ns;
4232 }
4233 if (process.env.NODE_ENV !== 'production') {
4234 if (options.outputSourceRange) {
4235 element.start = start;
4236 element.end = end;
4237 element.rawAttrsMap = element.attrsList.reduce((cumulated, attr) => {
4238 cumulated[attr.name] = attr;
4239 return cumulated;
4240 }, {});
4241 }
4242 attrs.forEach(attr => {
4243 if (invalidAttributeRE.test(attr.name)) {
4244 warn$1(`Invalid dynamic argument expression: attribute names cannot contain ` +
4245 `spaces, quotes, <, >, / or =.`, options.outputSourceRange
4246 ? {
4247 start: attr.start + attr.name.indexOf(`[`),
4248 end: attr.start + attr.name.length
4249 }
4250 : undefined);
4251 }
4252 });
4253 }
4254 if (isForbiddenTag(element) && !isServerRendering()) {
4255 element.forbidden = true;
4256 process.env.NODE_ENV !== 'production' &&
4257 warn$1('Templates should only be responsible for mapping the state to the ' +
4258 'UI. Avoid placing tags with side-effects in your templates, such as ' +
4259 `<${tag}>` +
4260 ', as they will not be parsed.', { start: element.start });
4261 }
4262 // apply pre-transforms
4263 for (let i = 0; i < preTransforms.length; i++) {
4264 element = preTransforms[i](element, options) || element;
4265 }
4266 if (!inVPre) {
4267 processPre(element);
4268 if (element.pre) {
4269 inVPre = true;
4270 }
4271 }
4272 if (platformIsPreTag(element.tag)) {
4273 inPre = true;
4274 }
4275 if (inVPre) {
4276 processRawAttrs(element);
4277 }
4278 else if (!element.processed) {
4279 // structural directives
4280 processFor(element);
4281 processIf(element);
4282 processOnce(element);
4283 }
4284 if (!root) {
4285 root = element;
4286 if (process.env.NODE_ENV !== 'production') {
4287 checkRootConstraints(root);
4288 }
4289 }
4290 if (!unary) {
4291 currentParent = element;
4292 stack.push(element);
4293 }
4294 else {
4295 closeElement(element);
4296 }
4297 },
4298 end(tag, start, end) {
4299 const element = stack[stack.length - 1];
4300 // pop stack
4301 stack.length -= 1;
4302 currentParent = stack[stack.length - 1];
4303 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
4304 element.end = end;
4305 }
4306 closeElement(element);
4307 },
4308 chars(text, start, end) {
4309 if (!currentParent) {
4310 if (process.env.NODE_ENV !== 'production') {
4311 if (text === template) {
4312 warnOnce('Component template requires a root element, rather than just text.', { start });
4313 }
4314 else if ((text = text.trim())) {
4315 warnOnce(`text "${text}" outside root element will be ignored.`, {
4316 start
4317 });
4318 }
4319 }
4320 return;
4321 }
4322 // IE textarea placeholder bug
4323 /* istanbul ignore if */
4324 if (isIE &&
4325 currentParent.tag === 'textarea' &&
4326 currentParent.attrsMap.placeholder === text) {
4327 return;
4328 }
4329 const children = currentParent.children;
4330 if (inPre || text.trim()) {
4331 text = isTextTag(currentParent)
4332 ? text
4333 : decodeHTMLCached(text);
4334 }
4335 else if (!children.length) {
4336 // remove the whitespace-only node right after an opening tag
4337 text = '';
4338 }
4339 else if (whitespaceOption) {
4340 if (whitespaceOption === 'condense') {
4341 // in condense mode, remove the whitespace node if it contains
4342 // line break, otherwise condense to a single space
4343 text = lineBreakRE.test(text) ? '' : ' ';
4344 }
4345 else {
4346 text = ' ';
4347 }
4348 }
4349 else {
4350 text = preserveWhitespace ? ' ' : '';
4351 }
4352 if (text) {
4353 if (!inPre && whitespaceOption === 'condense') {
4354 // condense consecutive whitespaces into single space
4355 text = text.replace(whitespaceRE, ' ');
4356 }
4357 let res;
4358 let child;
4359 if (!inVPre && text !== ' ' && (res = parseText(text, delimiters))) {
4360 child = {
4361 type: 2,
4362 expression: res.expression,
4363 tokens: res.tokens,
4364 text
4365 };
4366 }
4367 else if (text !== ' ' ||
4368 !children.length ||
4369 children[children.length - 1].text !== ' ') {
4370 child = {
4371 type: 3,
4372 text
4373 };
4374 }
4375 if (child) {
4376 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
4377 child.start = start;
4378 child.end = end;
4379 }
4380 children.push(child);
4381 }
4382 }
4383 },
4384 comment(text, start, end) {
4385 // adding anything as a sibling to the root node is forbidden
4386 // comments should still be allowed, but ignored
4387 if (currentParent) {
4388 const child = {
4389 type: 3,
4390 text,
4391 isComment: true
4392 };
4393 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
4394 child.start = start;
4395 child.end = end;
4396 }
4397 currentParent.children.push(child);
4398 }
4399 }
4400 });
4401 return root;
4402}
4403function processPre(el) {
4404 if (getAndRemoveAttr(el, 'v-pre') != null) {
4405 el.pre = true;
4406 }
4407}
4408function processRawAttrs(el) {
4409 const list = el.attrsList;
4410 const len = list.length;
4411 if (len) {
4412 const attrs = (el.attrs = new Array(len));
4413 for (let i = 0; i < len; i++) {
4414 attrs[i] = {
4415 name: list[i].name,
4416 value: JSON.stringify(list[i].value)
4417 };
4418 if (list[i].start != null) {
4419 attrs[i].start = list[i].start;
4420 attrs[i].end = list[i].end;
4421 }
4422 }
4423 }
4424 else if (!el.pre) {
4425 // non root node in pre blocks with no attributes
4426 el.plain = true;
4427 }
4428}
4429function processElement(element, options) {
4430 processKey(element);
4431 // determine whether this is a plain element after
4432 // removing structural attributes
4433 element.plain =
4434 !element.key && !element.scopedSlots && !element.attrsList.length;
4435 processRef(element);
4436 processSlotContent(element);
4437 processSlotOutlet(element);
4438 processComponent(element);
4439 for (let i = 0; i < transforms.length; i++) {
4440 element = transforms[i](element, options) || element;
4441 }
4442 processAttrs(element);
4443 return element;
4444}
4445function processKey(el) {
4446 const exp = getBindingAttr(el, 'key');
4447 if (exp) {
4448 if (process.env.NODE_ENV !== 'production') {
4449 if (el.tag === 'template') {
4450 warn$1(`<template> cannot be keyed. Place the key on real elements instead.`, getRawBindingAttr(el, 'key'));
4451 }
4452 if (el.for) {
4453 const iterator = el.iterator2 || el.iterator1;
4454 const parent = el.parent;
4455 if (iterator &&
4456 iterator === exp &&
4457 parent &&
4458 parent.tag === 'transition-group') {
4459 warn$1(`Do not use v-for index as key on <transition-group> children, ` +
4460 `this is the same as not using keys.`, getRawBindingAttr(el, 'key'), true /* tip */);
4461 }
4462 }
4463 }
4464 el.key = exp;
4465 }
4466}
4467function processRef(el) {
4468 const ref = getBindingAttr(el, 'ref');
4469 if (ref) {
4470 el.ref = ref;
4471 el.refInFor = checkInFor(el);
4472 }
4473}
4474function processFor(el) {
4475 let exp;
4476 if ((exp = getAndRemoveAttr(el, 'v-for'))) {
4477 const res = parseFor(exp);
4478 if (res) {
4479 extend(el, res);
4480 }
4481 else if (process.env.NODE_ENV !== 'production') {
4482 warn$1(`Invalid v-for expression: ${exp}`, el.rawAttrsMap['v-for']);
4483 }
4484 }
4485}
4486function parseFor(exp) {
4487 const inMatch = exp.match(forAliasRE);
4488 if (!inMatch)
4489 return;
4490 const res = {};
4491 res.for = inMatch[2].trim();
4492 const alias = inMatch[1].trim().replace(stripParensRE, '');
4493 const iteratorMatch = alias.match(forIteratorRE);
4494 if (iteratorMatch) {
4495 res.alias = alias.replace(forIteratorRE, '').trim();
4496 res.iterator1 = iteratorMatch[1].trim();
4497 if (iteratorMatch[2]) {
4498 res.iterator2 = iteratorMatch[2].trim();
4499 }
4500 }
4501 else {
4502 res.alias = alias;
4503 }
4504 return res;
4505}
4506function processIf(el) {
4507 const exp = getAndRemoveAttr(el, 'v-if');
4508 if (exp) {
4509 el.if = exp;
4510 addIfCondition(el, {
4511 exp: exp,
4512 block: el
4513 });
4514 }
4515 else {
4516 if (getAndRemoveAttr(el, 'v-else') != null) {
4517 el.else = true;
4518 }
4519 const elseif = getAndRemoveAttr(el, 'v-else-if');
4520 if (elseif) {
4521 el.elseif = elseif;
4522 }
4523 }
4524}
4525function processIfConditions(el, parent) {
4526 const prev = findPrevElement(parent.children);
4527 if (prev && prev.if) {
4528 addIfCondition(prev, {
4529 exp: el.elseif,
4530 block: el
4531 });
4532 }
4533 else if (process.env.NODE_ENV !== 'production') {
4534 warn$1(`v-${el.elseif ? 'else-if="' + el.elseif + '"' : 'else'} ` +
4535 `used on element <${el.tag}> without corresponding v-if.`, el.rawAttrsMap[el.elseif ? 'v-else-if' : 'v-else']);
4536 }
4537}
4538function findPrevElement(children) {
4539 let i = children.length;
4540 while (i--) {
4541 if (children[i].type === 1) {
4542 return children[i];
4543 }
4544 else {
4545 if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
4546 warn$1(`text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
4547 `will be ignored.`, children[i]);
4548 }
4549 children.pop();
4550 }
4551 }
4552}
4553function addIfCondition(el, condition) {
4554 if (!el.ifConditions) {
4555 el.ifConditions = [];
4556 }
4557 el.ifConditions.push(condition);
4558}
4559function processOnce(el) {
4560 const once = getAndRemoveAttr(el, 'v-once');
4561 if (once != null) {
4562 el.once = true;
4563 }
4564}
4565// handle content being passed to a component as slot,
4566// e.g. <template slot="xxx">, <div slot-scope="xxx">
4567function processSlotContent(el) {
4568 let slotScope;
4569 if (el.tag === 'template') {
4570 slotScope = getAndRemoveAttr(el, 'scope');
4571 /* istanbul ignore if */
4572 if (process.env.NODE_ENV !== 'production' && slotScope) {
4573 warn$1(`the "scope" attribute for scoped slots have been deprecated and ` +
4574 `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
4575 `can also be used on plain elements in addition to <template> to ` +
4576 `denote scoped slots.`, el.rawAttrsMap['scope'], true);
4577 }
4578 el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope');
4579 }
4580 else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
4581 /* istanbul ignore if */
4582 if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
4583 warn$1(`Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
4584 `(v-for takes higher priority). Use a wrapper <template> for the ` +
4585 `scoped slot to make it clearer.`, el.rawAttrsMap['slot-scope'], true);
4586 }
4587 el.slotScope = slotScope;
4588 }
4589 // slot="xxx"
4590 const slotTarget = getBindingAttr(el, 'slot');
4591 if (slotTarget) {
4592 el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget;
4593 el.slotTargetDynamic = !!(el.attrsMap[':slot'] || el.attrsMap['v-bind:slot']);
4594 // preserve slot as an attribute for native shadow DOM compat
4595 // only for non-scoped slots.
4596 if (el.tag !== 'template' && !el.slotScope) {
4597 addAttr(el, 'slot', slotTarget, getRawBindingAttr(el, 'slot'));
4598 }
4599 }
4600 // 2.6 v-slot syntax
4601 {
4602 if (el.tag === 'template') {
4603 // v-slot on <template>
4604 const slotBinding = getAndRemoveAttrByRegex(el, slotRE);
4605 if (slotBinding) {
4606 if (process.env.NODE_ENV !== 'production') {
4607 if (el.slotTarget || el.slotScope) {
4608 warn$1(`Unexpected mixed usage of different slot syntaxes.`, el);
4609 }
4610 if (el.parent && !maybeComponent(el.parent)) {
4611 warn$1(`<template v-slot> can only appear at the root level inside ` +
4612 `the receiving component`, el);
4613 }
4614 }
4615 const { name, dynamic } = getSlotName(slotBinding);
4616 el.slotTarget = name;
4617 el.slotTargetDynamic = dynamic;
4618 el.slotScope = slotBinding.value || emptySlotScopeToken; // force it into a scoped slot for perf
4619 }
4620 }
4621 else {
4622 // v-slot on component, denotes default slot
4623 const slotBinding = getAndRemoveAttrByRegex(el, slotRE);
4624 if (slotBinding) {
4625 if (process.env.NODE_ENV !== 'production') {
4626 if (!maybeComponent(el)) {
4627 warn$1(`v-slot can only be used on components or <template>.`, slotBinding);
4628 }
4629 if (el.slotScope || el.slotTarget) {
4630 warn$1(`Unexpected mixed usage of different slot syntaxes.`, el);
4631 }
4632 if (el.scopedSlots) {
4633 warn$1(`To avoid scope ambiguity, the default slot should also use ` +
4634 `<template> syntax when there are other named slots.`, slotBinding);
4635 }
4636 }
4637 // add the component's children to its default slot
4638 const slots = el.scopedSlots || (el.scopedSlots = {});
4639 const { name, dynamic } = getSlotName(slotBinding);
4640 const slotContainer = (slots[name] = createASTElement('template', [], el));
4641 slotContainer.slotTarget = name;
4642 slotContainer.slotTargetDynamic = dynamic;
4643 slotContainer.children = el.children.filter((c) => {
4644 if (!c.slotScope) {
4645 c.parent = slotContainer;
4646 return true;
4647 }
4648 });
4649 slotContainer.slotScope = slotBinding.value || emptySlotScopeToken;
4650 // remove children as they are returned from scopedSlots now
4651 el.children = [];
4652 // mark el non-plain so data gets generated
4653 el.plain = false;
4654 }
4655 }
4656 }
4657}
4658function getSlotName(binding) {
4659 let name = binding.name.replace(slotRE, '');
4660 if (!name) {
4661 if (binding.name[0] !== '#') {
4662 name = 'default';
4663 }
4664 else if (process.env.NODE_ENV !== 'production') {
4665 warn$1(`v-slot shorthand syntax requires a slot name.`, binding);
4666 }
4667 }
4668 return dynamicArgRE.test(name)
4669 ? // dynamic [name]
4670 { name: name.slice(1, -1), dynamic: true }
4671 : // static name
4672 { name: `"${name}"`, dynamic: false };
4673}
4674// handle <slot/> outlets
4675function processSlotOutlet(el) {
4676 if (el.tag === 'slot') {
4677 el.slotName = getBindingAttr(el, 'name');
4678 if (process.env.NODE_ENV !== 'production' && el.key) {
4679 warn$1(`\`key\` does not work on <slot> because slots are abstract outlets ` +
4680 `and can possibly expand into multiple elements. ` +
4681 `Use the key on a wrapping element instead.`, getRawBindingAttr(el, 'key'));
4682 }
4683 }
4684}
4685function processComponent(el) {
4686 let binding;
4687 if ((binding = getBindingAttr(el, 'is'))) {
4688 el.component = binding;
4689 }
4690 if (getAndRemoveAttr(el, 'inline-template') != null) {
4691 el.inlineTemplate = true;
4692 }
4693}
4694function processAttrs(el) {
4695 const list = el.attrsList;
4696 let i, l, name, rawName, value, modifiers, syncGen, isDynamic;
4697 for (i = 0, l = list.length; i < l; i++) {
4698 name = rawName = list[i].name;
4699 value = list[i].value;
4700 if (dirRE.test(name)) {
4701 // mark element as dynamic
4702 el.hasBindings = true;
4703 // modifiers
4704 modifiers = parseModifiers(name.replace(dirRE, ''));
4705 // support .foo shorthand syntax for the .prop modifier
4706 if (modifiers) {
4707 name = name.replace(modifierRE, '');
4708 }
4709 if (bindRE.test(name)) {
4710 // v-bind
4711 name = name.replace(bindRE, '');
4712 value = parseFilters(value);
4713 isDynamic = dynamicArgRE.test(name);
4714 if (isDynamic) {
4715 name = name.slice(1, -1);
4716 }
4717 if (process.env.NODE_ENV !== 'production' && value.trim().length === 0) {
4718 warn$1(`The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`);
4719 }
4720 if (modifiers) {
4721 if (modifiers.prop && !isDynamic) {
4722 name = camelize(name);
4723 if (name === 'innerHtml')
4724 name = 'innerHTML';
4725 }
4726 if (modifiers.camel && !isDynamic) {
4727 name = camelize(name);
4728 }
4729 if (modifiers.sync) {
4730 syncGen = genAssignmentCode(value, `$event`);
4731 if (!isDynamic) {
4732 addHandler(el, `update:${camelize(name)}`, syncGen, null, false, warn$1, list[i]);
4733 if (hyphenate(name) !== camelize(name)) {
4734 addHandler(el, `update:${hyphenate(name)}`, syncGen, null, false, warn$1, list[i]);
4735 }
4736 }
4737 else {
4738 // handler w/ dynamic event name
4739 addHandler(el, `"update:"+(${name})`, syncGen, null, false, warn$1, list[i], true // dynamic
4740 );
4741 }
4742 }
4743 }
4744 if ((modifiers && modifiers.prop) ||
4745 (!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name))) {
4746 addProp(el, name, value, list[i], isDynamic);
4747 }
4748 else {
4749 addAttr(el, name, value, list[i], isDynamic);
4750 }
4751 }
4752 else if (onRE.test(name)) {
4753 // v-on
4754 name = name.replace(onRE, '');
4755 isDynamic = dynamicArgRE.test(name);
4756 if (isDynamic) {
4757 name = name.slice(1, -1);
4758 }
4759 addHandler(el, name, value, modifiers, false, warn$1, list[i], isDynamic);
4760 }
4761 else {
4762 // normal directives
4763 name = name.replace(dirRE, '');
4764 // parse arg
4765 const argMatch = name.match(argRE);
4766 let arg = argMatch && argMatch[1];
4767 isDynamic = false;
4768 if (arg) {
4769 name = name.slice(0, -(arg.length + 1));
4770 if (dynamicArgRE.test(arg)) {
4771 arg = arg.slice(1, -1);
4772 isDynamic = true;
4773 }
4774 }
4775 addDirective(el, name, rawName, value, arg, isDynamic, modifiers, list[i]);
4776 if (process.env.NODE_ENV !== 'production' && name === 'model') {
4777 checkForAliasModel(el, value);
4778 }
4779 }
4780 }
4781 else {
4782 // literal attribute
4783 if (process.env.NODE_ENV !== 'production') {
4784 const res = parseText(value, delimiters);
4785 if (res) {
4786 warn$1(`${name}="${value}": ` +
4787 'Interpolation inside attributes has been removed. ' +
4788 'Use v-bind or the colon shorthand instead. For example, ' +
4789 'instead of <div id="{{ val }}">, use <div :id="val">.', list[i]);
4790 }
4791 }
4792 addAttr(el, name, JSON.stringify(value), list[i]);
4793 // #6887 firefox doesn't update muted state if set via attribute
4794 // even immediately after element creation
4795 if (!el.component &&
4796 name === 'muted' &&
4797 platformMustUseProp(el.tag, el.attrsMap.type, name)) {
4798 addProp(el, name, 'true', list[i]);
4799 }
4800 }
4801 }
4802}
4803function checkInFor(el) {
4804 let parent = el;
4805 while (parent) {
4806 if (parent.for !== undefined) {
4807 return true;
4808 }
4809 parent = parent.parent;
4810 }
4811 return false;
4812}
4813function parseModifiers(name) {
4814 const match = name.match(modifierRE);
4815 if (match) {
4816 const ret = {};
4817 match.forEach(m => {
4818 ret[m.slice(1)] = true;
4819 });
4820 return ret;
4821 }
4822}
4823function makeAttrsMap(attrs) {
4824 const map = {};
4825 for (let i = 0, l = attrs.length; i < l; i++) {
4826 if (process.env.NODE_ENV !== 'production' && map[attrs[i].name] && !isIE && !isEdge) {
4827 warn$1('duplicate attribute: ' + attrs[i].name, attrs[i]);
4828 }
4829 map[attrs[i].name] = attrs[i].value;
4830 }
4831 return map;
4832}
4833// for script (e.g. type="x/template") or style, do not decode content
4834function isTextTag(el) {
4835 return el.tag === 'script' || el.tag === 'style';
4836}
4837function isForbiddenTag(el) {
4838 return (el.tag === 'style' ||
4839 (el.tag === 'script' &&
4840 (!el.attrsMap.type || el.attrsMap.type === 'text/javascript')));
4841}
4842const ieNSBug = /^xmlns:NS\d+/;
4843const ieNSPrefix = /^NS\d+:/;
4844/* istanbul ignore next */
4845function guardIESVGBug(attrs) {
4846 const res = [];
4847 for (let i = 0; i < attrs.length; i++) {
4848 const attr = attrs[i];
4849 if (!ieNSBug.test(attr.name)) {
4850 attr.name = attr.name.replace(ieNSPrefix, '');
4851 res.push(attr);
4852 }
4853 }
4854 return res;
4855}
4856function checkForAliasModel(el, value) {
4857 let _el = el;
4858 while (_el) {
4859 if (_el.for && _el.alias === value) {
4860 warn$1(`<${el.tag} v-model="${value}">: ` +
4861 `You are binding v-model directly to a v-for iteration alias. ` +
4862 `This will not be able to modify the v-for source array because ` +
4863 `writing to the alias is like modifying a function local variable. ` +
4864 `Consider using an array of objects and use v-model on an object property instead.`, el.rawAttrsMap['v-model']);
4865 }
4866 _el = _el.parent;
4867 }
4868}
4869
4870/**
4871 * Expand input[v-model] with dynamic type bindings into v-if-else chains
4872 * Turn this:
4873 * <input v-model="data[type]" :type="type">
4874 * into this:
4875 * <input v-if="type === 'checkbox'" type="checkbox" v-model="data[type]">
4876 * <input v-else-if="type === 'radio'" type="radio" v-model="data[type]">
4877 * <input v-else :type="type" v-model="data[type]">
4878 */
4879function preTransformNode(el, options) {
4880 if (el.tag === 'input') {
4881 const map = el.attrsMap;
4882 if (!map['v-model']) {
4883 return;
4884 }
4885 let typeBinding;
4886 if (map[':type'] || map['v-bind:type']) {
4887 typeBinding = getBindingAttr(el, 'type');
4888 }
4889 if (!map.type && !typeBinding && map['v-bind']) {
4890 typeBinding = `(${map['v-bind']}).type`;
4891 }
4892 if (typeBinding) {
4893 const ifCondition = getAndRemoveAttr(el, 'v-if', true);
4894 const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : ``;
4895 const hasElse = getAndRemoveAttr(el, 'v-else', true) != null;
4896 const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true);
4897 // 1. checkbox
4898 const branch0 = cloneASTElement(el);
4899 // process for on the main node
4900 processFor(branch0);
4901 addRawAttr(branch0, 'type', 'checkbox');
4902 processElement(branch0, options);
4903 branch0.processed = true; // prevent it from double-processed
4904 branch0.if = `(${typeBinding})==='checkbox'` + ifConditionExtra;
4905 addIfCondition(branch0, {
4906 exp: branch0.if,
4907 block: branch0
4908 });
4909 // 2. add radio else-if condition
4910 const branch1 = cloneASTElement(el);
4911 getAndRemoveAttr(branch1, 'v-for', true);
4912 addRawAttr(branch1, 'type', 'radio');
4913 processElement(branch1, options);
4914 addIfCondition(branch0, {
4915 exp: `(${typeBinding})==='radio'` + ifConditionExtra,
4916 block: branch1
4917 });
4918 // 3. other
4919 const branch2 = cloneASTElement(el);
4920 getAndRemoveAttr(branch2, 'v-for', true);
4921 addRawAttr(branch2, ':type', typeBinding);
4922 processElement(branch2, options);
4923 addIfCondition(branch0, {
4924 exp: ifCondition,
4925 block: branch2
4926 });
4927 if (hasElse) {
4928 branch0.else = true;
4929 }
4930 else if (elseIfCondition) {
4931 branch0.elseif = elseIfCondition;
4932 }
4933 return branch0;
4934 }
4935 }
4936}
4937function cloneASTElement(el) {
4938 return createASTElement(el.tag, el.attrsList.slice(), el.parent);
4939}
4940var model$1 = {
4941 preTransformNode
4942};
4943
4944var modules = [klass, style, model$1];
4945
4946let warn;
4947// in some cases, the event used has to be determined at runtime
4948// so we used some reserved tokens during compile.
4949const RANGE_TOKEN = '__r';
4950function model(el, dir, _warn) {
4951 warn = _warn;
4952 const value = dir.value;
4953 const modifiers = dir.modifiers;
4954 const tag = el.tag;
4955 const type = el.attrsMap.type;
4956 if (process.env.NODE_ENV !== 'production') {
4957 // inputs with type="file" are read only and setting the input's
4958 // value will throw an error.
4959 if (tag === 'input' && type === 'file') {
4960 warn(`<${el.tag} v-model="${value}" type="file">:\n` +
4961 `File inputs are read only. Use a v-on:change listener instead.`, el.rawAttrsMap['v-model']);
4962 }
4963 }
4964 if (el.component) {
4965 genComponentModel(el, value, modifiers);
4966 // component v-model doesn't need extra runtime
4967 return false;
4968 }
4969 else if (tag === 'select') {
4970 genSelect(el, value, modifiers);
4971 }
4972 else if (tag === 'input' && type === 'checkbox') {
4973 genCheckboxModel(el, value, modifiers);
4974 }
4975 else if (tag === 'input' && type === 'radio') {
4976 genRadioModel(el, value, modifiers);
4977 }
4978 else if (tag === 'input' || tag === 'textarea') {
4979 genDefaultModel(el, value, modifiers);
4980 }
4981 else {
4982 genComponentModel(el, value, modifiers);
4983 // component v-model doesn't need extra runtime
4984 return false;
4985 }
4986 // ensure runtime directive metadata
4987 return true;
4988}
4989function genCheckboxModel(el, value, modifiers) {
4990 const number = modifiers && modifiers.number;
4991 const valueBinding = getBindingAttr(el, 'value') || 'null';
4992 const trueValueBinding = getBindingAttr(el, 'true-value') || 'true';
4993 const falseValueBinding = getBindingAttr(el, 'false-value') || 'false';
4994 addProp(el, 'checked', `Array.isArray(${value})` +
4995 `?_i(${value},${valueBinding})>-1` +
4996 (trueValueBinding === 'true'
4997 ? `:(${value})`
4998 : `:_q(${value},${trueValueBinding})`));
4999 addHandler(el, 'change', `var $$a=${value},` +
5000 '$$el=$event.target,' +
5001 `$$c=$$el.checked?(${trueValueBinding}):(${falseValueBinding});` +
5002 'if(Array.isArray($$a)){' +
5003 `var $$v=${number ? '_n(' + valueBinding + ')' : valueBinding},` +
5004 '$$i=_i($$a,$$v);' +
5005 `if($$el.checked){$$i<0&&(${genAssignmentCode(value, '$$a.concat([$$v])')})}` +
5006 `else{$$i>-1&&(${genAssignmentCode(value, '$$a.slice(0,$$i).concat($$a.slice($$i+1))')})}` +
5007 `}else{${genAssignmentCode(value, '$$c')}}`, null, true);
5008}
5009function genRadioModel(el, value, modifiers) {
5010 const number = modifiers && modifiers.number;
5011 let valueBinding = getBindingAttr(el, 'value') || 'null';
5012 valueBinding = number ? `_n(${valueBinding})` : valueBinding;
5013 addProp(el, 'checked', `_q(${value},${valueBinding})`);
5014 addHandler(el, 'change', genAssignmentCode(value, valueBinding), null, true);
5015}
5016function genSelect(el, value, modifiers) {
5017 const number = modifiers && modifiers.number;
5018 const selectedVal = `Array.prototype.filter` +
5019 `.call($event.target.options,function(o){return o.selected})` +
5020 `.map(function(o){var val = "_value" in o ? o._value : o.value;` +
5021 `return ${number ? '_n(val)' : 'val'}})`;
5022 const assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';
5023 let code = `var $$selectedVal = ${selectedVal};`;
5024 code = `${code} ${genAssignmentCode(value, assignment)}`;
5025 addHandler(el, 'change', code, null, true);
5026}
5027function genDefaultModel(el, value, modifiers) {
5028 const type = el.attrsMap.type;
5029 // warn if v-bind:value conflicts with v-model
5030 // except for inputs with v-bind:type
5031 if (process.env.NODE_ENV !== 'production') {
5032 const value = el.attrsMap['v-bind:value'] || el.attrsMap[':value'];
5033 const typeBinding = el.attrsMap['v-bind:type'] || el.attrsMap[':type'];
5034 if (value && !typeBinding) {
5035 const binding = el.attrsMap['v-bind:value'] ? 'v-bind:value' : ':value';
5036 warn(`${binding}="${value}" conflicts with v-model on the same element ` +
5037 'because the latter already expands to a value binding internally', el.rawAttrsMap[binding]);
5038 }
5039 }
5040 const { lazy, number, trim } = modifiers || {};
5041 const needCompositionGuard = !lazy && type !== 'range';
5042 const event = lazy ? 'change' : type === 'range' ? RANGE_TOKEN : 'input';
5043 let valueExpression = '$event.target.value';
5044 if (trim) {
5045 valueExpression = `$event.target.value.trim()`;
5046 }
5047 if (number) {
5048 valueExpression = `_n(${valueExpression})`;
5049 }
5050 let code = genAssignmentCode(value, valueExpression);
5051 if (needCompositionGuard) {
5052 code = `if($event.target.composing)return;${code}`;
5053 }
5054 addProp(el, 'value', `(${value})`);
5055 addHandler(el, event, code, null, true);
5056 if (trim || number) {
5057 addHandler(el, 'blur', '$forceUpdate()');
5058 }
5059}
5060
5061function text(el, dir) {
5062 if (dir.value) {
5063 addProp(el, 'textContent', `_s(${dir.value})`, dir);
5064 }
5065}
5066
5067function html(el, dir) {
5068 if (dir.value) {
5069 addProp(el, 'innerHTML', `_s(${dir.value})`, dir);
5070 }
5071}
5072
5073var directives = {
5074 model,
5075 text,
5076 html
5077};
5078
5079const baseOptions = {
5080 expectHTML: true,
5081 modules,
5082 directives,
5083 isPreTag,
5084 isUnaryTag,
5085 mustUseProp,
5086 canBeLeftOpenTag,
5087 isReservedTag,
5088 getTagNamespace,
5089 staticKeys: genStaticKeys$1(modules)
5090};
5091
5092let isStaticKey;
5093let isPlatformReservedTag$1;
5094const genStaticKeysCached = cached(genStaticKeys);
5095/**
5096 * Goal of the optimizer: walk the generated template AST tree
5097 * and detect sub-trees that are purely static, i.e. parts of
5098 * the DOM that never needs to change.
5099 *
5100 * Once we detect these sub-trees, we can:
5101 *
5102 * 1. Hoist them into constants, so that we no longer need to
5103 * create fresh nodes for them on each re-render;
5104 * 2. Completely skip them in the patching process.
5105 */
5106function optimize$1(root, options) {
5107 if (!root)
5108 return;
5109 isStaticKey = genStaticKeysCached(options.staticKeys || '');
5110 isPlatformReservedTag$1 = options.isReservedTag || no;
5111 // first pass: mark all non-static nodes.
5112 markStatic(root);
5113 // second pass: mark static roots.
5114 markStaticRoots(root, false);
5115}
5116function genStaticKeys(keys) {
5117 return makeMap('type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap' +
5118 (keys ? ',' + keys : ''));
5119}
5120function markStatic(node) {
5121 node.static = isStatic(node);
5122 if (node.type === 1) {
5123 // do not make component slot content static. this avoids
5124 // 1. components not able to mutate slot nodes
5125 // 2. static slot content fails for hot-reloading
5126 if (!isPlatformReservedTag$1(node.tag) &&
5127 node.tag !== 'slot' &&
5128 node.attrsMap['inline-template'] == null) {
5129 return;
5130 }
5131 for (let i = 0, l = node.children.length; i < l; i++) {
5132 const child = node.children[i];
5133 markStatic(child);
5134 if (!child.static) {
5135 node.static = false;
5136 }
5137 }
5138 if (node.ifConditions) {
5139 for (let i = 1, l = node.ifConditions.length; i < l; i++) {
5140 const block = node.ifConditions[i].block;
5141 markStatic(block);
5142 if (!block.static) {
5143 node.static = false;
5144 }
5145 }
5146 }
5147 }
5148}
5149function markStaticRoots(node, isInFor) {
5150 if (node.type === 1) {
5151 if (node.static || node.once) {
5152 node.staticInFor = isInFor;
5153 }
5154 // For a node to qualify as a static root, it should have children that
5155 // are not just static text. Otherwise the cost of hoisting out will
5156 // outweigh the benefits and it's better off to just always render it fresh.
5157 if (node.static &&
5158 node.children.length &&
5159 !(node.children.length === 1 && node.children[0].type === 3)) {
5160 node.staticRoot = true;
5161 return;
5162 }
5163 else {
5164 node.staticRoot = false;
5165 }
5166 if (node.children) {
5167 for (let i = 0, l = node.children.length; i < l; i++) {
5168 markStaticRoots(node.children[i], isInFor || !!node.for);
5169 }
5170 }
5171 if (node.ifConditions) {
5172 for (let i = 1, l = node.ifConditions.length; i < l; i++) {
5173 markStaticRoots(node.ifConditions[i].block, isInFor);
5174 }
5175 }
5176 }
5177}
5178function isStatic(node) {
5179 if (node.type === 2) {
5180 // expression
5181 return false;
5182 }
5183 if (node.type === 3) {
5184 // text
5185 return true;
5186 }
5187 return !!(node.pre ||
5188 (!node.hasBindings && // no dynamic bindings
5189 !node.if &&
5190 !node.for && // not v-if or v-for or v-else
5191 !isBuiltInTag(node.tag) && // not a built-in
5192 isPlatformReservedTag$1(node.tag) && // not a component
5193 !isDirectChildOfTemplateFor(node) &&
5194 Object.keys(node).every(isStaticKey)));
5195}
5196function isDirectChildOfTemplateFor(node) {
5197 while (node.parent) {
5198 node = node.parent;
5199 if (node.tag !== 'template') {
5200 return false;
5201 }
5202 if (node.for) {
5203 return true;
5204 }
5205 }
5206 return false;
5207}
5208
5209const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/;
5210const fnInvokeRE = /\([^)]*?\);*$/;
5211const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;
5212// KeyboardEvent.keyCode aliases
5213const keyCodes = {
5214 esc: 27,
5215 tab: 9,
5216 enter: 13,
5217 space: 32,
5218 up: 38,
5219 left: 37,
5220 right: 39,
5221 down: 40,
5222 delete: [8, 46]
5223};
5224// KeyboardEvent.key aliases
5225const keyNames = {
5226 // #7880: IE11 and Edge use `Esc` for Escape key name.
5227 esc: ['Esc', 'Escape'],
5228 tab: 'Tab',
5229 enter: 'Enter',
5230 // #9112: IE11 uses `Spacebar` for Space key name.
5231 space: [' ', 'Spacebar'],
5232 // #7806: IE11 uses key names without `Arrow` prefix for arrow keys.
5233 up: ['Up', 'ArrowUp'],
5234 left: ['Left', 'ArrowLeft'],
5235 right: ['Right', 'ArrowRight'],
5236 down: ['Down', 'ArrowDown'],
5237 // #9112: IE11 uses `Del` for Delete key name.
5238 delete: ['Backspace', 'Delete', 'Del']
5239};
5240// #4868: modifiers that prevent the execution of the listener
5241// need to explicitly return null so that we can determine whether to remove
5242// the listener for .once
5243const genGuard = condition => `if(${condition})return null;`;
5244const modifierCode = {
5245 stop: '$event.stopPropagation();',
5246 prevent: '$event.preventDefault();',
5247 self: genGuard(`$event.target !== $event.currentTarget`),
5248 ctrl: genGuard(`!$event.ctrlKey`),
5249 shift: genGuard(`!$event.shiftKey`),
5250 alt: genGuard(`!$event.altKey`),
5251 meta: genGuard(`!$event.metaKey`),
5252 left: genGuard(`'button' in $event && $event.button !== 0`),
5253 middle: genGuard(`'button' in $event && $event.button !== 1`),
5254 right: genGuard(`'button' in $event && $event.button !== 2`)
5255};
5256function genHandlers(events, isNative) {
5257 const prefix = isNative ? 'nativeOn:' : 'on:';
5258 let staticHandlers = ``;
5259 let dynamicHandlers = ``;
5260 for (const name in events) {
5261 const handlerCode = genHandler(events[name]);
5262 //@ts-expect-error
5263 if (events[name] && events[name].dynamic) {
5264 dynamicHandlers += `${name},${handlerCode},`;
5265 }
5266 else {
5267 staticHandlers += `"${name}":${handlerCode},`;
5268 }
5269 }
5270 staticHandlers = `{${staticHandlers.slice(0, -1)}}`;
5271 if (dynamicHandlers) {
5272 return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])`;
5273 }
5274 else {
5275 return prefix + staticHandlers;
5276 }
5277}
5278function genHandler(handler) {
5279 if (!handler) {
5280 return 'function(){}';
5281 }
5282 if (Array.isArray(handler)) {
5283 return `[${handler.map(handler => genHandler(handler)).join(',')}]`;
5284 }
5285 const isMethodPath = simplePathRE.test(handler.value);
5286 const isFunctionExpression = fnExpRE.test(handler.value);
5287 const isFunctionInvocation = simplePathRE.test(handler.value.replace(fnInvokeRE, ''));
5288 if (!handler.modifiers) {
5289 if (isMethodPath || isFunctionExpression) {
5290 return handler.value;
5291 }
5292 return `function($event){${isFunctionInvocation ? `return ${handler.value}` : handler.value}}`; // inline statement
5293 }
5294 else {
5295 let code = '';
5296 let genModifierCode = '';
5297 const keys = [];
5298 for (const key in handler.modifiers) {
5299 if (modifierCode[key]) {
5300 genModifierCode += modifierCode[key];
5301 // left/right
5302 if (keyCodes[key]) {
5303 keys.push(key);
5304 }
5305 }
5306 else if (key === 'exact') {
5307 const modifiers = handler.modifiers;
5308 genModifierCode += genGuard(['ctrl', 'shift', 'alt', 'meta']
5309 .filter(keyModifier => !modifiers[keyModifier])
5310 .map(keyModifier => `$event.${keyModifier}Key`)
5311 .join('||'));
5312 }
5313 else {
5314 keys.push(key);
5315 }
5316 }
5317 if (keys.length) {
5318 code += genKeyFilter(keys);
5319 }
5320 // Make sure modifiers like prevent and stop get executed after key filtering
5321 if (genModifierCode) {
5322 code += genModifierCode;
5323 }
5324 const handlerCode = isMethodPath
5325 ? `return ${handler.value}.apply(null, arguments)`
5326 : isFunctionExpression
5327 ? `return (${handler.value}).apply(null, arguments)`
5328 : isFunctionInvocation
5329 ? `return ${handler.value}`
5330 : handler.value;
5331 return `function($event){${code}${handlerCode}}`;
5332 }
5333}
5334function genKeyFilter(keys) {
5335 return (
5336 // make sure the key filters only apply to KeyboardEvents
5337 // #9441: can't use 'keyCode' in $event because Chrome autofill fires fake
5338 // key events that do not have keyCode property...
5339 `if(!$event.type.indexOf('key')&&` +
5340 `${keys.map(genFilterCode).join('&&')})return null;`);
5341}
5342function genFilterCode(key) {
5343 const keyVal = parseInt(key, 10);
5344 if (keyVal) {
5345 return `$event.keyCode!==${keyVal}`;
5346 }
5347 const keyCode = keyCodes[key];
5348 const keyName = keyNames[key];
5349 return (`_k($event.keyCode,` +
5350 `${JSON.stringify(key)},` +
5351 `${JSON.stringify(keyCode)},` +
5352 `$event.key,` +
5353 `${JSON.stringify(keyName)}` +
5354 `)`);
5355}
5356
5357function on(el, dir) {
5358 if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
5359 warn$2(`v-on without argument does not support modifiers.`);
5360 }
5361 el.wrapListeners = (code) => `_g(${code},${dir.value})`;
5362}
5363
5364function bind(el, dir) {
5365 el.wrapData = (code) => {
5366 return `_b(${code},'${el.tag}',${dir.value},${dir.modifiers && dir.modifiers.prop ? 'true' : 'false'}${dir.modifiers && dir.modifiers.sync ? ',true' : ''})`;
5367 };
5368}
5369
5370var baseDirectives = {
5371 on,
5372 bind,
5373 cloak: noop
5374};
5375
5376class CodegenState {
5377 constructor(options) {
5378 this.options = options;
5379 this.warn = options.warn || baseWarn;
5380 this.transforms = pluckModuleFunction(options.modules, 'transformCode');
5381 this.dataGenFns = pluckModuleFunction(options.modules, 'genData');
5382 this.directives = extend(extend({}, baseDirectives), options.directives);
5383 const isReservedTag = options.isReservedTag || no;
5384 this.maybeComponent = (el) => !!el.component || !isReservedTag(el.tag);
5385 this.onceId = 0;
5386 this.staticRenderFns = [];
5387 this.pre = false;
5388 }
5389}
5390function generate$1(ast, options) {
5391 const state = new CodegenState(options);
5392 // fix #11483, Root level <script> tags should not be rendered.
5393 const code = ast
5394 ? ast.tag === 'script'
5395 ? 'null'
5396 : genElement(ast, state)
5397 : '_c("div")';
5398 return {
5399 render: `with(this){return ${code}}`,
5400 staticRenderFns: state.staticRenderFns
5401 };
5402}
5403function genElement(el, state) {
5404 if (el.parent) {
5405 el.pre = el.pre || el.parent.pre;
5406 }
5407 if (el.staticRoot && !el.staticProcessed) {
5408 return genStatic(el, state);
5409 }
5410 else if (el.once && !el.onceProcessed) {
5411 return genOnce(el, state);
5412 }
5413 else if (el.for && !el.forProcessed) {
5414 return genFor(el, state);
5415 }
5416 else if (el.if && !el.ifProcessed) {
5417 return genIf(el, state);
5418 }
5419 else if (el.tag === 'template' && !el.slotTarget && !state.pre) {
5420 return genChildren(el, state) || 'void 0';
5421 }
5422 else if (el.tag === 'slot') {
5423 return genSlot(el, state);
5424 }
5425 else {
5426 // component or element
5427 let code;
5428 if (el.component) {
5429 code = genComponent(el.component, el, state);
5430 }
5431 else {
5432 let data;
5433 const maybeComponent = state.maybeComponent(el);
5434 if (!el.plain || (el.pre && maybeComponent)) {
5435 data = genData(el, state);
5436 }
5437 let tag;
5438 // check if this is a component in <script setup>
5439 const bindings = state.options.bindings;
5440 if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
5441 tag = checkBindingType(bindings, el.tag);
5442 }
5443 if (!tag)
5444 tag = `'${el.tag}'`;
5445 const children = el.inlineTemplate ? null : genChildren(el, state, true);
5446 code = `_c(${tag}${data ? `,${data}` : '' // data
5447 }${children ? `,${children}` : '' // children
5448 })`;
5449 }
5450 // module transforms
5451 for (let i = 0; i < state.transforms.length; i++) {
5452 code = state.transforms[i](el, code);
5453 }
5454 return code;
5455 }
5456}
5457function checkBindingType(bindings, key) {
5458 const camelName = camelize(key);
5459 const PascalName = capitalize(camelName);
5460 const checkType = (type) => {
5461 if (bindings[key] === type) {
5462 return key;
5463 }
5464 if (bindings[camelName] === type) {
5465 return camelName;
5466 }
5467 if (bindings[PascalName] === type) {
5468 return PascalName;
5469 }
5470 };
5471 const fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
5472 checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
5473 if (fromConst) {
5474 return fromConst;
5475 }
5476 const fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
5477 checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
5478 checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
5479 if (fromMaybeRef) {
5480 return fromMaybeRef;
5481 }
5482}
5483// hoist static sub-trees out
5484function genStatic(el, state) {
5485 el.staticProcessed = true;
5486 // Some elements (templates) need to behave differently inside of a v-pre
5487 // node. All pre nodes are static roots, so we can use this as a location to
5488 // wrap a state change and reset it upon exiting the pre node.
5489 const originalPreState = state.pre;
5490 if (el.pre) {
5491 state.pre = el.pre;
5492 }
5493 state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`);
5494 state.pre = originalPreState;
5495 return `_m(${state.staticRenderFns.length - 1}${el.staticInFor ? ',true' : ''})`;
5496}
5497// v-once
5498function genOnce(el, state) {
5499 el.onceProcessed = true;
5500 if (el.if && !el.ifProcessed) {
5501 return genIf(el, state);
5502 }
5503 else if (el.staticInFor) {
5504 let key = '';
5505 let parent = el.parent;
5506 while (parent) {
5507 if (parent.for) {
5508 key = parent.key;
5509 break;
5510 }
5511 parent = parent.parent;
5512 }
5513 if (!key) {
5514 process.env.NODE_ENV !== 'production' &&
5515 state.warn(`v-once can only be used inside v-for that is keyed. `, el.rawAttrsMap['v-once']);
5516 return genElement(el, state);
5517 }
5518 return `_o(${genElement(el, state)},${state.onceId++},${key})`;
5519 }
5520 else {
5521 return genStatic(el, state);
5522 }
5523}
5524function genIf(el, state, altGen, altEmpty) {
5525 el.ifProcessed = true; // avoid recursion
5526 return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty);
5527}
5528function genIfConditions(conditions, state, altGen, altEmpty) {
5529 if (!conditions.length) {
5530 return altEmpty || '_e()';
5531 }
5532 const condition = conditions.shift();
5533 if (condition.exp) {
5534 return `(${condition.exp})?${genTernaryExp(condition.block)}:${genIfConditions(conditions, state, altGen, altEmpty)}`;
5535 }
5536 else {
5537 return `${genTernaryExp(condition.block)}`;
5538 }
5539 // v-if with v-once should generate code like (a)?_m(0):_m(1)
5540 function genTernaryExp(el) {
5541 return altGen
5542 ? altGen(el, state)
5543 : el.once
5544 ? genOnce(el, state)
5545 : genElement(el, state);
5546 }
5547}
5548function genFor(el, state, altGen, altHelper) {
5549 const exp = el.for;
5550 const alias = el.alias;
5551 const iterator1 = el.iterator1 ? `,${el.iterator1}` : '';
5552 const iterator2 = el.iterator2 ? `,${el.iterator2}` : '';
5553 if (process.env.NODE_ENV !== 'production' &&
5554 state.maybeComponent(el) &&
5555 el.tag !== 'slot' &&
5556 el.tag !== 'template' &&
5557 !el.key) {
5558 state.warn(`<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
5559 `v-for should have explicit keys. ` +
5560 `See https://v2.vuejs.org/v2/guide/list.html#key for more info.`, el.rawAttrsMap['v-for'], true /* tip */);
5561 }
5562 el.forProcessed = true; // avoid recursion
5563 return (`${altHelper || '_l'}((${exp}),` +
5564 `function(${alias}${iterator1}${iterator2}){` +
5565 `return ${(altGen || genElement)(el, state)}` +
5566 '})');
5567}
5568function genData(el, state) {
5569 let data = '{';
5570 // directives first.
5571 // directives may mutate the el's other properties before they are generated.
5572 const dirs = genDirectives(el, state);
5573 if (dirs)
5574 data += dirs + ',';
5575 // key
5576 if (el.key) {
5577 data += `key:${el.key},`;
5578 }
5579 // ref
5580 if (el.ref) {
5581 data += `ref:${el.ref},`;
5582 }
5583 if (el.refInFor) {
5584 data += `refInFor:true,`;
5585 }
5586 // pre
5587 if (el.pre) {
5588 data += `pre:true,`;
5589 }
5590 // record original tag name for components using "is" attribute
5591 if (el.component) {
5592 data += `tag:"${el.tag}",`;
5593 }
5594 // module data generation functions
5595 for (let i = 0; i < state.dataGenFns.length; i++) {
5596 data += state.dataGenFns[i](el);
5597 }
5598 // attributes
5599 if (el.attrs) {
5600 data += `attrs:${genProps(el.attrs)},`;
5601 }
5602 // DOM props
5603 if (el.props) {
5604 data += `domProps:${genProps(el.props)},`;
5605 }
5606 // event handlers
5607 if (el.events) {
5608 data += `${genHandlers(el.events, false)},`;
5609 }
5610 if (el.nativeEvents) {
5611 data += `${genHandlers(el.nativeEvents, true)},`;
5612 }
5613 // slot target
5614 // only for non-scoped slots
5615 if (el.slotTarget && !el.slotScope) {
5616 data += `slot:${el.slotTarget},`;
5617 }
5618 // scoped slots
5619 if (el.scopedSlots) {
5620 data += `${genScopedSlots(el, el.scopedSlots, state)},`;
5621 }
5622 // component v-model
5623 if (el.model) {
5624 data += `model:{value:${el.model.value},callback:${el.model.callback},expression:${el.model.expression}},`;
5625 }
5626 // inline-template
5627 if (el.inlineTemplate) {
5628 const inlineTemplate = genInlineTemplate(el, state);
5629 if (inlineTemplate) {
5630 data += `${inlineTemplate},`;
5631 }
5632 }
5633 data = data.replace(/,$/, '') + '}';
5634 // v-bind dynamic argument wrap
5635 // v-bind with dynamic arguments must be applied using the same v-bind object
5636 // merge helper so that class/style/mustUseProp attrs are handled correctly.
5637 if (el.dynamicAttrs) {
5638 data = `_b(${data},"${el.tag}",${genProps(el.dynamicAttrs)})`;
5639 }
5640 // v-bind data wrap
5641 if (el.wrapData) {
5642 data = el.wrapData(data);
5643 }
5644 // v-on data wrap
5645 if (el.wrapListeners) {
5646 data = el.wrapListeners(data);
5647 }
5648 return data;
5649}
5650function genDirectives(el, state) {
5651 const dirs = el.directives;
5652 if (!dirs)
5653 return;
5654 let res = 'directives:[';
5655 let hasRuntime = false;
5656 let i, l, dir, needRuntime;
5657 for (i = 0, l = dirs.length; i < l; i++) {
5658 dir = dirs[i];
5659 needRuntime = true;
5660 const gen = state.directives[dir.name];
5661 if (gen) {
5662 // compile-time directive that manipulates AST.
5663 // returns true if it also needs a runtime counterpart.
5664 needRuntime = !!gen(el, dir, state.warn);
5665 }
5666 if (needRuntime) {
5667 hasRuntime = true;
5668 res += `{name:"${dir.name}",rawName:"${dir.rawName}"${dir.value
5669 ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}`
5670 : ''}${dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''}${dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''}},`;
5671 }
5672 }
5673 if (hasRuntime) {
5674 return res.slice(0, -1) + ']';
5675 }
5676}
5677function genInlineTemplate(el, state) {
5678 const ast = el.children[0];
5679 if (process.env.NODE_ENV !== 'production' && (el.children.length !== 1 || ast.type !== 1)) {
5680 state.warn('Inline-template components must have exactly one child element.', { start: el.start });
5681 }
5682 if (ast && ast.type === 1) {
5683 const inlineRenderFns = generate$1(ast, state.options);
5684 return `inlineTemplate:{render:function(){${inlineRenderFns.render}},staticRenderFns:[${inlineRenderFns.staticRenderFns
5685 .map(code => `function(){${code}}`)
5686 .join(',')}]}`;
5687 }
5688}
5689function genScopedSlots(el, slots, state) {
5690 // by default scoped slots are considered "stable", this allows child
5691 // components with only scoped slots to skip forced updates from parent.
5692 // but in some cases we have to bail-out of this optimization
5693 // for example if the slot contains dynamic names, has v-if or v-for on them...
5694 let needsForceUpdate = el.for ||
5695 Object.keys(slots).some(key => {
5696 const slot = slots[key];
5697 return (slot.slotTargetDynamic || slot.if || slot.for || containsSlotChild(slot) // is passing down slot from parent which may be dynamic
5698 );
5699 });
5700 // #9534: if a component with scoped slots is inside a conditional branch,
5701 // it's possible for the same component to be reused but with different
5702 // compiled slot content. To avoid that, we generate a unique key based on
5703 // the generated code of all the slot contents.
5704 let needsKey = !!el.if;
5705 // OR when it is inside another scoped slot or v-for (the reactivity may be
5706 // disconnected due to the intermediate scope variable)
5707 // #9438, #9506
5708 // TODO: this can be further optimized by properly analyzing in-scope bindings
5709 // and skip force updating ones that do not actually use scope variables.
5710 if (!needsForceUpdate) {
5711 let parent = el.parent;
5712 while (parent) {
5713 if ((parent.slotScope && parent.slotScope !== emptySlotScopeToken) ||
5714 parent.for) {
5715 needsForceUpdate = true;
5716 break;
5717 }
5718 if (parent.if) {
5719 needsKey = true;
5720 }
5721 parent = parent.parent;
5722 }
5723 }
5724 const generatedSlots = Object.keys(slots)
5725 .map(key => genScopedSlot(slots[key], state))
5726 .join(',');
5727 return `scopedSlots:_u([${generatedSlots}]${needsForceUpdate ? `,null,true` : ``}${!needsForceUpdate && needsKey ? `,null,false,${hash(generatedSlots)}` : ``})`;
5728}
5729function hash(str) {
5730 let hash = 5381;
5731 let i = str.length;
5732 while (i) {
5733 hash = (hash * 33) ^ str.charCodeAt(--i);
5734 }
5735 return hash >>> 0;
5736}
5737function containsSlotChild(el) {
5738 if (el.type === 1) {
5739 if (el.tag === 'slot') {
5740 return true;
5741 }
5742 return el.children.some(containsSlotChild);
5743 }
5744 return false;
5745}
5746function genScopedSlot(el, state) {
5747 const isLegacySyntax = el.attrsMap['slot-scope'];
5748 if (el.if && !el.ifProcessed && !isLegacySyntax) {
5749 return genIf(el, state, genScopedSlot, `null`);
5750 }
5751 if (el.for && !el.forProcessed) {
5752 return genFor(el, state, genScopedSlot);
5753 }
5754 const slotScope = el.slotScope === emptySlotScopeToken ? `` : String(el.slotScope);
5755 const fn = `function(${slotScope}){` +
5756 `return ${el.tag === 'template'
5757 ? el.if && isLegacySyntax
5758 ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
5759 : genChildren(el, state) || 'undefined'
5760 : genElement(el, state)}}`;
5761 // reverse proxy v-slot without scope on this.$slots
5762 const reverseProxy = slotScope ? `` : `,proxy:true`;
5763 return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`;
5764}
5765function genChildren(el, state, checkSkip, altGenElement, altGenNode) {
5766 const children = el.children;
5767 if (children.length) {
5768 const el = children[0];
5769 // optimize single v-for
5770 if (children.length === 1 &&
5771 el.for &&
5772 el.tag !== 'template' &&
5773 el.tag !== 'slot') {
5774 const normalizationType = checkSkip
5775 ? state.maybeComponent(el)
5776 ? `,1`
5777 : `,0`
5778 : ``;
5779 return `${(altGenElement || genElement)(el, state)}${normalizationType}`;
5780 }
5781 const normalizationType = checkSkip
5782 ? getNormalizationType(children, state.maybeComponent)
5783 : 0;
5784 const gen = altGenNode || genNode;
5785 return `[${children.map(c => gen(c, state)).join(',')}]${normalizationType ? `,${normalizationType}` : ''}`;
5786 }
5787}
5788// determine the normalization needed for the children array.
5789// 0: no normalization needed
5790// 1: simple normalization needed (possible 1-level deep nested array)
5791// 2: full normalization needed
5792function getNormalizationType(children, maybeComponent) {
5793 let res = 0;
5794 for (let i = 0; i < children.length; i++) {
5795 const el = children[i];
5796 if (el.type !== 1) {
5797 continue;
5798 }
5799 if (needsNormalization(el) ||
5800 (el.ifConditions &&
5801 el.ifConditions.some(c => needsNormalization(c.block)))) {
5802 res = 2;
5803 break;
5804 }
5805 if (maybeComponent(el) ||
5806 (el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))) {
5807 res = 1;
5808 }
5809 }
5810 return res;
5811}
5812function needsNormalization(el) {
5813 return el.for !== undefined || el.tag === 'template' || el.tag === 'slot';
5814}
5815function genNode(node, state) {
5816 if (node.type === 1) {
5817 return genElement(node, state);
5818 }
5819 else if (node.type === 3 && node.isComment) {
5820 return genComment(node);
5821 }
5822 else {
5823 return genText(node);
5824 }
5825}
5826function genText(text) {
5827 return `_v(${text.type === 2
5828 ? text.expression // no need for () because already wrapped in _s()
5829 : transformSpecialNewlines(JSON.stringify(text.text))})`;
5830}
5831function genComment(comment) {
5832 return `_e(${JSON.stringify(comment.text)})`;
5833}
5834function genSlot(el, state) {
5835 const slotName = el.slotName || '"default"';
5836 const children = genChildren(el, state);
5837 let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`;
5838 const attrs = el.attrs || el.dynamicAttrs
5839 ? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
5840 // slot props are camelized
5841 name: camelize(attr.name),
5842 value: attr.value,
5843 dynamic: attr.dynamic
5844 })))
5845 : null;
5846 const bind = el.attrsMap['v-bind'];
5847 if ((attrs || bind) && !children) {
5848 res += `,null`;
5849 }
5850 if (attrs) {
5851 res += `,${attrs}`;
5852 }
5853 if (bind) {
5854 res += `${attrs ? '' : ',null'},${bind}`;
5855 }
5856 return res + ')';
5857}
5858// componentName is el.component, take it as argument to shun flow's pessimistic refinement
5859function genComponent(componentName, el, state) {
5860 const children = el.inlineTemplate ? null : genChildren(el, state, true);
5861 return `_c(${componentName},${genData(el, state)}${children ? `,${children}` : ''})`;
5862}
5863function genProps(props) {
5864 let staticProps = ``;
5865 let dynamicProps = ``;
5866 for (let i = 0; i < props.length; i++) {
5867 const prop = props[i];
5868 const value = transformSpecialNewlines(prop.value);
5869 if (prop.dynamic) {
5870 dynamicProps += `${prop.name},${value},`;
5871 }
5872 else {
5873 staticProps += `"${prop.name}":${value},`;
5874 }
5875 }
5876 staticProps = `{${staticProps.slice(0, -1)}}`;
5877 if (dynamicProps) {
5878 return `_d(${staticProps},[${dynamicProps.slice(0, -1)}])`;
5879 }
5880 else {
5881 return staticProps;
5882 }
5883}
5884// #3895, #4268
5885function transformSpecialNewlines(text) {
5886 return text.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
5887}
5888
5889// these keywords should not appear inside expressions, but operators like
5890// typeof, instanceof and in are allowed
5891const prohibitedKeywordRE = new RegExp('\\b' +
5892 ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
5893 'super,throw,while,yield,delete,export,import,return,switch,default,' +
5894 'extends,finally,continue,debugger,function,arguments')
5895 .split(',')
5896 .join('\\b|\\b') +
5897 '\\b');
5898// these unary operators should not be used as property/method names
5899const unaryOperatorsRE = new RegExp('\\b' +
5900 'delete,typeof,void'.split(',').join('\\s*\\([^\\)]*\\)|\\b') +
5901 '\\s*\\([^\\)]*\\)');
5902// strip strings in expressions
5903const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
5904// detect problematic expressions in a template
5905function detectErrors(ast, warn) {
5906 if (ast) {
5907 checkNode(ast, warn);
5908 }
5909}
5910function checkNode(node, warn) {
5911 if (node.type === 1) {
5912 for (const name in node.attrsMap) {
5913 if (dirRE.test(name)) {
5914 const value = node.attrsMap[name];
5915 if (value) {
5916 const range = node.rawAttrsMap[name];
5917 if (name === 'v-for') {
5918 checkFor(node, `v-for="${value}"`, warn, range);
5919 }
5920 else if (name === 'v-slot' || name[0] === '#') {
5921 checkFunctionParameterExpression(value, `${name}="${value}"`, warn, range);
5922 }
5923 else if (onRE.test(name)) {
5924 checkEvent(value, `${name}="${value}"`, warn, range);
5925 }
5926 else {
5927 checkExpression(value, `${name}="${value}"`, warn, range);
5928 }
5929 }
5930 }
5931 }
5932 if (node.children) {
5933 for (let i = 0; i < node.children.length; i++) {
5934 checkNode(node.children[i], warn);
5935 }
5936 }
5937 }
5938 else if (node.type === 2) {
5939 checkExpression(node.expression, node.text, warn, node);
5940 }
5941}
5942function checkEvent(exp, text, warn, range) {
5943 const stripped = exp.replace(stripStringRE, '');
5944 const keywordMatch = stripped.match(unaryOperatorsRE);
5945 if (keywordMatch && stripped.charAt(keywordMatch.index - 1) !== '$') {
5946 warn(`avoid using JavaScript unary operator as property name: ` +
5947 `"${keywordMatch[0]}" in expression ${text.trim()}`, range);
5948 }
5949 checkExpression(exp, text, warn, range);
5950}
5951function checkFor(node, text, warn, range) {
5952 checkExpression(node.for || '', text, warn, range);
5953 checkIdentifier(node.alias, 'v-for alias', text, warn, range);
5954 checkIdentifier(node.iterator1, 'v-for iterator', text, warn, range);
5955 checkIdentifier(node.iterator2, 'v-for iterator', text, warn, range);
5956}
5957function checkIdentifier(ident, type, text, warn, range) {
5958 if (typeof ident === 'string') {
5959 try {
5960 new Function(`var ${ident}=_`);
5961 }
5962 catch (e) {
5963 warn(`invalid ${type} "${ident}" in expression: ${text.trim()}`, range);
5964 }
5965 }
5966}
5967function checkExpression(exp, text, warn, range) {
5968 try {
5969 new Function(`return ${exp}`);
5970 }
5971 catch (e) {
5972 const keywordMatch = exp
5973 .replace(stripStringRE, '')
5974 .match(prohibitedKeywordRE);
5975 if (keywordMatch) {
5976 warn(`avoid using JavaScript keyword as property name: ` +
5977 `"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`, range);
5978 }
5979 else {
5980 warn(`invalid expression: ${e.message} in\n\n` +
5981 ` ${exp}\n\n` +
5982 ` Raw expression: ${text.trim()}\n`, range);
5983 }
5984 }
5985}
5986function checkFunctionParameterExpression(exp, text, warn, range) {
5987 try {
5988 new Function(exp, '');
5989 }
5990 catch (e) {
5991 warn(`invalid function parameter expression: ${e.message} in\n\n` +
5992 ` ${exp}\n\n` +
5993 ` Raw expression: ${text.trim()}\n`, range);
5994 }
5995}
5996
5997const range = 2;
5998function generateCodeFrame(source, start = 0, end = source.length) {
5999 const lines = source.split(/\r?\n/);
6000 let count = 0;
6001 const res = [];
6002 for (let i = 0; i < lines.length; i++) {
6003 count += lines[i].length + 1;
6004 if (count >= start) {
6005 for (let j = i - range; j <= i + range || end > count; j++) {
6006 if (j < 0 || j >= lines.length)
6007 continue;
6008 res.push(`${j + 1}${repeat(` `, 3 - String(j + 1).length)}| ${lines[j]}`);
6009 const lineLength = lines[j].length;
6010 if (j === i) {
6011 // push underline
6012 const pad = start - (count - lineLength) + 1;
6013 const length = end > count ? lineLength - pad : end - start;
6014 res.push(` | ` + repeat(` `, pad) + repeat(`^`, length));
6015 }
6016 else if (j > i) {
6017 if (end > count) {
6018 const length = Math.min(end - count, lineLength);
6019 res.push(` | ` + repeat(`^`, length));
6020 }
6021 count += lineLength + 1;
6022 }
6023 }
6024 break;
6025 }
6026 }
6027 return res.join('\n');
6028}
6029function repeat(str, n) {
6030 let result = '';
6031 if (n > 0) {
6032 // eslint-disable-next-line no-constant-condition
6033 while (true) {
6034 // eslint-disable-line
6035 if (n & 1)
6036 result += str;
6037 n >>>= 1;
6038 if (n <= 0)
6039 break;
6040 str += str;
6041 }
6042 }
6043 return result;
6044}
6045
6046function createFunction(code, errors) {
6047 try {
6048 return new Function(code);
6049 }
6050 catch (err) {
6051 errors.push({ err, code });
6052 return noop;
6053 }
6054}
6055function createCompileToFunctionFn(compile) {
6056 const cache = Object.create(null);
6057 return function compileToFunctions(template, options, vm) {
6058 options = extend({}, options);
6059 const warn = options.warn || warn$2;
6060 delete options.warn;
6061 /* istanbul ignore if */
6062 if (process.env.NODE_ENV !== 'production') {
6063 // detect possible CSP restriction
6064 try {
6065 new Function('return 1');
6066 }
6067 catch (e) {
6068 if (e.toString().match(/unsafe-eval|CSP/)) {
6069 warn('It seems you are using the standalone build of Vue.js in an ' +
6070 'environment with Content Security Policy that prohibits unsafe-eval. ' +
6071 'The template compiler cannot work in this environment. Consider ' +
6072 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
6073 'templates into render functions.');
6074 }
6075 }
6076 }
6077 // check cache
6078 const key = options.delimiters
6079 ? String(options.delimiters) + template
6080 : template;
6081 if (cache[key]) {
6082 return cache[key];
6083 }
6084 // compile
6085 const compiled = compile(template, options);
6086 // check compilation errors/tips
6087 if (process.env.NODE_ENV !== 'production') {
6088 if (compiled.errors && compiled.errors.length) {
6089 if (options.outputSourceRange) {
6090 compiled.errors.forEach(e => {
6091 warn(`Error compiling template:\n\n${e.msg}\n\n` +
6092 generateCodeFrame(template, e.start, e.end), vm);
6093 });
6094 }
6095 else {
6096 warn(`Error compiling template:\n\n${template}\n\n` +
6097 compiled.errors.map(e => `- ${e}`).join('\n') +
6098 '\n', vm);
6099 }
6100 }
6101 if (compiled.tips && compiled.tips.length) {
6102 if (options.outputSourceRange) {
6103 compiled.tips.forEach(e => tip(e.msg, vm));
6104 }
6105 else {
6106 compiled.tips.forEach(msg => tip(msg, vm));
6107 }
6108 }
6109 }
6110 // turn code into functions
6111 const res = {};
6112 const fnGenErrors = [];
6113 res.render = createFunction(compiled.render, fnGenErrors);
6114 res.staticRenderFns = compiled.staticRenderFns.map(code => {
6115 return createFunction(code, fnGenErrors);
6116 });
6117 // check function generation errors.
6118 // this should only happen if there is a bug in the compiler itself.
6119 // mostly for codegen development use
6120 /* istanbul ignore if */
6121 if (process.env.NODE_ENV !== 'production') {
6122 if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
6123 warn(`Failed to generate render function:\n\n` +
6124 fnGenErrors
6125 .map(({ err, code }) => `${err.toString()} in\n\n${code}\n`)
6126 .join('\n'), vm);
6127 }
6128 }
6129 return (cache[key] = res);
6130 };
6131}
6132
6133function createCompilerCreator(baseCompile) {
6134 return function createCompiler(baseOptions) {
6135 function compile(template, options) {
6136 const finalOptions = Object.create(baseOptions);
6137 const errors = [];
6138 const tips = [];
6139 let warn = (msg, range, tip) => {
6140 (tip ? tips : errors).push(msg);
6141 };
6142 if (options) {
6143 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
6144 // $flow-disable-line
6145 const leadingSpaceLength = template.match(/^\s*/)[0].length;
6146 warn = (msg, range, tip) => {
6147 const data = typeof msg === 'string' ? { msg } : msg;
6148 if (range) {
6149 if (range.start != null) {
6150 data.start = range.start + leadingSpaceLength;
6151 }
6152 if (range.end != null) {
6153 data.end = range.end + leadingSpaceLength;
6154 }
6155 }
6156 (tip ? tips : errors).push(data);
6157 };
6158 }
6159 // merge custom modules
6160 if (options.modules) {
6161 finalOptions.modules = (baseOptions.modules || []).concat(options.modules);
6162 }
6163 // merge custom directives
6164 if (options.directives) {
6165 finalOptions.directives = extend(Object.create(baseOptions.directives || null), options.directives);
6166 }
6167 // copy other options
6168 for (const key in options) {
6169 if (key !== 'modules' && key !== 'directives') {
6170 finalOptions[key] = options[key];
6171 }
6172 }
6173 }
6174 finalOptions.warn = warn;
6175 const compiled = baseCompile(template.trim(), finalOptions);
6176 if (process.env.NODE_ENV !== 'production') {
6177 detectErrors(compiled.ast, warn);
6178 }
6179 compiled.errors = errors;
6180 compiled.tips = tips;
6181 return compiled;
6182 }
6183 return {
6184 compile,
6185 compileToFunctions: createCompileToFunctionFn(compile)
6186 };
6187 };
6188}
6189
6190// `createCompilerCreator` allows creating compilers that use alternative
6191// parser/optimizer/codegen, e.g the SSR optimizing compiler.
6192// Here we just export a default compiler using the default parts.
6193const createCompiler$1 = createCompilerCreator(function baseCompile(template, options) {
6194 const ast = parse(template.trim(), options);
6195 if (options.optimize !== false) {
6196 optimize$1(ast, options);
6197 }
6198 const code = generate$1(ast, options);
6199 return {
6200 ast,
6201 render: code.render,
6202 staticRenderFns: code.staticRenderFns
6203 };
6204});
6205
6206const { compile: compile$1, compileToFunctions: compileToFunctions$1 } = createCompiler$1(baseOptions);
6207
6208const isAttr = makeMap('accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
6209 'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
6210 'checked,cite,class,code,codebase,color,cols,colspan,content,' +
6211 'contenteditable,contextmenu,controls,coords,data,datetime,default,' +
6212 'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,for,' +
6213 'form,formaction,headers,height,hidden,high,href,hreflang,http-equiv,' +
6214 'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
6215 'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
6216 'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
6217 'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
6218 'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
6219 'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
6220 'target,title,usemap,value,width,wrap');
6221/* istanbul ignore next */
6222const isRenderableAttr = (name) => {
6223 return (isAttr(name) || name.indexOf('data-') === 0 || name.indexOf('aria-') === 0);
6224};
6225const propsToAttrMap = {
6226 acceptCharset: 'accept-charset',
6227 className: 'class',
6228 htmlFor: 'for',
6229 httpEquiv: 'http-equiv'
6230};
6231const ESC = {
6232 '<': '&lt;',
6233 '>': '&gt;',
6234 '"': '&quot;',
6235 '&': '&amp;'
6236};
6237function escape(s) {
6238 return s.replace(/[<>"&]/g, escapeChar);
6239}
6240function escapeChar(a) {
6241 return ESC[a] || a;
6242}
6243
6244const plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/;
6245// let the model AST transform translate v-model into appropriate
6246// props bindings
6247function applyModelTransform(el, state) {
6248 if (el.directives) {
6249 for (let i = 0; i < el.directives.length; i++) {
6250 const dir = el.directives[i];
6251 if (dir.name === 'model') {
6252 state.directives.model(el, dir, state.warn);
6253 // remove value for textarea as its converted to text
6254 if (el.tag === 'textarea' && el.props) {
6255 el.props = el.props.filter(p => p.name !== 'value');
6256 }
6257 break;
6258 }
6259 }
6260 }
6261}
6262function genAttrSegments(attrs) {
6263 return attrs.map(({ name, value }) => genAttrSegment(name, value));
6264}
6265function genDOMPropSegments(props, attrs) {
6266 const segments = [];
6267 props.forEach(({ name, value }) => {
6268 name = propsToAttrMap[name] || name.toLowerCase();
6269 if (isRenderableAttr(name) &&
6270 !(attrs && attrs.some(a => a.name === name))) {
6271 segments.push(genAttrSegment(name, value));
6272 }
6273 });
6274 return segments;
6275}
6276function genAttrSegment(name, value) {
6277 if (plainStringRE.test(value)) {
6278 // force double quote
6279 value = value.replace(/^'|'$/g, '"');
6280 // force enumerated attr to "true"
6281 if (isEnumeratedAttr(name) && value !== `"false"`) {
6282 value = `"true"`;
6283 }
6284 return {
6285 type: RAW,
6286 value: isBooleanAttr(name)
6287 ? ` ${name}="${name}"`
6288 : value === '""'
6289 ? ` ${name}`
6290 : ` ${name}="${JSON.parse(value)}"`
6291 };
6292 }
6293 else {
6294 return {
6295 type: EXPRESSION,
6296 value: `_ssrAttr(${JSON.stringify(name)},${value})`
6297 };
6298 }
6299}
6300function genClassSegments(staticClass, classBinding) {
6301 if (staticClass && !classBinding) {
6302 return [{ type: RAW, value: ` class="${JSON.parse(staticClass)}"` }];
6303 }
6304 else {
6305 return [
6306 {
6307 type: EXPRESSION,
6308 value: `_ssrClass(${staticClass || 'null'},${classBinding || 'null'})`
6309 }
6310 ];
6311 }
6312}
6313function genStyleSegments(staticStyle, parsedStaticStyle, styleBinding, vShowExpression) {
6314 if (staticStyle && !styleBinding && !vShowExpression) {
6315 return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }];
6316 }
6317 else {
6318 return [
6319 {
6320 type: EXPRESSION,
6321 value: `_ssrStyle(${parsedStaticStyle || 'null'},${styleBinding || 'null'}, ${vShowExpression
6322 ? `{ display: (${vShowExpression}) ? '' : 'none' }`
6323 : 'null'})`
6324 }
6325 ];
6326 }
6327}
6328
6329/**
6330 * In SSR, the vdom tree is generated only once and never patched, so
6331 * we can optimize most element / trees into plain string render functions.
6332 * The SSR optimizer walks the AST tree to detect optimizable elements and trees.
6333 *
6334 * The criteria for SSR optimizability is quite a bit looser than static tree
6335 * detection (which is designed for client re-render). In SSR we bail only for
6336 * components/slots/custom directives.
6337 */
6338// optimizability constants
6339const optimizability = {
6340 FALSE: 0,
6341 FULL: 1,
6342 SELF: 2,
6343 CHILDREN: 3,
6344 PARTIAL: 4 // self un-optimizable with some un-optimizable children
6345};
6346let isPlatformReservedTag;
6347function optimize(root, options) {
6348 if (!root)
6349 return;
6350 isPlatformReservedTag = options.isReservedTag || no;
6351 walk(root, true);
6352}
6353function walk(node, isRoot) {
6354 if (isUnOptimizableTree(node)) {
6355 node.ssrOptimizability = optimizability.FALSE;
6356 return;
6357 }
6358 // root node or nodes with custom directives should always be a VNode
6359 const selfUnoptimizable = isRoot || hasCustomDirective(node);
6360 const check = child => {
6361 if (child.ssrOptimizability !== optimizability.FULL) {
6362 node.ssrOptimizability = selfUnoptimizable
6363 ? optimizability.PARTIAL
6364 : optimizability.SELF;
6365 }
6366 };
6367 if (selfUnoptimizable) {
6368 node.ssrOptimizability = optimizability.CHILDREN;
6369 }
6370 if (node.type === 1) {
6371 for (let i = 0, l = node.children.length; i < l; i++) {
6372 const child = node.children[i];
6373 walk(child);
6374 check(child);
6375 }
6376 if (node.ifConditions) {
6377 for (let i = 1, l = node.ifConditions.length; i < l; i++) {
6378 const block = node.ifConditions[i].block;
6379 walk(block, isRoot);
6380 check(block);
6381 }
6382 }
6383 if (node.ssrOptimizability == null ||
6384 (!isRoot && (node.attrsMap['v-html'] || node.attrsMap['v-text']))) {
6385 node.ssrOptimizability = optimizability.FULL;
6386 }
6387 else {
6388 node.children = optimizeSiblings(node);
6389 }
6390 }
6391 else {
6392 node.ssrOptimizability = optimizability.FULL;
6393 }
6394}
6395function optimizeSiblings(el) {
6396 const children = el.children;
6397 const optimizedChildren = [];
6398 let currentOptimizableGroup = [];
6399 const pushGroup = () => {
6400 if (currentOptimizableGroup.length) {
6401 optimizedChildren.push({
6402 type: 1,
6403 parent: el,
6404 tag: 'template',
6405 attrsList: [],
6406 attrsMap: {},
6407 rawAttrsMap: {},
6408 children: currentOptimizableGroup,
6409 ssrOptimizability: optimizability.FULL
6410 });
6411 }
6412 currentOptimizableGroup = [];
6413 };
6414 for (let i = 0; i < children.length; i++) {
6415 const c = children[i];
6416 if (c.ssrOptimizability === optimizability.FULL) {
6417 currentOptimizableGroup.push(c);
6418 }
6419 else {
6420 // wrap fully-optimizable adjacent siblings inside a template tag
6421 // so that they can be optimized into a single ssrNode by codegen
6422 pushGroup();
6423 optimizedChildren.push(c);
6424 }
6425 }
6426 pushGroup();
6427 return optimizedChildren;
6428}
6429function isUnOptimizableTree(node) {
6430 if (node.type === 2 || node.type === 3) {
6431 // text or expression
6432 return false;
6433 }
6434 return (isBuiltInTag(node.tag) || // built-in (slot, component)
6435 !isPlatformReservedTag(node.tag) || // custom component
6436 !!node.component || // "is" component
6437 isSelectWithModel(node) // <select v-model> requires runtime inspection
6438 );
6439}
6440const isBuiltInDir = makeMap('text,html,show,on,bind,model,pre,cloak,once');
6441function hasCustomDirective(node) {
6442 return (node.type === 1 &&
6443 node.directives &&
6444 node.directives.some(d => !isBuiltInDir(d.name)));
6445}
6446// <select v-model> cannot be optimized because it requires a runtime check
6447// to determine proper selected option
6448function isSelectWithModel(node) {
6449 return (node.type === 1 &&
6450 node.tag === 'select' &&
6451 node.directives != null &&
6452 node.directives.some(d => d.name === 'model'));
6453}
6454
6455// The SSR codegen is essentially extending the default codegen to handle
6456// segment types
6457const RAW = 0;
6458const INTERPOLATION = 1;
6459const EXPRESSION = 2;
6460function generate(ast, options) {
6461 const state = new CodegenState(options);
6462 const code = ast ? genSSRElement(ast, state) : '_c("div")';
6463 return {
6464 render: `with(this){return ${code}}`,
6465 staticRenderFns: state.staticRenderFns
6466 };
6467}
6468function genSSRElement(el, state) {
6469 if (el.for && !el.forProcessed) {
6470 return genFor(el, state, genSSRElement);
6471 }
6472 else if (el.if && !el.ifProcessed) {
6473 return genIf(el, state, genSSRElement);
6474 }
6475 else if (el.tag === 'template' && !el.slotTarget) {
6476 return el.ssrOptimizability === optimizability.FULL
6477 ? genChildrenAsStringNode(el, state)
6478 : genSSRChildren(el, state) || 'void 0';
6479 }
6480 switch (el.ssrOptimizability) {
6481 case optimizability.FULL:
6482 // stringify whole tree
6483 return genStringElement(el, state);
6484 case optimizability.SELF:
6485 // stringify self and check children
6486 return genStringElementWithChildren(el, state);
6487 case optimizability.CHILDREN:
6488 // generate self as VNode and stringify children
6489 return genNormalElement(el, state, true);
6490 case optimizability.PARTIAL:
6491 // generate self as VNode and check children
6492 return genNormalElement(el, state, false);
6493 default:
6494 // bail whole tree
6495 return genElement(el, state);
6496 }
6497}
6498function genNormalElement(el, state, stringifyChildren) {
6499 const data = el.plain ? undefined : genData(el, state);
6500 const children = stringifyChildren
6501 ? `[${genChildrenAsStringNode(el, state)}]`
6502 : genSSRChildren(el, state, true);
6503 return `_c('${el.tag}'${data ? `,${data}` : ''}${children ? `,${children}` : ''})`;
6504}
6505function genSSRChildren(el, state, checkSkip) {
6506 return genChildren(el, state, checkSkip, genSSRElement, genSSRNode);
6507}
6508function genSSRNode(el, state) {
6509 return el.type === 1 ? genSSRElement(el, state) : genText(el);
6510}
6511function genChildrenAsStringNode(el, state) {
6512 return el.children.length
6513 ? `_ssrNode(${flattenSegments(childrenToSegments(el, state))})`
6514 : '';
6515}
6516function genStringElement(el, state) {
6517 return `_ssrNode(${elementToString(el, state)})`;
6518}
6519function genStringElementWithChildren(el, state) {
6520 const children = genSSRChildren(el, state, true);
6521 return `_ssrNode(${flattenSegments(elementToOpenTagSegments(el, state))},"</${el.tag}>"${children ? `,${children}` : ''})`;
6522}
6523function elementToString(el, state) {
6524 return `(${flattenSegments(elementToSegments(el, state))})`;
6525}
6526function elementToSegments(el, state) {
6527 // v-for / v-if
6528 if (el.for && !el.forProcessed) {
6529 el.forProcessed = true;
6530 return [
6531 {
6532 type: EXPRESSION,
6533 value: genFor(el, state, elementToString, '_ssrList')
6534 }
6535 ];
6536 }
6537 else if (el.if && !el.ifProcessed) {
6538 el.ifProcessed = true;
6539 return [
6540 {
6541 type: EXPRESSION,
6542 value: genIf(el, state, elementToString, '"<!---->"')
6543 }
6544 ];
6545 }
6546 else if (el.tag === 'template') {
6547 return childrenToSegments(el, state);
6548 }
6549 const openSegments = elementToOpenTagSegments(el, state);
6550 const childrenSegments = childrenToSegments(el, state);
6551 const { isUnaryTag } = state.options;
6552 const close = isUnaryTag && isUnaryTag(el.tag)
6553 ? []
6554 : [{ type: RAW, value: `</${el.tag}>` }];
6555 return openSegments.concat(childrenSegments, close);
6556}
6557function elementToOpenTagSegments(el, state) {
6558 applyModelTransform(el, state);
6559 let binding;
6560 const segments = [{ type: RAW, value: `<${el.tag}` }];
6561 // attrs
6562 if (el.attrs) {
6563 segments.push.apply(segments, genAttrSegments(el.attrs));
6564 }
6565 // domProps
6566 if (el.props) {
6567 segments.push.apply(segments, genDOMPropSegments(el.props, el.attrs));
6568 }
6569 // v-bind="object"
6570 if ((binding = el.attrsMap['v-bind'])) {
6571 segments.push({ type: EXPRESSION, value: `_ssrAttrs(${binding})` });
6572 }
6573 // v-bind.prop="object"
6574 if ((binding = el.attrsMap['v-bind.prop'])) {
6575 segments.push({ type: EXPRESSION, value: `_ssrDOMProps(${binding})` });
6576 }
6577 // class
6578 if (el.staticClass || el.classBinding) {
6579 segments.push.apply(segments, genClassSegments(el.staticClass, el.classBinding));
6580 }
6581 // style & v-show
6582 if (el.staticStyle || el.styleBinding || el.attrsMap['v-show']) {
6583 segments.push.apply(segments, genStyleSegments(el.attrsMap.style, el.staticStyle, el.styleBinding, el.attrsMap['v-show']));
6584 }
6585 // _scopedId
6586 if (state.options.scopeId) {
6587 segments.push({ type: RAW, value: ` ${state.options.scopeId}` });
6588 }
6589 segments.push({ type: RAW, value: `>` });
6590 return segments;
6591}
6592function childrenToSegments(el, state) {
6593 let binding;
6594 if ((binding = el.attrsMap['v-html'])) {
6595 return [{ type: EXPRESSION, value: `_s(${binding})` }];
6596 }
6597 if ((binding = el.attrsMap['v-text'])) {
6598 return [{ type: INTERPOLATION, value: `_s(${binding})` }];
6599 }
6600 if (el.tag === 'textarea' && (binding = el.attrsMap['v-model'])) {
6601 return [{ type: INTERPOLATION, value: `_s(${binding})` }];
6602 }
6603 return el.children ? nodesToSegments(el.children, state) : [];
6604}
6605function nodesToSegments(children, state) {
6606 const segments = [];
6607 for (let i = 0; i < children.length; i++) {
6608 const c = children[i];
6609 if (c.type === 1) {
6610 segments.push.apply(segments, elementToSegments(c, state));
6611 }
6612 else if (c.type === 2) {
6613 segments.push({ type: INTERPOLATION, value: c.expression });
6614 }
6615 else if (c.type === 3) {
6616 let text = escape(c.text);
6617 if (c.isComment) {
6618 text = '<!--' + text + '-->';
6619 }
6620 segments.push({ type: RAW, value: text });
6621 }
6622 }
6623 return segments;
6624}
6625function flattenSegments(segments) {
6626 const mergedSegments = [];
6627 let textBuffer = '';
6628 const pushBuffer = () => {
6629 if (textBuffer) {
6630 mergedSegments.push(JSON.stringify(textBuffer));
6631 textBuffer = '';
6632 }
6633 };
6634 for (let i = 0; i < segments.length; i++) {
6635 const s = segments[i];
6636 if (s.type === RAW) {
6637 textBuffer += s.value;
6638 }
6639 else if (s.type === INTERPOLATION) {
6640 pushBuffer();
6641 mergedSegments.push(`_ssrEscape(${s.value})`);
6642 }
6643 else if (s.type === EXPRESSION) {
6644 pushBuffer();
6645 mergedSegments.push(`(${s.value})`);
6646 }
6647 }
6648 pushBuffer();
6649 return mergedSegments.join('+');
6650}
6651
6652const createCompiler = createCompilerCreator(function baseCompile(template, options) {
6653 const ast = parse(template.trim(), options);
6654 optimize(ast, options);
6655 const code = generate(ast, options);
6656 return {
6657 ast,
6658 render: code.render,
6659 staticRenderFns: code.staticRenderFns
6660 };
6661});
6662
6663const { compile, compileToFunctions } = createCompiler(baseOptions);
6664
6665exports.compile = compile$1;
6666exports.compileToFunctions = compileToFunctions$1;
6667exports.generateCodeFrame = generateCodeFrame;
6668exports.parseComponent = parseComponent;
6669exports.ssrCompile = compile;
6670exports.ssrCompileToFunctions = compileToFunctions;