@vue/compiler-core 3.3.9 → 3.4.0-alpha.2

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
  );
@@ -675,470 +1603,545 @@ function getMemoedVNodeCall(node) {
675
1603
  }
676
1604
  const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
677
1605
 
678
- const deprecationData = {
679
- ["COMPILER_IS_ON_ELEMENT"]: {
680
- 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:".`,
681
- link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
682
- },
683
- ["COMPILER_V_BIND_SYNC"]: {
684
- 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}\`.`,
685
- link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
686
- },
687
- ["COMPILER_V_BIND_PROP"]: {
688
- 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.`
689
- },
690
- ["COMPILER_V_BIND_OBJECT_ORDER"]: {
691
- 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.`,
692
- link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
693
- },
694
- ["COMPILER_V_ON_NATIVE"]: {
695
- message: `.native modifier for v-on has been removed as is no longer necessary.`,
696
- link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
697
- },
698
- ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
699
- 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.`,
700
- link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
701
- },
702
- ["COMPILER_NATIVE_TEMPLATE"]: {
703
- message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
704
- },
705
- ["COMPILER_INLINE_TEMPLATE"]: {
706
- message: `"inline-template" has been removed in Vue 3.`,
707
- link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
708
- },
709
- ["COMPILER_FILTER"]: {
710
- 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.`,
711
- link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
712
- }
713
- };
714
- function getCompatValue(key, context) {
715
- const config = context.options ? context.options.compatConfig : context.compatConfig;
716
- const value = config && config[key];
717
- if (key === "MODE") {
718
- return value || 3;
719
- } else {
720
- return value;
721
- }
722
- }
723
- function isCompatEnabled(key, context) {
724
- const mode = getCompatValue("MODE", context);
725
- const value = getCompatValue(key, context);
726
- return mode === 3 ? value === true : value !== false;
727
- }
728
- function checkCompatEnabled(key, context, loc, ...args) {
729
- const enabled = isCompatEnabled(key, context);
730
- if (enabled) {
731
- warnDeprecation(key, context, loc, ...args);
732
- }
733
- return enabled;
734
- }
735
- function warnDeprecation(key, context, loc, ...args) {
736
- const val = getCompatValue(key, context);
737
- if (val === "suppress-warning") {
738
- return;
739
- }
740
- const { message, link } = deprecationData[key];
741
- const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
742
- Details: ${link}` : ``}`;
743
- const err = new SyntaxError(msg);
744
- err.code = key;
745
- if (loc)
746
- err.loc = loc;
747
- context.onWarn(err);
748
- }
749
-
750
- const decodeRE = /&(gt|lt|amp|apos|quot);/g;
751
- const decodeMap = {
752
- gt: ">",
753
- lt: "<",
754
- amp: "&",
755
- apos: "'",
756
- quot: '"'
757
- };
758
1606
  const defaultParserOptions = {
1607
+ parseMode: "base",
1608
+ ns: 0,
759
1609
  delimiters: [`{{`, `}}`],
760
1610
  getNamespace: () => 0,
761
- getTextMode: () => 0,
762
1611
  isVoidTag: shared.NO,
763
1612
  isPreTag: shared.NO,
764
1613
  isCustomElement: shared.NO,
765
- decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
766
1614
  onError: defaultOnError,
767
1615
  onWarn: defaultOnWarn,
768
1616
  comments: true
769
1617
  };
770
- function baseParse(content, options = {}) {
771
- const context = createParserContext(content, options);
772
- const start = getCursor(context);
773
- return createRoot(
774
- parseChildren(context, 0, []),
775
- getSelection(context, start)
776
- );
777
- }
778
- function createParserContext(content, rawOptions) {
779
- const options = shared.extend({}, defaultParserOptions);
780
- let key;
781
- for (key in rawOptions) {
782
- options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
783
- }
784
- return {
785
- options,
786
- column: 1,
787
- line: 1,
788
- offset: 0,
789
- originalSource: content,
790
- source: content,
791
- inPre: false,
792
- inVPre: false,
793
- onWarn: options.onWarn
794
- };
795
- }
796
- function parseChildren(context, mode, ancestors) {
797
- const parent = last(ancestors);
798
- const ns = parent ? parent.ns : 0;
799
- const nodes = [];
800
- while (!isEnd(context, mode, ancestors)) {
801
- const s = context.source;
802
- let node = void 0;
803
- if (mode === 0 || mode === 1) {
804
- if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
805
- node = parseInterpolation(context, mode);
806
- } else if (mode === 0 && s[0] === "<") {
807
- if (s.length === 1) {
808
- emitError(context, 5, 1);
809
- } else if (s[1] === "!") {
810
- if (startsWith(s, "<!--")) {
811
- node = parseComment(context);
812
- } else if (startsWith(s, "<!DOCTYPE")) {
813
- node = parseBogusComment(context);
814
- } else if (startsWith(s, "<![CDATA[")) {
815
- if (ns !== 0) {
816
- node = parseCDATA(context, ancestors);
817
- } else {
818
- emitError(context, 1);
819
- node = parseBogusComment(context);
820
- }
821
- } else {
822
- emitError(context, 11);
823
- 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);
824
1695
  }
825
- } else if (s[1] === "/") {
826
- if (s.length === 2) {
827
- emitError(context, 5, 2);
828
- } else if (s[2] === ">") {
829
- emitError(context, 14, 2);
830
- advanceBy(context, 3);
831
- continue;
832
- } else if (/[a-z]/i.test(s[2])) {
833
- emitError(context, 23);
834
- parseTag(context, 1 /* End */, parent);
835
- continue;
836
- } else {
837
- emitError(
838
- context,
839
- 12,
840
- 2
841
- );
842
- node = parseBogusComment(context);
1696
+ for (let j = 0; j <= i; j++) {
1697
+ const el = stack.shift();
1698
+ onCloseTag(el, end, j < i);
843
1699
  }
844
- } else if (/[a-z]/i.test(s[1])) {
845
- node = parseElement(context, ancestors);
846
- if (isCompatEnabled(
847
- "COMPILER_NATIVE_TEMPLATE",
848
- context
849
- ) && node && node.tag === "template" && !node.props.some(
850
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
851
- )) {
852
- warnDeprecation(
853
- "COMPILER_NATIVE_TEMPLATE",
854
- context,
855
- node.loc
856
- );
857
- 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]);
858
1757
  }
859
- } else if (s[1] === "?") {
860
- emitError(
861
- context,
862
- 21,
863
- 1
864
- );
865
- node = parseBogusComment(context);
866
- } else {
867
- emitError(context, 12, 1);
868
1758
  }
869
1759
  }
870
1760
  }
