@vue/compiler-dom 3.4.0-alpha.1 → 3.4.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,6 @@
1
1
  function makeMap(str, expectsLowerCase) {
2
- const map = /* @__PURE__ */ Object.create(null);
3
- const list = str.split(",");
4
- for (let i = 0; i < list.length; i++) {
5
- map[list[i]] = true;
6
- }
7
- return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
2
+ const set = new Set(str.split(","));
3
+ return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
8
4
  }
9
5
 
10
6
  const EMPTY_OBJ = Object.freeze({}) ;
@@ -36,10 +32,6 @@ const camelizeRE = /-(\w)/g;
36
32
  const camelize = cacheStringFunction((str) => {
37
33
  return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
38
34
  });
39
- const hyphenateRE = /\B([A-Z])/g;
40
- const hyphenate = cacheStringFunction(
41
- (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
42
- );
43
35
  const capitalize = cacheStringFunction((str) => {
44
36
  return str.charAt(0).toUpperCase() + str.slice(1);
45
37
  });
@@ -54,7 +46,7 @@ const PatchFlagNames = {
54
46
  [4]: `STYLE`,
55
47
  [8]: `PROPS`,
56
48
  [16]: `FULL_PROPS`,
57
- [32]: `HYDRATE_EVENTS`,
49
+ [32]: `NEED_HYDRATION`,
58
50
  [64]: `STABLE_FRAGMENT`,
59
51
  [128]: `KEYED_FRAGMENT`,
60
52
  [256]: `UNKEYED_FRAGMENT`,
@@ -132,83 +124,6 @@ const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
132
124
  const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
133
125
  const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
134
126
 
135
- function defaultOnError(error) {
136
- throw error;
137
- }
138
- function defaultOnWarn(msg) {
139
- console.warn(`[Vue warn] ${msg.message}`);
140
- }
141
- function createCompilerError(code, loc, messages, additionalMessage) {
142
- const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
143
- const error = new SyntaxError(String(msg));
144
- error.code = code;
145
- error.loc = loc;
146
- return error;
147
- }
148
- const errorMessages = {
149
- // parse errors
150
- [0]: "Illegal comment.",
151
- [1]: "CDATA section is allowed only in XML context.",
152
- [2]: "Duplicate attribute.",
153
- [3]: "End tag cannot have attributes.",
154
- [4]: "Illegal '/' in tags.",
155
- [5]: "Unexpected EOF in tag.",
156
- [6]: "Unexpected EOF in CDATA section.",
157
- [7]: "Unexpected EOF in comment.",
158
- [8]: "Unexpected EOF in script.",
159
- [9]: "Unexpected EOF in tag.",
160
- [10]: "Incorrectly closed comment.",
161
- [11]: "Incorrectly opened comment.",
162
- [12]: "Illegal tag name. Use '&lt;' to print '<'.",
163
- [13]: "Attribute value was expected.",
164
- [14]: "End tag name was expected.",
165
- [15]: "Whitespace was expected.",
166
- [16]: "Unexpected '<!--' in comment.",
167
- [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
168
- [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
169
- [19]: "Attribute name cannot start with '='.",
170
- [21]: "'<?' is allowed only in XML context.",
171
- [20]: `Unexpected null character.`,
172
- [22]: "Illegal '/' in tags.",
173
- // Vue-specific parse errors
174
- [23]: "Invalid end tag.",
175
- [24]: "Element is missing end tag.",
176
- [25]: "Interpolation end sign was not found.",
177
- [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
178
- [26]: "Legal directive name was expected.",
179
- // transform errors
180
- [28]: `v-if/v-else-if is missing expression.`,
181
- [29]: `v-if/else branches must use unique keys.`,
182
- [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
183
- [31]: `v-for is missing expression.`,
184
- [32]: `v-for has invalid expression.`,
185
- [33]: `<template v-for> key should be placed on the <template> tag.`,
186
- [34]: `v-bind is missing expression.`,
187
- [35]: `v-on is missing expression.`,
188
- [36]: `Unexpected custom directive on <slot> outlet.`,
189
- [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.`,
190
- [38]: `Duplicate slot names found. `,
191
- [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
192
- [40]: `v-slot can only be used on components or <template> tags.`,
193
- [41]: `v-model is missing expression.`,
194
- [42]: `v-model value must be a valid JavaScript member expression.`,
195
- [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
196
- [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
197
- Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
198
- [45]: `Error parsing JavaScript expression: `,
199
- [46]: `<KeepAlive> expects exactly one child component.`,
200
- // generic errors
201
- [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
202
- [48]: `ES module mode is not supported in this build of compiler.`,
203
- [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
204
- [50]: `"scopeId" option is only supported in module mode.`,
205
- // deprecations
206
- [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.`,
207
- [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
208
- // just to fulfill types
209
- [53]: ``
210
- };
211
-
212
127
  const FRAGMENT = Symbol(`Fragment` );
213
128
  const TELEPORT = Symbol(`Teleport` );
214
129
  const SUSPENSE = Symbol(`Suspense` );
@@ -298,13 +213,14 @@ function registerRuntimeHelpers(helpers) {
298
213
  }
299
214
 
300
215
  const locStub = {
301
- source: "",
302
216
  start: { line: 1, column: 1, offset: 0 },
303
- end: { line: 1, column: 1, offset: 0 }
217
+ end: { line: 1, column: 1, offset: 0 },
218
+ source: ""
304
219
  };
305
- function createRoot(children, loc = locStub) {
220
+ function createRoot(children, source = "") {
306
221
  return {
307
222
  type: 0,
223
+ source,
308
224
  children,
309
225
  helpers: /* @__PURE__ */ new Set(),
310
226
  components: [],
@@ -314,7 +230,7 @@ function createRoot(children, loc = locStub) {
314
230
  cached: 0,
315
231
  temps: 0,
316
232
  codegenNode: void 0,
317
- loc
233
+ loc: locStub
318
234
  };
319
235
  }
320
236
  function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
@@ -485,166 +401,1107 @@ function convertToBlock(node, { helper, removeHelper, inSSR }) {
485
401
  }
486
402
  }
487
403
 
488
- const isStaticExp = (p) => p.type === 4 && p.isStatic;
489
- const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
490
- function isCoreComponent(tag) {
491
- if (isBuiltInType(tag, "Teleport")) {
492
- return TELEPORT;
493
- } else if (isBuiltInType(tag, "Suspense")) {
494
- return SUSPENSE;
495
- } else if (isBuiltInType(tag, "KeepAlive")) {
496
- return KEEP_ALIVE;
497
- } else if (isBuiltInType(tag, "BaseTransition")) {
498
- return BASE_TRANSITION;
404
+ const defaultDelimitersOpen = new Uint8Array([123, 123]);
405
+ const defaultDelimitersClose = new Uint8Array([125, 125]);
406
+ function isTagStartChar(c) {
407
+ return c >= 97 && c <= 122 || c >= 65 && c <= 90;
408
+ }
409
+ function isWhitespace(c) {
410
+ return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
411
+ }
412
+ function isEndOfTagSection(c) {
413
+ return c === 47 || c === 62 || isWhitespace(c);
414
+ }
415
+ function toCharCodes(str) {
416
+ const ret = new Uint8Array(str.length);
417
+ for (let i = 0; i < str.length; i++) {
418
+ ret[i] = str.charCodeAt(i);
499
419
  }
420
+ return ret;
500
421
  }
501
- const nonIdentifierRE = /^\d|[^\$\w]/;
502
- const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
503
- const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
504
- const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
505
- const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
506
- const isMemberExpressionBrowser = (path) => {
507
- path = path.trim().replace(whitespaceRE, (s) => s.trim());
508
- let state = 0 /* inMemberExp */;
509
- let stateStack = [];
510
- let currentOpenBracketCount = 0;
511
- let currentOpenParensCount = 0;
512
- let currentStringType = null;
513
- for (let i = 0; i < path.length; i++) {
514
- const char = path.charAt(i);
515
- switch (state) {
516
- case 0 /* inMemberExp */:
517
- if (char === "[") {
518
- stateStack.push(state);
519
- state = 1 /* inBrackets */;
520
- currentOpenBracketCount++;
521
- } else if (char === "(") {
522
- stateStack.push(state);
523
- state = 2 /* inParens */;
524
- currentOpenParensCount++;
525
- } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
526
- return false;
527
- }
422
+ const Sequences = {
423
+ Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
424
+ // CDATA[
425
+ CdataEnd: new Uint8Array([93, 93, 62]),
426
+ // ]]>
427
+ CommentEnd: new Uint8Array([45, 45, 62]),
428
+ // `-->`
429
+ ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
430
+ // `<\/script`
431
+ StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
432
+ // `</style`
433
+ TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
434
+ // `</title`
435
+ TextareaEnd: new Uint8Array([
436
+ 60,
437
+ 47,
438
+ 116,
439
+ 101,
440
+ 120,
441
+ 116,
442
+ 97,
443
+ 114,
444
+ 101,
445
+ 97
446
+ ])
447
+ // `</textarea
448
+ };
449
+ class Tokenizer {
450
+ constructor(stack, cbs) {
451
+ this.stack = stack;
452
+ this.cbs = cbs;
453
+ /** The current state the tokenizer is in. */
454
+ this.state = 1;
455
+ /** The read buffer. */
456
+ this.buffer = "";
457
+ /** The beginning of the section that is currently being read. */
458
+ this.sectionStart = 0;
459
+ /** The index within the buffer that we are currently looking at. */
460
+ this.index = 0;
461
+ /** The start of the last entity. */
462
+ this.entityStart = 0;
463
+ /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
464
+ this.baseState = 1;
465
+ /** For special parsing behavior inside of script and style tags. */
466
+ this.inRCDATA = false;
467
+ /** For disabling RCDATA tags handling */
468
+ this.inXML = false;
469
+ /** Reocrd newline positions for fast line / column calculation */
470
+ this.newlines = [];
471
+ this.mode = 0;
472
+ this.delimiterOpen = defaultDelimitersOpen;
473
+ this.delimiterClose = defaultDelimitersClose;
474
+ this.delimiterIndex = -1;
475
+ this.currentSequence = void 0;
476
+ this.sequenceIndex = 0;
477
+ }
478
+ get inSFCRoot() {
479
+ return this.mode === 2 && this.stack.length === 0;
480
+ }
481
+ reset() {
482
+ this.state = 1;
483
+ this.mode = 0;
484
+ this.buffer = "";
485
+ this.sectionStart = 0;
486
+ this.index = 0;
487
+ this.baseState = 1;
488
+ this.currentSequence = void 0;
489
+ this.newlines.length = 0;
490
+ this.delimiterOpen = defaultDelimitersOpen;
491
+ this.delimiterClose = defaultDelimitersClose;
492
+ }
493
+ /**
494
+ * Generate Position object with line / column information using recorded
495
+ * newline positions. We know the index is always going to be an already
496
+ * processed index, so all the newlines up to this index should have been
497
+ * recorded.
498
+ */
499
+ getPos(index) {
500
+ let line = 1;
501
+ let column = index + 1;
502
+ for (let i = this.newlines.length - 1; i >= 0; i--) {
503
+ const newlineIndex = this.newlines[i];
504
+ if (index > newlineIndex) {
505
+ line = i + 2;
506
+ column = index - newlineIndex;
528
507
  break;
529
- case 1 /* inBrackets */:
530
- if (char === `'` || char === `"` || char === "`") {
531
- stateStack.push(state);
532
- state = 3 /* inString */;
533
- currentStringType = char;
534
- } else if (char === `[`) {
535
- currentOpenBracketCount++;
536
- } else if (char === `]`) {
537
- if (!--currentOpenBracketCount) {
538
- state = stateStack.pop();
539
- }
508
+ }
509
+ }
510
+ return {
511
+ column,
512
+ line,
513
+ offset: index
514
+ };
515
+ }
516
+ peek() {
517
+ return this.buffer.charCodeAt(this.index + 1);
518
+ }
519
+ stateText(c) {
520
+ if (c === 60) {
521
+ if (this.index > this.sectionStart) {
522
+ this.cbs.ontext(this.sectionStart, this.index);
523
+ }
524
+ this.state = 5;
525
+ this.sectionStart = this.index;
526
+ } else if (c === this.delimiterOpen[0]) {
527
+ this.state = 2;
528
+ this.delimiterIndex = 0;
529
+ this.stateInterpolationOpen(c);
530
+ }
531
+ }
532
+ stateInterpolationOpen(c) {
533
+ if (c === this.delimiterOpen[this.delimiterIndex]) {
534
+ if (this.delimiterIndex === this.delimiterOpen.length - 1) {
535
+ const start = this.index + 1 - this.delimiterOpen.length;
536
+ if (start > this.sectionStart) {
537
+ this.cbs.ontext(this.sectionStart, start);
540
538
  }
541
- break;
542
- case 2 /* inParens */:
543
- if (char === `'` || char === `"` || char === "`") {
544
- stateStack.push(state);
545
- state = 3 /* inString */;
546
- currentStringType = char;
547
- } else if (char === `(`) {
548
- currentOpenParensCount++;
549
- } else if (char === `)`) {
550
- if (i === path.length - 1) {
551
- return false;
552
- }
553
- if (!--currentOpenParensCount) {
554
- state = stateStack.pop();
555
- }
539
+ this.state = 3;
540
+ this.sectionStart = start;
541
+ } else {
542
+ this.delimiterIndex++;
543
+ }
544
+ } else if (this.inRCDATA) {
545
+ this.state = 32;
546
+ this.stateInRCDATA(c);
547
+ } else {
548
+ this.state = 1;
549
+ this.stateText(c);
550
+ }
551
+ }
552
+ stateInterpolation(c) {
553
+ if (c === this.delimiterClose[0]) {
554
+ this.state = 4;
555
+ this.delimiterIndex = 0;
556
+ this.stateInterpolationClose(c);
557
+ }
558
+ }
559
+ stateInterpolationClose(c) {
560
+ if (c === this.delimiterClose[this.delimiterIndex]) {
561
+ if (this.delimiterIndex === this.delimiterClose.length - 1) {
562
+ this.cbs.oninterpolation(this.sectionStart, this.index + 1);
563
+ if (this.inRCDATA) {
564
+ this.state = 32;
565
+ } else {
566
+ this.state = 1;
556
567
  }
557
- break;
558
- case 3 /* inString */:
559
- if (char === currentStringType) {
560
- state = stateStack.pop();
561
- currentStringType = null;
568
+ this.sectionStart = this.index + 1;
569
+ } else {
570
+ this.delimiterIndex++;
571
+ }
572
+ } else {
573
+ this.state = 3;
574
+ this.stateInterpolation(c);
575
+ }
576
+ }
577
+ stateSpecialStartSequence(c) {
578
+ const isEnd = this.sequenceIndex === this.currentSequence.length;
579
+ const isMatch = isEnd ? (
580
+ // If we are at the end of the sequence, make sure the tag name has ended
581
+ isEndOfTagSection(c)
582
+ ) : (
583
+ // Otherwise, do a case-insensitive comparison
584
+ (c | 32) === this.currentSequence[this.sequenceIndex]
585
+ );
586
+ if (!isMatch) {
587
+ this.inRCDATA = false;
588
+ } else if (!isEnd) {
589
+ this.sequenceIndex++;
590
+ return;
591
+ }
592
+ this.sequenceIndex = 0;
593
+ this.state = 6;
594
+ this.stateInTagName(c);
595
+ }
596
+ /** Look for an end tag. For <title> and <textarea>, also decode entities. */
597
+ stateInRCDATA(c) {
598
+ if (this.sequenceIndex === this.currentSequence.length) {
599
+ if (c === 62 || isWhitespace(c)) {
600
+ const endOfText = this.index - this.currentSequence.length;
601
+ if (this.sectionStart < endOfText) {
602
+ const actualIndex = this.index;
603
+ this.index = endOfText;
604
+ this.cbs.ontext(this.sectionStart, endOfText);
605
+ this.index = actualIndex;
562
606
  }
563
- break;
607
+ this.sectionStart = endOfText + 2;
608
+ this.stateInClosingTagName(c);
609
+ this.inRCDATA = false;
610
+ return;
611
+ }
612
+ this.sequenceIndex = 0;
613
+ }
614
+ if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
615
+ this.sequenceIndex += 1;
616
+ } else if (this.sequenceIndex === 0) {
617
+ if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
618
+ if (c === this.delimiterOpen[0]) {
619
+ this.state = 2;
620
+ this.delimiterIndex = 0;
621
+ this.stateInterpolationOpen(c);
622
+ }
623
+ } else if (this.fastForwardTo(60)) {
624
+ this.sequenceIndex = 1;
625
+ }
626
+ } else {
627
+ this.sequenceIndex = Number(c === 60);
564
628
  }
565
629
  }
566
- return !currentOpenBracketCount && !currentOpenParensCount;
567
- };
568
- const isMemberExpressionNode = NOOP ;
569
- const isMemberExpression = isMemberExpressionBrowser ;
570
- function getInnerRange(loc, offset, length) {
571
- const source = loc.source.slice(offset, offset + length);
572
- const newLoc = {
573
- source,
574
- start: advancePositionWithClone(loc.start, loc.source, offset),
575
- end: loc.end
576
- };
577
- if (length != null) {
578
- newLoc.end = advancePositionWithClone(
579
- loc.start,
580
- loc.source,
581
- offset + length
582
- );
630
+ stateCDATASequence(c) {
631
+ if (c === Sequences.Cdata[this.sequenceIndex]) {
632
+ if (++this.sequenceIndex === Sequences.Cdata.length) {
633
+ this.state = 28;
634
+ this.currentSequence = Sequences.CdataEnd;
635
+ this.sequenceIndex = 0;
636
+ this.sectionStart = this.index + 1;
637
+ }
638
+ } else {
639
+ this.sequenceIndex = 0;
640
+ this.state = 23;
641
+ this.stateInDeclaration(c);
642
+ }
643
+ }
644
+ /**
645
+ * When we wait for one specific character, we can speed things up
646
+ * by skipping through the buffer until we find it.
647
+ *
648
+ * @returns Whether the character was found.
649
+ */
650
+ fastForwardTo(c) {
651
+ while (++this.index < this.buffer.length) {
652
+ const cc = this.buffer.charCodeAt(this.index);
653
+ if (cc === 10) {
654
+ this.newlines.push(this.index);
655
+ }
656
+ if (cc === c) {
657
+ return true;
658
+ }
659
+ }
660
+ this.index = this.buffer.length - 1;
661
+ return false;
583
662
  }
584
- return newLoc;
585
- }
586
- function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
587
- return advancePositionWithMutation(
588
- extend({}, pos),
589
- source,
590
- numberOfCharacters
591
- );
592
- }
593
- function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
594
- let linesCount = 0;
595
- let lastNewLinePos = -1;
596
- for (let i = 0; i < numberOfCharacters; i++) {
597
- if (source.charCodeAt(i) === 10) {
598
- linesCount++;
599
- lastNewLinePos = i;
663
+ /**
664
+ * Comments and CDATA end with `-->` and `]]>`.
665
+ *
666
+ * Their common qualities are:
667
+ * - Their end sequences have a distinct character they start with.
668
+ * - That character is then repeated, so we have to check multiple repeats.
669
+ * - All characters but the start character of the sequence can be skipped.
670
+ */
671
+ stateInCommentLike(c) {
672
+ if (c === this.currentSequence[this.sequenceIndex]) {
673
+ if (++this.sequenceIndex === this.currentSequence.length) {
674
+ if (this.currentSequence === Sequences.CdataEnd) {
675
+ this.cbs.oncdata(this.sectionStart, this.index - 2);
676
+ } else {
677
+ this.cbs.oncomment(this.sectionStart, this.index - 2);
678
+ }
679
+ this.sequenceIndex = 0;
680
+ this.sectionStart = this.index + 1;
681
+ this.state = 1;
682
+ }
683
+ } else if (this.sequenceIndex === 0) {
684
+ if (this.fastForwardTo(this.currentSequence[0])) {
685
+ this.sequenceIndex = 1;
686
+ }
687
+ } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
688
+ this.sequenceIndex = 0;
689
+ }
690
+ }
691
+ startSpecial(sequence, offset) {
692
+ this.enterRCDATA(sequence, offset);
693
+ this.state = 31;
694
+ }
695
+ enterRCDATA(sequence, offset) {
696
+ this.inRCDATA = true;
697
+ this.currentSequence = sequence;
698
+ this.sequenceIndex = offset;
699
+ }
700
+ stateBeforeTagName(c) {
701
+ if (c === 33) {
702
+ this.state = 22;
703
+ this.sectionStart = this.index + 1;
704
+ } else if (c === 63) {
705
+ this.state = 24;
706
+ this.sectionStart = this.index + 1;
707
+ } else if (isTagStartChar(c)) {
708
+ this.sectionStart = this.index;
709
+ if (this.mode === 0) {
710
+ this.state = 6;
711
+ } else if (this.inSFCRoot) {
712
+ this.state = 34;
713
+ } else if (!this.inXML) {
714
+ const lower = c | 32;
715
+ if (lower === 116) {
716
+ this.state = 30;
717
+ } else {
718
+ this.state = lower === 115 ? 29 : 6;
719
+ }
720
+ } else {
721
+ this.state = 6;
722
+ }
723
+ } else if (c === 47) {
724
+ this.state = 8;
725
+ } else {
726
+ this.state = 1;
727
+ this.stateText(c);
600
728
  }
601
729
  }
602
- pos.offset += numberOfCharacters;
603
- pos.line += linesCount;
604
- pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
605
- return pos;
606
- }
607
- function assert(condition, msg) {
608
- if (!condition) {
609
- throw new Error(msg || `unexpected compiler condition`);
730
+ stateInTagName(c) {
731
+ if (isEndOfTagSection(c)) {
732
+ this.handleTagName(c);
733
+ }
610
734
  }
611
- }
612
- function findDir(node, name, allowEmpty = false) {
613
- for (let i = 0; i < node.props.length; i++) {
614
- const p = node.props[i];
615
- if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
616
- return p;
735
+ stateInSFCRootTagName(c) {
736
+ if (isEndOfTagSection(c)) {
737
+ const tag = this.buffer.slice(this.sectionStart, this.index);
738
+ if (tag !== "template") {
739
+ this.enterRCDATA(toCharCodes(`</` + tag), 0);
740
+ }
741
+ this.handleTagName(c);
617
742
  }
618
743
  }
619
- }
620
- function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
621
- for (let i = 0; i < node.props.length; i++) {
622
- const p = node.props[i];
623
- if (p.type === 6) {
624
- if (dynamicOnly)
625
- continue;
626
- if (p.name === name && (p.value || allowEmpty)) {
627
- return p;
744
+ handleTagName(c) {
745
+ this.cbs.onopentagname(this.sectionStart, this.index);
746
+ this.sectionStart = -1;
747
+ this.state = 11;
748
+ this.stateBeforeAttrName(c);
749
+ }
750
+ stateBeforeClosingTagName(c) {
751
+ if (isWhitespace(c)) ; else if (c === 62) {
752
+ {
753
+ this.cbs.onerr(14, this.index);
628
754
  }
629
- } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
630
- return p;
755
+ this.state = 1;
756
+ this.sectionStart = this.index + 1;
757
+ } else {
758
+ this.state = isTagStartChar(c) ? 9 : 27;
759
+ this.sectionStart = this.index;
631
760
  }
632
761
  }
633
- }
634
- function isStaticArgOf(arg, name) {
635
- return !!(arg && isStaticExp(arg) && arg.content === name);
636
- }
637
- function hasDynamicKeyVBind(node) {
638
- return node.props.some(
639
- (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
640
- p.arg.type !== 4 || // v-bind:[_ctx.foo]
641
- !p.arg.isStatic)
642
- // v-bind:[foo]
643
- );
644
- }
645
- function isText$1(node) {
646
- return node.type === 5 || node.type === 2;
647
- }
762
+ stateInClosingTagName(c) {
763
+ if (c === 62 || isWhitespace(c)) {
764
+ this.cbs.onclosetag(this.sectionStart, this.index);
765
+ this.sectionStart = -1;
766
+ this.state = 10;
767
+ this.stateAfterClosingTagName(c);
768
+ }
769
+ }
770
+ stateAfterClosingTagName(c) {
771
+ if (c === 62) {
772
+ this.state = 1;
773
+ this.sectionStart = this.index + 1;
774
+ }
775
+ }
776
+ stateBeforeAttrName(c) {
777
+ if (c === 62) {
778
+ this.cbs.onopentagend(this.index);
779
+ if (this.inRCDATA) {
780
+ this.state = 32;
781
+ } else {
782
+ this.state = 1;
783
+ }
784
+ this.sectionStart = this.index + 1;
785
+ } else if (c === 47) {
786
+ this.state = 7;
787
+ if (this.peek() !== 62) {
788
+ this.cbs.onerr(22, this.index);
789
+ }
790
+ } else if (c === 60 && this.peek() === 47) {
791
+ this.cbs.onopentagend(this.index);
792
+ this.state = 5;
793
+ this.sectionStart = this.index;
794
+ } else if (!isWhitespace(c)) {
795
+ if (c === 61) {
796
+ this.cbs.onerr(
797
+ 19,
798
+ this.index
799
+ );
800
+ }
801
+ this.handleAttrStart(c);
802
+ }
803
+ }
804
+ handleAttrStart(c) {
805
+ if (c === 118 && this.peek() === 45) {
806
+ this.state = 13;
807
+ this.sectionStart = this.index;
808
+ } else if (c === 46 || c === 58 || c === 64 || c === 35) {
809
+ this.cbs.ondirname(this.index, this.index + 1);
810
+ this.state = 14;
811
+ this.sectionStart = this.index + 1;
812
+ } else {
813
+ this.state = 12;
814
+ this.sectionStart = this.index;
815
+ }
816
+ }
817
+ stateInSelfClosingTag(c) {
818
+ if (c === 62) {
819
+ this.cbs.onselfclosingtag(this.index);
820
+ this.state = 1;
821
+ this.sectionStart = this.index + 1;
822
+ this.inRCDATA = false;
823
+ } else if (!isWhitespace(c)) {
824
+ this.state = 11;
825
+ this.stateBeforeAttrName(c);
826
+ }
827
+ }
828
+ stateInAttrName(c) {
829
+ if (c === 61 || isEndOfTagSection(c)) {
830
+ this.cbs.onattribname(this.sectionStart, this.index);
831
+ this.handleAttrNameEnd(c);
832
+ } else if (c === 34 || c === 39 || c === 60) {
833
+ this.cbs.onerr(
834
+ 17,
835
+ this.index
836
+ );
837
+ }
838
+ }
839
+ stateInDirName(c) {
840
+ if (c === 61 || isEndOfTagSection(c)) {
841
+ this.cbs.ondirname(this.sectionStart, this.index);
842
+ this.handleAttrNameEnd(c);
843
+ } else if (c === 58) {
844
+ this.cbs.ondirname(this.sectionStart, this.index);
845
+ this.state = 14;
846
+ this.sectionStart = this.index + 1;
847
+ } else if (c === 46) {
848
+ this.cbs.ondirname(this.sectionStart, this.index);
849
+ this.state = 16;
850
+ this.sectionStart = this.index + 1;
851
+ }
852
+ }
853
+ stateInDirArg(c) {
854
+ if (c === 61 || isEndOfTagSection(c)) {
855
+ this.cbs.ondirarg(this.sectionStart, this.index);
856
+ this.handleAttrNameEnd(c);
857
+ } else if (c === 91) {
858
+ this.state = 15;
859
+ } else if (c === 46) {
860
+ this.cbs.ondirarg(this.sectionStart, this.index);
861
+ this.state = 16;
862
+ this.sectionStart = this.index + 1;
863
+ }
864
+ }
865
+ stateInDynamicDirArg(c) {
866
+ if (c === 93) {
867
+ this.state = 14;
868
+ } else if (c === 61 || isEndOfTagSection(c)) {
869
+ this.cbs.ondirarg(this.sectionStart, this.index + 1);
870
+ this.handleAttrNameEnd(c);
871
+ {
872
+ this.cbs.onerr(
873
+ 27,
874
+ this.index
875
+ );
876
+ }
877
+ }
878
+ }
879
+ stateInDirModifier(c) {
880
+ if (c === 61 || isEndOfTagSection(c)) {
881
+ this.cbs.ondirmodifier(this.sectionStart, this.index);
882
+ this.handleAttrNameEnd(c);
883
+ } else if (c === 46) {
884
+ this.cbs.ondirmodifier(this.sectionStart, this.index);
885
+ this.sectionStart = this.index + 1;
886
+ }
887
+ }
888
+ handleAttrNameEnd(c) {
889
+ this.sectionStart = this.index;
890
+ this.state = 17;
891
+ this.cbs.onattribnameend(this.index);
892
+ this.stateAfterAttrName(c);
893
+ }
894
+ stateAfterAttrName(c) {
895
+ if (c === 61) {
896
+ this.state = 18;
897
+ } else if (c === 47 || c === 62) {
898
+ this.cbs.onattribend(0, this.sectionStart);
899
+ this.sectionStart = -1;
900
+ this.state = 11;
901
+ this.stateBeforeAttrName(c);
902
+ } else if (!isWhitespace(c)) {
903
+ this.cbs.onattribend(0, this.sectionStart);
904
+ this.handleAttrStart(c);
905
+ }
906
+ }
907
+ stateBeforeAttrValue(c) {
908
+ if (c === 34) {
909
+ this.state = 19;
910
+ this.sectionStart = this.index + 1;
911
+ } else if (c === 39) {
912
+ this.state = 20;
913
+ this.sectionStart = this.index + 1;
914
+ } else if (!isWhitespace(c)) {
915
+ this.sectionStart = this.index;
916
+ this.state = 21;
917
+ this.stateInAttrValueNoQuotes(c);
918
+ }
919
+ }
920
+ handleInAttrValue(c, quote) {
921
+ if (c === quote || this.fastForwardTo(quote)) {
922
+ this.cbs.onattribdata(this.sectionStart, this.index);
923
+ this.sectionStart = -1;
924
+ this.cbs.onattribend(
925
+ quote === 34 ? 3 : 2,
926
+ this.index + 1
927
+ );
928
+ this.state = 11;
929
+ }
930
+ }
931
+ stateInAttrValueDoubleQuotes(c) {
932
+ this.handleInAttrValue(c, 34);
933
+ }
934
+ stateInAttrValueSingleQuotes(c) {
935
+ this.handleInAttrValue(c, 39);
936
+ }
937
+ stateInAttrValueNoQuotes(c) {
938
+ if (isWhitespace(c) || c === 62) {
939
+ this.cbs.onattribdata(this.sectionStart, this.index);
940
+ this.sectionStart = -1;
941
+ this.cbs.onattribend(1, this.index);
942
+ this.state = 11;
943
+ this.stateBeforeAttrName(c);
944
+ } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
945
+ this.cbs.onerr(
946
+ 18,
947
+ this.index
948
+ );
949
+ } else ;
950
+ }
951
+ stateBeforeDeclaration(c) {
952
+ if (c === 91) {
953
+ this.state = 26;
954
+ this.sequenceIndex = 0;
955
+ } else {
956
+ this.state = c === 45 ? 25 : 23;
957
+ }
958
+ }
959
+ stateInDeclaration(c) {
960
+ if (c === 62 || this.fastForwardTo(62)) {
961
+ this.state = 1;
962
+ this.sectionStart = this.index + 1;
963
+ }
964
+ }
965
+ stateInProcessingInstruction(c) {
966
+ if (c === 62 || this.fastForwardTo(62)) {
967
+ this.cbs.onprocessinginstruction(this.sectionStart, this.index);
968
+ this.state = 1;
969
+ this.sectionStart = this.index + 1;
970
+ }
971
+ }
972
+ stateBeforeComment(c) {
973
+ if (c === 45) {
974
+ this.state = 28;
975
+ this.currentSequence = Sequences.CommentEnd;
976
+ this.sequenceIndex = 2;
977
+ this.sectionStart = this.index + 1;
978
+ } else {
979
+ this.state = 23;
980
+ }
981
+ }
982
+ stateInSpecialComment(c) {
983
+ if (c === 62 || this.fastForwardTo(62)) {
984
+ this.cbs.oncomment(this.sectionStart, this.index);
985
+ this.state = 1;
986
+ this.sectionStart = this.index + 1;
987
+ }
988
+ }
989
+ stateBeforeSpecialS(c) {
990
+ const lower = c | 32;
991
+ if (lower === Sequences.ScriptEnd[3]) {
992
+ this.startSpecial(Sequences.ScriptEnd, 4);
993
+ } else if (lower === Sequences.StyleEnd[3]) {
994
+ this.startSpecial(Sequences.StyleEnd, 4);
995
+ } else {
996
+ this.state = 6;
997
+ this.stateInTagName(c);
998
+ }
999
+ }
1000
+ stateBeforeSpecialT(c) {
1001
+ const lower = c | 32;
1002
+ if (lower === Sequences.TitleEnd[3]) {
1003
+ this.startSpecial(Sequences.TitleEnd, 4);
1004
+ } else if (lower === Sequences.TextareaEnd[3]) {
1005
+ this.startSpecial(Sequences.TextareaEnd, 4);
1006
+ } else {
1007
+ this.state = 6;
1008
+ this.stateInTagName(c);
1009
+ }
1010
+ }
1011
+ startEntity() {
1012
+ }
1013
+ stateInEntity() {
1014
+ }
1015
+ /**
1016
+ * Iterates through the buffer, calling the function corresponding to the current state.
1017
+ *
1018
+ * States that are more likely to be hit are higher up, as a performance improvement.
1019
+ */
1020
+ parse(input) {
1021
+ this.buffer = input;
1022
+ while (this.index < this.buffer.length) {
1023
+ const c = this.buffer.charCodeAt(this.index);
1024
+ if (c === 10) {
1025
+ this.newlines.push(this.index);
1026
+ }
1027
+ switch (this.state) {
1028
+ case 1: {
1029
+ this.stateText(c);
1030
+ break;
1031
+ }
1032
+ case 2: {
1033
+ this.stateInterpolationOpen(c);
1034
+ break;
1035
+ }
1036
+ case 3: {
1037
+ this.stateInterpolation(c);
1038
+ break;
1039
+ }
1040
+ case 4: {
1041
+ this.stateInterpolationClose(c);
1042
+ break;
1043
+ }
1044
+ case 31: {
1045
+ this.stateSpecialStartSequence(c);
1046
+ break;
1047
+ }
1048
+ case 32: {
1049
+ this.stateInRCDATA(c);
1050
+ break;
1051
+ }
1052
+ case 26: {
1053
+ this.stateCDATASequence(c);
1054
+ break;
1055
+ }
1056
+ case 19: {
1057
+ this.stateInAttrValueDoubleQuotes(c);
1058
+ break;
1059
+ }
1060
+ case 12: {
1061
+ this.stateInAttrName(c);
1062
+ break;
1063
+ }
1064
+ case 13: {
1065
+ this.stateInDirName(c);
1066
+ break;
1067
+ }
1068
+ case 14: {
1069
+ this.stateInDirArg(c);
1070
+ break;
1071
+ }
1072
+ case 15: {
1073
+ this.stateInDynamicDirArg(c);
1074
+ break;
1075
+ }
1076
+ case 16: {
1077
+ this.stateInDirModifier(c);
1078
+ break;
1079
+ }
1080
+ case 28: {
1081
+ this.stateInCommentLike(c);
1082
+ break;
1083
+ }
1084
+ case 27: {
1085
+ this.stateInSpecialComment(c);
1086
+ break;
1087
+ }
1088
+ case 11: {
1089
+ this.stateBeforeAttrName(c);
1090
+ break;
1091
+ }
1092
+ case 6: {
1093
+ this.stateInTagName(c);
1094
+ break;
1095
+ }
1096
+ case 34: {
1097
+ this.stateInSFCRootTagName(c);
1098
+ break;
1099
+ }
1100
+ case 9: {
1101
+ this.stateInClosingTagName(c);
1102
+ break;
1103
+ }
1104
+ case 5: {
1105
+ this.stateBeforeTagName(c);
1106
+ break;
1107
+ }
1108
+ case 17: {
1109
+ this.stateAfterAttrName(c);
1110
+ break;
1111
+ }
1112
+ case 20: {
1113
+ this.stateInAttrValueSingleQuotes(c);
1114
+ break;
1115
+ }
1116
+ case 18: {
1117
+ this.stateBeforeAttrValue(c);
1118
+ break;
1119
+ }
1120
+ case 8: {
1121
+ this.stateBeforeClosingTagName(c);
1122
+ break;
1123
+ }
1124
+ case 10: {
1125
+ this.stateAfterClosingTagName(c);
1126
+ break;
1127
+ }
1128
+ case 29: {
1129
+ this.stateBeforeSpecialS(c);
1130
+ break;
1131
+ }
1132
+ case 30: {
1133
+ this.stateBeforeSpecialT(c);
1134
+ break;
1135
+ }
1136
+ case 21: {
1137
+ this.stateInAttrValueNoQuotes(c);
1138
+ break;
1139
+ }
1140
+ case 7: {
1141
+ this.stateInSelfClosingTag(c);
1142
+ break;
1143
+ }
1144
+ case 23: {
1145
+ this.stateInDeclaration(c);
1146
+ break;
1147
+ }
1148
+ case 22: {
1149
+ this.stateBeforeDeclaration(c);
1150
+ break;
1151
+ }
1152
+ case 25: {
1153
+ this.stateBeforeComment(c);
1154
+ break;
1155
+ }
1156
+ case 24: {
1157
+ this.stateInProcessingInstruction(c);
1158
+ break;
1159
+ }
1160
+ case 33: {
1161
+ this.stateInEntity();
1162
+ break;
1163
+ }
1164
+ }
1165
+ this.index++;
1166
+ }
1167
+ this.cleanup();
1168
+ this.finish();
1169
+ }
1170
+ /**
1171
+ * Remove data that has already been consumed from the buffer.
1172
+ */
1173
+ cleanup() {
1174
+ if (this.sectionStart !== this.index) {
1175
+ if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
1176
+ this.cbs.ontext(this.sectionStart, this.index);
1177
+ this.sectionStart = this.index;
1178
+ } else if (this.state === 19 || this.state === 20 || this.state === 21) {
1179
+ this.cbs.onattribdata(this.sectionStart, this.index);
1180
+ this.sectionStart = this.index;
1181
+ }
1182
+ }
1183
+ }
1184
+ finish() {
1185
+ this.handleTrailingData();
1186
+ this.cbs.onend();
1187
+ }
1188
+ /** Handle any trailing data. */
1189
+ handleTrailingData() {
1190
+ const endIndex = this.buffer.length;
1191
+ if (this.sectionStart >= endIndex) {
1192
+ return;
1193
+ }
1194
+ if (this.state === 28) {
1195
+ if (this.currentSequence === Sequences.CdataEnd) {
1196
+ this.cbs.oncdata(this.sectionStart, endIndex);
1197
+ } else {
1198
+ this.cbs.oncomment(this.sectionStart, endIndex);
1199
+ }
1200
+ } 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 {
1201
+ this.cbs.ontext(this.sectionStart, endIndex);
1202
+ }
1203
+ }
1204
+ emitCodePoint(cp, consumed) {
1205
+ }
1206
+ }
1207
+
1208
+ const deprecationData = {
1209
+ ["COMPILER_IS_ON_ELEMENT"]: {
1210
+ 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:".`,
1211
+ link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
1212
+ },
1213
+ ["COMPILER_V_BIND_SYNC"]: {
1214
+ 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}\`.`,
1215
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
1216
+ },
1217
+ ["COMPILER_V_BIND_OBJECT_ORDER"]: {
1218
+ 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.`,
1219
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
1220
+ },
1221
+ ["COMPILER_V_ON_NATIVE"]: {
1222
+ message: `.native modifier for v-on has been removed as is no longer necessary.`,
1223
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
1224
+ },
1225
+ ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
1226
+ 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.`,
1227
+ link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
1228
+ },
1229
+ ["COMPILER_NATIVE_TEMPLATE"]: {
1230
+ message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
1231
+ },
1232
+ ["COMPILER_INLINE_TEMPLATE"]: {
1233
+ message: `"inline-template" has been removed in Vue 3.`,
1234
+ link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
1235
+ },
1236
+ ["COMPILER_FILTER"]: {
1237
+ 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.`,
1238
+ link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
1239
+ }
1240
+ };
1241
+ function getCompatValue(key, { compatConfig }) {
1242
+ const value = compatConfig && compatConfig[key];
1243
+ if (key === "MODE") {
1244
+ return value || 3;
1245
+ } else {
1246
+ return value;
1247
+ }
1248
+ }
1249
+ function isCompatEnabled(key, context) {
1250
+ const mode = getCompatValue("MODE", context);
1251
+ const value = getCompatValue(key, context);
1252
+ return mode === 3 ? value === true : value !== false;
1253
+ }
1254
+ function checkCompatEnabled(key, context, loc, ...args) {
1255
+ const enabled = isCompatEnabled(key, context);
1256
+ if (enabled) {
1257
+ warnDeprecation(key, context, loc, ...args);
1258
+ }
1259
+ return enabled;
1260
+ }
1261
+ function warnDeprecation(key, context, loc, ...args) {
1262
+ const val = getCompatValue(key, context);
1263
+ if (val === "suppress-warning") {
1264
+ return;
1265
+ }
1266
+ const { message, link } = deprecationData[key];
1267
+ const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
1268
+ Details: ${link}` : ``}`;
1269
+ const err = new SyntaxError(msg);
1270
+ err.code = key;
1271
+ if (loc)
1272
+ err.loc = loc;
1273
+ context.onWarn(err);
1274
+ }
1275
+
1276
+ function defaultOnError(error) {
1277
+ throw error;
1278
+ }
1279
+ function defaultOnWarn(msg) {
1280
+ console.warn(`[Vue warn] ${msg.message}`);
1281
+ }
1282
+ function createCompilerError(code, loc, messages, additionalMessage) {
1283
+ const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
1284
+ const error = new SyntaxError(String(msg));
1285
+ error.code = code;
1286
+ error.loc = loc;
1287
+ return error;
1288
+ }
1289
+ const errorMessages = {
1290
+ // parse errors
1291
+ [0]: "Illegal comment.",
1292
+ [1]: "CDATA section is allowed only in XML context.",
1293
+ [2]: "Duplicate attribute.",
1294
+ [3]: "End tag cannot have attributes.",
1295
+ [4]: "Illegal '/' in tags.",
1296
+ [5]: "Unexpected EOF in tag.",
1297
+ [6]: "Unexpected EOF in CDATA section.",
1298
+ [7]: "Unexpected EOF in comment.",
1299
+ [8]: "Unexpected EOF in script.",
1300
+ [9]: "Unexpected EOF in tag.",
1301
+ [10]: "Incorrectly closed comment.",
1302
+ [11]: "Incorrectly opened comment.",
1303
+ [12]: "Illegal tag name. Use '&lt;' to print '<'.",
1304
+ [13]: "Attribute value was expected.",
1305
+ [14]: "End tag name was expected.",
1306
+ [15]: "Whitespace was expected.",
1307
+ [16]: "Unexpected '<!--' in comment.",
1308
+ [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
1309
+ [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
1310
+ [19]: "Attribute name cannot start with '='.",
1311
+ [21]: "'<?' is allowed only in XML context.",
1312
+ [20]: `Unexpected null character.`,
1313
+ [22]: "Illegal '/' in tags.",
1314
+ // Vue-specific parse errors
1315
+ [23]: "Invalid end tag.",
1316
+ [24]: "Element is missing end tag.",
1317
+ [25]: "Interpolation end sign was not found.",
1318
+ [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
1319
+ [26]: "Legal directive name was expected.",
1320
+ // transform errors
1321
+ [28]: `v-if/v-else-if is missing expression.`,
1322
+ [29]: `v-if/else branches must use unique keys.`,
1323
+ [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
1324
+ [31]: `v-for is missing expression.`,
1325
+ [32]: `v-for has invalid expression.`,
1326
+ [33]: `<template v-for> key should be placed on the <template> tag.`,
1327
+ [34]: `v-bind is missing expression.`,
1328
+ [35]: `v-on is missing expression.`,
1329
+ [36]: `Unexpected custom directive on <slot> outlet.`,
1330
+ [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.`,
1331
+ [38]: `Duplicate slot names found. `,
1332
+ [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
1333
+ [40]: `v-slot can only be used on components or <template> tags.`,
1334
+ [41]: `v-model is missing expression.`,
1335
+ [42]: `v-model value must be a valid JavaScript member expression.`,
1336
+ [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
1337
+ [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
1338
+ Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
1339
+ [45]: `Error parsing JavaScript expression: `,
1340
+ [46]: `<KeepAlive> expects exactly one child component.`,
1341
+ // generic errors
1342
+ [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
1343
+ [48]: `ES module mode is not supported in this build of compiler.`,
1344
+ [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
1345
+ [50]: `"scopeId" option is only supported in module mode.`,
1346
+ // deprecations
1347
+ [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.`,
1348
+ [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
1349
+ // just to fulfill types
1350
+ [53]: ``
1351
+ };
1352
+
1353
+ const isStaticExp = (p) => p.type === 4 && p.isStatic;
1354
+ function isCoreComponent(tag) {
1355
+ switch (tag) {
1356
+ case "Teleport":
1357
+ case "teleport":
1358
+ return TELEPORT;
1359
+ case "Suspense":
1360
+ case "suspense":
1361
+ return SUSPENSE;
1362
+ case "KeepAlive":
1363
+ case "keep-alive":
1364
+ return KEEP_ALIVE;
1365
+ case "BaseTransition":
1366
+ case "base-transition":
1367
+ return BASE_TRANSITION;
1368
+ }
1369
+ }
1370
+ const nonIdentifierRE = /^\d|[^\$\w]/;
1371
+ const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
1372
+ const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
1373
+ const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
1374
+ const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
1375
+ const isMemberExpressionBrowser = (path) => {
1376
+ path = path.trim().replace(whitespaceRE, (s) => s.trim());
1377
+ let state = 0 /* inMemberExp */;
1378
+ let stateStack = [];
1379
+ let currentOpenBracketCount = 0;
1380
+ let currentOpenParensCount = 0;
1381
+ let currentStringType = null;
1382
+ for (let i = 0; i < path.length; i++) {
1383
+ const char = path.charAt(i);
1384
+ switch (state) {
1385
+ case 0 /* inMemberExp */:
1386
+ if (char === "[") {
1387
+ stateStack.push(state);
1388
+ state = 1 /* inBrackets */;
1389
+ currentOpenBracketCount++;
1390
+ } else if (char === "(") {
1391
+ stateStack.push(state);
1392
+ state = 2 /* inParens */;
1393
+ currentOpenParensCount++;
1394
+ } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
1395
+ return false;
1396
+ }
1397
+ break;
1398
+ case 1 /* inBrackets */:
1399
+ if (char === `'` || char === `"` || char === "`") {
1400
+ stateStack.push(state);
1401
+ state = 3 /* inString */;
1402
+ currentStringType = char;
1403
+ } else if (char === `[`) {
1404
+ currentOpenBracketCount++;
1405
+ } else if (char === `]`) {
1406
+ if (!--currentOpenBracketCount) {
1407
+ state = stateStack.pop();
1408
+ }
1409
+ }
1410
+ break;
1411
+ case 2 /* inParens */:
1412
+ if (char === `'` || char === `"` || char === "`") {
1413
+ stateStack.push(state);
1414
+ state = 3 /* inString */;
1415
+ currentStringType = char;
1416
+ } else if (char === `(`) {
1417
+ currentOpenParensCount++;
1418
+ } else if (char === `)`) {
1419
+ if (i === path.length - 1) {
1420
+ return false;
1421
+ }
1422
+ if (!--currentOpenParensCount) {
1423
+ state = stateStack.pop();
1424
+ }
1425
+ }
1426
+ break;
1427
+ case 3 /* inString */:
1428
+ if (char === currentStringType) {
1429
+ state = stateStack.pop();
1430
+ currentStringType = null;
1431
+ }
1432
+ break;
1433
+ }
1434
+ }
1435
+ return !currentOpenBracketCount && !currentOpenParensCount;
1436
+ };
1437
+ const isMemberExpressionNode = NOOP ;
1438
+ const isMemberExpression = isMemberExpressionBrowser ;
1439
+ function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
1440
+ return advancePositionWithMutation(
1441
+ {
1442
+ offset: pos.offset,
1443
+ line: pos.line,
1444
+ column: pos.column
1445
+ },
1446
+ source,
1447
+ numberOfCharacters
1448
+ );
1449
+ }
1450
+ function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
1451
+ let linesCount = 0;
1452
+ let lastNewLinePos = -1;
1453
+ for (let i = 0; i < numberOfCharacters; i++) {
1454
+ if (source.charCodeAt(i) === 10) {
1455
+ linesCount++;
1456
+ lastNewLinePos = i;
1457
+ }
1458
+ }
1459
+ pos.offset += numberOfCharacters;
1460
+ pos.line += linesCount;
1461
+ pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
1462
+ return pos;
1463
+ }
1464
+ function assert(condition, msg) {
1465
+ if (!condition) {
1466
+ throw new Error(msg || `unexpected compiler condition`);
1467
+ }
1468
+ }
1469
+ function findDir(node, name, allowEmpty = false) {
1470
+ for (let i = 0; i < node.props.length; i++) {
1471
+ const p = node.props[i];
1472
+ if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
1473
+ return p;
1474
+ }
1475
+ }
1476
+ }
1477
+ function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
1478
+ for (let i = 0; i < node.props.length; i++) {
1479
+ const p = node.props[i];
1480
+ if (p.type === 6) {
1481
+ if (dynamicOnly)
1482
+ continue;
1483
+ if (p.name === name && (p.value || allowEmpty)) {
1484
+ return p;
1485
+ }
1486
+ } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
1487
+ return p;
1488
+ }
1489
+ }
1490
+ }
1491
+ function isStaticArgOf(arg, name) {
1492
+ return !!(arg && isStaticExp(arg) && arg.content === name);
1493
+ }
1494
+ function hasDynamicKeyVBind(node) {
1495
+ return node.props.some(
1496
+ (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
1497
+ p.arg.type !== 4 || // v-bind:[_ctx.foo]
1498
+ !p.arg.isStatic)
1499
+ // v-bind:[foo]
1500
+ );
1501
+ }
1502
+ function isText$1(node) {
1503
+ return node.type === 5 || node.type === 2;
1504
+ }
648
1505
  function isVSlot(p) {
649
1506
  return p.type === 7 && p.name === "slot";
650
1507
  }
@@ -786,471 +1643,560 @@ function getMemoedVNodeCall(node) {
786
1643
  return node;
787
1644
  }
788
1645
  }
1646
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
789
1647
 
790
- const deprecationData = {
791
- ["COMPILER_IS_ON_ELEMENT"]: {
792
- 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:".`,
793
- link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
794
- },
795
- ["COMPILER_V_BIND_SYNC"]: {
796
- 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}\`.`,
797
- link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
798
- },
799
- ["COMPILER_V_BIND_PROP"]: {
800
- 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.`
801
- },
802
- ["COMPILER_V_BIND_OBJECT_ORDER"]: {
803
- 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.`,
804
- link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
805
- },
806
- ["COMPILER_V_ON_NATIVE"]: {
807
- message: `.native modifier for v-on has been removed as is no longer necessary.`,
808
- link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
809
- },
810
- ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
811
- 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.`,
812
- link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
813
- },
814
- ["COMPILER_NATIVE_TEMPLATE"]: {
815
- message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
816
- },
817
- ["COMPILER_INLINE_TEMPLATE"]: {
818
- message: `"inline-template" has been removed in Vue 3.`,
819
- link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
820
- },
821
- ["COMPILER_FILTER"]: {
822
- 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.`,
823
- link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
824
- }
825
- };
826
- function getCompatValue(key, context) {
827
- const config = context.options ? context.options.compatConfig : context.compatConfig;
828
- const value = config && config[key];
829
- if (key === "MODE") {
830
- return value || 3;
831
- } else {
832
- return value;
833
- }
834
- }
835
- function isCompatEnabled(key, context) {
836
- const mode = getCompatValue("MODE", context);
837
- const value = getCompatValue(key, context);
838
- return mode === 3 ? value === true : value !== false;
839
- }
840
- function checkCompatEnabled(key, context, loc, ...args) {
841
- const enabled = isCompatEnabled(key, context);
842
- if (enabled) {
843
- warnDeprecation(key, context, loc, ...args);
844
- }
845
- return enabled;
846
- }
847
- function warnDeprecation(key, context, loc, ...args) {
848
- const val = getCompatValue(key, context);
849
- if (val === "suppress-warning") {
850
- return;
851
- }
852
- const { message, link } = deprecationData[key];
853
- const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
854
- Details: ${link}` : ``}`;
855
- const err = new SyntaxError(msg);
856
- err.code = key;
857
- if (loc)
858
- err.loc = loc;
859
- context.onWarn(err);
860
- }
861
-
862
- const decodeRE = /&(gt|lt|amp|apos|quot);/g;
863
- const decodeMap = {
864
- gt: ">",
865
- lt: "<",
866
- amp: "&",
867
- apos: "'",
868
- quot: '"'
869
- };
870
1648
  const defaultParserOptions = {
1649
+ parseMode: "base",
1650
+ ns: 0,
871
1651
  delimiters: [`{{`, `}}`],
872
1652
  getNamespace: () => 0,
873
- getTextMode: () => 0,
874
1653
  isVoidTag: NO,
875
1654
  isPreTag: NO,
876
1655
  isCustomElement: NO,
877
- decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
878
1656
  onError: defaultOnError,
879
1657
  onWarn: defaultOnWarn,
880
1658
  comments: true
881
1659
  };
882
- function baseParse(content, options = {}) {
883
- const context = createParserContext(content, options);
884
- const start = getCursor(context);
885
- return createRoot(
886
- parseChildren(context, 0, []),
887
- getSelection(context, start)
888
- );
889
- }
890
- function createParserContext(content, rawOptions) {
891
- const options = extend({}, defaultParserOptions);
892
- let key;
893
- for (key in rawOptions) {
894
- options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
895
- }
896
- return {
897
- options,
898
- column: 1,
899
- line: 1,
900
- offset: 0,
901
- originalSource: content,
902
- source: content,
903
- inPre: false,
904
- inVPre: false,
905
- onWarn: options.onWarn
906
- };
907
- }
908
- function parseChildren(context, mode, ancestors) {
909
- const parent = last(ancestors);
910
- const ns = parent ? parent.ns : 0;
911
- const nodes = [];
912
- while (!isEnd(context, mode, ancestors)) {
913
- const s = context.source;
914
- let node = void 0;
915
- if (mode === 0 || mode === 1) {
916
- if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
917
- node = parseInterpolation(context, mode);
918
- } else if (mode === 0 && s[0] === "<") {
919
- if (s.length === 1) {
920
- emitError(context, 5, 1);
921
- } else if (s[1] === "!") {
922
- if (startsWith(s, "<!--")) {
923
- node = parseComment(context);
924
- } else if (startsWith(s, "<!DOCTYPE")) {
925
- node = parseBogusComment(context);
926
- } else if (startsWith(s, "<![CDATA[")) {
927
- if (ns !== 0) {
928
- node = parseCDATA(context, ancestors);
929
- } else {
930
- emitError(context, 1);
931
- node = parseBogusComment(context);
932
- }
933
- } else {
934
- emitError(context, 11);
935
- node = parseBogusComment(context);
1660
+ let currentOptions = defaultParserOptions;
1661
+ let currentRoot = null;
1662
+ let currentInput = "";
1663
+ let currentOpenTag = null;
1664
+ let currentProp = null;
1665
+ let currentAttrValue = "";
1666
+ let currentAttrStartIndex = -1;
1667
+ let currentAttrEndIndex = -1;
1668
+ let inPre = 0;
1669
+ let inVPre = false;
1670
+ let currentVPreBoundary = null;
1671
+ const stack = [];
1672
+ const tokenizer = new Tokenizer(stack, {
1673
+ onerr: emitError,
1674
+ ontext(start, end) {
1675
+ onText(getSlice(start, end), start, end);
1676
+ },
1677
+ ontextentity(char, start, end) {
1678
+ onText(char, start, end);
1679
+ },
1680
+ oninterpolation(start, end) {
1681
+ if (inVPre) {
1682
+ return onText(getSlice(start, end), start, end);
1683
+ }
1684
+ let innerStart = start + tokenizer.delimiterOpen.length;
1685
+ let innerEnd = end - tokenizer.delimiterClose.length;
1686
+ while (isWhitespace(currentInput.charCodeAt(innerStart))) {
1687
+ innerStart++;
1688
+ }
1689
+ while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
1690
+ innerEnd--;
1691
+ }
1692
+ let exp = getSlice(innerStart, innerEnd);
1693
+ if (exp.includes("&")) {
1694
+ {
1695
+ exp = currentOptions.decodeEntities(exp, false);
1696
+ }
1697
+ }
1698
+ addNode({
1699
+ type: 5,
1700
+ content: createSimpleExpression(exp, false, getLoc(innerStart, innerEnd)),
1701
+ loc: getLoc(start, end)
1702
+ });
1703
+ },
1704
+ onopentagname(start, end) {
1705
+ const name = getSlice(start, end);
1706
+ currentOpenTag = {
1707
+ type: 1,
1708
+ tag: name,
1709
+ ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
1710
+ tagType: 0,
1711
+ // will be refined on tag close
1712
+ props: [],
1713
+ children: [],
1714
+ loc: getLoc(start - 1, end),
1715
+ codegenNode: void 0
1716
+ };
1717
+ if (tokenizer.inSFCRoot) {
1718
+ currentOpenTag.innerLoc = getLoc(
1719
+ end + fastForward(end) + 1,
1720
+ end
1721
+ );
1722
+ }
1723
+ },
1724
+ onopentagend(end) {
1725
+ endOpenTag(end);
1726
+ },
1727
+ onclosetag(start, end) {
1728
+ const name = getSlice(start, end);
1729
+ if (!currentOptions.isVoidTag(name)) {
1730
+ let found = false;
1731
+ for (let i = 0; i < stack.length; i++) {
1732
+ const e = stack[i];
1733
+ if (e.tag.toLowerCase() === name.toLowerCase()) {
1734
+ found = true;
1735
+ if (i > 0) {
1736
+ emitError(24, stack[0].loc.start.offset);
936
1737
  }
937
- } else if (s[1] === "/") {
938
- if (s.length === 2) {
939
- emitError(context, 5, 2);
940
- } else if (s[2] === ">") {
941
- emitError(context, 14, 2);
942
- advanceBy(context, 3);
943
- continue;
944
- } else if (/[a-z]/i.test(s[2])) {
945
- emitError(context, 23);
946
- parseTag(context, 1 /* End */, parent);
947
- continue;
948
- } else {
949
- emitError(
950
- context,
951
- 12,
952
- 2
953
- );
954
- node = parseBogusComment(context);
1738
+ for (let j = 0; j <= i; j++) {
1739
+ const el = stack.shift();
1740
+ onCloseTag(el, end, j < i);
955
1741
  }
956
- } else if (/[a-z]/i.test(s[1])) {
957
- node = parseElement(context, ancestors);
958
- if (isCompatEnabled(
959
- "COMPILER_NATIVE_TEMPLATE",
960
- context
961
- ) && node && node.tag === "template" && !node.props.some(
962
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
963
- )) {
964
- warnDeprecation(
965
- "COMPILER_NATIVE_TEMPLATE",
966
- context,
967
- node.loc
968
- );
969
- node = node.children;
1742
+ break;
1743
+ }
1744
+ }
1745
+ if (!found) {
1746
+ emitError(23, backTrack(start, 60));
1747
+ }
1748
+ }
1749
+ },
1750
+ onselfclosingtag(end) {
1751
+ var _a;
1752
+ const name = currentOpenTag.tag;
1753
+ currentOpenTag.isSelfClosing = true;
1754
+ endOpenTag(end);
1755
+ if (((_a = stack[0]) == null ? void 0 : _a.tag) === name) {
1756
+ onCloseTag(stack.shift(), end);
1757
+ }
1758
+ },
1759
+ onattribname(start, end) {
1760
+ currentProp = {
1761
+ type: 6,
1762
+ name: getSlice(start, end),
1763
+ nameLoc: getLoc(start, end),
1764
+ value: void 0,
1765
+ loc: getLoc(start)
1766
+ };
1767
+ },
1768
+ ondirname(start, end) {
1769
+ const raw = getSlice(start, end);
1770
+ const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
1771
+ if (!inVPre && name === "") {
1772
+ emitError(26, start);
1773
+ }
1774
+ if (inVPre || name === "") {
1775
+ currentProp = {
1776
+ type: 6,
1777
+ name: raw,
1778
+ nameLoc: getLoc(start, end),
1779
+ value: void 0,
1780
+ loc: getLoc(start)
1781
+ };
1782
+ } else {
1783
+ currentProp = {
1784
+ type: 7,
1785
+ name,
1786
+ rawName: raw,
1787
+ exp: void 0,
1788
+ arg: void 0,
1789
+ modifiers: raw === "." ? ["prop"] : [],
1790
+ loc: getLoc(start)
1791
+ };
1792
+ if (name === "pre") {
1793
+ inVPre = true;
1794
+ currentVPreBoundary = currentOpenTag;
1795
+ const props = currentOpenTag.props;
1796
+ for (let i = 0; i < props.length; i++) {
1797
+ if (props[i].type === 7) {
1798
+ props[i] = dirToAttr(props[i]);
970
1799
  }
971
- } else if (s[1] === "?") {
972
- emitError(
973
- context,
974
- 21,
975
- 1
976
- );
977
- node = parseBogusComment(context);
978
- } else {
979
- emitError(context, 12, 1);
980
1800
  }
981
1801
  }
982
1802
  }
983
- if (!node) {
984
- node = parseText(context, mode);
1803
+ },
1804
+ ondirarg(start, end) {
1805
+ const arg = getSlice(start, end);
1806
+ if (inVPre) {
1807
+ currentProp.name += arg;
1808
+ setLocEnd(currentProp.nameLoc, end);
1809
+ } else {
1810
+ const isStatic = arg[0] !== `[`;
1811
+ currentProp.arg = createSimpleExpression(
1812
+ isStatic ? arg : arg.slice(1, -1),
1813
+ isStatic,
1814
+ getLoc(start, end),
1815
+ isStatic ? 3 : 0
1816
+ );
985
1817
  }
986
- if (isArray(node)) {
987
- for (let i = 0; i < node.length; i++) {
988
- pushNode(nodes, node[i]);
1818
+ },
1819
+ ondirmodifier(start, end) {
1820
+ const mod = getSlice(start, end);
1821
+ if (inVPre) {
1822
+ currentProp.name += "." + mod;
1823
+ setLocEnd(currentProp.nameLoc, end);
1824
+ } else if (currentProp.name === "slot") {
1825
+ const arg = currentProp.arg;
1826
+ if (arg) {
1827
+ arg.content += "." + mod;
1828
+ setLocEnd(arg.loc, end);
989
1829
  }
990
1830
  } else {
991
- pushNode(nodes, node);
1831
+ currentProp.modifiers.push(mod);
992
1832
  }
993
- }
994
- let removedWhitespace = false;
995
- if (mode !== 2 && mode !== 1) {
996
- const shouldCondense = context.options.whitespace !== "preserve";
997
- for (let i = 0; i < nodes.length; i++) {
998
- const node = nodes[i];
999
- if (node.type === 2) {
1000
- if (!context.inPre) {
1001
- if (!/[^\t\r\n\f ]/.test(node.content)) {
1002
- const prev = nodes[i - 1];
1003
- const next = nodes[i + 1];
1004
- 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))) {
1005
- removedWhitespace = true;
1006
- nodes[i] = null;
1007
- } else {
1008
- node.content = " ";
1009
- }
1010
- } else if (shouldCondense) {
1011
- node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
1833
+ },
1834
+ onattribdata(start, end) {
1835
+ currentAttrValue += getSlice(start, end);
1836
+ if (currentAttrStartIndex < 0)
1837
+ currentAttrStartIndex = start;
1838
+ currentAttrEndIndex = end;
1839
+ },
1840
+ onattribentity(char, start, end) {
1841
+ currentAttrValue += char;
1842
+ if (currentAttrStartIndex < 0)
1843
+ currentAttrStartIndex = start;
1844
+ currentAttrEndIndex = end;
1845
+ },
1846
+ onattribnameend(end) {
1847
+ const start = currentProp.loc.start.offset;
1848
+ const name = getSlice(start, end);
1849
+ if (currentProp.type === 7) {
1850
+ currentProp.rawName = name;
1851
+ }
1852
+ if (currentOpenTag.props.some(
1853
+ (p) => (p.type === 7 ? p.rawName : p.name) === name
1854
+ )) {
1855
+ emitError(2, start);
1856
+ }
1857
+ },
1858
+ onattribend(quote, end) {
1859
+ if (currentOpenTag && currentProp) {
1860
+ setLocEnd(currentProp.loc, end);
1861
+ if (quote !== 0) {
1862
+ if (currentAttrValue.includes("&")) {
1863
+ currentAttrValue = currentOptions.decodeEntities(
1864
+ currentAttrValue,
1865
+ true
1866
+ );
1867
+ }
1868
+ if (currentProp.type === 6) {
1869
+ if (currentProp.name === "class") {
1870
+ currentAttrValue = condense(currentAttrValue).trim();
1871
+ }
1872
+ if (quote === 1 && !currentAttrValue) {
1873
+ emitError(13, end);
1874
+ }
1875
+ currentProp.value = {
1876
+ type: 2,
1877
+ content: currentAttrValue,
1878
+ loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
1879
+ };
1880
+ if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
1881
+ tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
1012
1882
  }
1013
1883
  } else {
1014
- node.content = node.content.replace(/\r\n/g, "\n");
1884
+ currentProp.exp = createSimpleExpression(
1885
+ currentAttrValue,
1886
+ false,
1887
+ getLoc(currentAttrStartIndex, currentAttrEndIndex)
1888
+ );
1889
+ if (currentProp.name === "for") {
1890
+ currentProp.forParseResult = parseForExpression(currentProp.exp);
1891
+ }
1892
+ let syncIndex = -1;
1893
+ if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
1894
+ "COMPILER_V_BIND_SYNC",
1895
+ currentOptions,
1896
+ currentProp.loc,
1897
+ currentProp.rawName
1898
+ )) {
1899
+ currentProp.name = "model";
1900
+ currentProp.modifiers.splice(syncIndex, 1);
1901
+ }
1015
1902
  }
1016
- } else if (node.type === 3 && !context.options.comments) {
1017
- removedWhitespace = true;
1018
- nodes[i] = null;
1019
1903
  }
1904
+ if (currentProp.type !== 7 || currentProp.name !== "pre") {
1905
+ currentOpenTag.props.push(currentProp);
1906
+ }
1907
+ }
1908
+ currentAttrValue = "";
1909
+ currentAttrStartIndex = currentAttrEndIndex = -1;
1910
+ },
1911
+ oncomment(start, end) {
1912
+ if (currentOptions.comments) {
1913
+ addNode({
1914
+ type: 3,
1915
+ content: getSlice(start, end),
1916
+ loc: getLoc(start - 4, end + 3)
1917
+ });
1020
1918
  }
1021
- if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
1022
- const first = nodes[0];
1023
- if (first && first.type === 2) {
1024
- first.content = first.content.replace(/^\r?\n/, "");
1919
+ },
1920
+ onend() {
1921
+ const end = currentInput.length;
1922
+ if (tokenizer.state !== 1) {
1923
+ switch (tokenizer.state) {
1924
+ case 5:
1925
+ case 8:
1926
+ emitError(5, end);
1927
+ break;
1928
+ case 3:
1929
+ case 4:
1930
+ emitError(
1931
+ 25,
1932
+ tokenizer.sectionStart
1933
+ );
1934
+ break;
1935
+ case 28:
1936
+ if (tokenizer.currentSequence === Sequences.CdataEnd) {
1937
+ emitError(6, end);
1938
+ } else {
1939
+ emitError(7, end);
1940
+ }
1941
+ break;
1942
+ case 6:
1943
+ case 7:
1944
+ case 9:
1945
+ case 11:
1946
+ case 12:
1947
+ case 13:
1948
+ case 14:
1949
+ case 15:
1950
+ case 16:
1951
+ case 17:
1952
+ case 18:
1953
+ case 19:
1954
+ case 20:
1955
+ case 21:
1956
+ emitError(9, end);
1957
+ break;
1025
1958
  }
1026
1959
  }
1960
+ for (let index = 0; index < stack.length; index++) {
1961
+ onCloseTag(stack[index], end - 1);
1962
+ emitError(24, stack[index].loc.start.offset);
1963
+ }
1964
+ },
1965
+ oncdata(start, end) {
1966
+ if (stack[0].ns !== 0) {
1967
+ onText(getSlice(start, end), start, end);
1968
+ } else {
1969
+ emitError(1, start - 9);
1970
+ }
1971
+ },
1972
+ onprocessinginstruction(start) {
1973
+ if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
1974
+ emitError(
1975
+ 21,
1976
+ start - 1
1977
+ );
1978
+ }
1027
1979
  }
1028
- return removedWhitespace ? nodes.filter(Boolean) : nodes;
1980
+ });
1981
+ const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
1982
+ const stripParensRE = /^\(|\)$/g;
1983
+ function parseForExpression(input) {
1984
+ const loc = input.loc;
1985
+ const exp = input.content;
1986
+ const inMatch = exp.match(forAliasRE);
1987
+ if (!inMatch)
1988
+ return;
1989
+ const [, LHS, RHS] = inMatch;
1990
+ const createAliasExpression = (content, offset) => {
1991
+ const start = loc.start.offset + offset;
1992
+ const end = start + content.length;
1993
+ return createSimpleExpression(content, false, getLoc(start, end));
1994
+ };
1995
+ const result = {
1996
+ source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
1997
+ value: void 0,
1998
+ key: void 0,
1999
+ index: void 0,
2000
+ finalized: false
2001
+ };
2002
+ let valueContent = LHS.trim().replace(stripParensRE, "").trim();
2003
+ const trimmedOffset = LHS.indexOf(valueContent);
2004
+ const iteratorMatch = valueContent.match(forIteratorRE);
2005
+ if (iteratorMatch) {
2006
+ valueContent = valueContent.replace(forIteratorRE, "").trim();
2007
+ const keyContent = iteratorMatch[1].trim();
2008
+ let keyOffset;
2009
+ if (keyContent) {
2010
+ keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
2011
+ result.key = createAliasExpression(keyContent, keyOffset);
2012
+ }
2013
+ if (iteratorMatch[2]) {
2014
+ const indexContent = iteratorMatch[2].trim();
2015
+ if (indexContent) {
2016
+ result.index = createAliasExpression(
2017
+ indexContent,
2018
+ exp.indexOf(
2019
+ indexContent,
2020
+ result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
2021
+ )
2022
+ );
2023
+ }
2024
+ }
2025
+ }
2026
+ if (valueContent) {
2027
+ result.value = createAliasExpression(valueContent, trimmedOffset);
2028
+ }
2029
+ return result;
1029
2030
  }
1030
- function pushNode(nodes, node) {
1031
- if (node.type === 2) {
1032
- const prev = last(nodes);
1033
- if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
1034
- prev.content += node.content;
1035
- prev.loc.end = node.loc.end;
1036
- prev.loc.source += node.loc.source;
1037
- return;
2031
+ function getSlice(start, end) {
2032
+ return currentInput.slice(start, end);
2033
+ }
2034
+ function endOpenTag(end) {
2035
+ addNode(currentOpenTag);
2036
+ const { tag, ns } = currentOpenTag;
2037
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
2038
+ inPre++;
2039
+ }
2040
+ if (currentOptions.isVoidTag(tag)) {
2041
+ onCloseTag(currentOpenTag, end);
2042
+ } else {
2043
+ stack.unshift(currentOpenTag);
2044
+ if (ns === 1 || ns === 2) {
2045
+ tokenizer.inXML = true;
1038
2046
  }
1039
2047
  }
1040
- nodes.push(node);
2048
+ currentOpenTag = null;
1041
2049
  }
1042
- function parseCDATA(context, ancestors) {
1043
- advanceBy(context, 9);
1044
- const nodes = parseChildren(context, 3, ancestors);
1045
- if (context.source.length === 0) {
1046
- emitError(context, 6);
2050
+ function onText(content, start, end) {
2051
+ var _a;
2052
+ {
2053
+ const tag = (_a = stack[0]) == null ? void 0 : _a.tag;
2054
+ if (tag !== "script" && tag !== "style" && content.includes("&")) {
2055
+ content = currentOptions.decodeEntities(content, false);
2056
+ }
2057
+ }
2058
+ const parent = stack[0] || currentRoot;
2059
+ const lastNode = parent.children[parent.children.length - 1];
2060
+ if ((lastNode == null ? void 0 : lastNode.type) === 2) {
2061
+ lastNode.content += content;
2062
+ setLocEnd(lastNode.loc, end);
1047
2063
  } else {
1048
- advanceBy(context, 3);
2064
+ parent.children.push({
2065
+ type: 2,
2066
+ content,
2067
+ loc: getLoc(start, end)
2068
+ });
1049
2069
  }
1050
- return nodes;
1051
2070
  }
1052
- function parseComment(context) {
1053
- const start = getCursor(context);
1054
- let content;
1055
- const match = /--(\!)?>/.exec(context.source);
1056
- if (!match) {
1057
- content = context.source.slice(4);
1058
- advanceBy(context, context.source.length);
1059
- emitError(context, 7);
2071
+ function onCloseTag(el, end, isImplied = false) {
2072
+ if (isImplied) {
2073
+ setLocEnd(el.loc, backTrack(end, 60));
1060
2074
  } else {
1061
- if (match.index <= 3) {
1062
- emitError(context, 0);
1063
- }
1064
- if (match[1]) {
1065
- emitError(context, 10);
2075
+ setLocEnd(el.loc, end + fastForward(end) + 1);
2076
+ }
2077
+ if (tokenizer.inSFCRoot) {
2078
+ if (el.children.length) {
2079
+ el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
2080
+ } else {
2081
+ el.innerLoc.end = extend({}, el.innerLoc.start);
1066
2082
  }
1067
- content = context.source.slice(4, match.index);
1068
- const s = context.source.slice(0, match.index);
1069
- let prevIndex = 1, nestedIndex = 0;
1070
- while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
1071
- advanceBy(context, nestedIndex - prevIndex + 1);
1072
- if (nestedIndex + 4 < s.length) {
1073
- emitError(context, 16);
1074
- }
1075
- prevIndex = nestedIndex + 1;
2083
+ el.innerLoc.source = getSlice(
2084
+ el.innerLoc.start.offset,
2085
+ el.innerLoc.end.offset
2086
+ );
2087
+ }
2088
+ const { tag, ns } = el;
2089
+ if (!inVPre) {
2090
+ if (tag === "slot") {
2091
+ el.tagType = 2;
2092
+ } else if (isFragmentTemplate(el)) {
2093
+ el.tagType = 3;
2094
+ } else if (isComponent(el)) {
2095
+ el.tagType = 1;
1076
2096
  }
1077
- advanceBy(context, match.index + match[0].length - prevIndex + 1);
1078
2097
  }
1079
- return {
1080
- type: 3,
1081
- content,
1082
- loc: getSelection(context, start)
1083
- };
1084
- }
1085
- function parseBogusComment(context) {
1086
- const start = getCursor(context);
1087
- const contentStart = context.source[1] === "?" ? 1 : 2;
1088
- let content;
1089
- const closeIndex = context.source.indexOf(">");
1090
- if (closeIndex === -1) {
1091
- content = context.source.slice(contentStart);
1092
- advanceBy(context, context.source.length);
1093
- } else {
1094
- content = context.source.slice(contentStart, closeIndex);
1095
- advanceBy(context, closeIndex + 1);
2098
+ if (!tokenizer.inRCDATA) {
2099
+ el.children = condenseWhitespace(el.children, el.tag);
2100
+ }
2101
+ if (ns === 0 && currentOptions.isPreTag(tag)) {
2102
+ inPre--;
2103
+ }
2104
+ if (currentVPreBoundary === el) {
2105
+ inVPre = false;
2106
+ currentVPreBoundary = null;
2107
+ }
2108
+ if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
2109
+ tokenizer.inXML = false;
1096
2110
  }
1097
- return {
1098
- type: 3,
1099
- content,
1100
- loc: getSelection(context, start)
1101
- };
1102
- }
1103
- function parseElement(context, ancestors) {
1104
- const wasInPre = context.inPre;
1105
- const wasInVPre = context.inVPre;
1106
- const parent = last(ancestors);
1107
- const element = parseTag(context, 0 /* Start */, parent);
1108
- const isPreBoundary = context.inPre && !wasInPre;
1109
- const isVPreBoundary = context.inVPre && !wasInVPre;
1110
- if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
1111
- if (isPreBoundary) {
1112
- context.inPre = false;
1113
- }
1114
- if (isVPreBoundary) {
1115
- context.inVPre = false;
1116
- }
1117
- return element;
1118
- }
1119
- ancestors.push(element);
1120
- const mode = context.options.getTextMode(element, parent);
1121
- const children = parseChildren(context, mode, ancestors);
1122
- ancestors.pop();
1123
2111
  {
1124
- const inlineTemplateProp = element.props.find(
2112
+ const props = el.props;
2113
+ if (isCompatEnabled(
2114
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2115
+ currentOptions
2116
+ )) {
2117
+ let hasIf = false;
2118
+ let hasFor = false;
2119
+ for (let i = 0; i < props.length; i++) {
2120
+ const p = props[i];
2121
+ if (p.type === 7) {
2122
+ if (p.name === "if") {
2123
+ hasIf = true;
2124
+ } else if (p.name === "for") {
2125
+ hasFor = true;
2126
+ }
2127
+ }
2128
+ if (hasIf && hasFor) {
2129
+ warnDeprecation(
2130
+ "COMPILER_V_IF_V_FOR_PRECEDENCE",
2131
+ currentOptions,
2132
+ el.loc
2133
+ );
2134
+ break;
2135
+ }
2136
+ }
2137
+ }
2138
+ if (isCompatEnabled(
2139
+ "COMPILER_NATIVE_TEMPLATE",
2140
+ currentOptions
2141
+ ) && el.tag === "template" && !isFragmentTemplate(el)) {
2142
+ warnDeprecation(
2143
+ "COMPILER_NATIVE_TEMPLATE",
2144
+ currentOptions,
2145
+ el.loc
2146
+ );
2147
+ const parent = stack[0] || currentRoot;
2148
+ const index = parent.children.indexOf(el);
2149
+ parent.children.splice(index, 1, ...el.children);
2150
+ }
2151
+ const inlineTemplateProp = props.find(
1125
2152
  (p) => p.type === 6 && p.name === "inline-template"
1126
2153
  );
1127
2154
  if (inlineTemplateProp && checkCompatEnabled(
1128
2155
  "COMPILER_INLINE_TEMPLATE",
1129
- context,
2156
+ currentOptions,
1130
2157
  inlineTemplateProp.loc
1131
- )) {
1132
- const loc = getSelection(context, element.loc.end);
2158
+ ) && el.children.length) {
1133
2159
  inlineTemplateProp.value = {
1134
2160
  type: 2,
1135
- content: loc.source,
1136
- loc
2161
+ content: getSlice(
2162
+ el.children[0].loc.start.offset,
2163
+ el.children[el.children.length - 1].loc.end.offset
2164
+ ),
2165
+ loc: inlineTemplateProp.loc
1137
2166
  };
1138
2167
  }
1139
2168
  }
1140
- element.children = children;
1141
- if (startsWithEndTagOpen(context.source, element.tag)) {
1142
- parseTag(context, 1 /* End */, parent);
1143
- } else {
1144
- emitError(context, 24, 0, element.loc.start);
1145
- if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
1146
- const first = children[0];
1147
- if (first && startsWith(first.loc.source, "<!--")) {
1148
- emitError(context, 8);
1149
- }
1150
- }
1151
- }
1152
- element.loc = getSelection(context, element.loc.start);
1153
- if (isPreBoundary) {
1154
- context.inPre = false;
1155
- }
1156
- if (isVPreBoundary) {
1157
- context.inVPre = false;
1158
- }
1159
- return element;
1160
2169
  }
1161
- const isSpecialTemplateDirective = /* @__PURE__ */ makeMap(
1162
- `if,else,else-if,for,slot`
1163
- );
1164
- function parseTag(context, type, parent) {
1165
- const start = getCursor(context);
1166
- const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
1167
- const tag = match[1];
1168
- const ns = context.options.getNamespace(tag, parent);
1169
- advanceBy(context, match[0].length);
1170
- advanceSpaces(context);
1171
- const cursor = getCursor(context);
1172
- const currentSource = context.source;
1173
- if (context.options.isPreTag(tag)) {
1174
- context.inPre = true;
1175
- }
1176
- let props = parseAttributes(context, type);
1177
- if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
1178
- context.inVPre = true;
1179
- extend(context, cursor);
1180
- context.source = currentSource;
1181
- props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
1182
- }
1183
- let isSelfClosing = false;
1184
- if (context.source.length === 0) {
1185
- emitError(context, 9);
1186
- } else {
1187
- isSelfClosing = startsWith(context.source, "/>");
1188
- if (type === 1 /* End */ && isSelfClosing) {
1189
- emitError(context, 4);
1190
- }
1191
- advanceBy(context, isSelfClosing ? 2 : 1);
1192
- }
1193
- if (type === 1 /* End */) {
1194
- return;
2170
+ function fastForward(start, c) {
2171
+ let offset = 0;
2172
+ while (currentInput.charCodeAt(start + offset) !== 62 && start + offset < currentInput.length) {
2173
+ offset++;
1195
2174
  }
1196
- if (isCompatEnabled(
1197
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1198
- context
1199
- )) {
1200
- let hasIf = false;
1201
- let hasFor = false;
2175
+ return offset;
2176
+ }
2177
+ function backTrack(index, c) {
2178
+ let i = index;
2179
+ while (currentInput.charCodeAt(i) !== c && i >= 0)
2180
+ i--;
2181
+ return i;
2182
+ }
2183
+ const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
2184
+ function isFragmentTemplate({ tag, props }) {
2185
+ if (tag === "template") {
1202
2186
  for (let i = 0; i < props.length; i++) {
1203
- const p = props[i];
1204
- if (p.type === 7) {
1205
- if (p.name === "if") {
1206
- hasIf = true;
1207
- } else if (p.name === "for") {
1208
- hasFor = true;
1209
- }
1210
- }
1211
- if (hasIf && hasFor) {
1212
- warnDeprecation(
1213
- "COMPILER_V_IF_V_FOR_PRECEDENCE",
1214
- context,
1215
- getSelection(context, start)
1216
- );
1217
- break;
1218
- }
1219
- }
1220
- }
1221
- let tagType = 0;
1222
- if (!context.inVPre) {
1223
- if (tag === "slot") {
1224
- tagType = 2;
1225
- } else if (tag === "template") {
1226
- if (props.some(
1227
- (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
1228
- )) {
1229
- tagType = 3;
2187
+ if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
2188
+ return true;
1230
2189
  }
1231
- } else if (isComponent(tag, props, context)) {
1232
- tagType = 1;
1233
2190
  }
1234
2191
  }
1235
- return {
1236
- type: 1,
1237
- ns,
1238
- tag,
1239
- tagType,
1240
- props,
1241
- isSelfClosing,
1242
- children: [],
1243
- loc: getSelection(context, start),
1244
- codegenNode: void 0
1245
- // to be created during transform phase
1246
- };
2192
+ return false;
1247
2193
  }
1248
- function isComponent(tag, props, context) {
1249
- const options = context.options;
1250
- if (options.isCustomElement(tag)) {
2194
+ function isComponent({ tag, props }) {
2195
+ var _a;
2196
+ if (currentOptions.isCustomElement(tag)) {
1251
2197
  return false;
1252
2198
  }
1253
- if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
2199
+ if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
1254
2200
  return true;
1255
2201
  }
1256
2202
  for (let i = 0; i < props.length; i++) {
@@ -1261,374 +2207,179 @@ function isComponent(tag, props, context) {
1261
2207
  return true;
1262
2208
  } else if (checkCompatEnabled(
1263
2209
  "COMPILER_IS_ON_ELEMENT",
1264
- context,
2210
+ currentOptions,
1265
2211
  p.loc
1266
2212
  )) {
1267
2213
  return true;
1268
2214
  }
1269
2215
  }
1270
- } else {
1271
- if (p.name === "is") {
1272
- return true;
1273
- } else if (
1274
- // :is on plain element - only treat as component in compat mode
1275
- p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
1276
- "COMPILER_IS_ON_ELEMENT",
1277
- context,
1278
- p.loc
1279
- )
1280
- ) {
1281
- return true;
1282
- }
2216
+ } else if (// :is on plain element - only treat as component in compat mode
2217
+ p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
2218
+ "COMPILER_IS_ON_ELEMENT",
2219
+ currentOptions,
2220
+ p.loc
2221
+ )) {
2222
+ return true;
1283
2223
  }
1284
2224
  }
2225
+ return false;
1285
2226
  }
1286
- function parseAttributes(context, type) {
1287
- const props = [];
1288
- const attributeNames = /* @__PURE__ */ new Set();
1289
- while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
1290
- if (startsWith(context.source, "/")) {
1291
- emitError(context, 22);
1292
- advanceBy(context, 1);
1293
- advanceSpaces(context);
1294
- continue;
1295
- }
1296
- if (type === 1 /* End */) {
1297
- emitError(context, 3);
1298
- }
1299
- const attr = parseAttribute(context, attributeNames);
1300
- if (attr.type === 6 && attr.value && attr.name === "class") {
1301
- attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
1302
- }
1303
- if (type === 0 /* Start */) {
1304
- props.push(attr);
1305
- }
1306
- if (/^[^\t\r\n\f />]/.test(context.source)) {
1307
- emitError(context, 15);
1308
- }
1309
- advanceSpaces(context);
1310
- }
1311
- return props;
2227
+ function isUpperCase(c) {
2228
+ return c > 64 && c < 91;
1312
2229
  }
1313
- function parseAttribute(context, nameSet) {
1314
- var _a;
1315
- const start = getCursor(context);
1316
- const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
1317
- const name = match[0];
1318
- if (nameSet.has(name)) {
1319
- emitError(context, 2);
1320
- }
1321
- nameSet.add(name);
1322
- if (name[0] === "=") {
1323
- emitError(context, 19);
1324
- }
1325
- {
1326
- const pattern = /["'<]/g;
1327
- let m;
1328
- while (m = pattern.exec(name)) {
1329
- emitError(
1330
- context,
1331
- 17,
1332
- m.index
1333
- );
1334
- }
1335
- }
1336
- advanceBy(context, name.length);
1337
- let value = void 0;
1338
- if (/^[\t\r\n\f ]*=/.test(context.source)) {
1339
- advanceSpaces(context);
1340
- advanceBy(context, 1);
1341
- advanceSpaces(context);
1342
- value = parseAttributeValue(context);
1343
- if (!value) {
1344
- emitError(context, 13);
1345
- }
1346
- }
1347
- const loc = getSelection(context, start);
1348
- if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
1349
- const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
1350
- name
1351
- );
1352
- let isPropShorthand = startsWith(name, ".");
1353
- let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
1354
- let arg;
1355
- if (match2[2]) {
1356
- const isSlot = dirName === "slot";
1357
- const startOffset = name.lastIndexOf(
1358
- match2[2],
1359
- name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
1360
- );
1361
- const loc2 = getSelection(
1362
- context,
1363
- getNewPosition(context, start, startOffset),
1364
- getNewPosition(
1365
- context,
1366
- start,
1367
- startOffset + match2[2].length + (isSlot && match2[3] || "").length
1368
- )
1369
- );
1370
- let content = match2[2];
1371
- let isStatic = true;
1372
- if (content.startsWith("[")) {
1373
- isStatic = false;
1374
- if (!content.endsWith("]")) {
1375
- emitError(
1376
- context,
1377
- 27
1378
- );
1379
- content = content.slice(1);
1380
- } else {
1381
- content = content.slice(1, content.length - 1);
2230
+ const windowsNewlineRE = /\r\n/g;
2231
+ function condenseWhitespace(nodes, tag) {
2232
+ var _a, _b;
2233
+ const shouldCondense = currentOptions.whitespace !== "preserve";
2234
+ let removedWhitespace = false;
2235
+ for (let i = 0; i < nodes.length; i++) {
2236
+ const node = nodes[i];
2237
+ if (node.type === 2) {
2238
+ if (!inPre) {
2239
+ if (isAllWhitespace(node.content)) {
2240
+ const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
2241
+ const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
2242
+ if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2243
+ removedWhitespace = true;
2244
+ nodes[i] = null;
2245
+ } else {
2246
+ node.content = " ";
2247
+ }
2248
+ } else if (shouldCondense) {
2249
+ node.content = condense(node.content);
1382
2250
  }
1383
- } else if (isSlot) {
1384
- content += match2[3] || "";
1385
- }
1386
- arg = {
1387
- type: 4,
1388
- content,
1389
- isStatic,
1390
- constType: isStatic ? 3 : 0,
1391
- loc: loc2
1392
- };
1393
- }
1394
- if (value && value.isQuoted) {
1395
- const valueLoc = value.loc;
1396
- valueLoc.start.offset++;
1397
- valueLoc.start.column++;
1398
- valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
1399
- valueLoc.source = valueLoc.source.slice(1, -1);
1400
- }
1401
- const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
1402
- if (isPropShorthand)
1403
- modifiers.push("prop");
1404
- if (dirName === "bind" && arg) {
1405
- if (modifiers.includes("sync") && checkCompatEnabled(
1406
- "COMPILER_V_BIND_SYNC",
1407
- context,
1408
- loc,
1409
- arg.loc.source
1410
- )) {
1411
- dirName = "model";
1412
- modifiers.splice(modifiers.indexOf("sync"), 1);
1413
- }
1414
- if (modifiers.includes("prop")) {
1415
- checkCompatEnabled(
1416
- "COMPILER_V_BIND_PROP",
1417
- context,
1418
- loc
1419
- );
2251
+ } else {
2252
+ node.content = node.content.replace(windowsNewlineRE, "\n");
1420
2253
  }
1421
2254
  }
1422
- return {
1423
- type: 7,
1424
- name: dirName,
1425
- exp: value && {
1426
- type: 4,
1427
- content: value.content,
1428
- isStatic: false,
1429
- // Treat as non-constant by default. This can be potentially set to
1430
- // other values by `transformExpression` to make it eligible for hoisting.
1431
- constType: 0,
1432
- loc: value.loc
1433
- },
1434
- arg,
1435
- modifiers,
1436
- loc
1437
- };
1438
2255
  }
1439
- if (!context.inVPre && startsWith(name, "v-")) {
1440
- emitError(context, 26);
2256
+ if (inPre && tag && currentOptions.isPreTag(tag)) {
2257
+ const first = nodes[0];
2258
+ if (first && first.type === 2) {
2259
+ first.content = first.content.replace(/^\r?\n/, "");
2260
+ }
1441
2261
  }
1442
- return {
1443
- type: 6,
1444
- name,
1445
- value: value && {
1446
- type: 2,
1447
- content: value.content,
1448
- loc: value.loc
1449
- },
1450
- loc
1451
- };
2262
+ return removedWhitespace ? nodes.filter(Boolean) : nodes;
1452
2263
  }
1453
- function parseAttributeValue(context) {
1454
- const start = getCursor(context);
1455
- let content;
1456
- const quote = context.source[0];
1457
- const isQuoted = quote === `"` || quote === `'`;
1458
- if (isQuoted) {
1459
- advanceBy(context, 1);
1460
- const endIndex = context.source.indexOf(quote);
1461
- if (endIndex === -1) {
1462
- content = parseTextData(
1463
- context,
1464
- context.source.length,
1465
- 4
1466
- );
1467
- } else {
1468
- content = parseTextData(context, endIndex, 4);
1469
- advanceBy(context, 1);
1470
- }
1471
- } else {
1472
- const match = /^[^\t\r\n\f >]+/.exec(context.source);
1473
- if (!match) {
1474
- return void 0;
1475
- }
1476
- const unexpectedChars = /["'<=`]/g;
1477
- let m;
1478
- while (m = unexpectedChars.exec(match[0])) {
1479
- emitError(
1480
- context,
1481
- 18,
1482
- m.index
1483
- );
2264
+ function isAllWhitespace(str) {
2265
+ for (let i = 0; i < str.length; i++) {
2266
+ if (!isWhitespace(str.charCodeAt(i))) {
2267
+ return false;
1484
2268
  }
1485
- content = parseTextData(context, match[0].length, 4);
1486
- }
1487
- return { content, isQuoted, loc: getSelection(context, start) };
1488
- }
1489
- function parseInterpolation(context, mode) {
1490
- const [open, close] = context.options.delimiters;
1491
- const closeIndex = context.source.indexOf(close, open.length);
1492
- if (closeIndex === -1) {
1493
- emitError(context, 25);
1494
- return void 0;
1495
- }
1496
- const start = getCursor(context);
1497
- advanceBy(context, open.length);
1498
- const innerStart = getCursor(context);
1499
- const innerEnd = getCursor(context);
1500
- const rawContentLength = closeIndex - open.length;
1501
- const rawContent = context.source.slice(0, rawContentLength);
1502
- const preTrimContent = parseTextData(context, rawContentLength, mode);
1503
- const content = preTrimContent.trim();
1504
- const startOffset = preTrimContent.indexOf(content);
1505
- if (startOffset > 0) {
1506
- advancePositionWithMutation(innerStart, rawContent, startOffset);
1507
- }
1508
- const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
1509
- advancePositionWithMutation(innerEnd, rawContent, endOffset);
1510
- advanceBy(context, close.length);
1511
- return {
1512
- type: 5,
1513
- content: {
1514
- type: 4,
1515
- isStatic: false,
1516
- // Set `isConstant` to false by default and will decide in transformExpression
1517
- constType: 0,
1518
- content,
1519
- loc: getSelection(context, innerStart, innerEnd)
1520
- },
1521
- loc: getSelection(context, start)
1522
- };
2269
+ }
2270
+ return true;
1523
2271
  }
1524
- function parseText(context, mode) {
1525
- const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
1526
- let endIndex = context.source.length;
1527
- for (let i = 0; i < endTokens.length; i++) {
1528
- const index = context.source.indexOf(endTokens[i], 1);
1529
- if (index !== -1 && endIndex > index) {
1530
- endIndex = index;
2272
+ function hasNewlineChar(str) {
2273
+ for (let i = 0; i < str.length; i++) {
2274
+ const c = str.charCodeAt(i);
2275
+ if (c === 10 || c === 13) {
2276
+ return true;
1531
2277
  }
1532
2278
  }
1533
- const start = getCursor(context);
1534
- const content = parseTextData(context, endIndex, mode);
1535
- return {
1536
- type: 2,
1537
- content,
1538
- loc: getSelection(context, start)
1539
- };
2279
+ return false;
1540
2280
  }
1541
- function parseTextData(context, length, mode) {
1542
- const rawText = context.source.slice(0, length);
1543
- advanceBy(context, length);
1544
- if (mode === 2 || mode === 3 || !rawText.includes("&")) {
1545
- return rawText;
1546
- } else {
1547
- return context.options.decodeEntities(
1548
- rawText,
1549
- mode === 4
1550
- );
2281
+ function condense(str) {
2282
+ let ret = "";
2283
+ let prevCharIsWhitespace = false;
2284
+ for (let i = 0; i < str.length; i++) {
2285
+ if (isWhitespace(str.charCodeAt(i))) {
2286
+ if (!prevCharIsWhitespace) {
2287
+ ret += " ";
2288
+ prevCharIsWhitespace = true;
2289
+ }
2290
+ } else {
2291
+ ret += str[i];
2292
+ prevCharIsWhitespace = false;
2293
+ }
1551
2294
  }
2295
+ return ret;
1552
2296
  }
1553
- function getCursor(context) {
1554
- const { column, line, offset } = context;
1555
- return { column, line, offset };
2297
+ function addNode(node) {
2298
+ (stack[0] || currentRoot).children.push(node);
1556
2299
  }
1557
- function getSelection(context, start, end) {
1558
- end = end || getCursor(context);
2300
+ function getLoc(start, end) {
1559
2301
  return {
1560
- start,
1561
- end,
1562
- source: context.originalSource.slice(start.offset, end.offset)
2302
+ start: tokenizer.getPos(start),
2303
+ // @ts-expect-error allow late attachment
2304
+ end: end == null ? end : tokenizer.getPos(end),
2305
+ // @ts-expect-error allow late attachment
2306
+ source: end == null ? end : getSlice(start, end)
1563
2307
  };
1564
2308
  }
1565
- function last(xs) {
1566
- return xs[xs.length - 1];
2309
+ function setLocEnd(loc, end) {
2310
+ loc.end = tokenizer.getPos(end);
2311
+ loc.source = getSlice(loc.start.offset, end);
1567
2312
  }
1568
- function startsWith(source, searchString) {
1569
- return source.startsWith(searchString);
1570
- }
1571
- function advanceBy(context, numberOfCharacters) {
1572
- const { source } = context;
1573
- advancePositionWithMutation(context, source, numberOfCharacters);
1574
- context.source = source.slice(numberOfCharacters);
1575
- }
1576
- function advanceSpaces(context) {
1577
- const match = /^[\t\r\n\f ]+/.exec(context.source);
1578
- if (match) {
1579
- advanceBy(context, match[0].length);
1580
- }
1581
- }
1582
- function getNewPosition(context, start, numberOfCharacters) {
1583
- return advancePositionWithClone(
1584
- start,
1585
- context.originalSource.slice(start.offset, numberOfCharacters),
1586
- numberOfCharacters
1587
- );
1588
- }
1589
- function emitError(context, code, offset, loc = getCursor(context)) {
1590
- if (offset) {
1591
- loc.offset += offset;
1592
- loc.column += offset;
2313
+ function dirToAttr(dir) {
2314
+ const attr = {
2315
+ type: 6,
2316
+ name: dir.rawName,
2317
+ nameLoc: getLoc(
2318
+ dir.loc.start.offset,
2319
+ dir.loc.start.offset + dir.rawName.length
2320
+ ),
2321
+ value: void 0,
2322
+ loc: dir.loc
2323
+ };
2324
+ if (dir.exp) {
2325
+ const loc = dir.exp.loc;
2326
+ if (loc.end.offset < dir.loc.end.offset) {
2327
+ loc.start.offset--;
2328
+ loc.start.column--;
2329
+ loc.end.offset++;
2330
+ loc.end.column++;
2331
+ }
2332
+ attr.value = {
2333
+ type: 2,
2334
+ content: dir.exp.content,
2335
+ loc
2336
+ };
1593
2337
  }
1594
- context.options.onError(
1595
- createCompilerError(code, {
1596
- start: loc,
1597
- end: loc,
1598
- source: ""
1599
- })
1600
- );
1601
- }
1602
- function isEnd(context, mode, ancestors) {
1603
- const s = context.source;
1604
- switch (mode) {
1605
- case 0:
1606
- if (startsWith(s, "</")) {
1607
- for (let i = ancestors.length - 1; i >= 0; --i) {
1608
- if (startsWithEndTagOpen(s, ancestors[i].tag)) {
1609
- return true;
1610
- }
1611
- }
1612
- }
1613
- break;
1614
- case 1:
1615
- case 2: {
1616
- const parent = last(ancestors);
1617
- if (parent && startsWithEndTagOpen(s, parent.tag)) {
1618
- return true;
2338
+ return attr;
2339
+ }
2340
+ function emitError(code, index) {
2341
+ currentOptions.onError(createCompilerError(code, getLoc(index, index)));
2342
+ }
2343
+ function reset() {
2344
+ tokenizer.reset();
2345
+ currentOpenTag = null;
2346
+ currentProp = null;
2347
+ currentAttrValue = "";
2348
+ currentAttrStartIndex = -1;
2349
+ currentAttrEndIndex = -1;
2350
+ stack.length = 0;
2351
+ }
2352
+ function baseParse(input, options) {
2353
+ reset();
2354
+ currentInput = input;
2355
+ currentOptions = extend({}, defaultParserOptions);
2356
+ if (options) {
2357
+ let key;
2358
+ for (key in options) {
2359
+ if (options[key] != null) {
2360
+ currentOptions[key] = options[key];
1619
2361
  }
1620
- break;
1621
2362
  }
1622
- case 3:
1623
- if (startsWith(s, "]]>")) {
1624
- return true;
1625
- }
1626
- break;
1627
2363
  }
1628
- return !s;
1629
- }
1630
- function startsWithEndTagOpen(source, tag) {
1631
- return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
2364
+ {
2365
+ if (!currentOptions.decodeEntities) {
2366
+ throw new Error(
2367
+ `[@vue/compiler-core] decodeEntities option is required in browser builds.`
2368
+ );
2369
+ }
2370
+ }
2371
+ tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2372
+ const delimiters = options == null ? void 0 : options.delimiters;
2373
+ if (delimiters) {
2374
+ tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2375
+ tokenizer.delimiterClose = toCharCodes(delimiters[1]);
2376
+ }
2377
+ const root = currentRoot = createRoot([], input);
2378
+ tokenizer.parse(currentInput);
2379
+ root.loc = getLoc(0, input.length);
2380
+ root.children = condenseWhitespace(root.children);
2381
+ currentRoot = null;
2382
+ return root;
1632
2383
  }
1633
2384
 
1634
2385
  function hoistStatic(root, context) {
@@ -2040,6 +2791,7 @@ function transform(root, options) {
2040
2791
  root.hoists = context.hoists;
2041
2792
  root.temps = context.temps;
2042
2793
  root.cached = context.cached;
2794
+ root.transformed = true;
2043
2795
  {
2044
2796
  root.filters = [...context.filters];
2045
2797
  }
@@ -2196,7 +2948,7 @@ function createCodegenContext(ast, {
2196
2948
  ssr,
2197
2949
  isTS,
2198
2950
  inSSR,
2199
- source: ast.loc.source,
2951
+ source: ast.source,
2200
2952
  code: ``,
2201
2953
  column: 1,
2202
2954
  line: 1,
@@ -2207,7 +2959,7 @@ function createCodegenContext(ast, {
2207
2959
  helper(key) {
2208
2960
  return `_${helperNameMap[key]}`;
2209
2961
  },
2210
- push(code, node) {
2962
+ push(code, newlineIndex = -2 /* None */, node) {
2211
2963
  context.code += code;
2212
2964
  },
2213
2965
  indent() {
@@ -2225,7 +2977,7 @@ function createCodegenContext(ast, {
2225
2977
  }
2226
2978
  };
2227
2979
  function newline(n) {
2228
- context.push("\n" + ` `.repeat(n));
2980
+ context.push("\n" + ` `.repeat(n), 0 /* Start */);
2229
2981
  }
2230
2982
  return context;
2231
2983
  }
@@ -2262,9 +3014,11 @@ function generate(ast, options = {}) {
2262
3014
  push(`with (_ctx) {`);
2263
3015
  indent();
2264
3016
  if (hasHelpers) {
2265
- push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
2266
- push(`
2267
- `);
3017
+ push(
3018
+ `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
3019
+ `,
3020
+ -1 /* End */
3021
+ );
2268
3022
  newline();
2269
3023
  }
2270
3024
  }
@@ -2293,7 +3047,7 @@ function generate(ast, options = {}) {
2293
3047
  }
2294
3048
  if (ast.components.length || ast.directives.length || ast.temps) {
2295
3049
  push(`
2296
- `);
3050
+ `, 0 /* Start */);
2297
3051
  newline();
2298
3052
  }
2299
3053
  if (!ssr) {
@@ -2314,7 +3068,6 @@ function generate(ast, options = {}) {
2314
3068
  ast,
2315
3069
  code: context.code,
2316
3070
  preamble: isSetupInlined ? preambleContext.code : ``,
2317
- // SourceMapGenerator does have toJSON() method but it's not in the types
2318
3071
  map: context.map ? context.map.toJSON() : void 0
2319
3072
  };
2320
3073
  }
@@ -2333,7 +3086,7 @@ function genFunctionPreamble(ast, context) {
2333
3086
  if (helpers.length > 0) {
2334
3087
  {
2335
3088
  push(`const _Vue = ${VueBinding}
2336
- `);
3089
+ `, -1 /* End */);
2337
3090
  if (ast.hoists.length) {
2338
3091
  const staticHelpers = [
2339
3092
  CREATE_VNODE,
@@ -2343,7 +3096,7 @@ function genFunctionPreamble(ast, context) {
2343
3096
  CREATE_STATIC
2344
3097
  ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
2345
3098
  push(`const { ${staticHelpers} } = _Vue
2346
- `);
3099
+ `, -1 /* End */);
2347
3100
  }
2348
3101
  }
2349
3102
  }
@@ -2404,7 +3157,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2404
3157
  for (let i = 0; i < nodes.length; i++) {
2405
3158
  const node = nodes[i];
2406
3159
  if (isString(node)) {
2407
- push(node);
3160
+ push(node, -3 /* Unknown */);
2408
3161
  } else if (isArray(node)) {
2409
3162
  genNodeListAsArray(node, context);
2410
3163
  } else {
@@ -2422,7 +3175,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
2422
3175
  }
2423
3176
  function genNode(node, context) {
2424
3177
  if (isString(node)) {
2425
- context.push(node);
3178
+ context.push(node, -3 /* Unknown */);
2426
3179
  return;
2427
3180
  }
2428
3181
  if (isSymbol(node)) {
@@ -2502,11 +3255,15 @@ function genNode(node, context) {
2502
3255
  }
2503
3256
  }
2504
3257
  function genText(node, context) {
2505
- context.push(JSON.stringify(node.content), node);
3258
+ context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
2506
3259
  }
2507
3260
  function genExpression(node, context) {
2508
3261
  const { content, isStatic } = node;
2509
- context.push(isStatic ? JSON.stringify(content) : content, node);
3262
+ context.push(
3263
+ isStatic ? JSON.stringify(content) : content,
3264
+ -3 /* Unknown */,
3265
+ node
3266
+ );
2510
3267
  }
2511
3268
  function genInterpolation(node, context) {
2512
3269
  const { push, helper, pure } = context;
@@ -2520,7 +3277,7 @@ function genCompoundExpression(node, context) {
2520
3277
  for (let i = 0; i < node.children.length; i++) {
2521
3278
  const child = node.children[i];
2522
3279
  if (isString(child)) {
2523
- context.push(child);
3280
+ context.push(child, -3 /* Unknown */);
2524
3281
  } else {
2525
3282
  genNode(child, context);
2526
3283
  }
@@ -2534,9 +3291,9 @@ function genExpressionAsPropertyKey(node, context) {
2534
3291
  push(`]`);
2535
3292
  } else if (node.isStatic) {
2536
3293
  const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
2537
- push(text, node);
3294
+ push(text, -2 /* None */, node);
2538
3295
  } else {
2539
- push(`[${node.content}]`, node);
3296
+ push(`[${node.content}]`, -3 /* Unknown */, node);
2540
3297
  }
2541
3298
  }
2542
3299
  function genComment(node, context) {
@@ -2544,7 +3301,11 @@ function genComment(node, context) {
2544
3301
  if (pure) {
2545
3302
  push(PURE_ANNOTATION);
2546
3303
  }
2547
- push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
3304
+ push(
3305
+ `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
3306
+ -3 /* Unknown */,
3307
+ node
3308
+ );
2548
3309
  }
2549
3310
  function genVNodeCall(node, context) {
2550
3311
  const { push, helper, pure } = context;
@@ -2569,7 +3330,7 @@ function genVNodeCall(node, context) {
2569
3330
  push(PURE_ANNOTATION);
2570
3331
  }
2571
3332
  const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
2572
- push(helper(callHelper) + `(`, node);
3333
+ push(helper(callHelper) + `(`, -2 /* None */, node);
2573
3334
  genNodeList(
2574
3335
  genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
2575
3336
  context
@@ -2598,7 +3359,7 @@ function genCallExpression(node, context) {
2598
3359
  if (pure) {
2599
3360
  push(PURE_ANNOTATION);
2600
3361
  }
2601
- push(callee + `(`, node);
3362
+ push(callee + `(`, -2 /* None */, node);
2602
3363
  genNodeList(node.arguments, context);
2603
3364
  push(`)`);
2604
3365
  }
@@ -2606,7 +3367,7 @@ function genObjectExpression(node, context) {
2606
3367
  const { push, indent, deindent, newline } = context;
2607
3368
  const { properties } = node;
2608
3369
  if (!properties.length) {
2609
- push(`{}`, node);
3370
+ push(`{}`, -2 /* None */, node);
2610
3371
  return;
2611
3372
  }
2612
3373
  const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
@@ -2634,7 +3395,7 @@ function genFunctionExpression(node, context) {
2634
3395
  if (isSlot) {
2635
3396
  push(`_${helperNameMap[WITH_CTX]}(`);
2636
3397
  }
2637
- push(`(`, node);
3398
+ push(`(`, -2 /* None */, node);
2638
3399
  if (isArray(params)) {
2639
3400
  genNodeList(params, context);
2640
3401
  } else if (params) {
@@ -2769,6 +3530,15 @@ function walkBlockDeclarations(block, onIdent) {
2769
3530
  if (stmt.declare || !stmt.id)
2770
3531
  continue;
2771
3532
  onIdent(stmt.id);
3533
+ } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
3534
+ const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
3535
+ if (variable && variable.type === "VariableDeclaration") {
3536
+ for (const decl of variable.declarations) {
3537
+ for (const id of extractIdentifiers(decl.id)) {
3538
+ onIdent(id);
3539
+ }
3540
+ }
3541
+ }
2772
3542
  }
2773
3543
  }
2774
3544
  }
@@ -2979,7 +3749,7 @@ function processIf(node, dir, context, processCodegen) {
2979
3749
  context.removeNode();
2980
3750
  const branch = createIfBranch(node, dir);
2981
3751
  if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
2982
- !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
3752
+ !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
2983
3753
  branch.children = [...comments, ...branch.children];
2984
3754
  }
2985
3755
  {
@@ -3261,18 +4031,14 @@ function processFor(node, dir, context, processCodegen) {
3261
4031
  );
3262
4032
  return;
3263
4033
  }
3264
- const parseResult = parseForExpression(
3265
- // can only be simple expression because vFor transform is applied
3266
- // before expression transform.
3267
- dir.exp,
3268
- context
3269
- );
4034
+ const parseResult = dir.forParseResult;
3270
4035
  if (!parseResult) {
3271
4036
  context.onError(
3272
4037
  createCompilerError(32, dir.loc)
3273
4038
  );
3274
4039
  return;
3275
4040
  }
4041
+ finalizeForParseResult(parseResult, context);
3276
4042
  const { addIdentifiers, removeIdentifiers, scopes } = context;
3277
4043
  const { source, value, key, index } = parseResult;
3278
4044
  const forNode = {
@@ -3294,71 +4060,26 @@ function processFor(node, dir, context, processCodegen) {
3294
4060
  onExit();
3295
4061
  };
3296
4062
  }
3297
- const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
3298
- const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
3299
- const stripParensRE = /^\(|\)$/g;
3300
- function parseForExpression(input, context) {
3301
- const loc = input.loc;
3302
- const exp = input.content;
3303
- const inMatch = exp.match(forAliasRE);
3304
- if (!inMatch)
4063
+ function finalizeForParseResult(result, context) {
4064
+ if (result.finalized)
3305
4065
  return;
3306
- const [, LHS, RHS] = inMatch;
3307
- const result = {
3308
- source: createAliasExpression(
3309
- loc,
3310
- RHS.trim(),
3311
- exp.indexOf(RHS, LHS.length)
3312
- ),
3313
- value: void 0,
3314
- key: void 0,
3315
- index: void 0
3316
- };
3317
4066
  {
3318
4067
  validateBrowserExpression(result.source, context);
3319
- }
3320
- let valueContent = LHS.trim().replace(stripParensRE, "").trim();
3321
- const trimmedOffset = LHS.indexOf(valueContent);
3322
- const iteratorMatch = valueContent.match(forIteratorRE);
3323
- if (iteratorMatch) {
3324
- valueContent = valueContent.replace(forIteratorRE, "").trim();
3325
- const keyContent = iteratorMatch[1].trim();
3326
- let keyOffset;
3327
- if (keyContent) {
3328
- keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
3329
- result.key = createAliasExpression(loc, keyContent, keyOffset);
3330
- {
3331
- validateBrowserExpression(
3332
- result.key,
3333
- context,
3334
- true
3335
- );
3336
- }
4068
+ if (result.key) {
4069
+ validateBrowserExpression(
4070
+ result.key,
4071
+ context,
4072
+ true
4073
+ );
3337
4074
  }
3338
- if (iteratorMatch[2]) {
3339
- const indexContent = iteratorMatch[2].trim();
3340
- if (indexContent) {
3341
- result.index = createAliasExpression(
3342
- loc,
3343
- indexContent,
3344
- exp.indexOf(
3345
- indexContent,
3346
- result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
3347
- )
3348
- );
3349
- {
3350
- validateBrowserExpression(
3351
- result.index,
3352
- context,
3353
- true
3354
- );
3355
- }
3356
- }
4075
+ if (result.index) {
4076
+ validateBrowserExpression(
4077
+ result.index,
4078
+ context,
4079
+ true
4080
+ );
3357
4081
  }
3358
- }
3359
- if (valueContent) {
3360
- result.value = createAliasExpression(loc, valueContent, trimmedOffset);
3361
- {
4082
+ if (result.value) {
3362
4083
  validateBrowserExpression(
3363
4084
  result.value,
3364
4085
  context,
@@ -3366,14 +4087,7 @@ function parseForExpression(input, context) {
3366
4087
  );
3367
4088
  }
3368
4089
  }
3369
- return result;
3370
- }
3371
- function createAliasExpression(range, content, offset) {
3372
- return createSimpleExpression(
3373
- content,
3374
- false,
3375
- getInnerRange(range, offset, content.length)
3376
- );
4090
+ result.finalized = true;
3377
4091
  }
3378
4092
  function createForLoopParams({ value, key, index }, memoArgs = []) {
3379
4093
  return createParamsList([value, key, index, ...memoArgs]);
@@ -3403,11 +4117,9 @@ const trackSlotScopes = (node, context) => {
3403
4117
  const trackVForSlotScopes = (node, context) => {
3404
4118
  let vFor;
3405
4119
  if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
3406
- const result = vFor.parseResult = parseForExpression(
3407
- vFor.exp,
3408
- context
3409
- );
4120
+ const result = vFor.forParseResult;
3410
4121
  if (result) {
4122
+ finalizeForParseResult(result, context);
3411
4123
  const { value, key, index } = result;
3412
4124
  const { addIdentifiers, removeIdentifiers } = context;
3413
4125
  value && addIdentifiers(value);
@@ -3481,12 +4193,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3481
4193
  hasDynamicSlots = true;
3482
4194
  }
3483
4195
  const vFor = findDir(slotElement, "for");
3484
- const slotFunction = buildSlotFn(
3485
- slotProps,
3486
- vFor == null ? void 0 : vFor.exp,
3487
- slotChildren,
3488
- slotLoc
3489
- );
4196
+ const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
3490
4197
  let vIf;
3491
4198
  let vElse;
3492
4199
  if (vIf = findDir(slotElement, "if")) {
@@ -3535,8 +4242,9 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
3535
4242
  }
3536
4243
  } else if (vFor) {
3537
4244
  hasDynamicSlots = true;
3538
- const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
4245
+ const parseResult = vFor.forParseResult;
3539
4246
  if (parseResult) {
4247
+ finalizeForParseResult(parseResult, context);
3540
4248
  dynamicSlots.push(
3541
4249
  createCallExpression(context.helper(RENDER_LIST), [
3542
4250
  parseResult.source,
@@ -3797,17 +4505,6 @@ function resolveComponentType(node, context, ssr = false) {
3797
4505
  tag = isProp.value.content.slice(4);
3798
4506
  }
3799
4507
  }
3800
- const isDir = !isExplicitDynamic && findDir(node, "is");
3801
- if (isDir && isDir.exp) {
3802
- {
3803
- context.onWarn(
3804
- createCompilerError(52, isDir.loc)
3805
- );
3806
- }
3807
- return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
3808
- isDir.exp
3809
- ]);
3810
- }
3811
4508
  const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
3812
4509
  if (builtIn) {
3813
4510
  if (!ssr)
@@ -3879,7 +4576,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
3879
4576
  for (let i = 0; i < props.length; i++) {
3880
4577
  const prop = props[i];
3881
4578
  if (prop.type === 6) {
3882
- const { loc, name, value } = prop;
4579
+ const { loc, name, nameLoc, value } = prop;
3883
4580
  let isStatic = true;
3884
4581
  if (name === "ref") {
3885
4582
  hasRef = true;
@@ -3900,11 +4597,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
3900
4597
  }
3901
4598
  properties.push(
3902
4599
  createObjectProperty(
3903
- createSimpleExpression(
3904
- name,
3905
- true,
3906
- getInnerRange(loc, 0, name.length)
3907
- ),
4600
+ createSimpleExpression(name, true, nameLoc),
3908
4601
  createSimpleExpression(
3909
4602
  value ? value.content : "",
3910
4603
  isStatic,
@@ -3913,7 +4606,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
3913
4606
  )
3914
4607
  );
3915
4608
  } else {
3916
- const { name, arg, exp, loc } = prop;
4609
+ const { name, arg, exp, loc, modifiers } = prop;
3917
4610
  const isVBind = name === "bind";
3918
4611
  const isVOn = name === "on";
3919
4612
  if (name === "slot") {
@@ -4006,6 +4699,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
4006
4699
  }
4007
4700
  continue;
4008
4701
  }
4702
+ if (isVBind && modifiers.includes("prop")) {
4703
+ patchFlag |= 32;
4704
+ }
4009
4705
  const directiveTransform = context.directiveTransforms[name];
4010
4706
  if (directiveTransform) {
4011
4707
  const { props: props2, needRuntime } = directiveTransform(prop, node, context);
@@ -4383,8 +5079,13 @@ const transformOn$1 = (dir, node, context, augmentor) => {
4383
5079
  };
4384
5080
 
4385
5081
  const transformBind = (dir, _node, context) => {
4386
- const { exp, modifiers, loc } = dir;
5082
+ const { modifiers, loc } = dir;
4387
5083
  const arg = dir.arg;
5084
+ let { exp } = dir;
5085
+ if (!exp && arg.type === 4) {
5086
+ const propName = camelize(arg.content);
5087
+ exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
5088
+ }
4388
5089
  if (arg.type !== 4) {
4389
5090
  arg.children.unshift(`(`);
4390
5091
  arg.children.push(`) || ""`);
@@ -4783,7 +5484,7 @@ function getBaseTransformPreset(prefixIdentifiers) {
4783
5484
  }
4784
5485
  ];
4785
5486
  }
4786
- function baseCompile(template, options = {}) {
5487
+ function baseCompile(source, options = {}) {
4787
5488
  const onError = options.onError || defaultOnError;
4788
5489
  const isModuleMode = options.mode === "module";
4789
5490
  {
@@ -4800,7 +5501,7 @@ function baseCompile(template, options = {}) {
4800
5501
  if (options.scopeId && !isModuleMode) {
4801
5502
  onError(createCompilerError(50));
4802
5503
  }
4803
- const ast = isString(template) ? baseParse(template, options) : template;
5504
+ const ast = isString(source) ? baseParse(source, options) : source;
4804
5505
  const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
4805
5506
  transform(
4806
5507
  ast,
@@ -4866,25 +5567,22 @@ function decodeHtmlBrowser(raw, asAttr = false) {
4866
5567
  }
4867
5568
  }
4868
5569
 
4869
- const isRawTextContainer = /* @__PURE__ */ makeMap(
4870
- "style,iframe,script,noscript",
4871
- true
4872
- );
4873
5570
  const parserOptions = {
5571
+ parseMode: "html",
4874
5572
  isVoidTag,
4875
5573
  isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag),
4876
5574
  isPreTag: (tag) => tag === "pre",
4877
5575
  decodeEntities: decodeHtmlBrowser ,
4878
5576
  isBuiltInComponent: (tag) => {
4879
- if (isBuiltInType(tag, `Transition`)) {
5577
+ if (tag === "Transition" || tag === "transition") {
4880
5578
  return TRANSITION;
4881
- } else if (isBuiltInType(tag, `TransitionGroup`)) {
5579
+ } else if (tag === "TransitionGroup" || tag === "transition-group") {
4882
5580
  return TRANSITION_GROUP;
4883
5581
  }
4884
5582
  },
4885
5583
  // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
4886
- getNamespace(tag, parent) {
4887
- let ns = parent ? parent.ns : 0;
5584
+ getNamespace(tag, parent, rootNamespace) {
5585
+ let ns = parent ? parent.ns : rootNamespace;
4888
5586
  if (parent && ns === 2) {
4889
5587
  if (parent.tag === "annotation-xml") {
4890
5588
  if (tag === "svg") {
@@ -4912,18 +5610,6 @@ const parserOptions = {
4912
5610
  }
4913
5611
  }
4914
5612
  return ns;
4915
- },
4916
- // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
4917
- getTextMode({ tag, ns }) {
4918
- if (ns === 0) {
4919
- if (tag === "textarea" || tag === "title") {
4920
- return 1;
4921
- }
4922
- if (isRawTextContainer(tag)) {
4923
- return 2;
4924
- }
4925
- }
4926
- return 0;
4927
5613
  }
4928
5614
  };
4929
5615
 
@@ -5038,8 +5724,8 @@ const transformModel = (dir, node, context) => {
5038
5724
  );
5039
5725
  }
5040
5726
  function checkDuplicatedValue() {
5041
- const value = findProp(node, "value");
5042
- if (value) {
5727
+ const value = findDir(node, "bind");
5728
+ if (value && isStaticArgOf(value.arg, "value")) {
5043
5729
  context.onError(
5044
5730
  createDOMCompilerError(
5045
5731
  60,
@@ -5244,6 +5930,7 @@ const transformTransition = (node, context) => {
5244
5930
  node.props.push({
5245
5931
  type: 6,
5246
5932
  name: "persisted",
5933
+ nameLoc: node.loc,
5247
5934
  value: void 0,
5248
5935
  loc: node.loc
5249
5936
  });
@@ -5288,9 +5975,9 @@ const DOMDirectiveTransforms = {
5288
5975
  // override compiler-core
5289
5976
  show: transformShow
5290
5977
  };
5291
- function compile(template, options = {}) {
5978
+ function compile(src, options = {}) {
5292
5979
  return baseCompile(
5293
- template,
5980
+ src,
5294
5981
  extend({}, parserOptions, options, {
5295
5982
  nodeTransforms: [
5296
5983
  // ignore <script> and <tag>
@@ -5313,4 +6000,4 @@ function parse(template, options = {}) {
5313
6000
  return baseParse(template, extend({}, parserOptions, options));
5314
6001
  }
5315
6002
 
5316
- export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, DOMDirectiveTransforms, DOMErrorMessages, DOMNodeTransforms, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TRANSITION, TRANSITION_GROUP, TS_NODE_TYPES, UNREF, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, compile, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createDOMCompilerError, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, generate, generateCodeFrame, getBaseTransformPreset, getConstantType, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, parse, parserOptions, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel$1 as transformModel, transformOn$1 as transformOn, transformStyle, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
6003
+ export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, DOMDirectiveTransforms, DOMErrorMessages, DOMNodeTransforms, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TRANSITION, TRANSITION_GROUP, TS_NODE_TYPES, UNREF, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, compile, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createDOMCompilerError, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, forAliasRE, generate, generateCodeFrame, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, parse, parserOptions, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel$1 as transformModel, transformOn$1 as transformOn, transformStyle, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };