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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,86 +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
- }
15
- function createCompilerError(code, loc, messages, additionalMessage) {
16
- const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
17
- const error = new SyntaxError(String(msg));
18
- error.code = code;
19
- error.loc = loc;
20
- return error;
21
- }
22
- const errorMessages = {
23
- // parse errors
24
- [0]: "Illegal comment.",
25
- [1]: "CDATA section is allowed only in XML context.",
26
- [2]: "Duplicate attribute.",
27
- [3]: "End tag cannot have attributes.",
28
- [4]: "Illegal '/' in tags.",
29
- [5]: "Unexpected EOF in tag.",
30
- [6]: "Unexpected EOF in CDATA section.",
31
- [7]: "Unexpected EOF in comment.",
32
- [8]: "Unexpected EOF in script.",
33
- [9]: "Unexpected EOF in tag.",
34
- [10]: "Incorrectly closed comment.",
35
- [11]: "Incorrectly opened comment.",
36
- [12]: "Illegal tag name. Use '&lt;' to print '<'.",
37
- [13]: "Attribute value was expected.",
38
- [14]: "End tag name was expected.",
39
- [15]: "Whitespace was expected.",
40
- [16]: "Unexpected '<!--' in comment.",
41
- [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
42
- [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
43
- [19]: "Attribute name cannot start with '='.",
44
- [21]: "'<?' is allowed only in XML context.",
45
- [20]: `Unexpected null character.`,
46
- [22]: "Illegal '/' in tags.",
47
- // Vue-specific parse errors
48
- [23]: "Invalid end tag.",
49
- [24]: "Element is missing end tag.",
50
- [25]: "Interpolation end sign was not found.",
51
- [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
52
- [26]: "Legal directive name was expected.",
53
- // transform errors
54
- [28]: `v-if/v-else-if is missing expression.`,
55
- [29]: `v-if/else branches must use unique keys.`,
56
- [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
57
- [31]: `v-for is missing expression.`,
58
- [32]: `v-for has invalid expression.`,
59
- [33]: `<template v-for> key should be placed on the <template> tag.`,
60
- [34]: `v-bind is missing expression.`,
61
- [35]: `v-on is missing expression.`,
62
- [36]: `Unexpected custom directive on <slot> outlet.`,
63
- [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.`,
64
- [38]: `Duplicate slot names found. `,
65
- [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
66
- [40]: `v-slot can only be used on components or <template> tags.`,
67
- [41]: `v-model is missing expression.`,
68
- [42]: `v-model value must be a valid JavaScript member expression.`,
69
- [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
70
- [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
71
- Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
72
- [45]: `Error parsing JavaScript expression: `,
73
- [46]: `<KeepAlive> expects exactly one child component.`,
74
- // generic errors
75
- [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
76
- [48]: `ES module mode is not supported in this build of compiler.`,
77
- [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
78
- [50]: `"scopeId" option is only supported in module mode.`,
79
- // deprecations
80
- [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.`,
81
- [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
82
- // just to fulfill types
83
- [53]: ``
84
- };
85
-
86
11
  const FRAGMENT = Symbol(``);
87
12
  const TELEPORT = Symbol(``);
88
13
  const SUSPENSE = Symbol(``);
@@ -172,13 +97,14 @@ function registerRuntimeHelpers(helpers) {
172
97
  }
173
98
 
174
99
  const locStub = {
175
- source: "",
176
100
  start: { line: 1, column: 1, offset: 0 },
177
- end: { line: 1, column: 1, offset: 0 }
101
+ end: { line: 1, column: 1, offset: 0 },
102
+ source: ""
178
103
  };
179
- function createRoot(children, loc = locStub) {
104
+ function createRoot(children, source = "") {
180
105
  return {
181
106
  type: 0,
107
+ source,
182
108
  children,
183
109
  helpers: /* @__PURE__ */ new Set(),
184
110
  components: [],
@@ -188,7 +114,7 @@ function createRoot(children, loc = locStub) {
188
114
  cached: 0,
189
115
  temps: 0,
190
116
  codegenNode: void 0,
191
- loc
117
+ loc: locStub
192
118
  };
193
119
  }
194
120
  function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
@@ -359,17 +285,1028 @@ function convertToBlock(node, { helper, removeHelper, inSSR }) {
359
285
  }
360
286
  }
361
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
+ return enabled;
1203
+ }
1204
+ function warnDeprecation(key, context, loc, ...args) {
1205
+ const val = getCompatValue(key, context);
1206
+ if (val === "suppress-warning") {
1207
+ return;
1208
+ }
1209
+ const { message, link } = deprecationData[key];
1210
+ const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
1211
+ Details: ${link}` : ``}`;
1212
+ const err = new SyntaxError(msg);
1213
+ err.code = key;
1214
+ if (loc)
1215
+ err.loc = loc;
1216
+ context.onWarn(err);
1217
+ }
1218
+
1219
+ function defaultOnError(error) {
1220
+ throw error;
1221
+ }
1222
+ function defaultOnWarn(msg) {
1223
+ }
1224
+ function createCompilerError(code, loc, messages, additionalMessage) {
1225
+ const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
1226
+ const error = new SyntaxError(String(msg));
1227
+ error.code = code;
1228
+ error.loc = loc;
1229
+ return error;
1230
+ }
1231
+ const errorMessages = {
1232
+ // parse errors
1233
+ [0]: "Illegal comment.",
1234
+ [1]: "CDATA section is allowed only in XML context.",
1235
+ [2]: "Duplicate attribute.",
1236
+ [3]: "End tag cannot have attributes.",
1237
+ [4]: "Illegal '/' in tags.",
1238
+ [5]: "Unexpected EOF in tag.",
1239
+ [6]: "Unexpected EOF in CDATA section.",
1240
+ [7]: "Unexpected EOF in comment.",
1241
+ [8]: "Unexpected EOF in script.",
1242
+ [9]: "Unexpected EOF in tag.",
1243
+ [10]: "Incorrectly closed comment.",
1244
+ [11]: "Incorrectly opened comment.",
1245
+ [12]: "Illegal tag name. Use '&lt;' to print '<'.",
1246
+ [13]: "Attribute value was expected.",
1247
+ [14]: "End tag name was expected.",
1248
+ [15]: "Whitespace was expected.",
1249
+ [16]: "Unexpected '<!--' in comment.",
1250
+ [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
1251
+ [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
1252
+ [19]: "Attribute name cannot start with '='.",
1253
+ [21]: "'<?' is allowed only in XML context.",
1254
+ [20]: `Unexpected null character.`,
1255
+ [22]: "Illegal '/' in tags.",
1256
+ // Vue-specific parse errors
1257
+ [23]: "Invalid end tag.",
1258
+ [24]: "Element is missing end tag.",
1259
+ [25]: "Interpolation end sign was not found.",
1260
+ [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
1261
+ [26]: "Legal directive name was expected.",
1262
+ // transform errors
1263
+ [28]: `v-if/v-else-if is missing expression.`,
1264
+ [29]: `v-if/else branches must use unique keys.`,
1265
+ [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
1266
+ [31]: `v-for is missing expression.`,
1267
+ [32]: `v-for has invalid expression.`,
1268
+ [33]: `<template v-for> key should be placed on the <template> tag.`,
1269
+ [34]: `v-bind is missing expression.`,
1270
+ [35]: `v-on is missing expression.`,
1271
+ [36]: `Unexpected custom directive on <slot> outlet.`,
1272
+ [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.`,
1273
+ [38]: `Duplicate slot names found. `,
1274
+ [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
1275
+ [40]: `v-slot can only be used on components or <template> tags.`,
1276
+ [41]: `v-model is missing expression.`,
1277
+ [42]: `v-model value must be a valid JavaScript member expression.`,
1278
+ [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
1279
+ [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
1280
+ Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1281
+ [45]: `Error parsing JavaScript expression: `,
1282
+ [46]: `<KeepAlive> expects exactly one child component.`,
1283
+ // generic errors
1284
+ [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1285
+ [48]: `ES module mode is not supported in this build of compiler.`,
1286
+ [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1287
+ [50]: `"scopeId" option is only supported in module mode.`,
1288
+ // deprecations
1289
+ [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.`,
1290
+ [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
1291
+ // just to fulfill types
1292
+ [53]: ``
1293
+ };
1294
+
362
1295
  const isStaticExp = (p) => p.type === 4 && p.isStatic;
363
- const isBuiltInType = (tag, expected) => tag === expected || tag === shared.hyphenate(expected);
364
1296
  function isCoreComponent(tag) {
365
- if (isBuiltInType(tag, "Teleport")) {
366
- return TELEPORT;
367
- } else if (isBuiltInType(tag, "Suspense")) {
368
- return SUSPENSE;
369
- } else if (isBuiltInType(tag, "KeepAlive")) {
370
- return KEEP_ALIVE;
371
- } else if (isBuiltInType(tag, "BaseTransition")) {
372
- return BASE_TRANSITION;
1297
+ switch (tag) {
1298
+ case "Teleport":
1299
+ case "teleport":
1300
+ return TELEPORT;
1301
+ case "Suspense":
1302
+ case "suspense":
1303
+ return SUSPENSE;
1304
+ case "KeepAlive":
1305
+ case "keep-alive":
1306
+ return KEEP_ALIVE;
1307
+ case "BaseTransition":
1308
+ case "base-transition":
1309
+ return BASE_TRANSITION;
373
1310
  }
374
1311
  }
375
1312
  const nonIdentifierRE = /^\d|[^\$\w]/;
@@ -453,25 +1390,13 @@ const isMemberExpressionNode = (path, context) => {
453
1390
  }
454
1391
  };
455
1392
  const isMemberExpression = isMemberExpressionNode;
456
- function getInnerRange(loc, offset, length) {
457
- const source = loc.source.slice(offset, offset + length);
458
- const newLoc = {
459
- source,
460
- start: advancePositionWithClone(loc.start, loc.source, offset),
461
- end: loc.end
462
- };
463
- if (length != null) {
464
- newLoc.end = advancePositionWithClone(
465
- loc.start,
466
- loc.source,
467
- offset + length
468
- );
469
- }
470
- return newLoc;
471
- }
472
1393
  function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
473
1394
  return advancePositionWithMutation(
474
- shared.extend({}, pos),
1395
+ {
1396
+ offset: pos.offset,
1397
+ line: pos.line,
1398
+ column: pos.column
1399
+ },
475
1400
  source,
476
1401
  numberOfCharacters
477
1402
  );
@@ -672,438 +1597,519 @@ function getMemoedVNodeCall(node) {
672
1597
  return node;
673
1598
  }
674
1599
  }
1600
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
675
1601
 
676
- const deprecationData = {
677
- ["COMPILER_IS_ON_ELEMENT"]: {
678
- 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:".`,
679
- link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
680
- },
681
- ["COMPILER_V_BIND_SYNC"]: {
682
- 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}\`.`,
683
- link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
684
- },
685
- ["COMPILER_V_BIND_PROP"]: {
686
- 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.`
687
- },
688
- ["COMPILER_V_BIND_OBJECT_ORDER"]: {
689
- 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.`,
690
- link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
691
- },
692
- ["COMPILER_V_ON_NATIVE"]: {
693
- message: `.native modifier for v-on has been removed as is no longer necessary.`,
694
- link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
695
- },
696
- ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
697
- 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.`,
698
- link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
699
- },
700
- ["COMPILER_NATIVE_TEMPLATE"]: {
701
- message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
702
- },
703
- ["COMPILER_INLINE_TEMPLATE"]: {
704
- message: `"inline-template" has been removed in Vue 3.`,
705
- link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
706
- },
707
- ["COMPILER_FILTER"]: {
708
- 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.`,
709
- link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
710
- }
711
- };
712
- function getCompatValue(key, context) {
713
- const config = context.options ? context.options.compatConfig : context.compatConfig;
714
- const value = config && config[key];
715
- if (key === "MODE") {
716
- return value || 3;
717
- } else {
718
- return value;
719
- }
720
- }
721
- function isCompatEnabled(key, context) {
722
- const mode = getCompatValue("MODE", context);
723
- const value = getCompatValue(key, context);
724
- return mode === 3 ? value === true : value !== false;
725
- }
726
- function checkCompatEnabled(key, context, loc, ...args) {
727
- const enabled = isCompatEnabled(key, context);
728
- return enabled;
729
- }
730
- function warnDeprecation(key, context, loc, ...args) {
731
- const val = getCompatValue(key, context);
732
- if (val === "suppress-warning") {
733
- return;
734
- }
735
- const { message, link } = deprecationData[key];
736
- const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
737
- Details: ${link}` : ``}`;
738
- const err = new SyntaxError(msg);
739
- err.code = key;
740
- if (loc)
741
- err.loc = loc;
742
- context.onWarn(err);
743
- }
744
-
745
- const decodeRE = /&(gt|lt|amp|apos|quot);/g;
746
- const decodeMap = {
747
- gt: ">",
748
- lt: "<",
749
- amp: "&",
750
- apos: "'",
751
- quot: '"'
752
- };
753
1602
  const defaultParserOptions = {
1603
+ parseMode: "base",
1604
+ ns: 0,
754
1605
  delimiters: [`{{`, `}}`],
755
1606
  getNamespace: () => 0,
756
- getTextMode: () => 0,
757
1607
  isVoidTag: shared.NO,
758
1608
  isPreTag: shared.NO,
759
1609
  isCustomElement: shared.NO,
760
- decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
761
1610
  onError: defaultOnError,
762
1611
  onWarn: defaultOnWarn,
763
1612
  comments: false
764
1613
  };
765
- function baseParse(content, options = {}) {
766
- const context = createParserContext(content, options);
767
- const start = getCursor(context);
768
- return createRoot(
769
- parseChildren(context, 0, []),
770
- getSelection(context, start)
771
- );
772
- }
773
- function createParserContext(content, rawOptions) {
774
- const options = shared.extend({}, defaultParserOptions);
775
- let key;
776
- for (key in rawOptions) {
777
- options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
778
- }
779
- return {
780
- options,
781
- column: 1,
782
- line: 1,
783
- offset: 0,
784
- originalSource: content,
785
- source: content,
786
- inPre: false,
787
- inVPre: false,
788
- onWarn: options.onWarn
789
- };
790
- }
791
- function parseChildren(context, mode, ancestors) {
792
- const parent = last(ancestors);
793
- const ns = parent ? parent.ns : 0;
794
- const nodes = [];
795
- while (!isEnd(context, mode, ancestors)) {
796
- const s = context.source;
797
- let node = void 0;
798
- if (mode === 0 || mode === 1) {
799
- if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
800
- node = parseInterpolation(context, mode);
801
- } else if (mode === 0 && s[0] === "<") {
802
- if (s.length === 1) {
803
- emitError(context, 5, 1);
804
- } else if (s[1] === "!") {
805
- if (startsWith(s, "<!--")) {
806
- node = parseComment(context);
807
- } else if (startsWith(s, "<!DOCTYPE")) {
808
- node = parseBogusComment(context);
809
- } else if (startsWith(s, "<![CDATA[")) {
810
- if (ns !== 0) {
811
- node = parseCDATA(context, ancestors);
812
- } else {
813
- emitError(context, 1);
814
- node = parseBogusComment(context);
815
- }
816
- } else {
817
- emitError(context, 11);
818
- node = parseBogusComment(context);
1614
+ let currentOptions = defaultParserOptions;
1615
+ let currentRoot = null;
1616
+ let currentInput = "";
1617
+ let currentOpenTag = null;
1618
+ let currentProp = null;
1619
+ let currentAttrValue = "";
1620
+ let currentAttrStartIndex = -1;
1621
+ let currentAttrEndIndex = -1;
1622
+ let inPre = 0;
1623
+ let inVPre = false;
1624
+ let currentVPreBoundary = null;
1625
+ const stack = [];
1626
+ const tokenizer = new Tokenizer(stack, {
1627
+ onerr: emitError,
1628
+ ontext(start, end) {
1629
+ onText(getSlice(start, end), start, end);
1630
+ },
1631
+ ontextentity(char, start, end) {
1632
+ onText(char, start, end);
1633
+ },
1634
+ oninterpolation(start, end) {
1635
+ if (inVPre) {
1636
+ return onText(getSlice(start, end), start, end);
1637
+ }
1638
+ let innerStart = start + tokenizer.delimiterOpen.length;
1639
+ let innerEnd = end - tokenizer.delimiterClose.length;
1640
+ while (isWhitespace(currentInput.charCodeAt(innerStart))) {
1641
+ innerStart++;
1642
+ }
1643
+ while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
1644
+ innerEnd--;
1645
+ }
1646
+ let exp = getSlice(innerStart, innerEnd);
1647
+ if (exp.includes("&")) {
1648
+ {
1649
+ exp = decode_js.decodeHTML(exp);
1650
+ }
1651
+ }
1652
+ addNode({
1653
+ type: 5,
1654
+ content: createSimpleExpression(exp, false, getLoc(innerStart, innerEnd)),
1655
+ loc: getLoc(start, end)
1656
+ });
1657
+ },
1658
+ onopentagname(start, end) {
1659
+ const name = getSlice(start, end);
1660
+ currentOpenTag = {
1661
+ type: 1,
1662
+ tag: name,
1663
+ ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
1664
+ tagType: 0,
1665
+ // will be refined on tag close
1666
+ props: [],
1667
+ children: [],
1668
+ loc: getLoc(start - 1, end),
1669
+ codegenNode: void 0
1670
+ };
1671
+ if (tokenizer.inSFCRoot) {
1672
+ currentOpenTag.innerLoc = getLoc(
1673
+ end + fastForward(end) + 1,
1674
+ end
1675
+ );
1676
+ }
1677
+ },
1678
+ onopentagend(end) {
1679
+ endOpenTag(end);
1680
+ },
1681
+ onclosetag(start, end) {
1682
+ const name = getSlice(start, end);
1683
+ if (!currentOptions.isVoidTag(name)) {
1684
+ let found = false;
1685
+ for (let i = 0; i < stack.length; i++) {
1686
+ const e = stack[i];
1687
+ if (e.tag.toLowerCase() === name.toLowerCase()) {
1688
+ found = true;
1689
+ if (i > 0) {
1690
+ emitError(24, stack[0].loc.start.offset);
819
1691
  }
820
- } else if (s[1] === "/") {
821
- if (s.length === 2) {
822
- emitError(context, 5, 2);
823
- } else if (s[2] === ">") {
824
- emitError(context, 14, 2);
825
- advanceBy(context, 3);
826
- continue;
827
- } else if (/[a-z]/i.test(s[2])) {
828
- emitError(context, 23);
829
- parseTag(context, 1 /* End */, parent);
830
- continue;
831
- } else {
832
- emitError(
833
- context,
834
- 12,
835
- 2
836
- );
837
- node = parseBogusComment(context);
1692
+ for (let j = 0; j <= i; j++) {
1693
+ const el = stack.shift();
1694
+ onCloseTag(el, end, j < i);
838
1695
  }
839
- } else if (/[a-z]/i.test(s[1])) {
840
- node = parseElement(context, ancestors);
841
- if (isCompatEnabled(
842
- "COMPILER_NATIVE_TEMPLATE",
843
- context
844
- ) && node && node.tag === "template" && !node.props.some(
845
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
846
- )) {
847
- node = node.children;
1696
+ break;
1697
+ }
1698
+ }
1699
+ if (!found) {
1700
+ emitError(23, backTrack(start, 60));
1701
+ }
1702
+ }
1703
+ },
1704
+ onselfclosingtag(end) {
1705
+ var _a;
1706
+ const name = currentOpenTag.tag;
1707
+ currentOpenTag.isSelfClosing = true;
1708
+ endOpenTag(end);
1709
+ if (((_a = stack[0]) == null ? void 0 : _a.tag) === name) {
1710
+ onCloseTag(stack.shift(), end);
1711
+ }
1712
+ },
1713
+ onattribname(start, end) {
1714
+ currentProp = {
1715
+ type: 6,
1716
+ name: getSlice(start, end),
1717
+ nameLoc: getLoc(start, end),
1718
+ value: void 0,
1719
+ loc: getLoc(start)
1720
+ };
1721
+ },
1722
+ ondirname(start, end) {
1723
+ const raw = getSlice(start, end);
1724
+ const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
1725
+ if (!inVPre && name === "") {
1726
+ emitError(26, start);
1727
+ }
1728
+ if (inVPre || name === "") {
1729
+ currentProp = {
1730
+ type: 6,
1731
+ name: raw,
1732
+ nameLoc: getLoc(start, end),
1733
+ value: void 0,
1734
+ loc: getLoc(start)
1735
+ };
1736
+ } else {
1737
+ currentProp = {
1738
+ type: 7,
1739
+ name,
1740
+ rawName: raw,
1741
+ exp: void 0,
1742
+ arg: void 0,
1743
+ modifiers: raw === "." ? ["prop"] : [],
1744
+ loc: getLoc(start)
1745
+ };
1746
+ if (name === "pre") {
1747
+ inVPre = true;
1748
+ currentVPreBoundary = currentOpenTag;
1749
+ const props = currentOpenTag.props;
1750
+ for (let i = 0; i < props.length; i++) {
1751
+ if (props[i].type === 7) {
1752
+ props[i] = dirToAttr(props[i]);
848
1753
  }
849
- } else if (s[1] === "?") {
850
- emitError(
851
- context,
852
- 21,
853
- 1
854
- );
855
- node = parseBogusComment(context);
856
- } else {
857
- emitError(context, 12, 1);
858
1754
  }
859
1755
  }
860
1756
  }
861
- if (!node) {
862
- node = parseText(context, mode);
1757
+ },
1758
+ ondirarg(start, end) {
1759
+ if (start === end)
1760
+ return;
1761
+ const arg = getSlice(start, end);
1762
+ if (inVPre) {
1763
+ currentProp.name += arg;
1764
+ setLocEnd(currentProp.nameLoc, end);
1765
+ } else {
1766
+ const isStatic = arg[0] !== `[`;
1767
+ currentProp.arg = createSimpleExpression(
1768
+ isStatic ? arg : arg.slice(1, -1),
1769
+ isStatic,
1770
+ getLoc(start, end),
1771
+ isStatic ? 3 : 0
1772
+ );
863
1773
  }
864
- if (shared.isArray(node)) {
865
- for (let i = 0; i < node.length; i++) {
866
- pushNode(nodes, node[i]);
1774
+ },
1775
+ ondirmodifier(start, end) {
1776
+ const mod = getSlice(start, end);
1777
+ if (inVPre) {
1778
+ currentProp.name += "." + mod;
1779
+ setLocEnd(currentProp.nameLoc, end);
1780
+ } else if (currentProp.name === "slot") {
1781
+ const arg = currentProp.arg;
1782
+ if (arg) {
1783
+ arg.content += "." + mod;
1784
+ setLocEnd(arg.loc, end);
867
1785
  }
868
1786
  } else {
869
- pushNode(nodes, node);
1787
+ currentProp.modifiers.push(mod);
870
1788
  }
871
- }
872
- let removedWhitespace = false;
873
- if (mode !== 2 && mode !== 1) {
874
- const shouldCondense = context.options.whitespace !== "preserve";
875
- for (let i = 0; i < nodes.length; i++) {
876
- const node = nodes[i];
877
- if (node.type === 2) {
878
- if (!context.inPre) {
879
- if (!/[^\t\r\n\f ]/.test(node.content)) {
880
- const prev = nodes[i - 1];
881
- const next = nodes[i + 1];
882
- 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))) {
883
- removedWhitespace = true;
884
- nodes[i] = null;
885
- } else {
886
- node.content = " ";
887
- }
888
- } else if (shouldCondense) {
889
- node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
1789
+ },
1790
+ onattribdata(start, end) {
1791
+ currentAttrValue += getSlice(start, end);
1792
+ if (currentAttrStartIndex < 0)
1793
+ currentAttrStartIndex = start;
1794
+ currentAttrEndIndex = end;
1795
+ },
1796
+ onattribentity(char, start, end) {
1797
+ currentAttrValue += char;
1798
+ if (currentAttrStartIndex < 0)
1799
+ currentAttrStartIndex = start;
1800
+ currentAttrEndIndex = end;
1801
+ },
1802
+ onattribnameend(end) {
1803
+ const start = currentProp.loc.start.offset;
1804
+ const name = getSlice(start, end);
1805
+ if (currentProp.type === 7) {
1806
+ currentProp.rawName = name;
1807
+ }
1808
+ if (currentOpenTag.props.some(
1809
+ (p) => (p.type === 7 ? p.rawName : p.name) === name
1810
+ )) {
1811
+ emitError(2, start);
1812
+ }
1813
+ },
1814
+ onattribend(quote, end) {
1815
+ if (currentOpenTag && currentProp) {
1816
+ setLocEnd(currentProp.loc, end);
1817
+ if (quote !== 0) {
1818
+ if (currentProp.type === 6) {
1819
+ if (currentProp.name === "class") {
1820
+ currentAttrValue = condense(currentAttrValue).trim();
1821
+ }
1822
+ if (quote === 1 && !currentAttrValue) {
1823
+ emitError(13, end);
1824
+ }
1825
+ currentProp.value = {
1826
+ type: 2,
1827
+ content: currentAttrValue,
1828
+ loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
1829
+ };
1830
+ if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
1831
+ tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
890
1832
  }
891
1833
  } else {
892
- node.content = node.content.replace(/\r\n/g, "\n");
1834
+ currentProp.exp = createSimpleExpression(
1835
+ currentAttrValue,
1836
+ false,
1837
+ getLoc(currentAttrStartIndex, currentAttrEndIndex)
1838
+ );
1839
+ if (currentProp.name === "for") {
1840
+ currentProp.forParseResult = parseForExpression(currentProp.exp);
1841
+ }
1842
+ let syncIndex = -1;
1843
+ if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
1844
+ "COMPILER_V_BIND_SYNC",
1845
+ currentOptions,
1846
+ currentProp.loc,
1847
+ currentProp.rawName
1848
+ )) {
1849
+ currentProp.name = "model";
1850
+ currentProp.modifiers.splice(syncIndex, 1);
1851
+ }
893
1852
  }
894
- } else if (node.type === 3 && !context.options.comments) {
895
- removedWhitespace = true;
896
- nodes[i] = null;
897
1853
  }
1854
+ if (currentProp.type !== 7 || currentProp.name !== "pre") {
1855
+ currentOpenTag.props.push(currentProp);
1856
+ }
1857
+ }
1858
+ currentAttrValue = "";
1859
+ currentAttrStartIndex = currentAttrEndIndex = -1;
1860
+ },
1861
+ oncomment(start, end) {
1862
+ if (currentOptions.comments) {
1863
+ addNode({
1864
+ type: 3,
1865
+ content: getSlice(start, end),
1866
+ loc: getLoc(start - 4, end + 3)
1867
+ });
1868
+ }
1869
+ },
1870
+ onend() {
1871
+ const end = currentInput.length;
1872
+ if (tokenizer.state !== 1) {
1873
+ switch (tokenizer.state) {
1874
+ case 5:
1875
+ case 8:
1876
+ emitError(5, end);
1877
+ break;
1878
+ case 3:
1879
+ case 4:
1880
+ emitError(
1881
+ 25,
1882
+ tokenizer.sectionStart
1883
+ );
1884
+ break;
1885
+ case 28:
1886
+ if (tokenizer.currentSequence === Sequences.CdataEnd) {
1887
+ emitError(6, end);
1888
+ } else {
1889
+ emitError(7, end);
1890
+ }
1891
+ break;
1892
+ case 6:
1893
+ case 7:
1894
+ case 9:
1895
+ case 11:
1896
+ case 12:
1897
+ case 13:
1898
+ case 14:
1899
+ case 15:
1900
+ case 16:
1901
+ case 17:
1902
+ case 18:
1903
+ case 19:
1904
+ case 20:
1905
+ case 21:
1906
+ emitError(9, end);
1907
+ break;
1908
+ }
1909
+ }
1910
+ for (let index = 0; index < stack.length; index++) {
1911
+ onCloseTag(stack[index], end - 1);
1912
+ emitError(24, stack[index].loc.start.offset);
1913
+ }
1914
+ },
1915
+ oncdata(start, end) {
1916
+ if (stack[0].ns !== 0) {
1917
+ onText(getSlice(start, end), start, end);
1918
+ } else {
1919
+ emitError(1, start - 9);
1920
+ }
1921
+ },
1922
+ onprocessinginstruction(start) {
1923
+ if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
1924
+ emitError(
1925
+ 21,
1926
+ start - 1
1927
+ );
1928
+ }
1929
+ }
1930
+ });
1931
+ const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
1932
+ const stripParensRE = /^\(|\)$/g;
1933
+ function parseForExpression(input) {
1934
+ const loc = input.loc;
1935
+ const exp = input.content;
1936
+ const inMatch = exp.match(forAliasRE);
1937
+ if (!inMatch)
1938
+ return;
1939
+ const [, LHS, RHS] = inMatch;
1940
+ const createAliasExpression = (content, offset) => {
1941
+ const start = loc.start.offset + offset;
1942
+ const end = start + content.length;
1943
+ return createSimpleExpression(content, false, getLoc(start, end));
1944
+ };
1945
+ const result = {
1946
+ source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
1947
+ value: void 0,
1948
+ key: void 0,
1949
+ index: void 0,
1950
+ finalized: false
1951
+ };
1952
+ let valueContent = LHS.trim().replace(stripParensRE, "").trim();
1953
+ const trimmedOffset = LHS.indexOf(valueContent);
1954
+ const iteratorMatch = valueContent.match(forIteratorRE);
1955
+ if (iteratorMatch) {
1956
+ valueContent = valueContent.replace(forIteratorRE, "").trim();
1957
+ const keyContent = iteratorMatch[1].trim();
1958
+ let keyOffset;
1959
+ if (keyContent) {
1960
+ keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
1961
+ result.key = createAliasExpression(keyContent, keyOffset);
898
1962
  }
899
- if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
900
- const first = nodes[0];
901
- if (first && first.type === 2) {
902
- first.content = first.content.replace(/^\r?\n/, "");
1963
+ if (iteratorMatch[2]) {
1964
+ const indexContent = iteratorMatch[2].trim();
1965
+ if (indexContent) {
1966
+ result.index = createAliasExpression(
1967
+ indexContent,
1968
+ exp.indexOf(
1969
+ indexContent,
1970
+ result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
1971
+ )
1972
+ );
903
1973
  }
904
1974
  }
905
1975
  }
906
- return removedWhitespace ? nodes.filter(Boolean) : nodes;
1976
+ if (valueContent) {
1977
+ result.value = createAliasExpression(valueContent, trimmedOffset);
1978
+ }
1979
+ return result;
907
1980
  }
908
- function pushNode(nodes, node) {
909
- if (node.type === 2) {
910
- const prev = last(nodes);
911
- if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
912
- prev.content += node.content;
913
- prev.loc.end = node.loc.end;
914
- prev.loc.source += node.loc.source;
915
- return;
1981
+ function getSlice(start, end) {
1982
+ return currentInput.slice(start, end);
1983
+ }
1984
+ function endOpenTag(end) {
1985
+ addNode(currentOpenTag);
1986
+ const { tag, ns } = currentOpenTag;
1987
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
1988
+ inPre++;
1989
+ }
1990
+ if (currentOptions.isVoidTag(tag)) {
1991
+ onCloseTag(currentOpenTag, end);
1992
+ } else {
1993
+ stack.unshift(currentOpenTag);
1994
+ if (ns === 1 || ns === 2) {
1995
+ tokenizer.inXML = true;
916
1996
  }
917
1997
  }
918
- nodes.push(node);
1998
+ currentOpenTag = null;
919
1999
  }
920
- function parseCDATA(context, ancestors) {
921
- advanceBy(context, 9);
922
- const nodes = parseChildren(context, 3, ancestors);
923
- if (context.source.length === 0) {
924
- emitError(context, 6);
2000
+ function onText(content, start, end) {
2001
+ const parent = stack[0] || currentRoot;
2002
+ const lastNode = parent.children[parent.children.length - 1];
2003
+ if ((lastNode == null ? void 0 : lastNode.type) === 2) {
2004
+ lastNode.content += content;
2005
+ setLocEnd(lastNode.loc, end);
925
2006
  } else {
926
- advanceBy(context, 3);
2007
+ parent.children.push({
2008
+ type: 2,
2009
+ content,
2010
+ loc: getLoc(start, end)
2011
+ });
927
2012
  }
928
- return nodes;
929
2013
  }
930
- function parseComment(context) {
931
- const start = getCursor(context);
932
- let content;
933
- const match = /--(\!)?>/.exec(context.source);
934
- if (!match) {
935
- content = context.source.slice(4);
936
- advanceBy(context, context.source.length);
937
- emitError(context, 7);
2014
+ function onCloseTag(el, end, isImplied = false) {
2015
+ if (isImplied) {
2016
+ setLocEnd(el.loc, backTrack(end, 60));
938
2017
  } else {
939
- if (match.index <= 3) {
940
- emitError(context, 0);
941
- }
942
- if (match[1]) {
943
- emitError(context, 10);
2018
+ setLocEnd(el.loc, end + fastForward(end) + 1);
2019
+ }
2020
+ if (tokenizer.inSFCRoot) {
2021
+ if (el.children.length) {
2022
+ el.innerLoc.end = shared.extend({}, el.children[el.children.length - 1].loc.end);
2023
+ } else {
2024
+ el.innerLoc.end = shared.extend({}, el.innerLoc.start);
944
2025
  }
945
- content = context.source.slice(4, match.index);
946
- const s = context.source.slice(0, match.index);
947
- let prevIndex = 1, nestedIndex = 0;
948
- while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
949
- advanceBy(context, nestedIndex - prevIndex + 1);
950
- if (nestedIndex + 4 < s.length) {
951
- emitError(context, 16);
952
- }
953
- prevIndex = nestedIndex + 1;
2026
+ el.innerLoc.source = getSlice(
2027
+ el.innerLoc.start.offset,
2028
+ el.innerLoc.end.offset
2029
+ );
2030
+ }
2031
+ const { tag, ns } = el;
2032
+ if (!inVPre) {
2033
+ if (tag === "slot") {
2034
+ el.tagType = 2;
2035
+ } else if (isFragmentTemplate(el)) {
2036
+ el.tagType = 3;
2037
+ } else if (isComponent(el)) {
2038
+ el.tagType = 1;
954
2039
  }
955
- advanceBy(context, match.index + match[0].length - prevIndex + 1);
956
2040
  }
957
- return {
958
- type: 3,
959
- content,
960
- loc: getSelection(context, start)
961
- };
962
- }
963
- function parseBogusComment(context) {
964
- const start = getCursor(context);
965
- const contentStart = context.source[1] === "?" ? 1 : 2;
966
- let content;
967
- const closeIndex = context.source.indexOf(">");
968
- if (closeIndex === -1) {
969
- content = context.source.slice(contentStart);
970
- advanceBy(context, context.source.length);
971
- } else {
972
- content = context.source.slice(contentStart, closeIndex);
973
- advanceBy(context, closeIndex + 1);
2041
+ if (!tokenizer.inRCDATA) {
2042
+ el.children = condenseWhitespace(el.children, el.tag);
2043
+ }
2044
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
2045
+ inPre--;
2046
+ }
2047
+ if (currentVPreBoundary === el) {
2048
+ inVPre = false;
2049
+ currentVPreBoundary = null;
2050
+ }
2051
+ if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2052
+ tokenizer.inXML = false;
974
2053
  }
975
- return {
976
- type: 3,
977
- content,
978
- loc: getSelection(context, start)
979
- };
980
- }
981
- function parseElement(context, ancestors) {
982
- const wasInPre = context.inPre;
983
- const wasInVPre = context.inVPre;
984
- const parent = last(ancestors);
985
- const element = parseTag(context, 0 /* Start */, parent);
986
- const isPreBoundary = context.inPre && !wasInPre;
987
- const isVPreBoundary = context.inVPre && !wasInVPre;
988
- if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
989
- if (isPreBoundary) {
990
- context.inPre = false;
991
- }
992
- if (isVPreBoundary) {
993
- context.inVPre = false;
994
- }
995
- return element;
996
- }
997
- ancestors.push(element);
998
- const mode = context.options.getTextMode(element, parent);
999
- const children = parseChildren(context, mode, ancestors);
1000
- ancestors.pop();
1001
2054
  {
1002
- const inlineTemplateProp = element.props.find(
2055
+ const props = el.props;
2056
+ if (isCompatEnabled(
2057
+ "COMPILER_NATIVE_TEMPLATE",
2058
+ currentOptions
2059
+ ) && el.tag === "template" && !isFragmentTemplate(el)) {
2060
+ const parent = stack[0] || currentRoot;
2061
+ const index = parent.children.indexOf(el);
2062
+ parent.children.splice(index, 1, ...el.children);
2063
+ }
2064
+ const inlineTemplateProp = props.find(
1003
2065
  (p) => p.type === 6 && p.name === "inline-template"
1004
2066
  );
1005
2067
  if (inlineTemplateProp && checkCompatEnabled(
1006
2068
  "COMPILER_INLINE_TEMPLATE",
1007
- context,
2069
+ currentOptions,
1008
2070
  inlineTemplateProp.loc
1009
- )) {
1010
- const loc = getSelection(context, element.loc.end);
2071
+ ) && el.children.length) {
1011
2072
  inlineTemplateProp.value = {
1012
2073
  type: 2,
1013
- content: loc.source,
1014
- loc
2074
+ content: getSlice(
2075
+ el.children[0].loc.start.offset,
2076
+ el.children[el.children.length - 1].loc.end.offset
2077
+ ),
2078
+ loc: inlineTemplateProp.loc
1015
2079
  };
1016
2080
  }
1017
2081
  }
1018
- element.children = children;
1019
- if (startsWithEndTagOpen(context.source, element.tag)) {
1020
- parseTag(context, 1 /* End */, parent);
1021
- } else {
1022
- emitError(context, 24, 0, element.loc.start);
1023
- if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
1024
- const first = children[0];
1025
- if (first && startsWith(first.loc.source, "<!--")) {
1026
- emitError(context, 8);
1027
- }
1028
- }
1029
- }
1030
- element.loc = getSelection(context, element.loc.start);
1031
- if (isPreBoundary) {
1032
- context.inPre = false;
1033
- }
1034
- if (isVPreBoundary) {
1035
- context.inVPre = false;
1036
- }
1037
- return element;
1038
2082
  }
1039
- const isSpecialTemplateDirective = /* @__PURE__ */ shared.makeMap(
1040
- `if,else,else-if,for,slot`
1041
- );
1042
- function parseTag(context, type, parent) {
1043
- const start = getCursor(context);
1044
- const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
1045
- const tag = match[1];
1046
- const ns = context.options.getNamespace(tag, parent);
1047
- advanceBy(context, match[0].length);
1048
- advanceSpaces(context);
1049
- const cursor = getCursor(context);
1050
- const currentSource = context.source;
1051
- if (context.options.isPreTag(tag)) {
1052
- context.inPre = true;
1053
- }
1054
- let props = parseAttributes(context, type);
1055
- if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
1056
- context.inVPre = true;
1057
- shared.extend(context, cursor);
1058
- context.source = currentSource;
1059
- props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
1060
- }
1061
- let isSelfClosing = false;
1062
- if (context.source.length === 0) {
1063
- emitError(context, 9);
1064
- } else {
1065
- isSelfClosing = startsWith(context.source, "/>");
1066
- if (type === 1 /* End */ && isSelfClosing) {
1067
- emitError(context, 4);
1068
- }
1069
- advanceBy(context, isSelfClosing ? 2 : 1);
1070
- }
1071
- if (type === 1 /* End */) {
1072
- return;
2083
+ function fastForward(start, c) {
2084
+ let offset = 0;
2085
+ while (currentInput.charCodeAt(start + offset) !== 62 && start + offset < currentInput.length) {
2086
+ offset++;
1073
2087
  }
1074
- let tagType = 0;
1075
- if (!context.inVPre) {
1076
- if (tag === "slot") {
1077
- tagType = 2;
1078
- } else if (tag === "template") {
1079
- if (props.some(
1080
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
1081
- )) {
1082
- tagType = 3;
2088
+ return offset;
2089
+ }
2090
+ function backTrack(index, c) {
2091
+ let i = index;
2092
+ while (currentInput.charCodeAt(i) !== c && i >= 0)
2093
+ i--;
2094
+ return i;
2095
+ }
2096
+ const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
2097
+ function isFragmentTemplate({ tag, props }) {
2098
+ if (tag === "template") {
2099
+ for (let i = 0; i < props.length; i++) {
2100
+ if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
2101
+ return true;
1083
2102
  }
1084
- } else if (isComponent(tag, props, context)) {
1085
- tagType = 1;
1086
2103
  }
1087
2104
  }
1088
- return {
1089
- type: 1,
1090
- ns,
1091
- tag,
1092
- tagType,
1093
- props,
1094
- isSelfClosing,
1095
- children: [],
1096
- loc: getSelection(context, start),
1097
- codegenNode: void 0
1098
- // to be created during transform phase
1099
- };
2105
+ return false;
1100
2106
  }
1101
- function isComponent(tag, props, context) {
1102
- const options = context.options;
1103
- if (options.isCustomElement(tag)) {
2107
+ function isComponent({ tag, props }) {
2108
+ var _a;
2109
+ if (currentOptions.isCustomElement(tag)) {
1104
2110
  return false;
1105
2111
  }
1106
- if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
2112
+ if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
1107
2113
  return true;
1108
2114
  }
1109
2115
  for (let i = 0; i < props.length; i++) {
@@ -1114,367 +2120,172 @@ function isComponent(tag, props, context) {
1114
2120
  return true;
1115
2121
  } else if (checkCompatEnabled(
1116
2122
  "COMPILER_IS_ON_ELEMENT",
1117
- context,
2123
+ currentOptions,
1118
2124
  p.loc
1119
2125
  )) {
1120
2126
  return true;
1121
2127
  }
1122
2128
  }
1123
- } else {
1124
- if (p.name === "is") {
1125
- return true;
1126
- } else if (
1127
- // :is on plain element - only treat as component in compat mode
1128
- p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
1129
- "COMPILER_IS_ON_ELEMENT",
1130
- context,
1131
- p.loc
1132
- )
1133
- ) {
1134
- return true;
1135
- }
2129
+ } else if (// :is on plain element - only treat as component in compat mode
2130
+ p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
2131
+ "COMPILER_IS_ON_ELEMENT",
2132
+ currentOptions,
2133
+ p.loc
2134
+ )) {
2135
+ return true;
1136
2136
  }
1137
2137
  }
2138
+ return false;
1138
2139
  }
1139
- function parseAttributes(context, type) {
1140
- const props = [];
1141
- const attributeNames = /* @__PURE__ */ new Set();
1142
- while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
1143
- if (startsWith(context.source, "/")) {
1144
- emitError(context, 22);
1145
- advanceBy(context, 1);
1146
- advanceSpaces(context);
1147
- continue;
1148
- }
1149
- if (type === 1 /* End */) {
1150
- emitError(context, 3);
1151
- }
1152
- const attr = parseAttribute(context, attributeNames);
1153
- if (attr.type === 6 && attr.value && attr.name === "class") {
1154
- attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
1155
- }
1156
- if (type === 0 /* Start */) {
1157
- props.push(attr);
1158
- }
1159
- if (/^[^\t\r\n\f />]/.test(context.source)) {
1160
- emitError(context, 15);
1161
- }
1162
- advanceSpaces(context);
1163
- }
1164
- return props;
2140
+ function isUpperCase(c) {
2141
+ return c > 64 && c < 91;
1165
2142
  }
1166
- function parseAttribute(context, nameSet) {
1167
- var _a;
1168
- const start = getCursor(context);
1169
- const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
1170
- const name = match[0];
1171
- if (nameSet.has(name)) {
1172
- emitError(context, 2);
1173
- }
1174
- nameSet.add(name);
1175
- if (name[0] === "=") {
1176
- emitError(context, 19);
1177
- }
1178
- {
1179
- const pattern = /["'<]/g;
1180
- let m;
1181
- while (m = pattern.exec(name)) {
1182
- emitError(
1183
- context,
1184
- 17,
1185
- m.index
1186
- );
1187
- }
1188
- }
1189
- advanceBy(context, name.length);
1190
- let value = void 0;
1191
- if (/^[\t\r\n\f ]*=/.test(context.source)) {
1192
- advanceSpaces(context);
1193
- advanceBy(context, 1);
1194
- advanceSpaces(context);
1195
- value = parseAttributeValue(context);
1196
- if (!value) {
1197
- emitError(context, 13);
1198
- }
1199
- }
1200
- const loc = getSelection(context, start);
1201
- if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
1202
- const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
1203
- name
1204
- );
1205
- let isPropShorthand = startsWith(name, ".");
1206
- let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
1207
- let arg;
1208
- if (match2[2]) {
1209
- const isSlot = dirName === "slot";
1210
- const startOffset = name.lastIndexOf(
1211
- match2[2],
1212
- name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
1213
- );
1214
- const loc2 = getSelection(
1215
- context,
1216
- getNewPosition(context, start, startOffset),
1217
- getNewPosition(
1218
- context,
1219
- start,
1220
- startOffset + match2[2].length + (isSlot && match2[3] || "").length
1221
- )
1222
- );
1223
- let content = match2[2];
1224
- let isStatic = true;
1225
- if (content.startsWith("[")) {
1226
- isStatic = false;
1227
- if (!content.endsWith("]")) {
1228
- emitError(
1229
- context,
1230
- 27
1231
- );
1232
- content = content.slice(1);
1233
- } else {
1234
- content = content.slice(1, content.length - 1);
2143
+ const windowsNewlineRE = /\r\n/g;
2144
+ function condenseWhitespace(nodes, tag) {
2145
+ var _a, _b;
2146
+ const shouldCondense = currentOptions.whitespace !== "preserve";
2147
+ let removedWhitespace = false;
2148
+ for (let i = 0; i < nodes.length; i++) {
2149
+ const node = nodes[i];
2150
+ if (node.type === 2) {
2151
+ if (!inPre) {
2152
+ if (isAllWhitespace(node.content)) {
2153
+ const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
2154
+ const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
2155
+ if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2156
+ removedWhitespace = true;
2157
+ nodes[i] = null;
2158
+ } else {
2159
+ node.content = " ";
2160
+ }
2161
+ } else if (shouldCondense) {
2162
+ node.content = condense(node.content);
1235
2163
  }
1236
- } else if (isSlot) {
1237
- content += match2[3] || "";
1238
- }
1239
- arg = {
1240
- type: 4,
1241
- content,
1242
- isStatic,
1243
- constType: isStatic ? 3 : 0,
1244
- loc: loc2
1245
- };
1246
- }
1247
- if (value && value.isQuoted) {
1248
- const valueLoc = value.loc;
1249
- valueLoc.start.offset++;
1250
- valueLoc.start.column++;
1251
- valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
1252
- valueLoc.source = valueLoc.source.slice(1, -1);
1253
- }
1254
- const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
1255
- if (isPropShorthand)
1256
- modifiers.push("prop");
1257
- if (dirName === "bind" && arg) {
1258
- if (modifiers.includes("sync") && checkCompatEnabled(
1259
- "COMPILER_V_BIND_SYNC",
1260
- context,
1261
- loc,
1262
- arg.loc.source
1263
- )) {
1264
- dirName = "model";
1265
- modifiers.splice(modifiers.indexOf("sync"), 1);
2164
+ } else {
2165
+ node.content = node.content.replace(windowsNewlineRE, "\n");
1266
2166
  }
1267
2167
  }
1268
- return {
1269
- type: 7,
1270
- name: dirName,
1271
- exp: value && {
1272
- type: 4,
1273
- content: value.content,
1274
- isStatic: false,
1275
- // Treat as non-constant by default. This can be potentially set to
1276
- // other values by `transformExpression` to make it eligible for hoisting.
1277
- constType: 0,
1278
- loc: value.loc
1279
- },
1280
- arg,
1281
- modifiers,
1282
- loc
1283
- };
1284
2168
  }
1285
- if (!context.inVPre && startsWith(name, "v-")) {
1286
- emitError(context, 26);
2169
+ if (inPre && tag && currentOptions.isPreTag(tag)) {
2170
+ const first = nodes[0];
2171
+ if (first && first.type === 2) {
2172
+ first.content = first.content.replace(/^\r?\n/, "");
2173
+ }
1287
2174
  }
1288
- return {
1289
- type: 6,
1290
- name,
1291
- value: value && {
1292
- type: 2,
1293
- content: value.content,
1294
- loc: value.loc
1295
- },
1296
- loc
1297
- };
2175
+ return removedWhitespace ? nodes.filter(Boolean) : nodes;
1298
2176
  }
1299
- function parseAttributeValue(context) {
1300
- const start = getCursor(context);
1301
- let content;
1302
- const quote = context.source[0];
1303
- const isQuoted = quote === `"` || quote === `'`;
1304
- if (isQuoted) {
1305
- advanceBy(context, 1);
1306
- const endIndex = context.source.indexOf(quote);
1307
- if (endIndex === -1) {
1308
- content = parseTextData(
1309
- context,
1310
- context.source.length,
1311
- 4
1312
- );
1313
- } else {
1314
- content = parseTextData(context, endIndex, 4);
1315
- advanceBy(context, 1);
1316
- }
1317
- } else {
1318
- const match = /^[^\t\r\n\f >]+/.exec(context.source);
1319
- if (!match) {
1320
- return void 0;
1321
- }
1322
- const unexpectedChars = /["'<=`]/g;
1323
- let m;
1324
- while (m = unexpectedChars.exec(match[0])) {
1325
- emitError(
1326
- context,
1327
- 18,
1328
- m.index
1329
- );
2177
+ function isAllWhitespace(str) {
2178
+ for (let i = 0; i < str.length; i++) {
2179
+ if (!isWhitespace(str.charCodeAt(i))) {
2180
+ return false;
1330
2181
  }
1331
- content = parseTextData(context, match[0].length, 4);
1332
- }
1333
- return { content, isQuoted, loc: getSelection(context, start) };
1334
- }
1335
- function parseInterpolation(context, mode) {
1336
- const [open, close] = context.options.delimiters;
1337
- const closeIndex = context.source.indexOf(close, open.length);
1338
- if (closeIndex === -1) {
1339
- emitError(context, 25);
1340
- return void 0;
1341
- }
1342
- const start = getCursor(context);
1343
- advanceBy(context, open.length);
1344
- const innerStart = getCursor(context);
1345
- const innerEnd = getCursor(context);
1346
- const rawContentLength = closeIndex - open.length;
1347
- const rawContent = context.source.slice(0, rawContentLength);
1348
- const preTrimContent = parseTextData(context, rawContentLength, mode);
1349
- const content = preTrimContent.trim();
1350
- const startOffset = preTrimContent.indexOf(content);
1351
- if (startOffset > 0) {
1352
- advancePositionWithMutation(innerStart, rawContent, startOffset);
1353
- }
1354
- const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
1355
- advancePositionWithMutation(innerEnd, rawContent, endOffset);
1356
- advanceBy(context, close.length);
1357
- return {
1358
- type: 5,
1359
- content: {
1360
- type: 4,
1361
- isStatic: false,
1362
- // Set `isConstant` to false by default and will decide in transformExpression
1363
- constType: 0,
1364
- content,
1365
- loc: getSelection(context, innerStart, innerEnd)
1366
- },
1367
- loc: getSelection(context, start)
1368
- };
2182
+ }
2183
+ return true;
1369
2184
  }
1370
- function parseText(context, mode) {
1371
- const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
1372
- let endIndex = context.source.length;
1373
- for (let i = 0; i < endTokens.length; i++) {
1374
- const index = context.source.indexOf(endTokens[i], 1);
1375
- if (index !== -1 && endIndex > index) {
1376
- endIndex = index;
2185
+ function hasNewlineChar(str) {
2186
+ for (let i = 0; i < str.length; i++) {
2187
+ const c = str.charCodeAt(i);
2188
+ if (c === 10 || c === 13) {
2189
+ return true;
1377
2190
  }
1378
2191
  }
1379
- const start = getCursor(context);
1380
- const content = parseTextData(context, endIndex, mode);
1381
- return {
1382
- type: 2,
1383
- content,
1384
- loc: getSelection(context, start)
1385
- };
2192
+ return false;
1386
2193
  }
1387
- function parseTextData(context, length, mode) {
1388
- const rawText = context.source.slice(0, length);
1389
- advanceBy(context, length);
1390
- if (mode === 2 || mode === 3 || !rawText.includes("&")) {
1391
- return rawText;
1392
- } else {
1393
- return context.options.decodeEntities(
1394
- rawText,
1395
- mode === 4
1396
- );
2194
+ function condense(str) {
2195
+ let ret = "";
2196
+ let prevCharIsWhitespace = false;
2197
+ for (let i = 0; i < str.length; i++) {
2198
+ if (isWhitespace(str.charCodeAt(i))) {
2199
+ if (!prevCharIsWhitespace) {
2200
+ ret += " ";
2201
+ prevCharIsWhitespace = true;
2202
+ }
2203
+ } else {
2204
+ ret += str[i];
2205
+ prevCharIsWhitespace = false;
2206
+ }
1397
2207
  }
2208
+ return ret;
1398
2209
  }
1399
- function getCursor(context) {
1400
- const { column, line, offset } = context;
1401
- return { column, line, offset };
2210
+ function addNode(node) {
2211
+ (stack[0] || currentRoot).children.push(node);
1402
2212
  }
1403
- function getSelection(context, start, end) {
1404
- end = end || getCursor(context);
2213
+ function getLoc(start, end) {
1405
2214
  return {
1406
- start,
1407
- end,
1408
- source: context.originalSource.slice(start.offset, end.offset)
2215
+ start: tokenizer.getPos(start),
2216
+ // @ts-expect-error allow late attachment
2217
+ end: end == null ? end : tokenizer.getPos(end),
2218
+ // @ts-expect-error allow late attachment
2219
+ source: end == null ? end : getSlice(start, end)
1409
2220
  };
1410
2221
  }
1411
- function last(xs) {
1412
- return xs[xs.length - 1];
1413
- }
1414
- function startsWith(source, searchString) {
1415
- return source.startsWith(searchString);
1416
- }
1417
- function advanceBy(context, numberOfCharacters) {
1418
- const { source } = context;
1419
- advancePositionWithMutation(context, source, numberOfCharacters);
1420
- context.source = source.slice(numberOfCharacters);
2222
+ function setLocEnd(loc, end) {
2223
+ loc.end = tokenizer.getPos(end);
2224
+ loc.source = getSlice(loc.start.offset, end);
1421
2225
  }
1422
- function advanceSpaces(context) {
1423
- const match = /^[\t\r\n\f ]+/.exec(context.source);
1424
- if (match) {
1425
- advanceBy(context, match[0].length);
1426
- }
1427
- }
1428
- function getNewPosition(context, start, numberOfCharacters) {
1429
- return advancePositionWithClone(
1430
- start,
1431
- context.originalSource.slice(start.offset, numberOfCharacters),
1432
- numberOfCharacters
1433
- );
1434
- }
1435
- function emitError(context, code, offset, loc = getCursor(context)) {
1436
- if (offset) {
1437
- loc.offset += offset;
1438
- loc.column += offset;
1439
- }
1440
- context.options.onError(
1441
- createCompilerError(code, {
1442
- start: loc,
1443
- end: loc,
1444
- source: ""
1445
- })
1446
- );
1447
- }
1448
- function isEnd(context, mode, ancestors) {
1449
- const s = context.source;
1450
- switch (mode) {
1451
- case 0:
1452
- if (startsWith(s, "</")) {
1453
- for (let i = ancestors.length - 1; i >= 0; --i) {
1454
- if (startsWithEndTagOpen(s, ancestors[i].tag)) {
1455
- return true;
1456
- }
1457
- }
1458
- }
1459
- break;
1460
- case 1:
1461
- case 2: {
1462
- const parent = last(ancestors);
1463
- if (parent && startsWithEndTagOpen(s, parent.tag)) {
1464
- return true;
1465
- }
1466
- break;
1467
- }
1468
- case 3:
1469
- if (startsWith(s, "]]>")) {
1470
- return true;
1471
- }
1472
- break;
2226
+ function dirToAttr(dir) {
2227
+ const attr = {
2228
+ type: 6,
2229
+ name: dir.rawName,
2230
+ nameLoc: getLoc(
2231
+ dir.loc.start.offset,
2232
+ dir.loc.start.offset + dir.rawName.length
2233
+ ),
2234
+ value: void 0,
2235
+ loc: dir.loc
2236
+ };
2237
+ if (dir.exp) {
2238
+ const loc = dir.exp.loc;
2239
+ if (loc.end.offset < dir.loc.end.offset) {
2240
+ loc.start.offset--;
2241
+ loc.start.column--;
2242
+ loc.end.offset++;
2243
+ loc.end.column++;
2244
+ }
2245
+ attr.value = {
2246
+ type: 2,
2247
+ content: dir.exp.content,
2248
+ loc
2249
+ };
1473
2250
  }
1474
- return !s;
1475
- }
1476
- function startsWithEndTagOpen(source, tag) {
1477
- return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
2251
+ return attr;
2252
+ }
2253
+ function emitError(code, index) {
2254
+ currentOptions.onError(createCompilerError(code, getLoc(index, index)));
2255
+ }
2256
+ function reset() {
2257
+ tokenizer.reset();
2258
+ currentOpenTag = null;
2259
+ currentProp = null;
2260
+ currentAttrValue = "";
2261
+ currentAttrStartIndex = -1;
2262
+ currentAttrEndIndex = -1;
2263
+ stack.length = 0;
2264
+ }
2265
+ function baseParse(input, options) {
2266
+ reset();
2267
+ currentInput = input;
2268
+ currentOptions = shared.extend({}, defaultParserOptions);
2269
+ if (options) {
2270
+ let key;
2271
+ for (key in options) {
2272
+ if (options[key] != null) {
2273
+ currentOptions[key] = options[key];
2274
+ }
2275
+ }
2276
+ }
2277
+ tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2278
+ const delimiters = options == null ? void 0 : options.delimiters;
2279
+ if (delimiters) {
2280
+ tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2281
+ tokenizer.delimiterClose = toCharCodes(delimiters[1]);
2282
+ }
2283
+ const root = currentRoot = createRoot([], input);
2284
+ tokenizer.parse(currentInput);
2285
+ root.loc = getLoc(0, input.length);
2286
+ root.children = condenseWhitespace(root.children);
2287
+ currentRoot = null;
2288
+ return root;
1478
2289
  }
1479
2290
 
1480
2291
  function hoistStatic(root, context) {
@@ -1900,6 +2711,7 @@ function transform(root, options) {
1900
2711
  root.hoists = context.hoists;
1901
2712
  root.temps = context.temps;
1902
2713
  root.cached = context.cached;
2714
+ root.transformed = true;
1903
2715
  {
1904
2716
  root.filters = [...context.filters];
1905
2717
  }
@@ -2052,7 +2864,7 @@ function createCodegenContext(ast, {
2052
2864
  ssr,
2053
2865
  isTS,
2054
2866
  inSSR,
2055
- source: ast.loc.source,
2867
+ source: ast.source,
2056
2868
  code: ``,
2057
2869
  column: 1,
2058
2870
  line: 1,
@@ -2063,7 +2875,7 @@ function createCodegenContext(ast, {
2063
2875
  helper(key) {
2064
2876
  return `_${helperNameMap[key]}`;
2065
2877
  },
2066
- push(code, node) {
2878
+ push(code, newlineIndex = -2 /* None */, node) {
2067
2879
  context.code += code;
2068
2880
  if (context.map) {
2069
2881
  if (node) {
@@ -2076,7 +2888,20 @@ function createCodegenContext(ast, {
2076
2888
  }
2077
2889
  addMapping(node.loc.start, name);
2078
2890
  }
2079
- advancePositionWithMutation(context, code);
2891
+ if (newlineIndex === -3 /* Unknown */) {
2892
+ advancePositionWithMutation(context, code);
2893
+ } else {
2894
+ context.offset += code.length;
2895
+ if (newlineIndex === -2 /* None */) {
2896
+ context.column += code.length;
2897
+ } else {
2898
+ if (newlineIndex === -1 /* End */) {
2899
+ newlineIndex = code.length - 1;
2900
+ }
2901
+ context.line++;
2902
+ context.column = code.length - newlineIndex;
2903
+ }
2904
+ }
2080
2905
  if (node && node.loc !== locStub) {
2081
2906
  addMapping(node.loc.end);
2082
2907
  }
@@ -2097,26 +2922,27 @@ function createCodegenContext(ast, {
2097
2922
  }
2098
2923
  };
2099
2924
  function newline(n) {
2100
- context.push("\n" + ` `.repeat(n));
2101
- }
2102
- function addMapping(loc, name) {
2103
- context.map.addMapping({
2104
- name,
2105
- source: context.filename,
2106
- original: {
2107
- line: loc.line,
2108
- column: loc.column - 1
2109
- // source-map column is 0 based
2110
- },
2111
- generated: {
2112
- line: context.line,
2113
- column: context.column - 1
2114
- }
2925
+ context.push("\n" + ` `.repeat(n), 0 /* Start */);
2926
+ }
2927
+ function addMapping(loc, name = null) {
2928
+ const { _names, _mappings } = context.map;
2929
+ if (name !== null && !_names.has(name))
2930
+ _names.add(name);
2931
+ _mappings.add({
2932
+ originalLine: loc.line,
2933
+ originalColumn: loc.column - 1,
2934
+ // source-map column is 0 based
2935
+ generatedLine: context.line,
2936
+ generatedColumn: context.column - 1,
2937
+ source: filename,
2938
+ // @ts-ignore it is possible to be null
2939
+ name
2115
2940
  });
2116
2941
  }
2117
2942
  if (sourceMap) {
2118
2943
  context.map = new sourceMapJs.SourceMapGenerator();
2119
2944
  context.map.setSourceContent(filename, context.source);
2945
+ context.map._sources.add(filename);
2120
2946
  }
2121
2947
  return context;
2122
2948
  }
@@ -2161,9 +2987,11 @@ function generate(ast, options = {}) {
2161
2987
  push(`with (_ctx) {`);
2162
2988
  indent();
2163
2989
  if (hasHelpers) {
2164
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
2165
- push(`
2166
- `);
2990
+ push(
2991
+ `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
2992
+ `,
2993
+ -1 /* End */
2994
+ );
2167
2995
  newline();
2168
2996
  }
2169
2997
  }
@@ -2192,7 +3020,7 @@ function generate(ast, options = {}) {
2192
3020
  }
2193
3021
  if (ast.components.length || ast.directives.length || ast.temps) {
2194
3022
  push(`
2195
- `);
3023
+ `, 0 /* Start */);
2196
3024
  newline();
2197
3025
  }
2198
3026
  if (!ssr) {
@@ -2213,7 +3041,6 @@ function generate(ast, options = {}) {
2213
3041
  ast,
2214
3042
  code: context.code,
2215
3043
  preamble: isSetupInlined ? preambleContext.code : ``,
2216
- // SourceMapGenerator does have toJSON() method but it's not in the types
2217
3044
  map: context.map ? context.map.toJSON() : void 0
2218
3045
  };
2219
3046
  }
@@ -2231,11 +3058,14 @@ function genFunctionPreamble(ast, context) {
2231
3058
  const helpers = Array.from(ast.helpers);
2232
3059
  if (helpers.length > 0) {
2233
3060
  if (prefixIdentifiers) {
2234
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
2235
- `);
3061
+ push(
3062
+ `const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
3063
+ `,
3064
+ -1 /* End */
3065
+ );
2236
3066
  } else {
2237
3067
  push(`const _Vue = ${VueBinding}
2238
- `);
3068
+ `, -1 /* End */);
2239
3069
  if (ast.hoists.length) {
2240
3070
  const staticHelpers = [
2241
3071
  CREATE_VNODE,
@@ -2245,14 +3075,15 @@ function genFunctionPreamble(ast, context) {
2245
3075
  CREATE_STATIC
2246
3076
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
2247
3077
  push(`const { ${staticHelpers} } = _Vue
2248
- `);
3078
+ `, -1 /* End */);
2249
3079
  }
2250
3080
  }
2251
3081
  }
2252
3082
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2253
3083
  push(
2254
3084
  `const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
2255
- `
3085
+ `,
3086
+ -1 /* End */
2256
3087
  );
2257
3088
  }
2258
3089
  genHoists(ast.hoists, context);
@@ -2276,25 +3107,29 @@ function genModulePreamble(ast, context, genScopeId, inline) {
2276
3107
  if (optimizeImports) {
2277
3108
  push(
2278
3109
  `import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2279
- `
3110
+ `,
3111
+ -1 /* End */
2280
3112
  );
2281
3113
  push(
2282
3114
  `
2283
3115
  // Binding optimization for webpack code-split
2284
3116
  const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
2285
- `
3117
+ `,
3118
+ -1 /* End */
2286
3119
  );
2287
3120
  } else {
2288
3121
  push(
2289
3122
  `import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
2290
- `
3123
+ `,
3124
+ -1 /* End */
2291
3125
  );
2292
3126
  }
2293
3127
  }
2294
3128
  if (ast.ssrHelpers && ast.ssrHelpers.length) {
2295
3129
  push(
2296
3130
  `import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
2297
- `
3131
+ `,
3132
+ -1 /* End */
2298
3133
  );
2299
3134
  }
2300
3135
  if (ast.imports.length) {
@@ -2384,7 +3219,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2384
3219
  for (let i = 0; i < nodes.length; i++) {
2385
3220
  const node = nodes[i];
2386
3221
  if (shared.isString(node)) {
2387
- push(node);
3222
+ push(node, -3 /* Unknown */);
2388
3223
  } else if (shared.isArray(node)) {
2389
3224
  genNodeListAsArray(node, context);
2390
3225
  } else {
@@ -2402,7 +3237,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2402
3237
  }
2403
3238
  function genNode(node, context) {
2404
3239
  if (shared.isString(node)) {
2405
- context.push(node);
3240
+ context.push(node, -3 /* Unknown */);
2406
3241
  return;
2407
3242
  }
2408
3243
  if (shared.isSymbol(node)) {
@@ -2475,11 +3310,15 @@ function genNode(node, context) {
2475
3310
  }
2476
3311
  }
2477
3312
  function genText(node, context) {
2478
- context.push(JSON.stringify(node.content), node);
3313
+ context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
2479
3314
  }
2480
3315
  function genExpression(node, context) {
2481
3316
  const { content, isStatic } = node;
2482
- context.push(isStatic ? JSON.stringify(content) : content, node);
3317
+ context.push(
3318
+ isStatic ? JSON.stringify(content) : content,
3319
+ -3 /* Unknown */,
3320
+ node
3321
+ );
2483
3322
  }
2484
3323
  function genInterpolation(node, context) {
2485
3324
  const { push, helper, pure } = context;
@@ -2493,7 +3332,7 @@ function genCompoundExpression(node, context) {
2493
3332
  for (let i = 0; i < node.children.length; i++) {
2494
3333
  const child = node.children[i];
2495
3334
  if (shared.isString(child)) {
2496
- context.push(child);
3335
+ context.push(child, -3 /* Unknown */);
2497
3336
  } else {
2498
3337
  genNode(child, context);
2499
3338
  }
@@ -2507,9 +3346,9 @@ function genExpressionAsPropertyKey(node, context) {
2507
3346
  push(`]`);
2508
3347
  } else if (node.isStatic) {
2509
3348
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
2510
- push(text, node);
3349
+ push(text, -2 /* None */, node);
2511
3350
  } else {
2512
- push(`[${node.content}]`, node);
3351
+ push(`[${node.content}]`, -3 /* Unknown */, node);
2513
3352
  }
2514
3353
  }
2515
3354
  function genComment(node, context) {
@@ -2517,7 +3356,11 @@ function genComment(node, context) {
2517
3356
  if (pure) {
2518
3357
  push(PURE_ANNOTATION);
2519
3358
  }
2520
- push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
3359
+ push(
3360
+ `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
3361
+ -3 /* Unknown */,
3362
+ node
3363
+ );
2521
3364
  }
2522
3365
  function genVNodeCall(node, context) {
2523
3366
  const { push, helper, pure } = context;
@@ -2542,7 +3385,7 @@ function genVNodeCall(node, context) {
2542
3385
  push(PURE_ANNOTATION);
2543
3386
  }
2544
3387
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
2545
- push(helper(callHelper) + `(`, node);
3388
+ push(helper(callHelper) + `(`, -2 /* None */, node);
2546
3389
  genNodeList(
2547
3390
  genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
2548
3391
  context
@@ -2571,7 +3414,7 @@ function genCallExpression(node, context) {
2571
3414
  if (pure) {
2572
3415
  push(PURE_ANNOTATION);
2573
3416
  }
2574
- push(callee + `(`, node);
3417
+ push(callee + `(`, -2 /* None */, node);
2575
3418
  genNodeList(node.arguments, context);
2576
3419
  push(`)`);
2577
3420
  }
@@ -2579,7 +3422,7 @@ function genObjectExpression(node, context) {
2579
3422
  const { push, indent, deindent, newline } = context;
2580
3423
  const { properties } = node;
2581
3424
  if (!properties.length) {
2582
- push(`{}`, node);
3425
+ push(`{}`, -2 /* None */, node);
2583
3426
  return;
2584
3427
  }
2585
3428
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -2607,7 +3450,7 @@ function genFunctionExpression(node, context) {
2607
3450
  if (isSlot) {
2608
3451
  push(`_${helperNameMap[WITH_CTX]}(`);
2609
3452
  }
2610
- push(`(`, node);
3453
+ push(`(`, -2 /* None */, node);
2611
3454
  if (shared.isArray(params)) {
2612
3455
  genNodeList(params, context);
2613
3456
  } else if (params) {
@@ -2704,7 +3547,7 @@ function genTemplateLiteral(node, context) {
2704
3547
  for (let i = 0; i < l; i++) {
2705
3548
  const e = node.elements[i];
2706
3549
  if (shared.isString(e)) {
2707
- push(e.replace(/(`|\$|\\)/g, "\\$1"));
3550
+ push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
2708
3551
  } else {
2709
3552
  push("${");
2710
3553
  if (multilines)
@@ -2852,6 +3695,15 @@ function walkBlockDeclarations(block, onIdent) {
2852
3695
  if (stmt.declare || !stmt.id)
2853
3696
  continue;
2854
3697
  onIdent(stmt.id);
3698
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
3699
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
3700
+ if (variable && variable.type === "VariableDeclaration") {
3701
+ for (const decl of variable.declarations) {
3702
+ for (const id of extractIdentifiers(decl.id)) {
3703
+ onIdent(id);
3704
+ }
3705
+ }
3706
+ }
2855
3707
  }
2856
3708
  }
2857
3709
  }
@@ -3104,8 +3956,8 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
3104
3956
  const isScopeVarReference = context.identifiers[rawExp];
3105
3957
  const isAllowedGlobal = shared.isGloballyAllowed(rawExp);
3106
3958
  const isLiteral = isLiteralWhitelisted(rawExp);
3107
- if (!asParams && !isScopeVarReference && !isAllowedGlobal && !isLiteral) {
3108
- if (isConst(bindingMetadata[node.content])) {
3959
+ if (!asParams && !isScopeVarReference && !isLiteral && (!isAllowedGlobal || bindingMetadata[rawExp])) {
3960
+ if (isConst(bindingMetadata[rawExp])) {
3109
3961
  node.constType = 1;
3110
3962
  }
3111
3963
  node.content = rewriteIdentifier(rawExp);
@@ -3182,9 +4034,9 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
3182
4034
  id.name,
3183
4035
  false,
3184
4036
  {
3185
- source: source2,
3186
4037
  start: advancePositionWithClone(node.loc.start, source2, start),
3187
- end: advancePositionWithClone(node.loc.start, source2, end)
4038
+ end: advancePositionWithClone(node.loc.start, source2, end),
4039
+ source: source2
3188
4040
  },
3189
4041
  id.isConstant ? 3 : 0
3190
4042
  )
@@ -3589,18 +4441,14 @@ function processFor(node, dir, context, processCodegen) {
3589
4441
  );
3590
4442
  return;
3591
4443
  }
3592
- const parseResult = parseForExpression(
3593
- // can only be simple expression because vFor transform is applied
3594
- // before expression transform.
3595
- dir.exp,
3596
- context
3597
- );
4444
+ const parseResult = dir.forParseResult;
3598
4445
  if (!parseResult) {
3599
4446
  context.onError(
3600
4447
  createCompilerError(32, dir.loc)
3601
4448
  );
3602
4449
  return;
3603
4450
  }
4451
+ finalizeForParseResult(parseResult, context);
3604
4452
  const { addIdentifiers, removeIdentifiers, scopes } = context;
3605
4453
  const { source, value, key, index } = parseResult;
3606
4454
  const forNode = {
@@ -3632,77 +4480,37 @@ function processFor(node, dir, context, processCodegen) {
3632
4480
  onExit();
3633
4481
  };
3634
4482
  }
3635
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
3636
- const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
3637
- const stripParensRE = /^\(|\)$/g;
3638
- function parseForExpression(input, context) {
3639
- const loc = input.loc;
3640
- const exp = input.content;
3641
- const inMatch = exp.match(forAliasRE);
3642
- if (!inMatch)
4483
+ function finalizeForParseResult(result, context) {
4484
+ if (result.finalized)
3643
4485
  return;
3644
- const [, LHS, RHS] = inMatch;
3645
- const result = {
3646
- source: createAliasExpression(
3647
- loc,
3648
- RHS.trim(),
3649
- exp.indexOf(RHS, LHS.length)
3650
- ),
3651
- value: void 0,
3652
- key: void 0,
3653
- index: void 0
3654
- };
3655
4486
  if (context.prefixIdentifiers) {
3656
4487
  result.source = processExpression(
3657
4488
  result.source,
3658
4489
  context
3659
4490
  );
3660
- }
3661
- let valueContent = LHS.trim().replace(stripParensRE, "").trim();
3662
- const trimmedOffset = LHS.indexOf(valueContent);
3663
- const iteratorMatch = valueContent.match(forIteratorRE);
3664
- if (iteratorMatch) {
3665
- valueContent = valueContent.replace(forIteratorRE, "").trim();
3666
- const keyContent = iteratorMatch[1].trim();
3667
- let keyOffset;
3668
- if (keyContent) {
3669
- keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
3670
- result.key = createAliasExpression(loc, keyContent, keyOffset);
3671
- if (context.prefixIdentifiers) {
3672
- result.key = processExpression(result.key, context, true);
3673
- }
4491
+ if (result.key) {
4492
+ result.key = processExpression(
4493
+ result.key,
4494
+ context,
4495
+ true
4496
+ );
3674
4497
  }
3675
- if (iteratorMatch[2]) {
3676
- const indexContent = iteratorMatch[2].trim();
3677
- if (indexContent) {
3678
- result.index = createAliasExpression(
3679
- loc,
3680
- indexContent,
3681
- exp.indexOf(
3682
- indexContent,
3683
- result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
3684
- )
3685
- );
3686
- if (context.prefixIdentifiers) {
3687
- result.index = processExpression(result.index, context, true);
3688
- }
3689
- }
4498
+ if (result.index) {
4499
+ result.index = processExpression(
4500
+ result.index,
4501
+ context,
4502
+ true
4503
+ );
3690
4504
  }
3691
- }
3692
- if (valueContent) {
3693
- result.value = createAliasExpression(loc, valueContent, trimmedOffset);
3694
- if (context.prefixIdentifiers) {
3695
- result.value = processExpression(result.value, context, true);
4505
+ if (result.value) {
4506
+ result.value = processExpression(
4507
+ result.value,
4508
+ context,
4509
+ true
4510
+ );
3696
4511
  }
3697
4512
  }
3698
- return result;
3699
- }
3700
- function createAliasExpression(range, content, offset) {
3701
- return createSimpleExpression(
3702
- content,
3703
- false,
3704
- getInnerRange(range, offset, content.length)
3705
- );
4513
+ result.finalized = true;
3706
4514
  }
3707
4515
  function createForLoopParams({ value, key, index }, memoArgs = []) {
3708
4516
  return createParamsList([value, key, index, ...memoArgs]);
@@ -3738,11 +4546,9 @@ const trackSlotScopes = (node, context) => {
3738
4546
  const trackVForSlotScopes = (node, context) => {
3739
4547
  let vFor;
3740
4548
  if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
3741
- const result = vFor.parseResult = parseForExpression(
3742
- vFor.exp,
3743
- context
3744
- );
4549
+ const result = vFor.forParseResult;
3745
4550
  if (result) {
4551
+ finalizeForParseResult(result, context);
3746
4552
  const { value, key, index } = result;
3747
4553
  const { addIdentifiers, removeIdentifiers } = context;
3748
4554
  value && addIdentifiers(value);
@@ -3819,12 +4625,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3819
4625
  hasDynamicSlots = true;
3820
4626
  }
3821
4627
  const vFor = findDir(slotElement, "for");
3822
- const slotFunction = buildSlotFn(
3823
- slotProps,
3824
- vFor == null ? void 0 : vFor.exp,
3825
- slotChildren,
3826
- slotLoc
3827
- );
4628
+ const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
3828
4629
  let vIf;
3829
4630
  let vElse;
3830
4631
  if (vIf = findDir(slotElement, "if")) {
@@ -3873,8 +4674,9 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3873
4674
  }
3874
4675
  } else if (vFor) {
3875
4676
  hasDynamicSlots = true;
3876
- const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
4677
+ const parseResult = vFor.forParseResult;
3877
4678
  if (parseResult) {
4679
+ finalizeForParseResult(parseResult, context);
3878
4680
  dynamicSlots.push(
3879
4681
  createCallExpression(context.helper(RENDER_LIST), [
3880
4682
  parseResult.source,
@@ -4121,12 +4923,6 @@ function resolveComponentType(node, context, ssr = false) {
4121
4923
  tag = isProp.value.content.slice(4);
4122
4924
  }
4123
4925
  }
4124
- const isDir = !isExplicitDynamic && findDir(node, "is");
4125
- if (isDir && isDir.exp) {
4126
- return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
4127
- isDir.exp
4128
- ]);
4129
- }
4130
4926
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
4131
4927
  if (builtIn) {
4132
4928
  if (!ssr)
@@ -4249,7 +5045,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4249
5045
  for (let i = 0; i < props.length; i++) {
4250
5046
  const prop = props[i];
4251
5047
  if (prop.type === 6) {
4252
- const { loc, name, value } = prop;
5048
+ const { loc, name, nameLoc, value } = prop;
4253
5049
  let isStatic = true;
4254
5050
  if (name === "ref") {
4255
5051
  hasRef = true;
@@ -4282,11 +5078,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4282
5078
  }
4283
5079
  properties.push(
4284
5080
  createObjectProperty(
4285
- createSimpleExpression(
4286
- name,
4287
- true,
4288
- getInnerRange(loc, 0, name.length)
4289
- ),
5081
+ createSimpleExpression(name, true, nameLoc),
4290
5082
  createSimpleExpression(
4291
5083
  value ? value.content : "",
4292
5084
  isStatic,
@@ -4295,7 +5087,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4295
5087
  )
4296
5088
  );
4297
5089
  } else {
4298
- const { name, arg, exp, loc } = prop;
5090
+ const { name, arg, exp, loc, modifiers } = prop;
4299
5091
  const isVBind = name === "bind";
4300
5092
  const isVOn = name === "on";
4301
5093
  if (name === "slot") {
@@ -4367,6 +5159,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4367
5159
  }
4368
5160
  continue;
4369
5161
  }
5162
+ if (isVBind && modifiers.includes("prop")) {
5163
+ patchFlag |= 32;
5164
+ }
4370
5165
  const directiveTransform = context.directiveTransforms[name];
4371
5166
  if (directiveTransform) {
4372
5167
  const { props: props2, needRuntime } = directiveTransform(prop, node, context);
@@ -4764,8 +5559,16 @@ const transformOn = (dir, node, context, augmentor) => {
4764
5559
  };
4765
5560
 
4766
5561
  const transformBind = (dir, _node, context) => {
4767
- const { exp, modifiers, loc } = dir;
5562
+ const { modifiers, loc } = dir;
4768
5563
  const arg = dir.arg;
5564
+ let { exp } = dir;
5565
+ if (!exp && arg.type === 4) {
5566
+ const propName = shared.camelize(arg.content);
5567
+ exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5568
+ {
5569
+ exp = dir.exp = processExpression(exp, context);
5570
+ }
5571
+ }
4769
5572
  if (arg.type !== 4) {
4770
5573
  arg.children.unshift(`(`);
4771
5574
  arg.children.push(`) || ""`);
@@ -5187,7 +5990,7 @@ function getBaseTransformPreset(prefixIdentifiers) {
5187
5990
  }
5188
5991
  ];
5189
5992
  }
5190
- function baseCompile(template, options = {}) {
5993
+ function baseCompile(source, options = {}) {
5191
5994
  const onError = options.onError || defaultOnError;
5192
5995
  const isModuleMode = options.mode === "module";
5193
5996
  const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
@@ -5197,7 +6000,7 @@ function baseCompile(template, options = {}) {
5197
6000
  if (options.scopeId && !isModuleMode) {
5198
6001
  onError(createCompilerError(50));
5199
6002
  }
5200
- const ast = shared.isString(template) ? baseParse(template, options) : template;
6003
+ const ast = shared.isString(source) ? baseParse(source, options) : source;
5201
6004
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
5202
6005
  if (options.isTS) {
5203
6006
  const { expressionPlugins } = options;
@@ -5309,10 +6112,10 @@ exports.errorMessages = errorMessages;
5309
6112
  exports.extractIdentifiers = extractIdentifiers;
5310
6113
  exports.findDir = findDir;
5311
6114
  exports.findProp = findProp;
6115
+ exports.forAliasRE = forAliasRE;
5312
6116
  exports.generate = generate;
5313
6117
  exports.getBaseTransformPreset = getBaseTransformPreset;
5314
6118
  exports.getConstantType = getConstantType;
5315
- exports.getInnerRange = getInnerRange;
5316
6119
  exports.getMemoedVNodeCall = getMemoedVNodeCall;
5317
6120
  exports.getVNodeBlockHelper = getVNodeBlockHelper;
5318
6121
  exports.getVNodeHelper = getVNodeHelper;
@@ -5320,7 +6123,6 @@ exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
5320
6123
  exports.hasScopeRef = hasScopeRef;
5321
6124
  exports.helperNameMap = helperNameMap;
5322
6125
  exports.injectProp = injectProp;
5323
- exports.isBuiltInType = isBuiltInType;
5324
6126
  exports.isCoreComponent = isCoreComponent;
5325
6127
  exports.isFunctionType = isFunctionType;
5326
6128
  exports.isInDestructureAssignment = isInDestructureAssignment;