@vue/compiler-core 3.4.0-alpha.1 → 3.4.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,87 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var shared = require('@vue/shared');
6
+ var decode_js = require('entities/lib/decode.js');
6
7
  var parser = require('@babel/parser');
7
8
  var sourceMapJs = require('source-map-js');
8
9
  var estreeWalker = require('estree-walker');
9
10
 
10
- function defaultOnError(error) {
11
- throw error;
12
- }
13
- function defaultOnWarn(msg) {
14
- console.warn(`[Vue warn] ${msg.message}`);
15
- }
16
- function createCompilerError(code, loc, messages, additionalMessage) {
17
- const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
18
- const error = new SyntaxError(String(msg));
19
- error.code = code;
20
- error.loc = loc;
21
- return error;
22
- }
23
- const errorMessages = {
24
- // parse errors
25
- [0]: "Illegal comment.",
26
- [1]: "CDATA section is allowed only in XML context.",
27
- [2]: "Duplicate attribute.",
28
- [3]: "End tag cannot have attributes.",
29
- [4]: "Illegal '/' in tags.",
30
- [5]: "Unexpected EOF in tag.",
31
- [6]: "Unexpected EOF in CDATA section.",
32
- [7]: "Unexpected EOF in comment.",
33
- [8]: "Unexpected EOF in script.",
34
- [9]: "Unexpected EOF in tag.",
35
- [10]: "Incorrectly closed comment.",
36
- [11]: "Incorrectly opened comment.",
37
- [12]: "Illegal tag name. Use '&lt;' to print '<'.",
38
- [13]: "Attribute value was expected.",
39
- [14]: "End tag name was expected.",
40
- [15]: "Whitespace was expected.",
41
- [16]: "Unexpected '<!--' in comment.",
42
- [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
43
- [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
44
- [19]: "Attribute name cannot start with '='.",
45
- [21]: "'<?' is allowed only in XML context.",
46
- [20]: `Unexpected null character.`,
47
- [22]: "Illegal '/' in tags.",
48
- // Vue-specific parse errors
49
- [23]: "Invalid end tag.",
50
- [24]: "Element is missing end tag.",
51
- [25]: "Interpolation end sign was not found.",
52
- [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
53
- [26]: "Legal directive name was expected.",
54
- // transform errors
55
- [28]: `v-if/v-else-if is missing expression.`,
56
- [29]: `v-if/else branches must use unique keys.`,
57
- [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
58
- [31]: `v-for is missing expression.`,
59
- [32]: `v-for has invalid expression.`,
60
- [33]: `<template v-for> key should be placed on the <template> tag.`,
61
- [34]: `v-bind is missing expression.`,
62
- [35]: `v-on is missing expression.`,
63
- [36]: `Unexpected custom directive on <slot> outlet.`,
64
- [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
65
- [38]: `Duplicate slot names found. `,
66
- [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
67
- [40]: `v-slot can only be used on components or <template> tags.`,
68
- [41]: `v-model is missing expression.`,
69
- [42]: `v-model value must be a valid JavaScript member expression.`,
70
- [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
71
- [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
72
- Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
73
- [45]: `Error parsing JavaScript expression: `,
74
- [46]: `<KeepAlive> expects exactly one child component.`,
75
- // generic errors
76
- [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
77
- [48]: `ES module mode is not supported in this build of compiler.`,
78
- [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
79
- [50]: `"scopeId" option is only supported in module mode.`,
80
- // deprecations
81
- [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
82
- [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
83
- // just to fulfill types
84
- [53]: ``
85
- };
86
-
87
11
  const FRAGMENT = Symbol(`Fragment` );
88
12
  const TELEPORT = Symbol(`Teleport` );
89
13
  const SUSPENSE = Symbol(`Suspense` );
@@ -173,13 +97,14 @@ function registerRuntimeHelpers(helpers) {
173
97
  }
174
98
 
175
99
  const locStub = {
176
- source: "",
177
100
  start: { line: 1, column: 1, offset: 0 },
178
- end: { line: 1, column: 1, offset: 0 }
101
+ end: { line: 1, column: 1, offset: 0 },
102
+ source: ""
179
103
  };
180
- function createRoot(children, loc = locStub) {
104
+ function createRoot(children, source = "") {
181
105
  return {
182
106
  type: 0,
107
+ source,
183
108
  children,
184
109
  helpers: /* @__PURE__ */ new Set(),
185
110
  components: [],
@@ -189,7 +114,7 @@ function createRoot(children, loc = locStub) {
189
114
  cached: 0,
190
115
  temps: 0,
191
116
  codegenNode: void 0,
192
- loc
117
+ loc: locStub
193
118
  };
194
119
  }
195
120
  function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
@@ -360,17 +285,1032 @@ function convertToBlock(node, { helper, removeHelper, inSSR }) {
360
285
  }
361
286
  }
362
287
 
288
+ const defaultDelimitersOpen = new Uint8Array([123, 123]);
289
+ const defaultDelimitersClose = new Uint8Array([125, 125]);
290
+ function isTagStartChar(c) {
291
+ return c >= 97 && c <= 122 || c >= 65 && c <= 90;
292
+ }
293
+ function isWhitespace(c) {
294
+ return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
295
+ }
296
+ function isEndOfTagSection(c) {
297
+ return c === 47 || c === 62 || isWhitespace(c);
298
+ }
299
+ function toCharCodes(str) {
300
+ const ret = new Uint8Array(str.length);
301
+ for (let i = 0; i < str.length; i++) {
302
+ ret[i] = str.charCodeAt(i);
303
+ }
304
+ return ret;
305
+ }
306
+ const Sequences = {
307
+ Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
308
+ // CDATA[
309
+ CdataEnd: new Uint8Array([93, 93, 62]),
310
+ // ]]>
311
+ CommentEnd: new Uint8Array([45, 45, 62]),
312
+ // `-->`
313
+ ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
314
+ // `<\/script`
315
+ StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
316
+ // `</style`
317
+ TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
318
+ // `</title`
319
+ TextareaEnd: new Uint8Array([
320
+ 60,
321
+ 47,
322
+ 116,
323
+ 101,
324
+ 120,
325
+ 116,
326
+ 97,
327
+ 114,
328
+ 101,
329
+ 97
330
+ ])
331
+ // `</textarea
332
+ };
333
+ class Tokenizer {
334
+ constructor(stack, cbs) {
335
+ this.stack = stack;
336
+ this.cbs = cbs;
337
+ /** The current state the tokenizer is in. */
338
+ this.state = 1;
339
+ /** The read buffer. */
340
+ this.buffer = "";
341
+ /** The beginning of the section that is currently being read. */
342
+ this.sectionStart = 0;
343
+ /** The index within the buffer that we are currently looking at. */
344
+ this.index = 0;
345
+ /** The start of the last entity. */
346
+ this.entityStart = 0;
347
+ /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
348
+ this.baseState = 1;
349
+ /** For special parsing behavior inside of script and style tags. */
350
+ this.inRCDATA = false;
351
+ /** For disabling RCDATA tags handling */
352
+ this.inXML = false;
353
+ /** Reocrd newline positions for fast line / column calculation */
354
+ this.newlines = [];
355
+ this.mode = 0;
356
+ this.delimiterOpen = defaultDelimitersOpen;
357
+ this.delimiterClose = defaultDelimitersClose;
358
+ this.delimiterIndex = -1;
359
+ this.currentSequence = void 0;
360
+ this.sequenceIndex = 0;
361
+ {
362
+ this.entityDecoder = new decode_js.EntityDecoder(
363
+ decode_js.htmlDecodeTree,
364
+ (cp, consumed) => this.emitCodePoint(cp, consumed)
365
+ );
366
+ }
367
+ }
368
+ get inSFCRoot() {
369
+ return this.mode === 2 && this.stack.length === 0;
370
+ }
371
+ reset() {
372
+ this.state = 1;
373
+ this.mode = 0;
374
+ this.buffer = "";
375
+ this.sectionStart = 0;
376
+ this.index = 0;
377
+ this.baseState = 1;
378
+ this.currentSequence = void 0;
379
+ this.newlines.length = 0;
380
+ this.delimiterOpen = defaultDelimitersOpen;
381
+ this.delimiterClose = defaultDelimitersClose;
382
+ }
383
+ /**
384
+ * Generate Position object with line / column information using recorded
385
+ * newline positions. We know the index is always going to be an already
386
+ * processed index, so all the newlines up to this index should have been
387
+ * recorded.
388
+ */
389
+ getPos(index) {
390
+ let line = 1;
391
+ let column = index + 1;
392
+ for (let i = this.newlines.length - 1; i >= 0; i--) {
393
+ const newlineIndex = this.newlines[i];
394
+ if (index > newlineIndex) {
395
+ line = i + 2;
396
+ column = index - newlineIndex;
397
+ break;
398
+ }
399
+ }
400
+ return {
401
+ column,
402
+ line,
403
+ offset: index
404
+ };
405
+ }
406
+ peek() {
407
+ return this.buffer.charCodeAt(this.index + 1);
408
+ }
409
+ stateText(c) {
410
+ if (c === 60) {
411
+ if (this.index > this.sectionStart) {
412
+ this.cbs.ontext(this.sectionStart, this.index);
413
+ }
414
+ this.state = 5;
415
+ this.sectionStart = this.index;
416
+ } else if (c === 38) {
417
+ this.startEntity();
418
+ } else if (c === this.delimiterOpen[0]) {
419
+ this.state = 2;
420
+ this.delimiterIndex = 0;
421
+ this.stateInterpolationOpen(c);
422
+ }
423
+ }
424
+ stateInterpolationOpen(c) {
425
+ if (c === this.delimiterOpen[this.delimiterIndex]) {
426
+ if (this.delimiterIndex === this.delimiterOpen.length - 1) {
427
+ const start = this.index + 1 - this.delimiterOpen.length;
428
+ if (start > this.sectionStart) {
429
+ this.cbs.ontext(this.sectionStart, start);
430
+ }
431
+ this.state = 3;
432
+ this.sectionStart = start;
433
+ } else {
434
+ this.delimiterIndex++;
435
+ }
436
+ } else if (this.inRCDATA) {
437
+ this.state = 32;
438
+ this.stateInRCDATA(c);
439
+ } else {
440
+ this.state = 1;
441
+ this.stateText(c);
442
+ }
443
+ }
444
+ stateInterpolation(c) {
445
+ if (c === this.delimiterClose[0]) {
446
+ this.state = 4;
447
+ this.delimiterIndex = 0;
448
+ this.stateInterpolationClose(c);
449
+ }
450
+ }
451
+ stateInterpolationClose(c) {
452
+ if (c === this.delimiterClose[this.delimiterIndex]) {
453
+ if (this.delimiterIndex === this.delimiterClose.length - 1) {
454
+ this.cbs.oninterpolation(this.sectionStart, this.index + 1);
455
+ if (this.inRCDATA) {
456
+ this.state = 32;
457
+ } else {
458
+ this.state = 1;
459
+ }
460
+ this.sectionStart = this.index + 1;
461
+ } else {
462
+ this.delimiterIndex++;
463
+ }
464
+ } else {
465
+ this.state = 3;
466
+ this.stateInterpolation(c);
467
+ }
468
+ }
469
+ stateSpecialStartSequence(c) {
470
+ const isEnd = this.sequenceIndex === this.currentSequence.length;
471
+ const isMatch = isEnd ? (
472
+ // If we are at the end of the sequence, make sure the tag name has ended
473
+ isEndOfTagSection(c)
474
+ ) : (
475
+ // Otherwise, do a case-insensitive comparison
476
+ (c | 32) === this.currentSequence[this.sequenceIndex]
477
+ );
478
+ if (!isMatch) {
479
+ this.inRCDATA = false;
480
+ } else if (!isEnd) {
481
+ this.sequenceIndex++;
482
+ return;
483
+ }
484
+ this.sequenceIndex = 0;
485
+ this.state = 6;
486
+ this.stateInTagName(c);
487
+ }
488
+ /** Look for an end tag. For <title> and <textarea>, also decode entities. */
489
+ stateInRCDATA(c) {
490
+ if (this.sequenceIndex === this.currentSequence.length) {
491
+ if (c === 62 || isWhitespace(c)) {
492
+ const endOfText = this.index - this.currentSequence.length;
493
+ if (this.sectionStart < endOfText) {
494
+ const actualIndex = this.index;
495
+ this.index = endOfText;
496
+ this.cbs.ontext(this.sectionStart, endOfText);
497
+ this.index = actualIndex;
498
+ }
499
+ this.sectionStart = endOfText + 2;
500
+ this.stateInClosingTagName(c);
501
+ this.inRCDATA = false;
502
+ return;
503
+ }
504
+ this.sequenceIndex = 0;
505
+ }
506
+ if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
507
+ this.sequenceIndex += 1;
508
+ } else if (this.sequenceIndex === 0) {
509
+ if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
510
+ if (c === 38) {
511
+ this.startEntity();
512
+ } else if (c === this.delimiterOpen[0]) {
513
+ this.state = 2;
514
+ this.delimiterIndex = 0;
515
+ this.stateInterpolationOpen(c);
516
+ }
517
+ } else if (this.fastForwardTo(60)) {
518
+ this.sequenceIndex = 1;
519
+ }
520
+ } else {
521
+ this.sequenceIndex = Number(c === 60);
522
+ }
523
+ }
524
+ stateCDATASequence(c) {
525
+ if (c === Sequences.Cdata[this.sequenceIndex]) {
526
+ if (++this.sequenceIndex === Sequences.Cdata.length) {
527
+ this.state = 28;
528
+ this.currentSequence = Sequences.CdataEnd;
529
+ this.sequenceIndex = 0;
530
+ this.sectionStart = this.index + 1;
531
+ }
532
+ } else {
533
+ this.sequenceIndex = 0;
534
+ this.state = 23;
535
+ this.stateInDeclaration(c);
536
+ }
537
+ }
538
+ /**
539
+ * When we wait for one specific character, we can speed things up
540
+ * by skipping through the buffer until we find it.
541
+ *
542
+ * @returns Whether the character was found.
543
+ */
544
+ fastForwardTo(c) {
545
+ while (++this.index < this.buffer.length) {
546
+ const cc = this.buffer.charCodeAt(this.index);
547
+ if (cc === 10) {
548
+ this.newlines.push(this.index);
549
+ }
550
+ if (cc === c) {
551
+ return true;
552
+ }
553
+ }
554
+ this.index = this.buffer.length - 1;
555
+ return false;
556
+ }
557
+ /**
558
+ * Comments and CDATA end with `-->` and `]]>`.
559
+ *
560
+ * Their common qualities are:
561
+ * - Their end sequences have a distinct character they start with.
562
+ * - That character is then repeated, so we have to check multiple repeats.
563
+ * - All characters but the start character of the sequence can be skipped.
564
+ */
565
+ stateInCommentLike(c) {
566
+ if (c === this.currentSequence[this.sequenceIndex]) {
567
+ if (++this.sequenceIndex === this.currentSequence.length) {
568
+ if (this.currentSequence === Sequences.CdataEnd) {
569
+ this.cbs.oncdata(this.sectionStart, this.index - 2);
570
+ } else {
571
+ this.cbs.oncomment(this.sectionStart, this.index - 2);
572
+ }
573
+ this.sequenceIndex = 0;
574
+ this.sectionStart = this.index + 1;
575
+ this.state = 1;
576
+ }
577
+ } else if (this.sequenceIndex === 0) {
578
+ if (this.fastForwardTo(this.currentSequence[0])) {
579
+ this.sequenceIndex = 1;
580
+ }
581
+ } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
582
+ this.sequenceIndex = 0;
583
+ }
584
+ }
585
+ startSpecial(sequence, offset) {
586
+ this.enterRCDATA(sequence, offset);
587
+ this.state = 31;
588
+ }
589
+ enterRCDATA(sequence, offset) {
590
+ this.inRCDATA = true;
591
+ this.currentSequence = sequence;
592
+ this.sequenceIndex = offset;
593
+ }
594
+ stateBeforeTagName(c) {
595
+ if (c === 33) {
596
+ this.state = 22;
597
+ this.sectionStart = this.index + 1;
598
+ } else if (c === 63) {
599
+ this.state = 24;
600
+ this.sectionStart = this.index + 1;
601
+ } else if (isTagStartChar(c)) {
602
+ this.sectionStart = this.index;
603
+ if (this.mode === 0) {
604
+ this.state = 6;
605
+ } else if (this.inSFCRoot) {
606
+ this.state = 34;
607
+ } else if (!this.inXML) {
608
+ const lower = c | 32;
609
+ if (lower === 116) {
610
+ this.state = 30;
611
+ } else {
612
+ this.state = lower === 115 ? 29 : 6;
613
+ }
614
+ } else {
615
+ this.state = 6;
616
+ }
617
+ } else if (c === 47) {
618
+ this.state = 8;
619
+ } else {
620
+ this.state = 1;
621
+ this.stateText(c);
622
+ }
623
+ }
624
+ stateInTagName(c) {
625
+ if (isEndOfTagSection(c)) {
626
+ this.handleTagName(c);
627
+ }
628
+ }
629
+ stateInSFCRootTagName(c) {
630
+ if (isEndOfTagSection(c)) {
631
+ const tag = this.buffer.slice(this.sectionStart, this.index);
632
+ if (tag !== "template") {
633
+ this.enterRCDATA(toCharCodes(`</` + tag), 0);
634
+ }
635
+ this.handleTagName(c);
636
+ }
637
+ }
638
+ handleTagName(c) {
639
+ this.cbs.onopentagname(this.sectionStart, this.index);
640
+ this.sectionStart = -1;
641
+ this.state = 11;
642
+ this.stateBeforeAttrName(c);
643
+ }
644
+ stateBeforeClosingTagName(c) {
645
+ if (isWhitespace(c)) ; else if (c === 62) {
646
+ {
647
+ this.cbs.onerr(14, this.index);
648
+ }
649
+ this.state = 1;
650
+ this.sectionStart = this.index + 1;
651
+ } else {
652
+ this.state = isTagStartChar(c) ? 9 : 27;
653
+ this.sectionStart = this.index;
654
+ }
655
+ }
656
+ stateInClosingTagName(c) {
657
+ if (c === 62 || isWhitespace(c)) {
658
+ this.cbs.onclosetag(this.sectionStart, this.index);
659
+ this.sectionStart = -1;
660
+ this.state = 10;
661
+ this.stateAfterClosingTagName(c);
662
+ }
663
+ }
664
+ stateAfterClosingTagName(c) {
665
+ if (c === 62) {
666
+ this.state = 1;
667
+ this.sectionStart = this.index + 1;
668
+ }
669
+ }
670
+ stateBeforeAttrName(c) {
671
+ if (c === 62) {
672
+ this.cbs.onopentagend(this.index);
673
+ if (this.inRCDATA) {
674
+ this.state = 32;
675
+ } else {
676
+ this.state = 1;
677
+ }
678
+ this.sectionStart = this.index + 1;
679
+ } else if (c === 47) {
680
+ this.state = 7;
681
+ if (this.peek() !== 62) {
682
+ this.cbs.onerr(22, this.index);
683
+ }
684
+ } else if (c === 60 && this.peek() === 47) {
685
+ this.cbs.onopentagend(this.index);
686
+ this.state = 5;
687
+ this.sectionStart = this.index;
688
+ } else if (!isWhitespace(c)) {
689
+ if (c === 61) {
690
+ this.cbs.onerr(
691
+ 19,
692
+ this.index
693
+ );
694
+ }
695
+ this.handleAttrStart(c);
696
+ }
697
+ }
698
+ handleAttrStart(c) {
699
+ if (c === 118 && this.peek() === 45) {
700
+ this.state = 13;
701
+ this.sectionStart = this.index;
702
+ } else if (c === 46 || c === 58 || c === 64 || c === 35) {
703
+ this.cbs.ondirname(this.index, this.index + 1);
704
+ this.state = 14;
705
+ this.sectionStart = this.index + 1;
706
+ } else {
707
+ this.state = 12;
708
+ this.sectionStart = this.index;
709
+ }
710
+ }
711
+ stateInSelfClosingTag(c) {
712
+ if (c === 62) {
713
+ this.cbs.onselfclosingtag(this.index);
714
+ this.state = 1;
715
+ this.sectionStart = this.index + 1;
716
+ this.inRCDATA = false;
717
+ } else if (!isWhitespace(c)) {
718
+ this.state = 11;
719
+ this.stateBeforeAttrName(c);
720
+ }
721
+ }
722
+ stateInAttrName(c) {
723
+ if (c === 61 || isEndOfTagSection(c)) {
724
+ this.cbs.onattribname(this.sectionStart, this.index);
725
+ this.handleAttrNameEnd(c);
726
+ } else if (c === 34 || c === 39 || c === 60) {
727
+ this.cbs.onerr(
728
+ 17,
729
+ this.index
730
+ );
731
+ }
732
+ }
733
+ stateInDirName(c) {
734
+ if (c === 61 || isEndOfTagSection(c)) {
735
+ this.cbs.ondirname(this.sectionStart, this.index);
736
+ this.handleAttrNameEnd(c);
737
+ } else if (c === 58) {
738
+ this.cbs.ondirname(this.sectionStart, this.index);
739
+ this.state = 14;
740
+ this.sectionStart = this.index + 1;
741
+ } else if (c === 46) {
742
+ this.cbs.ondirname(this.sectionStart, this.index);
743
+ this.state = 16;
744
+ this.sectionStart = this.index + 1;
745
+ }
746
+ }
747
+ stateInDirArg(c) {
748
+ if (c === 61 || isEndOfTagSection(c)) {
749
+ this.cbs.ondirarg(this.sectionStart, this.index);
750
+ this.handleAttrNameEnd(c);
751
+ } else if (c === 91) {
752
+ this.state = 15;
753
+ } else if (c === 46) {
754
+ this.cbs.ondirarg(this.sectionStart, this.index);
755
+ this.state = 16;
756
+ this.sectionStart = this.index + 1;
757
+ }
758
+ }
759
+ stateInDynamicDirArg(c) {
760
+ if (c === 93) {
761
+ this.state = 14;
762
+ } else if (c === 61 || isEndOfTagSection(c)) {
763
+ this.cbs.ondirarg(this.sectionStart, this.index + 1);
764
+ this.handleAttrNameEnd(c);
765
+ {
766
+ this.cbs.onerr(
767
+ 27,
768
+ this.index
769
+ );
770
+ }
771
+ }
772
+ }
773
+ stateInDirModifier(c) {
774
+ if (c === 61 || isEndOfTagSection(c)) {
775
+ this.cbs.ondirmodifier(this.sectionStart, this.index);
776
+ this.handleAttrNameEnd(c);
777
+ } else if (c === 46) {
778
+ this.cbs.ondirmodifier(this.sectionStart, this.index);
779
+ this.sectionStart = this.index + 1;
780
+ }
781
+ }
782
+ handleAttrNameEnd(c) {
783
+ this.sectionStart = this.index;
784
+ this.state = 17;
785
+ this.cbs.onattribnameend(this.index);
786
+ this.stateAfterAttrName(c);
787
+ }
788
+ stateAfterAttrName(c) {
789
+ if (c === 61) {
790
+ this.state = 18;
791
+ } else if (c === 47 || c === 62) {
792
+ this.cbs.onattribend(0, this.sectionStart);
793
+ this.sectionStart = -1;
794
+ this.state = 11;
795
+ this.stateBeforeAttrName(c);
796
+ } else if (!isWhitespace(c)) {
797
+ this.cbs.onattribend(0, this.sectionStart);
798
+ this.handleAttrStart(c);
799
+ }
800
+ }
801
+ stateBeforeAttrValue(c) {
802
+ if (c === 34) {
803
+ this.state = 19;
804
+ this.sectionStart = this.index + 1;
805
+ } else if (c === 39) {
806
+ this.state = 20;
807
+ this.sectionStart = this.index + 1;
808
+ } else if (!isWhitespace(c)) {
809
+ this.sectionStart = this.index;
810
+ this.state = 21;
811
+ this.stateInAttrValueNoQuotes(c);
812
+ }
813
+ }
814
+ handleInAttrValue(c, quote) {
815
+ if (c === quote || false) {
816
+ this.cbs.onattribdata(this.sectionStart, this.index);
817
+ this.sectionStart = -1;
818
+ this.cbs.onattribend(
819
+ quote === 34 ? 3 : 2,
820
+ this.index + 1
821
+ );
822
+ this.state = 11;
823
+ } else if (c === 38) {
824
+ this.startEntity();
825
+ }
826
+ }
827
+ stateInAttrValueDoubleQuotes(c) {
828
+ this.handleInAttrValue(c, 34);
829
+ }
830
+ stateInAttrValueSingleQuotes(c) {
831
+ this.handleInAttrValue(c, 39);
832
+ }
833
+ stateInAttrValueNoQuotes(c) {
834
+ if (isWhitespace(c) || c === 62) {
835
+ this.cbs.onattribdata(this.sectionStart, this.index);
836
+ this.sectionStart = -1;
837
+ this.cbs.onattribend(1, this.index);
838
+ this.state = 11;
839
+ this.stateBeforeAttrName(c);
840
+ } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
841
+ this.cbs.onerr(
842
+ 18,
843
+ this.index
844
+ );
845
+ } else if (c === 38) {
846
+ this.startEntity();
847
+ }
848
+ }
849
+ stateBeforeDeclaration(c) {
850
+ if (c === 91) {
851
+ this.state = 26;
852
+ this.sequenceIndex = 0;
853
+ } else {
854
+ this.state = c === 45 ? 25 : 23;
855
+ }
856
+ }
857
+ stateInDeclaration(c) {
858
+ if (c === 62 || this.fastForwardTo(62)) {
859
+ this.state = 1;
860
+ this.sectionStart = this.index + 1;
861
+ }
862
+ }
863
+ stateInProcessingInstruction(c) {
864
+ if (c === 62 || this.fastForwardTo(62)) {
865
+ this.cbs.onprocessinginstruction(this.sectionStart, this.index);
866
+ this.state = 1;
867
+ this.sectionStart = this.index + 1;
868
+ }
869
+ }
870
+ stateBeforeComment(c) {
871
+ if (c === 45) {
872
+ this.state = 28;
873
+ this.currentSequence = Sequences.CommentEnd;
874
+ this.sequenceIndex = 2;
875
+ this.sectionStart = this.index + 1;
876
+ } else {
877
+ this.state = 23;
878
+ }
879
+ }
880
+ stateInSpecialComment(c) {
881
+ if (c === 62 || this.fastForwardTo(62)) {
882
+ this.cbs.oncomment(this.sectionStart, this.index);
883
+ this.state = 1;
884
+ this.sectionStart = this.index + 1;
885
+ }
886
+ }
887
+ stateBeforeSpecialS(c) {
888
+ const lower = c | 32;
889
+ if (lower === Sequences.ScriptEnd[3]) {
890
+ this.startSpecial(Sequences.ScriptEnd, 4);
891
+ } else if (lower === Sequences.StyleEnd[3]) {
892
+ this.startSpecial(Sequences.StyleEnd, 4);
893
+ } else {
894
+ this.state = 6;
895
+ this.stateInTagName(c);
896
+ }
897
+ }
898
+ stateBeforeSpecialT(c) {
899
+ const lower = c | 32;
900
+ if (lower === Sequences.TitleEnd[3]) {
901
+ this.startSpecial(Sequences.TitleEnd, 4);
902
+ } else if (lower === Sequences.TextareaEnd[3]) {
903
+ this.startSpecial(Sequences.TextareaEnd, 4);
904
+ } else {
905
+ this.state = 6;
906
+ this.stateInTagName(c);
907
+ }
908
+ }
909
+ startEntity() {
910
+ {
911
+ this.baseState = this.state;
912
+ this.state = 33;
913
+ this.entityStart = this.index;
914
+ this.entityDecoder.startEntity(
915
+ this.baseState === 1 || this.baseState === 32 ? decode_js.DecodingMode.Legacy : decode_js.DecodingMode.Attribute
916
+ );
917
+ }
918
+ }
919
+ stateInEntity() {
920
+ {
921
+ const length = this.entityDecoder.write(this.buffer, this.index);
922
+ if (length >= 0) {
923
+ this.state = this.baseState;
924
+ if (length === 0) {
925
+ this.index = this.entityStart;
926
+ }
927
+ } else {
928
+ this.index = this.buffer.length - 1;
929
+ }
930
+ }
931
+ }
932
+ /**
933
+ * Iterates through the buffer, calling the function corresponding to the current state.
934
+ *
935
+ * States that are more likely to be hit are higher up, as a performance improvement.
936
+ */
937
+ parse(input) {
938
+ this.buffer = input;
939
+ while (this.index < this.buffer.length) {
940
+ const c = this.buffer.charCodeAt(this.index);
941
+ if (c === 10) {
942
+ this.newlines.push(this.index);
943
+ }
944
+ switch (this.state) {
945
+ case 1: {
946
+ this.stateText(c);
947
+ break;
948
+ }
949
+ case 2: {
950
+ this.stateInterpolationOpen(c);
951
+ break;
952
+ }
953
+ case 3: {
954
+ this.stateInterpolation(c);
955
+ break;
956
+ }
957
+ case 4: {
958
+ this.stateInterpolationClose(c);
959
+ break;
960
+ }
961
+ case 31: {
962
+ this.stateSpecialStartSequence(c);
963
+ break;
964
+ }
965
+ case 32: {
966
+ this.stateInRCDATA(c);
967
+ break;
968
+ }
969
+ case 26: {
970
+ this.stateCDATASequence(c);
971
+ break;
972
+ }
973
+ case 19: {
974
+ this.stateInAttrValueDoubleQuotes(c);
975
+ break;
976
+ }
977
+ case 12: {
978
+ this.stateInAttrName(c);
979
+ break;
980
+ }
981
+ case 13: {
982
+ this.stateInDirName(c);
983
+ break;
984
+ }
985
+ case 14: {
986
+ this.stateInDirArg(c);
987
+ break;
988
+ }
989
+ case 15: {
990
+ this.stateInDynamicDirArg(c);
991
+ break;
992
+ }
993
+ case 16: {
994
+ this.stateInDirModifier(c);
995
+ break;
996
+ }
997
+ case 28: {
998
+ this.stateInCommentLike(c);
999
+ break;
1000
+ }
1001
+ case 27: {
1002
+ this.stateInSpecialComment(c);
1003
+ break;
1004
+ }
1005
+ case 11: {
1006
+ this.stateBeforeAttrName(c);
1007
+ break;
1008
+ }
1009
+ case 6: {
1010
+ this.stateInTagName(c);
1011
+ break;
1012
+ }
1013
+ case 34: {
1014
+ this.stateInSFCRootTagName(c);
1015
+ break;
1016
+ }
1017
+ case 9: {
1018
+ this.stateInClosingTagName(c);
1019
+ break;
1020
+ }
1021
+ case 5: {
1022
+ this.stateBeforeTagName(c);
1023
+ break;
1024
+ }
1025
+ case 17: {
1026
+ this.stateAfterAttrName(c);
1027
+ break;
1028
+ }
1029
+ case 20: {
1030
+ this.stateInAttrValueSingleQuotes(c);
1031
+ break;
1032
+ }
1033
+ case 18: {
1034
+ this.stateBeforeAttrValue(c);
1035
+ break;
1036
+ }
1037
+ case 8: {
1038
+ this.stateBeforeClosingTagName(c);
1039
+ break;
1040
+ }
1041
+ case 10: {
1042
+ this.stateAfterClosingTagName(c);
1043
+ break;
1044
+ }
1045
+ case 29: {
1046
+ this.stateBeforeSpecialS(c);
1047
+ break;
1048
+ }
1049
+ case 30: {
1050
+ this.stateBeforeSpecialT(c);
1051
+ break;
1052
+ }
1053
+ case 21: {
1054
+ this.stateInAttrValueNoQuotes(c);
1055
+ break;
1056
+ }
1057
+ case 7: {
1058
+ this.stateInSelfClosingTag(c);
1059
+ break;
1060
+ }
1061
+ case 23: {
1062
+ this.stateInDeclaration(c);
1063
+ break;
1064
+ }
1065
+ case 22: {
1066
+ this.stateBeforeDeclaration(c);
1067
+ break;
1068
+ }
1069
+ case 25: {
1070
+ this.stateBeforeComment(c);
1071
+ break;
1072
+ }
1073
+ case 24: {
1074
+ this.stateInProcessingInstruction(c);
1075
+ break;
1076
+ }
1077
+ case 33: {
1078
+ this.stateInEntity();
1079
+ break;
1080
+ }
1081
+ }
1082
+ this.index++;
1083
+ }
1084
+ this.cleanup();
1085
+ this.finish();
1086
+ }
1087
+ /**
1088
+ * Remove data that has already been consumed from the buffer.
1089
+ */
1090
+ cleanup() {
1091
+ if (this.sectionStart !== this.index) {
1092
+ if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
1093
+ this.cbs.ontext(this.sectionStart, this.index);
1094
+ this.sectionStart = this.index;
1095
+ } else if (this.state === 19 || this.state === 20 || this.state === 21) {
1096
+ this.cbs.onattribdata(this.sectionStart, this.index);
1097
+ this.sectionStart = this.index;
1098
+ }
1099
+ }
1100
+ }
1101
+ finish() {
1102
+ if (this.state === 33) {
1103
+ this.entityDecoder.end();
1104
+ this.state = this.baseState;
1105
+ }
1106
+ this.handleTrailingData();
1107
+ this.cbs.onend();
1108
+ }
1109
+ /** Handle any trailing data. */
1110
+ handleTrailingData() {
1111
+ const endIndex = this.buffer.length;
1112
+ if (this.sectionStart >= endIndex) {
1113
+ return;
1114
+ }
1115
+ if (this.state === 28) {
1116
+ if (this.currentSequence === Sequences.CdataEnd) {
1117
+ this.cbs.oncdata(this.sectionStart, endIndex);
1118
+ } else {
1119
+ this.cbs.oncomment(this.sectionStart, endIndex);
1120
+ }
1121
+ } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
1122
+ this.cbs.ontext(this.sectionStart, endIndex);
1123
+ }
1124
+ }
1125
+ emitCodePoint(cp, consumed) {
1126
+ {
1127
+ if (this.baseState !== 1 && this.baseState !== 32) {
1128
+ if (this.sectionStart < this.entityStart) {
1129
+ this.cbs.onattribdata(this.sectionStart, this.entityStart);
1130
+ }
1131
+ this.sectionStart = this.entityStart + consumed;
1132
+ this.index = this.sectionStart - 1;
1133
+ this.cbs.onattribentity(
1134
+ decode_js.fromCodePoint(cp),
1135
+ this.entityStart,
1136
+ this.sectionStart
1137
+ );
1138
+ } else {
1139
+ if (this.sectionStart < this.entityStart) {
1140
+ this.cbs.ontext(this.sectionStart, this.entityStart);
1141
+ }
1142
+ this.sectionStart = this.entityStart + consumed;
1143
+ this.index = this.sectionStart - 1;
1144
+ this.cbs.ontextentity(
1145
+ decode_js.fromCodePoint(cp),
1146
+ this.entityStart,
1147
+ this.sectionStart
1148
+ );
1149
+ }
1150
+ }
1151
+ }
1152
+ }
1153
+
1154
+ const deprecationData = {
1155
+ ["COMPILER_IS_ON_ELEMENT"]: {
1156
+ message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
1157
+ link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
1158
+ },
1159
+ ["COMPILER_V_BIND_SYNC"]: {
1160
+ message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
1161
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
1162
+ },
1163
+ ["COMPILER_V_BIND_OBJECT_ORDER"]: {
1164
+ message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
1165
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
1166
+ },
1167
+ ["COMPILER_V_ON_NATIVE"]: {
1168
+ message: `.native modifier for v-on has been removed as is no longer necessary.`,
1169
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
1170
+ },
1171
+ ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
1172
+ message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
1173
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
1174
+ },
1175
+ ["COMPILER_NATIVE_TEMPLATE"]: {
1176
+ message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
1177
+ },
1178
+ ["COMPILER_INLINE_TEMPLATE"]: {
1179
+ message: `"inline-template" has been removed in Vue 3.`,
1180
+ link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
1181
+ },
1182
+ ["COMPILER_FILTER"]: {
1183
+ message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
1184
+ link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
1185
+ }
1186
+ };
1187
+ function getCompatValue(key, { compatConfig }) {
1188
+ const value = compatConfig && compatConfig[key];
1189
+ if (key === "MODE") {
1190
+ return value || 3;
1191
+ } else {
1192
+ return value;
1193
+ }
1194
+ }
1195
+ function isCompatEnabled(key, context) {
1196
+ const mode = getCompatValue("MODE", context);
1197
+ const value = getCompatValue(key, context);
1198
+ return mode === 3 ? value === true : value !== false;
1199
+ }
1200
+ function checkCompatEnabled(key, context, loc, ...args) {
1201
+ const enabled = isCompatEnabled(key, context);
1202
+ if (enabled) {
1203
+ warnDeprecation(key, context, loc, ...args);
1204
+ }
1205
+ return enabled;
1206
+ }
1207
+ function warnDeprecation(key, context, loc, ...args) {
1208
+ const val = getCompatValue(key, context);
1209
+ if (val === "suppress-warning") {
1210
+ return;
1211
+ }
1212
+ const { message, link } = deprecationData[key];
1213
+ const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
1214
+ Details: ${link}` : ``}`;
1215
+ const err = new SyntaxError(msg);
1216
+ err.code = key;
1217
+ if (loc)
1218
+ err.loc = loc;
1219
+ context.onWarn(err);
1220
+ }
1221
+
1222
+ function defaultOnError(error) {
1223
+ throw error;
1224
+ }
1225
+ function defaultOnWarn(msg) {
1226
+ console.warn(`[Vue warn] ${msg.message}`);
1227
+ }
1228
+ function createCompilerError(code, loc, messages, additionalMessage) {
1229
+ const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
1230
+ const error = new SyntaxError(String(msg));
1231
+ error.code = code;
1232
+ error.loc = loc;
1233
+ return error;
1234
+ }
1235
+ const errorMessages = {
1236
+ // parse errors
1237
+ [0]: "Illegal comment.",
1238
+ [1]: "CDATA section is allowed only in XML context.",
1239
+ [2]: "Duplicate attribute.",
1240
+ [3]: "End tag cannot have attributes.",
1241
+ [4]: "Illegal '/' in tags.",
1242
+ [5]: "Unexpected EOF in tag.",
1243
+ [6]: "Unexpected EOF in CDATA section.",
1244
+ [7]: "Unexpected EOF in comment.",
1245
+ [8]: "Unexpected EOF in script.",
1246
+ [9]: "Unexpected EOF in tag.",
1247
+ [10]: "Incorrectly closed comment.",
1248
+ [11]: "Incorrectly opened comment.",
1249
+ [12]: "Illegal tag name. Use '&lt;' to print '<'.",
1250
+ [13]: "Attribute value was expected.",
1251
+ [14]: "End tag name was expected.",
1252
+ [15]: "Whitespace was expected.",
1253
+ [16]: "Unexpected '<!--' in comment.",
1254
+ [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
1255
+ [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
1256
+ [19]: "Attribute name cannot start with '='.",
1257
+ [21]: "'<?' is allowed only in XML context.",
1258
+ [20]: `Unexpected null character.`,
1259
+ [22]: "Illegal '/' in tags.",
1260
+ // Vue-specific parse errors
1261
+ [23]: "Invalid end tag.",
1262
+ [24]: "Element is missing end tag.",
1263
+ [25]: "Interpolation end sign was not found.",
1264
+ [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
1265
+ [26]: "Legal directive name was expected.",
1266
+ // transform errors
1267
+ [28]: `v-if/v-else-if is missing expression.`,
1268
+ [29]: `v-if/else branches must use unique keys.`,
1269
+ [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
1270
+ [31]: `v-for is missing expression.`,
1271
+ [32]: `v-for has invalid expression.`,
1272
+ [33]: `<template v-for> key should be placed on the <template> tag.`,
1273
+ [34]: `v-bind is missing expression.`,
1274
+ [35]: `v-on is missing expression.`,
1275
+ [36]: `Unexpected custom directive on <slot> outlet.`,
1276
+ [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
1277
+ [38]: `Duplicate slot names found. `,
1278
+ [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
1279
+ [40]: `v-slot can only be used on components or <template> tags.`,
1280
+ [41]: `v-model is missing expression.`,
1281
+ [42]: `v-model value must be a valid JavaScript member expression.`,
1282
+ [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
1283
+ [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
1284
+ Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1285
+ [45]: `Error parsing JavaScript expression: `,
1286
+ [46]: `<KeepAlive> expects exactly one child component.`,
1287
+ // generic errors
1288
+ [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1289
+ [48]: `ES module mode is not supported in this build of compiler.`,
1290
+ [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1291
+ [50]: `"scopeId" option is only supported in module mode.`,
1292
+ // deprecations
1293
+ [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
1294
+ [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
1295
+ // just to fulfill types
1296
+ [53]: ``
1297
+ };
1298
+
363
1299
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
364
- const isBuiltInType = (tag, expected) => tag === expected || tag === shared.hyphenate(expected);
365
1300
  function isCoreComponent(tag) {
366
- if (isBuiltInType(tag, "Teleport")) {
367
- return TELEPORT;
368
- } else if (isBuiltInType(tag, "Suspense")) {
369
- return SUSPENSE;
370
- } else if (isBuiltInType(tag, "KeepAlive")) {
371
- return KEEP_ALIVE;
372
- } else if (isBuiltInType(tag, "BaseTransition")) {
373
- return BASE_TRANSITION;
1301
+ switch (tag) {
1302
+ case "Teleport":
1303
+ case "teleport":
1304
+ return TELEPORT;
1305
+ case "Suspense":
1306
+ case "suspense":
1307
+ return SUSPENSE;
1308
+ case "KeepAlive":
1309
+ case "keep-alive":
1310
+ return KEEP_ALIVE;
1311
+ case "BaseTransition":
1312
+ case "base-transition":
1313
+ return BASE_TRANSITION;
374
1314
  }
375
1315
  }
376
1316
  const nonIdentifierRE = /^\d|[^\$\w]/;
@@ -454,25 +1394,13 @@ const isMemberExpressionNode = (path, context) => {
454
1394
  }
455
1395
  };
456
1396
  const isMemberExpression = isMemberExpressionNode;
457
- function getInnerRange(loc, offset, length) {
458
- const source = loc.source.slice(offset, offset + length);
459
- const newLoc = {
460
- source,
461
- start: advancePositionWithClone(loc.start, loc.source, offset),
462
- end: loc.end
463
- };
464
- if (length != null) {
465
- newLoc.end = advancePositionWithClone(
466
- loc.start,
467
- loc.source,
468
- offset + length
469
- );
470
- }
471
- return newLoc;
472
- }
473
1397
  function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
474
1398
  return advancePositionWithMutation(
475
- shared.extend({}, pos),
1399
+ {
1400
+ offset: pos.offset,
1401
+ line: pos.line,
1402
+ column: pos.column
1403
+ },
476
1404
  source,
477
1405
  numberOfCharacters
478
1406
  );
@@ -673,471 +1601,549 @@ function getMemoedVNodeCall(node) {
673
1601
  return node;
674
1602
  }
675
1603
  }
1604
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
676
1605
 
677
- const deprecationData = {
678
- ["COMPILER_IS_ON_ELEMENT"]: {
679
- message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
680
- link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
681
- },
682
- ["COMPILER_V_BIND_SYNC"]: {
683
- message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
684
- link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
685
- },
686
- ["COMPILER_V_BIND_PROP"]: {
687
- message: `.prop modifier for v-bind has been removed and no longer necessary. Vue 3 will automatically set a binding as DOM property when appropriate.`
688
- },
689
- ["COMPILER_V_BIND_OBJECT_ORDER"]: {
690
- message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
691
- link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
692
- },
693
- ["COMPILER_V_ON_NATIVE"]: {
694
- message: `.native modifier for v-on has been removed as is no longer necessary.`,
695
- link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
696
- },
697
- ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
698
- message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
699
- link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
700
- },
701
- ["COMPILER_NATIVE_TEMPLATE"]: {
702
- message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
703
- },
704
- ["COMPILER_INLINE_TEMPLATE"]: {
705
- message: `"inline-template" has been removed in Vue 3.`,
706
- link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
707
- },
708
- ["COMPILER_FILTER"]: {
709
- message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
710
- link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
711
- }
712
- };
713
- function getCompatValue(key, context) {
714
- const config = context.options ? context.options.compatConfig : context.compatConfig;
715
- const value = config && config[key];
716
- if (key === "MODE") {
717
- return value || 3;
718
- } else {
719
- return value;
720
- }
721
- }
722
- function isCompatEnabled(key, context) {
723
- const mode = getCompatValue("MODE", context);
724
- const value = getCompatValue(key, context);
725
- return mode === 3 ? value === true : value !== false;
726
- }
727
- function checkCompatEnabled(key, context, loc, ...args) {
728
- const enabled = isCompatEnabled(key, context);
729
- if (enabled) {
730
- warnDeprecation(key, context, loc, ...args);
731
- }
732
- return enabled;
733
- }
734
- function warnDeprecation(key, context, loc, ...args) {
735
- const val = getCompatValue(key, context);
736
- if (val === "suppress-warning") {
737
- return;
738
- }
739
- const { message, link } = deprecationData[key];
740
- const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
741
- Details: ${link}` : ``}`;
742
- const err = new SyntaxError(msg);
743
- err.code = key;
744
- if (loc)
745
- err.loc = loc;
746
- context.onWarn(err);
747
- }
748
-
749
- const decodeRE = /&(gt|lt|amp|apos|quot);/g;
750
- const decodeMap = {
751
- gt: ">",
752
- lt: "<",
753
- amp: "&",
754
- apos: "'",
755
- quot: '"'
756
- };
757
1606
  const defaultParserOptions = {
1607
+ parseMode: "base",
1608
+ ns: 0,
758
1609
  delimiters: [`{{`, `}}`],
759
1610
  getNamespace: () => 0,
760
- getTextMode: () => 0,
761
1611
  isVoidTag: shared.NO,
762
1612
  isPreTag: shared.NO,
763
1613
  isCustomElement: shared.NO,
764
- decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
765
1614
  onError: defaultOnError,
766
1615
  onWarn: defaultOnWarn,
767
1616
  comments: true
768
1617
  };
769
- function baseParse(content, options = {}) {
770
- const context = createParserContext(content, options);
771
- const start = getCursor(context);
772
- return createRoot(
773
- parseChildren(context, 0, []),
774
- getSelection(context, start)
775
- );
776
- }
777
- function createParserContext(content, rawOptions) {
778
- const options = shared.extend({}, defaultParserOptions);
779
- let key;
780
- for (key in rawOptions) {
781
- options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
782
- }
783
- return {
784
- options,
785
- column: 1,
786
- line: 1,
787
- offset: 0,
788
- originalSource: content,
789
- source: content,
790
- inPre: false,
791
- inVPre: false,
792
- onWarn: options.onWarn
793
- };
794
- }
795
- function parseChildren(context, mode, ancestors) {
796
- const parent = last(ancestors);
797
- const ns = parent ? parent.ns : 0;
798
- const nodes = [];
799
- while (!isEnd(context, mode, ancestors)) {
800
- const s = context.source;
801
- let node = void 0;
802
- if (mode === 0 || mode === 1) {
803
- if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
804
- node = parseInterpolation(context, mode);
805
- } else if (mode === 0 && s[0] === "<") {
806
- if (s.length === 1) {
807
- emitError(context, 5, 1);
808
- } else if (s[1] === "!") {
809
- if (startsWith(s, "<!--")) {
810
- node = parseComment(context);
811
- } else if (startsWith(s, "<!DOCTYPE")) {
812
- node = parseBogusComment(context);
813
- } else if (startsWith(s, "<![CDATA[")) {
814
- if (ns !== 0) {
815
- node = parseCDATA(context, ancestors);
816
- } else {
817
- emitError(context, 1);
818
- node = parseBogusComment(context);
819
- }
820
- } else {
821
- emitError(context, 11);
822
- node = parseBogusComment(context);
1618
+ let currentOptions = defaultParserOptions;
1619
+ let currentRoot = null;
1620
+ let currentInput = "";
1621
+ let currentOpenTag = null;
1622
+ let currentProp = null;
1623
+ let currentAttrValue = "";
1624
+ let currentAttrStartIndex = -1;
1625
+ let currentAttrEndIndex = -1;
1626
+ let inPre = 0;
1627
+ let inVPre = false;
1628
+ let currentVPreBoundary = null;
1629
+ const stack = [];
1630
+ const tokenizer = new Tokenizer(stack, {
1631
+ onerr: emitError,
1632
+ ontext(start, end) {
1633
+ onText(getSlice(start, end), start, end);
1634
+ },
1635
+ ontextentity(char, start, end) {
1636
+ onText(char, start, end);
1637
+ },
1638
+ oninterpolation(start, end) {
1639
+ if (inVPre) {
1640
+ return onText(getSlice(start, end), start, end);
1641
+ }
1642
+ let innerStart = start + tokenizer.delimiterOpen.length;
1643
+ let innerEnd = end - tokenizer.delimiterClose.length;
1644
+ while (isWhitespace(currentInput.charCodeAt(innerStart))) {
1645
+ innerStart++;
1646
+ }
1647
+ while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
1648
+ innerEnd--;
1649
+ }
1650
+ let exp = getSlice(innerStart, innerEnd);
1651
+ if (exp.includes("&")) {
1652
+ {
1653
+ exp = decode_js.decodeHTML(exp);
1654
+ }
1655
+ }
1656
+ addNode({
1657
+ type: 5,
1658
+ content: createSimpleExpression(exp, false, getLoc(innerStart, innerEnd)),
1659
+ loc: getLoc(start, end)
1660
+ });
1661
+ },
1662
+ onopentagname(start, end) {
1663
+ const name = getSlice(start, end);
1664
+ currentOpenTag = {
1665
+ type: 1,
1666
+ tag: name,
1667
+ ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
1668
+ tagType: 0,
1669
+ // will be refined on tag close
1670
+ props: [],
1671
+ children: [],
1672
+ loc: getLoc(start - 1, end),
1673
+ codegenNode: void 0
1674
+ };
1675
+ if (tokenizer.inSFCRoot) {
1676
+ currentOpenTag.innerLoc = getLoc(
1677
+ end + fastForward(end) + 1,
1678
+ end
1679
+ );
1680
+ }
1681
+ },
1682
+ onopentagend(end) {
1683
+ endOpenTag(end);
1684
+ },
1685
+ onclosetag(start, end) {
1686
+ const name = getSlice(start, end);
1687
+ if (!currentOptions.isVoidTag(name)) {
1688
+ let found = false;
1689
+ for (let i = 0; i < stack.length; i++) {
1690
+ const e = stack[i];
1691
+ if (e.tag.toLowerCase() === name.toLowerCase()) {
1692
+ found = true;
1693
+ if (i > 0) {
1694
+ emitError(24, stack[0].loc.start.offset);
823
1695
  }
824
- } else if (s[1] === "/") {
825
- if (s.length === 2) {
826
- emitError(context, 5, 2);
827
- } else if (s[2] === ">") {
828
- emitError(context, 14, 2);
829
- advanceBy(context, 3);
830
- continue;
831
- } else if (/[a-z]/i.test(s[2])) {
832
- emitError(context, 23);
833
- parseTag(context, 1 /* End */, parent);
834
- continue;
835
- } else {
836
- emitError(
837
- context,
838
- 12,
839
- 2
840
- );
841
- node = parseBogusComment(context);
1696
+ for (let j = 0; j <= i; j++) {
1697
+ const el = stack.shift();
1698
+ onCloseTag(el, end, j < i);
842
1699
  }
843
- } else if (/[a-z]/i.test(s[1])) {
844
- node = parseElement(context, ancestors);
845
- if (isCompatEnabled(
846
- "COMPILER_NATIVE_TEMPLATE",
847
- context
848
- ) && node && node.tag === "template" && !node.props.some(
849
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
850
- )) {
851
- warnDeprecation(
852
- "COMPILER_NATIVE_TEMPLATE",
853
- context,
854
- node.loc
855
- );
856
- node = node.children;
1700
+ break;
1701
+ }
1702
+ }
1703
+ if (!found) {
1704
+ emitError(23, backTrack(start, 60));
1705
+ }
1706
+ }
1707
+ },
1708
+ onselfclosingtag(end) {
1709
+ var _a;
1710
+ const name = currentOpenTag.tag;
1711
+ currentOpenTag.isSelfClosing = true;
1712
+ endOpenTag(end);
1713
+ if (((_a = stack[0]) == null ? void 0 : _a.tag) === name) {
1714
+ onCloseTag(stack.shift(), end);
1715
+ }
1716
+ },
1717
+ onattribname(start, end) {
1718
+ currentProp = {
1719
+ type: 6,
1720
+ name: getSlice(start, end),
1721
+ nameLoc: getLoc(start, end),
1722
+ value: void 0,
1723
+ loc: getLoc(start)
1724
+ };
1725
+ },
1726
+ ondirname(start, end) {
1727
+ const raw = getSlice(start, end);
1728
+ const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
1729
+ if (!inVPre && name === "") {
1730
+ emitError(26, start);
1731
+ }
1732
+ if (inVPre || name === "") {
1733
+ currentProp = {
1734
+ type: 6,
1735
+ name: raw,
1736
+ nameLoc: getLoc(start, end),
1737
+ value: void 0,
1738
+ loc: getLoc(start)
1739
+ };
1740
+ } else {
1741
+ currentProp = {
1742
+ type: 7,
1743
+ name,
1744
+ rawName: raw,
1745
+ exp: void 0,
1746
+ arg: void 0,
1747
+ modifiers: raw === "." ? ["prop"] : [],
1748
+ loc: getLoc(start)
1749
+ };
1750
+ if (name === "pre") {
1751
+ inVPre = true;
1752
+ currentVPreBoundary = currentOpenTag;
1753
+ const props = currentOpenTag.props;
1754
+ for (let i = 0; i < props.length; i++) {
1755
+ if (props[i].type === 7) {
1756
+ props[i] = dirToAttr(props[i]);
857
1757
  }
858
- } else if (s[1] === "?") {
859
- emitError(
860
- context,
861
- 21,
862
- 1
863
- );
864
- node = parseBogusComment(context);
865
- } else {
866
- emitError(context, 12, 1);
867
1758
  }
868
1759
  }
869
1760
  }
870
- if (!node) {
871
- node = parseText(context, mode);
1761
+ },
1762
+ ondirarg(start, end) {
1763
+ if (start === end)
1764
+ return;
1765
+ const arg = getSlice(start, end);
1766
+ if (inVPre) {
1767
+ currentProp.name += arg;
1768
+ setLocEnd(currentProp.nameLoc, end);
1769
+ } else {
1770
+ const isStatic = arg[0] !== `[`;
1771
+ currentProp.arg = createSimpleExpression(
1772
+ isStatic ? arg : arg.slice(1, -1),
1773
+ isStatic,
1774
+ getLoc(start, end),
1775
+ isStatic ? 3 : 0
1776
+ );
872
1777
  }
873
- if (shared.isArray(node)) {
874
- for (let i = 0; i < node.length; i++) {
875
- pushNode(nodes, node[i]);
1778
+ },
1779
+ ondirmodifier(start, end) {
1780
+ const mod = getSlice(start, end);
1781
+ if (inVPre) {
1782
+ currentProp.name += "." + mod;
1783
+ setLocEnd(currentProp.nameLoc, end);
1784
+ } else if (currentProp.name === "slot") {
1785
+ const arg = currentProp.arg;
1786
+ if (arg) {
1787
+ arg.content += "." + mod;
1788
+ setLocEnd(arg.loc, end);
876
1789
  }
877
1790
  } else {
878
- pushNode(nodes, node);
1791
+ currentProp.modifiers.push(mod);
879
1792
  }
880
- }
881
- let removedWhitespace = false;
882
- if (mode !== 2 && mode !== 1) {
883
- const shouldCondense = context.options.whitespace !== "preserve";
884
- for (let i = 0; i < nodes.length; i++) {
885
- const node = nodes[i];
886
- if (node.type === 2) {
887
- if (!context.inPre) {
888
- if (!/[^\t\r\n\f ]/.test(node.content)) {
889
- const prev = nodes[i - 1];
890
- const next = nodes[i + 1];
891
- if (!prev || !next || shouldCondense && (prev.type === 3 && next.type === 3 || prev.type === 3 && next.type === 1 || prev.type === 1 && next.type === 3 || prev.type === 1 && next.type === 1 && /[\r\n]/.test(node.content))) {
892
- removedWhitespace = true;
893
- nodes[i] = null;
894
- } else {
895
- node.content = " ";
896
- }
897
- } else if (shouldCondense) {
898
- node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
1793
+ },
1794
+ onattribdata(start, end) {
1795
+ currentAttrValue += getSlice(start, end);
1796
+ if (currentAttrStartIndex < 0)
1797
+ currentAttrStartIndex = start;
1798
+ currentAttrEndIndex = end;
1799
+ },
1800
+ onattribentity(char, start, end) {
1801
+ currentAttrValue += char;
1802
+ if (currentAttrStartIndex < 0)
1803
+ currentAttrStartIndex = start;
1804
+ currentAttrEndIndex = end;
1805
+ },
1806
+ onattribnameend(end) {
1807
+ const start = currentProp.loc.start.offset;
1808
+ const name = getSlice(start, end);
1809
+ if (currentProp.type === 7) {
1810
+ currentProp.rawName = name;
1811
+ }
1812
+ if (currentOpenTag.props.some(
1813
+ (p) => (p.type === 7 ? p.rawName : p.name) === name
1814
+ )) {
1815
+ emitError(2, start);
1816
+ }
1817
+ },
1818
+ onattribend(quote, end) {
1819
+ if (currentOpenTag && currentProp) {
1820
+ setLocEnd(currentProp.loc, end);
1821
+ if (quote !== 0) {
1822
+ if (currentProp.type === 6) {
1823
+ if (currentProp.name === "class") {
1824
+ currentAttrValue = condense(currentAttrValue).trim();
1825
+ }
1826
+ if (quote === 1 && !currentAttrValue) {
1827
+ emitError(13, end);
1828
+ }
1829
+ currentProp.value = {
1830
+ type: 2,
1831
+ content: currentAttrValue,
1832
+ loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
1833
+ };
1834
+ if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
1835
+ tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
899
1836
  }
900
1837
  } else {
901
- node.content = node.content.replace(/\r\n/g, "\n");
1838
+ currentProp.exp = createSimpleExpression(
1839
+ currentAttrValue,
1840
+ false,
1841
+ getLoc(currentAttrStartIndex, currentAttrEndIndex)
1842
+ );
1843
+ if (currentProp.name === "for") {
1844
+ currentProp.forParseResult = parseForExpression(currentProp.exp);
1845
+ }
1846
+ let syncIndex = -1;
1847
+ if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
1848
+ "COMPILER_V_BIND_SYNC",
1849
+ currentOptions,
1850
+ currentProp.loc,
1851
+ currentProp.rawName
1852
+ )) {
1853
+ currentProp.name = "model";
1854
+ currentProp.modifiers.splice(syncIndex, 1);
1855
+ }
902
1856
  }
903
- } else if (node.type === 3 && !context.options.comments) {
904
- removedWhitespace = true;
905
- nodes[i] = null;
906
1857
  }
1858
+ if (currentProp.type !== 7 || currentProp.name !== "pre") {
1859
+ currentOpenTag.props.push(currentProp);
1860
+ }
1861
+ }
1862
+ currentAttrValue = "";
1863
+ currentAttrStartIndex = currentAttrEndIndex = -1;
1864
+ },
1865
+ oncomment(start, end) {
1866
+ if (currentOptions.comments) {
1867
+ addNode({
1868
+ type: 3,
1869
+ content: getSlice(start, end),
1870
+ loc: getLoc(start - 4, end + 3)
1871
+ });
907
1872
  }
908
- if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
909
- const first = nodes[0];
910
- if (first && first.type === 2) {
911
- first.content = first.content.replace(/^\r?\n/, "");
1873
+ },
1874
+ onend() {
1875
+ const end = currentInput.length;
1876
+ if (tokenizer.state !== 1) {
1877
+ switch (tokenizer.state) {
1878
+ case 5:
1879
+ case 8:
1880
+ emitError(5, end);
1881
+ break;
1882
+ case 3:
1883
+ case 4:
1884
+ emitError(
1885
+ 25,
1886
+ tokenizer.sectionStart
1887
+ );
1888
+ break;
1889
+ case 28:
1890
+ if (tokenizer.currentSequence === Sequences.CdataEnd) {
1891
+ emitError(6, end);
1892
+ } else {
1893
+ emitError(7, end);
1894
+ }
1895
+ break;
1896
+ case 6:
1897
+ case 7:
1898
+ case 9:
1899
+ case 11:
1900
+ case 12:
1901
+ case 13:
1902
+ case 14:
1903
+ case 15:
1904
+ case 16:
1905
+ case 17:
1906
+ case 18:
1907
+ case 19:
1908
+ case 20:
1909
+ case 21:
1910
+ emitError(9, end);
1911
+ break;
912
1912
  }
913
1913
  }
1914
+ for (let index = 0; index < stack.length; index++) {
1915
+ onCloseTag(stack[index], end - 1);
1916
+ emitError(24, stack[index].loc.start.offset);
1917
+ }
1918
+ },
1919
+ oncdata(start, end) {
1920
+ if (stack[0].ns !== 0) {
1921
+ onText(getSlice(start, end), start, end);
1922
+ } else {
1923
+ emitError(1, start - 9);
1924
+ }
1925
+ },
1926
+ onprocessinginstruction(start) {
1927
+ if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
1928
+ emitError(
1929
+ 21,
1930
+ start - 1
1931
+ );
1932
+ }
914
1933
  }
915
- return removedWhitespace ? nodes.filter(Boolean) : nodes;
1934
+ });
1935
+ const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
1936
+ const stripParensRE = /^\(|\)$/g;
1937
+ function parseForExpression(input) {
1938
+ const loc = input.loc;
1939
+ const exp = input.content;
1940
+ const inMatch = exp.match(forAliasRE);
1941
+ if (!inMatch)
1942
+ return;
1943
+ const [, LHS, RHS] = inMatch;
1944
+ const createAliasExpression = (content, offset) => {
1945
+ const start = loc.start.offset + offset;
1946
+ const end = start + content.length;
1947
+ return createSimpleExpression(content, false, getLoc(start, end));
1948
+ };
1949
+ const result = {
1950
+ source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
1951
+ value: void 0,
1952
+ key: void 0,
1953
+ index: void 0,
1954
+ finalized: false
1955
+ };
1956
+ let valueContent = LHS.trim().replace(stripParensRE, "").trim();
1957
+ const trimmedOffset = LHS.indexOf(valueContent);
1958
+ const iteratorMatch = valueContent.match(forIteratorRE);
1959
+ if (iteratorMatch) {
1960
+ valueContent = valueContent.replace(forIteratorRE, "").trim();
1961
+ const keyContent = iteratorMatch[1].trim();
1962
+ let keyOffset;
1963
+ if (keyContent) {
1964
+ keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
1965
+ result.key = createAliasExpression(keyContent, keyOffset);
1966
+ }
1967
+ if (iteratorMatch[2]) {
1968
+ const indexContent = iteratorMatch[2].trim();
1969
+ if (indexContent) {
1970
+ result.index = createAliasExpression(
1971
+ indexContent,
1972
+ exp.indexOf(
1973
+ indexContent,
1974
+ result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
1975
+ )
1976
+ );
1977
+ }
1978
+ }
1979
+ }
1980
+ if (valueContent) {
1981
+ result.value = createAliasExpression(valueContent, trimmedOffset);
1982
+ }
1983
+ return result;
916
1984
  }
917
- function pushNode(nodes, node) {
918
- if (node.type === 2) {
919
- const prev = last(nodes);
920
- if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
921
- prev.content += node.content;
922
- prev.loc.end = node.loc.end;
923
- prev.loc.source += node.loc.source;
924
- return;
1985
+ function getSlice(start, end) {
1986
+ return currentInput.slice(start, end);
1987
+ }
1988
+ function endOpenTag(end) {
1989
+ addNode(currentOpenTag);
1990
+ const { tag, ns } = currentOpenTag;
1991
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
1992
+ inPre++;
1993
+ }
1994
+ if (currentOptions.isVoidTag(tag)) {
1995
+ onCloseTag(currentOpenTag, end);
1996
+ } else {
1997
+ stack.unshift(currentOpenTag);
1998
+ if (ns === 1 || ns === 2) {
1999
+ tokenizer.inXML = true;
925
2000
  }
926
2001
  }
927
- nodes.push(node);
2002
+ currentOpenTag = null;
928
2003
  }
929
- function parseCDATA(context, ancestors) {
930
- advanceBy(context, 9);
931
- const nodes = parseChildren(context, 3, ancestors);
932
- if (context.source.length === 0) {
933
- emitError(context, 6);
2004
+ function onText(content, start, end) {
2005
+ const parent = stack[0] || currentRoot;
2006
+ const lastNode = parent.children[parent.children.length - 1];
2007
+ if ((lastNode == null ? void 0 : lastNode.type) === 2) {
2008
+ lastNode.content += content;
2009
+ setLocEnd(lastNode.loc, end);
934
2010
  } else {
935
- advanceBy(context, 3);
2011
+ parent.children.push({
2012
+ type: 2,
2013
+ content,
2014
+ loc: getLoc(start, end)
2015
+ });
936
2016
  }
937
- return nodes;
938
2017
  }
939
- function parseComment(context) {
940
- const start = getCursor(context);
941
- let content;
942
- const match = /--(\!)?>/.exec(context.source);
943
- if (!match) {
944
- content = context.source.slice(4);
945
- advanceBy(context, context.source.length);
946
- emitError(context, 7);
2018
+ function onCloseTag(el, end, isImplied = false) {
2019
+ if (isImplied) {
2020
+ setLocEnd(el.loc, backTrack(end, 60));
947
2021
  } else {
948
- if (match.index <= 3) {
949
- emitError(context, 0);
950
- }
951
- if (match[1]) {
952
- emitError(context, 10);
2022
+ setLocEnd(el.loc, end + fastForward(end) + 1);
2023
+ }
2024
+ if (tokenizer.inSFCRoot) {
2025
+ if (el.children.length) {
2026
+ el.innerLoc.end = shared.extend({}, el.children[el.children.length - 1].loc.end);
2027
+ } else {
2028
+ el.innerLoc.end = shared.extend({}, el.innerLoc.start);
953
2029
  }
954
- content = context.source.slice(4, match.index);
955
- const s = context.source.slice(0, match.index);
956
- let prevIndex = 1, nestedIndex = 0;
957
- while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
958
- advanceBy(context, nestedIndex - prevIndex + 1);
959
- if (nestedIndex + 4 < s.length) {
960
- emitError(context, 16);
961
- }
962
- prevIndex = nestedIndex + 1;
2030
+ el.innerLoc.source = getSlice(
2031
+ el.innerLoc.start.offset,
2032
+ el.innerLoc.end.offset
2033
+ );
2034
+ }
2035
+ const { tag, ns } = el;
2036
+ if (!inVPre) {
2037
+ if (tag === "slot") {
2038
+ el.tagType = 2;
2039
+ } else if (isFragmentTemplate(el)) {
2040
+ el.tagType = 3;
2041
+ } else if (isComponent(el)) {
2042
+ el.tagType = 1;
963
2043
  }
964
- advanceBy(context, match.index + match[0].length - prevIndex + 1);
965
2044
  }
966
- return {
967
- type: 3,
968
- content,
969
- loc: getSelection(context, start)
970
- };
971
- }
972
- function parseBogusComment(context) {
973
- const start = getCursor(context);
974
- const contentStart = context.source[1] === "?" ? 1 : 2;
975
- let content;
976
- const closeIndex = context.source.indexOf(">");
977
- if (closeIndex === -1) {
978
- content = context.source.slice(contentStart);
979
- advanceBy(context, context.source.length);
980
- } else {
981
- content = context.source.slice(contentStart, closeIndex);
982
- advanceBy(context, closeIndex + 1);
2045
+ if (!tokenizer.inRCDATA) {
2046
+ el.children = condenseWhitespace(el.children, el.tag);
2047
+ }
2048
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
2049
+ inPre--;
2050
+ }
2051
+ if (currentVPreBoundary === el) {
2052
+ inVPre = false;
2053
+ currentVPreBoundary = null;
2054
+ }
2055
+ if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2056
+ tokenizer.inXML = false;
983
2057
  }
984
- return {
985
- type: 3,
986
- content,
987
- loc: getSelection(context, start)
988
- };
989
- }
990
- function parseElement(context, ancestors) {
991
- const wasInPre = context.inPre;
992
- const wasInVPre = context.inVPre;
993
- const parent = last(ancestors);
994
- const element = parseTag(context, 0 /* Start */, parent);
995
- const isPreBoundary = context.inPre && !wasInPre;
996
- const isVPreBoundary = context.inVPre && !wasInVPre;
997
- if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
998
- if (isPreBoundary) {
999
- context.inPre = false;
1000
- }
1001
- if (isVPreBoundary) {
1002
- context.inVPre = false;
1003
- }
1004
- return element;
1005
- }
1006
- ancestors.push(element);
1007
- const mode = context.options.getTextMode(element, parent);
1008
- const children = parseChildren(context, mode, ancestors);
1009
- ancestors.pop();
1010
2058
  {
1011
- const inlineTemplateProp = element.props.find(
2059
+ const props = el.props;
2060
+ if (isCompatEnabled(
2061
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2062
+ currentOptions
2063
+ )) {
2064
+ let hasIf = false;
2065
+ let hasFor = false;
2066
+ for (let i = 0; i < props.length; i++) {
2067
+ const p = props[i];
2068
+ if (p.type === 7) {
2069
+ if (p.name === "if") {
2070
+ hasIf = true;
2071
+ } else if (p.name === "for") {
2072
+ hasFor = true;
2073
+ }
2074
+ }
2075
+ if (hasIf && hasFor) {
2076
+ warnDeprecation(
2077
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2078
+ currentOptions,
2079
+ el.loc
2080
+ );
2081
+ break;
2082
+ }
2083
+ }
2084
+ }
2085
+ if (isCompatEnabled(
2086
+ "COMPILER_NATIVE_TEMPLATE",
2087
+ currentOptions
2088
+ ) && el.tag === "template" && !isFragmentTemplate(el)) {
2089
+ warnDeprecation(
2090
+ "COMPILER_NATIVE_TEMPLATE",
2091
+ currentOptions,
2092
+ el.loc
2093
+ );
2094
+ const parent = stack[0] || currentRoot;
2095
+ const index = parent.children.indexOf(el);
2096
+ parent.children.splice(index, 1, ...el.children);
2097
+ }
2098
+ const inlineTemplateProp = props.find(
1012
2099
  (p) => p.type === 6 && p.name === "inline-template"
1013
2100
  );
1014
2101
  if (inlineTemplateProp && checkCompatEnabled(
1015
2102
  "COMPILER_INLINE_TEMPLATE",
1016
- context,
2103
+ currentOptions,
1017
2104
  inlineTemplateProp.loc
1018
- )) {
1019
- const loc = getSelection(context, element.loc.end);
2105
+ ) && el.children.length) {
1020
2106
  inlineTemplateProp.value = {
1021
2107
  type: 2,
1022
- content: loc.source,
1023
- loc
2108
+ content: getSlice(
2109
+ el.children[0].loc.start.offset,
2110
+ el.children[el.children.length - 1].loc.end.offset
2111
+ ),
2112
+ loc: inlineTemplateProp.loc
1024
2113
  };
1025
2114
  }
1026
2115
  }
1027
- element.children = children;
1028
- if (startsWithEndTagOpen(context.source, element.tag)) {
1029
- parseTag(context, 1 /* End */, parent);
1030
- } else {
1031
- emitError(context, 24, 0, element.loc.start);
1032
- if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
1033
- const first = children[0];
1034
- if (first && startsWith(first.loc.source, "<!--")) {
1035
- emitError(context, 8);
1036
- }
1037
- }
1038
- }
1039
- element.loc = getSelection(context, element.loc.start);
1040
- if (isPreBoundary) {
1041
- context.inPre = false;
1042
- }
1043
- if (isVPreBoundary) {
1044
- context.inVPre = false;
1045
- }
1046
- return element;
1047
2116
  }
1048
- const isSpecialTemplateDirective = /* @__PURE__ */ shared.makeMap(
1049
- `if,else,else-if,for,slot`
1050
- );
1051
- function parseTag(context, type, parent) {
1052
- const start = getCursor(context);
1053
- const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
1054
- const tag = match[1];
1055
- const ns = context.options.getNamespace(tag, parent);
1056
- advanceBy(context, match[0].length);
1057
- advanceSpaces(context);
1058
- const cursor = getCursor(context);
1059
- const currentSource = context.source;
1060
- if (context.options.isPreTag(tag)) {
1061
- context.inPre = true;
1062
- }
1063
- let props = parseAttributes(context, type);
1064
- if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
1065
- context.inVPre = true;
1066
- shared.extend(context, cursor);
1067
- context.source = currentSource;
1068
- props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
1069
- }
1070
- let isSelfClosing = false;
1071
- if (context.source.length === 0) {
1072
- emitError(context, 9);
1073
- } else {
1074
- isSelfClosing = startsWith(context.source, "/>");
1075
- if (type === 1 /* End */ && isSelfClosing) {
1076
- emitError(context, 4);
1077
- }
1078
- advanceBy(context, isSelfClosing ? 2 : 1);
2117
+ function fastForward(start, c) {
2118
+ let offset = 0;
2119
+ while (currentInput.charCodeAt(start + offset) !== 62 && start + offset < currentInput.length) {
2120
+ offset++;
1079
2121
  }
1080
- if (type === 1 /* End */) {
1081
- return;
1082
- }
1083
- if (isCompatEnabled(
1084
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1085
- context
1086
- )) {
1087
- let hasIf = false;
1088
- let hasFor = false;
2122
+ return offset;
2123
+ }
2124
+ function backTrack(index, c) {
2125
+ let i = index;
2126
+ while (currentInput.charCodeAt(i) !== c && i >= 0)
2127
+ i--;
2128
+ return i;
2129
+ }
2130
+ const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
2131
+ function isFragmentTemplate({ tag, props }) {
2132
+ if (tag === "template") {
1089
2133
  for (let i = 0; i < props.length; i++) {
1090
- const p = props[i];
1091
- if (p.type === 7) {
1092
- if (p.name === "if") {
1093
- hasIf = true;
1094
- } else if (p.name === "for") {
1095
- hasFor = true;
1096
- }
1097
- }
1098
- if (hasIf && hasFor) {
1099
- warnDeprecation(
1100
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1101
- context,
1102
- getSelection(context, start)
1103
- );
1104
- break;
1105
- }
1106
- }
1107
- }
1108
- let tagType = 0;
1109
- if (!context.inVPre) {
1110
- if (tag === "slot") {
1111
- tagType = 2;
1112
- } else if (tag === "template") {
1113
- if (props.some(
1114
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
1115
- )) {
1116
- tagType = 3;
2134
+ if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
2135
+ return true;
1117
2136
  }
1118
- } else if (isComponent(tag, props, context)) {
1119
- tagType = 1;
1120
2137
  }
1121
2138
  }
1122
- return {
1123
- type: 1,
1124
- ns,
1125
- tag,
1126
- tagType,
1127
- props,
1128
- isSelfClosing,
1129
- children: [],
1130
- loc: getSelection(context, start),
1131
- codegenNode: void 0
1132
- // to be created during transform phase
1133
- };
2139
+ return false;
1134
2140
  }
1135
- function isComponent(tag, props, context) {
1136
- const options = context.options;
1137
- if (options.isCustomElement(tag)) {
2141
+ function isComponent({ tag, props }) {
2142
+ var _a;
2143
+ if (currentOptions.isCustomElement(tag)) {
1138
2144
  return false;
1139
2145
  }
1140
- if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
2146
+ if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
1141
2147
  return true;
1142
2148
  }
1143
2149
  for (let i = 0; i < props.length; i++) {
@@ -1148,374 +2154,179 @@ function isComponent(tag, props, context) {
1148
2154
  return true;
1149
2155
  } else if (checkCompatEnabled(
1150
2156
  "COMPILER_IS_ON_ELEMENT",
1151
- context,
2157
+ currentOptions,
1152
2158
  p.loc
1153
2159
  )) {
1154
2160
  return true;
1155
2161
  }
1156
2162
  }
1157
- } else {
1158
- if (p.name === "is") {
1159
- return true;
1160
- } else if (
1161
- // :is on plain element - only treat as component in compat mode
1162
- p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
1163
- "COMPILER_IS_ON_ELEMENT",
1164
- context,
1165
- p.loc
1166
- )
1167
- ) {
1168
- return true;
1169
- }
2163
+ } else if (// :is on plain element - only treat as component in compat mode
2164
+ p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
2165
+ "COMPILER_IS_ON_ELEMENT",
2166
+ currentOptions,
2167
+ p.loc
2168
+ )) {
2169
+ return true;
1170
2170
  }
1171
2171
  }
2172
+ return false;
1172
2173
  }
1173
- function parseAttributes(context, type) {
1174
- const props = [];
1175
- const attributeNames = /* @__PURE__ */ new Set();
1176
- while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
1177
- if (startsWith(context.source, "/")) {
1178
- emitError(context, 22);
1179
- advanceBy(context, 1);
1180
- advanceSpaces(context);
1181
- continue;
1182
- }
1183
- if (type === 1 /* End */) {
1184
- emitError(context, 3);
1185
- }
1186
- const attr = parseAttribute(context, attributeNames);
1187
- if (attr.type === 6 && attr.value && attr.name === "class") {
1188
- attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
1189
- }
1190
- if (type === 0 /* Start */) {
1191
- props.push(attr);
1192
- }
1193
- if (/^[^\t\r\n\f />]/.test(context.source)) {
1194
- emitError(context, 15);
1195
- }
1196
- advanceSpaces(context);
1197
- }
1198
- return props;
2174
+ function isUpperCase(c) {
2175
+ return c > 64 && c < 91;
1199
2176
  }
1200
- function parseAttribute(context, nameSet) {
1201
- var _a;
1202
- const start = getCursor(context);
1203
- const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
1204
- const name = match[0];
1205
- if (nameSet.has(name)) {
1206
- emitError(context, 2);
1207
- }
1208
- nameSet.add(name);
1209
- if (name[0] === "=") {
1210
- emitError(context, 19);
1211
- }
1212
- {
1213
- const pattern = /["'<]/g;
1214
- let m;
1215
- while (m = pattern.exec(name)) {
1216
- emitError(
1217
- context,
1218
- 17,
1219
- m.index
1220
- );
1221
- }
1222
- }
1223
- advanceBy(context, name.length);
1224
- let value = void 0;
1225
- if (/^[\t\r\n\f ]*=/.test(context.source)) {
1226
- advanceSpaces(context);
1227
- advanceBy(context, 1);
1228
- advanceSpaces(context);
1229
- value = parseAttributeValue(context);
1230
- if (!value) {
1231
- emitError(context, 13);
1232
- }
1233
- }
1234
- const loc = getSelection(context, start);
1235
- if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
1236
- const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
1237
- name
1238
- );
1239
- let isPropShorthand = startsWith(name, ".");
1240
- let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
1241
- let arg;
1242
- if (match2[2]) {
1243
- const isSlot = dirName === "slot";
1244
- const startOffset = name.lastIndexOf(
1245
- match2[2],
1246
- name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
1247
- );
1248
- const loc2 = getSelection(
1249
- context,
1250
- getNewPosition(context, start, startOffset),
1251
- getNewPosition(
1252
- context,
1253
- start,
1254
- startOffset + match2[2].length + (isSlot && match2[3] || "").length
1255
- )
1256
- );
1257
- let content = match2[2];
1258
- let isStatic = true;
1259
- if (content.startsWith("[")) {
1260
- isStatic = false;
1261
- if (!content.endsWith("]")) {
1262
- emitError(
1263
- context,
1264
- 27
1265
- );
1266
- content = content.slice(1);
1267
- } else {
1268
- content = content.slice(1, content.length - 1);
2177
+ const windowsNewlineRE = /\r\n/g;
2178
+ function condenseWhitespace(nodes, tag) {
2179
+ var _a, _b;
2180
+ const shouldCondense = currentOptions.whitespace !== "preserve";
2181
+ let removedWhitespace = false;
2182
+ for (let i = 0; i < nodes.length; i++) {
2183
+ const node = nodes[i];
2184
+ if (node.type === 2) {
2185
+ if (!inPre) {
2186
+ if (isAllWhitespace(node.content)) {
2187
+ const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
2188
+ const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
2189
+ if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2190
+ removedWhitespace = true;
2191
+ nodes[i] = null;
2192
+ } else {
2193
+ node.content = " ";
2194
+ }
2195
+ } else if (shouldCondense) {
2196
+ node.content = condense(node.content);
1269
2197
  }
1270
- } else if (isSlot) {
1271
- content += match2[3] || "";
1272
- }
1273
- arg = {
1274
- type: 4,
1275
- content,
1276
- isStatic,
1277
- constType: isStatic ? 3 : 0,
1278
- loc: loc2
1279
- };
1280
- }
1281
- if (value && value.isQuoted) {
1282
- const valueLoc = value.loc;
1283
- valueLoc.start.offset++;
1284
- valueLoc.start.column++;
1285
- valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
1286
- valueLoc.source = valueLoc.source.slice(1, -1);
1287
- }
1288
- const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
1289
- if (isPropShorthand)
1290
- modifiers.push("prop");
1291
- if (dirName === "bind" && arg) {
1292
- if (modifiers.includes("sync") && checkCompatEnabled(
1293
- "COMPILER_V_BIND_SYNC",
1294
- context,
1295
- loc,
1296
- arg.loc.source
1297
- )) {
1298
- dirName = "model";
1299
- modifiers.splice(modifiers.indexOf("sync"), 1);
1300
- }
1301
- if (modifiers.includes("prop")) {
1302
- checkCompatEnabled(
1303
- "COMPILER_V_BIND_PROP",
1304
- context,
1305
- loc
1306
- );
2198
+ } else {
2199
+ node.content = node.content.replace(windowsNewlineRE, "\n");
1307
2200
  }
1308
2201
  }
1309
- return {
1310
- type: 7,
1311
- name: dirName,
1312
- exp: value && {
1313
- type: 4,
1314
- content: value.content,
1315
- isStatic: false,
1316
- // Treat as non-constant by default. This can be potentially set to
1317
- // other values by `transformExpression` to make it eligible for hoisting.
1318
- constType: 0,
1319
- loc: value.loc
1320
- },
1321
- arg,
1322
- modifiers,
1323
- loc
1324
- };
1325
2202
  }
1326
- if (!context.inVPre && startsWith(name, "v-")) {
1327
- emitError(context, 26);
2203
+ if (inPre && tag && currentOptions.isPreTag(tag)) {
2204
+ const first = nodes[0];
2205
+ if (first && first.type === 2) {
2206
+ first.content = first.content.replace(/^\r?\n/, "");
2207
+ }
1328
2208
  }
1329
- return {
1330
- type: 6,
1331
- name,
1332
- value: value && {
1333
- type: 2,
1334
- content: value.content,
1335
- loc: value.loc
1336
- },
1337
- loc
1338
- };
2209
+ return removedWhitespace ? nodes.filter(Boolean) : nodes;
1339
2210
  }
1340
- function parseAttributeValue(context) {
1341
- const start = getCursor(context);
1342
- let content;
1343
- const quote = context.source[0];
1344
- const isQuoted = quote === `"` || quote === `'`;
1345
- if (isQuoted) {
1346
- advanceBy(context, 1);
1347
- const endIndex = context.source.indexOf(quote);
1348
- if (endIndex === -1) {
1349
- content = parseTextData(
1350
- context,
1351
- context.source.length,
1352
- 4
1353
- );
1354
- } else {
1355
- content = parseTextData(context, endIndex, 4);
1356
- advanceBy(context, 1);
1357
- }
1358
- } else {
1359
- const match = /^[^\t\r\n\f >]+/.exec(context.source);
1360
- if (!match) {
1361
- return void 0;
1362
- }
1363
- const unexpectedChars = /["'<=`]/g;
1364
- let m;
1365
- while (m = unexpectedChars.exec(match[0])) {
1366
- emitError(
1367
- context,
1368
- 18,
1369
- m.index
1370
- );
2211
+ function isAllWhitespace(str) {
2212
+ for (let i = 0; i < str.length; i++) {
2213
+ if (!isWhitespace(str.charCodeAt(i))) {
2214
+ return false;
1371
2215
  }
1372
- content = parseTextData(context, match[0].length, 4);
1373
- }
1374
- return { content, isQuoted, loc: getSelection(context, start) };
1375
- }
1376
- function parseInterpolation(context, mode) {
1377
- const [open, close] = context.options.delimiters;
1378
- const closeIndex = context.source.indexOf(close, open.length);
1379
- if (closeIndex === -1) {
1380
- emitError(context, 25);
1381
- return void 0;
1382
- }
1383
- const start = getCursor(context);
1384
- advanceBy(context, open.length);
1385
- const innerStart = getCursor(context);
1386
- const innerEnd = getCursor(context);
1387
- const rawContentLength = closeIndex - open.length;
1388
- const rawContent = context.source.slice(0, rawContentLength);
1389
- const preTrimContent = parseTextData(context, rawContentLength, mode);
1390
- const content = preTrimContent.trim();
1391
- const startOffset = preTrimContent.indexOf(content);
1392
- if (startOffset > 0) {
1393
- advancePositionWithMutation(innerStart, rawContent, startOffset);
1394
- }
1395
- const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
1396
- advancePositionWithMutation(innerEnd, rawContent, endOffset);
1397
- advanceBy(context, close.length);
1398
- return {
1399
- type: 5,
1400
- content: {
1401
- type: 4,
1402
- isStatic: false,
1403
- // Set `isConstant` to false by default and will decide in transformExpression
1404
- constType: 0,
1405
- content,
1406
- loc: getSelection(context, innerStart, innerEnd)
1407
- },
1408
- loc: getSelection(context, start)
1409
- };
2216
+ }
2217
+ return true;
1410
2218
  }
1411
- function parseText(context, mode) {
1412
- const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
1413
- let endIndex = context.source.length;
1414
- for (let i = 0; i < endTokens.length; i++) {
1415
- const index = context.source.indexOf(endTokens[i], 1);
1416
- if (index !== -1 && endIndex > index) {
1417
- endIndex = index;
2219
+ function hasNewlineChar(str) {
2220
+ for (let i = 0; i < str.length; i++) {
2221
+ const c = str.charCodeAt(i);
2222
+ if (c === 10 || c === 13) {
2223
+ return true;
1418
2224
  }
1419
2225
  }
1420
- const start = getCursor(context);
1421
- const content = parseTextData(context, endIndex, mode);
1422
- return {
1423
- type: 2,
1424
- content,
1425
- loc: getSelection(context, start)
1426
- };
2226
+ return false;
1427
2227
  }
1428
- function parseTextData(context, length, mode) {
1429
- const rawText = context.source.slice(0, length);
1430
- advanceBy(context, length);
1431
- if (mode === 2 || mode === 3 || !rawText.includes("&")) {
1432
- return rawText;
1433
- } else {
1434
- return context.options.decodeEntities(
1435
- rawText,
1436
- mode === 4
1437
- );
2228
+ function condense(str) {
2229
+ let ret = "";
2230
+ let prevCharIsWhitespace = false;
2231
+ for (let i = 0; i < str.length; i++) {
2232
+ if (isWhitespace(str.charCodeAt(i))) {
2233
+ if (!prevCharIsWhitespace) {
2234
+ ret += " ";
2235
+ prevCharIsWhitespace = true;
2236
+ }
2237
+ } else {
2238
+ ret += str[i];
2239
+ prevCharIsWhitespace = false;
2240
+ }
1438
2241
  }
2242
+ return ret;
1439
2243
  }
1440
- function getCursor(context) {
1441
- const { column, line, offset } = context;
1442
- return { column, line, offset };
2244
+ function addNode(node) {
2245
+ (stack[0] || currentRoot).children.push(node);
1443
2246
  }
1444
- function getSelection(context, start, end) {
1445
- end = end || getCursor(context);
2247
+ function getLoc(start, end) {
1446
2248
  return {
1447
- start,
1448
- end,
1449
- source: context.originalSource.slice(start.offset, end.offset)
2249
+ start: tokenizer.getPos(start),
2250
+ // @ts-expect-error allow late attachment
2251
+ end: end == null ? end : tokenizer.getPos(end),
2252
+ // @ts-expect-error allow late attachment
2253
+ source: end == null ? end : getSlice(start, end)
1450
2254
  };
1451
2255
  }
1452
- function last(xs) {
1453
- return xs[xs.length - 1];
2256
+ function setLocEnd(loc, end) {
2257
+ loc.end = tokenizer.getPos(end);
2258
+ loc.source = getSlice(loc.start.offset, end);
1454
2259
  }
1455
- function startsWith(source, searchString) {
1456
- return source.startsWith(searchString);
1457
- }
1458
- function advanceBy(context, numberOfCharacters) {
1459
- const { source } = context;
1460
- advancePositionWithMutation(context, source, numberOfCharacters);
1461
- context.source = source.slice(numberOfCharacters);
1462
- }
1463
- function advanceSpaces(context) {
1464
- const match = /^[\t\r\n\f ]+/.exec(context.source);
1465
- if (match) {
1466
- advanceBy(context, match[0].length);
2260
+ function dirToAttr(dir) {
2261
+ const attr = {
2262
+ type: 6,
2263
+ name: dir.rawName,
2264
+ nameLoc: getLoc(
2265
+ dir.loc.start.offset,
2266
+ dir.loc.start.offset + dir.rawName.length
2267
+ ),
2268
+ value: void 0,
2269
+ loc: dir.loc
2270
+ };
2271
+ if (dir.exp) {
2272
+ const loc = dir.exp.loc;
2273
+ if (loc.end.offset < dir.loc.end.offset) {
2274
+ loc.start.offset--;
2275
+ loc.start.column--;
2276
+ loc.end.offset++;
2277
+ loc.end.column++;
2278
+ }
2279
+ attr.value = {
2280
+ type: 2,
2281
+ content: dir.exp.content,
2282
+ loc
2283
+ };
1467
2284
  }
2285
+ return attr;
1468
2286
  }
1469
- function getNewPosition(context, start, numberOfCharacters) {
1470
- return advancePositionWithClone(
1471
- start,
1472
- context.originalSource.slice(start.offset, numberOfCharacters),
1473
- numberOfCharacters
1474
- );
2287
+ function emitError(code, index) {
2288
+ currentOptions.onError(createCompilerError(code, getLoc(index, index)));
1475
2289
  }
1476
- function emitError(context, code, offset, loc = getCursor(context)) {
1477
- if (offset) {
1478
- loc.offset += offset;
1479
- loc.column += offset;
1480
- }
1481
- context.options.onError(
1482
- createCompilerError(code, {
1483
- start: loc,
1484
- end: loc,
1485
- source: ""
1486
- })
1487
- );
2290
+ function reset() {
2291
+ tokenizer.reset();
2292
+ currentOpenTag = null;
2293
+ currentProp = null;
2294
+ currentAttrValue = "";
2295
+ currentAttrStartIndex = -1;
2296
+ currentAttrEndIndex = -1;
2297
+ stack.length = 0;
1488
2298
  }
1489
- function isEnd(context, mode, ancestors) {
1490
- const s = context.source;
1491
- switch (mode) {
1492
- case 0:
1493
- if (startsWith(s, "</")) {
1494
- for (let i = ancestors.length - 1; i >= 0; --i) {
1495
- if (startsWithEndTagOpen(s, ancestors[i].tag)) {
1496
- return true;
1497
- }
1498
- }
1499
- }
1500
- break;
1501
- case 1:
1502
- case 2: {
1503
- const parent = last(ancestors);
1504
- if (parent && startsWithEndTagOpen(s, parent.tag)) {
1505
- return true;
2299
+ function baseParse(input, options) {
2300
+ reset();
2301
+ currentInput = input;
2302
+ currentOptions = shared.extend({}, defaultParserOptions);
2303
+ if (options) {
2304
+ let key;
2305
+ for (key in options) {
2306
+ if (options[key] != null) {
2307
+ currentOptions[key] = options[key];
1506
2308
  }
1507
- break;
1508
2309
  }
1509
- case 3:
1510
- if (startsWith(s, "]]>")) {
1511
- return true;
1512
- }
1513
- break;
1514
2310
  }
1515
- return !s;
1516
- }
1517
- function startsWithEndTagOpen(source, tag) {
1518
- return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
2311
+ {
2312
+ if (currentOptions.decodeEntities) {
2313
+ console.warn(
2314
+ `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
2315
+ );
2316
+ }
2317
+ }
2318
+ tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2319
+ const delimiters = options == null ? void 0 : options.delimiters;
2320
+ if (delimiters) {
2321
+ tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2322
+ tokenizer.delimiterClose = toCharCodes(delimiters[1]);
2323
+ }
2324
+ const root = currentRoot = createRoot([], input);
2325
+ tokenizer.parse(currentInput);
2326
+ root.loc = getLoc(0, input.length);
2327
+ root.children = condenseWhitespace(root.children);
2328
+ currentRoot = null;
2329
+ return root;
1519
2330
  }
1520
2331
 
1521
2332
  function hoistStatic(root, context) {
@@ -1955,6 +2766,7 @@ function transform(root, options) {
1955
2766
  root.hoists = context.hoists;
1956
2767
  root.temps = context.temps;
1957
2768
  root.cached = context.cached;
2769
+ root.transformed = true;
1958
2770
  {
1959
2771
  root.filters = [...context.filters];
1960
2772
  }
@@ -2111,7 +2923,7 @@ function createCodegenContext(ast, {
2111
2923
  ssr,
2112
2924
  isTS,
2113
2925
  inSSR,
2114
- source: ast.loc.source,
2926
+ source: ast.source,
2115
2927
  code: ``,
2116
2928
  column: 1,
2117
2929
  line: 1,
@@ -2122,7 +2934,7 @@ function createCodegenContext(ast, {
2122
2934
  helper(key) {
2123
2935
  return `_${helperNameMap[key]}`;
2124
2936
  },
2125
- push(code, node) {
2937
+ push(code, newlineIndex = -2 /* None */, node) {
2126
2938
  context.code += code;
2127
2939
  if (context.map) {
2128
2940
  if (node) {
@@ -2135,7 +2947,20 @@ function createCodegenContext(ast, {
2135
2947
  }
2136
2948
  addMapping(node.loc.start, name);
2137
2949
  }
2138
- advancePositionWithMutation(context, code);
2950
+ if (newlineIndex === -3 /* Unknown */) {
2951
+ advancePositionWithMutation(context, code);
2952
+ } else {
2953
+ context.offset += code.length;
2954
+ if (newlineIndex === -2 /* None */) {
2955
+ context.column += code.length;
2956
+ } else {
2957
+ if (newlineIndex === -1 /* End */) {
2958
+ newlineIndex = code.length - 1;
2959
+ }
2960
+ context.line++;
2961
+ context.column = code.length - newlineIndex;
2962
+ }
2963
+ }
2139
2964
  if (node && node.loc !== locStub) {
2140
2965
  addMapping(node.loc.end);
2141
2966
  }
@@ -2156,26 +2981,27 @@ function createCodegenContext(ast, {
2156
2981
  }
2157
2982
  };
2158
2983
  function newline(n) {
2159
- context.push("\n" + ` `.repeat(n));
2160
- }
2161
- function addMapping(loc, name) {
2162
- context.map.addMapping({
2163
- name,
2164
- source: context.filename,
2165
- original: {
2166
- line: loc.line,
2167
- column: loc.column - 1
2168
- // source-map column is 0 based
2169
- },
2170
- generated: {
2171
- line: context.line,
2172
- column: context.column - 1
2173
- }
2984
+ context.push("\n" + ` `.repeat(n), 0 /* Start */);
2985
+ }
2986
+ function addMapping(loc, name = null) {
2987
+ const { _names, _mappings } = context.map;
2988
+ if (name !== null && !_names.has(name))
2989
+ _names.add(name);
2990
+ _mappings.add({
2991
+ originalLine: loc.line,
2992
+ originalColumn: loc.column - 1,
2993
+ // source-map column is 0 based
2994
+ generatedLine: context.line,
2995
+ generatedColumn: context.column - 1,
2996
+ source: filename,
2997
+ // @ts-ignore it is possible to be null
2998
+ name
2174
2999
  });
2175
3000
  }
2176
3001
  if (sourceMap) {
2177
3002
  context.map = new sourceMapJs.SourceMapGenerator();
2178
3003
  context.map.setSourceContent(filename, context.source);
3004
+ context.map._sources.add(filename);
2179
3005
  }
2180
3006
  return context;
2181
3007
  }
@@ -2220,9 +3046,11 @@ function generate(ast, options = {}) {
2220
3046
  push(`with (_ctx) {`);
2221
3047
  indent();
2222
3048
  if (hasHelpers) {
2223
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
2224
- push(`
2225
- `);
3049
+ push(
3050
+ `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3051
+ `,
3052
+ -1 /* End */
3053
+ );
2226
3054
  newline();
2227
3055
  }
2228
3056
  }
@@ -2251,7 +3079,7 @@ function generate(ast, options = {}) {
2251
3079
  }
2252
3080
  if (ast.components.length || ast.directives.length || ast.temps) {
2253
3081
  push(`
2254
- `);
3082
+ `, 0 /* Start */);
2255
3083
  newline();
2256
3084
  }
2257
3085
  if (!ssr) {
@@ -2272,7 +3100,6 @@ function generate(ast, options = {}) {
2272
3100
  ast,
2273
3101
  code: context.code,
2274
3102
  preamble: isSetupInlined ? preambleContext.code : ``,
2275
- // SourceMapGenerator does have toJSON() method but it's not in the types
2276
3103
  map: context.map ? context.map.toJSON() : void 0
2277
3104
  };
2278
3105
  }
@@ -2290,11 +3117,14 @@ function genFunctionPreamble(ast, context) {
2290
3117
  const helpers = Array.from(ast.helpers);
2291
3118
  if (helpers.length > 0) {
2292
3119
  if (prefixIdentifiers) {
2293
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
2294
- `);
3120
+ push(
3121
+ `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
3122
+ `,
3123
+ -1 /* End */
3124
+ );
2295
3125
  } else {
2296
3126
  push(`const _Vue = ${VueBinding}
2297
- `);
3127
+ `, -1 /* End */);
2298
3128
  if (ast.hoists.length) {
2299
3129
  const staticHelpers = [
2300
3130
  CREATE_VNODE,
@@ -2304,14 +3134,15 @@ function genFunctionPreamble(ast, context) {
2304
3134
  CREATE_STATIC
2305
3135
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
2306
3136
  push(`const { ${staticHelpers} } = _Vue
2307
- `);
3137
+ `, -1 /* End */);
2308
3138
  }
2309
3139
  }
2310
3140
  }
2311
3141
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2312
3142
  push(
2313
3143
  `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
2314
- `
3144
+ `,
3145
+ -1 /* End */
2315
3146
  );
2316
3147
  }
2317
3148
  genHoists(ast.hoists, context);
@@ -2335,25 +3166,29 @@ function genModulePreamble(ast, context, genScopeId, inline) {
2335
3166
  if (optimizeImports) {
2336
3167
  push(
2337
3168
  `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2338
- `
3169
+ `,
3170
+ -1 /* End */
2339
3171
  );
2340
3172
  push(
2341
3173
  `
2342
3174
  // Binding optimization for webpack code-split
2343
3175
  const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
2344
- `
3176
+ `,
3177
+ -1 /* End */
2345
3178
  );
2346
3179
  } else {
2347
3180
  push(
2348
3181
  `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2349
- `
3182
+ `,
3183
+ -1 /* End */
2350
3184
  );
2351
3185
  }
2352
3186
  }
2353
3187
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2354
3188
  push(
2355
3189
  `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
2356
- `
3190
+ `,
3191
+ -1 /* End */
2357
3192
  );
2358
3193
  }
2359
3194
  if (ast.imports.length) {
@@ -2443,7 +3278,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2443
3278
  for (let i = 0; i < nodes.length; i++) {
2444
3279
  const node = nodes[i];
2445
3280
  if (shared.isString(node)) {
2446
- push(node);
3281
+ push(node, -3 /* Unknown */);
2447
3282
  } else if (shared.isArray(node)) {
2448
3283
  genNodeListAsArray(node, context);
2449
3284
  } else {
@@ -2461,7 +3296,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2461
3296
  }
2462
3297
  function genNode(node, context) {
2463
3298
  if (shared.isString(node)) {
2464
- context.push(node);
3299
+ context.push(node, -3 /* Unknown */);
2465
3300
  return;
2466
3301
  }
2467
3302
  if (shared.isSymbol(node)) {
@@ -2546,11 +3381,15 @@ function genNode(node, context) {
2546
3381
  }
2547
3382
  }
2548
3383
  function genText(node, context) {
2549
- context.push(JSON.stringify(node.content), node);
3384
+ context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
2550
3385
  }
2551
3386
  function genExpression(node, context) {
2552
3387
  const { content, isStatic } = node;
2553
- context.push(isStatic ? JSON.stringify(content) : content, node);
3388
+ context.push(
3389
+ isStatic ? JSON.stringify(content) : content,
3390
+ -3 /* Unknown */,
3391
+ node
3392
+ );
2554
3393
  }
2555
3394
  function genInterpolation(node, context) {
2556
3395
  const { push, helper, pure } = context;
@@ -2564,7 +3403,7 @@ function genCompoundExpression(node, context) {
2564
3403
  for (let i = 0; i < node.children.length; i++) {
2565
3404
  const child = node.children[i];
2566
3405
  if (shared.isString(child)) {
2567
- context.push(child);
3406
+ context.push(child, -3 /* Unknown */);
2568
3407
  } else {
2569
3408
  genNode(child, context);
2570
3409
  }
@@ -2578,9 +3417,9 @@ function genExpressionAsPropertyKey(node, context) {
2578
3417
  push(`]`);
2579
3418
  } else if (node.isStatic) {
2580
3419
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
2581
- push(text, node);
3420
+ push(text, -2 /* None */, node);
2582
3421
  } else {
2583
- push(`[${node.content}]`, node);
3422
+ push(`[${node.content}]`, -3 /* Unknown */, node);
2584
3423
  }
2585
3424
  }
2586
3425
  function genComment(node, context) {
@@ -2588,7 +3427,11 @@ function genComment(node, context) {
2588
3427
  if (pure) {
2589
3428
  push(PURE_ANNOTATION);
2590
3429
  }
2591
- push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
3430
+ push(
3431
+ `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
3432
+ -3 /* Unknown */,
3433
+ node
3434
+ );
2592
3435
  }
2593
3436
  function genVNodeCall(node, context) {
2594
3437
  const { push, helper, pure } = context;
@@ -2613,7 +3456,7 @@ function genVNodeCall(node, context) {
2613
3456
  push(PURE_ANNOTATION);
2614
3457
  }
2615
3458
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
2616
- push(helper(callHelper) + `(`, node);
3459
+ push(helper(callHelper) + `(`, -2 /* None */, node);
2617
3460
  genNodeList(
2618
3461
  genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
2619
3462
  context
@@ -2642,7 +3485,7 @@ function genCallExpression(node, context) {
2642
3485
  if (pure) {
2643
3486
  push(PURE_ANNOTATION);
2644
3487
  }
2645
- push(callee + `(`, node);
3488
+ push(callee + `(`, -2 /* None */, node);
2646
3489
  genNodeList(node.arguments, context);
2647
3490
  push(`)`);
2648
3491
  }
@@ -2650,7 +3493,7 @@ function genObjectExpression(node, context) {
2650
3493
  const { push, indent, deindent, newline } = context;
2651
3494
  const { properties } = node;
2652
3495
  if (!properties.length) {
2653
- push(`{}`, node);
3496
+ push(`{}`, -2 /* None */, node);
2654
3497
  return;
2655
3498
  }
2656
3499
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -2678,7 +3521,7 @@ function genFunctionExpression(node, context) {
2678
3521
  if (isSlot) {
2679
3522
  push(`_${helperNameMap[WITH_CTX]}(`);
2680
3523
  }
2681
- push(`(`, node);
3524
+ push(`(`, -2 /* None */, node);
2682
3525
  if (shared.isArray(params)) {
2683
3526
  genNodeList(params, context);
2684
3527
  } else if (params) {
@@ -2775,7 +3618,7 @@ function genTemplateLiteral(node, context) {
2775
3618
  for (let i = 0; i < l; i++) {
2776
3619
  const e = node.elements[i];
2777
3620
  if (shared.isString(e)) {
2778
- push(e.replace(/(`|\$|\\)/g, "\\$1"));
3621
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
2779
3622
  } else {
2780
3623
  push("${");
2781
3624
  if (multilines)
@@ -2923,6 +3766,15 @@ function walkBlockDeclarations(block, onIdent) {
2923
3766
  if (stmt.declare || !stmt.id)
2924
3767
  continue;
2925
3768
  onIdent(stmt.id);
3769
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
3770
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
3771
+ if (variable && variable.type === "VariableDeclaration") {
3772
+ for (const decl of variable.declarations) {
3773
+ for (const id of extractIdentifiers(decl.id)) {
3774
+ onIdent(id);
3775
+ }
3776
+ }
3777
+ }
2926
3778
  }
2927
3779
  }
2928
3780
  }
@@ -3175,8 +4027,8 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
3175
4027
  const isScopeVarReference = context.identifiers[rawExp];
3176
4028
  const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
3177
4029
  const isLiteral = isLiteralWhitelisted(rawExp);
3178
- if (!asParams && !isScopeVarReference && !isAllowedGlobal && !isLiteral) {
3179
- if (isConst(bindingMetadata[node.content])) {
4030
+ if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
4031
+ if (isConst(bindingMetadata[rawExp])) {
3180
4032
  node.constType = 1;
3181
4033
  }
3182
4034
  node.content = rewriteIdentifier(rawExp);
@@ -3253,9 +4105,9 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
3253
4105
  id.name,
3254
4106
  false,
3255
4107
  {
3256
- source: source2,
3257
4108
  start: advancePositionWithClone(node.loc.start, source2, start),
3258
- end: advancePositionWithClone(node.loc.start, source2, end)
4109
+ end: advancePositionWithClone(node.loc.start, source2, end),
4110
+ source: source2
3259
4111
  },
3260
4112
  id.isConstant ? 3 : 0
3261
4113
  )
@@ -3374,7 +4226,7 @@ function processIf(node, dir, context, processCodegen) {
3374
4226
  context.removeNode();
3375
4227
  const branch = createIfBranch(node, dir);
3376
4228
  if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
3377
- !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
4229
+ !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
3378
4230
  branch.children = [...comments, ...branch.children];
3379
4231
  }
3380
4232
  {
@@ -3670,18 +4522,14 @@ function processFor(node, dir, context, processCodegen) {
3670
4522
  );
3671
4523
  return;
3672
4524
  }
3673
- const parseResult = parseForExpression(
3674
- // can only be simple expression because vFor transform is applied
3675
- // before expression transform.
3676
- dir.exp,
3677
- context
3678
- );
4525
+ const parseResult = dir.forParseResult;
3679
4526
  if (!parseResult) {
3680
4527
  context.onError(
3681
4528
  createCompilerError(32, dir.loc)
3682
4529
  );
3683
4530
  return;
3684
4531
  }
4532
+ finalizeForParseResult(parseResult, context);
3685
4533
  const { addIdentifiers, removeIdentifiers, scopes } = context;
3686
4534
  const { source, value, key, index } = parseResult;
3687
4535
  const forNode = {
@@ -3713,77 +4561,37 @@ function processFor(node, dir, context, processCodegen) {
3713
4561
  onExit();
3714
4562
  };
3715
4563
  }
3716
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
3717
- const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
3718
- const stripParensRE = /^\(|\)$/g;
3719
- function parseForExpression(input, context) {
3720
- const loc = input.loc;
3721
- const exp = input.content;
3722
- const inMatch = exp.match(forAliasRE);
3723
- if (!inMatch)
4564
+ function finalizeForParseResult(result, context) {
4565
+ if (result.finalized)
3724
4566
  return;
3725
- const [, LHS, RHS] = inMatch;
3726
- const result = {
3727
- source: createAliasExpression(
3728
- loc,
3729
- RHS.trim(),
3730
- exp.indexOf(RHS, LHS.length)
3731
- ),
3732
- value: void 0,
3733
- key: void 0,
3734
- index: void 0
3735
- };
3736
4567
  if (context.prefixIdentifiers) {
3737
4568
  result.source = processExpression(
3738
4569
  result.source,
3739
4570
  context
3740
4571
  );
3741
- }
3742
- let valueContent = LHS.trim().replace(stripParensRE, "").trim();
3743
- const trimmedOffset = LHS.indexOf(valueContent);
3744
- const iteratorMatch = valueContent.match(forIteratorRE);
3745
- if (iteratorMatch) {
3746
- valueContent = valueContent.replace(forIteratorRE, "").trim();
3747
- const keyContent = iteratorMatch[1].trim();
3748
- let keyOffset;
3749
- if (keyContent) {
3750
- keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
3751
- result.key = createAliasExpression(loc, keyContent, keyOffset);
3752
- if (context.prefixIdentifiers) {
3753
- result.key = processExpression(result.key, context, true);
3754
- }
4572
+ if (result.key) {
4573
+ result.key = processExpression(
4574
+ result.key,
4575
+ context,
4576
+ true
4577
+ );
3755
4578
  }
3756
- if (iteratorMatch[2]) {
3757
- const indexContent = iteratorMatch[2].trim();
3758
- if (indexContent) {
3759
- result.index = createAliasExpression(
3760
- loc,
3761
- indexContent,
3762
- exp.indexOf(
3763
- indexContent,
3764
- result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
3765
- )
3766
- );
3767
- if (context.prefixIdentifiers) {
3768
- result.index = processExpression(result.index, context, true);
3769
- }
3770
- }
4579
+ if (result.index) {
4580
+ result.index = processExpression(
4581
+ result.index,
4582
+ context,
4583
+ true
4584
+ );
3771
4585
  }
3772
- }
3773
- if (valueContent) {
3774
- result.value = createAliasExpression(loc, valueContent, trimmedOffset);
3775
- if (context.prefixIdentifiers) {
3776
- result.value = processExpression(result.value, context, true);
4586
+ if (result.value) {
4587
+ result.value = processExpression(
4588
+ result.value,
4589
+ context,
4590
+ true
4591
+ );
3777
4592
  }
3778
4593
  }
3779
- return result;
3780
- }
3781
- function createAliasExpression(range, content, offset) {
3782
- return createSimpleExpression(
3783
- content,
3784
- false,
3785
- getInnerRange(range, offset, content.length)
3786
- );
4594
+ result.finalized = true;
3787
4595
  }
3788
4596
  function createForLoopParams({ value, key, index }, memoArgs = []) {
3789
4597
  return createParamsList([value, key, index, ...memoArgs]);
@@ -3819,11 +4627,9 @@ const trackSlotScopes = (node, context) => {
3819
4627
  const trackVForSlotScopes = (node, context) => {
3820
4628
  let vFor;
3821
4629
  if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
3822
- const result = vFor.parseResult = parseForExpression(
3823
- vFor.exp,
3824
- context
3825
- );
4630
+ const result = vFor.forParseResult;
3826
4631
  if (result) {
4632
+ finalizeForParseResult(result, context);
3827
4633
  const { value, key, index } = result;
3828
4634
  const { addIdentifiers, removeIdentifiers } = context;
3829
4635
  value && addIdentifiers(value);
@@ -3900,12 +4706,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3900
4706
  hasDynamicSlots = true;
3901
4707
  }
3902
4708
  const vFor = findDir(slotElement, "for");
3903
- const slotFunction = buildSlotFn(
3904
- slotProps,
3905
- vFor == null ? void 0 : vFor.exp,
3906
- slotChildren,
3907
- slotLoc
3908
- );
4709
+ const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
3909
4710
  let vIf;
3910
4711
  let vElse;
3911
4712
  if (vIf = findDir(slotElement, "if")) {
@@ -3954,8 +4755,9 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3954
4755
  }
3955
4756
  } else if (vFor) {
3956
4757
  hasDynamicSlots = true;
3957
- const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
4758
+ const parseResult = vFor.forParseResult;
3958
4759
  if (parseResult) {
4760
+ finalizeForParseResult(parseResult, context);
3959
4761
  dynamicSlots.push(
3960
4762
  createCallExpression(context.helper(RENDER_LIST), [
3961
4763
  parseResult.source,
@@ -4216,17 +5018,6 @@ function resolveComponentType(node, context, ssr = false) {
4216
5018
  tag = isProp.value.content.slice(4);
4217
5019
  }
4218
5020
  }
4219
- const isDir = !isExplicitDynamic && findDir(node, "is");
4220
- if (isDir && isDir.exp) {
4221
- {
4222
- context.onWarn(
4223
- createCompilerError(52, isDir.loc)
4224
- );
4225
- }
4226
- return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
4227
- isDir.exp
4228
- ]);
4229
- }
4230
5021
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
4231
5022
  if (builtIn) {
4232
5023
  if (!ssr)
@@ -4349,7 +5140,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4349
5140
  for (let i = 0; i < props.length; i++) {
4350
5141
  const prop = props[i];
4351
5142
  if (prop.type === 6) {
4352
- const { loc, name, value } = prop;
5143
+ const { loc, name, nameLoc, value } = prop;
4353
5144
  let isStatic = true;
4354
5145
  if (name === "ref") {
4355
5146
  hasRef = true;
@@ -4382,11 +5173,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4382
5173
  }
4383
5174
  properties.push(
4384
5175
  createObjectProperty(
4385
- createSimpleExpression(
4386
- name,
4387
- true,
4388
- getInnerRange(loc, 0, name.length)
4389
- ),
5176
+ createSimpleExpression(name, true, nameLoc),
4390
5177
  createSimpleExpression(
4391
5178
  value ? value.content : "",
4392
5179
  isStatic,
@@ -4395,7 +5182,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4395
5182
  )
4396
5183
  );
4397
5184
  } else {
4398
- const { name, arg, exp, loc } = prop;
5185
+ const { name, arg, exp, loc, modifiers } = prop;
4399
5186
  const isVBind = name === "bind";
4400
5187
  const isVOn = name === "on";
4401
5188
  if (name === "slot") {
@@ -4488,6 +5275,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4488
5275
  }
4489
5276
  continue;
4490
5277
  }
5278
+ if (isVBind && modifiers.includes("prop")) {
5279
+ patchFlag |= 32;
5280
+ }
4491
5281
  const directiveTransform = context.directiveTransforms[name];
4492
5282
  if (directiveTransform) {
4493
5283
  const { props: props2, needRuntime } = directiveTransform(prop, node, context);
@@ -4890,8 +5680,16 @@ const transformOn = (dir, node, context, augmentor) => {
4890
5680
  };
4891
5681
 
4892
5682
  const transformBind = (dir, _node, context) => {
4893
- const { exp, modifiers, loc } = dir;
5683
+ const { modifiers, loc } = dir;
4894
5684
  const arg = dir.arg;
5685
+ let { exp } = dir;
5686
+ if (!exp && arg.type === 4) {
5687
+ const propName = shared.camelize(arg.content);
5688
+ exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5689
+ {
5690
+ exp = dir.exp = processExpression(exp, context);
5691
+ }
5692
+ }
4895
5693
  if (arg.type !== 4) {
4896
5694
  arg.children.unshift(`(`);
4897
5695
  arg.children.push(`) || ""`);
@@ -5318,7 +6116,7 @@ function getBaseTransformPreset(prefixIdentifiers) {
5318
6116
  }
5319
6117
  ];
5320
6118
  }
5321
- function baseCompile(template, options = {}) {
6119
+ function baseCompile(source, options = {}) {
5322
6120
  const onError = options.onError || defaultOnError;
5323
6121
  const isModuleMode = options.mode === "module";
5324
6122
  const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
@@ -5328,7 +6126,7 @@ function baseCompile(template, options = {}) {
5328
6126
  if (options.scopeId && !isModuleMode) {
5329
6127
  onError(createCompilerError(50));
5330
6128
  }
5331
- const ast = shared.isString(template) ? baseParse(template, options) : template;
6129
+ const ast = shared.isString(source) ? baseParse(source, options) : source;
5332
6130
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
5333
6131
  if (options.isTS) {
5334
6132
  const { expressionPlugins } = options;
@@ -5440,10 +6238,10 @@ exports.errorMessages = errorMessages;
5440
6238
  exports.extractIdentifiers = extractIdentifiers;
5441
6239
  exports.findDir = findDir;
5442
6240
  exports.findProp = findProp;
6241
+ exports.forAliasRE = forAliasRE;
5443
6242
  exports.generate = generate;
5444
6243
  exports.getBaseTransformPreset = getBaseTransformPreset;
5445
6244
  exports.getConstantType = getConstantType;
5446
- exports.getInnerRange = getInnerRange;
5447
6245
  exports.getMemoedVNodeCall = getMemoedVNodeCall;
5448
6246
  exports.getVNodeBlockHelper = getVNodeBlockHelper;
5449
6247
  exports.getVNodeHelper = getVNodeHelper;
@@ -5451,7 +6249,6 @@ exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
5451
6249
  exports.hasScopeRef = hasScopeRef;
5452
6250
  exports.helperNameMap = helperNameMap;
5453
6251
  exports.injectProp = injectProp;
5454
- exports.isBuiltInType = isBuiltInType;
5455
6252
  exports.isCoreComponent = isCoreComponent;
5456
6253
  exports.isFunctionType = isFunctionType;
5457
6254
  exports.isInDestructureAssignment = isInDestructureAssignment;