UNPKG

154 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var deindent = _interopDefault(require('de-indent'));
8var he = _interopDefault(require('he'));
9var babel = _interopDefault(require('babel-core'));
10var prettier = _interopDefault(require('prettier'));
11var t = require('babel-types');
12var generate = _interopDefault(require('babel-generator'));
13var template = _interopDefault(require('babel-template'));
14
15/* */
16
17// these helpers produces better vm code in JS engines due to their
18// explicitness and function inlining
19
20
21
22
23
24
25
26
27/**
28 * Check if value is primitive
29 */
30
31
32/**
33 * Quick object check - this is primarily used to tell
34 * Objects from primitive values when we know the value
35 * is a JSON-compliant type.
36 */
37function isObject (obj) {
38 return obj !== null && typeof obj === 'object'
39}
40
41var _toString = Object.prototype.toString;
42
43/**
44 * Strict object type check. Only returns true
45 * for plain JavaScript objects.
46 */
47function isPlainObject (obj) {
48 return _toString.call(obj) === '[object Object]'
49}
50
51
52
53/**
54 * Check if val is a valid array index.
55 */
56function isValidArrayIndex (val) {
57 var n = parseFloat(val);
58 return n >= 0 && Math.floor(n) === n && isFinite(val)
59}
60
61/**
62 * Convert a value to a string that is actually rendered.
63 */
64
65
66/**
67 * Convert a input value to a number for persistence.
68 * If the conversion fails, return original string.
69 */
70
71
72/**
73 * Make a map and return a function for checking if a key
74 * is in that map.
75 */
76function makeMap (
77 str,
78 expectsLowerCase
79) {
80 var map = Object.create(null);
81 var list = str.split(',');
82 for (var i = 0; i < list.length; i++) {
83 map[list[i]] = true;
84 }
85 return expectsLowerCase
86 ? function (val) { return map[val.toLowerCase()]; }
87 : function (val) { return map[val]; }
88}
89
90/**
91 * Check if a tag is a built-in tag.
92 */
93var isBuiltInTag = makeMap('slot,component', true);
94
95/**
96 * Check if a attribute is a reserved attribute.
97 */
98var isReservedAttribute = makeMap('key,ref,slot,is');
99
100/**
101 * Remove an item from an array
102 */
103function remove (arr, item) {
104 if (arr.length) {
105 var index = arr.indexOf(item);
106 if (index > -1) {
107 return arr.splice(index, 1)
108 }
109 }
110}
111
112/**
113 * Check whether the object has the property.
114 */
115var hasOwnProperty = Object.prototype.hasOwnProperty;
116function hasOwn (obj, key) {
117 return hasOwnProperty.call(obj, key)
118}
119
120/**
121 * Create a cached version of a pure function.
122 */
123function cached (fn) {
124 var cache = Object.create(null);
125 return (function cachedFn (str) {
126 var hit = cache[str];
127 return hit || (cache[str] = fn(str))
128 })
129}
130
131/**
132 * Camelize a hyphen-delimited string.
133 */
134var camelizeRE = /-(\w)/g;
135var camelize = cached(function (str) {
136 return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
137});
138
139/**
140 * Capitalize a string.
141 */
142
143
144/**
145 * Hyphenate a camelCase string.
146 */
147var hyphenateRE = /([^-])([A-Z])/g;
148var hyphenate = cached(function (str) {
149 return str
150 .replace(hyphenateRE, '$1-$2')
151 .replace(hyphenateRE, '$1-$2')
152 .toLowerCase()
153});
154
155/**
156 * Simple bind, faster than native
157 */
158
159
160/**
161 * Convert an Array-like object to a real Array.
162 */
163
164
165/**
166 * Mix properties into target object.
167 */
168function extend (to, _from) {
169 for (var key in _from) {
170 to[key] = _from[key];
171 }
172 return to
173}
174
175/**
176 * Merge an Array of Objects into a single Object.
177 */
178
179
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/**
188 * Always return false.
189 */
190var no = function (a, b, c) { return false; };
191
192/**
193 * Return same value
194 */
195var identity = function (_) { return _; };
196
197/**
198 * Generate a static keys string from compiler modules.
199 */
200function genStaticKeys (modules) {
201 return modules.reduce(function (keys, m) {
202 return keys.concat(m.staticKeys || [])
203 }, []).join(',')
204}
205
206/**
207 * Check if two values are loosely equal - that is,
208 * if they are plain objects, do they have the same shape?
209 */
210
211
212
213
214/**
215 * Ensure a function is called only once.
216 */
217
218/* */
219
220var isUnaryTag = makeMap(
221 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
222 'link,meta,param,source,track,wbr'
223);
224
225// Elements that you can, intentionally, leave open
226// (and which close themselves)
227var canBeLeftOpenTag = makeMap(
228 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'
229);
230
231// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
232// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
233var isNonPhrasingTag = makeMap(
234 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
235 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
236 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
237 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
238 'title,tr,track'
239);
240
241/**
242 * Not type-checking this file because it's mostly vendor code.
243 */
244
245/*!
246 * HTML Parser By John Resig (ejohn.org)
247 * Modified by Juriy "kangax" Zaytsev
248 * Original code by Erik Arvidsson, Mozilla Public License
249 * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
250 */
251
252// Regular Expressions for parsing tags and attributes
253var singleAttrIdentifier = /([^\s"'<>/=]+)/;
254var singleAttrAssign = /(?:=)/;
255var singleAttrValues = [
256 // attr value double quotes
257 /"([^"]*)"+/.source,
258 // attr value, single quotes
259 /'([^']*)'+/.source,
260 // attr value, no quotes
261 /([^\s"'=<>`]+)/.source
262];
263var attribute = new RegExp(
264 '^\\s*' + singleAttrIdentifier.source +
265 '(?:\\s*(' + singleAttrAssign.source + ')' +
266 '\\s*(?:' + singleAttrValues.join('|') + '))?'
267);
268
269// could use https://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-QName
270// but for Vue templates we can enforce a simple charset
271var ncname = '[a-zA-Z_][\\w\\-\\.]*';
272var qnameCapture = '((?:' + ncname + '\\:)?' + ncname + ')';
273var startTagOpen = new RegExp('^<' + qnameCapture);
274var startTagClose = /^\s*(\/?)>/;
275var endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>');
276var doctype = /^<!DOCTYPE [^>]+>/i;
277var comment = /^<!--/;
278var conditionalComment = /^<!\[/;
279
280var IS_REGEX_CAPTURING_BROKEN = false;
281'x'.replace(/x(.)?/g, function (m, g) {
282 IS_REGEX_CAPTURING_BROKEN = g === '';
283});
284
285// Special Elements (can contain anything)
286var isPlainTextElement = makeMap('script,style,textarea', true);
287var reCache = {};
288
289var decodingMap = {
290 '&lt;': '<',
291 '&gt;': '>',
292 '&quot;': '"',
293 '&amp;': '&',
294 '&#10;': '\n'
295};
296var encodedAttr = /&(?:lt|gt|quot|amp);/g;
297var encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10);/g;
298
299// #5992
300var isIgnoreNewlineTag = makeMap('pre,textarea', true);
301var shouldIgnoreFirstNewline = function (tag, html) { return tag && isIgnoreNewlineTag(tag) && html[0] === '\n'; };
302
303function decodeAttr (value, shouldDecodeNewlines) {
304 var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;
305 return value.replace(re, function (match) { return decodingMap[match]; })
306}
307
308function parseHTML (html, options) {
309 var stack = [];
310 var expectHTML = options.expectHTML;
311 var isUnaryTag$$1 = options.isUnaryTag || no;
312 var canBeLeftOpenTag$$1 = options.canBeLeftOpenTag || no;
313 var index = 0;
314 var last, lastTag;
315 while (html) {
316 last = html;
317 // Make sure we're not in a plaintext content element like script/style
318 if (!lastTag || !isPlainTextElement(lastTag)) {
319 if (shouldIgnoreFirstNewline(lastTag, html)) {
320 advance(1);
321 }
322 var textEnd = html.indexOf('<');
323 if (textEnd === 0) {
324 // Comment:
325 if (comment.test(html)) {
326 var commentEnd = html.indexOf('-->');
327
328 if (commentEnd >= 0) {
329 if (options.shouldKeepComment) {
330 options.comment(html.substring(4, commentEnd));
331 }
332 advance(commentEnd + 3);
333 continue
334 }
335 }
336
337 // http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment
338 if (conditionalComment.test(html)) {
339 var conditionalEnd = html.indexOf(']>');
340
341 if (conditionalEnd >= 0) {
342 advance(conditionalEnd + 2);
343 continue
344 }
345 }
346
347 // Doctype:
348 var doctypeMatch = html.match(doctype);
349 if (doctypeMatch) {
350 advance(doctypeMatch[0].length);
351 continue
352 }
353
354 // End tag:
355 var endTagMatch = html.match(endTag);
356 if (endTagMatch) {
357 var curIndex = index;
358 advance(endTagMatch[0].length);
359 parseEndTag(endTagMatch[1], curIndex, index);
360 continue
361 }
362
363 // Start tag:
364 var startTagMatch = parseStartTag();
365 if (startTagMatch) {
366 handleStartTag(startTagMatch);
367 continue
368 }
369 }
370
371 var text = (void 0), rest = (void 0), next = (void 0);
372 if (textEnd >= 0) {
373 rest = html.slice(textEnd);
374 while (
375 !endTag.test(rest) &&
376 !startTagOpen.test(rest) &&
377 !comment.test(rest) &&
378 !conditionalComment.test(rest)
379 ) {
380 // < in plain text, be forgiving and treat it as text
381 next = rest.indexOf('<', 1);
382 if (next < 0) { break }
383 textEnd += next;
384 rest = html.slice(textEnd);
385 }
386 text = html.substring(0, textEnd);
387 advance(textEnd);
388 }
389
390 if (textEnd < 0) {
391 text = html;
392 html = '';
393 }
394
395 if (options.chars && text) {
396 options.chars(text);
397 }
398 } else {
399 var endTagLength = 0;
400 var stackedTag = lastTag.toLowerCase();
401 var reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp('([\\s\\S]*?)(</' + stackedTag + '[^>]*>)', 'i'));
402 var rest$1 = html.replace(reStackedTag, function (all, text, endTag) {
403 endTagLength = endTag.length;
404 if (!isPlainTextElement(stackedTag) && stackedTag !== 'noscript') {
405 text = text
406 .replace(/<!--([\s\S]*?)-->/g, '$1')
407 .replace(/<!\[CDATA\[([\s\S]*?)]]>/g, '$1');
408 }
409 if (shouldIgnoreFirstNewline(stackedTag, text)) {
410 text = text.slice(1);
411 }
412 if (options.chars) {
413 options.chars(text);
414 }
415 return ''
416 });
417 index += html.length - rest$1.length;
418 html = rest$1;
419 parseEndTag(stackedTag, index - endTagLength, index);
420 }
421
422 if (html === last) {
423 options.chars && options.chars(html);
424 if (process.env.NODE_ENV !== 'production' && !stack.length && options.warn) {
425 options.warn(("Mal-formatted tag at end of template: \"" + html + "\""));
426 }
427 break
428 }
429 }
430
431 // Clean up any remaining tags
432 parseEndTag();
433
434 function advance (n) {
435 index += n;
436 html = html.substring(n);
437 }
438
439 function parseStartTag () {
440 var start = html.match(startTagOpen);
441 if (start) {
442 var match = {
443 tagName: start[1],
444 attrs: [],
445 start: index
446 };
447 advance(start[0].length);
448 var end, attr;
449 while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {
450 advance(attr[0].length);
451 match.attrs.push(attr);
452 }
453 if (end) {
454 match.unarySlash = end[1];
455 advance(end[0].length);
456 match.end = index;
457 return match
458 }
459 }
460 }
461
462 function handleStartTag (match) {
463 var tagName = match.tagName;
464 var unarySlash = match.unarySlash;
465
466 if (expectHTML) {
467 if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
468 parseEndTag(lastTag);
469 }
470 if (canBeLeftOpenTag$$1(tagName) && lastTag === tagName) {
471 parseEndTag(tagName);
472 }
473 }
474
475 var unary = isUnaryTag$$1(tagName) || !!unarySlash;
476
477 var l = match.attrs.length;
478 var attrs = new Array(l);
479 for (var i = 0; i < l; i++) {
480 var args = match.attrs[i];
481 // hackish work around FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=369778
482 if (IS_REGEX_CAPTURING_BROKEN && args[0].indexOf('""') === -1) {
483 if (args[3] === '') { delete args[3]; }
484 if (args[4] === '') { delete args[4]; }
485 if (args[5] === '') { delete args[5]; }
486 }
487 var value = args[3] || args[4] || args[5] || '';
488 attrs[i] = {
489 name: args[1],
490 value: decodeAttr(
491 value,
492 options.shouldDecodeNewlines
493 )
494 };
495 }
496
497 if (!unary) {
498 stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs });
499 lastTag = tagName;
500 }
501
502 if (options.start) {
503 options.start(tagName, attrs, unary, match.start, match.end);
504 }
505 }
506
507 function parseEndTag (tagName, start, end) {
508 var pos, lowerCasedTagName;
509 if (start == null) { start = index; }
510 if (end == null) { end = index; }
511
512 if (tagName) {
513 lowerCasedTagName = tagName.toLowerCase();
514 }
515
516 // Find the closest opened tag of the same type
517 if (tagName) {
518 for (pos = stack.length - 1; pos >= 0; pos--) {
519 if (stack[pos].lowerCasedTag === lowerCasedTagName) {
520 break
521 }
522 }
523 } else {
524 // If no tag name is provided, clean shop
525 pos = 0;
526 }
527
528 if (pos >= 0) {
529 // Close all the open elements, up the stack
530 for (var i = stack.length - 1; i >= pos; i--) {
531 if (process.env.NODE_ENV !== 'production' &&
532 (i > pos || !tagName) &&
533 options.warn
534 ) {
535 options.warn(
536 ("tag <" + (stack[i].tag) + "> has no matching end tag.")
537 );
538 }
539 if (options.end) {
540 options.end(stack[i].tag, start, end);
541 }
542 }
543
544 // Remove the open elements from the stack
545 stack.length = pos;
546 lastTag = pos && stack[pos - 1].tag;
547 } else if (lowerCasedTagName === 'br') {
548 if (options.start) {
549 options.start(tagName, [], true, start, end);
550 }
551 } else if (lowerCasedTagName === 'p') {
552 if (options.start) {
553 options.start(tagName, [], false, start, end);
554 }
555 if (options.end) {
556 options.end(tagName, start, end);
557 }
558 }
559 }
560}
561
562/* */
563
564var splitRE = /\r?\n/g;
565var replaceRE = /./g;
566var isSpecialTag = makeMap('script,style,template', true);
567
568
569
570/**
571 * Parse a single-file component (*.vue) file into an SFC Descriptor Object.
572 */
573function parseComponent (
574 content,
575 options
576 ) {
577 if ( options === void 0 ) options = {};
578
579 var sfc = {
580 template: null,
581 script: null,
582 styles: [],
583 customBlocks: []
584 };
585 var depth = 0;
586 var currentBlock = null;
587
588 function start (
589 tag,
590 attrs,
591 unary,
592 start,
593 end
594 ) {
595 if (depth === 0) {
596 currentBlock = {
597 type: tag,
598 content: '',
599 start: end,
600 attrs: attrs.reduce(function (cumulated, ref) {
601 var name = ref.name;
602 var value = ref.value;
603
604 cumulated[name] = value || true;
605 return cumulated
606 }, Object.create(null))
607 };
608 if (isSpecialTag(tag)) {
609 checkAttrs(currentBlock, attrs);
610 if (tag === 'style') {
611 sfc.styles.push(currentBlock);
612 } else {
613 sfc[tag] = currentBlock;
614 }
615 } else { // custom blocks
616 sfc.customBlocks.push(currentBlock);
617 }
618 }
619 if (!unary) {
620 depth++;
621 }
622 }
623
624 function checkAttrs (block, attrs) {
625 for (var i = 0; i < attrs.length; i++) {
626 var attr = attrs[i];
627 if (attr.name === 'lang') {
628 block.lang = attr.value;
629 }
630 if (attr.name === 'scoped') {
631 block.scoped = true;
632 }
633 if (attr.name === 'module') {
634 block.module = attr.value || true;
635 }
636 if (attr.name === 'src') {
637 block.src = attr.value;
638 }
639 }
640 }
641
642 function end (tag, start, end) {
643 if (depth === 1 && currentBlock) {
644 currentBlock.end = start;
645 var text = deindent(content.slice(currentBlock.start, currentBlock.end));
646 // pad content so that linters and pre-processors can output correct
647 // line numbers in errors and warnings
648 if (currentBlock.type !== 'template' && options.pad) {
649 text = padContent(currentBlock, options.pad) + text;
650 }
651 currentBlock.content = text;
652 currentBlock = null;
653 }
654 depth--;
655 }
656
657 function padContent (block, pad) {
658 if (pad === 'space') {
659 return content.slice(0, block.start).replace(replaceRE, ' ')
660 } else {
661 var offset = content.slice(0, block.start).split(splitRE).length;
662 var padChar = block.type === 'script' && !block.lang
663 ? '//\n'
664 : '\n';
665 return Array(offset).join(padChar)
666 }
667 }
668
669 parseHTML(content, {
670 start: start,
671 end: end
672 });
673
674 return sfc
675}
676
677/* globals renderer */
678
679var isPreTag = function (tag) { return tag === 'pre'; };
680
681var isReservedTag = makeMap(
682 'template,script,style,element,content,slot,link,meta,svg,view,' +
683 'a,div,img,image,text,span,richtext,input,switch,textarea,spinner,select,' +
684 'slider,slider-neighbor,indicator,trisition,trisition-group,canvas,' +
685 'list,cell,header,loading,loading-indicator,refresh,scrollable,scroller,' +
686 'video,web,embed,tabbar,tabheader,datepicker,timepicker,marquee,countdown',
687 true
688);
689
690// these are reserved for web because they are directly compiled away
691// during template compilation
692var isReservedAttr = makeMap('style,class');
693
694// Elements that you can, intentionally, leave open (and which close themselves)
695// more flexable than web
696var canBeLeftOpenTag$1 = makeMap(
697 'web,spinner,switch,video,textarea,canvas,' +
698 'indicator,marquee,countdown',
699 true
700);
701
702var isUnaryTag$1 = makeMap(
703 'embed,img,image,input,link,meta',
704 true
705);
706
707function mustUseProp () { /* console.log('mustUseProp') */ }
708function getTagNamespace () { /* console.log('getTagNamespace') */ }
709
710
711
712
713
714
715// 用于小程序的 event type 到 web 的 event
716
717/* */
718
719var validDivisionCharRE = /[\w).+\-_$\]]/;
720
721function parseFilters (exp) {
722 var inSingle = false;
723 var inDouble = false;
724 var inTemplateString = false;
725 var inRegex = false;
726 var curly = 0;
727 var square = 0;
728 var paren = 0;
729 var lastFilterIndex = 0;
730 var c, prev, i, expression, filters;
731
732 for (i = 0; i < exp.length; i++) {
733 prev = c;
734 c = exp.charCodeAt(i);
735 if (inSingle) {
736 if (c === 0x27 && prev !== 0x5C) { inSingle = false; }
737 } else if (inDouble) {
738 if (c === 0x22 && prev !== 0x5C) { inDouble = false; }
739 } else if (inTemplateString) {
740 if (c === 0x60 && prev !== 0x5C) { inTemplateString = false; }
741 } else if (inRegex) {
742 if (c === 0x2f && prev !== 0x5C) { inRegex = false; }
743 } else if (
744 c === 0x7C && // pipe
745 exp.charCodeAt(i + 1) !== 0x7C &&
746 exp.charCodeAt(i - 1) !== 0x7C &&
747 !curly && !square && !paren
748 ) {
749 if (expression === undefined) {
750 // first filter, end of expression
751 lastFilterIndex = i + 1;
752 expression = exp.slice(0, i).trim();
753 } else {
754 pushFilter();
755 }
756 } else {
757 switch (c) {
758 case 0x22: inDouble = true; break // "
759 case 0x27: inSingle = true; break // '
760 case 0x60: inTemplateString = true; break // `
761 case 0x28: paren++; break // (
762 case 0x29: paren--; break // )
763 case 0x5B: square++; break // [
764 case 0x5D: square--; break // ]
765 case 0x7B: curly++; break // {
766 case 0x7D: curly--; break // }
767 }
768 if (c === 0x2f) { // /
769 var j = i - 1;
770 var p = (void 0);
771 // find first non-whitespace prev char
772 for (; j >= 0; j--) {
773 p = exp.charAt(j);
774 if (p !== ' ') { break }
775 }
776 if (!p || !validDivisionCharRE.test(p)) {
777 inRegex = true;
778 }
779 }
780 }
781 }
782
783 if (expression === undefined) {
784 expression = exp.slice(0, i).trim();
785 } else if (lastFilterIndex !== 0) {
786 pushFilter();
787 }
788
789 function pushFilter () {
790 (filters || (filters = [])).push(exp.slice(lastFilterIndex, i).trim());
791 lastFilterIndex = i + 1;
792 }
793
794 if (filters) {
795 for (i = 0; i < filters.length; i++) {
796 expression = wrapFilter(expression, filters[i]);
797 }
798 }
799
800 return expression
801}
802
803function wrapFilter (exp, filter) {
804 var i = filter.indexOf('(');
805 if (i < 0) {
806 // _f: resolveFilter
807 return ("_f(\"" + filter + "\")(" + exp + ")")
808 } else {
809 var name = filter.slice(0, i);
810 var args = filter.slice(i + 1);
811 return ("_f(\"" + name + "\")(" + exp + "," + args)
812 }
813}
814
815/* */
816
817var defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g;
818var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
819
820var buildRegex = cached(function (delimiters) {
821 var open = delimiters[0].replace(regexEscapeRE, '\\$&');
822 var close = delimiters[1].replace(regexEscapeRE, '\\$&');
823 return new RegExp(open + '((?:.|\\n)+?)' + close, 'g')
824});
825
826function parseText (
827 text,
828 delimiters
829) {
830 var tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE;
831 if (!tagRE.test(text)) {
832 return
833 }
834 var tokens = [];
835 var lastIndex = tagRE.lastIndex = 0;
836 var match, index;
837 while ((match = tagRE.exec(text))) {
838 index = match.index;
839 // push text token
840 if (index > lastIndex) {
841 tokens.push(JSON.stringify(text.slice(lastIndex, index)));
842 }
843 // tag token
844 var exp = parseFilters(match[1].trim());
845 tokens.push(("_s(" + exp + ")"));
846 lastIndex = index + match[0].length;
847 }
848 if (lastIndex < text.length) {
849 tokens.push(JSON.stringify(text.slice(lastIndex)));
850 }
851 return tokens.join('+')
852}
853
854/* */
855
856function baseWarn (msg) {
857 console.error(("[Vue compiler]: " + msg));
858}
859
860function pluckModuleFunction (
861 modules,
862 key
863) {
864 return modules
865 ? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; })
866 : []
867}
868
869function addProp (el, name, value) {
870 (el.props || (el.props = [])).push({ name: name, value: value });
871}
872
873function addAttr (el, name, value) {
874 (el.attrs || (el.attrs = [])).push({ name: name, value: value });
875}
876
877function addDirective (
878 el,
879 name,
880 rawName,
881 value,
882 arg,
883 modifiers
884) {
885 (el.directives || (el.directives = [])).push({ name: name, rawName: rawName, value: value, arg: arg, modifiers: modifiers });
886}
887
888function addHandler (
889 el,
890 name,
891 value,
892 modifiers,
893 important,
894 warn
895) {
896 // warn prevent and passive modifier
897 /* istanbul ignore if */
898 if (
899 process.env.NODE_ENV !== 'production' && warn &&
900 modifiers && modifiers.prevent && modifiers.passive
901 ) {
902 warn(
903 'passive and prevent can\'t be used together. ' +
904 'Passive handler can\'t prevent default event.'
905 );
906 }
907 // check capture modifier
908 if (modifiers && modifiers.capture) {
909 delete modifiers.capture;
910 name = '!' + name; // mark the event as captured
911 }
912 if (modifiers && modifiers.once) {
913 delete modifiers.once;
914 name = '~' + name; // mark the event as once
915 }
916 /* istanbul ignore if */
917 if (modifiers && modifiers.passive) {
918 delete modifiers.passive;
919 name = '&' + name; // mark the event as passive
920 }
921 var events;
922 if (modifiers && modifiers.native) {
923 delete modifiers.native;
924 events = el.nativeEvents || (el.nativeEvents = {});
925 } else {
926 events = el.events || (el.events = {});
927 }
928 var newHandler = { value: value, modifiers: modifiers };
929 var handlers = events[name];
930 /* istanbul ignore if */
931 if (Array.isArray(handlers)) {
932 important ? handlers.unshift(newHandler) : handlers.push(newHandler);
933 } else if (handlers) {
934 events[name] = important ? [newHandler, handlers] : [handlers, newHandler];
935 } else {
936 events[name] = newHandler;
937 }
938}
939
940function getBindingAttr (
941 el,
942 name,
943 getStatic
944) {
945 var dynamicValue =
946 getAndRemoveAttr(el, ':' + name) ||
947 getAndRemoveAttr(el, 'v-bind:' + name);
948 if (dynamicValue != null) {
949 return parseFilters(dynamicValue)
950 } else if (getStatic !== false) {
951 var staticValue = getAndRemoveAttr(el, name);
952 if (staticValue != null) {
953 return JSON.stringify(staticValue)
954 }
955 }
956}
957
958function getAndRemoveAttr (el, name) {
959 var val;
960 if ((val = el.attrsMap[name]) != null) {
961 var list = el.attrsList;
962 for (var i = 0, l = list.length; i < l; i++) {
963 if (list[i].name === name) {
964 list.splice(i, 1);
965 break
966 }
967 }
968 }
969 return val
970}
971
972/* */
973
974function transformNode (el, options) {
975 var warn = options.warn || baseWarn;
976 var staticClass = getAndRemoveAttr(el, 'class');
977 if (process.env.NODE_ENV !== 'production' && staticClass) {
978 var expression = parseText(staticClass, options.delimiters);
979 if (expression) {
980 warn(
981 "class=\"" + staticClass + "\": " +
982 'Interpolation inside attributes has been removed. ' +
983 'Use v-bind or the colon shorthand instead. For example, ' +
984 'instead of <div class="{{ val }}">, use <div :class="val">.'
985 );
986 }
987 }
988 if (staticClass) {
989 el.staticClass = JSON.stringify(staticClass);
990 }
991 var classBinding = getBindingAttr(el, 'class', false /* getStatic */);
992 if (classBinding) {
993 el.classBinding = classBinding;
994 }
995}
996
997function genData (el) {
998 var data = '';
999 if (el.staticClass) {
1000 data += "staticClass:" + (el.staticClass) + ",";
1001 }
1002 if (el.classBinding) {
1003 data += "class:" + (el.classBinding) + ",";
1004 }
1005 return data
1006}
1007
1008var klass = {
1009 staticKeys: ['staticClass'],
1010 transformNode: transformNode,
1011 genData: genData
1012};
1013
1014/* */
1015
1016var parseStyleText = cached(function (cssText) {
1017 var res = {};
1018 var listDelimiter = /;(?![^(]*\))/g;
1019 var propertyDelimiter = /:(.+)/;
1020 cssText.split(listDelimiter).forEach(function (item) {
1021 if (item) {
1022 var tmp = item.split(propertyDelimiter);
1023 tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim());
1024 }
1025 });
1026 return res
1027});
1028
1029// normalize possible array / string values into Object
1030
1031
1032/**
1033 * parent component style should be after child's
1034 * so that parent component's style could override it
1035 */
1036
1037/* */
1038
1039function transformNode$1 (el, options) {
1040 var warn = options.warn || baseWarn;
1041 var staticStyle = getAndRemoveAttr(el, 'style');
1042 if (staticStyle) {
1043 /* istanbul ignore if */
1044 if (process.env.NODE_ENV !== 'production') {
1045 var expression = parseText(staticStyle, options.delimiters);
1046 if (expression) {
1047 warn(
1048 "style=\"" + staticStyle + "\": " +
1049 'Interpolation inside attributes has been removed. ' +
1050 'Use v-bind or the colon shorthand instead. For example, ' +
1051 'instead of <div style="{{ val }}">, use <div :style="val">.'
1052 );
1053 }
1054 }
1055 el.staticStyle = JSON.stringify(parseStyleText(staticStyle));
1056 }
1057
1058 var styleBinding = getBindingAttr(el, 'style', false /* getStatic */);
1059 if (styleBinding) {
1060 el.styleBinding = styleBinding;
1061 }
1062}
1063
1064function genData$1 (el) {
1065 var data = '';
1066 if (el.staticStyle) {
1067 data += "staticStyle:" + (el.staticStyle) + ",";
1068 }
1069 if (el.styleBinding) {
1070 data += "style:(" + (el.styleBinding) + "),";
1071 }
1072 return data
1073}
1074
1075var style = {
1076 staticKeys: ['staticStyle'],
1077 transformNode: transformNode$1,
1078 genData: genData$1
1079};
1080
1081var modules = [
1082 klass,
1083 style
1084];
1085
1086var ASSET_TYPES = [
1087 'component',
1088 'directive',
1089 'filter'
1090];
1091
1092var LIFECYCLE_HOOKS = [
1093 'beforeCreate',
1094 'created',
1095 'beforeMount',
1096 'mounted',
1097 'beforeUpdate',
1098 'updated',
1099 'beforeDestroy',
1100 'destroyed',
1101 'activated',
1102 'deactivated', 'onLaunch',
1103 'onLoad',
1104 'onShow',
1105 'onReady',
1106 'onHide',
1107 'onUnload',
1108 'onPullDownRefresh',
1109 'onReachBottom',
1110 'onShareAppMessage',
1111 'onPageScroll',
1112 'onTabItemTap',
1113 'attached',
1114 'ready',
1115 'moved',
1116 'detached'
1117];
1118
1119/* */
1120
1121var config = ({
1122 /**
1123 * Option merge strategies (used in core/util/options)
1124 */
1125 optionMergeStrategies: Object.create(null),
1126
1127 /**
1128 * Whether to suppress warnings.
1129 */
1130 silent: false,
1131
1132 /**
1133 * Show production mode tip message on boot?
1134 */
1135 productionTip: process.env.NODE_ENV !== 'production',
1136
1137 /**
1138 * Whether to enable devtools
1139 */
1140 devtools: process.env.NODE_ENV !== 'production',
1141
1142 /**
1143 * Whether to record perf
1144 */
1145 performance: false,
1146
1147 /**
1148 * Error handler for watcher errors
1149 */
1150 errorHandler: null,
1151
1152 /**
1153 * Warn handler for watcher warns
1154 */
1155 warnHandler: null,
1156
1157 /**
1158 * Ignore certain custom elements
1159 */
1160 ignoredElements: [],
1161
1162 /**
1163 * Custom user key aliases for v-on
1164 */
1165 keyCodes: Object.create(null),
1166
1167 /**
1168 * Check if a tag is reserved so that it cannot be registered as a
1169 * component. This is platform-dependent and may be overwritten.
1170 */
1171 isReservedTag: no,
1172
1173 /**
1174 * Check if an attribute is reserved so that it cannot be used as a component
1175 * prop. This is platform-dependent and may be overwritten.
1176 */
1177 isReservedAttr: no,
1178
1179 /**
1180 * Check if a tag is an unknown element.
1181 * Platform-dependent.
1182 */
1183 isUnknownElement: no,
1184
1185 /**
1186 * Get the namespace of an element
1187 */
1188 getTagNamespace: noop,
1189
1190 /**
1191 * Parse the real tag name for the specific platform.
1192 */
1193 parsePlatformTagName: identity,
1194
1195 /**
1196 * Check if an attribute must be bound using property, e.g. value
1197 * Platform-dependent.
1198 */
1199 mustUseProp: no,
1200
1201 /**
1202 * Exposed for legacy reasons
1203 */
1204 _lifecycleHooks: LIFECYCLE_HOOKS
1205});
1206
1207/* */
1208
1209/**
1210 * Cross-platform code generation for component v-model
1211 */
1212function genComponentModel (
1213 el,
1214 value,
1215 modifiers
1216) {
1217 var ref = modifiers || {};
1218 var number = ref.number;
1219 var trim = ref.trim;
1220
1221 var baseValueExpression = '$$v';
1222 var valueExpression = baseValueExpression;
1223 if (trim) {
1224 valueExpression =
1225 "(typeof " + baseValueExpression + " === 'string'" +
1226 "? " + baseValueExpression + ".trim()" +
1227 ": " + baseValueExpression + ")";
1228 }
1229 if (number) {
1230 valueExpression = "_n(" + valueExpression + ")";
1231 }
1232 var assignment = genAssignmentCode(value, valueExpression);
1233
1234 el.model = {
1235 value: ("(" + value + ")"),
1236 expression: ("\"" + value + "\""),
1237 callback: ("function (" + baseValueExpression + ") {" + assignment + "}")
1238 };
1239}
1240
1241/**
1242 * Cross-platform codegen helper for generating v-model value assignment code.
1243 */
1244function genAssignmentCode (
1245 value,
1246 assignment
1247) {
1248 var modelRs = parseModel(value);
1249 if (modelRs.idx === null) {
1250 return (value + "=" + assignment)
1251 } else {
1252 return ("$set(" + (modelRs.exp) + ", " + (modelRs.idx) + ", " + assignment + ")")
1253 }
1254}
1255
1256/**
1257 * parse directive model to do the array update transform. a[idx] = val => $$a.splice($$idx, 1, val)
1258 *
1259 * for loop possible cases:
1260 *
1261 * - test
1262 * - test[idx]
1263 * - test[test1[idx]]
1264 * - test["a"][idx]
1265 * - xxx.test[a[a].test1[idx]]
1266 * - test.xxx.a["asa"][test1[idx]]
1267 *
1268 */
1269
1270var len;
1271var str;
1272var chr;
1273var index;
1274var expressionPos;
1275var expressionEndPos;
1276
1277function parseModel (val) {
1278 str = val;
1279 len = str.length;
1280 index = expressionPos = expressionEndPos = 0;
1281
1282 if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
1283 return {
1284 exp: val,
1285 idx: null
1286 }
1287 }
1288
1289 while (!eof()) {
1290 chr = next();
1291 /* istanbul ignore if */
1292 if (isStringStart(chr)) {
1293 parseString(chr);
1294 } else if (chr === 0x5B) {
1295 parseBracket(chr);
1296 }
1297 }
1298
1299 return {
1300 exp: val.substring(0, expressionPos),
1301 idx: val.substring(expressionPos + 1, expressionEndPos)
1302 }
1303}
1304
1305function next () {
1306 return str.charCodeAt(++index)
1307}
1308
1309function eof () {
1310 return index >= len
1311}
1312
1313function isStringStart (chr) {
1314 return chr === 0x22 || chr === 0x27
1315}
1316
1317function parseBracket (chr) {
1318 var inBracket = 1;
1319 expressionPos = index;
1320 while (!eof()) {
1321 chr = next();
1322 if (isStringStart(chr)) {
1323 parseString(chr);
1324 continue
1325 }
1326 if (chr === 0x5B) { inBracket++; }
1327 if (chr === 0x5D) { inBracket--; }
1328 if (inBracket === 0) {
1329 expressionEndPos = index;
1330 break
1331 }
1332 }
1333}
1334
1335function parseString (chr) {
1336 var stringQuote = chr;
1337 while (!eof()) {
1338 chr = next();
1339 if (chr === stringQuote) {
1340 break
1341 }
1342 }
1343}
1344
1345/* */
1346
1347var warn;
1348
1349// in some cases, the event used has to be determined at runtime
1350// so we used some reserved tokens during compile.
1351var RANGE_TOKEN = '__r';
1352var CHECKBOX_RADIO_TOKEN = '__c';
1353
1354function model (
1355 el,
1356 dir,
1357 _warn
1358) {
1359 warn = _warn;
1360 var value = dir.value;
1361 var modifiers = dir.modifiers;
1362 var tag = el.tag;
1363 var type = el.attrsMap.type;
1364
1365 if (process.env.NODE_ENV !== 'production') {
1366 var dynamicType = el.attrsMap['v-bind:type'] || el.attrsMap[':type'];
1367 if (tag === 'input' && dynamicType) {
1368 warn(
1369 "<input :type=\"" + dynamicType + "\" v-model=\"" + value + "\">:\n" +
1370 "v-model does not support dynamic input types. Use v-if branches instead."
1371 );
1372 }
1373 // inputs with type="file" are read only and setting the input's
1374 // value will throw an error.
1375 if (tag === 'input' && type === 'file') {
1376 warn(
1377 "<" + (el.tag) + " v-model=\"" + value + "\" type=\"file\">:\n" +
1378 "File inputs are read only. Use a v-on:change listener instead."
1379 );
1380 }
1381 }
1382
1383 if (el.component) {
1384 genComponentModel(el, value, modifiers);
1385 // component v-model doesn't need extra runtime
1386 return false
1387 } else if (tag === 'select') {
1388 genSelect(el, value, modifiers);
1389 } else if (tag === 'input' && type === 'checkbox') {
1390 genCheckboxModel(el, value, modifiers);
1391 } else if (tag === 'input' && type === 'radio') {
1392 genRadioModel(el, value, modifiers);
1393 } else if (tag === 'input' || tag === 'textarea') {
1394 genDefaultModel(el, value, modifiers);
1395 } else if (!config.isReservedTag(tag)) {
1396 genComponentModel(el, value, modifiers);
1397 // component v-model doesn't need extra runtime
1398 return false
1399 } else if (process.env.NODE_ENV !== 'production') {
1400 warn(
1401 "<" + (el.tag) + " v-model=\"" + value + "\">: " +
1402 "v-model is not supported on this element type. " +
1403 'If you are working with contenteditable, it\'s recommended to ' +
1404 'wrap a library dedicated for that purpose inside a custom component.'
1405 );
1406 }
1407
1408 // ensure runtime directive metadata
1409 return true
1410}
1411
1412function genCheckboxModel (
1413 el,
1414 value,
1415 modifiers
1416) {
1417 var number = modifiers && modifiers.number;
1418 var valueBinding = getBindingAttr(el, 'value') || 'null';
1419 var trueValueBinding = getBindingAttr(el, 'true-value') || 'true';
1420 var falseValueBinding = getBindingAttr(el, 'false-value') || 'false';
1421 addProp(el, 'checked',
1422 "Array.isArray(" + value + ")" +
1423 "?_i(" + value + "," + valueBinding + ")>-1" + (
1424 trueValueBinding === 'true'
1425 ? (":(" + value + ")")
1426 : (":_q(" + value + "," + trueValueBinding + ")")
1427 )
1428 );
1429 addHandler(el, CHECKBOX_RADIO_TOKEN,
1430 "var $$a=" + value + "," +
1431 '$$el=$event.target,' +
1432 "$$c=$$el.checked?(" + trueValueBinding + "):(" + falseValueBinding + ");" +
1433 'if(Array.isArray($$a)){' +
1434 "var $$v=" + (number ? '_n(' + valueBinding + ')' : valueBinding) + "," +
1435 '$$i=_i($$a,$$v);' +
1436 "if($$c){$$i<0&&(" + value + "=$$a.concat($$v))}" +
1437 "else{$$i>-1&&(" + value + "=$$a.slice(0,$$i).concat($$a.slice($$i+1)))}" +
1438 "}else{" + (genAssignmentCode(value, '$$c')) + "}",
1439 null, true
1440 );
1441}
1442
1443function genRadioModel (
1444 el,
1445 value,
1446 modifiers
1447) {
1448 var number = modifiers && modifiers.number;
1449 var valueBinding = getBindingAttr(el, 'value') || 'null';
1450 valueBinding = number ? ("_n(" + valueBinding + ")") : valueBinding;
1451 addProp(el, 'checked', ("_q(" + value + "," + valueBinding + ")"));
1452 addHandler(el, CHECKBOX_RADIO_TOKEN, genAssignmentCode(value, valueBinding), null, true);
1453}
1454
1455function genSelect (
1456 el,
1457 value,
1458 modifiers
1459) {
1460 var number = modifiers && modifiers.number;
1461 var selectedVal = "Array.prototype.filter" +
1462 ".call($event.target.options,function(o){return o.selected})" +
1463 ".map(function(o){var val = \"_value\" in o ? o._value : o.value;" +
1464 "return " + (number ? '_n(val)' : 'val') + "})";
1465
1466 var assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]';
1467 var code = "var $$selectedVal = " + selectedVal + ";";
1468 code = code + " " + (genAssignmentCode(value, assignment));
1469 addHandler(el, 'change', code, null, true);
1470}
1471
1472function genDefaultModel (
1473 el,
1474 value,
1475 modifiers
1476) {
1477 var type = el.attrsMap.type;
1478 var ref = modifiers || {};
1479 var lazy = ref.lazy;
1480 var number = ref.number;
1481 var trim = ref.trim;
1482 var needCompositionGuard = !lazy && type !== 'range';
1483 var event = lazy
1484 ? 'change'
1485 : type === 'range'
1486 ? RANGE_TOKEN
1487 : 'input';
1488
1489 var valueExpression = '$event.target.value';
1490 if (trim) {
1491 valueExpression = "$event.target.value.trim()";
1492 }
1493 if (number) {
1494 valueExpression = "_n(" + valueExpression + ")";
1495 }
1496
1497 var code = genAssignmentCode(value, valueExpression);
1498 if (needCompositionGuard) {
1499 code = "if($event.target.composing)return;" + code;
1500 }
1501
1502 addProp(el, 'value', ("(" + value + ")"));
1503 addHandler(el, event, code, null, true);
1504 if (trim || number) {
1505 addHandler(el, 'blur', '$forceUpdate()');
1506 }
1507}
1508
1509/* */
1510
1511function text (el, dir) {
1512 if (dir.value) {
1513 addProp(el, 'textContent', ("_s(" + (dir.value) + ")"));
1514 }
1515}
1516
1517/* */
1518
1519function html (el, dir) {
1520 if (dir.value) {
1521 addProp(el, 'innerHTML', ("_s(" + (dir.value) + ")"));
1522 }
1523}
1524
1525var directives = {
1526 model: model,
1527 text: text,
1528 html: html
1529};
1530
1531/* */
1532
1533var isUnaryTag$2 = makeMap(
1534 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
1535 'link,meta,param,source,track,wbr'
1536);
1537
1538// Elements that you can, intentionally, leave open
1539// (and which close themselves)
1540var canBeLeftOpenTag$2 = makeMap(
1541 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'
1542);
1543
1544// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
1545// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
1546var isNonPhrasingTag$1 = makeMap(
1547 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
1548 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
1549 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
1550 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
1551 'title,tr,track'
1552);
1553
1554/* */
1555
1556var baseOptions = {
1557 expectHTML: true,
1558 modules: modules,
1559 directives: directives,
1560 isPreTag: isPreTag,
1561 isUnaryTag: isUnaryTag$2,
1562 mustUseProp: mustUseProp,
1563 canBeLeftOpenTag: canBeLeftOpenTag$2,
1564 isReservedTag: isReservedTag,
1565 getTagNamespace: getTagNamespace,
1566 staticKeys: genStaticKeys(modules)
1567};
1568
1569/* */
1570
1571var warn$2 = noop;
1572var tip = noop;
1573var formatComponentName = (null); // work around flow check
1574
1575if (process.env.NODE_ENV !== 'production') {
1576 var hasConsole = typeof console !== 'undefined';
1577 var classifyRE = /(?:^|[-_])(\w)/g;
1578 var classify = function (str) { return str
1579 .replace(classifyRE, function (c) { return c.toUpperCase(); })
1580 .replace(/[-_]/g, ''); };
1581
1582 warn$2 = function (msg, vm) {
1583 var trace = vm ? generateComponentTrace(vm) : '';
1584
1585 if (config.warnHandler) {
1586 config.warnHandler.call(null, msg, vm, trace);
1587 } else if (hasConsole && (!config.silent)) {
1588 console.error(("[Vue warn]: " + msg + trace));
1589 }
1590 };
1591
1592 tip = function (msg, vm) {
1593 if (hasConsole && (!config.silent)) {
1594 console.warn("[Vue tip]: " + msg + (
1595 vm ? generateComponentTrace(vm) : ''
1596 ));
1597 }
1598 };
1599
1600 formatComponentName = function (vm, includeFile) {
1601 if (vm.$root === vm) {
1602 return '<Root>'
1603 }
1604 var name = typeof vm === 'string'
1605 ? vm
1606 : typeof vm === 'function' && vm.options
1607 ? vm.options.name
1608 : vm._isVue
1609 ? vm.$options.name || vm.$options._componentTag
1610 : vm.name;
1611
1612 var file = vm._isVue && vm.$options.__file;
1613 if (!name && file) {
1614 var match = file.match(/([^/\\]+)\.vue$/);
1615 name = match && match[1];
1616 }
1617
1618 return (
1619 (name ? ("<" + (classify(name)) + ">") : "<Anonymous>") +
1620 (file && includeFile !== false ? (" at " + file) : '')
1621 )
1622 };
1623
1624 var repeat = function (str, n) {
1625 var res = '';
1626 while (n) {
1627 if (n % 2 === 1) { res += str; }
1628 if (n > 1) { str += str; }
1629 n >>= 1;
1630 }
1631 return res
1632 };
1633
1634 var generateComponentTrace = function (vm) {
1635 if (vm._isVue && vm.$parent) {
1636 var tree = [];
1637 var currentRecursiveSequence = 0;
1638 while (vm) {
1639 if (tree.length > 0) {
1640 var last = tree[tree.length - 1];
1641 if (last.constructor === vm.constructor) {
1642 currentRecursiveSequence++;
1643 vm = vm.$parent;
1644 continue
1645 } else if (currentRecursiveSequence > 0) {
1646 tree[tree.length - 1] = [last, currentRecursiveSequence];
1647 currentRecursiveSequence = 0;
1648 }
1649 }
1650 tree.push(vm);
1651 vm = vm.$parent;
1652 }
1653 return '\n\nfound in\n\n' + tree
1654 .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm)
1655 ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)")
1656 : formatComponentName(vm))); })
1657 .join('\n')
1658 } else {
1659 return ("\n\n(found in " + (formatComponentName(vm)) + ")")
1660 }
1661 };
1662}
1663
1664/* */
1665
1666function handleError (err, vm, info) {
1667 if (config.errorHandler) {
1668 config.errorHandler.call(null, err, vm, info);
1669 } else {
1670 if (process.env.NODE_ENV !== 'production') {
1671 warn$2(("Error in " + info + ": \"" + (err.toString()) + "\""), vm);
1672 }
1673 /* istanbul ignore else */
1674 if (inBrowser && typeof console !== 'undefined') {
1675 console.error(err);
1676 } else {
1677 throw err
1678 }
1679 }
1680}
1681
1682/* */
1683
1684// can we use __proto__?
1685var hasProto = '__proto__' in {};
1686
1687// Browser environment sniffing
1688var inBrowser = typeof window !== 'undefined';
1689var UA = ['mpvue-runtime'].join();
1690var isIE = UA && /msie|trident/.test(UA);
1691var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
1692var isEdge = UA && UA.indexOf('edge/') > 0;
1693var isAndroid = UA && UA.indexOf('android') > 0;
1694var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
1695var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
1696
1697// Firefix has a "watch" function on Object.prototype...
1698var nativeWatch = ({}).watch;
1699
1700var supportsPassive = false;
1701if (inBrowser) {
1702 try {
1703 var opts = {};
1704 Object.defineProperty(opts, 'passive', ({
1705 get: function get () {
1706 /* istanbul ignore next */
1707 supportsPassive = true;
1708 }
1709 })); // https://github.com/facebook/flow/issues/285
1710 window.addEventListener('test-passive', null, opts);
1711 } catch (e) {}
1712}
1713
1714// this needs to be lazy-evaled because vue may be required before
1715// vue-server-renderer can set VUE_ENV
1716var _isServer;
1717var isServerRendering = function () {
1718 if (_isServer === undefined) {
1719 /* istanbul ignore if */
1720 if (!inBrowser && typeof global !== 'undefined') {
1721 // detect presence of vue-server-renderer and avoid
1722 // Webpack shimming the process
1723 _isServer = global['process'].env.VUE_ENV === 'server';
1724 } else {
1725 _isServer = false;
1726 }
1727 }
1728 return _isServer
1729};
1730
1731// detect devtools
1732
1733
1734/* istanbul ignore next */
1735function isNative (Ctor) {
1736 return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
1737}
1738
1739var hasSymbol =
1740 typeof Symbol !== 'undefined' && isNative(Symbol) &&
1741 typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);
1742
1743/**
1744 * Defer a task to execute it asynchronously.
1745 */
1746var nextTick = (function () {
1747 var callbacks = [];
1748 var pending = false;
1749 var timerFunc;
1750
1751 function nextTickHandler () {
1752 pending = false;
1753 var copies = callbacks.slice(0);
1754 callbacks.length = 0;
1755 for (var i = 0; i < copies.length; i++) {
1756 copies[i]();
1757 }
1758 }
1759
1760 // the nextTick behavior leverages the microtask queue, which can be accessed
1761 // via either native Promise.then or MutationObserver.
1762 // MutationObserver has wider support, however it is seriously bugged in
1763 // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
1764 // completely stops working after triggering a few times... so, if native
1765 // Promise is available, we will use it:
1766 /* istanbul ignore if */
1767 if (typeof Promise !== 'undefined' && isNative(Promise)) {
1768 var p = Promise.resolve();
1769 var logError = function (err) { console.error(err); };
1770 timerFunc = function () {
1771 p.then(nextTickHandler).catch(logError);
1772 // in problematic UIWebViews, Promise.then doesn't completely break, but
1773 // it can get stuck in a weird state where callbacks are pushed into the
1774 // microtask queue but the queue isn't being flushed, until the browser
1775 // needs to do some other work, e.g. handle a timer. Therefore we can
1776 // "force" the microtask queue to be flushed by adding an empty timer.
1777 if (isIOS) { setTimeout(noop); }
1778 };
1779 // } else if (typeof MutationObserver !== 'undefined' && (
1780 // isNative(MutationObserver) ||
1781 // // PhantomJS and iOS 7.x
1782 // MutationObserver.toString() === '[object MutationObserverConstructor]'
1783 // )) {
1784 // // use MutationObserver where native Promise is not available,
1785 // // e.g. PhantomJS IE11, iOS7, Android 4.4
1786 // var counter = 1
1787 // var observer = new MutationObserver(nextTickHandler)
1788 // var textNode = document.createTextNode(String(counter))
1789 // observer.observe(textNode, {
1790 // characterData: true
1791 // })
1792 // timerFunc = () => {
1793 // counter = (counter + 1) % 2
1794 // textNode.data = String(counter)
1795 // }
1796 } else {
1797 // fallback to setTimeout
1798 /* istanbul ignore next */
1799 timerFunc = function () {
1800 setTimeout(nextTickHandler, 0);
1801 };
1802 }
1803
1804 return function queueNextTick (cb, ctx) {
1805 var _resolve;
1806 callbacks.push(function () {
1807 if (cb) {
1808 try {
1809 cb.call(ctx);
1810 } catch (e) {
1811 handleError(e, ctx, 'nextTick');
1812 }
1813 } else if (_resolve) {
1814 _resolve(ctx);
1815 }
1816 });
1817 if (!pending) {
1818 pending = true;
1819 timerFunc();
1820 }
1821 if (!cb && typeof Promise !== 'undefined') {
1822 return new Promise(function (resolve, reject) {
1823 _resolve = resolve;
1824 })
1825 }
1826 }
1827})();
1828
1829var _Set;
1830/* istanbul ignore if */
1831if (typeof Set !== 'undefined' && isNative(Set)) {
1832 // use native Set when available.
1833 _Set = Set;
1834} else {
1835 // a non-standard Set polyfill that only works with primitive keys.
1836 _Set = (function () {
1837 function Set () {
1838 this.set = Object.create(null);
1839 }
1840 Set.prototype.has = function has (key) {
1841 return this.set[key] === true
1842 };
1843 Set.prototype.add = function add (key) {
1844 this.set[key] = true;
1845 };
1846 Set.prototype.clear = function clear () {
1847 this.set = Object.create(null);
1848 };
1849
1850 return Set;
1851 }());
1852}
1853
1854/* */
1855
1856var onRE = /^@|^v-on:/;
1857var dirRE = /^v-|^@|^:/;
1858var forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/;
1859var forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/;
1860
1861var argRE = /:(.*)$/;
1862var bindRE = /^:|^v-bind:/;
1863var modifierRE = /\.[^.]+/g;
1864
1865var decodeHTMLCached = cached(he.decode);
1866
1867// configurable state
1868var warn$1;
1869var delimiters;
1870var transforms;
1871var preTransforms;
1872var postTransforms;
1873var platformIsPreTag;
1874var platformMustUseProp;
1875var platformGetTagNamespace;
1876
1877/**
1878 * Convert HTML string to AST.
1879 */
1880function parse (
1881 template$$1,
1882 options
1883) {
1884 warn$1 = options.warn || baseWarn;
1885
1886 platformIsPreTag = options.isPreTag || no;
1887 platformMustUseProp = options.mustUseProp || no;
1888 platformGetTagNamespace = options.getTagNamespace || no;
1889
1890 transforms = pluckModuleFunction(options.modules, 'transformNode');
1891 preTransforms = pluckModuleFunction(options.modules, 'preTransformNode');
1892 postTransforms = pluckModuleFunction(options.modules, 'postTransformNode');
1893
1894 delimiters = options.delimiters;
1895
1896 var stack = [];
1897 var preserveWhitespace = options.preserveWhitespace !== false;
1898 var root;
1899 var currentParent;
1900 var inVPre = false;
1901 var inPre = false;
1902 var warned = false;
1903
1904 function warnOnce (msg) {
1905 if (!warned) {
1906 warned = true;
1907 warn$1(msg);
1908 }
1909 }
1910
1911 function endPre (element) {
1912 // check pre state
1913 if (element.pre) {
1914 inVPre = false;
1915 }
1916 if (platformIsPreTag(element.tag)) {
1917 inPre = false;
1918 }
1919 }
1920
1921 parseHTML(template$$1, {
1922 warn: warn$1,
1923 expectHTML: options.expectHTML,
1924 isUnaryTag: options.isUnaryTag,
1925 canBeLeftOpenTag: options.canBeLeftOpenTag,
1926 shouldDecodeNewlines: options.shouldDecodeNewlines,
1927 shouldKeepComment: options.comments,
1928 start: function start (tag, attrs, unary) {
1929 // check namespace.
1930 // inherit parent ns if there is one
1931 var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);
1932
1933 // handle IE svg bug
1934 /* istanbul ignore if */
1935 if (isIE && ns === 'svg') {
1936 attrs = guardIESVGBug(attrs);
1937 }
1938
1939 var element = {
1940 type: 1,
1941 tag: tag,
1942 attrsList: attrs,
1943 attrsMap: makeAttrsMap(attrs),
1944 parent: currentParent,
1945 children: []
1946 };
1947 if (ns) {
1948 element.ns = ns;
1949 }
1950
1951 if (isForbiddenTag(element) && !isServerRendering()) {
1952 element.forbidden = true;
1953 process.env.NODE_ENV !== 'production' && warn$1(
1954 'Templates should only be responsible for mapping the state to the ' +
1955 'UI. Avoid placing tags with side-effects in your templates, such as ' +
1956 "<" + tag + ">" + ', as they will not be parsed.'
1957 );
1958 }
1959
1960 // apply pre-transforms
1961 for (var i = 0; i < preTransforms.length; i++) {
1962 preTransforms[i](element, options);
1963 }
1964
1965 if (!inVPre) {
1966 processPre(element);
1967 if (element.pre) {
1968 inVPre = true;
1969 }
1970 }
1971 if (platformIsPreTag(element.tag)) {
1972 inPre = true;
1973 }
1974 if (inVPre) {
1975 processRawAttrs(element);
1976 } else {
1977 processFor(element);
1978 processIf(element);
1979 processOnce(element);
1980 processKey(element);
1981
1982 // determine whether this is a plain element after
1983 // removing structural attributes
1984 element.plain = !element.key && !attrs.length;
1985
1986 processRef(element);
1987 processSlot(element);
1988 processComponent(element);
1989 for (var i$1 = 0; i$1 < transforms.length; i$1++) {
1990 transforms[i$1](element, options);
1991 }
1992 processAttrs(element);
1993 }
1994
1995 function checkRootConstraints (el) {
1996 if (process.env.NODE_ENV !== 'production') {
1997 if (el.tag === 'slot' || el.tag === 'template') {
1998 warnOnce(
1999 "Cannot use <" + (el.tag) + "> as component root element because it may " +
2000 'contain multiple nodes.'
2001 );
2002 }
2003 if (el.attrsMap.hasOwnProperty('v-for')) {
2004 warnOnce(
2005 'Cannot use v-for on stateful component root element because ' +
2006 'it renders multiple elements.'
2007 );
2008 }
2009 }
2010 }
2011
2012 // tree management
2013 if (!root) {
2014 root = element;
2015 checkRootConstraints(root);
2016 } else if (!stack.length) {
2017 // allow root elements with v-if, v-else-if and v-else
2018 if (root.if && (element.elseif || element.else)) {
2019 checkRootConstraints(element);
2020 addIfCondition(root, {
2021 exp: element.elseif,
2022 block: element
2023 });
2024 } else if (process.env.NODE_ENV !== 'production') {
2025 warnOnce(
2026 "Component template should contain exactly one root element. " +
2027 "If you are using v-if on multiple elements, " +
2028 "use v-else-if to chain them instead."
2029 );
2030 }
2031 }
2032 if (currentParent && !element.forbidden) {
2033 if (element.elseif || element.else) {
2034 processIfConditions(element, currentParent);
2035 } else if (element.slotScope) { // scoped slot
2036 currentParent.plain = false;
2037 var name = element.slotTarget || '"default"';(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element;
2038 } else {
2039 currentParent.children.push(element);
2040 element.parent = currentParent;
2041 }
2042 }
2043 if (!unary) {
2044 currentParent = element;
2045 stack.push(element);
2046 } else {
2047 endPre(element);
2048 }
2049 // apply post-transforms
2050 for (var i$2 = 0; i$2 < postTransforms.length; i$2++) {
2051 postTransforms[i$2](element, options);
2052 }
2053 },
2054
2055 end: function end () {
2056 // remove trailing whitespace
2057 var element = stack[stack.length - 1];
2058 var lastNode = element.children[element.children.length - 1];
2059 if (lastNode && lastNode.type === 3 && lastNode.text === ' ' && !inPre) {
2060 element.children.pop();
2061 }
2062 // pop stack
2063 stack.length -= 1;
2064 currentParent = stack[stack.length - 1];
2065 endPre(element);
2066 },
2067
2068 chars: function chars (text) {
2069 if (!currentParent) {
2070 if (process.env.NODE_ENV !== 'production') {
2071 if (text === template$$1) {
2072 warnOnce(
2073 'Component template requires a root element, rather than just text.'
2074 );
2075 } else if ((text = text.trim())) {
2076 warnOnce(
2077 ("text \"" + text + "\" outside root element will be ignored.")
2078 );
2079 }
2080 }
2081 return
2082 }
2083 // IE textarea placeholder bug
2084 /* istanbul ignore if */
2085 if (isIE &&
2086 currentParent.tag === 'textarea' &&
2087 currentParent.attrsMap.placeholder === text
2088 ) {
2089 return
2090 }
2091 var children = currentParent.children;
2092 text = inPre || text.trim()
2093 ? isTextTag(currentParent) ? text : decodeHTMLCached(text)
2094 // only preserve whitespace if its not right after a starting tag
2095 : preserveWhitespace && children.length ? ' ' : '';
2096 if (text) {
2097 var expression;
2098 if (!inVPre && text !== ' ' && (expression = parseText(text, delimiters))) {
2099 children.push({
2100 type: 2,
2101 expression: expression,
2102 text: text
2103 });
2104 } else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
2105 children.push({
2106 type: 3,
2107 text: text
2108 });
2109 }
2110 }
2111 },
2112 comment: function comment (text) {
2113 currentParent.children.push({
2114 type: 3,
2115 text: text,
2116 isComment: true
2117 });
2118 }
2119 });
2120 return root
2121}
2122
2123function processPre (el) {
2124 if (getAndRemoveAttr(el, 'v-pre') != null) {
2125 el.pre = true;
2126 }
2127}
2128
2129function processRawAttrs (el) {
2130 var l = el.attrsList.length;
2131 if (l) {
2132 var attrs = el.attrs = new Array(l);
2133 for (var i = 0; i < l; i++) {
2134 attrs[i] = {
2135 name: el.attrsList[i].name,
2136 value: JSON.stringify(el.attrsList[i].value)
2137 };
2138 }
2139 } else if (!el.pre) {
2140 // non root node in pre blocks with no attributes
2141 el.plain = true;
2142 }
2143}
2144
2145function processKey (el) {
2146 var exp = getBindingAttr(el, 'key');
2147 if (exp) {
2148 if (process.env.NODE_ENV !== 'production' && el.tag === 'template') {
2149 warn$1("<template> cannot be keyed. Place the key on real elements instead.");
2150 }
2151 el.key = exp;
2152 }
2153}
2154
2155function processRef (el) {
2156 var ref = getBindingAttr(el, 'ref');
2157 if (ref) {
2158 el.ref = ref;
2159 el.refInFor = checkInFor(el);
2160 }
2161}
2162
2163function processFor (el) {
2164 var exp;
2165 if ((exp = getAndRemoveAttr(el, 'v-for'))) {
2166 var inMatch = exp.match(forAliasRE);
2167 if (!inMatch) {
2168 process.env.NODE_ENV !== 'production' && warn$1(
2169 ("Invalid v-for expression: " + exp)
2170 );
2171 return
2172 }
2173 el.for = inMatch[2].trim();
2174 var alias = inMatch[1].trim();
2175 var iteratorMatch = alias.match(forIteratorRE);
2176 if (iteratorMatch) {
2177 el.alias = iteratorMatch[1].trim();
2178 el.iterator1 = iteratorMatch[2].trim();
2179 if (iteratorMatch[3]) {
2180 el.iterator2 = iteratorMatch[3].trim();
2181 }
2182 } else {
2183 el.alias = alias;
2184 }
2185 }
2186}
2187
2188function processIf (el) {
2189 var exp = getAndRemoveAttr(el, 'v-if');
2190 if (exp) {
2191 el.if = exp;
2192 addIfCondition(el, {
2193 exp: exp,
2194 block: el
2195 });
2196 } else {
2197 if (getAndRemoveAttr(el, 'v-else') != null) {
2198 el.else = true;
2199 }
2200 var elseif = getAndRemoveAttr(el, 'v-else-if');
2201 if (elseif) {
2202 el.elseif = elseif;
2203 }
2204 }
2205}
2206
2207function processIfConditions (el, parent) {
2208 var prev = findPrevElement(parent.children);
2209 if (prev && prev.if) {
2210 addIfCondition(prev, {
2211 exp: el.elseif,
2212 block: el
2213 });
2214 } else if (process.env.NODE_ENV !== 'production') {
2215 warn$1(
2216 "v-" + (el.elseif ? ('else-if="' + el.elseif + '"') : 'else') + " " +
2217 "used on element <" + (el.tag) + "> without corresponding v-if."
2218 );
2219 }
2220}
2221
2222function findPrevElement (children) {
2223 var i = children.length;
2224 while (i--) {
2225 if (children[i].type === 1) {
2226 return children[i]
2227 } else {
2228 if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
2229 warn$1(
2230 "text \"" + (children[i].text.trim()) + "\" between v-if and v-else(-if) " +
2231 "will be ignored."
2232 );
2233 }
2234 children.pop();
2235 }
2236 }
2237}
2238
2239function addIfCondition (el, condition) {
2240 if (!el.ifConditions) {
2241 el.ifConditions = [];
2242 }
2243 el.ifConditions.push(condition);
2244}
2245
2246function processOnce (el) {
2247 var once$$1 = getAndRemoveAttr(el, 'v-once');
2248 if (once$$1 != null) {
2249 el.once = true;
2250 }
2251}
2252
2253function processSlot (el) {
2254 if (el.tag === 'slot') {
2255 el.slotName = getBindingAttr(el, 'name');
2256 if (process.env.NODE_ENV !== 'production' && el.key) {
2257 warn$1(
2258 "`key` does not work on <slot> because slots are abstract outlets " +
2259 "and can possibly expand into multiple elements. " +
2260 "Use the key on a wrapping element instead."
2261 );
2262 }
2263 } else {
2264 var slotTarget = getBindingAttr(el, 'slot');
2265 if (slotTarget) {
2266 el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget;
2267 }
2268 if (el.tag === 'template') {
2269 el.slotScope = getAndRemoveAttr(el, 'scope');
2270 }
2271 }
2272}
2273
2274function processComponent (el) {
2275 var binding;
2276 if ((binding = getBindingAttr(el, 'is'))) {
2277 el.component = binding;
2278 }
2279 if (getAndRemoveAttr(el, 'inline-template') != null) {
2280 el.inlineTemplate = true;
2281 }
2282}
2283
2284function processAttrs (el) {
2285 var list = el.attrsList;
2286 var i, l, name, rawName, value, modifiers, isProp;
2287 for (i = 0, l = list.length; i < l; i++) {
2288 name = rawName = list[i].name;
2289 value = list[i].value;
2290 if (dirRE.test(name)) {
2291 // mark element as dynamic
2292 el.hasBindings = true;
2293 // modifiers
2294 modifiers = parseModifiers(name);
2295 if (modifiers) {
2296 name = name.replace(modifierRE, '');
2297 }
2298 if (bindRE.test(name)) { // v-bind
2299 name = name.replace(bindRE, '');
2300 value = parseFilters(value);
2301 isProp = false;
2302 if (modifiers) {
2303 if (modifiers.prop) {
2304 isProp = true;
2305 name = camelize(name);
2306 if (name === 'innerHtml') { name = 'innerHTML'; }
2307 }
2308 if (modifiers.camel) {
2309 name = camelize(name);
2310 }
2311 if (modifiers.sync) {
2312 addHandler(
2313 el,
2314 ("update:" + (camelize(name))),
2315 genAssignmentCode(value, "$event")
2316 );
2317 }
2318 }
2319 if (!el.component && (
2320 isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)
2321 )) {
2322 addProp(el, name, value);
2323 } else {
2324 addAttr(el, name, value);
2325 }
2326 } else if (onRE.test(name)) { // v-on
2327 name = name.replace(onRE, '');
2328 addHandler(el, name, value, modifiers, false, warn$1);
2329 } else { // normal directives
2330 name = name.replace(dirRE, '');
2331 // parse arg
2332 var argMatch = name.match(argRE);
2333 var arg = argMatch && argMatch[1];
2334 if (arg) {
2335 name = name.slice(0, -(arg.length + 1));
2336 }
2337 addDirective(el, name, rawName, value, arg, modifiers);
2338 if (process.env.NODE_ENV !== 'production' && name === 'model') {
2339 checkForAliasModel(el, value);
2340 }
2341 }
2342 } else {
2343 // literal attribute
2344 if (process.env.NODE_ENV !== 'production') {
2345 var expression = parseText(value, delimiters);
2346 if (expression) {
2347 warn$1(
2348 name + "=\"" + value + "\": " +
2349 'Interpolation inside attributes has been removed. ' +
2350 'Use v-bind or the colon shorthand instead. For example, ' +
2351 'instead of <div id="{{ val }}">, use <div :id="val">.'
2352 );
2353 }
2354 }
2355 addAttr(el, name, JSON.stringify(value));
2356 }
2357 }
2358}
2359
2360function checkInFor (el) {
2361 var parent = el;
2362 while (parent) {
2363 if (parent.for !== undefined) {
2364 return true
2365 }
2366 parent = parent.parent;
2367 }
2368 return false
2369}
2370
2371function parseModifiers (name) {
2372 var match = name.match(modifierRE);
2373 if (match) {
2374 var ret = {};
2375 match.forEach(function (m) { ret[m.slice(1)] = true; });
2376 return ret
2377 }
2378}
2379
2380function makeAttrsMap (attrs) {
2381 var map = {};
2382 for (var i = 0, l = attrs.length; i < l; i++) {
2383 if (
2384 process.env.NODE_ENV !== 'production' &&
2385 map[attrs[i].name] && !isIE && !isEdge
2386 ) {
2387 warn$1('duplicate attribute: ' + attrs[i].name);
2388 }
2389 map[attrs[i].name] = attrs[i].value;
2390 }
2391 return map
2392}
2393
2394// for script (e.g. type="x/template") or style, do not decode content
2395function isTextTag (el) {
2396 return el.tag === 'script' || el.tag === 'style'
2397}
2398
2399function isForbiddenTag (el) {
2400 return (
2401 el.tag === 'style' ||
2402 (el.tag === 'script' && (
2403 !el.attrsMap.type ||
2404 el.attrsMap.type === 'text/javascript'
2405 ))
2406 )
2407}
2408
2409var ieNSBug = /^xmlns:NS\d+/;
2410var ieNSPrefix = /^NS\d+:/;
2411
2412/* istanbul ignore next */
2413function guardIESVGBug (attrs) {
2414 var res = [];
2415 for (var i = 0; i < attrs.length; i++) {
2416 var attr = attrs[i];
2417 if (!ieNSBug.test(attr.name)) {
2418 attr.name = attr.name.replace(ieNSPrefix, '');
2419 res.push(attr);
2420 }
2421 }
2422 return res
2423}
2424
2425function checkForAliasModel (el, value) {
2426 var _el = el;
2427 while (_el) {
2428 if (_el.for && _el.alias === value) {
2429 warn$1(
2430 "<" + (el.tag) + " v-model=\"" + value + "\">: " +
2431 "You are binding v-model directly to a v-for iteration alias. " +
2432 "This will not be able to modify the v-for source array because " +
2433 "writing to the alias is like modifying a function local variable. " +
2434 "Consider using an array of objects and use v-model on an object property instead."
2435 );
2436 }
2437 _el = _el.parent;
2438 }
2439}
2440
2441/* */
2442
2443var isStaticKey;
2444var isPlatformReservedTag;
2445
2446var genStaticKeysCached = cached(genStaticKeys$1);
2447
2448/**
2449 * Goal of the optimizer: walk the generated template AST tree
2450 * and detect sub-trees that are purely static, i.e. parts of
2451 * the DOM that never needs to change.
2452 *
2453 * Once we detect these sub-trees, we can:
2454 *
2455 * 1. Hoist them into constants, so that we no longer need to
2456 * create fresh nodes for them on each re-render;
2457 * 2. Completely skip them in the patching process.
2458 */
2459function optimize (root, options) {
2460 if (!root) { return }
2461 isStaticKey = genStaticKeysCached(options.staticKeys || '');
2462 isPlatformReservedTag = options.isReservedTag || no;
2463 // first pass: mark all non-static nodes.
2464 markStatic(root);
2465 // second pass: mark static roots.
2466 markStaticRoots(root, false);
2467}
2468
2469function genStaticKeys$1 (keys) {
2470 return makeMap(
2471 'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +
2472 (keys ? ',' + keys : '')
2473 )
2474}
2475
2476function markStatic (node) {
2477 node.static = isStatic(node);
2478 if (node.type === 1) {
2479 // do not make component slot content static. this avoids
2480 // 1. components not able to mutate slot nodes
2481 // 2. static slot content fails for hot-reloading
2482 if (
2483 !isPlatformReservedTag(node.tag) &&
2484 node.tag !== 'slot' &&
2485 node.attrsMap['inline-template'] == null
2486 ) {
2487 return
2488 }
2489 for (var i = 0, l = node.children.length; i < l; i++) {
2490 var child = node.children[i];
2491 markStatic(child);
2492 if (!child.static) {
2493 node.static = false;
2494 }
2495 }
2496 if (node.ifConditions) {
2497 for (var i$1 = 1, l$1 = node.ifConditions.length; i$1 < l$1; i$1++) {
2498 var block = node.ifConditions[i$1].block;
2499 markStatic(block);
2500 if (!block.static) {
2501 node.static = false;
2502 }
2503 }
2504 }
2505 }
2506}
2507
2508function markStaticRoots (node, isInFor) {
2509 if (node.type === 1) {
2510 if (node.static || node.once) {
2511 node.staticInFor = isInFor;
2512 }
2513 // For a node to qualify as a static root, it should have children that
2514 // are not just static text. Otherwise the cost of hoisting out will
2515 // outweigh the benefits and it's better off to just always render it fresh.
2516 if (node.static && node.children.length && !(
2517 node.children.length === 1 &&
2518 node.children[0].type === 3
2519 )) {
2520 node.staticRoot = true;
2521 return
2522 } else {
2523 node.staticRoot = false;
2524 }
2525 if (node.children) {
2526 for (var i = 0, l = node.children.length; i < l; i++) {
2527 markStaticRoots(node.children[i], isInFor || !!node.for);
2528 }
2529 }
2530 if (node.ifConditions) {
2531 for (var i$1 = 1, l$1 = node.ifConditions.length; i$1 < l$1; i$1++) {
2532 markStaticRoots(node.ifConditions[i$1].block, isInFor);
2533 }
2534 }
2535 }
2536}
2537
2538function isStatic (node) {
2539 if (node.type === 2) { // expression
2540 return false
2541 }
2542 if (node.type === 3) { // text
2543 return true
2544 }
2545 return !!(node.pre || (
2546 !node.hasBindings && // no dynamic bindings
2547 !node.if && !node.for && // not v-if or v-for or v-else
2548 !isBuiltInTag(node.tag) && // not a built-in
2549 isPlatformReservedTag(node.tag) && // not a component
2550 !isDirectChildOfTemplateFor(node) &&
2551 Object.keys(node).every(isStaticKey)
2552 ))
2553}
2554
2555function isDirectChildOfTemplateFor (node) {
2556 while (node.parent) {
2557 node = node.parent;
2558 if (node.tag !== 'template') {
2559 return false
2560 }
2561 if (node.for) {
2562 return true
2563 }
2564 }
2565 return false
2566}
2567
2568/* */
2569
2570var fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/;
2571var simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/;
2572
2573// keyCode aliases
2574var keyCodes = {
2575 esc: 27,
2576 tab: 9,
2577 enter: 13,
2578 space: 32,
2579 up: 38,
2580 left: 37,
2581 right: 39,
2582 down: 40,
2583 'delete': [8, 46]
2584};
2585
2586// #4868: modifiers that prevent the execution of the listener
2587// need to explicitly return null so that we can determine whether to remove
2588// the listener for .once
2589var genGuard = function (condition) { return ("if(" + condition + ")return null;"); };
2590
2591var modifierCode = {
2592 stop: '$event.stopPropagation();',
2593 prevent: '$event.preventDefault();',
2594 self: genGuard("$event.target !== $event.currentTarget"),
2595 ctrl: genGuard("!$event.ctrlKey"),
2596 shift: genGuard("!$event.shiftKey"),
2597 alt: genGuard("!$event.altKey"),
2598 meta: genGuard("!$event.metaKey"),
2599 left: genGuard("'button' in $event && $event.button !== 0"),
2600 middle: genGuard("'button' in $event && $event.button !== 1"),
2601 right: genGuard("'button' in $event && $event.button !== 2")
2602};
2603
2604function genHandlers (
2605 events,
2606 isNative,
2607 warn
2608) {
2609 var res = isNative ? 'nativeOn:{' : 'on:{';
2610 for (var name in events) {
2611 var handler = events[name];
2612 // #5330: warn click.right, since right clicks do not actually fire click events.
2613 if (process.env.NODE_ENV !== 'production' &&
2614 name === 'click' &&
2615 handler && handler.modifiers && handler.modifiers.right
2616 ) {
2617 warn(
2618 "Use \"contextmenu\" instead of \"click.right\" since right clicks " +
2619 "do not actually fire \"click\" events."
2620 );
2621 }
2622 res += "\"" + name + "\":" + (genHandler(name, handler)) + ",";
2623 }
2624 return res.slice(0, -1) + '}'
2625}
2626
2627function genHandler (
2628 name,
2629 handler
2630) {
2631 if (!handler) {
2632 return 'function(){}'
2633 }
2634
2635 if (Array.isArray(handler)) {
2636 return ("[" + (handler.map(function (handler) { return genHandler(name, handler); }).join(',')) + "]")
2637 }
2638
2639 var isMethodPath = simplePathRE.test(handler.value);
2640 var isFunctionExpression = fnExpRE.test(handler.value);
2641
2642 if (!handler.modifiers) {
2643 return isMethodPath || isFunctionExpression
2644 ? handler.value
2645 : ("function($event){" + (handler.value) + "}") // inline statement
2646 } else {
2647 var code = '';
2648 var genModifierCode = '';
2649 var keys = [];
2650 for (var key in handler.modifiers) {
2651 if (modifierCode[key]) {
2652 genModifierCode += modifierCode[key];
2653 // left/right
2654 if (keyCodes[key]) {
2655 keys.push(key);
2656 }
2657 } else {
2658 keys.push(key);
2659 }
2660 }
2661 if (keys.length) {
2662 code += genKeyFilter(keys);
2663 }
2664 // Make sure modifiers like prevent and stop get executed after key filtering
2665 if (genModifierCode) {
2666 code += genModifierCode;
2667 }
2668 var handlerCode = isMethodPath
2669 ? handler.value + '($event)'
2670 : isFunctionExpression
2671 ? ("(" + (handler.value) + ")($event)")
2672 : handler.value;
2673 return ("function($event){" + code + handlerCode + "}")
2674 }
2675}
2676
2677function genKeyFilter (keys) {
2678 return ("if(!('button' in $event)&&" + (keys.map(genFilterCode).join('&&')) + ")return null;")
2679}
2680
2681function genFilterCode (key) {
2682 var keyVal = parseInt(key, 10);
2683 if (keyVal) {
2684 return ("$event.keyCode!==" + keyVal)
2685 }
2686 var alias = keyCodes[key];
2687 return ("_k($event.keyCode," + (JSON.stringify(key)) + (alias ? ',' + JSON.stringify(alias) : '') + ")")
2688}
2689
2690/* */
2691
2692var emptyObject = Object.freeze({});
2693
2694/**
2695 * Check if a string starts with $ or _
2696 */
2697
2698
2699/**
2700 * Define a property.
2701 */
2702function def (obj, key, val, enumerable) {
2703 Object.defineProperty(obj, key, {
2704 value: val,
2705 enumerable: !!enumerable,
2706 writable: true,
2707 configurable: true
2708 });
2709}
2710
2711/* */
2712
2713
2714var uid = 0;
2715
2716/**
2717 * A dep is an observable that can have multiple
2718 * directives subscribing to it.
2719 */
2720var Dep = function Dep () {
2721 this.id = uid++;
2722 this.subs = [];
2723};
2724
2725Dep.prototype.addSub = function addSub (sub) {
2726 this.subs.push(sub);
2727};
2728
2729Dep.prototype.removeSub = function removeSub (sub) {
2730 remove(this.subs, sub);
2731};
2732
2733Dep.prototype.depend = function depend () {
2734 if (Dep.target) {
2735 Dep.target.addDep(this);
2736 }
2737};
2738
2739Dep.prototype.notify = function notify () {
2740 // stabilize the subscriber list first
2741 var subs = this.subs.slice();
2742 for (var i = 0, l = subs.length; i < l; i++) {
2743 subs[i].update();
2744 }
2745};
2746
2747// the current target watcher being evaluated.
2748// this is globally unique because there could be only one
2749// watcher being evaluated at any time.
2750Dep.target = null;
2751
2752/*
2753 * not type checking this file because flow doesn't play well with
2754 * dynamically accessing methods on Array prototype
2755 */
2756
2757var arrayProto = Array.prototype;
2758var arrayMethods = Object.create(arrayProto);[
2759 'push',
2760 'pop',
2761 'shift',
2762 'unshift',
2763 'splice',
2764 'sort',
2765 'reverse'
2766]
2767.forEach(function (method) {
2768 // cache original method
2769 var original = arrayProto[method];
2770 def(arrayMethods, method, function mutator () {
2771 var args = [], len = arguments.length;
2772 while ( len-- ) args[ len ] = arguments[ len ];
2773
2774 var result = original.apply(this, args);
2775 var ob = this.__ob__;
2776 var inserted;
2777 switch (method) {
2778 case 'push':
2779 case 'unshift':
2780 inserted = args;
2781 break
2782 case 'splice':
2783 inserted = args.slice(2);
2784 break
2785 }
2786 if (inserted) { ob.observeArray(inserted); }
2787 // notify change
2788 ob.dep.notify();
2789 return result
2790 });
2791});
2792
2793/* */
2794
2795var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
2796
2797/**
2798 * By default, when a reactive property is set, the new value is
2799 * also converted to become reactive. However when passing down props,
2800 * we don't want to force conversion because the value may be a nested value
2801 * under a frozen data structure. Converting it would defeat the optimization.
2802 */
2803var observerState = {
2804 shouldConvert: true
2805};
2806
2807/**
2808 * Observer class that are attached to each observed
2809 * object. Once attached, the observer converts target
2810 * object's property keys into getter/setters that
2811 * collect dependencies and dispatches updates.
2812 */
2813var Observer = function Observer (value, key) {
2814 this.value = value;
2815 this.dep = new Dep();
2816 this.vmCount = 0;
2817 if (key) {
2818 this.key = key;
2819 }
2820 def(value, '__ob__', this);
2821 if (Array.isArray(value)) {
2822 var augment = hasProto
2823 ? protoAugment
2824 : copyAugment;
2825 augment(value, arrayMethods, arrayKeys);
2826 this.observeArray(value);
2827 } else {
2828 this.walk(value);
2829 }
2830};
2831
2832/**
2833 * Walk through each property and convert them into
2834 * getter/setters. This method should only be called when
2835 * value type is Object.
2836 */
2837Observer.prototype.walk = function walk (obj) {
2838 var keys = Object.keys(obj);
2839 for (var i = 0; i < keys.length; i++) {
2840 defineReactive$$1(obj, keys[i], obj[keys[i]]);
2841 }
2842};
2843
2844/**
2845 * Observe a list of Array items.
2846 */
2847Observer.prototype.observeArray = function observeArray (items) {
2848 for (var i = 0, l = items.length; i < l; i++) {
2849 observe(items[i]);
2850 }
2851};
2852
2853// helpers
2854
2855/**
2856 * Augment an target Object or Array by intercepting
2857 * the prototype chain using __proto__
2858 */
2859function protoAugment (target, src, keys) {
2860 /* eslint-disable no-proto */
2861 target.__proto__ = src;
2862 /* eslint-enable no-proto */
2863}
2864
2865/**
2866 * Augment an target Object or Array by defining
2867 * hidden properties.
2868 */
2869/* istanbul ignore next */
2870function copyAugment (target, src, keys) {
2871 for (var i = 0, l = keys.length; i < l; i++) {
2872 var key = keys[i];
2873 def(target, key, src[key]);
2874 }
2875}
2876
2877/**
2878 * Attempt to create an observer instance for a value,
2879 * returns the new observer if successfully observed,
2880 * or the existing observer if the value already has one.
2881 */
2882function observe (value, asRootData, key) {
2883 if (!isObject(value)) {
2884 return
2885 }
2886 var ob;
2887 if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
2888 ob = value.__ob__;
2889 } else if (
2890 observerState.shouldConvert &&
2891 !isServerRendering() &&
2892 (Array.isArray(value) || isPlainObject(value)) &&
2893 Object.isExtensible(value) &&
2894 !value._isVue
2895 ) {
2896 ob = new Observer(value, key);
2897 ob.__keyPath = ob.__keyPath ? ob.__keyPath : {};
2898 ob.__keyPath[key] = true;
2899 }
2900 if (asRootData && ob) {
2901 ob.vmCount++;
2902 }
2903 return ob
2904}
2905
2906/**
2907 * Define a reactive property on an Object.
2908 */
2909function defineReactive$$1 (
2910 obj,
2911 key,
2912 val,
2913 customSetter,
2914 shallow
2915) {
2916 var dep = new Dep();
2917
2918 var property = Object.getOwnPropertyDescriptor(obj, key);
2919 if (property && property.configurable === false) {
2920 return
2921 }
2922
2923 // cater for pre-defined getter/setters
2924 var getter = property && property.get;
2925 var setter = property && property.set;
2926
2927 var childOb = !shallow && observe(val, undefined, key);
2928 Object.defineProperty(obj, key, {
2929 enumerable: true,
2930 configurable: true,
2931 get: function reactiveGetter () {
2932 var value = getter ? getter.call(obj) : val;
2933 if (Dep.target) {
2934 dep.depend();
2935 if (childOb) {
2936 childOb.dep.depend();
2937 }
2938 if (Array.isArray(value)) {
2939 dependArray(value);
2940 }
2941 }
2942 return value
2943 },
2944 set: function reactiveSetter (newVal) {
2945 var value = getter ? getter.call(obj) : val;
2946 /* eslint-disable no-self-compare */
2947 if (newVal === value || (newVal !== newVal && value !== value)) {
2948 return
2949 }
2950
2951 /* eslint-enable no-self-compare */
2952 if (process.env.NODE_ENV !== 'production' && customSetter) {
2953 customSetter();
2954 }
2955 if (setter) {
2956 setter.call(obj, newVal);
2957 } else {
2958 val = newVal;
2959 }
2960 childOb = !shallow && observe(newVal, undefined, key);
2961 dep.notify();
2962 obj.__keyPath = obj.__keyPath ? obj.__keyPath : {};
2963 obj.__keyPath[key] = true;
2964 }
2965 });
2966}
2967
2968/**
2969 * Set a property on an object. Adds the new property and
2970 * triggers change notification if the property doesn't
2971 * already exist.
2972 */
2973function set (target, key, val) {
2974 if (Array.isArray(target) && isValidArrayIndex(key)) {
2975 target.length = Math.max(target.length, key);
2976 target.splice(key, 1, val);
2977 return val
2978 }
2979 if (hasOwn(target, key)) {
2980 target[key] = val;
2981 return val
2982 }
2983 var ob = (target).__ob__;
2984 if (target._isVue || (ob && ob.vmCount)) {
2985 process.env.NODE_ENV !== 'production' && warn$2(
2986 'Avoid adding reactive properties to a Vue instance or its root $data ' +
2987 'at runtime - declare it upfront in the data option.'
2988 );
2989 return val
2990 }
2991 if (!ob) {
2992 target[key] = val;
2993 return val
2994 }
2995 defineReactive$$1(ob.value, key, val);
2996 // Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
2997 if (!target.__keyPath) {
2998 target.__keyPath = {};
2999 }
3000 target.__keyPath[key] = true;
3001 ob.dep.notify();
3002 return val
3003}
3004
3005/**
3006 * Delete a property and trigger change if necessary.
3007 */
3008
3009
3010/**
3011 * Collect dependencies on array elements when the array is touched, since
3012 * we cannot intercept array element access like property getters.
3013 */
3014function dependArray (value) {
3015 for (var e = (void 0), i = 0, l = value.length; i < l; i++) {
3016 e = value[i];
3017 e && e.__ob__ && e.__ob__.dep.depend();
3018 if (Array.isArray(e)) {
3019 dependArray(e);
3020 }
3021 }
3022}
3023
3024/* */
3025
3026/**
3027 * Option overwriting strategies are functions that handle
3028 * how to merge a parent option value and a child option
3029 * value into the final value.
3030 */
3031var strats = config.optionMergeStrategies;
3032
3033/**
3034 * Options with restrictions
3035 */
3036if (process.env.NODE_ENV !== 'production') {
3037 strats.el = strats.propsData = function (parent, child, vm, key) {
3038 if (!vm) {
3039 warn$2(
3040 "option \"" + key + "\" can only be used during instance " +
3041 'creation with the `new` keyword.'
3042 );
3043 }
3044 return defaultStrat(parent, child)
3045 };
3046}
3047
3048/**
3049 * Helper that recursively merges two data objects together.
3050 */
3051function mergeData (to, from) {
3052 if (!from) { return to }
3053 var key, toVal, fromVal;
3054 var keys = Object.keys(from);
3055 for (var i = 0; i < keys.length; i++) {
3056 key = keys[i];
3057 toVal = to[key];
3058 fromVal = from[key];
3059 if (!hasOwn(to, key)) {
3060 set(to, key, fromVal);
3061 } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
3062 mergeData(toVal, fromVal);
3063 }
3064 }
3065 return to
3066}
3067
3068/**
3069 * Data
3070 */
3071function mergeDataOrFn (
3072 parentVal,
3073 childVal,
3074 vm
3075) {
3076 if (!vm) {
3077 // in a Vue.extend merge, both should be functions
3078 if (!childVal) {
3079 return parentVal
3080 }
3081 if (!parentVal) {
3082 return childVal
3083 }
3084 // when parentVal & childVal are both present,
3085 // we need to return a function that returns the
3086 // merged result of both functions... no need to
3087 // check if parentVal is a function here because
3088 // it has to be a function to pass previous merges.
3089 return function mergedDataFn () {
3090 return mergeData(
3091 typeof childVal === 'function' ? childVal.call(this) : childVal,
3092 parentVal.call(this)
3093 )
3094 }
3095 } else if (parentVal || childVal) {
3096 return function mergedInstanceDataFn () {
3097 // instance merge
3098 var instanceData = typeof childVal === 'function'
3099 ? childVal.call(vm)
3100 : childVal;
3101 var defaultData = typeof parentVal === 'function'
3102 ? parentVal.call(vm)
3103 : undefined;
3104 if (instanceData) {
3105 return mergeData(instanceData, defaultData)
3106 } else {
3107 return defaultData
3108 }
3109 }
3110 }
3111}
3112
3113strats.data = function (
3114 parentVal,
3115 childVal,
3116 vm
3117) {
3118 if (!vm) {
3119 if (childVal && typeof childVal !== 'function') {
3120 process.env.NODE_ENV !== 'production' && warn$2(
3121 'The "data" option should be a function ' +
3122 'that returns a per-instance value in component ' +
3123 'definitions.',
3124 vm
3125 );
3126
3127 return parentVal
3128 }
3129 return mergeDataOrFn.call(this, parentVal, childVal)
3130 }
3131
3132 return mergeDataOrFn(parentVal, childVal, vm)
3133};
3134
3135/**
3136 * Hooks and props are merged as arrays.
3137 */
3138function mergeHook (
3139 parentVal,
3140 childVal
3141) {
3142 return childVal
3143 ? parentVal
3144 ? parentVal.concat(childVal)
3145 : Array.isArray(childVal)
3146 ? childVal
3147 : [childVal]
3148 : parentVal
3149}
3150
3151LIFECYCLE_HOOKS.forEach(function (hook) {
3152 strats[hook] = mergeHook;
3153});
3154
3155/**
3156 * Assets
3157 *
3158 * When a vm is present (instance creation), we need to do
3159 * a three-way merge between constructor options, instance
3160 * options and parent options.
3161 */
3162function mergeAssets (parentVal, childVal) {
3163 var res = Object.create(parentVal || null);
3164 return childVal
3165 ? extend(res, childVal)
3166 : res
3167}
3168
3169ASSET_TYPES.forEach(function (type) {
3170 strats[type + 's'] = mergeAssets;
3171});
3172
3173/**
3174 * Watchers.
3175 *
3176 * Watchers hashes should not overwrite one
3177 * another, so we merge them as arrays.
3178 */
3179strats.watch = function (parentVal, childVal) {
3180 // work around Firefox's Object.prototype.watch...
3181 if (parentVal === nativeWatch) { parentVal = undefined; }
3182 if (childVal === nativeWatch) { childVal = undefined; }
3183 /* istanbul ignore if */
3184 if (!childVal) { return Object.create(parentVal || null) }
3185 if (!parentVal) { return childVal }
3186 var ret = {};
3187 extend(ret, parentVal);
3188 for (var key in childVal) {
3189 var parent = ret[key];
3190 var child = childVal[key];
3191 if (parent && !Array.isArray(parent)) {
3192 parent = [parent];
3193 }
3194 ret[key] = parent
3195 ? parent.concat(child)
3196 : Array.isArray(child) ? child : [child];
3197 }
3198 return ret
3199};
3200
3201/**
3202 * Other object hashes.
3203 */
3204strats.props =
3205strats.methods =
3206strats.inject =
3207strats.computed = function (parentVal, childVal) {
3208 if (!childVal) { return Object.create(parentVal || null) }
3209 if (!parentVal) { return childVal }
3210 var ret = Object.create(null);
3211 extend(ret, parentVal);
3212 extend(ret, childVal);
3213 return ret
3214};
3215strats.provide = mergeDataOrFn;
3216
3217/**
3218 * Default strategy.
3219 */
3220var defaultStrat = function (parentVal, childVal) {
3221 return childVal === undefined
3222 ? parentVal
3223 : childVal
3224};
3225
3226/**
3227 * Merge two option objects into a new one.
3228 * Core utility used in both instantiation and inheritance.
3229 */
3230
3231
3232/**
3233 * Resolve an asset.
3234 * This function is used because child instances need access
3235 * to assets defined in its ancestor chain.
3236 */
3237
3238/* */
3239
3240/* */
3241
3242/* */
3243
3244function on (el, dir) {
3245 if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
3246 warn$2("v-on without argument does not support modifiers.");
3247 }
3248 el.wrapListeners = function (code) { return ("_g(" + code + "," + (dir.value) + ")"); };
3249}
3250
3251/* */
3252
3253function bind$1 (el, dir) {
3254 el.wrapData = function (code) {
3255 return ("_b(" + code + ",'" + (el.tag) + "'," + (dir.value) + "," + (dir.modifiers && dir.modifiers.prop ? 'true' : 'false') + (dir.modifiers && dir.modifiers.sync ? ',true' : '') + ")")
3256 };
3257}
3258
3259/* */
3260
3261var baseDirectives = {
3262 on: on,
3263 bind: bind$1,
3264 cloak: noop
3265};
3266
3267/* */
3268
3269var CodegenState = function CodegenState (options) {
3270 this.options = options;
3271 this.warn = options.warn || baseWarn;
3272 this.transforms = pluckModuleFunction(options.modules, 'transformCode');
3273 this.dataGenFns = pluckModuleFunction(options.modules, 'genData');
3274 this.directives = extend(extend({}, baseDirectives), options.directives);
3275 var isReservedTag = options.isReservedTag || no;
3276 this.maybeComponent = function (el) { return !isReservedTag(el.tag); };
3277 this.onceId = 0;
3278 this.staticRenderFns = [];
3279};
3280
3281
3282
3283function generate$1 (
3284 ast,
3285 options
3286) {
3287 var state = new CodegenState(options);
3288 var code = ast ? genElement(ast, state) : '_c("div")';
3289 return {
3290 render: ("with(this){return " + code + "}"),
3291 staticRenderFns: state.staticRenderFns
3292 }
3293}
3294
3295function genElement (el, state) {
3296 if (el.staticRoot && !el.staticProcessed) {
3297 return genStatic(el, state)
3298 } else if (el.once && !el.onceProcessed) {
3299 return genOnce(el, state)
3300 } else if (el.for && !el.forProcessed) {
3301 return genFor(el, state)
3302 } else if (el.if && !el.ifProcessed) {
3303 return genIf(el, state)
3304 } else if (el.tag === 'template' && !el.slotTarget) {
3305 return genChildren(el, state) || 'void 0'
3306 } else if (el.tag === 'slot') {
3307 return genSlot(el, state)
3308 } else {
3309 // component or element
3310 var code;
3311 if (el.component) {
3312 code = genComponent(el.component, el, state);
3313 } else {
3314 var data = el.plain ? undefined : genData$2(el, state);
3315
3316 var children = el.inlineTemplate ? null : genChildren(el, state, true);
3317 code = "_c('" + (el.tag) + "'" + (data ? ("," + data) : '') + (children ? ("," + children) : '') + ")";
3318 }
3319 // module transforms
3320 for (var i = 0; i < state.transforms.length; i++) {
3321 code = state.transforms[i](el, code);
3322 }
3323 return code
3324 }
3325}
3326
3327// hoist static sub-trees out
3328function genStatic (el, state) {
3329 el.staticProcessed = true;
3330 state.staticRenderFns.push(("with(this){return " + (genElement(el, state)) + "}"));
3331 return ("_m(" + (state.staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + ")")
3332}
3333
3334// v-once
3335function genOnce (el, state) {
3336 el.onceProcessed = true;
3337 if (el.if && !el.ifProcessed) {
3338 return genIf(el, state)
3339 } else if (el.staticInFor) {
3340 var key = '';
3341 var parent = el.parent;
3342 while (parent) {
3343 if (parent.for) {
3344 key = parent.key;
3345 break
3346 }
3347 parent = parent.parent;
3348 }
3349 if (!key) {
3350 process.env.NODE_ENV !== 'production' && state.warn(
3351 "v-once can only be used inside v-for that is keyed. "
3352 );
3353 return genElement(el, state)
3354 }
3355 return ("_o(" + (genElement(el, state)) + "," + (state.onceId++) + (key ? ("," + key) : "") + ")")
3356 } else {
3357 return genStatic(el, state)
3358 }
3359}
3360
3361function genIf (
3362 el,
3363 state,
3364 altGen,
3365 altEmpty
3366) {
3367 el.ifProcessed = true; // avoid recursion
3368 return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
3369}
3370
3371function genIfConditions (
3372 conditions,
3373 state,
3374 altGen,
3375 altEmpty
3376) {
3377 if (!conditions.length) {
3378 return altEmpty || '_e()'
3379 }
3380
3381 var condition = conditions.shift();
3382 if (condition.exp) {
3383 return ("(" + (condition.exp) + ")?" + (genTernaryExp(condition.block)) + ":" + (genIfConditions(conditions, state, altGen, altEmpty)))
3384 } else {
3385 return ("" + (genTernaryExp(condition.block)))
3386 }
3387
3388 // v-if with v-once should generate code like (a)?_m(0):_m(1)
3389 function genTernaryExp (el) {
3390 return altGen
3391 ? altGen(el, state)
3392 : el.once
3393 ? genOnce(el, state)
3394 : genElement(el, state)
3395 }
3396}
3397
3398function genFor (
3399 el,
3400 state,
3401 altGen,
3402 altHelper
3403) {
3404 var exp = el.for;
3405 var alias = el.alias;
3406 var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
3407 var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
3408
3409 if (process.env.NODE_ENV !== 'production' &&
3410 state.maybeComponent(el) &&
3411 el.tag !== 'slot' &&
3412 el.tag !== 'template' &&
3413 !el.key
3414 ) {
3415 state.warn(
3416 "<" + (el.tag) + " v-for=\"" + alias + " in " + exp + "\">: component lists rendered with " +
3417 "v-for should have explicit keys. " +
3418 "See https://vuejs.org/guide/list.html#key for more info.",
3419 true /* tip */
3420 );
3421 }
3422
3423 el.forProcessed = true; // avoid recursion
3424 return (altHelper || '_l') + "((" + exp + ")," +
3425 "function(" + alias + iterator1 + iterator2 + "){" +
3426 "return " + ((altGen || genElement)(el, state)) +
3427 '})'
3428}
3429
3430function genData$2 (el, state) {
3431 var data = '{';
3432
3433 // directives first.
3434 // directives may mutate the el's other properties before they are generated.
3435 var dirs = genDirectives(el, state);
3436 if (dirs) { data += dirs + ','; }
3437
3438 // key
3439 if (el.key) {
3440 data += "key:" + (el.key) + ",";
3441 }
3442 // ref
3443 if (el.ref) {
3444 data += "ref:" + (el.ref) + ",";
3445 }
3446 if (el.refInFor) {
3447 data += "refInFor:true,";
3448 }
3449 // pre
3450 if (el.pre) {
3451 data += "pre:true,";
3452 }
3453 // record original tag name for components using "is" attribute
3454 if (el.component) {
3455 data += "tag:\"" + (el.tag) + "\",";
3456 }
3457 // module data generation functions
3458 for (var i = 0; i < state.dataGenFns.length; i++) {
3459 data += state.dataGenFns[i](el);
3460 }
3461 // attributes
3462 if (el.attrs) {
3463 data += "attrs:{" + (genProps(el.attrs)) + "},";
3464 }
3465 // DOM props
3466 if (el.props) {
3467 data += "domProps:{" + (genProps(el.props)) + "},";
3468 }
3469 // event handlers
3470 if (el.events) {
3471 data += (genHandlers(el.events, false, state.warn)) + ",";
3472 }
3473 if (el.nativeEvents) {
3474 data += (genHandlers(el.nativeEvents, true, state.warn)) + ",";
3475 }
3476 // slot target
3477 if (el.slotTarget) {
3478 data += "slot:" + (el.slotTarget) + ",";
3479 }
3480 // scoped slots
3481 if (el.scopedSlots) {
3482 data += (genScopedSlots(el.scopedSlots, state)) + ",";
3483 }
3484 // component v-model
3485 if (el.model) {
3486 data += "model:{value:" + (el.model.value) + ",callback:" + (el.model.callback) + ",expression:" + (el.model.expression) + "},";
3487 }
3488 // inline-template
3489 if (el.inlineTemplate) {
3490 var inlineTemplate = genInlineTemplate(el, state);
3491 if (inlineTemplate) {
3492 data += inlineTemplate + ",";
3493 }
3494 }
3495 data = data.replace(/,$/, '') + '}';
3496 // v-bind data wrap
3497 if (el.wrapData) {
3498 data = el.wrapData(data);
3499 }
3500 // v-on data wrap
3501 if (el.wrapListeners) {
3502 data = el.wrapListeners(data);
3503 }
3504 return data
3505}
3506
3507function genDirectives (el, state) {
3508 var dirs = el.directives;
3509 if (!dirs) { return }
3510 var res = 'directives:[';
3511 var hasRuntime = false;
3512 var i, l, dir, needRuntime;
3513 for (i = 0, l = dirs.length; i < l; i++) {
3514 dir = dirs[i];
3515 needRuntime = true;
3516 var gen = state.directives[dir.name];
3517 if (gen) {
3518 // compile-time directive that manipulates AST.
3519 // returns true if it also needs a runtime counterpart.
3520 needRuntime = !!gen(el, dir, state.warn);
3521 }
3522 if (needRuntime) {
3523 hasRuntime = true;
3524 res += "{name:\"" + (dir.name) + "\",rawName:\"" + (dir.rawName) + "\"" + (dir.value ? (",value:(" + (dir.value) + "),expression:" + (JSON.stringify(dir.value))) : '') + (dir.arg ? (",arg:\"" + (dir.arg) + "\"") : '') + (dir.modifiers ? (",modifiers:" + (JSON.stringify(dir.modifiers))) : '') + "},";
3525 }
3526 }
3527 if (hasRuntime) {
3528 return res.slice(0, -1) + ']'
3529 }
3530}
3531
3532function genInlineTemplate (el, state) {
3533 var ast = el.children[0];
3534 if (process.env.NODE_ENV !== 'production' && (
3535 el.children.length > 1 || ast.type !== 1
3536 )) {
3537 state.warn('Inline-template components must have exactly one child element.');
3538 }
3539 if (ast.type === 1) {
3540 var inlineRenderFns = generate$1(ast, state.options);
3541 return ("inlineTemplate:{render:function(){" + (inlineRenderFns.render) + "},staticRenderFns:[" + (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){" + code + "}"); }).join(',')) + "]}")
3542 }
3543}
3544
3545function genScopedSlots (
3546 slots,
3547 state
3548) {
3549 return ("scopedSlots:_u([" + (Object.keys(slots).map(function (key) {
3550 return genScopedSlot(key, slots[key], state)
3551 }).join(',')) + "])")
3552}
3553
3554function genScopedSlot (
3555 key,
3556 el,
3557 state
3558) {
3559 if (el.for && !el.forProcessed) {
3560 return genForScopedSlot(key, el, state)
3561 }
3562 return "{key:" + key + ",fn:function(" + (String(el.attrsMap.scope)) + "){" +
3563 "return " + (el.tag === 'template'
3564 ? genChildren(el, state) || 'void 0'
3565 : genElement(el, state)) + "}}"
3566}
3567
3568function genForScopedSlot (
3569 key,
3570 el,
3571 state
3572) {
3573 var exp = el.for;
3574 var alias = el.alias;
3575 var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
3576 var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
3577 el.forProcessed = true; // avoid recursion
3578 return "_l((" + exp + ")," +
3579 "function(" + alias + iterator1 + iterator2 + "){" +
3580 "return " + (genScopedSlot(key, el, state)) +
3581 '})'
3582}
3583
3584function genChildren (
3585 el,
3586 state,
3587 checkSkip,
3588 altGenElement,
3589 altGenNode
3590) {
3591 var children = el.children;
3592 if (children.length) {
3593 var el$1 = children[0];
3594 // optimize single v-for
3595 if (children.length === 1 &&
3596 el$1.for &&
3597 el$1.tag !== 'template' &&
3598 el$1.tag !== 'slot'
3599 ) {
3600 return (altGenElement || genElement)(el$1, state)
3601 }
3602 var normalizationType = checkSkip
3603 ? getNormalizationType(children, state.maybeComponent)
3604 : 0;
3605 var gen = altGenNode || genNode;
3606 return ("[" + (children.map(function (c) { return gen(c, state); }).join(',')) + "]" + (normalizationType ? ("," + normalizationType) : ''))
3607 }
3608}
3609
3610// determine the normalization needed for the children array.
3611// 0: no normalization needed
3612// 1: simple normalization needed (possible 1-level deep nested array)
3613// 2: full normalization needed
3614function getNormalizationType (
3615 children,
3616 maybeComponent
3617) {
3618 var res = 0;
3619 for (var i = 0; i < children.length; i++) {
3620 var el = children[i];
3621 if (el.type !== 1) {
3622 continue
3623 }
3624 if (needsNormalization(el) ||
3625 (el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {
3626 res = 2;
3627 break
3628 }
3629 if (maybeComponent(el) ||
3630 (el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {
3631 res = 1;
3632 }
3633 }
3634 return res
3635}
3636
3637function needsNormalization (el) {
3638 return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
3639}
3640
3641function genNode (node, state) {
3642 if (node.type === 1) {
3643 return genElement(node, state)
3644 } if (node.type === 3 && node.isComment) {
3645 return genComment(node)
3646 } else {
3647 return genText(node)
3648 }
3649}
3650
3651function genText (text) {
3652 return ("_v(" + (text.type === 2
3653 ? text.expression // no need for () because already wrapped in _s()
3654 : transformSpecialNewlines(JSON.stringify(text.text))) + ")")
3655}
3656
3657function genComment (comment) {
3658 return ("_e('" + (comment.text) + "')")
3659}
3660
3661function genSlot (el, state) {
3662 var slotName = el.slotName || '"default"';
3663 var children = genChildren(el, state);
3664 var res = "_t(" + slotName + (children ? ("," + children) : '');
3665 var attrs = el.attrs && ("{" + (el.attrs.map(function (a) { return ((camelize(a.name)) + ":" + (a.value)); }).join(',')) + "}");
3666 var bind$$1 = el.attrsMap['v-bind'];
3667 if ((attrs || bind$$1) && !children) {
3668 res += ",null";
3669 }
3670 if (attrs) {
3671 res += "," + attrs;
3672 }
3673 if (bind$$1) {
3674 res += (attrs ? '' : ',null') + "," + bind$$1;
3675 }
3676 return res + ')'
3677}
3678
3679// componentName is el.component, take it as argument to shun flow's pessimistic refinement
3680function genComponent (
3681 componentName,
3682 el,
3683 state
3684) {
3685 var children = el.inlineTemplate ? null : genChildren(el, state, true);
3686 return ("_c(" + componentName + "," + (genData$2(el, state)) + (children ? ("," + children) : '') + ")")
3687}
3688
3689function genProps (props) {
3690 var res = '';
3691 for (var i = 0; i < props.length; i++) {
3692 var prop = props[i];
3693 res += "\"" + (prop.name) + "\":" + (transformSpecialNewlines(prop.value)) + ",";
3694 }
3695 return res.slice(0, -1)
3696}
3697
3698// #3895, #4268
3699function transformSpecialNewlines (text) {
3700 return text
3701 .replace(/\u2028/g, '\\u2028')
3702 .replace(/\u2029/g, '\\u2029')
3703}
3704
3705/* */
3706
3707// these keywords should not appear inside expressions, but operators like
3708// typeof, instanceof and in are allowed
3709var prohibitedKeywordRE = new RegExp('\\b' + (
3710 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
3711 'super,throw,while,yield,delete,export,import,return,switch,default,' +
3712 'extends,finally,continue,debugger,function,arguments'
3713).split(',').join('\\b|\\b') + '\\b');
3714
3715// these unary operators should not be used as property/method names
3716var unaryOperatorsRE = new RegExp('\\b' + (
3717 'delete,typeof,void'
3718).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)');
3719
3720// check valid identifier for v-for
3721var identRE = /[A-Za-z_$][\w$]*/;
3722
3723// strip strings in expressions
3724var stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
3725
3726// detect problematic expressions in a template
3727function detectErrors (ast) {
3728 var errors = [];
3729 if (ast) {
3730 checkNode(ast, errors);
3731 }
3732 return errors
3733}
3734
3735function checkNode (node, errors) {
3736 if (node.type === 1) {
3737 for (var name in node.attrsMap) {
3738 if (dirRE.test(name)) {
3739 var value = node.attrsMap[name];
3740 if (value) {
3741 if (name === 'v-for') {
3742 checkFor(node, ("v-for=\"" + value + "\""), errors);
3743 } else if (onRE.test(name)) {
3744 checkEvent(value, (name + "=\"" + value + "\""), errors);
3745 } else {
3746 checkExpression(value, (name + "=\"" + value + "\""), errors);
3747 }
3748 }
3749 }
3750 }
3751 if (node.children) {
3752 for (var i = 0; i < node.children.length; i++) {
3753 checkNode(node.children[i], errors);
3754 }
3755 }
3756 } else if (node.type === 2) {
3757 checkExpression(node.expression, node.text, errors);
3758 }
3759}
3760
3761function checkEvent (exp, text, errors) {
3762 var stipped = exp.replace(stripStringRE, '');
3763 var keywordMatch = stipped.match(unaryOperatorsRE);
3764 if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
3765 errors.push(
3766 "avoid using JavaScript unary operator as property name: " +
3767 "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim())
3768 );
3769 }
3770 checkExpression(exp, text, errors);
3771}
3772
3773function checkFor (node, text, errors) {
3774 checkExpression(node.for || '', text, errors);
3775 checkIdentifier(node.alias, 'v-for alias', text, errors);
3776 checkIdentifier(node.iterator1, 'v-for iterator', text, errors);
3777 checkIdentifier(node.iterator2, 'v-for iterator', text, errors);
3778}
3779
3780function checkIdentifier (ident, type, text, errors) {
3781 if (typeof ident === 'string' && !identRE.test(ident)) {
3782 errors.push(("invalid " + type + " \"" + ident + "\" in expression: " + (text.trim())));
3783 }
3784}
3785
3786function checkExpression (exp, text, errors) {
3787 try {
3788 new Function(("return " + exp));
3789 } catch (e) {
3790 var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE);
3791 if (keywordMatch) {
3792 errors.push(
3793 "avoid using JavaScript keyword as property name: " +
3794 "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim())
3795 );
3796 } else {
3797 errors.push(("invalid expression: " + (text.trim())));
3798 }
3799 }
3800}
3801
3802/* */
3803
3804function createFunction (code, errors) {
3805 try {
3806 return new Function(code)
3807 } catch (err) {
3808 errors.push({ err: err, code: code });
3809 return noop
3810 }
3811}
3812
3813function createCompileToFunctionFn (compile) {
3814 var cache = Object.create(null);
3815
3816 return function compileToFunctions (
3817 template$$1,
3818 options,
3819 vm
3820 ) {
3821 options = options || {};
3822
3823 /* istanbul ignore if */
3824 if (process.env.NODE_ENV !== 'production') {
3825 // detect possible CSP restriction
3826 try {
3827 new Function('return 1');
3828 } catch (e) {
3829 if (e.toString().match(/unsafe-eval|CSP/)) {
3830 warn$2(
3831 'It seems you are using the standalone build of Vue.js in an ' +
3832 'environment with Content Security Policy that prohibits unsafe-eval. ' +
3833 'The template compiler cannot work in this environment. Consider ' +
3834 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
3835 'templates into render functions.'
3836 );
3837 }
3838 }
3839 }
3840
3841 // check cache
3842 var key = options.delimiters
3843 ? String(options.delimiters) + template$$1
3844 : template$$1;
3845 if (cache[key]) {
3846 return cache[key]
3847 }
3848
3849 // compile
3850 var compiled = compile(template$$1, options);
3851
3852 // check compilation errors/tips
3853 if (process.env.NODE_ENV !== 'production') {
3854 if (compiled.errors && compiled.errors.length) {
3855 warn$2(
3856 "Error compiling template:\n\n" + template$$1 + "\n\n" +
3857 compiled.errors.map(function (e) { return ("- " + e); }).join('\n') + '\n',
3858 vm
3859 );
3860 }
3861 if (compiled.tips && compiled.tips.length) {
3862 compiled.tips.forEach(function (msg) { return tip(msg, vm); });
3863 }
3864 }
3865
3866 // turn code into functions
3867 var res = {};
3868 var fnGenErrors = [];
3869 res.render = createFunction(compiled.render, fnGenErrors);
3870 res.staticRenderFns = compiled.staticRenderFns.map(function (code) {
3871 return createFunction(code, fnGenErrors)
3872 });
3873
3874 // check function generation errors.
3875 // this should only happen if there is a bug in the compiler itself.
3876 // mostly for codegen development use
3877 /* istanbul ignore if */
3878 if (process.env.NODE_ENV !== 'production') {
3879 if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
3880 warn$2(
3881 "Failed to generate render function:\n\n" +
3882 fnGenErrors.map(function (ref) {
3883 var err = ref.err;
3884 var code = ref.code;
3885
3886 return ((err.toString()) + " in\n\n" + code + "\n");
3887 }).join('\n'),
3888 vm
3889 );
3890 }
3891 }
3892
3893 return (cache[key] = res)
3894 }
3895}
3896
3897/* */
3898
3899function createCompilerCreator (baseCompile) {
3900 return function createCompiler (baseOptions) {
3901 function compile (
3902 template$$1,
3903 options
3904 ) {
3905 var finalOptions = Object.create(baseOptions);
3906 var errors = [];
3907 var tips = [];
3908 finalOptions.warn = function (msg, tip) {
3909 (tip ? tips : errors).push(msg);
3910 };
3911
3912 if (options) {
3913 // merge custom modules
3914 if (options.modules) {
3915 finalOptions.modules =
3916 (baseOptions.modules || []).concat(options.modules);
3917 }
3918 // merge custom directives
3919 if (options.directives) {
3920 finalOptions.directives = extend(
3921 Object.create(baseOptions.directives),
3922 options.directives
3923 );
3924 }
3925 // copy other options
3926 for (var key in options) {
3927 if (key !== 'modules' && key !== 'directives') {
3928 finalOptions[key] = options[key];
3929 }
3930 }
3931 }
3932
3933 var compiled = baseCompile(template$$1, finalOptions);
3934 if (process.env.NODE_ENV !== 'production') {
3935 errors.push.apply(errors, detectErrors(compiled.ast));
3936 }
3937 compiled.errors = errors;
3938 compiled.tips = tips;
3939 return compiled
3940 }
3941
3942 return {
3943 compile: compile,
3944 compileToFunctions: createCompileToFunctionFn(compile)
3945 }
3946 }
3947}
3948
3949var tagMap = {
3950 'br': 'view',
3951 'hr': 'view',
3952
3953 'p': 'view',
3954 'h1': 'view',
3955 'h2': 'view',
3956 'h3': 'view',
3957 'h4': 'view',
3958 'h5': 'view',
3959 'h6': 'view',
3960 'abbr': 'view',
3961 'address': 'view',
3962 'b': 'view',
3963 'bdi': 'view',
3964 'bdo': 'view',
3965 'blockquote': 'view',
3966 'cite': 'view',
3967 'code': 'view',
3968 'del': 'view',
3969 'ins': 'view',
3970 'dfn': 'view',
3971 'em': 'view',
3972 'strong': 'view',
3973 'samp': 'view',
3974 'kbd': 'view',
3975 'var': 'view',
3976 'i': 'view',
3977 'mark': 'view',
3978 'pre': 'view',
3979 'q': 'view',
3980 'ruby': 'view',
3981 'rp': 'view',
3982 'rt': 'view',
3983 's': 'view',
3984 'small': 'view',
3985 'sub': 'view',
3986 'sup': 'view',
3987 'time': 'view',
3988 'u': 'view',
3989 'wbr': 'view',
3990
3991 // 表单元素
3992 'form': 'form',
3993 'input': 'input',
3994 'textarea': 'textarea',
3995 'button': 'button',
3996 'select': 'picker',
3997 'option': 'view',
3998 'optgroup': 'view',
3999 'label': 'label',
4000 'fieldset': 'view',
4001 'datalist': 'picker',
4002 'legend': 'view',
4003 'output': 'view',
4004
4005 // 框架
4006 'iframe': 'view',
4007 // 图像
4008 'img': 'image',
4009 'canvas': 'canvas',
4010 'figure': 'view',
4011 'figcaption': 'view',
4012
4013 // 音视频
4014 'audio': 'audio',
4015 'source': 'audio',
4016 'video': 'video',
4017 'track': 'video',
4018 // 链接
4019 'a': 'navigator',
4020 'nav': 'view',
4021 'link': 'navigator',
4022 // 列表
4023 'ul': 'view',
4024 'ol': 'view',
4025 'li': 'view',
4026 'dl': 'view',
4027 'dt': 'view',
4028 'dd': 'view',
4029 'menu': 'view',
4030 'command': 'view',
4031
4032 // 表格table
4033 'table': 'view',
4034 'caption': 'view',
4035 'th': 'view',
4036 'td': 'view',
4037 'tr': 'view',
4038 'thead': 'view',
4039 'tbody': 'view',
4040 'tfoot': 'view',
4041 'col': 'view',
4042 'colgroup': 'view',
4043
4044 // 样式 节
4045 'div': 'view',
4046 'main': 'view',
4047 'span': 'label',
4048 'header': 'view',
4049 'footer': 'view',
4050 'section': 'view',
4051 'article': 'view',
4052 'aside': 'view',
4053 'details': 'view',
4054 'dialog': 'view',
4055 'summary': 'view',
4056
4057 'progress': 'progress',
4058 'meter': 'progress', // todo
4059 'head': 'view', // todo
4060 'meta': 'view', // todo
4061 'base': 'text', // todo
4062 // 'map': 'image', // TODO不是很恰当
4063 'area': 'navigator', // j结合map使用
4064
4065 'script': 'view',
4066 'noscript': 'view',
4067 'embed': 'view',
4068 'object': 'view',
4069 'param': 'view',
4070
4071 // https://mp.weixin.qq.com/debug/wxadoc/dev/component/
4072 // [...document.querySelectorAll('.markdown-section tbody td:first-child')].map(v => v.textContent).join(',\n')
4073 'view': 'view',
4074 'scroll-view': 'scroll-view',
4075 'swiper': 'swiper',
4076 'icon': 'icon',
4077 'text': 'text',
4078 // 'progress': 'progress',
4079 // 'button': 'button',
4080 // 'form': 'form',
4081 // 'input': 'input',
4082 'checkbox': 'checkbox',
4083 'radio': 'radio',
4084 'picker': 'picker',
4085 'picker-view': 'picker-view',
4086 'slider': 'slider',
4087 'switch': 'switch',
4088 // 'label': 'label',
4089 'navigator': 'navigator',
4090 // 'audio': 'audio',
4091 'image': 'image',
4092 // 'video': 'video',
4093 'map': 'map',
4094 // 'canvas': 'canvas',
4095 'contact-button': 'contact-button',
4096 'block': 'block'
4097};
4098
4099function maybeTag (tagName) {
4100 return tagMap[tagName]
4101}
4102
4103function getWxEleId (index, arr) {
4104 if (!arr || !arr.length) {
4105 return ("'" + index + "'")
4106 }
4107
4108 var str = arr.join("+'-'+");
4109 return ("'" + index + "_'+" + str)
4110}
4111
4112// 检查不允许在 v-for 的时候出现2个及其以上相同 iterator1
4113function checkRepeatIterator (arr, options) {
4114 var len = arr.length;
4115 if (len > 1 && len !== new Set(arr).size) {
4116 options.warn(("同一组件内嵌套的 v-for 不能连续使用相同的索引,目前为: " + arr), false);
4117 }
4118}
4119
4120function fixDefaultIterator (path) {
4121 var forText = path.for;
4122 var iterator1 = path.iterator1;
4123 if (forText && !iterator1) {
4124 path.iterator1 = 'index';
4125 }
4126}
4127
4128function addAttr$1 (path, key, value, inVdom) {
4129 path[key] = value;
4130 path.plain = false;
4131 // path.attrsMap[key] = value
4132 if (!inVdom) {
4133 path.attrsMap[("data-" + key)] = "{{" + value + "}}";
4134 }
4135
4136 // if (!path.attrsList) {
4137 // path.attrsList = []
4138 // }
4139 // path.attrsList.push({ name: `':${key}'`, value })
4140
4141 if (!path.attrs) {
4142 path.attrs = [];
4143 }
4144 path.attrs.push({ name: key, value: value });
4145}
4146
4147function mark (path, options, deps, iteratorArr) {
4148 if ( iteratorArr === void 0 ) iteratorArr = [];
4149
4150 fixDefaultIterator(path);
4151
4152 var tag = path.tag;
4153 var children = path.children;
4154 var iterator1 = path.iterator1;
4155 var events = path.events;
4156 var directives = path.directives;
4157 var ifConditions = path.ifConditions;
4158
4159 var currentArr = Object.assign([], iteratorArr);
4160
4161 if (iterator1) {
4162 currentArr.push(iterator1);
4163 }
4164
4165 checkRepeatIterator(currentArr, options);
4166
4167 // 递归子节点
4168 if (children && children.length) {
4169 children.forEach(function (v, i) {
4170 // const counterIterator = children.slice(0, i).filter(v => v.for).map(v => v.for + '.length').join(`+'-'+`)
4171 mark(v, options, deps, currentArr);
4172 });
4173 }
4174
4175 // fix: v-else events
4176 if (ifConditions && ifConditions.length > 1) {
4177 ifConditions.slice(1).forEach(function (v, i) {
4178 mark(v.block, options, deps, currentArr);
4179 });
4180 }
4181
4182 // for mpvue-template-compiler
4183 // events || v-model
4184 var hasModel = directives && directives.find(function (v) { return v.name === 'model'; });
4185 var needEventsID = events || hasModel;
4186
4187 if (needEventsID) {
4188 var eventId = getWxEleId(deps.eventIndex, currentArr);
4189 // const eventId = getWxEleId(eIndex, currentArr)
4190 addAttr$1(path, 'eventid', eventId);
4191 path.attrsMap['data-comkey'] = '{{$k}}';
4192 deps.eventIndex += 1;
4193 // eIndex += 1
4194 }
4195
4196 // 子组件
4197 if (!tag || maybeTag(tag)) {
4198 return
4199 }
4200
4201 // eg. '1-'+i+'-'+j
4202 var value = getWxEleId(deps.comIndex, currentArr);
4203 addAttr$1(path, 'mpcomid', value, true);
4204 path['mpcomid'] = value;
4205 deps.comIndex += 1;
4206}
4207
4208// 全局的事件触发器 ID
4209// let eIndex = 0
4210function markComponent (ast, options) {
4211 var deps = { comIndex: 0, eventIndex: 0 };
4212 mark(ast, options, deps);
4213
4214 return ast
4215}
4216
4217/* */
4218
4219// for mp
4220// `createCompilerCreator` allows creating compilers that use alternative
4221// parser/optimizer/codegen, e.g the SSR optimizing compiler.
4222// Here we just export a default compiler using the default parts.
4223var createCompiler = createCompilerCreator(function baseCompile (
4224 template$$1,
4225 options
4226) {
4227 var originAst = parse(template$$1.trim(), options);
4228 var ast = markComponent(originAst, options);
4229 optimize(ast, options);
4230 var code = generate$1(ast, options);
4231 return {
4232 ast: ast,
4233 render: code.render,
4234 staticRenderFns: code.staticRenderFns
4235 }
4236});
4237
4238// type:
4239// 0, 默认值, 拼接 ${name}={{ ${content} }}
4240// 1, 拼接 ${name}
4241// 2, 拼接 ${map[key]}={{ '${content}' }}
4242// 3, 拼接 {{ ${content} }}
4243// 4, 拼接为空字符串
4244// 5, 不需要在wxml上表现出来,可直接清除
4245
4246var noSupport = {
4247 type: 4,
4248 check: function (k, v, errors) {
4249 errors(("不支持此指令: " + k + "=\"" + v + "\""));
4250 return false
4251 }
4252};
4253var wxmlDirectiveMap = {
4254 'v-if': {
4255 name: 'wx:if',
4256 type: 0
4257 },
4258 'v-else-if': {
4259 name: 'wx:elif',
4260 type: 0
4261 },
4262 'v-else': {
4263 name: 'wx:else',
4264 type: 1
4265 },
4266 'v-text': {
4267 name: '',
4268 type: 1
4269 },
4270 'v-html': {
4271 name: '',
4272 type: 1
4273 },
4274 'v-on': {
4275 name: '',
4276 map: {
4277 click: 'tap',
4278 touchstart: 'touchstart',
4279 touchmove: 'touchmove',
4280 touchcancel: 'touchcancel',
4281 touchend: 'touchend',
4282 tap: 'tap',
4283 longtap: 'longtap',
4284 input: 'input',
4285 change: 'change',
4286 submit: 'submit',
4287 blur: 'blur',
4288 focus: 'focus',
4289 reset: 'reset',
4290 confirm: 'confirm',
4291 columnchange: 'columnchange',
4292 linechange: 'linechange',
4293 error: 'error',
4294 scrolltoupper: 'scrolltoupper',
4295 scrolltolower: 'scrolltolower',
4296 scroll: 'scroll',
4297 load: 'load'
4298 },
4299 type: 2
4300 },
4301 'v-bind': {
4302 name: '',
4303 map: {
4304 'href': 'url'
4305 },
4306 type: 3
4307 },
4308 'href': {
4309 name: 'url',
4310 type: 2
4311 },
4312 'v-pre': noSupport,
4313 'v-cloak': noSupport,
4314 'v-once': {
4315 name: '',
4316 type: 5
4317 }
4318};
4319
4320var tagConfig = {
4321 virtualTag: ['slot', 'template', 'block']
4322};
4323
4324// babel-plugin-transform-object-to-ternary-operator.js
4325
4326function getStrByNode (node, onlyStr) {
4327 if ( onlyStr === void 0 ) onlyStr = false;
4328
4329 if (onlyStr) {
4330 return node.value || node.name || ''
4331 }
4332 return node.type === 'StringLiteral' ? node : t.stringLiteral(node.name || '')
4333}
4334
4335// 把 { key: value } 转换成 [ value ? 'key' : '' ]
4336var objectVisitor = {
4337 ObjectExpression: function (path) {
4338 var elements = path.node.properties.map(function (propertyItem) {
4339 return t.conditionalExpression(propertyItem.value, getStrByNode(propertyItem.key), t.stringLiteral(''))
4340 });
4341 path.replaceWith(t.arrayExpression(elements));
4342 }
4343};
4344
4345function transformObjectToTernaryOperator (babel$$1) {
4346 return { visitor: objectVisitor }
4347}
4348
4349// 把 { key: value } 转换成 'key:' + value + ';'
4350var objectToStringVisitor = {
4351 ObjectExpression: function (path) {
4352 var expression = path.node.properties.map(function (propertyItem) {
4353 var keyStr = getStrByNode(propertyItem.key, true);
4354 var key = keyStr ? hyphenate(keyStr) : keyStr;
4355 var ref = generate(t.ExpressionStatement(propertyItem.value));
4356 var val = ref.code;
4357 return ("'" + key + ":' + (" + (val.slice(0, -1)) + ") + ';'")
4358 }).join('+');
4359
4360 var p = template(expression)({});
4361 path.replaceWith(p.expression);
4362 }
4363};
4364function transformObjectToString (babel$$1) {
4365 return { visitor: objectToStringVisitor }
4366}
4367
4368function transformDynamicClass (staticClass, clsBinding) {
4369 if ( staticClass === void 0 ) staticClass = '';
4370
4371 var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator] });
4372 // 先实现功能,再优化代码
4373 // https://github.com/babel/babel/issues/7138
4374 var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
4375 return (staticClass + " {{" + cls + "}}")
4376}
4377
4378function transformDynamicStyle (staticStyle, styleBinding) {
4379 if ( staticStyle === void 0 ) staticStyle = '';
4380
4381 var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString] });
4382 var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
4383 return (staticStyle + " {{" + cls + "}}")
4384}
4385
4386var attrs = {
4387 format: function format (attrs) {
4388 if ( attrs === void 0 ) attrs = {};
4389
4390 var obj = {};
4391
4392 Object.keys(attrs).map(function (key) {
4393 var val = attrs[key];
4394 obj[key.replace('@', 'v-on:').replace(/^:/, 'v-bind:')] = val;
4395 });
4396
4397 return obj
4398 },
4399
4400 convertAttr: function convertAttr (ast, log) {
4401 var this$1 = this;
4402
4403 var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
4404 var tag = ast.tag;
4405 var staticClass = ast.staticClass;
4406 var attrs = {};
4407 var wxClass = this.classObj(attrsMap['v-bind:class'], staticClass);
4408 wxClass.length ? attrsMap['class'] = wxClass : '';
4409 var wxStyle = this.styleObj(attrsMap['v-bind:style'], attrsMap['style']);
4410 wxStyle.length ? attrsMap['style'] = wxStyle : '';
4411
4412 Object.keys(attrsMap).map(function (key) {
4413 var val = attrsMap[key];
4414 if (key === 'v-bind:class' || key === 'v-bind:style') {
4415 return
4416 }
4417 if (key === 'v-text') {
4418 ast.children.unshift({
4419 text: ("{{" + val + "}}"),
4420 type: 3
4421 });
4422 } else if (key === 'v-html') {
4423 ast.tag = 'rich-text';
4424 attrs['nodes'] = "{{" + val + "}}";
4425 } else if (key === 'v-show') {
4426 attrs['hidden'] = "{{!(" + val + ")}}";
4427 } else if (/^v\-on\:/i.test(key)) {
4428 attrs = this$1.event(key, val, attrs, tag);
4429 } else if (/^v\-bind\:/i.test(key)) {
4430 attrs = this$1.bind(key, val, attrs, tag, attrsMap['wx:key']);
4431 } else if (/^v\-model/.test(key)) {
4432 attrs = this$1.model(key, val, attrs, tag, log);
4433 } else if (wxmlDirectiveMap[key]) {
4434 var ref = wxmlDirectiveMap[key] || {};
4435 var name = ref.name; if ( name === void 0 ) name = '';
4436 var type = ref.type;
4437 var map = ref.map; if ( map === void 0 ) map = {};
4438 var check = ref.check;
4439 if (!(check && !check(key, val, log)) && !(!name || typeof type !== 'number')) {
4440 // 见 ./wxmlDirectiveMap.js 注释
4441 if (type === 0) {
4442 attrs[name] = "{{" + val + "}}";
4443 }
4444
4445 if (type === 1) {
4446 attrs[name] = undefined;
4447 }
4448
4449 if (type === 2) {
4450 attrs[name] = val;
4451 }
4452
4453 if (type === 3) {
4454 attrs[map[name] || name] = "{{" + val + "}}";
4455 return
4456 }
4457 }
4458 } else if (/^v\-/.test(key)) {
4459 log(("不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
4460 } else {
4461 if ((tagConfig.virtualTag.indexOf(tag) > -1) && (key === 'class' || key === 'style' || key === 'data-mpcomid')) {
4462 if (key !== 'data-mpcomid') {
4463 log(("template 不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
4464 }
4465 } else {
4466 attrs[key] = val;
4467 }
4468 }
4469 });
4470 ast.attrsMap = attrs;
4471 return ast
4472 },
4473
4474 event: function event (key, val, attrs, tag) {
4475 // 小程序能力所致,bind 和 catch 事件同时绑定时候,只会触发 bind ,catch 不会被触发。
4476 // .stop 的使用会阻止冒泡,但是同时绑定了一个非冒泡事件,会导致该元素上的 catchEventName 失效!
4477 // .prevent 可以直接干掉,因为小程序里没有什么默认事件,比如submit并不会跳转页面
4478 // .capture 不能做,因为小程序没有捕获类型的事件
4479 // .self 没有可以判断的标识
4480 // .once 也不能做,因为小程序没有 removeEventListener, 虽然可以直接在 handleProxy 中处理,但非常的不优雅,违背了原意,暂不考虑
4481 var name = key.replace(/^v\-on\:/i, '').replace(/\.prevent/i, '');
4482 var ref = name.split('.');
4483 var eventName = ref[0];
4484 var eventNameMap = ref.slice(1);
4485 var eventMap = wxmlDirectiveMap['v-on'];
4486 var check = wxmlDirectiveMap.check;
4487
4488 if (check) {
4489 check(key, val);
4490 }
4491 var wxmlEventName = '';
4492 if (eventName === 'change' && (tag === 'input' || tag === 'textarea')) {
4493 wxmlEventName = 'blur';
4494 } else {
4495 wxmlEventName = eventMap.map[eventName];
4496 }
4497
4498 var eventType = 'bind';
4499 var isStop = eventNameMap.includes('stop');
4500 if (eventNameMap.includes('capture')) {
4501 eventType = isStop ? 'capture-catch:' : 'capture-bind:';
4502 } else if (isStop) {
4503 eventType = 'catch';
4504 }
4505
4506 wxmlEventName = eventType + (wxmlEventName || eventName);
4507 attrs[wxmlEventName] = 'handleProxy';
4508
4509 return attrs
4510 },
4511
4512 bind: function bind (key, val, attrs, tag, isIf) {
4513 var name = key.replace(/^v\-bind\:/i, '');
4514
4515 if (isIf && name === 'key') {
4516 attrs['wx:key'] = val;
4517 }
4518
4519 if (tag === 'template') {
4520 return attrs
4521 }
4522
4523 if (name === 'href') {
4524 attrs['url'] = "{{" + val + "}}";
4525 } else {
4526 attrs[name] = "{{" + val + "}}";
4527 }
4528
4529 return attrs
4530 },
4531
4532 classObj: function classObj (clsBinding, staticCls) {
4533 if ( clsBinding === void 0 ) clsBinding = '';
4534
4535 if (!clsBinding && !staticCls) {
4536 return ''
4537 }
4538 if (!clsBinding && staticCls) {
4539 return staticCls
4540 }
4541
4542 return transformDynamicClass(staticCls, clsBinding)
4543 },
4544
4545 styleObj: function styleObj (styleBinding, staticStyle) {
4546 if ( styleBinding === void 0 ) styleBinding = '';
4547
4548 if (!styleBinding && !staticStyle) {
4549 return ''
4550 }
4551 if (!styleBinding && staticStyle) {
4552 return staticStyle
4553 }
4554
4555 return transformDynamicStyle(staticStyle, styleBinding)
4556 },
4557
4558 model: function model (key, val, attrs, tag) {
4559 var isFormInput = tag === 'input' || tag === 'textarea';
4560 attrs['value'] = "{{" + val + "}}";
4561 if (key === 'v-model.lazy') {
4562 if (isFormInput) {
4563 attrs['bindblur'] = 'handleProxy';
4564 } else {
4565 attrs['bindchange'] = 'handleProxy';
4566 }
4567 } else {
4568 if (isFormInput) {
4569 attrs['bindinput'] = 'handleProxy';
4570 } else {
4571 attrs['bindchange'] = 'handleProxy';
4572 }
4573 }
4574
4575 return attrs
4576 }
4577};
4578
4579function getSlotsName (obj) {
4580 if (!obj) {
4581 return ''
4582 }
4583 // wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a不能放在最后,会出错
4584 return tmplateSlotsObj(obj)
4585 .concat(
4586 Object.keys(obj).map(function(k) {
4587 return '$slot' + k + ":'" + obj[k] + "'"
4588 })
4589 )
4590 .join(',')
4591}
4592
4593function tmplateSlotsObj(obj) {
4594 if (!obj) {
4595 return []
4596 }
4597 // wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a1不能写成 'a1' 带引号的形式,会出错
4598 var $for = Object.keys(obj)
4599 .map(function(k) {
4600 return (k + ":'" + (obj[k]) + "'")
4601 })
4602 .join(',');
4603 return $for ? [("$for:{" + $for + "}")] : []
4604}
4605
4606var component = {
4607 isComponent: function isComponent (tagName, components) {
4608 if ( components === void 0 ) components = {};
4609
4610 return !!components[tagName]
4611 },
4612 convertComponent: function convertComponent (ast, components, slotName) {
4613 var attrsMap = ast.attrsMap;
4614 var tag = ast.tag;
4615 var mpcomid = ast.mpcomid;
4616 var slots = ast.slots;
4617 if (slotName) {
4618 attrsMap['data'] = "{{...$root[$p], ...$root[$k], $root}}";
4619 // bindedName is available when rendering slot in v-for
4620 var bindedName = attrsMap['v-bind:name'];
4621 if(bindedName) {
4622 attrsMap['is'] = "{{$for[" + bindedName + "]}}";
4623 } else {
4624 attrsMap['is'] = "{{" + slotName + "}}";
4625 }
4626 } else {
4627 var slotsName = getSlotsName(slots);
4628 var restSlotsName = slotsName ? (", " + slotsName) : '';
4629 attrsMap['data'] = "{{...$root[$kk+" + mpcomid + "], $root" + restSlotsName + "}}";
4630 attrsMap['is'] = components[tag].name;
4631 }
4632 return ast
4633 }
4634};
4635
4636var tag = function (ast, options) {
4637 var tag = ast.tag;
4638 var elseif = ast.elseif;
4639 var elseText = ast.else;
4640 var forText = ast.for;
4641 var staticClass = ast.staticClass; if ( staticClass === void 0 ) staticClass = '';
4642 var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
4643 var components = options.components;
4644 var ifText = attrsMap['v-if'];
4645 var href = attrsMap.href;
4646 var bindHref = attrsMap['v-bind:href'];
4647 var name = attrsMap.name;
4648
4649 if (!tag) {
4650 return ast
4651 }
4652 var isComponent = component.isComponent(tag, components);
4653 if (tag !== 'template' && tag !== 'block' && tag !== 'slot' && !isComponent) {
4654 ast.staticClass = staticClass ? ("_" + tag + " " + staticClass) : ("_" + tag);
4655 }
4656 ast.tag = tagMap[tag] || tag;
4657
4658 var isSlot = tag === 'slot';
4659
4660 if ((ifText || elseif || elseText || forText) && tag === 'template') {
4661 ast.tag = 'block';
4662 } else if (isComponent || isSlot) {
4663 var originSlotName = name || 'default';
4664 var slotName = isSlot ? ("$slot" + originSlotName + " || '" + originSlotName + "'") : undefined;
4665
4666 // 用完必须删除,不然会被编译成 <template name="xxx"> 在小程序中就会表示这是一个模版申明而不是使用,小程序中不能同时申明和使用模版
4667 delete ast.attrsMap.name;
4668 ast = component.convertComponent(ast, components, slotName);
4669 ast.tag = 'template';
4670 } else if (tag === 'a' && !(href || bindHref)) {
4671 ast.tag = 'view';
4672 } else if (ast.events && ast.events.scroll) {
4673 ast.tag = 'scroll-view';
4674 } else if (tag === 'input') {
4675 var type = attrsMap.type;
4676 if (type && ['button', 'checkbox', 'radio'].indexOf(type) > -1) {
4677 delete ast.attrsMap.type;
4678 ast.tag = type;
4679 }
4680 if (type === 'button') {
4681 ast.children.push({
4682 text: attrsMap.value || '',
4683 type: 3
4684 });
4685 delete ast.attrsMap.value;
4686 }
4687 }
4688 return ast
4689};
4690
4691var astMap = {
4692 if: 'wx:if',
4693 iterator1: 'wx:for-index',
4694 key: 'wx:key',
4695 alias: 'wx:for-item',
4696 'v-for': 'wx:for'
4697};
4698
4699var convertFor = function (ast) {
4700 var iterator1 = ast.iterator1;
4701 var forText = ast.for;
4702 var key = ast.key;
4703 var alias = ast.alias;
4704 var attrsMap = ast.attrsMap;
4705
4706 if (forText) {
4707 attrsMap[astMap['v-for']] = "{{" + forText + "}}";
4708 if (iterator1) {
4709 attrsMap[astMap['iterator1']] = iterator1;
4710 }
4711 if (key) {
4712 attrsMap[astMap['key']] = key;
4713 }
4714 if (alias) {
4715 attrsMap[astMap['alias']] = alias;
4716 }
4717
4718 delete attrsMap['v-for'];
4719 }
4720
4721 return ast
4722};
4723
4724function convertAst (node, options, util) {
4725 if ( options === void 0 ) options = {};
4726
4727 var children = node.children;
4728 var ifConditions = node.ifConditions;
4729 var staticClass = node.staticClass; if ( staticClass === void 0 ) staticClass = '';
4730 var mpcomid = node.mpcomid;
4731 var tagName = node.tag;
4732 var log = util.log;
4733 var deps = util.deps;
4734 var slots = util.slots;
4735 var slotTemplates = util.slotTemplates;
4736 var wxmlAst = Object.assign({}, node);
4737 var moduleId = options.moduleId;
4738 var components = options.components;
4739 wxmlAst.tag = tagName = tagName ? hyphenate(tagName) : tagName;
4740 // 引入 import, isSlot 是使用 slot 的编译地方,意即 <slot></slot> 的地方
4741 var isSlot = tagName === 'slot';
4742 if (isSlot) {
4743 deps.slots = 'slots';
4744 // 把当前 slot 节点包裹 template
4745 var defSlot = Object.assign({}, wxmlAst);
4746 defSlot.tag = 'template';
4747 var templateName = "" + (defSlot.attrsMap.name || 'default');
4748 defSlot.attrsMap.name = templateName;
4749 wxmlAst.children = [];
4750 defSlot.parent = node.parent.parent;
4751 slotTemplates[templateName] = defSlot;
4752 }
4753
4754 var currentIsComponent = component.isComponent(tagName, components);
4755 if (currentIsComponent) {
4756 deps[tagName] = tagName;
4757 }
4758
4759 if (moduleId && !currentIsComponent && tagConfig.virtualTag.indexOf(tagName) < 0) {
4760 wxmlAst.staticClass = staticClass ? (moduleId + " " + staticClass).replace(/\"/g, '') : moduleId;
4761 } else {
4762 wxmlAst.staticClass = staticClass.replace(/\"/g, '');
4763 }
4764
4765 // 组件内部的node节点全部是 slot
4766 wxmlAst.slots = {};
4767 if (currentIsComponent && children && children.length) {
4768 // 只检查组件下的子节点(不检查孙子节点)是不是具名 slot,不然就是 default slot
4769 children
4770 .reduce(function (res, n) {
4771 var ref = n.attrsMap || {};
4772 var slot = ref.slot;
4773 // 不是具名的,全部放在第一个数组元素中
4774 var arr = slot ? res : res[0];
4775 arr.push(n);
4776 return res
4777 }, [[]])
4778 .forEach(function (n) {
4779 var isDefault = Array.isArray(n);
4780 var slotName = isDefault ? 'default' : n.attrsMap.slot;
4781 var slotId = moduleId + "-" + slotName + "-" + (mpcomid.replace(/\'/g, ''));
4782 var node = isDefault ? { tag: 'slot', attrsMap: {}, children: n } : n;
4783
4784 node.tag = 'template';
4785 node.attrsMap.name = slotId;
4786 delete node.attrsMap.slot;
4787 // 缓存,会集中生成一个 slots 文件
4788 slots[slotId] = { node: convertAst(node, options, util), name: slotName, slotId: slotId };
4789 wxmlAst.slots[slotName] = slotId;
4790 });
4791 // 清理当前组件下的节点信息,因为 slot 都被转移了
4792 children.length = 0;
4793 wxmlAst.children.length = 0;
4794 }
4795
4796 wxmlAst.attrsMap = attrs.format(wxmlAst.attrsMap);
4797 wxmlAst = tag(wxmlAst, options);
4798 wxmlAst = convertFor(wxmlAst, options);
4799 wxmlAst = attrs.convertAttr(wxmlAst, log);
4800 if (children && !isSlot) {
4801 wxmlAst.children = children.map(function (k) { return convertAst(k, options, util); });
4802 }
4803
4804 if (ifConditions) {
4805 var length = ifConditions.length;
4806 for (var i = 1; i < length; i++) {
4807 wxmlAst.ifConditions[i].block = convertAst(ifConditions[i].block, options, util);
4808 }
4809 }
4810
4811 return wxmlAst
4812}
4813
4814function wxmlAst (compiled, options, log) {
4815 if ( options === void 0 ) options = {};
4816
4817 var ast = compiled.ast;
4818 var deps = {
4819 // slots: 'slots'
4820 };
4821 var slots = {
4822 // slotId: nodeAst
4823 };
4824 var slotTemplates = {
4825 };
4826
4827 var wxast = convertAst(ast, options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates });
4828 var children = Object.keys(slotTemplates).map(function (k) { return convertAst(slotTemplates[k], options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates }); });
4829 wxast.children = children.concat(wxast.children);
4830 return {
4831 wxast: wxast,
4832 deps: deps,
4833 slots: slots
4834 }
4835}
4836
4837function generate$2 (obj, options) {
4838 if ( options === void 0 ) options = {};
4839
4840 var tag = obj.tag;
4841 var attrsMap = obj.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
4842 var children = obj.children;
4843 var text = obj.text;
4844 var ifConditions = obj.ifConditions;
4845 if (!tag) { return text }
4846 var child = '';
4847 if (children && children.length) {
4848 // 递归子节点
4849 child = children.map(function (v) { return generate$2(v, options); }).join('');
4850 }
4851
4852 // v-if 指令
4853 var ifConditionsArr = [];
4854 if (ifConditions) {
4855 var length = ifConditions.length;
4856 for (var i = 1; i < length; i++) {
4857 ifConditionsArr.push(generate$2(ifConditions[i].block, options));
4858 }
4859 }
4860
4861 var attrs = Object.keys(attrsMap).map(function (k) { return convertAttr(k, attrsMap[k]); }).join(' ');
4862
4863 var tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea'];
4864 if (tags.indexOf(tag) > -1 && !(children && children.length)) {
4865 return ("<" + tag + (attrs ? ' ' + attrs : '') + " />" + (ifConditionsArr.join('')))
4866 }
4867 return ("<" + tag + (attrs ? ' ' + attrs : '') + ">" + (child || '') + "</" + tag + ">" + (ifConditionsArr.join('')))
4868}
4869
4870function convertAttr (key, val) {
4871 return (val === '' || typeof val === 'undefined') ? key : (key + "=\"" + val + "\"")
4872}
4873
4874var utils = {
4875 toLowerCase: function toLowerCase (str) {
4876 return str.replace(/([A-Z])/g, '-$1').toLowerCase().trim()
4877 },
4878
4879 getChar: function getChar (index) {
4880 return String.fromCharCode(0x61 + index)
4881 },
4882
4883 log: function log (compiled) {
4884 compiled.mpErrors = [];
4885 compiled.mpTips = [];
4886
4887 return function (str, type) {
4888 if (type === 'waring') {
4889 compiled.mpTips.push(str);
4890 } else {
4891 compiled.mpErrors.push(str);
4892 }
4893 }
4894 }
4895};
4896
4897function compileToWxml$1 (compiled, options) {
4898 if ( options === void 0 ) options = {};
4899
4900 // TODO, compiled is undefined
4901 var components = options.components; if ( components === void 0 ) components = {};
4902 var log = utils.log(compiled);
4903
4904 var ref = wxmlAst(compiled, options, log);
4905 var wxast = ref.wxast;
4906 var deps = ref.deps; if ( deps === void 0 ) deps = {};
4907 var slots = ref.slots; if ( slots === void 0 ) slots = {};
4908 var code = generate$2(wxast, options);
4909
4910 // 引用子模版
4911 var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
4912 code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";
4913
4914 // 生成 slots code
4915 Object.keys(slots).forEach(function (k) {
4916 var slot = slots[k];
4917 slot.code = generate$2(slot.node, options);
4918 });
4919
4920 // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响
4921 return { code: code, compiled: compiled, slots: slots, importCode: importCode }
4922}
4923
4924// type:
4925// 0, 默认值, 拼接 ${name}={{ ${content} }}
4926// 1, 拼接 ${name}
4927// 2, 拼接 ${map[key]}={{ '${content}' }}
4928// 3, 拼接 {{ ${content} }}
4929// 4, 拼接为空字符串
4930// 5, 不需要在wxml上表现出来,可直接清除
4931
4932var noSupport$1 = {
4933 type: 4,
4934 check: function (k, v, errors) {
4935 errors(("不支持此指令: " + k + "=\"" + v + "\""));
4936 return false
4937 }
4938};
4939var wxmlDirectiveMap$1 = {
4940 'v-if': {
4941 name: 's-if',
4942 type: 2
4943 },
4944 'v-else-if': {
4945 name: 's-elif',
4946 type: 2
4947 },
4948 'v-else': {
4949 name: 'w-else',
4950 type: 1
4951 },
4952 'v-text': {
4953 name: '',
4954 type: 1
4955 },
4956 'v-html': {
4957 name: '',
4958 type: 1
4959 },
4960 'v-on': {
4961 name: '',
4962 map: {
4963 click: 'tap',
4964 touchstart: 'touchstart',
4965 touchmove: 'touchmove',
4966 touchcancel: 'touchcancel',
4967 touchend: 'touchend',
4968 tap: 'tap',
4969 longtap: 'longtap',
4970 input: 'input',
4971 change: 'change',
4972 submit: 'submit',
4973 blur: 'blur',
4974 focus: 'focus',
4975 reset: 'reset',
4976 confirm: 'confirm',
4977 columnchange: 'columnchange',
4978 linechange: 'linechange',
4979 error: 'error',
4980 scrolltoupper: 'scrolltoupper',
4981 scrolltolower: 'scrolltolower',
4982 scroll: 'scroll',
4983 load: 'load'
4984 },
4985 type: 2
4986 },
4987 'v-bind': {
4988 name: '',
4989 map: {
4990 'href': 'url'
4991 },
4992 type: 3
4993 },
4994 'href': {
4995 name: 'url',
4996 type: 2
4997 },
4998 'v-pre': noSupport$1,
4999 'v-cloak': noSupport$1,
5000 'v-once': {
5001 name: '',
5002 type: 5
5003 }
5004};
5005
5006var tagConfig$1 = {
5007 virtualTag: ['slot', 'template', 'block']
5008};
5009
5010// babel-plugin-transform-object-to-ternary-operator.js
5011
5012function getStrByNode$1 (node, onlyStr) {
5013 if ( onlyStr === void 0 ) onlyStr = false;
5014
5015 if (onlyStr) {
5016 return node.value || node.name || ''
5017 }
5018 return node.type === 'StringLiteral' ? node : t.stringLiteral(node.name || '')
5019}
5020
5021// 把 { key: value } 转换成 [ value ? 'key' : '' ]
5022var objectVisitor$1 = {
5023 ObjectExpression: function (path) {
5024 var elements = path.node.properties.map(function (propertyItem) {
5025 return t.conditionalExpression(propertyItem.value, getStrByNode$1(propertyItem.key), t.stringLiteral(''))
5026 });
5027 path.replaceWith(t.arrayExpression(elements));
5028 }
5029};
5030
5031function transformObjectToTernaryOperator$1 (babel$$1) {
5032 return { visitor: objectVisitor$1 }
5033}
5034
5035// 把 { key: value } 转换成 'key:' + value + ';'
5036var objectToStringVisitor$1 = {
5037 ObjectExpression: function (path) {
5038 var expression = path.node.properties.map(function (propertyItem) {
5039 var keyStr = getStrByNode$1(propertyItem.key, true);
5040 var key = keyStr ? hyphenate(keyStr) : keyStr;
5041 var ref = generate(t.ExpressionStatement(propertyItem.value));
5042 var val = ref.code;
5043 return ("'" + key + ":' + (" + (val.slice(0, -1)) + ") + ';'")
5044 }).join('+');
5045
5046 var p = template(expression)({});
5047 path.replaceWith(p.expression);
5048 }
5049};
5050function transformObjectToString$1 (babel$$1) {
5051 return { visitor: objectToStringVisitor$1 }
5052}
5053
5054function transformDynamicClass$1 (staticClass, clsBinding) {
5055 if ( staticClass === void 0 ) staticClass = '';
5056
5057 var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator$1] });
5058 // 先实现功能,再优化代码
5059 // https://github.com/babel/babel/issues/7138
5060 var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
5061 return (staticClass + " {{" + cls + "}}")
5062}
5063
5064function transformDynamicStyle$1 (staticStyle, styleBinding) {
5065 if ( staticStyle === void 0 ) staticStyle = '';
5066
5067 var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString$1] });
5068 var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
5069 return (staticStyle + " {{" + cls + "}}")
5070}
5071
5072var attrs$1 = {
5073 format: function format (attrs) {
5074 if ( attrs === void 0 ) attrs = {};
5075
5076 var obj = {};
5077
5078 Object.keys(attrs).map(function (key) {
5079 var val = attrs[key];
5080 obj[key.replace('@', 'v-on:').replace(/^:/, 'v-bind:')] = val;
5081 });
5082
5083 return obj
5084 },
5085
5086 convertAttr: function convertAttr (ast, log) {
5087 var this$1 = this;
5088
5089 var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
5090 var tag = ast.tag;
5091 var staticClass = ast.staticClass;
5092 var attrs = {};
5093 var wxClass = this.classObj(attrsMap['v-bind:class'], staticClass);
5094 wxClass.length ? attrsMap['class'] = wxClass : '';
5095 var wxStyle = this.styleObj(attrsMap['v-bind:style'], attrsMap['style']);
5096 wxStyle.length ? attrsMap['style'] = wxStyle : '';
5097
5098 Object.keys(attrsMap).map(function (key) {
5099 var val = attrsMap[key];
5100 if (key === 'v-bind:class' || key === 'v-bind:style') {
5101 return
5102 }
5103 if (key === 'v-text') {
5104 ast.children.unshift({
5105 text: ("{{" + val + "}}"),
5106 type: 3
5107 });
5108 } else if (key === 'v-html') {
5109 ast.tag = 'rich-text';
5110 attrs['nodes'] = "{{" + val + "}}";
5111 } else if (key === 'v-show') {
5112 attrs['hidden'] = "{{!(" + val + ")}}";
5113 } else if (/^v\-on\:/i.test(key)) {
5114 attrs = this$1.event(key, val, attrs, tag);
5115 } else if (/^v\-bind\:/i.test(key)) {
5116 attrs = this$1.bind(key, val, attrs, tag, attrsMap['wx:key']);
5117 } else if (/^v\-model/.test(key)) {
5118 attrs = this$1.model(key, val, attrs, tag, log);
5119 } else if (wxmlDirectiveMap$1[key]) {
5120 var ref = wxmlDirectiveMap$1[key] || {};
5121 var name = ref.name; if ( name === void 0 ) name = '';
5122 var type = ref.type;
5123 var map = ref.map; if ( map === void 0 ) map = {};
5124 var check = ref.check;
5125 if (!(check && !check(key, val, log)) && !(!name || typeof type !== 'number')) {
5126 // 见 ./wxmlDirectiveMap.js 注释
5127 if (type === 0) {
5128 attrs[name] = "{{" + val + "}}";
5129 }
5130
5131 if (type === 1) {
5132 attrs[name] = undefined;
5133 }
5134
5135 if (type === 2) {
5136 attrs[name] = val;
5137 }
5138
5139 if (type === 3) {
5140 attrs[map[name] || name] = "{{" + val + "}}";
5141 return
5142 }
5143 }
5144 } else if (/^v\-/.test(key)) {
5145 log(("不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
5146 } else {
5147 if ((tagConfig$1.virtualTag.indexOf(tag) > -1) && (key === 'class' || key === 'style' || key === 'data-mpcomid')) {
5148 if (key !== 'data-mpcomid') {
5149 log(("template 不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
5150 }
5151 } else {
5152 attrs[key] = val;
5153 }
5154 }
5155 });
5156 ast.attrsMap = attrs;
5157 return ast
5158 },
5159
5160 event: function event (key, val, attrs, tag) {
5161 // 小程序能力所致,bind 和 catch 事件同时绑定时候,只会触发 bind ,catch 不会被触发。
5162 // .stop 的使用会阻止冒泡,但是同时绑定了一个非冒泡事件,会导致该元素上的 catchEventName 失效!
5163 // .prevent 可以直接干掉,因为小程序里没有什么默认事件,比如submit并不会跳转页面
5164 // .capture 不能做,因为小程序没有捕获类型的事件
5165 // .self 没有可以判断的标识
5166 // .once 也不能做,因为小程序没有 removeEventListener, 虽然可以直接在 handleProxy 中处理,但非常的不优雅,违背了原意,暂不考虑
5167 var name = key.replace(/^v\-on\:/i, '').replace(/\.prevent/i, '');
5168 var ref = name.split('.');
5169 var eventName = ref[0];
5170 var eventNameMap = ref.slice(1);
5171 var eventMap = wxmlDirectiveMap$1['v-on'];
5172 var check = wxmlDirectiveMap$1.check;
5173
5174 if (check) {
5175 check(key, val);
5176 }
5177 var wxmlEventName = '';
5178 if (eventName === 'change' && (tag === 'input' || tag === 'textarea')) {
5179 wxmlEventName = 'blur';
5180 } else {
5181 wxmlEventName = eventMap.map[eventName];
5182 }
5183
5184 var eventType = 'bind';
5185 var isStop = eventNameMap.includes('stop');
5186 if (eventNameMap.includes('capture')) {
5187 eventType = isStop ? 'capture-catch:' : 'capture-bind:';
5188 } else if (isStop) {
5189 eventType = 'catch';
5190 }
5191
5192 wxmlEventName = eventType + (wxmlEventName || eventName);
5193 attrs[wxmlEventName] = 'handleProxy';
5194
5195 return attrs
5196 },
5197
5198 bind: function bind (key, val, attrs, tag, isIf) {
5199 var name = key.replace(/^v\-bind\:/i, '');
5200
5201 if (isIf && name === 'key') {
5202 attrs['wx:key'] = val;
5203 }
5204
5205 if (tag === 'template') {
5206 return attrs
5207 }
5208
5209 if (name === 'href') {
5210 attrs['url'] = "{{" + val + "}}";
5211 } else {
5212 attrs[name] = "{{" + val + "}}";
5213 }
5214
5215 if (tag === 'scroll-view') {
5216 if (name === 'scroll-top' || name === 'scroll-left' || name === 'scroll-into-view') {
5217 attrs[name] = "{=" + val + "=}";
5218 }
5219 }
5220
5221 if (tag === 'input' || tag === 'textarea' || tag === 'slider') {
5222 if (name === 'value') {
5223 attrs[name] = "{=" + val + "=}";
5224 }
5225 }
5226
5227 if (tag === 'movable-view' && (name === 'x' || name === 'y')) {
5228 attrs[name] = "{=" + val + "=}";
5229 }
5230
5231 return attrs
5232 },
5233
5234 classObj: function classObj (clsBinding, staticCls) {
5235 if ( clsBinding === void 0 ) clsBinding = '';
5236
5237 if (!clsBinding && !staticCls) {
5238 return ''
5239 }
5240 if (!clsBinding && staticCls) {
5241 return staticCls
5242 }
5243
5244 return transformDynamicClass$1(staticCls, clsBinding)
5245 },
5246
5247 styleObj: function styleObj (styleBinding, staticStyle) {
5248 if ( styleBinding === void 0 ) styleBinding = '';
5249
5250 if (!styleBinding && !staticStyle) {
5251 return ''
5252 }
5253 if (!styleBinding && staticStyle) {
5254 return staticStyle
5255 }
5256
5257 return transformDynamicStyle$1(staticStyle, styleBinding)
5258 },
5259
5260 model: function model (key, val, attrs, tag) {
5261 var isFormInput = tag === 'input' || tag === 'textarea';
5262 attrs['value'] = "{{" + val + "}}";
5263 if (key === 'v-model.lazy') {
5264 if (isFormInput) {
5265 attrs['bindblur'] = 'handleProxy';
5266 } else {
5267 attrs['bindchange'] = 'handleProxy';
5268 }
5269 } else {
5270 if (isFormInput) {
5271 attrs['bindinput'] = 'handleProxy';
5272 } else {
5273 attrs['bindchange'] = 'handleProxy';
5274 }
5275 }
5276
5277 return attrs
5278 }
5279};
5280
5281function getSlotsName$1 (obj) {
5282 if (!obj) {
5283 return ''
5284 }
5285 // wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a不能放在最后,会出错
5286 return tmplateSlotsObj$1(obj)
5287 .concat(
5288 Object.keys(obj).map(function (k) { return ("$slot" + k + ":'" + (obj[k]) + "'"); })
5289 )
5290 .join(',')
5291}
5292
5293function tmplateSlotsObj$1 (obj) {
5294 if (!obj) {
5295 return []
5296 }
5297 // wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a1不能写成 'a1' 带引号的形式,会出错
5298 var $for = Object.keys(obj)
5299 .map(function (k) { return (k + ":'" + (obj[k]) + "'"); })
5300 .join(',');
5301 return $for ? [("$for:{" + $for + "}")] : []
5302}
5303
5304var component$1 = {
5305 isComponent: function isComponent (tagName, components) {
5306 if ( components === void 0 ) components = {};
5307
5308 return !!components[tagName]
5309 },
5310 convertComponent: function convertComponent (ast, components, slotName) {
5311 var attrsMap = ast.attrsMap;
5312 var tag = ast.tag;
5313 var mpcomid = ast.mpcomid;
5314 var slots = ast.slots;
5315 if (slotName) {
5316 attrsMap['data'] = '{{{...$root[$k], $root}}}';
5317 // bindedName is available when rendering slot in v-for
5318 var bindedName = attrsMap['v-bind:name'];
5319 if (bindedName) {
5320 attrsMap['is'] = '{{$for[' + bindedName + ']}}';
5321 } else {
5322 attrsMap['is'] = '{{' + slotName + '}}';
5323 }
5324 } else {
5325 var slotsName = getSlotsName$1(slots);
5326 var restSlotsName = slotsName ? (", " + slotsName) : '';
5327 attrsMap['data'] = "{{{...$root[$kk+" + mpcomid + "], $root" + restSlotsName + "}}}";
5328 attrsMap['is'] = components[tag].name;
5329 }
5330 return ast
5331 }
5332};
5333
5334var tagMap$1 = {
5335 'br': 'view',
5336 'hr': 'view',
5337
5338 'p': 'view',
5339 'h1': 'view',
5340 'h2': 'view',
5341 'h3': 'view',
5342 'h4': 'view',
5343 'h5': 'view',
5344 'h6': 'view',
5345 'abbr': 'view',
5346 'address': 'view',
5347 'b': 'view',
5348 'bdi': 'view',
5349 'bdo': 'view',
5350 'blockquote': 'view',
5351 'cite': 'view',
5352 'code': 'view',
5353 'del': 'view',
5354 'ins': 'view',
5355 'dfn': 'view',
5356 'em': 'view',
5357 'strong': 'view',
5358 'samp': 'view',
5359 'kbd': 'view',
5360 'var': 'view',
5361 'i': 'view',
5362 'mark': 'view',
5363 'pre': 'view',
5364 'q': 'view',
5365 'ruby': 'view',
5366 'rp': 'view',
5367 'rt': 'view',
5368 's': 'view',
5369 'small': 'view',
5370 'sub': 'view',
5371 'sup': 'view',
5372 'time': 'view',
5373 'u': 'view',
5374 'wbr': 'view',
5375
5376 // 表单元素
5377 'form': 'form',
5378 'input': 'input',
5379 'textarea': 'textarea',
5380 'button': 'button',
5381 'select': 'picker',
5382 'option': 'view',
5383 'optgroup': 'view',
5384 'label': 'label',
5385 'fieldset': 'view',
5386 'datalist': 'picker',
5387 'legend': 'view',
5388 'output': 'view',
5389
5390 // 框架
5391 'iframe': 'view',
5392 // 图像
5393 'img': 'image',
5394 'canvas': 'canvas',
5395 'figure': 'view',
5396 'figcaption': 'view',
5397
5398 // 音视频
5399 'audio': 'audio',
5400 'source': 'audio',
5401 'video': 'video',
5402 'track': 'video',
5403 // 链接
5404 'a': 'navigator',
5405 'nav': 'view',
5406 'link': 'navigator',
5407 // 列表
5408 'ul': 'view',
5409 'ol': 'view',
5410 'li': 'view',
5411 'dl': 'view',
5412 'dt': 'view',
5413 'dd': 'view',
5414 'menu': 'view',
5415 'command': 'view',
5416
5417 // 表格table
5418 'table': 'view',
5419 'caption': 'view',
5420 'th': 'view',
5421 'td': 'view',
5422 'tr': 'view',
5423 'thead': 'view',
5424 'tbody': 'view',
5425 'tfoot': 'view',
5426 'col': 'view',
5427 'colgroup': 'view',
5428
5429 // 样式 节
5430 'div': 'view',
5431 'main': 'view',
5432 'span': 'label',
5433 'header': 'view',
5434 'footer': 'view',
5435 'section': 'view',
5436 'article': 'view',
5437 'aside': 'view',
5438 'details': 'view',
5439 'dialog': 'view',
5440 'summary': 'view',
5441
5442 'progress': 'progress',
5443 'meter': 'progress', // todo
5444 'head': 'view', // todo
5445 'meta': 'view', // todo
5446 'base': 'text', // todo
5447 // 'map': 'image', // TODO不是很恰当
5448 'area': 'navigator', // j结合map使用
5449
5450 'script': 'view',
5451 'noscript': 'view',
5452 'embed': 'view',
5453 'object': 'view',
5454 'param': 'view',
5455
5456 // https://mp.weixin.qq.com/debug/wxadoc/dev/component/
5457 // [...document.querySelectorAll('.markdown-section tbody td:first-child')].map(v => v.textContent).join(',\n')
5458 'view': 'view',
5459 'scroll-view': 'scroll-view',
5460 'swiper': 'swiper',
5461 'icon': 'icon',
5462 'text': 'text',
5463 // 'progress': 'progress',
5464 // 'button': 'button',
5465 // 'form': 'form',
5466 // 'input': 'input',
5467 'checkbox': 'checkbox',
5468 'radio': 'radio',
5469 'picker': 'picker',
5470 'picker-view': 'picker-view',
5471 'slider': 'slider',
5472 'switch': 'switch',
5473 // 'label': 'label',
5474 'navigator': 'navigator',
5475 // 'audio': 'audio',
5476 'image': 'image',
5477 // 'video': 'video',
5478 'map': 'map',
5479 // 'canvas': 'canvas',
5480 'contact-button': 'contact-button',
5481 'block': 'block'
5482};
5483
5484var tag$1 = function (ast, options) {
5485 var tag = ast.tag;
5486 var elseif = ast.elseif;
5487 var elseText = ast.else;
5488 var forText = ast.for;
5489 var staticClass = ast.staticClass; if ( staticClass === void 0 ) staticClass = '';
5490 var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
5491 var components = options.components;
5492 var ifText = attrsMap['v-if'];
5493 var href = attrsMap.href;
5494 var bindHref = attrsMap['v-bind:href'];
5495 var name = attrsMap.name;
5496
5497 if (!tag) {
5498 return ast
5499 }
5500 var isComponent = component$1.isComponent(tag, components);
5501 if (tag !== 'template' && tag !== 'block' && tag !== 'slot' && !isComponent) {
5502 ast.staticClass = staticClass ? ("_" + tag + " " + staticClass) : ("_" + tag);
5503 }
5504 ast.tag = tagMap$1[tag] || tag;
5505
5506 var isSlot = tag === 'slot';
5507
5508 if ((ifText || elseif || elseText || forText) && tag === 'template') {
5509 ast.tag = 'block';
5510 } else if (isComponent || isSlot) {
5511 var originSlotName = name || 'default';
5512 var slotName = isSlot ? ("$slot" + originSlotName + " || '" + originSlotName + "'") : undefined;
5513
5514 // 用完必须删除,不然会被编译成 <template name="xxx"> 在小程序中就会表示这是一个模版申明而不是使用,小程序中不能同时申明和使用模版
5515 delete ast.attrsMap.name;
5516 ast = component$1.convertComponent(ast, components, slotName);
5517 ast.tag = 'template';
5518 } else if (tag === 'a' && !(href || bindHref)) {
5519 ast.tag = 'view';
5520 } else if (ast.events && ast.events.scroll) {
5521 ast.tag = 'scroll-view';
5522 } else if (tag === 'input') {
5523 var type = attrsMap.type;
5524 if (type && ['button', 'checkbox', 'radio'].indexOf(type) > -1) {
5525 delete ast.attrsMap.type;
5526 ast.tag = type;
5527 }
5528 if (type === 'button') {
5529 ast.children.push({
5530 text: attrsMap.value || '',
5531 type: 3
5532 });
5533 delete ast.attrsMap.value;
5534 }
5535 }
5536 return ast
5537};
5538
5539var astMap$1 = {
5540 'if': 's-if',
5541 'v-for': 's-for',
5542 'alias': 's-for-item',
5543 'iterator1': 's-for-index',
5544 'key': 's-key'
5545};
5546
5547var convertFor$1 = function (ast) {
5548 var iterator1 = ast.iterator1;
5549 var forText = ast.for;
5550 var key = ast.key;
5551 var alias = ast.alias;
5552 var attrsMap = ast.attrsMap;
5553
5554 // 缩写:<view s-for="p,index in persons">
5555 // 全写:<view s-for="persons" s-for-index="index" s-for-item="p">
5556
5557 if (forText) {
5558 attrsMap[astMap$1['v-for']] = alias + "," + iterator1 + " in " + forText;
5559 // attrsMap[astMap['v-for']] = forText
5560 // if (iterator1) {
5561 // attrsMap[astMap['iterator1']] = iterator1
5562 // }
5563 // if (alias) {
5564 // attrsMap[astMap['alias']] = alias
5565 // }
5566 // if (key) {
5567 // attrsMap[astMap['key']] = key
5568 // }
5569 delete attrsMap['v-for'];
5570 }
5571
5572
5573 return ast
5574};
5575
5576function convertAst$1 (node, options, util) {
5577 if ( options === void 0 ) options = {};
5578
5579 var children = node.children;
5580 var ifConditions = node.ifConditions;
5581 var staticClass = node.staticClass; if ( staticClass === void 0 ) staticClass = '';
5582 var mpcomid = node.mpcomid;
5583 var tagName = node.tag;
5584 var log = util.log;
5585 var deps = util.deps;
5586 var slots = util.slots;
5587 var slotTemplates = util.slotTemplates;
5588 var wxmlAst = Object.assign({}, node);
5589 var moduleId = options.moduleId;
5590 var components = options.components;
5591 wxmlAst.tag = tagName = tagName ? hyphenate(tagName) : tagName;
5592 // 引入 import, isSlot 是使用 slot 的编译地方,意即 <slot></slot> 的地方
5593 var isSlot = tagName === 'slot';
5594 if (isSlot) {
5595 deps.slots = 'slots';
5596 // 把当前 slot 节点包裹 template
5597 var defSlot = Object.assign({}, wxmlAst);
5598 defSlot.tag = 'template';
5599 var templateName = "" + (defSlot.attrsMap.name || 'default');
5600 defSlot.attrsMap.name = templateName;
5601 wxmlAst.children = [];
5602 defSlot.parent = node.parent.parent;
5603 slotTemplates[templateName] = defSlot;
5604 }
5605
5606 var currentIsComponent = component$1.isComponent(tagName, components);
5607 if (currentIsComponent) {
5608 deps[tagName] = tagName;
5609 }
5610
5611 if (moduleId && !currentIsComponent && tagConfig$1.virtualTag.indexOf(tagName) < 0) {
5612 wxmlAst.staticClass = staticClass ? (moduleId + " " + staticClass).replace(/\"/g, '') : moduleId;
5613 } else {
5614 wxmlAst.staticClass = staticClass.replace(/\"/g, '');
5615 }
5616
5617 // 组件内部的node节点全部是 slot
5618 wxmlAst.slots = {};
5619 if (currentIsComponent && children && children.length) {
5620 // 只检查组件下的子节点(不检查孙子节点)是不是具名 slot,不然就是 default slot
5621 children
5622 .reduce(function (res, n) {
5623 var ref = n.attrsMap || {};
5624 var slot = ref.slot;
5625 // 不是具名的,全部放在第一个数组元素中
5626 var arr = slot ? res : res[0];
5627 arr.push(n);
5628 return res
5629 }, [[]])
5630 .forEach(function (n) {
5631 var isDefault = Array.isArray(n);
5632 var slotName = isDefault ? 'default' : n.attrsMap.slot;
5633 var slotId = moduleId + "-" + slotName + "-" + (mpcomid.replace(/\'/g, ''));
5634 var node = isDefault ? { tag: 'slot', attrsMap: {}, children: n } : n;
5635
5636 node.tag = 'template';
5637 node.attrsMap.name = slotId;
5638 delete node.attrsMap.slot;
5639 // 缓存,会集中生成一个 slots 文件
5640 slots[slotId] = { node: convertAst$1(node, options, util), name: slotName, slotId: slotId };
5641 wxmlAst.slots[slotName] = slotId;
5642 });
5643 // 清理当前组件下的节点信息,因为 slot 都被转移了
5644 children.length = 0;
5645 wxmlAst.children.length = 0;
5646 }
5647
5648 wxmlAst.attrsMap = attrs$1.format(wxmlAst.attrsMap);
5649 wxmlAst = tag$1(wxmlAst, options);
5650 wxmlAst = convertFor$1(wxmlAst, options);
5651 wxmlAst = attrs$1.convertAttr(wxmlAst, log);
5652 if (children && !isSlot) {
5653 wxmlAst.children = children.map(function (k) { return convertAst$1(k, options, util); });
5654 }
5655
5656 if (ifConditions) {
5657 var length = ifConditions.length;
5658 for (var i = 1; i < length; i++) {
5659 wxmlAst.ifConditions[i].block = convertAst$1(ifConditions[i].block, options, util);
5660 }
5661 }
5662
5663 return wxmlAst
5664}
5665
5666function wxmlAst$1 (compiled, options, log) {
5667 if ( options === void 0 ) options = {};
5668
5669 var ast = compiled.ast;
5670 var deps = {
5671 // slots: 'slots'
5672 };
5673 var slots = {
5674 // slotId: nodeAst
5675 };
5676 var slotTemplates = {
5677 };
5678
5679 var wxast = convertAst$1(ast, options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates });
5680 var children = Object.keys(slotTemplates).map(function (k) { return convertAst$1(slotTemplates[k], options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates }); });
5681 wxast.children = children.concat(wxast.children);
5682 return {
5683 wxast: wxast,
5684 deps: deps,
5685 slots: slots
5686 }
5687}
5688
5689function generate$3 (obj, options) {
5690 if ( options === void 0 ) options = {};
5691
5692 var tag = obj.tag;
5693 var attrsMap = obj.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
5694 var children = obj.children;
5695 var text = obj.text;
5696 var ifConditions = obj.ifConditions;
5697 if (!tag) { return text }
5698 var child = '';
5699 if (children && children.length) {
5700 // 递归子节点
5701 child = children.map(function (v) { return generate$3(v, options); }).join('');
5702 }
5703
5704 // v-if 指令
5705 var ifConditionsArr = [];
5706 if (ifConditions) {
5707 var length = ifConditions.length;
5708 for (var i = 1; i < length; i++) {
5709 ifConditionsArr.push(generate$3(ifConditions[i].block, options));
5710 }
5711 }
5712
5713 var attrs = Object.keys(attrsMap).map(function (k) { return convertAttr$1(k, attrsMap[k]); }).join(' ');
5714
5715 var tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea'];
5716 if (tags.indexOf(tag) > -1 && !(children && children.length)) {
5717 return ("<" + tag + (attrs ? ' ' + attrs : '') + " />" + (ifConditionsArr.join('')))
5718 }
5719 return ("<" + tag + (attrs ? ' ' + attrs : '') + ">" + (child || '') + "</" + tag + ">" + (ifConditionsArr.join('')))
5720}
5721
5722function convertAttr$1 (key, val) {
5723 return (val === '' || typeof val === 'undefined') ? key : (key + "=\"" + val + "\"")
5724}
5725
5726var utils$1 = {
5727 toLowerCase: function toLowerCase (str) {
5728 return str.replace(/([A-Z])/g, '-$1').toLowerCase().trim()
5729 },
5730
5731 getChar: function getChar (index) {
5732 return String.fromCharCode(0x61 + index)
5733 },
5734
5735 log: function log (compiled) {
5736 compiled.mpErrors = [];
5737 compiled.mpTips = [];
5738
5739 return function (str, type) {
5740 if (type === 'waring') {
5741 compiled.mpTips.push(str);
5742 } else {
5743 compiled.mpErrors.push(str);
5744 }
5745 }
5746 }
5747};
5748
5749function compileToWxml$2 (compiled, options) {
5750 if ( options === void 0 ) options = {};
5751
5752 // TODO, compiled is undefined
5753 var components = options.components; if ( components === void 0 ) components = {};
5754 var log = utils$1.log(compiled);
5755
5756 var ref = wxmlAst$1(compiled, options, log);
5757 var wxast = ref.wxast;
5758 var deps = ref.deps; if ( deps === void 0 ) deps = {};
5759 var slots = ref.slots; if ( slots === void 0 ) slots = {};
5760 var code = generate$3(wxast, options);
5761
5762 // 引用子模版
5763 var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
5764 code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";
5765
5766 // 生成 slots code
5767 Object.keys(slots).forEach(function (k) {
5768 var slot = slots[k];
5769 slot.code = generate$3(slot.node, options);
5770 });
5771
5772 // TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响
5773 return { code: code, compiled: compiled, slots: slots, importCode: importCode }
5774}
5775
5776/* */
5777
5778function compileToWxml (compiled, options, fileExt) {
5779 var code;
5780 switch(fileExt.platform) {
5781 case 'swan':
5782 code = compileToWxml$2(compiled, options);
5783 break
5784 case 'wx':
5785 code = compileToWxml$1(compiled, options);
5786 break
5787 default:
5788 code = compileToWxml$1(compiled, options);
5789 }
5790 return code
5791}
5792
5793var ref = createCompiler(baseOptions);
5794var compile = ref.compile;
5795var compileToFunctions = ref.compileToFunctions;
5796
5797/* */
5798
5799exports.parseComponent = parseComponent;
5800exports.compile = compile;
5801exports.compileToFunctions = compileToFunctions;
5802exports.compileToWxml = compileToWxml;