1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var deindent = _interopDefault(require('de-indent'));
|
8 | var he = _interopDefault(require('he'));
|
9 | var babel = _interopDefault(require('babel-core'));
|
10 | var prettier = _interopDefault(require('prettier'));
|
11 | var t = require('babel-types');
|
12 | var generate = _interopDefault(require('babel-generator'));
|
13 | var template = _interopDefault(require('babel-template'));
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function isObject (obj) {
|
38 | return obj !== null && typeof obj === 'object'
|
39 | }
|
40 |
|
41 | var _toString = Object.prototype.toString;
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | function isPlainObject (obj) {
|
48 | return _toString.call(obj) === '[object Object]'
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function isValidArrayIndex (val) {
|
57 | var n = parseFloat(val);
|
58 | return n >= 0 && Math.floor(n) === n && isFinite(val)
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function 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 |
|
92 |
|
93 | var isBuiltInTag = makeMap('slot,component', true);
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var isReservedAttribute = makeMap('key,ref,slot,is');
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | function 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 |
|
114 |
|
115 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
116 | function hasOwn (obj, key) {
|
117 | return hasOwnProperty.call(obj, key)
|
118 | }
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | function 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 |
|
133 |
|
134 | var camelizeRE = /-(\w)/g;
|
135 | var camelize = cached(function (str) {
|
136 | return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
|
137 | });
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | var hyphenateRE = /([^-])([A-Z])/g;
|
148 | var hyphenate = cached(function (str) {
|
149 | return str
|
150 | .replace(hyphenateRE, '$1-$2')
|
151 | .replace(hyphenateRE, '$1-$2')
|
152 | .toLowerCase()
|
153 | });
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | function extend (to, _from) {
|
169 | for (var key in _from) {
|
170 | to[key] = _from[key];
|
171 | }
|
172 | return to
|
173 | }
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | function noop (a, b, c) {}
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | var no = function (a, b, c) { return false; };
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | var identity = function (_) { return _; };
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | function genStaticKeys (modules) {
|
201 | return modules.reduce(function (keys, m) {
|
202 | return keys.concat(m.staticKeys || [])
|
203 | }, []).join(',')
|
204 | }
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | var isUnaryTag = makeMap(
|
221 | 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
|
222 | 'link,meta,param,source,track,wbr'
|
223 | );
|
224 |
|
225 |
|
226 |
|
227 | var canBeLeftOpenTag = makeMap(
|
228 | 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'
|
229 | );
|
230 |
|
231 |
|
232 |
|
233 | var 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 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | var singleAttrIdentifier = /([^\s"'<>/=]+)/;
|
254 | var singleAttrAssign = /(?:=)/;
|
255 | var singleAttrValues = [
|
256 |
|
257 | /"([^"]*)"+/.source,
|
258 |
|
259 | /'([^']*)'+/.source,
|
260 |
|
261 | /([^\s"'=<>`]+)/.source
|
262 | ];
|
263 | var attribute = new RegExp(
|
264 | '^\\s*' + singleAttrIdentifier.source +
|
265 | '(?:\\s*(' + singleAttrAssign.source + ')' +
|
266 | '\\s*(?:' + singleAttrValues.join('|') + '))?'
|
267 | );
|
268 |
|
269 |
|
270 |
|
271 | var ncname = '[a-zA-Z_][\\w\\-\\.]*';
|
272 | var qnameCapture = '((?:' + ncname + '\\:)?' + ncname + ')';
|
273 | var startTagOpen = new RegExp('^<' + qnameCapture);
|
274 | var startTagClose = /^\s*(\/?)>/;
|
275 | var endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>');
|
276 | var doctype = /^<!DOCTYPE [^>]+>/i;
|
277 | var comment = /^<!--/;
|
278 | var conditionalComment = /^<!\[/;
|
279 |
|
280 | var IS_REGEX_CAPTURING_BROKEN = false;
|
281 | 'x'.replace(/x(.)?/g, function (m, g) {
|
282 | IS_REGEX_CAPTURING_BROKEN = g === '';
|
283 | });
|
284 |
|
285 |
|
286 | var isPlainTextElement = makeMap('script,style,textarea', true);
|
287 | var reCache = {};
|
288 |
|
289 | var decodingMap = {
|
290 | '<': '<',
|
291 | '>': '>',
|
292 | '"': '"',
|
293 | '&': '&',
|
294 | ' ': '\n'
|
295 | };
|
296 | var encodedAttr = /&(?:lt|gt|quot|amp);/g;
|
297 | var encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#10);/g;
|
298 |
|
299 |
|
300 | var isIgnoreNewlineTag = makeMap('pre,textarea', true);
|
301 | var shouldIgnoreFirstNewline = function (tag, html) { return tag && isIgnoreNewlineTag(tag) && html[0] === '\n'; };
|
302 |
|
303 | function decodeAttr (value, shouldDecodeNewlines) {
|
304 | var re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr;
|
305 | return value.replace(re, function (match) { return decodingMap[match]; })
|
306 | }
|
307 |
|
308 | function 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 |
|
318 | if (!lastTag || !isPlainTextElement(lastTag)) {
|
319 | if (shouldIgnoreFirstNewline(lastTag, html)) {
|
320 | advance(1);
|
321 | }
|
322 | var textEnd = html.indexOf('<');
|
323 | if (textEnd === 0) {
|
324 |
|
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 |
|
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 |
|
348 | var doctypeMatch = html.match(doctype);
|
349 | if (doctypeMatch) {
|
350 | advance(doctypeMatch[0].length);
|
351 | continue
|
352 | }
|
353 |
|
354 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
525 | pos = 0;
|
526 | }
|
527 |
|
528 | if (pos >= 0) {
|
529 |
|
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 |
|
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 |
|
564 | var splitRE = /\r?\n/g;
|
565 | var replaceRE = /./g;
|
566 | var isSpecialTag = makeMap('script,style,template', true);
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | function 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 {
|
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 |
|
647 |
|
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 |
|
678 |
|
679 | var isPreTag = function (tag) { return tag === 'pre'; };
|
680 |
|
681 | var 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 |
|
691 |
|
692 | var isReservedAttr = makeMap('style,class');
|
693 |
|
694 |
|
695 |
|
696 | var canBeLeftOpenTag$1 = makeMap(
|
697 | 'web,spinner,switch,video,textarea,canvas,' +
|
698 | 'indicator,marquee,countdown',
|
699 | true
|
700 | );
|
701 |
|
702 | var isUnaryTag$1 = makeMap(
|
703 | 'embed,img,image,input,link,meta',
|
704 | true
|
705 | );
|
706 |
|
707 | function mustUseProp () { }
|
708 | function getTagNamespace () { }
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 | var validDivisionCharRE = /[\w).+\-_$\]]/;
|
720 |
|
721 | function 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 &&
|
745 | exp.charCodeAt(i + 1) !== 0x7C &&
|
746 | exp.charCodeAt(i - 1) !== 0x7C &&
|
747 | !curly && !square && !paren
|
748 | ) {
|
749 | if (expression === undefined) {
|
750 |
|
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 |
|
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 |
|
803 | function wrapFilter (exp, filter) {
|
804 | var i = filter.indexOf('(');
|
805 | if (i < 0) {
|
806 |
|
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 |
|
817 | var defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g;
|
818 | var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
|
819 |
|
820 | var 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 |
|
826 | function 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 |
|
840 | if (index > lastIndex) {
|
841 | tokens.push(JSON.stringify(text.slice(lastIndex, index)));
|
842 | }
|
843 |
|
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 |
|
856 | function baseWarn (msg) {
|
857 | console.error(("[Vue compiler]: " + msg));
|
858 | }
|
859 |
|
860 | function pluckModuleFunction (
|
861 | modules,
|
862 | key
|
863 | ) {
|
864 | return modules
|
865 | ? modules.map(function (m) { return m[key]; }).filter(function (_) { return _; })
|
866 | : []
|
867 | }
|
868 |
|
869 | function addProp (el, name, value) {
|
870 | (el.props || (el.props = [])).push({ name: name, value: value });
|
871 | }
|
872 |
|
873 | function addAttr (el, name, value) {
|
874 | (el.attrs || (el.attrs = [])).push({ name: name, value: value });
|
875 | }
|
876 |
|
877 | function 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 |
|
888 | function addHandler (
|
889 | el,
|
890 | name,
|
891 | value,
|
892 | modifiers,
|
893 | important,
|
894 | warn
|
895 | ) {
|
896 |
|
897 |
|
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 |
|
908 | if (modifiers && modifiers.capture) {
|
909 | delete modifiers.capture;
|
910 | name = '!' + name;
|
911 | }
|
912 | if (modifiers && modifiers.once) {
|
913 | delete modifiers.once;
|
914 | name = '~' + name;
|
915 | }
|
916 |
|
917 | if (modifiers && modifiers.passive) {
|
918 | delete modifiers.passive;
|
919 | name = '&' + name;
|
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 |
|
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 |
|
940 | function 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 |
|
958 | function 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 |
|
974 | function 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 );
|
992 | if (classBinding) {
|
993 | el.classBinding = classBinding;
|
994 | }
|
995 | }
|
996 |
|
997 | function 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 |
|
1008 | var klass = {
|
1009 | staticKeys: ['staticClass'],
|
1010 | transformNode: transformNode,
|
1011 | genData: genData
|
1012 | };
|
1013 |
|
1014 |
|
1015 |
|
1016 | var 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 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 | function transformNode$1 (el, options) {
|
1040 | var warn = options.warn || baseWarn;
|
1041 | var staticStyle = getAndRemoveAttr(el, 'style');
|
1042 | if (staticStyle) {
|
1043 |
|
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 );
|
1059 | if (styleBinding) {
|
1060 | el.styleBinding = styleBinding;
|
1061 | }
|
1062 | }
|
1063 |
|
1064 | function 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 |
|
1075 | var style = {
|
1076 | staticKeys: ['staticStyle'],
|
1077 | transformNode: transformNode$1,
|
1078 | genData: genData$1
|
1079 | };
|
1080 |
|
1081 | var modules = [
|
1082 | klass,
|
1083 | style
|
1084 | ];
|
1085 |
|
1086 | var ASSET_TYPES = [
|
1087 | 'component',
|
1088 | 'directive',
|
1089 | 'filter'
|
1090 | ];
|
1091 |
|
1092 | var 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 |
|
1121 | var config = ({
|
1122 | |
1123 |
|
1124 |
|
1125 | optionMergeStrategies: Object.create(null),
|
1126 |
|
1127 | |
1128 |
|
1129 |
|
1130 | silent: false,
|
1131 |
|
1132 | |
1133 |
|
1134 |
|
1135 | productionTip: process.env.NODE_ENV !== 'production',
|
1136 |
|
1137 | |
1138 |
|
1139 |
|
1140 | devtools: process.env.NODE_ENV !== 'production',
|
1141 |
|
1142 | |
1143 |
|
1144 |
|
1145 | performance: false,
|
1146 |
|
1147 | |
1148 |
|
1149 |
|
1150 | errorHandler: null,
|
1151 |
|
1152 | |
1153 |
|
1154 |
|
1155 | warnHandler: null,
|
1156 |
|
1157 | |
1158 |
|
1159 |
|
1160 | ignoredElements: [],
|
1161 |
|
1162 | |
1163 |
|
1164 |
|
1165 | keyCodes: Object.create(null),
|
1166 |
|
1167 | |
1168 |
|
1169 |
|
1170 |
|
1171 | isReservedTag: no,
|
1172 |
|
1173 | |
1174 |
|
1175 |
|
1176 |
|
1177 | isReservedAttr: no,
|
1178 |
|
1179 | |
1180 |
|
1181 |
|
1182 |
|
1183 | isUnknownElement: no,
|
1184 |
|
1185 | |
1186 |
|
1187 |
|
1188 | getTagNamespace: noop,
|
1189 |
|
1190 | |
1191 |
|
1192 |
|
1193 | parsePlatformTagName: identity,
|
1194 |
|
1195 | |
1196 |
|
1197 |
|
1198 |
|
1199 | mustUseProp: no,
|
1200 |
|
1201 | |
1202 |
|
1203 |
|
1204 | _lifecycleHooks: LIFECYCLE_HOOKS
|
1205 | });
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 | function 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 |
|
1243 |
|
1244 | function 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 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 | var len;
|
1271 | var str;
|
1272 | var chr;
|
1273 | var index;
|
1274 | var expressionPos;
|
1275 | var expressionEndPos;
|
1276 |
|
1277 | function 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 |
|
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 |
|
1305 | function next () {
|
1306 | return str.charCodeAt(++index)
|
1307 | }
|
1308 |
|
1309 | function eof () {
|
1310 | return index >= len
|
1311 | }
|
1312 |
|
1313 | function isStringStart (chr) {
|
1314 | return chr === 0x22 || chr === 0x27
|
1315 | }
|
1316 |
|
1317 | function 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 |
|
1335 | function parseString (chr) {
|
1336 | var stringQuote = chr;
|
1337 | while (!eof()) {
|
1338 | chr = next();
|
1339 | if (chr === stringQuote) {
|
1340 | break
|
1341 | }
|
1342 | }
|
1343 | }
|
1344 |
|
1345 |
|
1346 |
|
1347 | var warn;
|
1348 |
|
1349 |
|
1350 |
|
1351 | var RANGE_TOKEN = '__r';
|
1352 | var CHECKBOX_RADIO_TOKEN = '__c';
|
1353 |
|
1354 | function 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 |
|
1374 |
|
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 |
|
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 |
|
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 |
|
1409 | return true
|
1410 | }
|
1411 |
|
1412 | function 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 |
|
1443 | function 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 |
|
1455 | function 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 |
|
1472 | function 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 |
|
1511 | function text (el, dir) {
|
1512 | if (dir.value) {
|
1513 | addProp(el, 'textContent', ("_s(" + (dir.value) + ")"));
|
1514 | }
|
1515 | }
|
1516 |
|
1517 |
|
1518 |
|
1519 | function html (el, dir) {
|
1520 | if (dir.value) {
|
1521 | addProp(el, 'innerHTML', ("_s(" + (dir.value) + ")"));
|
1522 | }
|
1523 | }
|
1524 |
|
1525 | var directives = {
|
1526 | model: model,
|
1527 | text: text,
|
1528 | html: html
|
1529 | };
|
1530 |
|
1531 |
|
1532 |
|
1533 | var 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 |
|
1539 |
|
1540 | var canBeLeftOpenTag$2 = makeMap(
|
1541 | 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source'
|
1542 | );
|
1543 |
|
1544 |
|
1545 |
|
1546 | var 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 |
|
1556 | var 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 |
|
1571 | var warn$2 = noop;
|
1572 | var tip = noop;
|
1573 | var formatComponentName = (null);
|
1574 |
|
1575 | if (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 |
|
1666 | function 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 |
|
1674 | if (inBrowser && typeof console !== 'undefined') {
|
1675 | console.error(err);
|
1676 | } else {
|
1677 | throw err
|
1678 | }
|
1679 | }
|
1680 | }
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 | var hasProto = '__proto__' in {};
|
1686 |
|
1687 |
|
1688 | var inBrowser = typeof window !== 'undefined';
|
1689 | var UA = ['mpvue-runtime'].join();
|
1690 | var isIE = UA && /msie|trident/.test(UA);
|
1691 | var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
|
1692 | var isEdge = UA && UA.indexOf('edge/') > 0;
|
1693 | var isAndroid = UA && UA.indexOf('android') > 0;
|
1694 | var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
|
1695 | var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
1696 |
|
1697 |
|
1698 | var nativeWatch = ({}).watch;
|
1699 |
|
1700 | var supportsPassive = false;
|
1701 | if (inBrowser) {
|
1702 | try {
|
1703 | var opts = {};
|
1704 | Object.defineProperty(opts, 'passive', ({
|
1705 | get: function get () {
|
1706 |
|
1707 | supportsPassive = true;
|
1708 | }
|
1709 | }));
|
1710 | window.addEventListener('test-passive', null, opts);
|
1711 | } catch (e) {}
|
1712 | }
|
1713 |
|
1714 |
|
1715 |
|
1716 | var _isServer;
|
1717 | var isServerRendering = function () {
|
1718 | if (_isServer === undefined) {
|
1719 |
|
1720 | if (!inBrowser && typeof global !== 'undefined') {
|
1721 |
|
1722 |
|
1723 | _isServer = global['process'].env.VUE_ENV === 'server';
|
1724 | } else {
|
1725 | _isServer = false;
|
1726 | }
|
1727 | }
|
1728 | return _isServer
|
1729 | };
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 | function isNative (Ctor) {
|
1736 | return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
|
1737 | }
|
1738 |
|
1739 | var hasSymbol =
|
1740 | typeof Symbol !== 'undefined' && isNative(Symbol) &&
|
1741 | typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys);
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 | var 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 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
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 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | if (isIOS) { setTimeout(noop); }
|
1778 | };
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 | } else {
|
1797 |
|
1798 |
|
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 |
|
1829 | var _Set;
|
1830 |
|
1831 | if (typeof Set !== 'undefined' && isNative(Set)) {
|
1832 |
|
1833 | _Set = Set;
|
1834 | } else {
|
1835 |
|
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 |
|
1856 | var onRE = /^@|^v-on:/;
|
1857 | var dirRE = /^v-|^@|^:/;
|
1858 | var forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/;
|
1859 | var forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/;
|
1860 |
|
1861 | var argRE = /:(.*)$/;
|
1862 | var bindRE = /^:|^v-bind:/;
|
1863 | var modifierRE = /\.[^.]+/g;
|
1864 |
|
1865 | var decodeHTMLCached = cached(he.decode);
|
1866 |
|
1867 |
|
1868 | var warn$1;
|
1869 | var delimiters;
|
1870 | var transforms;
|
1871 | var preTransforms;
|
1872 | var postTransforms;
|
1873 | var platformIsPreTag;
|
1874 | var platformMustUseProp;
|
1875 | var platformGetTagNamespace;
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 | function 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 |
|
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 |
|
1930 |
|
1931 | var ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag);
|
1932 |
|
1933 |
|
1934 |
|
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 |
|
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 |
|
1983 |
|
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 |
|
2013 | if (!root) {
|
2014 | root = element;
|
2015 | checkRootConstraints(root);
|
2016 | } else if (!stack.length) {
|
2017 |
|
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) {
|
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 |
|
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 |
|
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 |
|
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 |
|
2084 |
|
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 |
|
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 |
|
2123 | function processPre (el) {
|
2124 | if (getAndRemoveAttr(el, 'v-pre') != null) {
|
2125 | el.pre = true;
|
2126 | }
|
2127 | }
|
2128 |
|
2129 | function 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 |
|
2141 | el.plain = true;
|
2142 | }
|
2143 | }
|
2144 |
|
2145 | function 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 |
|
2155 | function processRef (el) {
|
2156 | var ref = getBindingAttr(el, 'ref');
|
2157 | if (ref) {
|
2158 | el.ref = ref;
|
2159 | el.refInFor = checkInFor(el);
|
2160 | }
|
2161 | }
|
2162 |
|
2163 | function 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 |
|
2188 | function 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 |
|
2207 | function 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 |
|
2222 | function 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 |
|
2239 | function addIfCondition (el, condition) {
|
2240 | if (!el.ifConditions) {
|
2241 | el.ifConditions = [];
|
2242 | }
|
2243 | el.ifConditions.push(condition);
|
2244 | }
|
2245 |
|
2246 | function processOnce (el) {
|
2247 | var once$$1 = getAndRemoveAttr(el, 'v-once');
|
2248 | if (once$$1 != null) {
|
2249 | el.once = true;
|
2250 | }
|
2251 | }
|
2252 |
|
2253 | function 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 |
|
2274 | function 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 |
|
2284 | function 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 |
|
2292 | el.hasBindings = true;
|
2293 |
|
2294 | modifiers = parseModifiers(name);
|
2295 | if (modifiers) {
|
2296 | name = name.replace(modifierRE, '');
|
2297 | }
|
2298 | if (bindRE.test(name)) {
|
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)) {
|
2327 | name = name.replace(onRE, '');
|
2328 | addHandler(el, name, value, modifiers, false, warn$1);
|
2329 | } else {
|
2330 | name = name.replace(dirRE, '');
|
2331 |
|
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 |
|
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 |
|
2360 | function 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 |
|
2371 | function 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 |
|
2380 | function 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 |
|
2395 | function isTextTag (el) {
|
2396 | return el.tag === 'script' || el.tag === 'style'
|
2397 | }
|
2398 |
|
2399 | function 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 |
|
2409 | var ieNSBug = /^xmlns:NS\d+/;
|
2410 | var ieNSPrefix = /^NS\d+:/;
|
2411 |
|
2412 |
|
2413 | function 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 |
|
2425 | function 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 |
|
2443 | var isStaticKey;
|
2444 | var isPlatformReservedTag;
|
2445 |
|
2446 | var genStaticKeysCached = cached(genStaticKeys$1);
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 | function optimize (root, options) {
|
2460 | if (!root) { return }
|
2461 | isStaticKey = genStaticKeysCached(options.staticKeys || '');
|
2462 | isPlatformReservedTag = options.isReservedTag || no;
|
2463 |
|
2464 | markStatic(root);
|
2465 |
|
2466 | markStaticRoots(root, false);
|
2467 | }
|
2468 |
|
2469 | function genStaticKeys$1 (keys) {
|
2470 | return makeMap(
|
2471 | 'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +
|
2472 | (keys ? ',' + keys : '')
|
2473 | )
|
2474 | }
|
2475 |
|
2476 | function markStatic (node) {
|
2477 | node.static = isStatic(node);
|
2478 | if (node.type === 1) {
|
2479 |
|
2480 |
|
2481 |
|
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 |
|
2508 | function markStaticRoots (node, isInFor) {
|
2509 | if (node.type === 1) {
|
2510 | if (node.static || node.once) {
|
2511 | node.staticInFor = isInFor;
|
2512 | }
|
2513 |
|
2514 |
|
2515 |
|
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 |
|
2538 | function isStatic (node) {
|
2539 | if (node.type === 2) {
|
2540 | return false
|
2541 | }
|
2542 | if (node.type === 3) {
|
2543 | return true
|
2544 | }
|
2545 | return !!(node.pre || (
|
2546 | !node.hasBindings &&
|
2547 | !node.if && !node.for &&
|
2548 | !isBuiltInTag(node.tag) &&
|
2549 | isPlatformReservedTag(node.tag) &&
|
2550 | !isDirectChildOfTemplateFor(node) &&
|
2551 | Object.keys(node).every(isStaticKey)
|
2552 | ))
|
2553 | }
|
2554 |
|
2555 | function 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 |
|
2570 | var fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/;
|
2571 | var simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/;
|
2572 |
|
2573 |
|
2574 | var 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 |
|
2587 |
|
2588 |
|
2589 | var genGuard = function (condition) { return ("if(" + condition + ")return null;"); };
|
2590 |
|
2591 | var 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 |
|
2604 | function 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 |
|
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 |
|
2627 | function 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) + "}")
|
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 |
|
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 |
|
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 |
|
2677 | function genKeyFilter (keys) {
|
2678 | return ("if(!('button' in $event)&&" + (keys.map(genFilterCode).join('&&')) + ")return null;")
|
2679 | }
|
2680 |
|
2681 | function 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 |
|
2692 | var emptyObject = Object.freeze({});
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 | function 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 |
|
2714 | var uid = 0;
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 | var Dep = function Dep () {
|
2721 | this.id = uid++;
|
2722 | this.subs = [];
|
2723 | };
|
2724 |
|
2725 | Dep.prototype.addSub = function addSub (sub) {
|
2726 | this.subs.push(sub);
|
2727 | };
|
2728 |
|
2729 | Dep.prototype.removeSub = function removeSub (sub) {
|
2730 | remove(this.subs, sub);
|
2731 | };
|
2732 |
|
2733 | Dep.prototype.depend = function depend () {
|
2734 | if (Dep.target) {
|
2735 | Dep.target.addDep(this);
|
2736 | }
|
2737 | };
|
2738 |
|
2739 | Dep.prototype.notify = function notify () {
|
2740 |
|
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 |
|
2748 |
|
2749 |
|
2750 | Dep.target = null;
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 | var arrayProto = Array.prototype;
|
2758 | var arrayMethods = Object.create(arrayProto);[
|
2759 | 'push',
|
2760 | 'pop',
|
2761 | 'shift',
|
2762 | 'unshift',
|
2763 | 'splice',
|
2764 | 'sort',
|
2765 | 'reverse'
|
2766 | ]
|
2767 | .forEach(function (method) {
|
2768 |
|
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 |
|
2788 | ob.dep.notify();
|
2789 | return result
|
2790 | });
|
2791 | });
|
2792 |
|
2793 |
|
2794 |
|
2795 | var arrayKeys = Object.getOwnPropertyNames(arrayMethods);
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 | var observerState = {
|
2804 | shouldConvert: true
|
2805 | };
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 | var 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 |
|
2834 |
|
2835 |
|
2836 |
|
2837 | Observer.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 |
|
2846 |
|
2847 | Observer.prototype.observeArray = function observeArray (items) {
|
2848 | for (var i = 0, l = items.length; i < l; i++) {
|
2849 | observe(items[i]);
|
2850 | }
|
2851 | };
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 | function protoAugment (target, src, keys) {
|
2860 |
|
2861 | target.__proto__ = src;
|
2862 |
|
2863 | }
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 | function 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 |
|
2879 |
|
2880 |
|
2881 |
|
2882 | function 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 | }
|
2898 | if (asRootData && ob) {
|
2899 | ob.vmCount++;
|
2900 | }
|
2901 | return ob
|
2902 | }
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 | function defineReactive$$1 (
|
2908 | obj,
|
2909 | key,
|
2910 | val,
|
2911 | customSetter,
|
2912 | shallow
|
2913 | ) {
|
2914 | var dep = new Dep();
|
2915 |
|
2916 | var property = Object.getOwnPropertyDescriptor(obj, key);
|
2917 | if (property && property.configurable === false) {
|
2918 | return
|
2919 | }
|
2920 |
|
2921 |
|
2922 | var getter = property && property.get;
|
2923 | var setter = property && property.set;
|
2924 |
|
2925 | var childOb = !shallow && observe(val, undefined, key);
|
2926 | Object.defineProperty(obj, key, {
|
2927 | enumerable: true,
|
2928 | configurable: true,
|
2929 | get: function reactiveGetter () {
|
2930 | var value = getter ? getter.call(obj) : val;
|
2931 | if (Dep.target) {
|
2932 | dep.depend();
|
2933 | if (childOb) {
|
2934 | childOb.dep.depend();
|
2935 | }
|
2936 | if (Array.isArray(value)) {
|
2937 | dependArray(value);
|
2938 | }
|
2939 | }
|
2940 | return value
|
2941 | },
|
2942 | set: function reactiveSetter (newVal) {
|
2943 | var value = getter ? getter.call(obj) : val;
|
2944 |
|
2945 | if (newVal === value || (newVal !== newVal && value !== value)) {
|
2946 | return
|
2947 | }
|
2948 |
|
2949 |
|
2950 | if (process.env.NODE_ENV !== 'production' && customSetter) {
|
2951 | customSetter();
|
2952 | }
|
2953 | if (setter) {
|
2954 | setter.call(obj, newVal);
|
2955 | } else {
|
2956 | val = newVal;
|
2957 | }
|
2958 | childOb = !shallow && observe(newVal, undefined, key);
|
2959 | dep.notify();
|
2960 |
|
2961 | var ob = obj.__ob__;
|
2962 | if (!ob.__keyPath) {
|
2963 | def(ob, '__keyPath', {}, false);
|
2964 | }
|
2965 | ob.__keyPath[key] = true;
|
2966 | }
|
2967 | });
|
2968 | }
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 | function set (target, key, val) {
|
2976 | if (Array.isArray(target) && isValidArrayIndex(key)) {
|
2977 | target.length = Math.max(target.length, key);
|
2978 | target.splice(key, 1, val);
|
2979 | return val
|
2980 | }
|
2981 | if (hasOwn(target, key)) {
|
2982 | target[key] = val;
|
2983 | return val
|
2984 | }
|
2985 | var ob = (target).__ob__;
|
2986 | if (target._isVue || (ob && ob.vmCount)) {
|
2987 | process.env.NODE_ENV !== 'production' && warn$2(
|
2988 | 'Avoid adding reactive properties to a Vue instance or its root $data ' +
|
2989 | 'at runtime - declare it upfront in the data option.'
|
2990 | );
|
2991 | return val
|
2992 | }
|
2993 | if (!ob) {
|
2994 | target[key] = val;
|
2995 | return val
|
2996 | }
|
2997 | defineReactive$$1(ob.value, key, val);
|
2998 |
|
2999 | if (!target.__keyPath) {
|
3000 | def(target, '__keyPath', {}, false);
|
3001 | }
|
3002 | target.__keyPath[key] = true;
|
3003 | ob.dep.notify();
|
3004 | return val
|
3005 | }
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 | function dependArray (value) {
|
3017 | for (var e = (void 0), i = 0, l = value.length; i < l; i++) {
|
3018 | e = value[i];
|
3019 | e && e.__ob__ && e.__ob__.dep.depend();
|
3020 | if (Array.isArray(e)) {
|
3021 | dependArray(e);
|
3022 | }
|
3023 | }
|
3024 | }
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 |
|
3033 | var strats = config.optionMergeStrategies;
|
3034 |
|
3035 |
|
3036 |
|
3037 |
|
3038 | if (process.env.NODE_ENV !== 'production') {
|
3039 | strats.el = strats.propsData = function (parent, child, vm, key) {
|
3040 | if (!vm) {
|
3041 | warn$2(
|
3042 | "option \"" + key + "\" can only be used during instance " +
|
3043 | 'creation with the `new` keyword.'
|
3044 | );
|
3045 | }
|
3046 | return defaultStrat(parent, child)
|
3047 | };
|
3048 | }
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 | function mergeData (to, from) {
|
3054 | if (!from) { return to }
|
3055 | var key, toVal, fromVal;
|
3056 | var keys = Object.keys(from);
|
3057 | for (var i = 0; i < keys.length; i++) {
|
3058 | key = keys[i];
|
3059 | toVal = to[key];
|
3060 | fromVal = from[key];
|
3061 | if (!hasOwn(to, key)) {
|
3062 | set(to, key, fromVal);
|
3063 | } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
|
3064 | mergeData(toVal, fromVal);
|
3065 | }
|
3066 | }
|
3067 | return to
|
3068 | }
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 | function mergeDataOrFn (
|
3074 | parentVal,
|
3075 | childVal,
|
3076 | vm
|
3077 | ) {
|
3078 | if (!vm) {
|
3079 |
|
3080 | if (!childVal) {
|
3081 | return parentVal
|
3082 | }
|
3083 | if (!parentVal) {
|
3084 | return childVal
|
3085 | }
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 | return function mergedDataFn () {
|
3092 | return mergeData(
|
3093 | typeof childVal === 'function' ? childVal.call(this) : childVal,
|
3094 | parentVal.call(this)
|
3095 | )
|
3096 | }
|
3097 | } else if (parentVal || childVal) {
|
3098 | return function mergedInstanceDataFn () {
|
3099 |
|
3100 | var instanceData = typeof childVal === 'function'
|
3101 | ? childVal.call(vm)
|
3102 | : childVal;
|
3103 | var defaultData = typeof parentVal === 'function'
|
3104 | ? parentVal.call(vm)
|
3105 | : undefined;
|
3106 | if (instanceData) {
|
3107 | return mergeData(instanceData, defaultData)
|
3108 | } else {
|
3109 | return defaultData
|
3110 | }
|
3111 | }
|
3112 | }
|
3113 | }
|
3114 |
|
3115 | strats.data = function (
|
3116 | parentVal,
|
3117 | childVal,
|
3118 | vm
|
3119 | ) {
|
3120 | if (!vm) {
|
3121 | if (childVal && typeof childVal !== 'function') {
|
3122 | process.env.NODE_ENV !== 'production' && warn$2(
|
3123 | 'The "data" option should be a function ' +
|
3124 | 'that returns a per-instance value in component ' +
|
3125 | 'definitions.',
|
3126 | vm
|
3127 | );
|
3128 |
|
3129 | return parentVal
|
3130 | }
|
3131 | return mergeDataOrFn.call(this, parentVal, childVal)
|
3132 | }
|
3133 |
|
3134 | return mergeDataOrFn(parentVal, childVal, vm)
|
3135 | };
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 | function mergeHook (
|
3141 | parentVal,
|
3142 | childVal
|
3143 | ) {
|
3144 | return childVal
|
3145 | ? parentVal
|
3146 | ? parentVal.concat(childVal)
|
3147 | : Array.isArray(childVal)
|
3148 | ? childVal
|
3149 | : [childVal]
|
3150 | : parentVal
|
3151 | }
|
3152 |
|
3153 | LIFECYCLE_HOOKS.forEach(function (hook) {
|
3154 | strats[hook] = mergeHook;
|
3155 | });
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 | function mergeAssets (parentVal, childVal) {
|
3165 | var res = Object.create(parentVal || null);
|
3166 | return childVal
|
3167 | ? extend(res, childVal)
|
3168 | : res
|
3169 | }
|
3170 |
|
3171 | ASSET_TYPES.forEach(function (type) {
|
3172 | strats[type + 's'] = mergeAssets;
|
3173 | });
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 | strats.watch = function (parentVal, childVal) {
|
3182 |
|
3183 | if (parentVal === nativeWatch) { parentVal = undefined; }
|
3184 | if (childVal === nativeWatch) { childVal = undefined; }
|
3185 |
|
3186 | if (!childVal) { return Object.create(parentVal || null) }
|
3187 | if (!parentVal) { return childVal }
|
3188 | var ret = {};
|
3189 | extend(ret, parentVal);
|
3190 | for (var key in childVal) {
|
3191 | var parent = ret[key];
|
3192 | var child = childVal[key];
|
3193 | if (parent && !Array.isArray(parent)) {
|
3194 | parent = [parent];
|
3195 | }
|
3196 | ret[key] = parent
|
3197 | ? parent.concat(child)
|
3198 | : Array.isArray(child) ? child : [child];
|
3199 | }
|
3200 | return ret
|
3201 | };
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 | strats.props =
|
3207 | strats.methods =
|
3208 | strats.inject =
|
3209 | strats.computed = function (parentVal, childVal) {
|
3210 | if (!childVal) { return Object.create(parentVal || null) }
|
3211 | if (!parentVal) { return childVal }
|
3212 | var ret = Object.create(null);
|
3213 | extend(ret, parentVal);
|
3214 | extend(ret, childVal);
|
3215 | return ret
|
3216 | };
|
3217 | strats.provide = mergeDataOrFn;
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 | var defaultStrat = function (parentVal, childVal) {
|
3223 | return childVal === undefined
|
3224 | ? parentVal
|
3225 | : childVal
|
3226 | };
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 |
|
3233 |
|
3234 |
|
3235 |
|
3236 |
|
3237 |
|
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 | function on (el, dir) {
|
3247 | if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
|
3248 | warn$2("v-on without argument does not support modifiers.");
|
3249 | }
|
3250 | el.wrapListeners = function (code) { return ("_g(" + code + "," + (dir.value) + ")"); };
|
3251 | }
|
3252 |
|
3253 |
|
3254 |
|
3255 | function bind$1 (el, dir) {
|
3256 | el.wrapData = function (code) {
|
3257 | return ("_b(" + code + ",'" + (el.tag) + "'," + (dir.value) + "," + (dir.modifiers && dir.modifiers.prop ? 'true' : 'false') + (dir.modifiers && dir.modifiers.sync ? ',true' : '') + ")")
|
3258 | };
|
3259 | }
|
3260 |
|
3261 |
|
3262 |
|
3263 | var baseDirectives = {
|
3264 | on: on,
|
3265 | bind: bind$1,
|
3266 | cloak: noop
|
3267 | };
|
3268 |
|
3269 |
|
3270 |
|
3271 | var CodegenState = function CodegenState (options) {
|
3272 | this.options = options;
|
3273 | this.warn = options.warn || baseWarn;
|
3274 | this.transforms = pluckModuleFunction(options.modules, 'transformCode');
|
3275 | this.dataGenFns = pluckModuleFunction(options.modules, 'genData');
|
3276 | this.directives = extend(extend({}, baseDirectives), options.directives);
|
3277 | var isReservedTag = options.isReservedTag || no;
|
3278 | this.maybeComponent = function (el) { return !isReservedTag(el.tag); };
|
3279 | this.onceId = 0;
|
3280 | this.staticRenderFns = [];
|
3281 | };
|
3282 |
|
3283 |
|
3284 |
|
3285 | function generate$1 (
|
3286 | ast,
|
3287 | options
|
3288 | ) {
|
3289 | var state = new CodegenState(options);
|
3290 | var code = ast ? genElement(ast, state) : '_c("div")';
|
3291 | return {
|
3292 | render: ("with(this){return " + code + "}"),
|
3293 | staticRenderFns: state.staticRenderFns
|
3294 | }
|
3295 | }
|
3296 |
|
3297 | function genElement (el, state) {
|
3298 | if (el.staticRoot && !el.staticProcessed) {
|
3299 | return genStatic(el, state)
|
3300 | } else if (el.once && !el.onceProcessed) {
|
3301 | return genOnce(el, state)
|
3302 | } else if (el.for && !el.forProcessed) {
|
3303 | return genFor(el, state)
|
3304 | } else if (el.if && !el.ifProcessed) {
|
3305 | return genIf(el, state)
|
3306 | } else if (el.tag === 'template' && !el.slotTarget) {
|
3307 | return genChildren(el, state) || 'void 0'
|
3308 | } else if (el.tag === 'slot') {
|
3309 | return genSlot(el, state)
|
3310 | } else {
|
3311 |
|
3312 | var code;
|
3313 | if (el.component) {
|
3314 | code = genComponent(el.component, el, state);
|
3315 | } else {
|
3316 | var data = el.plain ? undefined : genData$2(el, state);
|
3317 |
|
3318 | var children = el.inlineTemplate ? null : genChildren(el, state, true);
|
3319 | code = "_c('" + (el.tag) + "'" + (data ? ("," + data) : '') + (children ? ("," + children) : '') + ")";
|
3320 | }
|
3321 |
|
3322 | for (var i = 0; i < state.transforms.length; i++) {
|
3323 | code = state.transforms[i](el, code);
|
3324 | }
|
3325 | return code
|
3326 | }
|
3327 | }
|
3328 |
|
3329 |
|
3330 | function genStatic (el, state) {
|
3331 | el.staticProcessed = true;
|
3332 | state.staticRenderFns.push(("with(this){return " + (genElement(el, state)) + "}"));
|
3333 | return ("_m(" + (state.staticRenderFns.length - 1) + (el.staticInFor ? ',true' : '') + ")")
|
3334 | }
|
3335 |
|
3336 |
|
3337 | function genOnce (el, state) {
|
3338 | el.onceProcessed = true;
|
3339 | if (el.if && !el.ifProcessed) {
|
3340 | return genIf(el, state)
|
3341 | } else if (el.staticInFor) {
|
3342 | var key = '';
|
3343 | var parent = el.parent;
|
3344 | while (parent) {
|
3345 | if (parent.for) {
|
3346 | key = parent.key;
|
3347 | break
|
3348 | }
|
3349 | parent = parent.parent;
|
3350 | }
|
3351 | if (!key) {
|
3352 | process.env.NODE_ENV !== 'production' && state.warn(
|
3353 | "v-once can only be used inside v-for that is keyed. "
|
3354 | );
|
3355 | return genElement(el, state)
|
3356 | }
|
3357 | return ("_o(" + (genElement(el, state)) + "," + (state.onceId++) + (key ? ("," + key) : "") + ")")
|
3358 | } else {
|
3359 | return genStatic(el, state)
|
3360 | }
|
3361 | }
|
3362 |
|
3363 | function genIf (
|
3364 | el,
|
3365 | state,
|
3366 | altGen,
|
3367 | altEmpty
|
3368 | ) {
|
3369 | el.ifProcessed = true;
|
3370 | return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
|
3371 | }
|
3372 |
|
3373 | function genIfConditions (
|
3374 | conditions,
|
3375 | state,
|
3376 | altGen,
|
3377 | altEmpty
|
3378 | ) {
|
3379 | if (!conditions.length) {
|
3380 | return altEmpty || '_e()'
|
3381 | }
|
3382 |
|
3383 | var condition = conditions.shift();
|
3384 | if (condition.exp) {
|
3385 | return ("(" + (condition.exp) + ")?" + (genTernaryExp(condition.block)) + ":" + (genIfConditions(conditions, state, altGen, altEmpty)))
|
3386 | } else {
|
3387 | return ("" + (genTernaryExp(condition.block)))
|
3388 | }
|
3389 |
|
3390 |
|
3391 | function genTernaryExp (el) {
|
3392 | return altGen
|
3393 | ? altGen(el, state)
|
3394 | : el.once
|
3395 | ? genOnce(el, state)
|
3396 | : genElement(el, state)
|
3397 | }
|
3398 | }
|
3399 |
|
3400 | function genFor (
|
3401 | el,
|
3402 | state,
|
3403 | altGen,
|
3404 | altHelper
|
3405 | ) {
|
3406 | var exp = el.for;
|
3407 | var alias = el.alias;
|
3408 | var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
|
3409 | var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
|
3410 |
|
3411 | if (process.env.NODE_ENV !== 'production' &&
|
3412 | state.maybeComponent(el) &&
|
3413 | el.tag !== 'slot' &&
|
3414 | el.tag !== 'template' &&
|
3415 | !el.key
|
3416 | ) {
|
3417 | state.warn(
|
3418 | "<" + (el.tag) + " v-for=\"" + alias + " in " + exp + "\">: component lists rendered with " +
|
3419 | "v-for should have explicit keys. " +
|
3420 | "See https://vuejs.org/guide/list.html#key for more info.",
|
3421 | true
|
3422 | );
|
3423 | }
|
3424 |
|
3425 | el.forProcessed = true;
|
3426 | return (altHelper || '_l') + "((" + exp + ")," +
|
3427 | "function(" + alias + iterator1 + iterator2 + "){" +
|
3428 | "return " + ((altGen || genElement)(el, state)) +
|
3429 | '})'
|
3430 | }
|
3431 |
|
3432 | function genData$2 (el, state) {
|
3433 | var data = '{';
|
3434 |
|
3435 |
|
3436 |
|
3437 | var dirs = genDirectives(el, state);
|
3438 | if (dirs) { data += dirs + ','; }
|
3439 |
|
3440 |
|
3441 | if (el.key) {
|
3442 | data += "key:" + (el.key) + ",";
|
3443 | }
|
3444 |
|
3445 | if (el.ref) {
|
3446 | data += "ref:" + (el.ref) + ",";
|
3447 | }
|
3448 | if (el.refInFor) {
|
3449 | data += "refInFor:true,";
|
3450 | }
|
3451 |
|
3452 | if (el.pre) {
|
3453 | data += "pre:true,";
|
3454 | }
|
3455 |
|
3456 | if (el.component) {
|
3457 | data += "tag:\"" + (el.tag) + "\",";
|
3458 | }
|
3459 |
|
3460 | for (var i = 0; i < state.dataGenFns.length; i++) {
|
3461 | data += state.dataGenFns[i](el);
|
3462 | }
|
3463 |
|
3464 | if (el.attrs) {
|
3465 | data += "attrs:{" + (genProps(el.attrs)) + "},";
|
3466 | }
|
3467 |
|
3468 | if (el.props) {
|
3469 | data += "domProps:{" + (genProps(el.props)) + "},";
|
3470 | }
|
3471 |
|
3472 | if (el.events) {
|
3473 | data += (genHandlers(el.events, false, state.warn)) + ",";
|
3474 | }
|
3475 | if (el.nativeEvents) {
|
3476 | data += (genHandlers(el.nativeEvents, true, state.warn)) + ",";
|
3477 | }
|
3478 |
|
3479 | if (el.slotTarget) {
|
3480 | data += "slot:" + (el.slotTarget) + ",";
|
3481 | }
|
3482 |
|
3483 | if (el.scopedSlots) {
|
3484 | data += (genScopedSlots(el.scopedSlots, state)) + ",";
|
3485 | }
|
3486 |
|
3487 | if (el.model) {
|
3488 | data += "model:{value:" + (el.model.value) + ",callback:" + (el.model.callback) + ",expression:" + (el.model.expression) + "},";
|
3489 | }
|
3490 |
|
3491 | if (el.inlineTemplate) {
|
3492 | var inlineTemplate = genInlineTemplate(el, state);
|
3493 | if (inlineTemplate) {
|
3494 | data += inlineTemplate + ",";
|
3495 | }
|
3496 | }
|
3497 | data = data.replace(/,$/, '') + '}';
|
3498 |
|
3499 | if (el.wrapData) {
|
3500 | data = el.wrapData(data);
|
3501 | }
|
3502 |
|
3503 | if (el.wrapListeners) {
|
3504 | data = el.wrapListeners(data);
|
3505 | }
|
3506 | return data
|
3507 | }
|
3508 |
|
3509 | function genDirectives (el, state) {
|
3510 | var dirs = el.directives;
|
3511 | if (!dirs) { return }
|
3512 | var res = 'directives:[';
|
3513 | var hasRuntime = false;
|
3514 | var i, l, dir, needRuntime;
|
3515 | for (i = 0, l = dirs.length; i < l; i++) {
|
3516 | dir = dirs[i];
|
3517 | needRuntime = true;
|
3518 | var gen = state.directives[dir.name];
|
3519 | if (gen) {
|
3520 |
|
3521 |
|
3522 | needRuntime = !!gen(el, dir, state.warn);
|
3523 | }
|
3524 | if (needRuntime) {
|
3525 | hasRuntime = true;
|
3526 | 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))) : '') + "},";
|
3527 | }
|
3528 | }
|
3529 | if (hasRuntime) {
|
3530 | return res.slice(0, -1) + ']'
|
3531 | }
|
3532 | }
|
3533 |
|
3534 | function genInlineTemplate (el, state) {
|
3535 | var ast = el.children[0];
|
3536 | if (process.env.NODE_ENV !== 'production' && (
|
3537 | el.children.length > 1 || ast.type !== 1
|
3538 | )) {
|
3539 | state.warn('Inline-template components must have exactly one child element.');
|
3540 | }
|
3541 | if (ast.type === 1) {
|
3542 | var inlineRenderFns = generate$1(ast, state.options);
|
3543 | return ("inlineTemplate:{render:function(){" + (inlineRenderFns.render) + "},staticRenderFns:[" + (inlineRenderFns.staticRenderFns.map(function (code) { return ("function(){" + code + "}"); }).join(',')) + "]}")
|
3544 | }
|
3545 | }
|
3546 |
|
3547 | function genScopedSlots (
|
3548 | slots,
|
3549 | state
|
3550 | ) {
|
3551 | return ("scopedSlots:_u([" + (Object.keys(slots).map(function (key) {
|
3552 | return genScopedSlot(key, slots[key], state)
|
3553 | }).join(',')) + "])")
|
3554 | }
|
3555 |
|
3556 | function genScopedSlot (
|
3557 | key,
|
3558 | el,
|
3559 | state
|
3560 | ) {
|
3561 | if (el.for && !el.forProcessed) {
|
3562 | return genForScopedSlot(key, el, state)
|
3563 | }
|
3564 | return "{key:" + key + ",fn:function(" + (String(el.attrsMap.scope)) + "){" +
|
3565 | "return " + (el.tag === 'template'
|
3566 | ? genChildren(el, state) || 'void 0'
|
3567 | : genElement(el, state)) + "}}"
|
3568 | }
|
3569 |
|
3570 | function genForScopedSlot (
|
3571 | key,
|
3572 | el,
|
3573 | state
|
3574 | ) {
|
3575 | var exp = el.for;
|
3576 | var alias = el.alias;
|
3577 | var iterator1 = el.iterator1 ? ("," + (el.iterator1)) : '';
|
3578 | var iterator2 = el.iterator2 ? ("," + (el.iterator2)) : '';
|
3579 | el.forProcessed = true;
|
3580 | return "_l((" + exp + ")," +
|
3581 | "function(" + alias + iterator1 + iterator2 + "){" +
|
3582 | "return " + (genScopedSlot(key, el, state)) +
|
3583 | '})'
|
3584 | }
|
3585 |
|
3586 | function genChildren (
|
3587 | el,
|
3588 | state,
|
3589 | checkSkip,
|
3590 | altGenElement,
|
3591 | altGenNode
|
3592 | ) {
|
3593 | var children = el.children;
|
3594 | if (children.length) {
|
3595 | var el$1 = children[0];
|
3596 |
|
3597 | if (children.length === 1 &&
|
3598 | el$1.for &&
|
3599 | el$1.tag !== 'template' &&
|
3600 | el$1.tag !== 'slot'
|
3601 | ) {
|
3602 | return (altGenElement || genElement)(el$1, state)
|
3603 | }
|
3604 | var normalizationType = checkSkip
|
3605 | ? getNormalizationType(children, state.maybeComponent)
|
3606 | : 0;
|
3607 | var gen = altGenNode || genNode;
|
3608 | return ("[" + (children.map(function (c) { return gen(c, state); }).join(',')) + "]" + (normalizationType ? ("," + normalizationType) : ''))
|
3609 | }
|
3610 | }
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 | function getNormalizationType (
|
3617 | children,
|
3618 | maybeComponent
|
3619 | ) {
|
3620 | var res = 0;
|
3621 | for (var i = 0; i < children.length; i++) {
|
3622 | var el = children[i];
|
3623 | if (el.type !== 1) {
|
3624 | continue
|
3625 | }
|
3626 | if (needsNormalization(el) ||
|
3627 | (el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {
|
3628 | res = 2;
|
3629 | break
|
3630 | }
|
3631 | if (maybeComponent(el) ||
|
3632 | (el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {
|
3633 | res = 1;
|
3634 | }
|
3635 | }
|
3636 | return res
|
3637 | }
|
3638 |
|
3639 | function needsNormalization (el) {
|
3640 | return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
|
3641 | }
|
3642 |
|
3643 | function genNode (node, state) {
|
3644 | if (node.type === 1) {
|
3645 | return genElement(node, state)
|
3646 | } if (node.type === 3 && node.isComment) {
|
3647 | return genComment(node)
|
3648 | } else {
|
3649 | return genText(node)
|
3650 | }
|
3651 | }
|
3652 |
|
3653 | function genText (text) {
|
3654 | return ("_v(" + (text.type === 2
|
3655 | ? text.expression
|
3656 | : transformSpecialNewlines(JSON.stringify(text.text))) + ")")
|
3657 | }
|
3658 |
|
3659 | function genComment (comment) {
|
3660 | return ("_e('" + (comment.text) + "')")
|
3661 | }
|
3662 |
|
3663 | function genSlot (el, state) {
|
3664 | var slotName = el.slotName || '"default"';
|
3665 | var children = genChildren(el, state);
|
3666 | var res = "_t(" + slotName + (children ? ("," + children) : '');
|
3667 | var attrs = el.attrs && ("{" + (el.attrs.map(function (a) { return ((camelize(a.name)) + ":" + (a.value)); }).join(',')) + "}");
|
3668 | var bind$$1 = el.attrsMap['v-bind'];
|
3669 | if ((attrs || bind$$1) && !children) {
|
3670 | res += ",null";
|
3671 | }
|
3672 | if (attrs) {
|
3673 | res += "," + attrs;
|
3674 | }
|
3675 | if (bind$$1) {
|
3676 | res += (attrs ? '' : ',null') + "," + bind$$1;
|
3677 | }
|
3678 | return res + ')'
|
3679 | }
|
3680 |
|
3681 |
|
3682 | function genComponent (
|
3683 | componentName,
|
3684 | el,
|
3685 | state
|
3686 | ) {
|
3687 | var children = el.inlineTemplate ? null : genChildren(el, state, true);
|
3688 | return ("_c(" + componentName + "," + (genData$2(el, state)) + (children ? ("," + children) : '') + ")")
|
3689 | }
|
3690 |
|
3691 | function genProps (props) {
|
3692 | var res = '';
|
3693 | for (var i = 0; i < props.length; i++) {
|
3694 | var prop = props[i];
|
3695 | res += "\"" + (prop.name) + "\":" + (transformSpecialNewlines(prop.value)) + ",";
|
3696 | }
|
3697 | return res.slice(0, -1)
|
3698 | }
|
3699 |
|
3700 |
|
3701 | function transformSpecialNewlines (text) {
|
3702 | return text
|
3703 | .replace(/\u2028/g, '\\u2028')
|
3704 | .replace(/\u2029/g, '\\u2029')
|
3705 | }
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 | var prohibitedKeywordRE = new RegExp('\\b' + (
|
3712 | 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
|
3713 | 'super,throw,while,yield,delete,export,import,return,switch,default,' +
|
3714 | 'extends,finally,continue,debugger,function,arguments'
|
3715 | ).split(',').join('\\b|\\b') + '\\b');
|
3716 |
|
3717 |
|
3718 | var unaryOperatorsRE = new RegExp('\\b' + (
|
3719 | 'delete,typeof,void'
|
3720 | ).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)');
|
3721 |
|
3722 |
|
3723 | var identRE = /[A-Za-z_$][\w$]*/;
|
3724 |
|
3725 |
|
3726 | var stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
|
3727 |
|
3728 |
|
3729 | function detectErrors (ast) {
|
3730 | var errors = [];
|
3731 | if (ast) {
|
3732 | checkNode(ast, errors);
|
3733 | }
|
3734 | return errors
|
3735 | }
|
3736 |
|
3737 | function checkNode (node, errors) {
|
3738 | if (node.type === 1) {
|
3739 | for (var name in node.attrsMap) {
|
3740 | if (dirRE.test(name)) {
|
3741 | var value = node.attrsMap[name];
|
3742 | if (value) {
|
3743 | if (name === 'v-for') {
|
3744 | checkFor(node, ("v-for=\"" + value + "\""), errors);
|
3745 | } else if (onRE.test(name)) {
|
3746 | checkEvent(value, (name + "=\"" + value + "\""), errors);
|
3747 | } else {
|
3748 | checkExpression(value, (name + "=\"" + value + "\""), errors);
|
3749 | }
|
3750 | }
|
3751 | }
|
3752 | }
|
3753 | if (node.children) {
|
3754 | for (var i = 0; i < node.children.length; i++) {
|
3755 | checkNode(node.children[i], errors);
|
3756 | }
|
3757 | }
|
3758 | } else if (node.type === 2) {
|
3759 | checkExpression(node.expression, node.text, errors);
|
3760 | }
|
3761 | }
|
3762 |
|
3763 | function checkEvent (exp, text, errors) {
|
3764 | var stipped = exp.replace(stripStringRE, '');
|
3765 | var keywordMatch = stipped.match(unaryOperatorsRE);
|
3766 | if (keywordMatch && stipped.charAt(keywordMatch.index - 1) !== '$') {
|
3767 | errors.push(
|
3768 | "avoid using JavaScript unary operator as property name: " +
|
3769 | "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim())
|
3770 | );
|
3771 | }
|
3772 | checkExpression(exp, text, errors);
|
3773 | }
|
3774 |
|
3775 | function checkFor (node, text, errors) {
|
3776 | checkExpression(node.for || '', text, errors);
|
3777 | checkIdentifier(node.alias, 'v-for alias', text, errors);
|
3778 | checkIdentifier(node.iterator1, 'v-for iterator', text, errors);
|
3779 | checkIdentifier(node.iterator2, 'v-for iterator', text, errors);
|
3780 | }
|
3781 |
|
3782 | function checkIdentifier (ident, type, text, errors) {
|
3783 | if (typeof ident === 'string' && !identRE.test(ident)) {
|
3784 | errors.push(("invalid " + type + " \"" + ident + "\" in expression: " + (text.trim())));
|
3785 | }
|
3786 | }
|
3787 |
|
3788 | function checkExpression (exp, text, errors) {
|
3789 | try {
|
3790 | new Function(("return " + exp));
|
3791 | } catch (e) {
|
3792 | var keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE);
|
3793 | if (keywordMatch) {
|
3794 | errors.push(
|
3795 | "avoid using JavaScript keyword as property name: " +
|
3796 | "\"" + (keywordMatch[0]) + "\" in expression " + (text.trim())
|
3797 | );
|
3798 | } else {
|
3799 | errors.push(("invalid expression: " + (text.trim())));
|
3800 | }
|
3801 | }
|
3802 | }
|
3803 |
|
3804 |
|
3805 |
|
3806 | function createFunction (code, errors) {
|
3807 | try {
|
3808 | return new Function(code)
|
3809 | } catch (err) {
|
3810 | errors.push({ err: err, code: code });
|
3811 | return noop
|
3812 | }
|
3813 | }
|
3814 |
|
3815 | function createCompileToFunctionFn (compile) {
|
3816 | var cache = Object.create(null);
|
3817 |
|
3818 | return function compileToFunctions (
|
3819 | template$$1,
|
3820 | options,
|
3821 | vm
|
3822 | ) {
|
3823 | options = options || {};
|
3824 |
|
3825 |
|
3826 | if (process.env.NODE_ENV !== 'production') {
|
3827 |
|
3828 | try {
|
3829 | new Function('return 1');
|
3830 | } catch (e) {
|
3831 | if (e.toString().match(/unsafe-eval|CSP/)) {
|
3832 | warn$2(
|
3833 | 'It seems you are using the standalone build of Vue.js in an ' +
|
3834 | 'environment with Content Security Policy that prohibits unsafe-eval. ' +
|
3835 | 'The template compiler cannot work in this environment. Consider ' +
|
3836 | 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
|
3837 | 'templates into render functions.'
|
3838 | );
|
3839 | }
|
3840 | }
|
3841 | }
|
3842 |
|
3843 |
|
3844 | var key = options.delimiters
|
3845 | ? String(options.delimiters) + template$$1
|
3846 | : template$$1;
|
3847 | if (cache[key]) {
|
3848 | return cache[key]
|
3849 | }
|
3850 |
|
3851 |
|
3852 | var compiled = compile(template$$1, options);
|
3853 |
|
3854 |
|
3855 | if (process.env.NODE_ENV !== 'production') {
|
3856 | if (compiled.errors && compiled.errors.length) {
|
3857 | warn$2(
|
3858 | "Error compiling template:\n\n" + template$$1 + "\n\n" +
|
3859 | compiled.errors.map(function (e) { return ("- " + e); }).join('\n') + '\n',
|
3860 | vm
|
3861 | );
|
3862 | }
|
3863 | if (compiled.tips && compiled.tips.length) {
|
3864 | compiled.tips.forEach(function (msg) { return tip(msg, vm); });
|
3865 | }
|
3866 | }
|
3867 |
|
3868 |
|
3869 | var res = {};
|
3870 | var fnGenErrors = [];
|
3871 | res.render = createFunction(compiled.render, fnGenErrors);
|
3872 | res.staticRenderFns = compiled.staticRenderFns.map(function (code) {
|
3873 | return createFunction(code, fnGenErrors)
|
3874 | });
|
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 |
|
3880 | if (process.env.NODE_ENV !== 'production') {
|
3881 | if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
|
3882 | warn$2(
|
3883 | "Failed to generate render function:\n\n" +
|
3884 | fnGenErrors.map(function (ref) {
|
3885 | var err = ref.err;
|
3886 | var code = ref.code;
|
3887 |
|
3888 | return ((err.toString()) + " in\n\n" + code + "\n");
|
3889 | }).join('\n'),
|
3890 | vm
|
3891 | );
|
3892 | }
|
3893 | }
|
3894 |
|
3895 | return (cache[key] = res)
|
3896 | }
|
3897 | }
|
3898 |
|
3899 |
|
3900 |
|
3901 | function createCompilerCreator (baseCompile) {
|
3902 | return function createCompiler (baseOptions) {
|
3903 | function compile (
|
3904 | template$$1,
|
3905 | options
|
3906 | ) {
|
3907 | var finalOptions = Object.create(baseOptions);
|
3908 | var errors = [];
|
3909 | var tips = [];
|
3910 | finalOptions.warn = function (msg, tip) {
|
3911 | (tip ? tips : errors).push(msg);
|
3912 | };
|
3913 |
|
3914 | if (options) {
|
3915 |
|
3916 | if (options.modules) {
|
3917 | finalOptions.modules =
|
3918 | (baseOptions.modules || []).concat(options.modules);
|
3919 | }
|
3920 |
|
3921 | if (options.directives) {
|
3922 | finalOptions.directives = extend(
|
3923 | Object.create(baseOptions.directives),
|
3924 | options.directives
|
3925 | );
|
3926 | }
|
3927 |
|
3928 | for (var key in options) {
|
3929 | if (key !== 'modules' && key !== 'directives') {
|
3930 | finalOptions[key] = options[key];
|
3931 | }
|
3932 | }
|
3933 | }
|
3934 |
|
3935 | var compiled = baseCompile(template$$1, finalOptions);
|
3936 | if (process.env.NODE_ENV !== 'production') {
|
3937 | errors.push.apply(errors, detectErrors(compiled.ast));
|
3938 | }
|
3939 | compiled.errors = errors;
|
3940 | compiled.tips = tips;
|
3941 | return compiled
|
3942 | }
|
3943 |
|
3944 | return {
|
3945 | compile: compile,
|
3946 | compileToFunctions: createCompileToFunctionFn(compile)
|
3947 | }
|
3948 | }
|
3949 | }
|
3950 |
|
3951 | var tagMap = {
|
3952 | 'br': 'view',
|
3953 | 'hr': 'view',
|
3954 |
|
3955 | 'p': 'view',
|
3956 | 'h1': 'view',
|
3957 | 'h2': 'view',
|
3958 | 'h3': 'view',
|
3959 | 'h4': 'view',
|
3960 | 'h5': 'view',
|
3961 | 'h6': 'view',
|
3962 | 'abbr': 'view',
|
3963 | 'address': 'view',
|
3964 | 'b': 'view',
|
3965 | 'bdi': 'view',
|
3966 | 'bdo': 'view',
|
3967 | 'blockquote': 'view',
|
3968 | 'cite': 'view',
|
3969 | 'code': 'view',
|
3970 | 'del': 'view',
|
3971 | 'ins': 'view',
|
3972 | 'dfn': 'view',
|
3973 | 'em': 'view',
|
3974 | 'strong': 'view',
|
3975 | 'samp': 'view',
|
3976 | 'kbd': 'view',
|
3977 | 'var': 'view',
|
3978 | 'i': 'view',
|
3979 | 'mark': 'view',
|
3980 | 'pre': 'view',
|
3981 | 'q': 'view',
|
3982 | 'ruby': 'view',
|
3983 | 'rp': 'view',
|
3984 | 'rt': 'view',
|
3985 | 's': 'view',
|
3986 | 'small': 'view',
|
3987 | 'sub': 'view',
|
3988 | 'sup': 'view',
|
3989 | 'time': 'view',
|
3990 | 'u': 'view',
|
3991 | 'wbr': 'view',
|
3992 |
|
3993 |
|
3994 | 'form': 'form',
|
3995 | 'input': 'input',
|
3996 | 'textarea': 'textarea',
|
3997 | 'button': 'button',
|
3998 | 'select': 'picker',
|
3999 | 'option': 'view',
|
4000 | 'optgroup': 'view',
|
4001 | 'label': 'label',
|
4002 | 'fieldset': 'view',
|
4003 | 'datalist': 'picker',
|
4004 | 'legend': 'view',
|
4005 | 'output': 'view',
|
4006 |
|
4007 |
|
4008 | 'iframe': 'view',
|
4009 |
|
4010 | 'img': 'image',
|
4011 | 'canvas': 'canvas',
|
4012 | 'figure': 'view',
|
4013 | 'figcaption': 'view',
|
4014 |
|
4015 |
|
4016 | 'audio': 'audio',
|
4017 | 'source': 'audio',
|
4018 | 'video': 'video',
|
4019 | 'track': 'video',
|
4020 |
|
4021 | 'a': 'navigator',
|
4022 | 'nav': 'view',
|
4023 | 'link': 'navigator',
|
4024 |
|
4025 | 'ul': 'view',
|
4026 | 'ol': 'view',
|
4027 | 'li': 'view',
|
4028 | 'dl': 'view',
|
4029 | 'dt': 'view',
|
4030 | 'dd': 'view',
|
4031 | 'menu': 'view',
|
4032 | 'command': 'view',
|
4033 |
|
4034 |
|
4035 | 'table': 'view',
|
4036 | 'caption': 'view',
|
4037 | 'th': 'view',
|
4038 | 'td': 'view',
|
4039 | 'tr': 'view',
|
4040 | 'thead': 'view',
|
4041 | 'tbody': 'view',
|
4042 | 'tfoot': 'view',
|
4043 | 'col': 'view',
|
4044 | 'colgroup': 'view',
|
4045 |
|
4046 |
|
4047 | 'div': 'view',
|
4048 | 'main': 'view',
|
4049 | 'span': 'label',
|
4050 | 'header': 'view',
|
4051 | 'footer': 'view',
|
4052 | 'section': 'view',
|
4053 | 'article': 'view',
|
4054 | 'aside': 'view',
|
4055 | 'details': 'view',
|
4056 | 'dialog': 'view',
|
4057 | 'summary': 'view',
|
4058 |
|
4059 | 'progress': 'progress',
|
4060 | 'meter': 'progress',
|
4061 | 'head': 'view',
|
4062 | 'meta': 'view',
|
4063 | 'base': 'text',
|
4064 |
|
4065 | 'area': 'navigator',
|
4066 |
|
4067 | 'script': 'view',
|
4068 | 'noscript': 'view',
|
4069 | 'embed': 'view',
|
4070 | 'object': 'view',
|
4071 | 'param': 'view',
|
4072 |
|
4073 |
|
4074 |
|
4075 | 'view': 'view',
|
4076 | 'scroll-view': 'scroll-view',
|
4077 | 'swiper': 'swiper',
|
4078 | 'icon': 'icon',
|
4079 | 'text': 'text',
|
4080 |
|
4081 |
|
4082 |
|
4083 |
|
4084 | 'checkbox': 'checkbox',
|
4085 | 'radio': 'radio',
|
4086 | 'picker': 'picker',
|
4087 | 'picker-view': 'picker-view',
|
4088 | 'slider': 'slider',
|
4089 | 'switch': 'switch',
|
4090 |
|
4091 | 'navigator': 'navigator',
|
4092 |
|
4093 | 'image': 'image',
|
4094 |
|
4095 | 'map': 'map',
|
4096 |
|
4097 | 'contact-button': 'contact-button',
|
4098 | 'block': 'block'
|
4099 | };
|
4100 |
|
4101 | function maybeTag (tagName) {
|
4102 | return tagMap[tagName]
|
4103 | }
|
4104 |
|
4105 | function getWxEleId (index, arr) {
|
4106 | if (!arr || !arr.length) {
|
4107 | return ("'" + index + "'")
|
4108 | }
|
4109 |
|
4110 | var str = arr.join("+'-'+");
|
4111 | return ("'" + index + "_'+" + str)
|
4112 | }
|
4113 |
|
4114 |
|
4115 | function checkRepeatIterator (arr, options) {
|
4116 | var len = arr.length;
|
4117 | if (len > 1 && len !== new Set(arr).size) {
|
4118 | options.warn(("同一组件内嵌套的 v-for 不能连续使用相同的索引,目前为: " + arr), false);
|
4119 | }
|
4120 | }
|
4121 |
|
4122 | function fixDefaultIterator (path) {
|
4123 | var forText = path.for;
|
4124 | var iterator1 = path.iterator1;
|
4125 | if (forText && !iterator1) {
|
4126 | path.iterator1 = 'index';
|
4127 | }
|
4128 | }
|
4129 |
|
4130 | function addAttr$1 (path, key, value, inVdom) {
|
4131 | path[key] = value;
|
4132 | path.plain = false;
|
4133 |
|
4134 | if (!inVdom) {
|
4135 | path.attrsMap[("data-" + key)] = "{{" + value + "}}";
|
4136 | }
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 | if (!path.attrs) {
|
4144 | path.attrs = [];
|
4145 | }
|
4146 | path.attrs.push({ name: key, value: value });
|
4147 | }
|
4148 |
|
4149 | function mark (path, options, deps, iteratorArr) {
|
4150 | if ( iteratorArr === void 0 ) iteratorArr = [];
|
4151 |
|
4152 | fixDefaultIterator(path);
|
4153 |
|
4154 | var tag = path.tag;
|
4155 | var children = path.children;
|
4156 | var iterator1 = path.iterator1;
|
4157 | var events = path.events;
|
4158 | var directives = path.directives;
|
4159 | var ifConditions = path.ifConditions;
|
4160 |
|
4161 | var currentArr = Object.assign([], iteratorArr);
|
4162 |
|
4163 | if (iterator1) {
|
4164 | currentArr.push(iterator1);
|
4165 | }
|
4166 |
|
4167 | checkRepeatIterator(currentArr, options);
|
4168 |
|
4169 |
|
4170 | if (children && children.length) {
|
4171 | children.forEach(function (v, i) {
|
4172 |
|
4173 | mark(v, options, deps, currentArr);
|
4174 | });
|
4175 | }
|
4176 |
|
4177 |
|
4178 | if (ifConditions && ifConditions.length > 1) {
|
4179 | ifConditions.slice(1).forEach(function (v, i) {
|
4180 | mark(v.block, options, deps, currentArr);
|
4181 | });
|
4182 | }
|
4183 |
|
4184 |
|
4185 |
|
4186 | var hasModel = directives && directives.find(function (v) { return v.name === 'model'; });
|
4187 | var needEventsID = events || hasModel;
|
4188 |
|
4189 | if (needEventsID) {
|
4190 | var eventId = getWxEleId(deps.eventIndex, currentArr);
|
4191 |
|
4192 | addAttr$1(path, 'eventid', eventId);
|
4193 | path.attrsMap['data-comkey'] = '{{$k}}';
|
4194 | deps.eventIndex += 1;
|
4195 |
|
4196 | }
|
4197 |
|
4198 |
|
4199 | if (!tag || maybeTag(tag)) {
|
4200 | return
|
4201 | }
|
4202 |
|
4203 |
|
4204 | var value = getWxEleId(deps.comIndex, currentArr);
|
4205 | addAttr$1(path, 'mpcomid', value, true);
|
4206 | path['mpcomid'] = value;
|
4207 | deps.comIndex += 1;
|
4208 | }
|
4209 |
|
4210 |
|
4211 |
|
4212 | function markComponent (ast, options) {
|
4213 | var deps = { comIndex: 0, eventIndex: 0 };
|
4214 | mark(ast, options, deps);
|
4215 |
|
4216 | return ast
|
4217 | }
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 |
|
4223 |
|
4224 |
|
4225 | var createCompiler = createCompilerCreator(function baseCompile (
|
4226 | template$$1,
|
4227 | options
|
4228 | ) {
|
4229 | var originAst = parse(template$$1.trim(), options);
|
4230 | var ast = markComponent(originAst, options);
|
4231 | optimize(ast, options);
|
4232 | var code = generate$1(ast, options);
|
4233 | return {
|
4234 | ast: ast,
|
4235 | render: code.render,
|
4236 | staticRenderFns: code.staticRenderFns
|
4237 | }
|
4238 | });
|
4239 |
|
4240 |
|
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 | var noSupport = {
|
4249 | type: 4,
|
4250 | check: function (k, v, errors) {
|
4251 | errors(("不支持此指令: " + k + "=\"" + v + "\""));
|
4252 | return false
|
4253 | }
|
4254 | };
|
4255 | var wxmlDirectiveMap = {
|
4256 | 'v-if': {
|
4257 | name: 'wx:if',
|
4258 | type: 0
|
4259 | },
|
4260 | 'v-else-if': {
|
4261 | name: 'wx:elif',
|
4262 | type: 0
|
4263 | },
|
4264 | 'v-else': {
|
4265 | name: 'wx:else',
|
4266 | type: 1
|
4267 | },
|
4268 | 'v-text': {
|
4269 | name: '',
|
4270 | type: 1
|
4271 | },
|
4272 | 'v-html': {
|
4273 | name: '',
|
4274 | type: 1
|
4275 | },
|
4276 | 'v-on': {
|
4277 | name: '',
|
4278 | map: {
|
4279 | click: 'tap',
|
4280 | touchstart: 'touchstart',
|
4281 | touchmove: 'touchmove',
|
4282 | touchcancel: 'touchcancel',
|
4283 | touchend: 'touchend',
|
4284 | tap: 'tap',
|
4285 | longtap: 'longtap',
|
4286 | input: 'input',
|
4287 | change: 'change',
|
4288 | submit: 'submit',
|
4289 | blur: 'blur',
|
4290 | focus: 'focus',
|
4291 | reset: 'reset',
|
4292 | confirm: 'confirm',
|
4293 | columnchange: 'columnchange',
|
4294 | linechange: 'linechange',
|
4295 | error: 'error',
|
4296 | scrolltoupper: 'scrolltoupper',
|
4297 | scrolltolower: 'scrolltolower',
|
4298 | scroll: 'scroll',
|
4299 | load: 'load'
|
4300 | },
|
4301 | type: 2
|
4302 | },
|
4303 | 'v-bind': {
|
4304 | name: '',
|
4305 | map: {
|
4306 | 'href': 'url'
|
4307 | },
|
4308 | type: 3
|
4309 | },
|
4310 | 'href': {
|
4311 | name: 'url',
|
4312 | type: 2
|
4313 | },
|
4314 | 'v-pre': noSupport,
|
4315 | 'v-cloak': noSupport,
|
4316 | 'v-once': {
|
4317 | name: '',
|
4318 | type: 5
|
4319 | }
|
4320 | };
|
4321 |
|
4322 | var tagConfig = {
|
4323 | virtualTag: ['slot', 'template', 'block']
|
4324 | };
|
4325 |
|
4326 |
|
4327 |
|
4328 | function getStrByNode (node, onlyStr) {
|
4329 | if ( onlyStr === void 0 ) onlyStr = false;
|
4330 |
|
4331 | if (onlyStr) {
|
4332 | return node.value || node.name || ''
|
4333 | }
|
4334 | return node.type === 'StringLiteral' ? node : t.stringLiteral(node.name || '')
|
4335 | }
|
4336 |
|
4337 |
|
4338 | var objectVisitor = {
|
4339 | ObjectExpression: function (path) {
|
4340 | var elements = path.node.properties.map(function (propertyItem) {
|
4341 | return t.conditionalExpression(propertyItem.value, getStrByNode(propertyItem.key), t.stringLiteral(''))
|
4342 | });
|
4343 | path.replaceWith(t.arrayExpression(elements));
|
4344 | }
|
4345 | };
|
4346 |
|
4347 | function transformObjectToTernaryOperator (babel$$1) {
|
4348 | return { visitor: objectVisitor }
|
4349 | }
|
4350 |
|
4351 |
|
4352 | var objectToStringVisitor = {
|
4353 | ObjectExpression: function (path) {
|
4354 | var expression = path.node.properties.map(function (propertyItem) {
|
4355 | var keyStr = getStrByNode(propertyItem.key, true);
|
4356 | var key = keyStr ? hyphenate(keyStr) : keyStr;
|
4357 | var ref = generate(t.ExpressionStatement(propertyItem.value));
|
4358 | var val = ref.code;
|
4359 | return ("'" + key + ":' + (" + (val.slice(0, -1)) + ") + ';'")
|
4360 | }).join('+');
|
4361 |
|
4362 | var p = template(expression)({});
|
4363 | path.replaceWith(p.expression);
|
4364 | }
|
4365 | };
|
4366 | function transformObjectToString (babel$$1) {
|
4367 | return { visitor: objectToStringVisitor }
|
4368 | }
|
4369 |
|
4370 | function transformDynamicClass (staticClass, clsBinding) {
|
4371 | if ( staticClass === void 0 ) staticClass = '';
|
4372 |
|
4373 | var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator] });
|
4374 |
|
4375 |
|
4376 | var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
|
4377 | return (staticClass + " {{" + cls + "}}")
|
4378 | }
|
4379 |
|
4380 | function transformDynamicStyle (staticStyle, styleBinding) {
|
4381 | if ( staticStyle === void 0 ) staticStyle = '';
|
4382 |
|
4383 | var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString] });
|
4384 | var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
|
4385 | return (staticStyle + " {{" + cls + "}}")
|
4386 | }
|
4387 |
|
4388 | var attrs = {
|
4389 | format: function format (attrs) {
|
4390 | if ( attrs === void 0 ) attrs = {};
|
4391 |
|
4392 | var obj = {};
|
4393 |
|
4394 | Object.keys(attrs).map(function (key) {
|
4395 | var val = attrs[key];
|
4396 | obj[key.replace('@', 'v-on:').replace(/^:/, 'v-bind:')] = val;
|
4397 | });
|
4398 |
|
4399 | return obj
|
4400 | },
|
4401 |
|
4402 | convertAttr: function convertAttr (ast, log) {
|
4403 | var this$1 = this;
|
4404 |
|
4405 | var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
4406 | var tag = ast.tag;
|
4407 | var staticClass = ast.staticClass;
|
4408 | var attrs = {};
|
4409 | var wxClass = this.classObj(attrsMap['v-bind:class'], staticClass);
|
4410 | wxClass.length ? attrsMap['class'] = wxClass : '';
|
4411 | var wxStyle = this.styleObj(attrsMap['v-bind:style'], attrsMap['style']);
|
4412 | wxStyle.length ? attrsMap['style'] = wxStyle : '';
|
4413 |
|
4414 | Object.keys(attrsMap).map(function (key) {
|
4415 | var val = attrsMap[key];
|
4416 | if (key === 'v-bind:class' || key === 'v-bind:style') {
|
4417 | return
|
4418 | }
|
4419 | if (key === 'v-text') {
|
4420 | ast.children.unshift({
|
4421 | text: ("{{" + val + "}}"),
|
4422 | type: 3
|
4423 | });
|
4424 | } else if (key === 'v-html') {
|
4425 | ast.tag = 'rich-text';
|
4426 | attrs['nodes'] = "{{" + val + "}}";
|
4427 | } else if (key === 'v-show') {
|
4428 | attrs['hidden'] = "{{!(" + val + ")}}";
|
4429 | } else if (/^v\-on\:/i.test(key)) {
|
4430 | attrs = this$1.event(key, val, attrs, tag);
|
4431 | } else if (/^v\-bind\:/i.test(key)) {
|
4432 | attrs = this$1.bind(key, val, attrs, tag, attrsMap['wx:key']);
|
4433 | } else if (/^v\-model/.test(key)) {
|
4434 | attrs = this$1.model(key, val, attrs, tag, log);
|
4435 | } else if (wxmlDirectiveMap[key]) {
|
4436 | var ref = wxmlDirectiveMap[key] || {};
|
4437 | var name = ref.name; if ( name === void 0 ) name = '';
|
4438 | var type = ref.type;
|
4439 | var map = ref.map; if ( map === void 0 ) map = {};
|
4440 | var check = ref.check;
|
4441 | if (!(check && !check(key, val, log)) && !(!name || typeof type !== 'number')) {
|
4442 |
|
4443 | if (type === 0) {
|
4444 | attrs[name] = "{{" + val + "}}";
|
4445 | }
|
4446 |
|
4447 | if (type === 1) {
|
4448 | attrs[name] = undefined;
|
4449 | }
|
4450 |
|
4451 | if (type === 2) {
|
4452 | attrs[name] = val;
|
4453 | }
|
4454 |
|
4455 | if (type === 3) {
|
4456 | attrs[map[name] || name] = "{{" + val + "}}";
|
4457 | return
|
4458 | }
|
4459 | }
|
4460 | } else if (/^v\-/.test(key)) {
|
4461 | log(("不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
|
4462 | } else {
|
4463 | if ((tagConfig.virtualTag.indexOf(tag) > -1) && (key === 'class' || key === 'style' || key === 'data-mpcomid')) {
|
4464 | if (key !== 'data-mpcomid') {
|
4465 | log(("template 不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
|
4466 | }
|
4467 | } else {
|
4468 | attrs[key] = val;
|
4469 | }
|
4470 | }
|
4471 | });
|
4472 | ast.attrsMap = attrs;
|
4473 | return ast
|
4474 | },
|
4475 |
|
4476 | event: function event (key, val, attrs, tag) {
|
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 | var name = key.replace(/^v\-on\:/i, '').replace(/\.prevent/i, '');
|
4484 | var ref = name.split('.');
|
4485 | var eventName = ref[0];
|
4486 | var eventNameMap = ref.slice(1);
|
4487 | var eventMap = wxmlDirectiveMap['v-on'];
|
4488 | var check = wxmlDirectiveMap.check;
|
4489 |
|
4490 | if (check) {
|
4491 | check(key, val);
|
4492 | }
|
4493 | var wxmlEventName = '';
|
4494 | if (eventName === 'change' && (tag === 'input' || tag === 'textarea')) {
|
4495 | wxmlEventName = 'blur';
|
4496 | } else {
|
4497 | wxmlEventName = eventMap.map[eventName];
|
4498 | }
|
4499 |
|
4500 | var eventType = 'bind';
|
4501 | var isStop = eventNameMap.includes('stop');
|
4502 | if (eventNameMap.includes('capture')) {
|
4503 | eventType = isStop ? 'capture-catch:' : 'capture-bind:';
|
4504 | } else if (isStop) {
|
4505 | eventType = 'catch';
|
4506 | }
|
4507 |
|
4508 | wxmlEventName = eventType + (wxmlEventName || eventName);
|
4509 | attrs[wxmlEventName] = 'handleProxy';
|
4510 |
|
4511 | return attrs
|
4512 | },
|
4513 |
|
4514 | bind: function bind (key, val, attrs, tag, isIf) {
|
4515 | var name = key.replace(/^v\-bind\:/i, '');
|
4516 |
|
4517 | if (isIf && name === 'key') {
|
4518 | attrs['wx:key'] = val;
|
4519 | }
|
4520 |
|
4521 | if (tag === 'template') {
|
4522 | return attrs
|
4523 | }
|
4524 |
|
4525 | if (name === 'href') {
|
4526 | attrs['url'] = "{{" + val + "}}";
|
4527 | } else {
|
4528 | attrs[name] = "{{" + val + "}}";
|
4529 | }
|
4530 |
|
4531 | return attrs
|
4532 | },
|
4533 |
|
4534 | classObj: function classObj (clsBinding, staticCls) {
|
4535 | if ( clsBinding === void 0 ) clsBinding = '';
|
4536 |
|
4537 | if (!clsBinding && !staticCls) {
|
4538 | return ''
|
4539 | }
|
4540 | if (!clsBinding && staticCls) {
|
4541 | return staticCls
|
4542 | }
|
4543 |
|
4544 | return transformDynamicClass(staticCls, clsBinding)
|
4545 | },
|
4546 |
|
4547 | styleObj: function styleObj (styleBinding, staticStyle) {
|
4548 | if ( styleBinding === void 0 ) styleBinding = '';
|
4549 |
|
4550 | if (!styleBinding && !staticStyle) {
|
4551 | return ''
|
4552 | }
|
4553 | if (!styleBinding && staticStyle) {
|
4554 | return staticStyle
|
4555 | }
|
4556 |
|
4557 | return transformDynamicStyle(staticStyle, styleBinding)
|
4558 | },
|
4559 |
|
4560 | model: function model (key, val, attrs, tag) {
|
4561 | var isFormInput = tag === 'input' || tag === 'textarea';
|
4562 | attrs['value'] = "{{" + val + "}}";
|
4563 | if (key === 'v-model.lazy') {
|
4564 | if (isFormInput) {
|
4565 | attrs['bindblur'] = 'handleProxy';
|
4566 | } else {
|
4567 | attrs['bindchange'] = 'handleProxy';
|
4568 | }
|
4569 | } else {
|
4570 | if (isFormInput) {
|
4571 | attrs['bindinput'] = 'handleProxy';
|
4572 | } else {
|
4573 | attrs['bindchange'] = 'handleProxy';
|
4574 | }
|
4575 | }
|
4576 |
|
4577 | return attrs
|
4578 | }
|
4579 | };
|
4580 |
|
4581 | function getSlotsName (obj) {
|
4582 | if (!obj) {
|
4583 | return ''
|
4584 | }
|
4585 |
|
4586 | return tmplateSlotsObj(obj)
|
4587 | .concat(
|
4588 | Object.keys(obj).map(function(k) {
|
4589 | return '$slot' + k + ":'" + obj[k] + "'"
|
4590 | })
|
4591 | )
|
4592 | .join(',')
|
4593 | }
|
4594 |
|
4595 | function tmplateSlotsObj(obj) {
|
4596 | if (!obj) {
|
4597 | return []
|
4598 | }
|
4599 |
|
4600 | var $for = Object.keys(obj)
|
4601 | .map(function(k) {
|
4602 | return (k + ":'" + (obj[k]) + "'")
|
4603 | })
|
4604 | .join(',');
|
4605 | return $for ? [("$for:{" + $for + "}")] : []
|
4606 | }
|
4607 |
|
4608 | var component = {
|
4609 | isComponent: function isComponent (tagName, components) {
|
4610 | if ( components === void 0 ) components = {};
|
4611 |
|
4612 | return !!components[tagName]
|
4613 | },
|
4614 | convertComponent: function convertComponent (ast, components, slotName) {
|
4615 | var attrsMap = ast.attrsMap;
|
4616 | var tag = ast.tag;
|
4617 | var mpcomid = ast.mpcomid;
|
4618 | var slots = ast.slots;
|
4619 | if (slotName) {
|
4620 | attrsMap['data'] = "{{...$root[$p], ...$root[$k], $root}}";
|
4621 |
|
4622 | var bindedName = attrsMap['v-bind:name'];
|
4623 | if(bindedName) {
|
4624 | attrsMap['is'] = "{{$for[" + bindedName + "]}}";
|
4625 | } else {
|
4626 | attrsMap['is'] = "{{" + slotName + "}}";
|
4627 | }
|
4628 | } else {
|
4629 | var slotsName = getSlotsName(slots);
|
4630 | var restSlotsName = slotsName ? (", " + slotsName) : '';
|
4631 | attrsMap['data'] = "{{...$root[$kk+" + mpcomid + "], $root" + restSlotsName + "}}";
|
4632 | attrsMap['is'] = components[tag].name;
|
4633 | }
|
4634 | return ast
|
4635 | }
|
4636 | };
|
4637 |
|
4638 | var tag = function (ast, options) {
|
4639 | var tag = ast.tag;
|
4640 | var elseif = ast.elseif;
|
4641 | var elseText = ast.else;
|
4642 | var forText = ast.for;
|
4643 | var staticClass = ast.staticClass; if ( staticClass === void 0 ) staticClass = '';
|
4644 | var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
4645 | var components = options.components;
|
4646 | var ifText = attrsMap['v-if'];
|
4647 | var href = attrsMap.href;
|
4648 | var bindHref = attrsMap['v-bind:href'];
|
4649 | var name = attrsMap.name;
|
4650 |
|
4651 | if (!tag) {
|
4652 | return ast
|
4653 | }
|
4654 | var isComponent = component.isComponent(tag, components);
|
4655 | if (tag !== 'template' && tag !== 'block' && tag !== 'slot' && !isComponent) {
|
4656 | ast.staticClass = staticClass ? ("_" + tag + " " + staticClass) : ("_" + tag);
|
4657 | }
|
4658 | ast.tag = tagMap[tag] || tag;
|
4659 |
|
4660 | var isSlot = tag === 'slot';
|
4661 |
|
4662 | if ((ifText || elseif || elseText || forText) && tag === 'template') {
|
4663 | ast.tag = 'block';
|
4664 | } else if (isComponent || isSlot) {
|
4665 | var originSlotName = name || 'default';
|
4666 | var slotName = isSlot ? ("$slot" + originSlotName + " || '" + originSlotName + "'") : undefined;
|
4667 |
|
4668 |
|
4669 | delete ast.attrsMap.name;
|
4670 | ast = component.convertComponent(ast, components, slotName);
|
4671 | ast.tag = 'template';
|
4672 | } else if (tag === 'a' && !(href || bindHref)) {
|
4673 | ast.tag = 'view';
|
4674 | } else if (ast.events && ast.events.scroll) {
|
4675 | ast.tag = 'scroll-view';
|
4676 | } else if (tag === 'input') {
|
4677 | var type = attrsMap.type;
|
4678 | if (type && ['button', 'checkbox', 'radio'].indexOf(type) > -1) {
|
4679 | delete ast.attrsMap.type;
|
4680 | ast.tag = type;
|
4681 | }
|
4682 | if (type === 'button') {
|
4683 | ast.children.push({
|
4684 | text: attrsMap.value || '',
|
4685 | type: 3
|
4686 | });
|
4687 | delete ast.attrsMap.value;
|
4688 | }
|
4689 | }
|
4690 | return ast
|
4691 | };
|
4692 |
|
4693 | var astMap = {
|
4694 | if: 'wx:if',
|
4695 | iterator1: 'wx:for-index',
|
4696 | key: 'wx:key',
|
4697 | alias: 'wx:for-item',
|
4698 | 'v-for': 'wx:for'
|
4699 | };
|
4700 |
|
4701 | var convertFor = function (ast) {
|
4702 | var iterator1 = ast.iterator1;
|
4703 | var forText = ast.for;
|
4704 | var key = ast.key;
|
4705 | var alias = ast.alias;
|
4706 | var attrsMap = ast.attrsMap;
|
4707 |
|
4708 | if (forText) {
|
4709 | attrsMap[astMap['v-for']] = "{{" + forText + "}}";
|
4710 | if (iterator1) {
|
4711 | attrsMap[astMap['iterator1']] = iterator1;
|
4712 | }
|
4713 | if (key) {
|
4714 | attrsMap[astMap['key']] = key;
|
4715 | }
|
4716 | if (alias) {
|
4717 | attrsMap[astMap['alias']] = alias;
|
4718 | }
|
4719 |
|
4720 | delete attrsMap['v-for'];
|
4721 | }
|
4722 |
|
4723 | return ast
|
4724 | };
|
4725 |
|
4726 | function convertAst (node, options, util) {
|
4727 | if ( options === void 0 ) options = {};
|
4728 |
|
4729 | var children = node.children;
|
4730 | var ifConditions = node.ifConditions;
|
4731 | var staticClass = node.staticClass; if ( staticClass === void 0 ) staticClass = '';
|
4732 | var mpcomid = node.mpcomid;
|
4733 | var tagName = node.tag;
|
4734 | var log = util.log;
|
4735 | var deps = util.deps;
|
4736 | var slots = util.slots;
|
4737 | var slotTemplates = util.slotTemplates;
|
4738 | var wxmlAst = Object.assign({}, node);
|
4739 | var moduleId = options.moduleId;
|
4740 | var components = options.components;
|
4741 | wxmlAst.tag = tagName = tagName ? hyphenate(tagName) : tagName;
|
4742 |
|
4743 | var isSlot = tagName === 'slot';
|
4744 | if (isSlot) {
|
4745 | deps.slots = 'slots';
|
4746 |
|
4747 | var defSlot = Object.assign({}, wxmlAst);
|
4748 | defSlot.tag = 'template';
|
4749 | var templateName = "" + (defSlot.attrsMap.name || 'default');
|
4750 | defSlot.attrsMap.name = templateName;
|
4751 | wxmlAst.children = [];
|
4752 | defSlot.parent = node.parent.parent;
|
4753 | slotTemplates[templateName] = defSlot;
|
4754 | }
|
4755 |
|
4756 | var currentIsComponent = component.isComponent(tagName, components);
|
4757 | if (currentIsComponent) {
|
4758 | deps[tagName] = tagName;
|
4759 | }
|
4760 |
|
4761 | if (moduleId && !currentIsComponent && tagConfig.virtualTag.indexOf(tagName) < 0) {
|
4762 | wxmlAst.staticClass = staticClass ? (moduleId + " " + staticClass).replace(/\"/g, '') : moduleId;
|
4763 | } else {
|
4764 | wxmlAst.staticClass = staticClass.replace(/\"/g, '');
|
4765 | }
|
4766 |
|
4767 |
|
4768 | wxmlAst.slots = {};
|
4769 | if (currentIsComponent && children && children.length) {
|
4770 |
|
4771 | children
|
4772 | .reduce(function (res, n) {
|
4773 | var ref = n.attrsMap || {};
|
4774 | var slot = ref.slot;
|
4775 |
|
4776 | var arr = slot ? res : res[0];
|
4777 | arr.push(n);
|
4778 | return res
|
4779 | }, [[]])
|
4780 | .forEach(function (n) {
|
4781 | var isDefault = Array.isArray(n);
|
4782 | var slotName = isDefault ? 'default' : n.attrsMap.slot;
|
4783 | var slotId = moduleId + "-" + slotName + "-" + (mpcomid.replace(/\'/g, ''));
|
4784 | var node = isDefault ? { tag: 'slot', attrsMap: {}, children: n } : n;
|
4785 |
|
4786 | node.tag = 'template';
|
4787 | node.attrsMap.name = slotId;
|
4788 | delete node.attrsMap.slot;
|
4789 |
|
4790 | slots[slotId] = { node: convertAst(node, options, util), name: slotName, slotId: slotId };
|
4791 | wxmlAst.slots[slotName] = slotId;
|
4792 | });
|
4793 |
|
4794 | children.length = 0;
|
4795 | wxmlAst.children.length = 0;
|
4796 | }
|
4797 |
|
4798 | wxmlAst.attrsMap = attrs.format(wxmlAst.attrsMap);
|
4799 | wxmlAst = tag(wxmlAst, options);
|
4800 | wxmlAst = convertFor(wxmlAst, options);
|
4801 | wxmlAst = attrs.convertAttr(wxmlAst, log);
|
4802 | if (children && !isSlot) {
|
4803 | wxmlAst.children = children.map(function (k) { return convertAst(k, options, util); });
|
4804 | }
|
4805 |
|
4806 | if (ifConditions) {
|
4807 | var length = ifConditions.length;
|
4808 | for (var i = 1; i < length; i++) {
|
4809 | wxmlAst.ifConditions[i].block = convertAst(ifConditions[i].block, options, util);
|
4810 | }
|
4811 | }
|
4812 |
|
4813 | return wxmlAst
|
4814 | }
|
4815 |
|
4816 | function wxmlAst (compiled, options, log) {
|
4817 | if ( options === void 0 ) options = {};
|
4818 |
|
4819 | var ast = compiled.ast;
|
4820 | var deps = {
|
4821 |
|
4822 | };
|
4823 | var slots = {
|
4824 |
|
4825 | };
|
4826 | var slotTemplates = {
|
4827 | };
|
4828 |
|
4829 | var wxast = convertAst(ast, options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates });
|
4830 | var children = Object.keys(slotTemplates).map(function (k) { return convertAst(slotTemplates[k], options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates }); });
|
4831 | wxast.children = children.concat(wxast.children);
|
4832 | return {
|
4833 | wxast: wxast,
|
4834 | deps: deps,
|
4835 | slots: slots
|
4836 | }
|
4837 | }
|
4838 |
|
4839 | function generate$2 (obj, options) {
|
4840 | if ( options === void 0 ) options = {};
|
4841 |
|
4842 | var tag = obj.tag;
|
4843 | var attrsMap = obj.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
4844 | var children = obj.children;
|
4845 | var text = obj.text;
|
4846 | var ifConditions = obj.ifConditions;
|
4847 | if (!tag) { return text }
|
4848 | var child = '';
|
4849 | if (children && children.length) {
|
4850 |
|
4851 | child = children.map(function (v) { return generate$2(v, options); }).join('');
|
4852 | }
|
4853 |
|
4854 |
|
4855 | var ifConditionsArr = [];
|
4856 | if (ifConditions) {
|
4857 | var length = ifConditions.length;
|
4858 | for (var i = 1; i < length; i++) {
|
4859 | ifConditionsArr.push(generate$2(ifConditions[i].block, options));
|
4860 | }
|
4861 | }
|
4862 |
|
4863 | var attrs = Object.keys(attrsMap).map(function (k) { return convertAttr(k, attrsMap[k]); }).join(' ');
|
4864 |
|
4865 | var tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea'];
|
4866 | if (tags.indexOf(tag) > -1 && !(children && children.length)) {
|
4867 | return ("<" + tag + (attrs ? ' ' + attrs : '') + " />" + (ifConditionsArr.join('')))
|
4868 | }
|
4869 | return ("<" + tag + (attrs ? ' ' + attrs : '') + ">" + (child || '') + "</" + tag + ">" + (ifConditionsArr.join('')))
|
4870 | }
|
4871 |
|
4872 | function convertAttr (key, val) {
|
4873 | return (val === '' || typeof val === 'undefined') ? key : (key + "=\"" + val + "\"")
|
4874 | }
|
4875 |
|
4876 | var utils = {
|
4877 | toLowerCase: function toLowerCase (str) {
|
4878 | return str.replace(/([A-Z])/g, '-$1').toLowerCase().trim()
|
4879 | },
|
4880 |
|
4881 | getChar: function getChar (index) {
|
4882 | return String.fromCharCode(0x61 + index)
|
4883 | },
|
4884 |
|
4885 | log: function log (compiled) {
|
4886 | compiled.mpErrors = [];
|
4887 | compiled.mpTips = [];
|
4888 |
|
4889 | return function (str, type) {
|
4890 | if (type === 'waring') {
|
4891 | compiled.mpTips.push(str);
|
4892 | } else {
|
4893 | compiled.mpErrors.push(str);
|
4894 | }
|
4895 | }
|
4896 | }
|
4897 | };
|
4898 |
|
4899 | function compileToWxml$1 (compiled, options) {
|
4900 | if ( options === void 0 ) options = {};
|
4901 |
|
4902 |
|
4903 | var components = options.components; if ( components === void 0 ) components = {};
|
4904 | var log = utils.log(compiled);
|
4905 |
|
4906 | var ref = wxmlAst(compiled, options, log);
|
4907 | var wxast = ref.wxast;
|
4908 | var deps = ref.deps; if ( deps === void 0 ) deps = {};
|
4909 | var slots = ref.slots; if ( slots === void 0 ) slots = {};
|
4910 | var code = generate$2(wxast, options);
|
4911 |
|
4912 |
|
4913 | var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
|
4914 | code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";
|
4915 |
|
4916 |
|
4917 | Object.keys(slots).forEach(function (k) {
|
4918 | var slot = slots[k];
|
4919 | slot.code = generate$2(slot.node, options);
|
4920 | });
|
4921 |
|
4922 |
|
4923 | return { code: code, compiled: compiled, slots: slots, importCode: importCode }
|
4924 | }
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 | var noSupport$1 = {
|
4935 | type: 4,
|
4936 | check: function (k, v, errors) {
|
4937 | errors(("不支持此指令: " + k + "=\"" + v + "\""));
|
4938 | return false
|
4939 | }
|
4940 | };
|
4941 | var wxmlDirectiveMap$1 = {
|
4942 | 'v-if': {
|
4943 | name: 's-if',
|
4944 | type: 2
|
4945 | },
|
4946 | 'v-else-if': {
|
4947 | name: 's-elif',
|
4948 | type: 2
|
4949 | },
|
4950 | 'v-else': {
|
4951 | name: 'w-else',
|
4952 | type: 1
|
4953 | },
|
4954 | 'v-text': {
|
4955 | name: '',
|
4956 | type: 1
|
4957 | },
|
4958 | 'v-html': {
|
4959 | name: '',
|
4960 | type: 1
|
4961 | },
|
4962 | 'v-on': {
|
4963 | name: '',
|
4964 | map: {
|
4965 | click: 'tap',
|
4966 | touchstart: 'touchstart',
|
4967 | touchmove: 'touchmove',
|
4968 | touchcancel: 'touchcancel',
|
4969 | touchend: 'touchend',
|
4970 | tap: 'tap',
|
4971 | longtap: 'longtap',
|
4972 | input: 'input',
|
4973 | change: 'change',
|
4974 | submit: 'submit',
|
4975 | blur: 'blur',
|
4976 | focus: 'focus',
|
4977 | reset: 'reset',
|
4978 | confirm: 'confirm',
|
4979 | columnchange: 'columnchange',
|
4980 | linechange: 'linechange',
|
4981 | error: 'error',
|
4982 | scrolltoupper: 'scrolltoupper',
|
4983 | scrolltolower: 'scrolltolower',
|
4984 | scroll: 'scroll',
|
4985 | load: 'load'
|
4986 | },
|
4987 | type: 2
|
4988 | },
|
4989 | 'v-bind': {
|
4990 | name: '',
|
4991 | map: {
|
4992 | 'href': 'url'
|
4993 | },
|
4994 | type: 3
|
4995 | },
|
4996 | 'href': {
|
4997 | name: 'url',
|
4998 | type: 2
|
4999 | },
|
5000 | 'v-pre': noSupport$1,
|
5001 | 'v-cloak': noSupport$1,
|
5002 | 'v-once': {
|
5003 | name: '',
|
5004 | type: 5
|
5005 | }
|
5006 | };
|
5007 |
|
5008 | var tagConfig$1 = {
|
5009 | virtualTag: ['slot', 'template', 'block']
|
5010 | };
|
5011 |
|
5012 |
|
5013 |
|
5014 | function getStrByNode$1 (node, onlyStr) {
|
5015 | if ( onlyStr === void 0 ) onlyStr = false;
|
5016 |
|
5017 | if (onlyStr) {
|
5018 | return node.value || node.name || ''
|
5019 | }
|
5020 | return node.type === 'StringLiteral' ? node : t.stringLiteral(node.name || '')
|
5021 | }
|
5022 |
|
5023 |
|
5024 | var objectVisitor$1 = {
|
5025 | ObjectExpression: function (path) {
|
5026 | var elements = path.node.properties.map(function (propertyItem) {
|
5027 | return t.conditionalExpression(propertyItem.value, getStrByNode$1(propertyItem.key), t.stringLiteral(''))
|
5028 | });
|
5029 | path.replaceWith(t.arrayExpression(elements));
|
5030 | }
|
5031 | };
|
5032 |
|
5033 | function transformObjectToTernaryOperator$1 (babel$$1) {
|
5034 | return { visitor: objectVisitor$1 }
|
5035 | }
|
5036 |
|
5037 |
|
5038 | var objectToStringVisitor$1 = {
|
5039 | ObjectExpression: function (path) {
|
5040 | var expression = path.node.properties.map(function (propertyItem) {
|
5041 | var keyStr = getStrByNode$1(propertyItem.key, true);
|
5042 | var key = keyStr ? hyphenate(keyStr) : keyStr;
|
5043 | var ref = generate(t.ExpressionStatement(propertyItem.value));
|
5044 | var val = ref.code;
|
5045 | return ("'" + key + ":' + (" + (val.slice(0, -1)) + ") + ';'")
|
5046 | }).join('+');
|
5047 |
|
5048 | var p = template(expression)({});
|
5049 | path.replaceWith(p.expression);
|
5050 | }
|
5051 | };
|
5052 | function transformObjectToString$1 (babel$$1) {
|
5053 | return { visitor: objectToStringVisitor$1 }
|
5054 | }
|
5055 |
|
5056 | function transformDynamicClass$1 (staticClass, clsBinding) {
|
5057 | if ( staticClass === void 0 ) staticClass = '';
|
5058 |
|
5059 | var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator$1] });
|
5060 |
|
5061 |
|
5062 | var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
|
5063 | return (staticClass + " {{" + cls + "}}")
|
5064 | }
|
5065 |
|
5066 | function transformDynamicStyle$1 (staticStyle, styleBinding) {
|
5067 | if ( staticStyle === void 0 ) staticStyle = '';
|
5068 |
|
5069 | var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString$1] });
|
5070 | var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
|
5071 | return (staticStyle + " {{" + cls + "}}")
|
5072 | }
|
5073 |
|
5074 | var attrs$1 = {
|
5075 | format: function format (attrs) {
|
5076 | if ( attrs === void 0 ) attrs = {};
|
5077 |
|
5078 | var obj = {};
|
5079 |
|
5080 | Object.keys(attrs).map(function (key) {
|
5081 | var val = attrs[key];
|
5082 | obj[key.replace('@', 'v-on:').replace(/^:/, 'v-bind:')] = val;
|
5083 | });
|
5084 |
|
5085 | return obj
|
5086 | },
|
5087 |
|
5088 | convertAttr: function convertAttr (ast, log) {
|
5089 | var this$1 = this;
|
5090 |
|
5091 | var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
5092 | var tag = ast.tag;
|
5093 | var staticClass = ast.staticClass;
|
5094 | var attrs = {};
|
5095 | var wxClass = this.classObj(attrsMap['v-bind:class'], staticClass);
|
5096 | wxClass.length ? attrsMap['class'] = wxClass : '';
|
5097 | var wxStyle = this.styleObj(attrsMap['v-bind:style'], attrsMap['style']);
|
5098 | wxStyle.length ? attrsMap['style'] = wxStyle : '';
|
5099 |
|
5100 | Object.keys(attrsMap).map(function (key) {
|
5101 | var val = attrsMap[key];
|
5102 | if (key === 'v-bind:class' || key === 'v-bind:style') {
|
5103 | return
|
5104 | }
|
5105 | if (key === 'v-text') {
|
5106 | ast.children.unshift({
|
5107 | text: ("{{" + val + "}}"),
|
5108 | type: 3
|
5109 | });
|
5110 | } else if (key === 'v-html') {
|
5111 | ast.tag = 'rich-text';
|
5112 | attrs['nodes'] = "{{" + val + "}}";
|
5113 | } else if (key === 'v-show') {
|
5114 | attrs['hidden'] = "{{!(" + val + ")}}";
|
5115 | } else if (/^v\-on\:/i.test(key)) {
|
5116 | attrs = this$1.event(key, val, attrs, tag);
|
5117 | } else if (/^v\-bind\:/i.test(key)) {
|
5118 | attrs = this$1.bind(key, val, attrs, tag, attrsMap['wx:key']);
|
5119 | } else if (/^v\-model/.test(key)) {
|
5120 | attrs = this$1.model(key, val, attrs, tag, log);
|
5121 | } else if (wxmlDirectiveMap$1[key]) {
|
5122 | var ref = wxmlDirectiveMap$1[key] || {};
|
5123 | var name = ref.name; if ( name === void 0 ) name = '';
|
5124 | var type = ref.type;
|
5125 | var map = ref.map; if ( map === void 0 ) map = {};
|
5126 | var check = ref.check;
|
5127 | if (!(check && !check(key, val, log)) && !(!name || typeof type !== 'number')) {
|
5128 |
|
5129 | if (type === 0) {
|
5130 | attrs[name] = "{{" + val + "}}";
|
5131 | }
|
5132 |
|
5133 | if (type === 1) {
|
5134 | attrs[name] = undefined;
|
5135 | }
|
5136 |
|
5137 | if (type === 2) {
|
5138 | attrs[name] = val;
|
5139 | }
|
5140 |
|
5141 | if (type === 3) {
|
5142 | attrs[map[name] || name] = "{{" + val + "}}";
|
5143 | return
|
5144 | }
|
5145 | }
|
5146 | } else if (/^v\-/.test(key)) {
|
5147 | log(("不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
|
5148 | } else {
|
5149 | if ((tagConfig$1.virtualTag.indexOf(tag) > -1) && (key === 'class' || key === 'style' || key === 'data-mpcomid')) {
|
5150 | if (key !== 'data-mpcomid') {
|
5151 | log(("template 不支持此属性-> " + key + "=\"" + val + "\""), 'waring');
|
5152 | }
|
5153 | } else {
|
5154 | attrs[key] = val;
|
5155 | }
|
5156 | }
|
5157 | });
|
5158 | ast.attrsMap = attrs;
|
5159 | return ast
|
5160 | },
|
5161 |
|
5162 | event: function event (key, val, attrs, tag) {
|
5163 |
|
5164 |
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 | var name = key.replace(/^v\-on\:/i, '').replace(/\.prevent/i, '');
|
5170 | var ref = name.split('.');
|
5171 | var eventName = ref[0];
|
5172 | var eventNameMap = ref.slice(1);
|
5173 | var eventMap = wxmlDirectiveMap$1['v-on'];
|
5174 | var check = wxmlDirectiveMap$1.check;
|
5175 |
|
5176 | if (check) {
|
5177 | check(key, val);
|
5178 | }
|
5179 | var wxmlEventName = '';
|
5180 | if (eventName === 'change' && (tag === 'input' || tag === 'textarea')) {
|
5181 | wxmlEventName = 'blur';
|
5182 | } else {
|
5183 | wxmlEventName = eventMap.map[eventName];
|
5184 | }
|
5185 |
|
5186 | var eventType = 'bind';
|
5187 | var isStop = eventNameMap.includes('stop');
|
5188 | if (eventNameMap.includes('capture')) {
|
5189 | eventType = isStop ? 'capture-catch:' : 'capture-bind:';
|
5190 | } else if (isStop) {
|
5191 | eventType = 'catch';
|
5192 | }
|
5193 |
|
5194 | wxmlEventName = eventType + (wxmlEventName || eventName);
|
5195 | attrs[wxmlEventName] = 'handleProxy';
|
5196 |
|
5197 | return attrs
|
5198 | },
|
5199 |
|
5200 | bind: function bind (key, val, attrs, tag, isIf) {
|
5201 | var name = key.replace(/^v\-bind\:/i, '');
|
5202 |
|
5203 | if (isIf && name === 'key') {
|
5204 | attrs['wx:key'] = val;
|
5205 | }
|
5206 |
|
5207 | if (tag === 'template') {
|
5208 | return attrs
|
5209 | }
|
5210 |
|
5211 | if (name === 'href') {
|
5212 | attrs['url'] = "{{" + val + "}}";
|
5213 | } else {
|
5214 | attrs[name] = "{{" + val + "}}";
|
5215 | }
|
5216 |
|
5217 | if (tag === 'scroll-view') {
|
5218 | if (name === 'scroll-top' || name === 'scroll-left' || name === 'scroll-into-view') {
|
5219 | attrs[name] = "{=" + val + "=}";
|
5220 | }
|
5221 | }
|
5222 |
|
5223 | if (tag === 'input' || tag === 'textarea' || tag === 'slider') {
|
5224 | if (name === 'value') {
|
5225 | attrs[name] = "{=" + val + "=}";
|
5226 | }
|
5227 | }
|
5228 |
|
5229 | if (tag === 'movable-view' && (name === 'x' || name === 'y')) {
|
5230 | attrs[name] = "{=" + val + "=}";
|
5231 | }
|
5232 |
|
5233 | return attrs
|
5234 | },
|
5235 |
|
5236 | classObj: function classObj (clsBinding, staticCls) {
|
5237 | if ( clsBinding === void 0 ) clsBinding = '';
|
5238 |
|
5239 | if (!clsBinding && !staticCls) {
|
5240 | return ''
|
5241 | }
|
5242 | if (!clsBinding && staticCls) {
|
5243 | return staticCls
|
5244 | }
|
5245 |
|
5246 | return transformDynamicClass$1(staticCls, clsBinding)
|
5247 | },
|
5248 |
|
5249 | styleObj: function styleObj (styleBinding, staticStyle) {
|
5250 | if ( styleBinding === void 0 ) styleBinding = '';
|
5251 |
|
5252 | if (!styleBinding && !staticStyle) {
|
5253 | return ''
|
5254 | }
|
5255 | if (!styleBinding && staticStyle) {
|
5256 | return staticStyle
|
5257 | }
|
5258 |
|
5259 | return transformDynamicStyle$1(staticStyle, styleBinding)
|
5260 | },
|
5261 |
|
5262 | model: function model (key, val, attrs, tag) {
|
5263 | var isFormInput = tag === 'input' || tag === 'textarea';
|
5264 | attrs['value'] = "{{" + val + "}}";
|
5265 | if (key === 'v-model.lazy') {
|
5266 | if (isFormInput) {
|
5267 | attrs['bindblur'] = 'handleProxy';
|
5268 | } else {
|
5269 | attrs['bindchange'] = 'handleProxy';
|
5270 | }
|
5271 | } else {
|
5272 | if (isFormInput) {
|
5273 | attrs['bindinput'] = 'handleProxy';
|
5274 | } else {
|
5275 | attrs['bindchange'] = 'handleProxy';
|
5276 | }
|
5277 | }
|
5278 |
|
5279 | return attrs
|
5280 | }
|
5281 | };
|
5282 |
|
5283 | function getSlotsName$1 (obj) {
|
5284 | if (!obj) {
|
5285 | return ''
|
5286 | }
|
5287 |
|
5288 | return tmplateSlotsObj$1(obj)
|
5289 | .concat(
|
5290 | Object.keys(obj).map(function (k) { return ("$slot" + k + ":'" + (obj[k]) + "'"); })
|
5291 | )
|
5292 | .join(',')
|
5293 | }
|
5294 |
|
5295 | function tmplateSlotsObj$1 (obj) {
|
5296 | if (!obj) {
|
5297 | return []
|
5298 | }
|
5299 |
|
5300 | var $for = Object.keys(obj)
|
5301 | .map(function (k) { return (k + ":'" + (obj[k]) + "'"); })
|
5302 | .join(',');
|
5303 | return $for ? [("$for:{" + $for + "}")] : []
|
5304 | }
|
5305 |
|
5306 | var component$1 = {
|
5307 | isComponent: function isComponent (tagName, components) {
|
5308 | if ( components === void 0 ) components = {};
|
5309 |
|
5310 | return !!components[tagName]
|
5311 | },
|
5312 | convertComponent: function convertComponent (ast, components, slotName) {
|
5313 | var attrsMap = ast.attrsMap;
|
5314 | var tag = ast.tag;
|
5315 | var mpcomid = ast.mpcomid;
|
5316 | var slots = ast.slots;
|
5317 | if (slotName) {
|
5318 | attrsMap['data'] = '{{{...$root[$k], $root}}}';
|
5319 |
|
5320 | var bindedName = attrsMap['v-bind:name'];
|
5321 | if (bindedName) {
|
5322 | attrsMap['is'] = '{{$for[' + bindedName + ']}}';
|
5323 | } else {
|
5324 | attrsMap['is'] = '{{' + slotName + '}}';
|
5325 | }
|
5326 | } else {
|
5327 | var slotsName = getSlotsName$1(slots);
|
5328 | var restSlotsName = slotsName ? (", " + slotsName) : '';
|
5329 | attrsMap['data'] = "{{{...$root[$kk+" + mpcomid + "], $root" + restSlotsName + "}}}";
|
5330 | attrsMap['is'] = components[tag].name;
|
5331 | }
|
5332 | return ast
|
5333 | }
|
5334 | };
|
5335 |
|
5336 | var tagMap$1 = {
|
5337 | 'br': 'view',
|
5338 | 'hr': 'view',
|
5339 |
|
5340 | 'p': 'view',
|
5341 | 'h1': 'view',
|
5342 | 'h2': 'view',
|
5343 | 'h3': 'view',
|
5344 | 'h4': 'view',
|
5345 | 'h5': 'view',
|
5346 | 'h6': 'view',
|
5347 | 'abbr': 'view',
|
5348 | 'address': 'view',
|
5349 | 'b': 'view',
|
5350 | 'bdi': 'view',
|
5351 | 'bdo': 'view',
|
5352 | 'blockquote': 'view',
|
5353 | 'cite': 'view',
|
5354 | 'code': 'view',
|
5355 | 'del': 'view',
|
5356 | 'ins': 'view',
|
5357 | 'dfn': 'view',
|
5358 | 'em': 'view',
|
5359 | 'strong': 'view',
|
5360 | 'samp': 'view',
|
5361 | 'kbd': 'view',
|
5362 | 'var': 'view',
|
5363 | 'i': 'view',
|
5364 | 'mark': 'view',
|
5365 | 'pre': 'view',
|
5366 | 'q': 'view',
|
5367 | 'ruby': 'view',
|
5368 | 'rp': 'view',
|
5369 | 'rt': 'view',
|
5370 | 's': 'view',
|
5371 | 'small': 'view',
|
5372 | 'sub': 'view',
|
5373 | 'sup': 'view',
|
5374 | 'time': 'view',
|
5375 | 'u': 'view',
|
5376 | 'wbr': 'view',
|
5377 |
|
5378 |
|
5379 | 'form': 'form',
|
5380 | 'input': 'input',
|
5381 | 'textarea': 'textarea',
|
5382 | 'button': 'button',
|
5383 | 'select': 'picker',
|
5384 | 'option': 'view',
|
5385 | 'optgroup': 'view',
|
5386 | 'label': 'label',
|
5387 | 'fieldset': 'view',
|
5388 | 'datalist': 'picker',
|
5389 | 'legend': 'view',
|
5390 | 'output': 'view',
|
5391 |
|
5392 |
|
5393 | 'iframe': 'view',
|
5394 |
|
5395 | 'img': 'image',
|
5396 | 'canvas': 'canvas',
|
5397 | 'figure': 'view',
|
5398 | 'figcaption': 'view',
|
5399 |
|
5400 |
|
5401 | 'audio': 'audio',
|
5402 | 'source': 'audio',
|
5403 | 'video': 'video',
|
5404 | 'track': 'video',
|
5405 |
|
5406 | 'a': 'navigator',
|
5407 | 'nav': 'view',
|
5408 | 'link': 'navigator',
|
5409 |
|
5410 | 'ul': 'view',
|
5411 | 'ol': 'view',
|
5412 | 'li': 'view',
|
5413 | 'dl': 'view',
|
5414 | 'dt': 'view',
|
5415 | 'dd': 'view',
|
5416 | 'menu': 'view',
|
5417 | 'command': 'view',
|
5418 |
|
5419 |
|
5420 | 'table': 'view',
|
5421 | 'caption': 'view',
|
5422 | 'th': 'view',
|
5423 | 'td': 'view',
|
5424 | 'tr': 'view',
|
5425 | 'thead': 'view',
|
5426 | 'tbody': 'view',
|
5427 | 'tfoot': 'view',
|
5428 | 'col': 'view',
|
5429 | 'colgroup': 'view',
|
5430 |
|
5431 |
|
5432 | 'div': 'view',
|
5433 | 'main': 'view',
|
5434 | 'span': 'label',
|
5435 | 'header': 'view',
|
5436 | 'footer': 'view',
|
5437 | 'section': 'view',
|
5438 | 'article': 'view',
|
5439 | 'aside': 'view',
|
5440 | 'details': 'view',
|
5441 | 'dialog': 'view',
|
5442 | 'summary': 'view',
|
5443 |
|
5444 | 'progress': 'progress',
|
5445 | 'meter': 'progress',
|
5446 | 'head': 'view',
|
5447 | 'meta': 'view',
|
5448 | 'base': 'text',
|
5449 |
|
5450 | 'area': 'navigator',
|
5451 |
|
5452 | 'script': 'view',
|
5453 | 'noscript': 'view',
|
5454 | 'embed': 'view',
|
5455 | 'object': 'view',
|
5456 | 'param': 'view',
|
5457 |
|
5458 |
|
5459 |
|
5460 | 'view': 'view',
|
5461 | 'scroll-view': 'scroll-view',
|
5462 | 'swiper': 'swiper',
|
5463 | 'icon': 'icon',
|
5464 | 'text': 'text',
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 | 'checkbox': 'checkbox',
|
5470 | 'radio': 'radio',
|
5471 | 'picker': 'picker',
|
5472 | 'picker-view': 'picker-view',
|
5473 | 'slider': 'slider',
|
5474 | 'switch': 'switch',
|
5475 |
|
5476 | 'navigator': 'navigator',
|
5477 |
|
5478 | 'image': 'image',
|
5479 |
|
5480 | 'map': 'map',
|
5481 |
|
5482 | 'contact-button': 'contact-button',
|
5483 | 'block': 'block'
|
5484 | };
|
5485 |
|
5486 | var tag$1 = function (ast, options) {
|
5487 | var tag = ast.tag;
|
5488 | var elseif = ast.elseif;
|
5489 | var elseText = ast.else;
|
5490 | var forText = ast.for;
|
5491 | var staticClass = ast.staticClass; if ( staticClass === void 0 ) staticClass = '';
|
5492 | var attrsMap = ast.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
5493 | var components = options.components;
|
5494 | var ifText = attrsMap['v-if'];
|
5495 | var href = attrsMap.href;
|
5496 | var bindHref = attrsMap['v-bind:href'];
|
5497 | var name = attrsMap.name;
|
5498 |
|
5499 | if (!tag) {
|
5500 | return ast
|
5501 | }
|
5502 | var isComponent = component$1.isComponent(tag, components);
|
5503 | if (tag !== 'template' && tag !== 'block' && tag !== 'slot' && !isComponent) {
|
5504 | ast.staticClass = staticClass ? ("_" + tag + " " + staticClass) : ("_" + tag);
|
5505 | }
|
5506 | ast.tag = tagMap$1[tag] || tag;
|
5507 |
|
5508 | var isSlot = tag === 'slot';
|
5509 |
|
5510 | if ((ifText || elseif || elseText || forText) && tag === 'template') {
|
5511 | ast.tag = 'block';
|
5512 | } else if (isComponent || isSlot) {
|
5513 | var originSlotName = name || 'default';
|
5514 | var slotName = isSlot ? ("$slot" + originSlotName + " || '" + originSlotName + "'") : undefined;
|
5515 |
|
5516 |
|
5517 | delete ast.attrsMap.name;
|
5518 | ast = component$1.convertComponent(ast, components, slotName);
|
5519 | ast.tag = 'template';
|
5520 | } else if (tag === 'a' && !(href || bindHref)) {
|
5521 | ast.tag = 'view';
|
5522 | } else if (ast.events && ast.events.scroll) {
|
5523 | ast.tag = 'scroll-view';
|
5524 | } else if (tag === 'input') {
|
5525 | var type = attrsMap.type;
|
5526 | if (type && ['button', 'checkbox', 'radio'].indexOf(type) > -1) {
|
5527 | delete ast.attrsMap.type;
|
5528 | ast.tag = type;
|
5529 | }
|
5530 | if (type === 'button') {
|
5531 | ast.children.push({
|
5532 | text: attrsMap.value || '',
|
5533 | type: 3
|
5534 | });
|
5535 | delete ast.attrsMap.value;
|
5536 | }
|
5537 | }
|
5538 | return ast
|
5539 | };
|
5540 |
|
5541 | var astMap$1 = {
|
5542 | 'if': 's-if',
|
5543 | 'v-for': 's-for',
|
5544 | 'alias': 's-for-item',
|
5545 | 'iterator1': 's-for-index',
|
5546 | 'key': 's-key'
|
5547 | };
|
5548 |
|
5549 | var convertFor$1 = function (ast) {
|
5550 | var iterator1 = ast.iterator1;
|
5551 | var forText = ast.for;
|
5552 | var key = ast.key;
|
5553 | var alias = ast.alias;
|
5554 | var attrsMap = ast.attrsMap;
|
5555 |
|
5556 |
|
5557 |
|
5558 |
|
5559 | if (forText) {
|
5560 | attrsMap[astMap$1['v-for']] = alias + "," + iterator1 + " in " + forText;
|
5561 |
|
5562 |
|
5563 |
|
5564 |
|
5565 |
|
5566 |
|
5567 |
|
5568 |
|
5569 |
|
5570 |
|
5571 | delete attrsMap['v-for'];
|
5572 | }
|
5573 |
|
5574 |
|
5575 | return ast
|
5576 | };
|
5577 |
|
5578 | function convertAst$1 (node, options, util) {
|
5579 | if ( options === void 0 ) options = {};
|
5580 |
|
5581 | var children = node.children;
|
5582 | var ifConditions = node.ifConditions;
|
5583 | var staticClass = node.staticClass; if ( staticClass === void 0 ) staticClass = '';
|
5584 | var mpcomid = node.mpcomid;
|
5585 | var tagName = node.tag;
|
5586 | var log = util.log;
|
5587 | var deps = util.deps;
|
5588 | var slots = util.slots;
|
5589 | var slotTemplates = util.slotTemplates;
|
5590 | var wxmlAst = Object.assign({}, node);
|
5591 | var moduleId = options.moduleId;
|
5592 | var components = options.components;
|
5593 | wxmlAst.tag = tagName = tagName ? hyphenate(tagName) : tagName;
|
5594 |
|
5595 | var isSlot = tagName === 'slot';
|
5596 | if (isSlot) {
|
5597 | deps.slots = 'slots';
|
5598 |
|
5599 | var defSlot = Object.assign({}, wxmlAst);
|
5600 | defSlot.tag = 'template';
|
5601 | var templateName = "" + (defSlot.attrsMap.name || 'default');
|
5602 | defSlot.attrsMap.name = templateName;
|
5603 | wxmlAst.children = [];
|
5604 | defSlot.parent = node.parent.parent;
|
5605 | slotTemplates[templateName] = defSlot;
|
5606 | }
|
5607 |
|
5608 | var currentIsComponent = component$1.isComponent(tagName, components);
|
5609 | if (currentIsComponent) {
|
5610 | deps[tagName] = tagName;
|
5611 | }
|
5612 |
|
5613 | if (moduleId && !currentIsComponent && tagConfig$1.virtualTag.indexOf(tagName) < 0) {
|
5614 | wxmlAst.staticClass = staticClass ? (moduleId + " " + staticClass).replace(/\"/g, '') : moduleId;
|
5615 | } else {
|
5616 | wxmlAst.staticClass = staticClass.replace(/\"/g, '');
|
5617 | }
|
5618 |
|
5619 |
|
5620 | wxmlAst.slots = {};
|
5621 | if (currentIsComponent && children && children.length) {
|
5622 |
|
5623 | children
|
5624 | .reduce(function (res, n) {
|
5625 | var ref = n.attrsMap || {};
|
5626 | var slot = ref.slot;
|
5627 |
|
5628 | var arr = slot ? res : res[0];
|
5629 | arr.push(n);
|
5630 | return res
|
5631 | }, [[]])
|
5632 | .forEach(function (n) {
|
5633 | var isDefault = Array.isArray(n);
|
5634 | var slotName = isDefault ? 'default' : n.attrsMap.slot;
|
5635 | var slotId = moduleId + "-" + slotName + "-" + (mpcomid.replace(/\'/g, ''));
|
5636 | var node = isDefault ? { tag: 'slot', attrsMap: {}, children: n } : n;
|
5637 |
|
5638 | node.tag = 'template';
|
5639 | node.attrsMap.name = slotId;
|
5640 | delete node.attrsMap.slot;
|
5641 |
|
5642 | slots[slotId] = { node: convertAst$1(node, options, util), name: slotName, slotId: slotId };
|
5643 | wxmlAst.slots[slotName] = slotId;
|
5644 | });
|
5645 |
|
5646 | children.length = 0;
|
5647 | wxmlAst.children.length = 0;
|
5648 | }
|
5649 |
|
5650 | wxmlAst.attrsMap = attrs$1.format(wxmlAst.attrsMap);
|
5651 | wxmlAst = tag$1(wxmlAst, options);
|
5652 | wxmlAst = convertFor$1(wxmlAst, options);
|
5653 | wxmlAst = attrs$1.convertAttr(wxmlAst, log);
|
5654 | if (children && !isSlot) {
|
5655 | wxmlAst.children = children.map(function (k) { return convertAst$1(k, options, util); });
|
5656 | }
|
5657 |
|
5658 | if (ifConditions) {
|
5659 | var length = ifConditions.length;
|
5660 | for (var i = 1; i < length; i++) {
|
5661 | wxmlAst.ifConditions[i].block = convertAst$1(ifConditions[i].block, options, util);
|
5662 | }
|
5663 | }
|
5664 |
|
5665 | return wxmlAst
|
5666 | }
|
5667 |
|
5668 | function wxmlAst$1 (compiled, options, log) {
|
5669 | if ( options === void 0 ) options = {};
|
5670 |
|
5671 | var ast = compiled.ast;
|
5672 | var deps = {
|
5673 |
|
5674 | };
|
5675 | var slots = {
|
5676 |
|
5677 | };
|
5678 | var slotTemplates = {
|
5679 | };
|
5680 |
|
5681 | var wxast = convertAst$1(ast, options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates });
|
5682 | var children = Object.keys(slotTemplates).map(function (k) { return convertAst$1(slotTemplates[k], options, { log: log, deps: deps, slots: slots, slotTemplates: slotTemplates }); });
|
5683 | wxast.children = children.concat(wxast.children);
|
5684 | return {
|
5685 | wxast: wxast,
|
5686 | deps: deps,
|
5687 | slots: slots
|
5688 | }
|
5689 | }
|
5690 |
|
5691 | function generate$3 (obj, options) {
|
5692 | if ( options === void 0 ) options = {};
|
5693 |
|
5694 | var tag = obj.tag;
|
5695 | var attrsMap = obj.attrsMap; if ( attrsMap === void 0 ) attrsMap = {};
|
5696 | var children = obj.children;
|
5697 | var text = obj.text;
|
5698 | var ifConditions = obj.ifConditions;
|
5699 | if (!tag) { return text }
|
5700 | var child = '';
|
5701 | if (children && children.length) {
|
5702 |
|
5703 | child = children.map(function (v) { return generate$3(v, options); }).join('');
|
5704 | }
|
5705 |
|
5706 |
|
5707 | var ifConditionsArr = [];
|
5708 | if (ifConditions) {
|
5709 | var length = ifConditions.length;
|
5710 | for (var i = 1; i < length; i++) {
|
5711 | ifConditionsArr.push(generate$3(ifConditions[i].block, options));
|
5712 | }
|
5713 | }
|
5714 |
|
5715 | var attrs = Object.keys(attrsMap).map(function (k) { return convertAttr$1(k, attrsMap[k]); }).join(' ');
|
5716 |
|
5717 | var tags = ['progress', 'checkbox', 'switch', 'input', 'radio', 'slider', 'textarea'];
|
5718 | if (tags.indexOf(tag) > -1 && !(children && children.length)) {
|
5719 | return ("<" + tag + (attrs ? ' ' + attrs : '') + " />" + (ifConditionsArr.join('')))
|
5720 | }
|
5721 | return ("<" + tag + (attrs ? ' ' + attrs : '') + ">" + (child || '') + "</" + tag + ">" + (ifConditionsArr.join('')))
|
5722 | }
|
5723 |
|
5724 | function convertAttr$1 (key, val) {
|
5725 | return (val === '' || typeof val === 'undefined') ? key : (key + "=\"" + val + "\"")
|
5726 | }
|
5727 |
|
5728 | var utils$1 = {
|
5729 | toLowerCase: function toLowerCase (str) {
|
5730 | return str.replace(/([A-Z])/g, '-$1').toLowerCase().trim()
|
5731 | },
|
5732 |
|
5733 | getChar: function getChar (index) {
|
5734 | return String.fromCharCode(0x61 + index)
|
5735 | },
|
5736 |
|
5737 | log: function log (compiled) {
|
5738 | compiled.mpErrors = [];
|
5739 | compiled.mpTips = [];
|
5740 |
|
5741 | return function (str, type) {
|
5742 | if (type === 'waring') {
|
5743 | compiled.mpTips.push(str);
|
5744 | } else {
|
5745 | compiled.mpErrors.push(str);
|
5746 | }
|
5747 | }
|
5748 | }
|
5749 | };
|
5750 |
|
5751 | function compileToWxml$2 (compiled, options) {
|
5752 | if ( options === void 0 ) options = {};
|
5753 |
|
5754 |
|
5755 | var components = options.components; if ( components === void 0 ) components = {};
|
5756 | var log = utils$1.log(compiled);
|
5757 |
|
5758 | var ref = wxmlAst$1(compiled, options, log);
|
5759 | var wxast = ref.wxast;
|
5760 | var deps = ref.deps; if ( deps === void 0 ) deps = {};
|
5761 | var slots = ref.slots; if ( slots === void 0 ) slots = {};
|
5762 | var code = generate$3(wxast, options);
|
5763 |
|
5764 |
|
5765 | var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
|
5766 | code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";
|
5767 |
|
5768 |
|
5769 | Object.keys(slots).forEach(function (k) {
|
5770 | var slot = slots[k];
|
5771 | slot.code = generate$3(slot.node, options);
|
5772 | });
|
5773 |
|
5774 |
|
5775 | return { code: code, compiled: compiled, slots: slots, importCode: importCode }
|
5776 | }
|
5777 |
|
5778 |
|
5779 |
|
5780 | function compileToWxml (compiled, options, fileExt) {
|
5781 | var code;
|
5782 | switch(fileExt.platform) {
|
5783 | case 'swan':
|
5784 | code = compileToWxml$2(compiled, options);
|
5785 | break
|
5786 | case 'wx':
|
5787 | code = compileToWxml$1(compiled, options);
|
5788 | break
|
5789 | default:
|
5790 | code = compileToWxml$1(compiled, options);
|
5791 | }
|
5792 | return code
|
5793 | }
|
5794 |
|
5795 | var ref = createCompiler(baseOptions);
|
5796 | var compile = ref.compile;
|
5797 | var compileToFunctions = ref.compileToFunctions;
|
5798 |
|
5799 |
|
5800 |
|
5801 | exports.parseComponent = parseComponent;
|
5802 | exports.compile = compile;
|
5803 | exports.compileToFunctions = compileToFunctions;
|
5804 | exports.compileToWxml = compileToWxml;
|