871
- if (!node) {
872
- node = parseText(context, mode);
1761
+ },
1762
+ ondirarg(start, end) {
1763
+ const arg = getSlice(start, end);
1764
+ if (inVPre) {
1765
+ currentProp.name += arg;
1766
+ setLocEnd(currentProp.nameLoc, end);
1767
+ } else {
1768
+ const isStatic = arg[0] !== `[`;
1769
+ currentProp.arg = createSimpleExpression(
1770
+ isStatic ? arg : arg.slice(1, -1),
1771
+ isStatic,
1772
+ getLoc(start, end),
1773
+ isStatic ? 3 : 0
1774
+ );
873
1775
  }
874
- if (shared.isArray(node)) {
875
- for (let i = 0; i < node.length; i++) {
876
- pushNode(nodes, node[i]);
1776
+ },
1777
+ ondirmodifier(start, end) {
1778
+ const mod = getSlice(start, end);
1779
+ if (inVPre) {
1780
+ currentProp.name += "." + mod;
1781
+ setLocEnd(currentProp.nameLoc, end);
1782
+ } else if (currentProp.name === "slot") {
1783
+ const arg = currentProp.arg;
1784
+ if (arg) {
1785
+ arg.content += "." + mod;
1786
+ setLocEnd(arg.loc, end);
877
1787
  }
878
1788
  } else {
879
- pushNode(nodes, node);
1789
+ currentProp.modifiers.push(mod);
880
1790
  }
881
- }
882
- let removedWhitespace = false;
883
- if (mode !== 2 && mode !== 1) {
884
- const shouldCondense = context.options.whitespace !== "preserve";
885
- for (let i = 0; i < nodes.length; i++) {
886
- const node = nodes[i];
887
- if (node.type === 2) {
888
- if (!context.inPre) {
889
- if (!/[^\t\r\n\f ]/.test(node.content)) {
890
- const prev = nodes[i - 1];
891
- const next = nodes[i + 1];
892
- 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))) {
893
- removedWhitespace = true;
894
- nodes[i] = null;
895
- } else {
896
- node.content = " ";
897
- }
898
- } else if (shouldCondense) {
899
- node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
1791
+ },
1792
+ onattribdata(start, end) {
1793
+ currentAttrValue += getSlice(start, end);
1794
+ if (currentAttrStartIndex < 0)
1795
+ currentAttrStartIndex = start;
1796
+ currentAttrEndIndex = end;
1797
+ },
1798
+ onattribentity(char, start, end) {
1799
+ currentAttrValue += char;
1800
+ if (currentAttrStartIndex < 0)
1801
+ currentAttrStartIndex = start;
1802
+ currentAttrEndIndex = end;
1803
+ },
1804
+ onattribnameend(end) {
1805
+ const start = currentProp.loc.start.offset;
1806
+ const name = getSlice(start, end);
1807
+ if (currentProp.type === 7) {
1808
+ currentProp.rawName = name;
1809
+ }
1810
+ if (currentOpenTag.props.some(
1811
+ (p) => (p.type === 7 ? p.rawName : p.name) === name
1812
+ )) {
1813
+ emitError(2, start);
1814
+ }
1815
+ },
1816
+ onattribend(quote, end) {
1817
+ if (currentOpenTag && currentProp) {
1818
+ setLocEnd(currentProp.loc, end);
1819
+ if (quote !== 0) {
1820
+ if (currentProp.type === 6) {
1821
+ if (currentProp.name === "class") {
1822
+ currentAttrValue = condense(currentAttrValue).trim();
1823
+ }
1824
+ if (quote === 1 && !currentAttrValue) {
1825
+ emitError(13, end);
1826
+ }
1827
+ currentProp.value = {
1828
+ type: 2,
1829
+ content: currentAttrValue,
1830
+ loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
1831
+ };
1832
+ if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
1833
+ tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
900
1834
  }
901
1835
  } else {
902
- node.content = node.content.replace(/\r\n/g, "\n");
1836
+ currentProp.exp = createSimpleExpression(
1837
+ currentAttrValue,
1838
+ false,
1839
+ getLoc(currentAttrStartIndex, currentAttrEndIndex)
1840
+ );
1841
+ if (currentProp.name === "for") {
1842
+ currentProp.forParseResult = parseForExpression(currentProp.exp);
1843
+ }
1844
+ let syncIndex = -1;
1845
+ if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
1846
+ "COMPILER_V_BIND_SYNC",
1847
+ currentOptions,
1848
+ currentProp.loc,
1849
+ currentProp.rawName
1850
+ )) {
1851
+ currentProp.name = "model";
1852
+ currentProp.modifiers.splice(syncIndex, 1);
1853
+ }
903
1854
  }
904
- } else if (node.type === 3 && !context.options.comments) {
905
- removedWhitespace = true;
906
- nodes[i] = null;
907
1855
  }
1856
+ if (currentProp.type !== 7 || currentProp.name !== "pre") {
1857
+ currentOpenTag.props.push(currentProp);
1858
+ }
1859
+ }
1860
+ currentAttrValue = "";
1861
+ currentAttrStartIndex = currentAttrEndIndex = -1;
1862
+ },
1863
+ oncomment(start, end) {
1864
+ if (currentOptions.comments) {
1865
+ addNode({
1866
+ type: 3,
1867
+ content: getSlice(start, end),
1868
+ loc: getLoc(start - 4, end + 3)
1869
+ });
908
1870
  }
909
- if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
910
- const first = nodes[0];
911
- if (first && first.type === 2) {
912
- first.content = first.content.replace(/^\r?\n/, "");
1871
+ },
1872
+ onend() {
1873
+ const end = currentInput.length;
1874
+ if (tokenizer.state !== 1) {
1875
+ switch (tokenizer.state) {
1876
+ case 5:
1877
+ case 8:
1878
+ emitError(5, end);
1879
+ break;
1880
+ case 3:
1881
+ case 4:
1882
+ emitError(
1883
+ 25,
1884
+ tokenizer.sectionStart
1885
+ );
1886
+ break;
1887
+ case 28:
1888
+ if (tokenizer.currentSequence === Sequences.CdataEnd) {
1889
+ emitError(6, end);
1890
+ } else {
1891
+ emitError(7, end);
1892
+ }
1893
+ break;
1894
+ case 6:
1895
+ case 7:
1896
+ case 9:
1897
+ case 11:
1898
+ case 12:
1899
+ case 13:
1900
+ case 14:
1901
+ case 15:
1902
+ case 16:
1903
+ case 17:
1904
+ case 18:
1905
+ case 19:
1906
+ case 20:
1907
+ case 21:
1908
+ emitError(9, end);
1909
+ break;
913
1910
  }
914
1911
  }
1912
+ for (let index = 0; index < stack.length; index++) {
1913
+ onCloseTag(stack[index], end - 1);
1914
+ emitError(24, stack[index].loc.start.offset);
1915
+ }
1916
+ },
1917
+ oncdata(start, end) {
1918
+ if (stack[0].ns !== 0) {
1919
+ onText(getSlice(start, end), start, end);
1920
+ } else {
1921
+ emitError(1, start - 9);
1922
+ }
1923
+ },
1924
+ onprocessinginstruction(start) {
1925
+ if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
1926
+ emitError(
1927
+ 21,
1928
+ start - 1
1929
+ );
1930
+ }
915
1931
  }
916
- return removedWhitespace ? nodes.filter(Boolean) : nodes;
1932
+ });
1933
+ const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
1934
+ const stripParensRE = /^\(|\)$/g;
1935
+ function parseForExpression(input) {
1936
+ const loc = input.loc;
1937
+ const exp = input.content;
1938
+ const inMatch = exp.match(forAliasRE);
1939
+ if (!inMatch)
1940
+ return;
1941
+ const [, LHS, RHS] = inMatch;
1942
+ const createAliasExpression = (content, offset) => {
1943
+ const start = loc.start.offset + offset;
1944
+ const end = start + content.length;
1945
+ return createSimpleExpression(content, false, getLoc(start, end));
1946
+ };
1947
+ const result = {
1948
+ source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
1949
+ value: void 0,
1950
+ key: void 0,
1951
+ index: void 0,
1952
+ finalized: false
1953
+ };
1954
+ let valueContent = LHS.trim().replace(stripParensRE, "").trim();
1955
+ const trimmedOffset = LHS.indexOf(valueContent);
1956
+ const iteratorMatch = valueContent.match(forIteratorRE);
1957
+ if (iteratorMatch) {
1958
+ valueContent = valueContent.replace(forIteratorRE, "").trim();
1959
+ const keyContent = iteratorMatch[1].trim();
1960
+ let keyOffset;
1961
+ if (keyContent) {
1962
+ keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
1963
+ result.key = createAliasExpression(keyContent, keyOffset);
1964
+ }
1965
+ if (iteratorMatch[2]) {
1966
+ const indexContent = iteratorMatch[2].trim();
1967
+ if (indexContent) {
1968
+ result.index = createAliasExpression(
1969
+ indexContent,
1970
+ exp.indexOf(
1971
+ indexContent,
1972
+ result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
1973
+ )
1974
+ );
1975
+ }
1976
+ }
1977
+ }
1978
+ if (valueContent) {
1979
+ result.value = createAliasExpression(valueContent, trimmedOffset);
1980
+ }
1981
+ return result;
917
1982
  }
