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