918
- function pushNode(nodes, node) {
919
- if (node.type === 2) {
920
- const prev = last(nodes);
921
- if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
922
- prev.content += node.content;
923
- prev.loc.end = node.loc.end;
924
- prev.loc.source += node.loc.source;
925
- return;
1983
+ function getSlice(start, end) {
1984
+ return currentInput.slice(start, end);
1985
+ }
1986
+ function endOpenTag(end) {
1987
+ addNode(currentOpenTag);
1988
+ const { tag, ns } = currentOpenTag;
1989
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
1990
+ inPre++;
1991
+ }
1992
+ if (currentOptions.isVoidTag(tag)) {
1993
+ onCloseTag(currentOpenTag, end);
1994
+ } else {
1995
+ stack.unshift(currentOpenTag);
1996
+ if (ns === 1 || ns === 2) {
1997
+ tokenizer.inXML = true;
926
1998
  }
927
1999
  }
928
- nodes.push(node);
2000
+ currentOpenTag = null;
929
2001
  }
930
- function parseCDATA(context, ancestors) {
931
- advanceBy(context, 9);
932
- const nodes = parseChildren(context, 3, ancestors);
933
- if (context.source.length === 0) {
934
- emitError(context, 6);
2002
+ function onText(content, start, end) {
2003
+ const parent = stack[0] || currentRoot;
2004
+ const lastNode = parent.children[parent.children.length - 1];
2005
+ if ((lastNode == null ? void 0 : lastNode.type) === 2) {
2006
+ lastNode.content += content;
2007
+ setLocEnd(lastNode.loc, end);
935
2008
  } else {
936
- advanceBy(context, 3);
2009
+ parent.children.push({
2010
+ type: 2,
2011
+ content,
2012
+ loc: getLoc(start, end)
2013
+ });
937
2014
  }
938
- return nodes;
939
2015
  }
940
- function parseComment(context) {
941
- const start = getCursor(context);
942
- let content;
943
- const match = /--(\!)?>/.exec(context.source);
944
- if (!match) {
945
- content = context.source.slice(4);
946
- advanceBy(context, context.source.length);
947
- emitError(context, 7);
2016
+ function onCloseTag(el, end, isImplied = false) {
2017
+ if (isImplied) {
2018
+ setLocEnd(el.loc, backTrack(end, 60));
948
2019
  } else {
949
- if (match.index <= 3) {
950
- emitError(context, 0);
951
- }
952
- if (match[1]) {
953
- emitError(context, 10);
2020
+ setLocEnd(el.loc, end + fastForward(end) + 1);
2021
+ }
2022
+ if (tokenizer.inSFCRoot) {
2023
+ if (el.children.length) {
2024
+ el.innerLoc.end = shared.extend({}, el.children[el.children.length - 1].loc.end);
2025
+ } else {
2026
+ el.innerLoc.end = shared.extend({}, el.innerLoc.start);
954
2027
  }
955
- content = context.source.slice(4, match.index);
956
- const s = context.source.slice(0, match.index);
957
- let prevIndex = 1, nestedIndex = 0;
958
- while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
959
- advanceBy(context, nestedIndex - prevIndex + 1);
960
- if (nestedIndex + 4 < s.length) {
961
- emitError(context, 16);
962
- }
963
- prevIndex = nestedIndex + 1;
2028
+ el.innerLoc.source = getSlice(
2029
+ el.innerLoc.start.offset,
2030
+ el.innerLoc.end.offset
2031
+ );
2032
+ }
2033
+ const { tag, ns } = el;
2034
+ if (!inVPre) {
2035
+ if (tag === "slot") {
2036
+ el.tagType = 2;
2037
+ } else if (isFragmentTemplate(el)) {
2038
+ el.tagType = 3;
2039
+ } else if (isComponent(el)) {
2040
+ el.tagType = 1;
964
2041
  }
965
- advanceBy(context, match.index + match[0].length - prevIndex + 1);
966
2042
  }
967
- return {
968
- type: 3,
969
- content,
970
- loc: getSelection(context, start)
971
- };
972
- }
973
- function parseBogusComment(context) {
974
- const start = getCursor(context);
975
- const contentStart = context.source[1] === "?" ? 1 : 2;
976
- let content;
977
- const closeIndex = context.source.indexOf(">");
978
- if (closeIndex === -1) {
979
- content = context.source.slice(contentStart);
980
- advanceBy(context, context.source.length);
981
- } else {
982
- content = context.source.slice(contentStart, closeIndex);
983
- advanceBy(context, closeIndex + 1);
2043
+ if (!tokenizer.inRCDATA) {
2044
+ el.children = condenseWhitespace(el.children, el.tag);
2045
+ }
2046
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
2047
+ inPre--;
2048
+ }
2049
+ if (currentVPreBoundary === el) {
2050
+ inVPre = false;
2051
+ currentVPreBoundary = null;
2052
+ }
2053
+ if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2054
+ tokenizer.inXML = false;
984
2055
  }
985
- return {
986
- type: 3,
987
- content,
988
- loc: getSelection(context, start)
989
- };
990
- }
991
- function parseElement(context, ancestors) {
992
- const wasInPre = context.inPre;
993
- const wasInVPre = context.inVPre;
994
- const parent = last(ancestors);
995
- const element = parseTag(context, 0 /* Start */, parent);
996
- const isPreBoundary = context.inPre && !wasInPre;
997
- const isVPreBoundary = context.inVPre && !wasInVPre;
998
- if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
999
- if (isPreBoundary) {
1000
- context.inPre = false;
1001
- }
1002
- if (isVPreBoundary) {
1003
- context.inVPre = false;
1004
- }
1005
- return element;
1006
- }
1007
- ancestors.push(element);
1008
- const mode = context.options.getTextMode(element, parent);
1009
- const children = parseChildren(context, mode, ancestors);
1010
- ancestors.pop();
1011
2056
  {
1012
- const inlineTemplateProp = element.props.find(
2057
+ const props = el.props;
2058
+ if (isCompatEnabled(
2059
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2060
+ currentOptions
2061
+ )) {
2062
+ let hasIf = false;
2063
+ let hasFor = false;
2064
+ for (let i = 0; i < props.length; i++) {
2065
+ const p = props[i];
2066
+ if (p.type === 7) {
2067
+ if (p.name === "if") {
2068
+ hasIf = true;
2069
+ } else if (p.name === "for") {
2070
+ hasFor = true;
2071
+ }
2072
+ }
2073
+ if (hasIf && hasFor) {
2074
+ warnDeprecation(
2075
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2076
+ currentOptions,
2077
+ el.loc
2078
+ );
2079
+ break;
2080
+ }
2081
+ }
2082
+ }
2083
+ if (isCompatEnabled(
2084
+ "COMPILER_NATIVE_TEMPLATE",
2085
+ currentOptions
2086
+ ) && el.tag === "template" && !isFragmentTemplate(el)) {
2087
+ warnDeprecation(
2088
+ "COMPILER_NATIVE_TEMPLATE",
2089
+ currentOptions,
2090
+ el.loc
2091
+ );
2092
+ const parent = stack[0] || currentRoot;
2093
+ const index = parent.children.indexOf(el);
2094
+ parent.children.splice(index, 1, ...el.children);
2095
+ }
2096
+ const inlineTemplateProp = props.find(
1013
2097
  (p) => p.type === 6 && p.name === "inline-template"
1014
2098
  );
1015
2099
  if (inlineTemplateProp && checkCompatEnabled(
1016
2100
  "COMPILER_INLINE_TEMPLATE",
1017
- context,
2101
+ currentOptions,
1018
2102
  inlineTemplateProp.loc
1019
- )) {
1020
- const loc = getSelection(context, element.loc.end);
2103
+ ) && el.children.length) {
1021
2104
  inlineTemplateProp.value = {
1022
2105
  type: 2,
1023
- content: loc.source,
1024
- loc
2106
+ content: getSlice(
2107
+ el.children[0].loc.start.offset,
2108
+ el.children[el.children.length - 1].loc.end.offset
2109
+ ),
2110
+ loc: inlineTemplateProp.loc
1025
2111
  };
1026
2112
  }
1027
2113
  }
1028
- element.children = children;
1029
- if (startsWithEndTagOpen(context.source, element.tag)) {
1030
- parseTag(context, 1 /* End */, parent);
1031
- } else {
1032
- emitError(context, 24, 0, element.loc.start);
1033
- if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
1034
- const first = children[0];
1035
- if (first && startsWith(first.loc.source, "<!--")) {
1036
- emitError(context, 8);
1037
- }
1038
- }
1039
- }
1040
- element.loc = getSelection(context, element.loc.start);
1041
- if (isPreBoundary) {
1042
- context.inPre = false;
1043
- }
1044
- if (isVPreBoundary) {
1045
- context.inVPre = false;
1046
- }
1047
- return element;
1048
2114
  }
1049
- const isSpecialTemplateDirective = /* @__PURE__ */ shared.makeMap(
1050
- `if,else,else-if,for,slot`
1051
- );
1052
- function parseTag(context, type, parent) {
1053
- const start = getCursor(context);
1054
- const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
1055
- const tag = match[1];
1056
- const ns = context.options.getNamespace(tag, parent);
1057
- advanceBy(context, match[0].length);
1058
- advanceSpaces(context);
1059
- const cursor = getCursor(context);
1060
- const currentSource = context.source;
1061
- if (context.options.isPreTag(tag)) {
1062
- context.inPre = true;
1063
- }
1064
- let props = parseAttributes(context, type);
1065
- if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
1066
- context.inVPre = true;
1067
- shared.extend(context, cursor);
1068
- context.source = currentSource;
1069
- props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
1070
- }
1071
- let isSelfClosing = false;
1072
- if (context.source.length === 0) {
1073
- emitError(context, 9);
1074
- } else {
1075
- isSelfClosing = startsWith(context.source, "/>");
1076
- if (type === 1 /* End */ && isSelfClosing) {
1077
- emitError(context, 4);
1078
- }
1079
- advanceBy(context, isSelfClosing ? 2 : 1);
1080
- }
1081
- if (type === 1 /* End */) {
1082
- return;
2115
+ function fastForward(start, c) {
2116
+ let offset = 0;
2117
+ while (currentInput.charCodeAt(start + offset) !== 62 && start + offset < currentInput.length) {
2118
+ offset++;
1083
2119
  }
1084
- if (isCompatEnabled(
1085
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1086
- context
1087
- )) {
1088
- let hasIf = false;
1089
- let hasFor = false;
2120
+ return offset;
2121
+ }
2122
+ function backTrack(index, c) {
2123
+ let i = index;
2124
+ while (currentInput.charCodeAt(i) !== c && i >= 0)
2125
+ i--;
2126
+ return i;
2127
+ }
2128
+ const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
2129
+ function isFragmentTemplate({ tag, props }) {
2130
+ if (tag === "template") {
1090
2131
  for (let i = 0; i < props.length; i++) {
1091
- const p = props[i];
1092
- if (p.type === 7) {
1093
- if (p.name === "if") {
1094
- hasIf = true;
1095
- } else if (p.name === "for") {
1096
- hasFor = true;
1097
- }
1098
- }
1099
- if (hasIf && hasFor) {
1100
- warnDeprecation(
1101
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1102
- context,
1103
- getSelection(context, start)
1104
- );
1105
- break;
1106
- }
1107
- }
1108
- }
1109
- let tagType = 0;
1110
- if (!context.inVPre) {
1111
- if (tag === "slot") {
1112
- tagType = 2;
1113
- } else if (tag === "template") {
1114
- if (props.some(
1115
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
1116
- )) {
1117
- tagType = 3;
2132
+ if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
2133
+ return true;
1118
2134
  }
1119
- } else if (isComponent(tag, props, context)) {
1120
- tagType = 1;
1121
2135
  }
1122
2136
  }
1123
- return {
1124
- type: 1,
1125
- ns,
1126
- tag,
1127
- tagType,
1128
- props,
1129
- isSelfClosing,
1130
- children: [],
1131
- loc: getSelection(context, start),
1132
- codegenNode: void 0
1133
- // to be created during transform phase
1134
- };
2137
+ return false;
1135
2138
  }
1136
- function isComponent(tag, props, context) {
1137
- const options = context.options;
1138
- if (options.isCustomElement(tag)) {
2139
+ function isComponent({ tag, props }) {
2140
+ var _a;
2141
+ if (currentOptions.isCustomElement(tag)) {
1139
2142
  return false;
1140
2143
  }
1141
- if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
2144
+ if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
1142
2145
  return true;
1143
2146
  }
1144
2147
  for (let i = 0; i < props.length; i++) {
@@ -1149,374 +2152,179 @@ function isComponent(tag, props, context) {
1149
2152
  return true;
1150
2153
  } else if (checkCompatEnabled(
1151
2154
  "COMPILER_IS_ON_ELEMENT",
1152
- context,
2155
+ currentOptions,
1153
2156
  p.loc
1154
2157
  )) {
1155
2158
  return true;
1156
2159
  }
1157
2160
  }
1158
- } else {
1159
- if (p.name === "is") {
1160
- return true;
1161
- } else if (
1162
- // :is on plain element - only treat as component in compat mode
1163
- p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
1164
- "COMPILER_IS_ON_ELEMENT",
1165
- context,
1166
- p.loc
1167
- )
1168
- ) {
1169
- return true;
1170
- }
2161
+ } else if (// :is on plain element - only treat as component in compat mode
2162
+ p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
2163
+ "COMPILER_IS_ON_ELEMENT",
2164
+ currentOptions,
2165
+ p.loc
2166
+ )) {
2167
+ return true;
1171
2168
  }
1172
2169
  }
2170
+ return false;
1173
2171
  }
1174
- function parseAttributes(context, type) {
1175
- const props = [];
1176
- const attributeNames = /* @__PURE__ */ new Set();
1177
- while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
1178
- if (startsWith(context.source, "/")) {
1179
- emitError(context, 22);
1180
- advanceBy(context, 1);
1181
- advanceSpaces(context);
1182
- continue;
1183
- }
1184
- if (type === 1 /* End */) {
1185
- emitError(context, 3);
1186
- }
1187
- const attr = parseAttribute(context, attributeNames);
1188
- if (attr.type === 6 && attr.value && attr.name === "class") {
1189
- attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
1190
- }
1191
- if (type === 0 /* Start */) {
1192
- props.push(attr);
1193
- }
1194
- if (/^[^\t\r\n\f />]/.test(context.source)) {
1195
- emitError(context, 15);
1196
- }
1197
- advanceSpaces(context);
1198
- }
1199
- return props;
2172
+ function isUpperCase(c) {
2173
+ return c > 64 && c < 91;
1200
2174
  }
1201
- function parseAttribute(context, nameSet) {
1202
- var _a;
1203
- const start = getCursor(context);
1204
- const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
1205
- const name = match[0];
1206
- if (nameSet.has(name)) {
1207
- emitError(context, 2);
1208
- }
1209
- nameSet.add(name);
1210
- if (name[0] === "=") {
1211
- emitError(context, 19);
1212
- }
1213
- {
1214
- const pattern = /["'<]/g;
1215
- let m;
1216
- while (m = pattern.exec(name)) {
1217
- emitError(
1218
- context,
1219
- 17,
1220
- m.index
1221
- );
1222
- }
1223
- }
1224
- advanceBy(context, name.length);
1225
- let value = void 0;
1226
- if (/^[\t\r\n\f ]*=/.test(context.source)) {
1227
- advanceSpaces(context);
1228
- advanceBy(context, 1);
1229
- advanceSpaces(context);
1230
- value = parseAttributeValue(context);
1231
- if (!value) {
1232
- emitError(context, 13);
1233
- }
1234
- }
1235
- const loc = getSelection(context, start);
1236
- if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
1237
- const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
1238
- name
1239
- );
1240
- let isPropShorthand = startsWith(name, ".");
1241
- let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
1242
- let arg;
1243
- if (match2[2]) {
1244
- const isSlot = dirName === "slot";
1245
- const startOffset = name.lastIndexOf(
1246
- match2[2],
1247
- name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
1248
- );
1249
- const loc2 = getSelection(
1250
- context,
1251
- getNewPosition(context, start, startOffset),
1252
- getNewPosition(
1253
- context,
1254
- start,
1255
- startOffset + match2[2].length + (isSlot && match2[3] || "").length
1256
- )
1257
- );
1258
- let content = match2[2];
1259
- let isStatic = true;
1260
- if (content.startsWith("[")) {
1261
- isStatic = false;
1262
- if (!content.endsWith("]")) {
1263
- emitError(
1264
- context,
1265
- 27
1266
- );
1267
- content = content.slice(1);
1268
- } else {
1269
- content = content.slice(1, content.length - 1);
2175
+ const windowsNewlineRE = /\r\n/g;
2176
+ function condenseWhitespace(nodes, tag) {
2177
+ var _a, _b;
2178
+ const shouldCondense = currentOptions.whitespace !== "preserve";
2179
+ let removedWhitespace = false;
2180
+ for (let i = 0; i < nodes.length; i++) {
2181
+ const node = nodes[i];
2182
+ if (node.type === 2) {
2183
+ if (!inPre) {
2184
+ if (isAllWhitespace(node.content)) {
2185
+ const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
2186
+ const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
2187
+ if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2188
+ removedWhitespace = true;
2189
+ nodes[i] = null;
2190
+ } else {
2191
+ node.content = " ";
2192
+ }
2193
+ } else if (shouldCondense) {
2194
+ node.content = condense(node.content);
1270
2195
  }
1271
- } else if (isSlot) {
1272
- content += match2[3] || "";
1273
- }
1274
- arg = {
1275
- type: 4,
1276
- content,
1277
- isStatic,
1278
- constType: isStatic ? 3 : 0,
1279
- loc: loc2
1280
- };
1281
- }
1282
- if (value && value.isQuoted) {
1283
- const valueLoc = value.loc;
1284
- valueLoc.start.offset++;
1285
- valueLoc.start.column++;
1286
- valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
1287
- valueLoc.source = valueLoc.source.slice(1, -1);
1288
- }
1289
- const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
1290
- if (isPropShorthand)
1291
- modifiers.push("prop");
1292
- if (dirName === "bind" && arg) {
1293
- if (modifiers.includes("sync") && checkCompatEnabled(
1294
- "COMPILER_V_BIND_SYNC",
1295
- context,
1296
- loc,
1297
- arg.loc.source
1298
- )) {
1299
- dirName = "model";
1300
- modifiers.splice(modifiers.indexOf("sync"), 1);
1301
- }
1302
- if (modifiers.includes("prop")) {
1303
- checkCompatEnabled(
1304
- "COMPILER_V_BIND_PROP",
1305
- context,
1306
- loc
1307
- );
2196
+ } else {
2197
+ node.content = node.content.replace(windowsNewlineRE, "\n");
1308
2198
  }
1309
2199
  }
1310
- return {
1311
- type: 7,
1312
- name: dirName,
1313
- exp: value && {
1314
- type: 4,
1315
- content: value.content,
1316
- isStatic: false,
1317
- // Treat as non-constant by default. This can be potentially set to
1318
- // other values by `transformExpression` to make it eligible for hoisting.
1319
- constType: 0,
1320
- loc: value.loc
1321
- },
1322
- arg,
1323
- modifiers,
1324
- loc
1325
- };
1326
2200
  }
1327
- if (!context.inVPre && startsWith(name, "v-")) {
1328
- emitError(context, 26);
2201
+ if (inPre && tag && currentOptions.isPreTag(tag)) {
2202
+ const first = nodes[0];
2203
+ if (first && first.type === 2) {
2204
+ first.content = first.content.replace(/^\r?\n/, "");
2205
+ }
1329
2206
  }
1330
- return {
1331
- type: 6,
1332
- name,
1333
- value: value && {
1334
- type: 2,
1335
- content: value.content,
1336
- loc: value.loc
1337
- },
1338
- loc
1339
- };
2207
+ return removedWhitespace ? nodes.filter(Boolean) : nodes;
1340
2208
  }
1341
- function parseAttributeValue(context) {
1342
- const start = getCursor(context);
1343
- let content;
1344
- const quote = context.source[0];
1345
- const isQuoted = quote === `"` || quote === `'`;
1346
- if (isQuoted) {
1347
- advanceBy(context, 1);
1348
- const endIndex = context.source.indexOf(quote);
1349
- if (endIndex === -1) {
1350
- content = parseTextData(
1351
- context,
1352
- context.source.length,
1353
- 4
1354
- );
1355
- } else {
1356
- content = parseTextData(context, endIndex, 4);
1357
- advanceBy(context, 1);
1358
- }
1359
- } else {
1360
- const match = /^[^\t\r\n\f >]+/.exec(context.source);
1361
- if (!match) {
1362
- return void 0;
1363
- }
1364
- const unexpectedChars = /["'<=`]/g;
1365
- let m;
1366
- while (m = unexpectedChars.exec(match[0])) {
1367
- emitError(
1368
- context,
1369
- 18,
1370
- m.index
1371
- );
2209
+ function isAllWhitespace(str) {
2210
+ for (let i = 0; i < str.length; i++) {
2211
+ if (!isWhitespace(str.charCodeAt(i))) {
2212
+ return false;
1372
2213
  }
1373
- content = parseTextData(context, match[0].length, 4);
1374
- }
1375
- return { content, isQuoted, loc: getSelection(context, start) };
1376
- }
1377
- function parseInterpolation(context, mode) {
1378
- const [open, close] = context.options.delimiters;
1379
- const closeIndex = context.source.indexOf(close, open.length);
1380
- if (closeIndex === -1) {
1381
- emitError(context, 25);
1382
- return void 0;
1383
- }
1384
- const start = getCursor(context);
1385
- advanceBy(context, open.length);
1386
- const innerStart = getCursor(context);
1387
- const innerEnd = getCursor(context);
1388
- const rawContentLength = closeIndex - open.length;
1389
- const rawContent = context.source.slice(0, rawContentLength);
1390
- const preTrimContent = parseTextData(context, rawContentLength, mode);
1391
- const content = preTrimContent.trim();
1392
- const startOffset = preTrimContent.indexOf(content);
1393
- if (startOffset > 0) {
1394
- advancePositionWithMutation(innerStart, rawContent, startOffset);
1395
- }
1396
- const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
1397
- advancePositionWithMutation(innerEnd, rawContent, endOffset);
1398
- advanceBy(context, close.length);
1399
- return {
1400
- type: 5,
1401
- content: {
1402
- type: 4,
1403
- isStatic: false,
1404
- // Set `isConstant` to false by default and will decide in transformExpression
1405
- constType: 0,
1406
- content,
1407
- loc: getSelection(context, innerStart, innerEnd)
1408
- },
1409
- loc: getSelection(context, start)
1410
- };
2214
+ }
2215
+ return true;
1411
2216
  }
1412
- function parseText(context, mode) {
1413
- const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
1414
- let endIndex = context.source.length;
1415
- for (let i = 0; i < endTokens.length; i++) {
1416
- const index = context.source.indexOf(endTokens[i], 1);
1417
- if (index !== -1 && endIndex > index) {
1418
- endIndex = index;
2217
+ function hasNewlineChar(str) {
2218
+ for (let i = 0; i < str.length; i++) {
2219
+ const c = str.charCodeAt(i);
2220
+ if (c === 10 || c === 13) {
2221
+ return true;
1419
2222
  }
1420
2223
  }
1421
- const start = getCursor(context);
1422
- const content = parseTextData(context, endIndex, mode);
1423
- return {
1424
- type: 2,
1425
- content,
1426
- loc: getSelection(context, start)
1427
- };
2224
+ return false;
1428
2225
  }
1429
- function parseTextData(context, length, mode) {
1430
- const rawText = context.source.slice(0, length);
1431
- advanceBy(context, length);
1432
- if (mode === 2 || mode === 3 || !rawText.includes("&")) {
1433
- return rawText;
1434
- } else {
1435
- return context.options.decodeEntities(
1436
- rawText,
1437
- mode === 4
1438
- );
2226
+ function condense(str) {
2227
+ let ret = "";
2228
+ let prevCharIsWhitespace = false;
2229
+ for (let i = 0; i < str.length; i++) {
2230
+ if (isWhitespace(str.charCodeAt(i))) {
2231
+ if (!prevCharIsWhitespace) {
2232
+ ret += " ";
2233
+ prevCharIsWhitespace = true;
2234
+ }
2235
+ } else {
2236
+ ret += str[i];
2237
+ prevCharIsWhitespace = false;
2238
+ }
1439
2239
  }
2240
+ return ret;
1440
2241
  }
1441
- function getCursor(context) {
1442
- const { column, line, offset } = context;
1443
- return { column, line, offset };
2242
+ function addNode(node) {
2243
+ (stack[0] || currentRoot).children.push(node);
1444
2244
  }
1445
- function getSelection(context, start, end) {
1446
- end = end || getCursor(context);
2245
+ function getLoc(start, end) {
1447
2246
  return {
1448
- start,
1449
- end,
1450
- source: context.originalSource.slice(start.offset, end.offset)
2247
+ start: tokenizer.getPos(start),
2248
+ // @ts-expect-error allow late attachment
2249
+ end: end == null ? end : tokenizer.getPos(end),
2250
+ // @ts-expect-error allow late attachment
2251
+ source: end == null ? end : getSlice(start, end)
1451
2252
  };
1452
2253
  }
1453
- function last(xs) {
1454
- return xs[xs.length - 1];
1455
- }
1456
- function startsWith(source, searchString) {
1457
- return source.startsWith(searchString);
2254
+ function setLocEnd(loc, end) {
2255
+ loc.end = tokenizer.getPos(end);
2256
+ loc.source = getSlice(loc.start.offset, end);
1458
2257
  }
1459
- function advanceBy(context, numberOfCharacters) {
1460
- const { source } = context;
1461
- advancePositionWithMutation(context, source, numberOfCharacters);
1462
- context.source = source.slice(numberOfCharacters);
1463
- }
1464
- function advanceSpaces(context) {
1465
- const match = /^[\t\r\n\f ]+/.exec(context.source);
1466
- if (match) {
1467
- advanceBy(context, match[0].length);
2258
+ function dirToAttr(dir) {
2259
+ const attr = {
2260
+ type: 6,
2261
+ name: dir.rawName,
2262
+ nameLoc: getLoc(
2263
+ dir.loc.start.offset,
2264
+ dir.loc.start.offset + dir.rawName.length
2265
+ ),
2266
+ value: void 0,
2267
+ loc: dir.loc
2268
+ };
2269
+ if (dir.exp) {
2270
+ const loc = dir.exp.loc;
2271
+ if (loc.end.offset < dir.loc.end.offset) {
2272
+ loc.start.offset--;
2273
+ loc.start.column--;
2274
+ loc.end.offset++;
2275
+ loc.end.column++;
2276
+ }
2277
+ attr.value = {
2278
+ type: 2,
2279
+ content: dir.exp.content,
2280
+ loc
2281
+ };
1468
2282
  }
2283
+ return attr;
1469
2284
  }
1470
- function getNewPosition(context, start, numberOfCharacters) {
1471
- return advancePositionWithClone(
1472
- start,
1473
- context.originalSource.slice(start.offset, numberOfCharacters),
1474
- numberOfCharacters
1475
- );
2285
+ function emitError(code, index) {
2286
+ currentOptions.onError(createCompilerError(code, getLoc(index, index)));
1476
2287
  }
1477
- function emitError(context, code, offset, loc = getCursor(context)) {
1478
- if (offset) {
1479
- loc.offset += offset;
1480
- loc.column += offset;
1481
- }
1482
- context.options.onError(
1483
- createCompilerError(code, {
1484
- start: loc,
1485
- end: loc,
1486
- source: ""
1487
- })
1488
- );
2288
+ function reset() {
2289
+ tokenizer.reset();
2290
+ currentOpenTag = null;
2291
+ currentProp = null;
2292
+ currentAttrValue = "";
2293
+ currentAttrStartIndex = -1;
2294
+ currentAttrEndIndex = -1;
2295
+ stack.length = 0;
1489
2296
  }
1490
- function isEnd(context, mode, ancestors) {
1491
- const s = context.source;
1492
- switch (mode) {
1493
- case 0:
1494
- if (startsWith(s, "</")) {
1495
- for (let i = ancestors.length - 1; i >= 0; --i) {
1496
- if (startsWithEndTagOpen(s, ancestors[i].tag)) {
1497
- return true;
1498
- }
1499
- }
1500
- }
1501
- break;
1502
- case 1:
1503
- case 2: {
1504
- const parent = last(ancestors);
1505
- if (parent && startsWithEndTagOpen(s, parent.tag)) {
1506
- return true;
2297
+ function baseParse(input, options) {
2298
+ reset();
2299
+ currentInput = input;
2300
+ currentOptions = shared.extend({}, defaultParserOptions);
2301
+ if (options) {
2302
+ let key;
2303
+ for (key in options) {
2304
+ if (options[key] != null) {
2305
+ currentOptions[key] = options[key];
1507
2306
  }
1508
- break;
1509
2307
  }
1510
- case 3:
1511
- if (startsWith(s, "]]>")) {
1512
- return true;
1513
- }
1514
- break;
1515
2308
  }
1516
- return !s;
1517
- }
1518
- function startsWithEndTagOpen(source, tag) {
1519
- return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
2309
+ {
2310
+ if (currentOptions.decodeEntities) {
2311
+ console.warn(
2312
+ `[@vue/compiler-core] decodeEntities option is passed but will be ignored in non-browser builds.`
2313
+ );
2314
+ }
2315
+ }
2316
+ tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2317
+ const delimiters = options == null ? void 0 : options.delimiters;
2318
+ if (delimiters) {
2319
+ tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2320
+ tokenizer.delimiterClose = toCharCodes(delimiters[1]);
2321
+ }
2322
+ const root = currentRoot = createRoot([], input);
2323
+ tokenizer.parse(currentInput);
2324
+ root.loc = getLoc(0, input.length);
2325
+ root.children = condenseWhitespace(root.children);
2326
+ currentRoot = null;
2327
+ return root;
1520
2328
  }
1521
2329
 
1522
2330
  function hoistStatic(root, context) {
@@ -1956,6 +2764,7 @@ function transform(root, options) {
1956
2764
  root.hoists = context.hoists;
1957
2765
  root.temps = context.temps;
1958
2766
  root.cached = context.cached;
2767
+ root.transformed = true;
1959
2768
  {
1960
2769
  root.filters = [...context.filters];
1961
2770
  }
@@ -2112,7 +2921,7 @@ function createCodegenContext(ast, {
2112
2921
  ssr,
2113
2922
  isTS,
2114
2923
  inSSR,
2115
- source: ast.loc.source,
2924
+ source: ast.source,
2116
2925
  code: ``,
2117
2926
  column: 1,
2118
2927
  line: 1,
@@ -2123,7 +2932,7 @@ function createCodegenContext(ast, {
2123
2932
  helper(key) {
2124
2933
  return `_${helperNameMap[key]}`;
2125
2934
  },
2126
- push(code, node) {
2935
+ push(code, newlineIndex = -2 /* None */, node) {
2127
2936
  context.code += code;
2128
2937
  if (context.map) {
2129
2938
  if (node) {
@@ -2136,7 +2945,20 @@ function createCodegenContext(ast, {
2136
2945
  }
2137
2946
  addMapping(node.loc.start, name);
2138
2947
  }
2139
- advancePositionWithMutation(context, code);
2948
+ if (newlineIndex === -3 /* Unknown */) {
2949
+ advancePositionWithMutation(context, code);
2950
+ } else {
2951
+ context.offset += code.length;
2952
+ if (newlineIndex === -2 /* None */) {
2953
+ context.column += code.length;
2954
+ } else {
2955
+ if (newlineIndex === -1 /* End */) {
2956
+ newlineIndex = code.length - 1;
2957
+ }
2958
+ context.line++;
2959
+ context.column = code.length - newlineIndex;
2960
+ }
2961
+ }
2140
2962
  if (node && node.loc !== locStub) {
2141
2963
  addMapping(node.loc.end);
2142
2964
  }
@@ -2157,26 +2979,27 @@ function createCodegenContext(ast, {
2157
2979
  }
2158
2980
  };
2159
2981
  function newline(n) {
2160
- context.push("\n" + ` `.repeat(n));
2161
- }
2162
- function addMapping(loc, name) {
2163
- context.map.addMapping({
2164
- name,
2165
- source: context.filename,
2166
- original: {
2167
- line: loc.line,
2168
- column: loc.column - 1
2169
- // source-map column is 0 based
2170
- },
2171
- generated: {
2172
- line: context.line,
2173
- column: context.column - 1
2174
- }
2982
+ context.push("\n" + ` `.repeat(n), 0 /* Start */);
2983
+ }
2984
+ function addMapping(loc, name = null) {
2985
+ const { _names, _mappings } = context.map;
2986
+ if (name !== null && !_names.has(name))
2987
+ _names.add(name);
2988
+ _mappings.add({
2989
+ originalLine: loc.line,
2990
+ originalColumn: loc.column - 1,
2991
+ // source-map column is 0 based
2992
+ generatedLine: context.line,
2993
+ generatedColumn: context.column - 1,
2994
+ source: filename,
2995
+ // @ts-ignore it is possible to be null
2996
+ name
2175
2997
  });
2176
2998
  }
2177
2999
  if (sourceMap) {
2178
3000
  context.map = new sourceMapJs.SourceMapGenerator();
2179
3001
  context.map.setSourceContent(filename, context.source);
3002
+ context.map._sources.add(filename);
2180
3003
  }
2181
3004
  return context;
2182
3005
  }
@@ -2221,9 +3044,11 @@ function generate(ast, options = {}) {
2221
3044
  push(`with (_ctx) {`);
2222
3045
  indent();
2223
3046
  if (hasHelpers) {
2224
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
2225
- push(`
2226
- `);
3047
+ push(
3048
+ `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3049
+ `,
3050
+ -1 /* End */
3051
+ );
2227
3052
  newline();
2228
3053
  }
2229
3054
  }
@@ -2252,7 +3077,7 @@ function generate(ast, options = {}) {
2252
3077
  }
2253
3078
  if (ast.components.length || ast.directives.length || ast.temps) {
2254
3079
  push(`
2255
- `);
3080
+ `, 0 /* Start */);
2256
3081
  newline();
2257
3082
  }
2258
3083
  if (!ssr) {
@@ -2273,7 +3098,6 @@ function generate(ast, options = {}) {
2273
3098
  ast,
2274
3099
  code: context.code,
2275
3100
  preamble: isSetupInlined ? preambleContext.code : ``,
2276
- // SourceMapGenerator does have toJSON() method but it's not in the types
2277
3101
  map: context.map ? context.map.toJSON() : void 0
2278
3102
  };
2279
3103
  }
@@ -2291,11 +3115,14 @@ function genFunctionPreamble(ast, context) {
2291
3115
  const helpers = Array.from(ast.helpers);
2292
3116
  if (helpers.length > 0) {
2293
3117
  if (prefixIdentifiers) {
2294
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
2295
- `);
3118
+ push(
3119
+ `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
3120
+ `,
3121
+ -1 /* End */
3122
+ );
2296
3123
  } else {
2297
3124
  push(`const _Vue = ${VueBinding}
2298
- `);
3125
+ `, -1 /* End */);
2299
3126
  if (ast.hoists.length) {
2300
3127
  const staticHelpers = [
2301
3128
  CREATE_VNODE,
@@ -2305,14 +3132,15 @@ function genFunctionPreamble(ast, context) {
2305
3132
  CREATE_STATIC
2306
3133
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
2307
3134
  push(`const { ${staticHelpers} } = _Vue
2308
- `);
3135
+ `, -1 /* End */);
2309
3136
  }
2310
3137
  }
2311
3138
  }
2312
3139
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2313
3140
  push(
2314
3141
  `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
2315
- `
3142
+ `,
3143
+ -1 /* End */
2316
3144
  );
2317
3145
  }
2318
3146
  genHoists(ast.hoists, context);
@@ -2336,25 +3164,29 @@ function genModulePreamble(ast, context, genScopeId, inline) {
2336
3164
  if (optimizeImports) {
2337
3165
  push(
2338
3166
  `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2339
- `
3167
+ `,
3168
+ -1 /* End */
2340
3169
  );
2341
3170
  push(
2342
3171
  `
2343
3172
  // Binding optimization for webpack code-split
2344
3173
  const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
2345
- `
3174
+ `,
3175
+ -1 /* End */
2346
3176
  );
2347
3177
  } else {
2348
3178
  push(
2349
3179
  `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2350
- `
3180
+ `,
3181
+ -1 /* End */
2351
3182
  );
2352
3183
  }
2353
3184
  }
2354
3185
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2355
3186
  push(
2356
3187
  `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
2357
- `
3188
+ `,
3189
+ -1 /* End */
2358
3190
  );
2359
3191
  }
2360
3192
  if (ast.imports.length) {
@@ -2444,7 +3276,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2444
3276
  for (let i = 0; i < nodes.length; i++) {
2445
3277
  const node = nodes[i];
2446
3278
  if (shared.isString(node)) {
2447
- push(node);
3279
+ push(node, -3 /* Unknown */);
2448
3280
  } else if (shared.isArray(node)) {
2449
3281
  genNodeListAsArray(node, context);
2450
3282
  } else {
@@ -2462,7 +3294,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2462
3294
  }
2463
3295
  function genNode(node, context) {
2464
3296
  if (shared.isString(node)) {
2465
- context.push(node);
3297
+ context.push(node, -3 /* Unknown */);
2466
3298
  return;
2467
3299
  }
2468
3300
  if (shared.isSymbol(node)) {
@@ -2547,11 +3379,15 @@ function genNode(node, context) {
2547
3379
  }
2548
3380
  }
2549
3381
  function genText(node, context) {
2550
- context.push(JSON.stringify(node.content), node);
3382
+ context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
2551
3383
  }
2552
3384
  function genExpression(node, context) {
2553
3385
  const { content, isStatic } = node;
2554
- context.push(isStatic ? JSON.stringify(content) : content, node);
3386
+ context.push(
3387
+ isStatic ? JSON.stringify(content) : content,
3388
+ -3 /* Unknown */,
3389
+ node
3390
+ );
2555
3391
  }
2556
3392
  function genInterpolation(node, context) {
2557
3393
  const { push, helper, pure } = context;
@@ -2565,7 +3401,7 @@ function genCompoundExpression(node, context) {
2565
3401
  for (let i = 0; i < node.children.length; i++) {
2566
3402
  const child = node.children[i];
2567
3403
  if (shared.isString(child)) {
2568
- context.push(child);
3404
+ context.push(child, -3 /* Unknown */);
2569
3405
  } else {
2570
3406
  genNode(child, context);
2571
3407
  }
@@ -2579,9 +3415,9 @@ function genExpressionAsPropertyKey(node, context) {
2579
3415
  push(`]`);
2580
3416
  } else if (node.isStatic) {
2581
3417
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
2582
- push(text, node);
3418
+ push(text, -2 /* None */, node);
2583
3419
  } else {
2584
- push(`[${node.content}]`, node);
3420
+ push(`[${node.content}]`, -3 /* Unknown */, node);
2585
3421
  }
2586
3422
  }
2587
3423
  function genComment(node, context) {
@@ -2589,7 +3425,11 @@ function genComment(node, context) {
2589
3425
  if (pure) {
2590
3426
  push(PURE_ANNOTATION);
2591
3427
  }
2592
- push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
3428
+ push(
3429
+ `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
3430
+ -3 /* Unknown */,
3431
+ node
3432
+ );
2593
3433
  }
2594
3434
  function genVNodeCall(node, context) {
2595
3435
  const { push, helper, pure } = context;
@@ -2614,7 +3454,7 @@ function genVNodeCall(node, context) {
2614
3454
  push(PURE_ANNOTATION);
2615
3455
  }
2616
3456
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
2617
- push(helper(callHelper) + `(`, node);
3457
+ push(helper(callHelper) + `(`, -2 /* None */, node);
2618
3458
  genNodeList(
2619
3459
  genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
2620
3460
  context
@@ -2643,7 +3483,7 @@ function genCallExpression(node, context) {
2643
3483
  if (pure) {
2644
3484
  push(PURE_ANNOTATION);
2645
3485
  }
2646
- push(callee + `(`, node);
3486
+ push(callee + `(`, -2 /* None */, node);
2647
3487
  genNodeList(node.arguments, context);
2648
3488
  push(`)`);
2649
3489
  }
@@ -2651,7 +3491,7 @@ function genObjectExpression(node, context) {
2651
3491
  const { push, indent, deindent, newline } = context;
2652
3492
  const { properties } = node;
2653
3493
  if (!properties.length) {
2654
- push(`{}`, node);
3494
+ push(`{}`, -2 /* None */, node);
2655
3495
  return;
2656
3496
  }
2657
3497
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -2679,7 +3519,7 @@ function genFunctionExpression(node, context) {
2679
3519
  if (isSlot) {
2680
3520
  push(`_${helperNameMap[WITH_CTX]}(`);
2681
3521
  }
2682
- push(`(`, node);
3522
+ push(`(`, -2 /* None */, node);
2683
3523
  if (shared.isArray(params)) {
2684
3524
  genNodeList(params, context);
2685
3525
  } else if (params) {
@@ -2776,7 +3616,7 @@ function genTemplateLiteral(node, context) {
2776
3616
  for (let i = 0; i < l; i++) {
2777
3617
  const e = node.elements[i];
2778
3618
  if (shared.isString(e)) {
2779
- push(e.replace(/(`|\$|\\)/g, "\\$1"));
3619
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
2780
3620
  } else {
2781
3621
  push("${");
2782
3622
  if (multilines)
@@ -3263,9 +4103,9 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
3263
4103
  id.name,
3264
4104
  false,
3265
4105
  {
3266
- source: source2,
3267
4106
  start: advancePositionWithClone(node.loc.start, source2, start),
3268
- end: advancePositionWithClone(node.loc.start, source2, end)
4107
+ end: advancePositionWithClone(node.loc.start, source2, end),
4108
+ source: source2
3269
4109
  },
3270
4110
  id.isConstant ? 3 : 0
3271
4111
  )
@@ -3384,7 +4224,7 @@ function processIf(node, dir, context, processCodegen) {
3384
4224
  context.removeNode();
3385
4225
  const branch = createIfBranch(node, dir);
3386
4226
  if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
3387
- !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
4227
+ !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
3388
4228
  branch.children = [...comments, ...branch.children];
3389
4229
  }
3390
4230
  {
@@ -3680,18 +4520,14 @@ function processFor(node, dir, context, processCodegen) {
3680
4520
  );
3681
4521
  return;
3682
4522
  }
3683
- const parseResult = parseForExpression(
3684
- // can only be simple expression because vFor transform is applied
3685
- // before expression transform.
3686
- dir.exp,
3687
- context
3688
- );
4523
+ const parseResult = dir.forParseResult;
3689
4524
  if (!parseResult) {
3690
4525
  context.onError(
3691
4526
  createCompilerError(32, dir.loc)
3692
4527
  );
3693
4528
  return;
3694
4529
  }
4530
+ finalizeForParseResult(parseResult, context);
3695
4531
  const { addIdentifiers, removeIdentifiers, scopes } = context;
3696
4532
  const { source, value, key, index } = parseResult;
3697
4533
  const forNode = {
@@ -3723,76 +4559,37 @@ function processFor(node, dir, context, processCodegen) {
3723
4559
  onExit();
3724
4560
  };
3725
4561
  }
3726
- const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
3727
- const stripParensRE = /^\(|\)$/g;
3728
- function parseForExpression(input, context) {
3729
- const loc = input.loc;
3730
- const exp = input.content;
3731
- const inMatch = exp.match(forAliasRE);
3732
- if (!inMatch)
4562
+ function finalizeForParseResult(result, context) {
4563
+ if (result.finalized)
3733
4564
  return;
3734
- const [, LHS, RHS] = inMatch;
3735
- const result = {
3736
- source: createAliasExpression(
3737
- loc,
3738
- RHS.trim(),
3739
- exp.indexOf(RHS, LHS.length)
3740
- ),
3741
- value: void 0,
3742
- key: void 0,
3743
- index: void 0
3744
- };
3745
4565
  if (context.prefixIdentifiers) {
3746
4566
  result.source = processExpression(
3747
4567
  result.source,
3748
4568
  context
3749
4569
  );
3750
- }
3751
- let valueContent = LHS.trim().replace(stripParensRE, "").trim();
3752
- const trimmedOffset = LHS.indexOf(valueContent);
3753
- const iteratorMatch = valueContent.match(forIteratorRE);
3754
- if (iteratorMatch) {
3755
- valueContent = valueContent.replace(forIteratorRE, "").trim();
3756
- const keyContent = iteratorMatch[1].trim();
3757
- let keyOffset;
3758
- if (keyContent) {
3759
- keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
3760
- result.key = createAliasExpression(loc, keyContent, keyOffset);
3761
- if (context.prefixIdentifiers) {
3762
- result.key = processExpression(result.key, context, true);
3763
- }
4570
+ if (result.key) {
4571
+ result.key = processExpression(
4572
+ result.key,
4573
+ context,
4574
+ true
4575
+ );
3764
4576
  }
3765
- if (iteratorMatch[2]) {
3766
- const indexContent = iteratorMatch[2].trim();
3767
- if (indexContent) {
3768
- result.index = createAliasExpression(
3769
- loc,
3770
- indexContent,
3771
- exp.indexOf(
3772
- indexContent,
3773
- result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
3774
- )
3775
- );
3776
- if (context.prefixIdentifiers) {
3777
- result.index = processExpression(result.index, context, true);
3778
- }
3779
- }
4577
+ if (result.index) {
4578
+ result.index = processExpression(
4579
+ result.index,
4580
+ context,
4581
+ true
4582
+ );
3780
4583
  }
3781
- }
3782
- if (valueContent) {
3783
- result.value = createAliasExpression(loc, valueContent, trimmedOffset);
3784
- if (context.prefixIdentifiers) {
3785
- result.value = processExpression(result.value, context, true);
4584
+ if (result.value) {
4585
+ result.value = processExpression(
4586
+ result.value,
4587
+ context,
4588
+ true
4589
+ );
3786
4590
  }
3787
4591
  }
3788
- return result;
3789
- }
3790
- function createAliasExpression(range, content, offset) {
3791
- return createSimpleExpression(
3792
- content,
3793
- false,
3794
- getInnerRange(range, offset, content.length)
3795
- );
4592
+ result.finalized = true;
3796
4593
  }
3797
4594
  function createForLoopParams({ value, key, index }, memoArgs = []) {
3798
4595
  return createParamsList([value, key, index, ...memoArgs]);
@@ -3828,11 +4625,9 @@ const trackSlotScopes = (node, context) => {
3828
4625
  const trackVForSlotScopes = (node, context) => {
3829
4626
  let vFor;
3830
4627
  if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
3831
- const result = vFor.parseResult = parseForExpression(
3832
- vFor.exp,
3833
- context
3834
- );
4628
+ const result = vFor.forParseResult;
3835
4629
  if (result) {
4630
+ finalizeForParseResult(result, context);
3836
4631
  const { value, key, index } = result;
3837
4632
  const { addIdentifiers, removeIdentifiers } = context;
3838
4633
  value && addIdentifiers(value);
@@ -3909,12 +4704,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3909
4704
  hasDynamicSlots = true;
3910
4705
  }
3911
4706
  const vFor = findDir(slotElement, "for");
3912
- const slotFunction = buildSlotFn(
3913
- slotProps,
3914
- vFor == null ? void 0 : vFor.exp,
3915
- slotChildren,
3916
- slotLoc
3917
- );
4707
+ const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
3918
4708
  let vIf;
3919
4709
  let vElse;
3920
4710
  if (vIf = findDir(slotElement, "if")) {
@@ -3963,8 +4753,9 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3963
4753
  }
3964
4754
  } else if (vFor) {
3965
4755
  hasDynamicSlots = true;
3966
- const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
4756
+ const parseResult = vFor.forParseResult;
3967
4757
  if (parseResult) {
4758
+ finalizeForParseResult(parseResult, context);
3968
4759
  dynamicSlots.push(
3969
4760
  createCallExpression(context.helper(RENDER_LIST), [
3970
4761
  parseResult.source,
@@ -4225,17 +5016,6 @@ function resolveComponentType(node, context, ssr = false) {
4225
5016
  tag = isProp.value.content.slice(4);
4226
5017
  }
4227
5018
  }
4228
- const isDir = !isExplicitDynamic && findDir(node, "is");
4229
- if (isDir && isDir.exp) {
4230
- {
4231
- context.onWarn(
4232
- createCompilerError(52, isDir.loc)
4233
- );
4234
- }
4235
- return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
4236
- isDir.exp
4237
- ]);
4238
- }
4239
5019
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
4240
5020
  if (builtIn) {
4241
5021
  if (!ssr)
@@ -4358,7 +5138,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4358
5138
  for (let i = 0; i < props.length; i++) {
4359
5139
  const prop = props[i];
4360
5140
  if (prop.type === 6) {
4361
- const { loc, name, value } = prop;
5141
+ const { loc, name, nameLoc, value } = prop;
4362
5142
  let isStatic = true;
4363
5143
  if (name === "ref") {
4364
5144
  hasRef = true;
@@ -4391,11 +5171,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4391
5171
  }
4392
5172
  properties.push(
4393
5173
  createObjectProperty(
4394
- createSimpleExpression(
4395
- name,
4396
- true,
4397
- getInnerRange(loc, 0, name.length)
4398
- ),
5174
+ createSimpleExpression(name, true, nameLoc),
4399
5175
  createSimpleExpression(
4400
5176
  value ? value.content : "",
4401
5177
  isStatic,
@@ -4902,8 +5678,16 @@ const transformOn = (dir, node, context, augmentor) => {
4902
5678
  };
4903
5679
 
4904
5680
  const transformBind = (dir, _node, context) => {
4905
- const { exp, modifiers, loc } = dir;
5681
+ const { modifiers, loc } = dir;
4906
5682
  const arg = dir.arg;
5683
+ let { exp } = dir;
5684
+ if (!exp && arg.type === 4) {
5685
+ const propName = shared.camelize(arg.content);
5686
+ exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5687
+ {
5688
+ exp = dir.exp = processExpression(exp, context);
5689
+ }
5690
+ }
4907
5691
  if (arg.type !== 4) {
4908
5692
  arg.children.unshift(`(`);
4909
5693
  arg.children.push(`) || ""`);
@@ -5330,7 +6114,7 @@ function getBaseTransformPreset(prefixIdentifiers) {
5330
6114
  }
5331
6115
  ];
5332
6116
  }
5333
- function baseCompile(template, options = {}) {
6117
+ function baseCompile(source, options = {}) {
5334
6118
  const onError = options.onError || defaultOnError;
5335
6119
  const isModuleMode = options.mode === "module";
5336
6120
  const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
@@ -5340,7 +6124,7 @@ function baseCompile(template, options = {}) {
5340
6124
  if (options.scopeId && !isModuleMode) {
5341
6125
  onError(createCompilerError(50));
5342
6126
  }
5343
- const ast = shared.isString(template) ? baseParse(template, options) : template;
6127
+ const ast = shared.isString(source) ? baseParse(source, options) : source;
5344
6128
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
5345
6129
  if (options.isTS) {
5346
6130
  const { expressionPlugins } = options;
@@ -5448,6 +6232,7 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
5448
6232
  exports.createTemplateLiteral = createTemplateLiteral;
5449
6233
  exports.createTransformContext = createTransformContext;
5450
6234
  exports.createVNodeCall = createVNodeCall;
6235
+ exports.errorMessages = errorMessages;
5451
6236
  exports.extractIdentifiers = extractIdentifiers;
5452
6237
  exports.findDir = findDir;
5453
6238
  exports.findProp = findProp;
@@ -5455,7 +6240,6 @@ exports.forAliasRE = forAliasRE;
5455
6240
  exports.generate = generate;
5456
6241
  exports.getBaseTransformPreset = getBaseTransformPreset;
5457
6242
  exports.getConstantType = getConstantType;
5458
- exports.getInnerRange = getInnerRange;
5459
6243
  exports.getMemoedVNodeCall = getMemoedVNodeCall;
5460
6244
  exports.getVNodeBlockHelper = getVNodeBlockHelper;
5461
6245
  exports.getVNodeHelper = getVNodeHelper;
@@ -5463,7 +6247,6 @@ exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
5463
6247
  exports.hasScopeRef = hasScopeRef;
5464
6248
  exports.helperNameMap = helperNameMap;
5465
6249
  exports.injectProp = injectProp;
5466
- exports.isBuiltInType = isBuiltInType;
5467
6250
  exports.isCoreComponent = isCoreComponent;
5468
6251
  exports.isFunctionType = isFunctionType;
5469
6252
  exports.isInDestructureAssignment = isInDestructureAssignment;