@vue/compiler-dom 3.2.35 → 3.2.38
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-dom.cjs.js +83 -83
- package/dist/compiler-dom.cjs.prod.js +72 -72
- package/dist/compiler-dom.esm-browser.js +596 -575
- package/dist/compiler-dom.esm-browser.prod.js +1 -1
- package/dist/compiler-dom.esm-bundler.js +57 -57
- package/dist/compiler-dom.global.js +596 -575
- package/dist/compiler-dom.global.prod.js +1 -1
- package/package.json +3 -3
|
@@ -18,29 +18,29 @@ function makeMap(str, expectsLowerCase) {
|
|
|
18
18
|
* dev only flag -> name mapping
|
|
19
19
|
*/
|
|
20
20
|
const PatchFlagNames = {
|
|
21
|
-
[1 /* TEXT */]: `TEXT`,
|
|
22
|
-
[2 /* CLASS */]: `CLASS`,
|
|
23
|
-
[4 /* STYLE */]: `STYLE`,
|
|
24
|
-
[8 /* PROPS */]: `PROPS`,
|
|
25
|
-
[16 /* FULL_PROPS */]: `FULL_PROPS`,
|
|
26
|
-
[32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
|
|
27
|
-
[64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
|
|
28
|
-
[128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
|
|
29
|
-
[256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
|
|
30
|
-
[512 /* NEED_PATCH */]: `NEED_PATCH`,
|
|
31
|
-
[1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
|
|
32
|
-
[2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
|
|
33
|
-
[-1 /* HOISTED */]: `HOISTED`,
|
|
34
|
-
[-2 /* BAIL */]: `BAIL`
|
|
21
|
+
[1 /* PatchFlags.TEXT */]: `TEXT`,
|
|
22
|
+
[2 /* PatchFlags.CLASS */]: `CLASS`,
|
|
23
|
+
[4 /* PatchFlags.STYLE */]: `STYLE`,
|
|
24
|
+
[8 /* PatchFlags.PROPS */]: `PROPS`,
|
|
25
|
+
[16 /* PatchFlags.FULL_PROPS */]: `FULL_PROPS`,
|
|
26
|
+
[32 /* PatchFlags.HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
|
|
27
|
+
[64 /* PatchFlags.STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
|
|
28
|
+
[128 /* PatchFlags.KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
|
|
29
|
+
[256 /* PatchFlags.UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
|
|
30
|
+
[512 /* PatchFlags.NEED_PATCH */]: `NEED_PATCH`,
|
|
31
|
+
[1024 /* PatchFlags.DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
|
|
32
|
+
[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
|
|
33
|
+
[-1 /* PatchFlags.HOISTED */]: `HOISTED`,
|
|
34
|
+
[-2 /* PatchFlags.BAIL */]: `BAIL`
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Dev only
|
|
39
39
|
*/
|
|
40
40
|
const slotFlagsText = {
|
|
41
|
-
[1 /* STABLE */]: 'STABLE',
|
|
42
|
-
[2 /* DYNAMIC */]: 'DYNAMIC',
|
|
43
|
-
[3 /* FORWARDED */]: 'FORWARDED'
|
|
41
|
+
[1 /* SlotFlags.STABLE */]: 'STABLE',
|
|
42
|
+
[2 /* SlotFlags.DYNAMIC */]: 'DYNAMIC',
|
|
43
|
+
[3 /* SlotFlags.FORWARDED */]: 'FORWARDED'
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const range = 2;
|
|
@@ -205,65 +205,65 @@ function createCompilerError(code, loc, messages, additionalMessage) {
|
|
|
205
205
|
}
|
|
206
206
|
const errorMessages = {
|
|
207
207
|
// parse errors
|
|
208
|
-
[0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
209
|
-
[1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
210
|
-
[2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
211
|
-
[3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
212
|
-
[4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
213
|
-
[5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
214
|
-
[6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
215
|
-
[7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
216
|
-
[8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
217
|
-
[9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
218
|
-
[10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
219
|
-
[11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
220
|
-
[12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
221
|
-
[13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
222
|
-
[14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
223
|
-
[15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
224
|
-
[16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
225
|
-
[17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
226
|
-
[18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
227
|
-
[19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
228
|
-
[21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
229
|
-
[20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
230
|
-
[22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
208
|
+
[0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
209
|
+
[1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
210
|
+
[2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
211
|
+
[3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
212
|
+
[4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
213
|
+
[5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
214
|
+
[6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
215
|
+
[7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
216
|
+
[8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
217
|
+
[9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
218
|
+
[10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
219
|
+
[11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
220
|
+
[12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
221
|
+
[13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
222
|
+
[14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
223
|
+
[15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
224
|
+
[16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
225
|
+
[17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
226
|
+
[18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
227
|
+
[19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
228
|
+
[21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
229
|
+
[20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
230
|
+
[22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
231
231
|
// Vue-specific parse errors
|
|
232
|
-
[23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
233
|
-
[24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
234
|
-
[25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
235
|
-
[27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
232
|
+
[23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
233
|
+
[24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
234
|
+
[25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
235
|
+
[27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
236
236
|
'Note that dynamic directive argument cannot contain spaces.',
|
|
237
|
-
[26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
237
|
+
[26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
238
238
|
// transform errors
|
|
239
|
-
[28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
240
|
-
[29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
241
|
-
[30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
242
|
-
[31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
243
|
-
[32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
244
|
-
[33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
245
|
-
[34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
246
|
-
[35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
247
|
-
[36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
248
|
-
[37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
239
|
+
[28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
240
|
+
[29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
241
|
+
[30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
242
|
+
[31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
243
|
+
[32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
244
|
+
[33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
245
|
+
[34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
246
|
+
[35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
247
|
+
[36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
248
|
+
[37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
249
249
|
`When there are multiple named slots, all slots should use <template> ` +
|
|
250
250
|
`syntax to avoid scope ambiguity.`,
|
|
251
|
-
[38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
252
|
-
[39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
251
|
+
[38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
252
|
+
[39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
253
253
|
`default slot. These children will be ignored.`,
|
|
254
|
-
[40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
255
|
-
[41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
256
|
-
[42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
257
|
-
[43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
|
258
|
-
[44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
259
|
-
[45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
254
|
+
[40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
255
|
+
[41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
256
|
+
[42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
257
|
+
[43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
|
258
|
+
[44 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
259
|
+
[45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
260
260
|
// generic errors
|
|
261
|
-
[46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
262
|
-
[47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
263
|
-
[48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
264
|
-
[49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
261
|
+
[46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
262
|
+
[47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
263
|
+
[48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
264
|
+
[49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
265
265
|
// just to fulfill types
|
|
266
|
-
[50 /* __EXTEND_POINT__ */]: ``
|
|
266
|
+
[50 /* ErrorCodes.__EXTEND_POINT__ */]: ``
|
|
267
267
|
};
|
|
268
268
|
|
|
269
269
|
const FRAGMENT = Symbol(`Fragment` );
|
|
@@ -366,7 +366,7 @@ const locStub = {
|
|
|
366
366
|
};
|
|
367
367
|
function createRoot(children, loc = locStub) {
|
|
368
368
|
return {
|
|
369
|
-
type: 0 /* ROOT */,
|
|
369
|
+
type: 0 /* NodeTypes.ROOT */,
|
|
370
370
|
children,
|
|
371
371
|
helpers: [],
|
|
372
372
|
components: [],
|
|
@@ -393,7 +393,7 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
return {
|
|
396
|
-
type: 13 /* VNODE_CALL */,
|
|
396
|
+
type: 13 /* NodeTypes.VNODE_CALL */,
|
|
397
397
|
tag,
|
|
398
398
|
props,
|
|
399
399
|
children,
|
|
@@ -408,38 +408,38 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
408
408
|
}
|
|
409
409
|
function createArrayExpression(elements, loc = locStub) {
|
|
410
410
|
return {
|
|
411
|
-
type: 17 /* JS_ARRAY_EXPRESSION */,
|
|
411
|
+
type: 17 /* NodeTypes.JS_ARRAY_EXPRESSION */,
|
|
412
412
|
loc,
|
|
413
413
|
elements
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
416
|
function createObjectExpression(properties, loc = locStub) {
|
|
417
417
|
return {
|
|
418
|
-
type: 15 /* JS_OBJECT_EXPRESSION */,
|
|
418
|
+
type: 15 /* NodeTypes.JS_OBJECT_EXPRESSION */,
|
|
419
419
|
loc,
|
|
420
420
|
properties
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
function createObjectProperty(key, value) {
|
|
424
424
|
return {
|
|
425
|
-
type: 16 /* JS_PROPERTY */,
|
|
425
|
+
type: 16 /* NodeTypes.JS_PROPERTY */,
|
|
426
426
|
loc: locStub,
|
|
427
427
|
key: isString(key) ? createSimpleExpression(key, true) : key,
|
|
428
428
|
value
|
|
429
429
|
};
|
|
430
430
|
}
|
|
431
|
-
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
|
|
431
|
+
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
432
432
|
return {
|
|
433
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
433
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
434
434
|
loc,
|
|
435
435
|
content,
|
|
436
436
|
isStatic,
|
|
437
|
-
constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
|
|
437
|
+
constType: isStatic ? 3 /* ConstantTypes.CAN_STRINGIFY */ : constType
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
function createInterpolation(content, loc) {
|
|
441
441
|
return {
|
|
442
|
-
type: 5 /* INTERPOLATION */,
|
|
442
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
443
443
|
loc,
|
|
444
444
|
content: isString(content)
|
|
445
445
|
? createSimpleExpression(content, false, loc)
|
|
@@ -448,14 +448,14 @@ function createInterpolation(content, loc) {
|
|
|
448
448
|
}
|
|
449
449
|
function createCompoundExpression(children, loc = locStub) {
|
|
450
450
|
return {
|
|
451
|
-
type: 8 /* COMPOUND_EXPRESSION */,
|
|
451
|
+
type: 8 /* NodeTypes.COMPOUND_EXPRESSION */,
|
|
452
452
|
loc,
|
|
453
453
|
children
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
456
|
function createCallExpression(callee, args = [], loc = locStub) {
|
|
457
457
|
return {
|
|
458
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
458
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
459
459
|
loc,
|
|
460
460
|
callee,
|
|
461
461
|
arguments: args
|
|
@@ -463,7 +463,7 @@ function createCallExpression(callee, args = [], loc = locStub) {
|
|
|
463
463
|
}
|
|
464
464
|
function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
|
|
465
465
|
return {
|
|
466
|
-
type: 18 /* JS_FUNCTION_EXPRESSION */,
|
|
466
|
+
type: 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */,
|
|
467
467
|
params,
|
|
468
468
|
returns,
|
|
469
469
|
newline,
|
|
@@ -473,7 +473,7 @@ function createFunctionExpression(params, returns = undefined, newline = false,
|
|
|
473
473
|
}
|
|
474
474
|
function createConditionalExpression(test, consequent, alternate, newline = true) {
|
|
475
475
|
return {
|
|
476
|
-
type: 19 /* JS_CONDITIONAL_EXPRESSION */,
|
|
476
|
+
type: 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */,
|
|
477
477
|
test,
|
|
478
478
|
consequent,
|
|
479
479
|
alternate,
|
|
@@ -483,7 +483,7 @@ function createConditionalExpression(test, consequent, alternate, newline = true
|
|
|
483
483
|
}
|
|
484
484
|
function createCacheExpression(index, value, isVNode = false) {
|
|
485
485
|
return {
|
|
486
|
-
type: 20 /* JS_CACHE_EXPRESSION */,
|
|
486
|
+
type: 20 /* NodeTypes.JS_CACHE_EXPRESSION */,
|
|
487
487
|
index,
|
|
488
488
|
value,
|
|
489
489
|
isVNode,
|
|
@@ -492,21 +492,21 @@ function createCacheExpression(index, value, isVNode = false) {
|
|
|
492
492
|
}
|
|
493
493
|
function createBlockStatement(body) {
|
|
494
494
|
return {
|
|
495
|
-
type: 21 /* JS_BLOCK_STATEMENT */,
|
|
495
|
+
type: 21 /* NodeTypes.JS_BLOCK_STATEMENT */,
|
|
496
496
|
body,
|
|
497
497
|
loc: locStub
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
500
|
function createTemplateLiteral(elements) {
|
|
501
501
|
return {
|
|
502
|
-
type: 22 /* JS_TEMPLATE_LITERAL */,
|
|
502
|
+
type: 22 /* NodeTypes.JS_TEMPLATE_LITERAL */,
|
|
503
503
|
elements,
|
|
504
504
|
loc: locStub
|
|
505
505
|
};
|
|
506
506
|
}
|
|
507
507
|
function createIfStatement(test, consequent, alternate) {
|
|
508
508
|
return {
|
|
509
|
-
type: 23 /* JS_IF_STATEMENT */,
|
|
509
|
+
type: 23 /* NodeTypes.JS_IF_STATEMENT */,
|
|
510
510
|
test,
|
|
511
511
|
consequent,
|
|
512
512
|
alternate,
|
|
@@ -515,7 +515,7 @@ function createIfStatement(test, consequent, alternate) {
|
|
|
515
515
|
}
|
|
516
516
|
function createAssignmentExpression(left, right) {
|
|
517
517
|
return {
|
|
518
|
-
type: 24 /* JS_ASSIGNMENT_EXPRESSION */,
|
|
518
|
+
type: 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */,
|
|
519
519
|
left,
|
|
520
520
|
right,
|
|
521
521
|
loc: locStub
|
|
@@ -523,20 +523,20 @@ function createAssignmentExpression(left, right) {
|
|
|
523
523
|
}
|
|
524
524
|
function createSequenceExpression(expressions) {
|
|
525
525
|
return {
|
|
526
|
-
type: 25 /* JS_SEQUENCE_EXPRESSION */,
|
|
526
|
+
type: 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */,
|
|
527
527
|
expressions,
|
|
528
528
|
loc: locStub
|
|
529
529
|
};
|
|
530
530
|
}
|
|
531
531
|
function createReturnStatement(returns) {
|
|
532
532
|
return {
|
|
533
|
-
type: 26 /* JS_RETURN_STATEMENT */,
|
|
533
|
+
type: 26 /* NodeTypes.JS_RETURN_STATEMENT */,
|
|
534
534
|
returns,
|
|
535
535
|
loc: locStub
|
|
536
536
|
};
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
-
const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
|
|
539
|
+
const isStaticExp = (p) => p.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && p.isStatic;
|
|
540
540
|
const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
|
|
541
541
|
function isCoreComponent(tag) {
|
|
542
542
|
if (isBuiltInType(tag, 'Teleport')) {
|
|
@@ -566,7 +566,7 @@ const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
|
|
566
566
|
const isMemberExpressionBrowser = (path) => {
|
|
567
567
|
// remove whitespaces around . or [ first
|
|
568
568
|
path = path.trim().replace(whitespaceRE, s => s.trim());
|
|
569
|
-
let state = 0 /* inMemberExp */;
|
|
569
|
+
let state = 0 /* MemberExpLexState.inMemberExp */;
|
|
570
570
|
let stateStack = [];
|
|
571
571
|
let currentOpenBracketCount = 0;
|
|
572
572
|
let currentOpenParensCount = 0;
|
|
@@ -574,25 +574,25 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
574
574
|
for (let i = 0; i < path.length; i++) {
|
|
575
575
|
const char = path.charAt(i);
|
|
576
576
|
switch (state) {
|
|
577
|
-
case 0 /* inMemberExp */:
|
|
577
|
+
case 0 /* MemberExpLexState.inMemberExp */:
|
|
578
578
|
if (char === '[') {
|
|
579
579
|
stateStack.push(state);
|
|
580
|
-
state = 1 /* inBrackets */;
|
|
580
|
+
state = 1 /* MemberExpLexState.inBrackets */;
|
|
581
581
|
currentOpenBracketCount++;
|
|
582
582
|
}
|
|
583
583
|
else if (char === '(') {
|
|
584
584
|
stateStack.push(state);
|
|
585
|
-
state = 2 /* inParens */;
|
|
585
|
+
state = 2 /* MemberExpLexState.inParens */;
|
|
586
586
|
currentOpenParensCount++;
|
|
587
587
|
}
|
|
588
588
|
else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
|
|
589
589
|
return false;
|
|
590
590
|
}
|
|
591
591
|
break;
|
|
592
|
-
case 1 /* inBrackets */:
|
|
592
|
+
case 1 /* MemberExpLexState.inBrackets */:
|
|
593
593
|
if (char === `'` || char === `"` || char === '`') {
|
|
594
594
|
stateStack.push(state);
|
|
595
|
-
state = 3 /* inString */;
|
|
595
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
596
596
|
currentStringType = char;
|
|
597
597
|
}
|
|
598
598
|
else if (char === `[`) {
|
|
@@ -604,10 +604,10 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
break;
|
|
607
|
-
case 2 /* inParens */:
|
|
607
|
+
case 2 /* MemberExpLexState.inParens */:
|
|
608
608
|
if (char === `'` || char === `"` || char === '`') {
|
|
609
609
|
stateStack.push(state);
|
|
610
|
-
state = 3 /* inString */;
|
|
610
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
611
611
|
currentStringType = char;
|
|
612
612
|
}
|
|
613
613
|
else if (char === `(`) {
|
|
@@ -623,7 +623,7 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
625
|
break;
|
|
626
|
-
case 3 /* inString */:
|
|
626
|
+
case 3 /* MemberExpLexState.inString */:
|
|
627
627
|
if (char === currentStringType) {
|
|
628
628
|
state = stateStack.pop();
|
|
629
629
|
currentStringType = null;
|
|
@@ -680,7 +680,7 @@ function assert(condition, msg) {
|
|
|
680
680
|
function findDir(node, name, allowEmpty = false) {
|
|
681
681
|
for (let i = 0; i < node.props.length; i++) {
|
|
682
682
|
const p = node.props[i];
|
|
683
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
683
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
684
684
|
(allowEmpty || p.exp) &&
|
|
685
685
|
(isString(name) ? p.name === name : name.test(p.name))) {
|
|
686
686
|
return p;
|
|
@@ -690,7 +690,7 @@ function findDir(node, name, allowEmpty = false) {
|
|
|
690
690
|
function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
691
691
|
for (let i = 0; i < node.props.length; i++) {
|
|
692
692
|
const p = node.props[i];
|
|
693
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
693
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
694
694
|
if (dynamicOnly)
|
|
695
695
|
continue;
|
|
696
696
|
if (p.name === name && (p.value || allowEmpty)) {
|
|
@@ -708,24 +708,24 @@ function isStaticArgOf(arg, name) {
|
|
|
708
708
|
return !!(arg && isStaticExp(arg) && arg.content === name);
|
|
709
709
|
}
|
|
710
710
|
function hasDynamicKeyVBind(node) {
|
|
711
|
-
return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
711
|
+
return node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
712
712
|
p.name === 'bind' &&
|
|
713
713
|
(!p.arg || // v-bind="obj"
|
|
714
|
-
p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
714
|
+
p.arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
715
715
|
!p.arg.isStatic) // v-bind:[foo]
|
|
716
716
|
);
|
|
717
717
|
}
|
|
718
718
|
function isText(node) {
|
|
719
|
-
return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
|
|
719
|
+
return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
|
|
720
720
|
}
|
|
721
721
|
function isVSlot(p) {
|
|
722
|
-
return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
|
|
722
|
+
return p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'slot';
|
|
723
723
|
}
|
|
724
724
|
function isTemplateNode(node) {
|
|
725
|
-
return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
|
|
725
|
+
return (node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 3 /* ElementTypes.TEMPLATE */);
|
|
726
726
|
}
|
|
727
727
|
function isSlotOutlet(node) {
|
|
728
|
-
return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
|
|
728
|
+
return node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 2 /* ElementTypes.SLOT */;
|
|
729
729
|
}
|
|
730
730
|
function getVNodeHelper(ssr, isComponent) {
|
|
731
731
|
return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
|
@@ -737,7 +737,7 @@ const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
|
|
737
737
|
function getUnnormalizedProps(props, callPath = []) {
|
|
738
738
|
if (props &&
|
|
739
739
|
!isString(props) &&
|
|
740
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
740
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
741
741
|
const callee = props.callee;
|
|
742
742
|
if (!isString(callee) && propsHelperSet.has(callee)) {
|
|
743
743
|
return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
|
|
@@ -755,12 +755,12 @@ function injectProp(node, prop, context) {
|
|
|
755
755
|
*
|
|
756
756
|
* we need to get the real props before normalization
|
|
757
757
|
*/
|
|
758
|
-
let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
|
|
758
|
+
let props = node.type === 13 /* NodeTypes.VNODE_CALL */ ? node.props : node.arguments[2];
|
|
759
759
|
let callPath = [];
|
|
760
760
|
let parentCall;
|
|
761
761
|
if (props &&
|
|
762
762
|
!isString(props) &&
|
|
763
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
763
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
764
764
|
const ret = getUnnormalizedProps(props);
|
|
765
765
|
props = ret[0];
|
|
766
766
|
callPath = ret[1];
|
|
@@ -769,12 +769,12 @@ function injectProp(node, prop, context) {
|
|
|
769
769
|
if (props == null || isString(props)) {
|
|
770
770
|
propsWithInjection = createObjectExpression([prop]);
|
|
771
771
|
}
|
|
772
|
-
else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
772
|
+
else if (props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
773
773
|
// merged props... add ours
|
|
774
774
|
// only inject key to object literal if it's the first argument so that
|
|
775
775
|
// if doesn't override user provided keys
|
|
776
776
|
const first = props.arguments[0];
|
|
777
|
-
if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
777
|
+
if (!isString(first) && first.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
778
778
|
first.properties.unshift(prop);
|
|
779
779
|
}
|
|
780
780
|
else {
|
|
@@ -791,12 +791,12 @@ function injectProp(node, prop, context) {
|
|
|
791
791
|
}
|
|
792
792
|
!propsWithInjection && (propsWithInjection = props);
|
|
793
793
|
}
|
|
794
|
-
else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
794
|
+
else if (props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
795
795
|
let alreadyExists = false;
|
|
796
796
|
// check existing key to avoid overriding user provided keys
|
|
797
|
-
if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
797
|
+
if (prop.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
798
798
|
const propKeyName = prop.key.content;
|
|
799
|
-
alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
799
|
+
alreadyExists = props.properties.some(p => p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
800
800
|
p.key.content === propKeyName);
|
|
801
801
|
}
|
|
802
802
|
if (!alreadyExists) {
|
|
@@ -817,7 +817,7 @@ function injectProp(node, prop, context) {
|
|
|
817
817
|
parentCall = callPath[callPath.length - 2];
|
|
818
818
|
}
|
|
819
819
|
}
|
|
820
|
-
if (node.type === 13 /* VNODE_CALL */) {
|
|
820
|
+
if (node.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
821
821
|
if (parentCall) {
|
|
822
822
|
parentCall.arguments[0] = propsWithInjection;
|
|
823
823
|
}
|
|
@@ -846,45 +846,45 @@ function hasScopeRef(node, ids) {
|
|
|
846
846
|
return false;
|
|
847
847
|
}
|
|
848
848
|
switch (node.type) {
|
|
849
|
-
case 1 /* ELEMENT */:
|
|
849
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
850
850
|
for (let i = 0; i < node.props.length; i++) {
|
|
851
851
|
const p = node.props[i];
|
|
852
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
852
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
853
853
|
(hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
|
|
854
854
|
return true;
|
|
855
855
|
}
|
|
856
856
|
}
|
|
857
857
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
858
|
-
case 11 /* FOR */:
|
|
858
|
+
case 11 /* NodeTypes.FOR */:
|
|
859
859
|
if (hasScopeRef(node.source, ids)) {
|
|
860
860
|
return true;
|
|
861
861
|
}
|
|
862
862
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
863
|
-
case 9 /* IF */:
|
|
863
|
+
case 9 /* NodeTypes.IF */:
|
|
864
864
|
return node.branches.some(b => hasScopeRef(b, ids));
|
|
865
|
-
case 10 /* IF_BRANCH */:
|
|
865
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
866
866
|
if (hasScopeRef(node.condition, ids)) {
|
|
867
867
|
return true;
|
|
868
868
|
}
|
|
869
869
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
870
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
870
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
871
871
|
return (!node.isStatic &&
|
|
872
872
|
isSimpleIdentifier(node.content) &&
|
|
873
873
|
!!ids[node.content]);
|
|
874
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
874
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
875
875
|
return node.children.some(c => isObject(c) && hasScopeRef(c, ids));
|
|
876
|
-
case 5 /* INTERPOLATION */:
|
|
877
|
-
case 12 /* TEXT_CALL */:
|
|
876
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
877
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
878
878
|
return hasScopeRef(node.content, ids);
|
|
879
|
-
case 2 /* TEXT */:
|
|
880
|
-
case 3 /* COMMENT */:
|
|
879
|
+
case 2 /* NodeTypes.TEXT */:
|
|
880
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
881
881
|
return false;
|
|
882
882
|
default:
|
|
883
883
|
return false;
|
|
884
884
|
}
|
|
885
885
|
}
|
|
886
886
|
function getMemoedVNodeCall(node) {
|
|
887
|
-
if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
887
|
+
if (node.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
888
888
|
return node.arguments[1].returns;
|
|
889
889
|
}
|
|
890
890
|
else {
|
|
@@ -901,23 +901,23 @@ function makeBlock(node, { helper, removeHelper, inSSR }) {
|
|
|
901
901
|
}
|
|
902
902
|
|
|
903
903
|
const deprecationData = {
|
|
904
|
-
["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
|
|
904
|
+
["COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */]: {
|
|
905
905
|
message: `Platform-native elements with "is" prop will no longer be ` +
|
|
906
906
|
`treated as components in Vue 3 unless the "is" value is explicitly ` +
|
|
907
907
|
`prefixed with "vue:".`,
|
|
908
908
|
link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
|
909
909
|
},
|
|
910
|
-
["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
|
|
910
|
+
["COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */]: {
|
|
911
911
|
message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
|
|
912
912
|
`argument instead. \`v-bind:${key}.sync\` should be changed to ` +
|
|
913
913
|
`\`v-model:${key}\`.`,
|
|
914
914
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
|
915
915
|
},
|
|
916
|
-
["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
|
|
916
|
+
["COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */]: {
|
|
917
917
|
message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
|
|
918
918
|
`Vue 3 will automatically set a binding as DOM property when appropriate.`
|
|
919
919
|
},
|
|
920
|
-
["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
920
|
+
["COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
921
921
|
message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
|
|
922
922
|
`object spread: it will now overwrite an existing non-mergeable attribute ` +
|
|
923
923
|
`that appears before v-bind in the case of conflict. ` +
|
|
@@ -925,11 +925,11 @@ const deprecationData = {
|
|
|
925
925
|
`You can also suppress this warning if the usage is intended.`,
|
|
926
926
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
|
927
927
|
},
|
|
928
|
-
["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
|
|
928
|
+
["COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */]: {
|
|
929
929
|
message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
|
930
930
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
|
931
931
|
},
|
|
932
|
-
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
932
|
+
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
933
933
|
message: `v-if / v-for precedence when used on the same element has changed ` +
|
|
934
934
|
`in Vue 3: v-if now takes higher precedence and will no longer have ` +
|
|
935
935
|
`access to v-for scope variables. It is best to avoid the ambiguity ` +
|
|
@@ -937,15 +937,15 @@ const deprecationData = {
|
|
|
937
937
|
`data source.`,
|
|
938
938
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
|
939
939
|
},
|
|
940
|
-
["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
|
|
940
|
+
["COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */]: {
|
|
941
941
|
message: `<template> with no special directives will render as a native template ` +
|
|
942
942
|
`element instead of its inner content in Vue 3.`
|
|
943
943
|
},
|
|
944
|
-
["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
|
|
944
|
+
["COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */]: {
|
|
945
945
|
message: `"inline-template" has been removed in Vue 3.`,
|
|
946
946
|
link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
|
947
947
|
},
|
|
948
|
-
["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
|
|
948
|
+
["COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */]: {
|
|
949
949
|
message: `filters have been removed in Vue 3. ` +
|
|
950
950
|
`The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
|
|
951
951
|
`Use method calls or computed properties instead.`,
|
|
@@ -1005,8 +1005,8 @@ const decodeMap = {
|
|
|
1005
1005
|
};
|
|
1006
1006
|
const defaultParserOptions = {
|
|
1007
1007
|
delimiters: [`{{`, `}}`],
|
|
1008
|
-
getNamespace: () => 0 /* HTML */,
|
|
1009
|
-
getTextMode: () => 0 /* DATA */,
|
|
1008
|
+
getNamespace: () => 0 /* Namespaces.HTML */,
|
|
1009
|
+
getTextMode: () => 0 /* TextModes.DATA */,
|
|
1010
1010
|
isVoidTag: NO,
|
|
1011
1011
|
isPreTag: NO,
|
|
1012
1012
|
isCustomElement: NO,
|
|
@@ -1018,7 +1018,7 @@ const defaultParserOptions = {
|
|
|
1018
1018
|
function baseParse(content, options = {}) {
|
|
1019
1019
|
const context = createParserContext(content, options);
|
|
1020
1020
|
const start = getCursor(context);
|
|
1021
|
-
return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
|
|
1021
|
+
return createRoot(parseChildren(context, 0 /* TextModes.DATA */, []), getSelection(context, start));
|
|
1022
1022
|
}
|
|
1023
1023
|
function createParserContext(content, rawOptions) {
|
|
1024
1024
|
const options = extend({}, defaultParserOptions);
|
|
@@ -1044,20 +1044,20 @@ function createParserContext(content, rawOptions) {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
function parseChildren(context, mode, ancestors) {
|
|
1046
1046
|
const parent = last(ancestors);
|
|
1047
|
-
const ns = parent ? parent.ns : 0 /* HTML */;
|
|
1047
|
+
const ns = parent ? parent.ns : 0 /* Namespaces.HTML */;
|
|
1048
1048
|
const nodes = [];
|
|
1049
1049
|
while (!isEnd(context, mode, ancestors)) {
|
|
1050
1050
|
const s = context.source;
|
|
1051
1051
|
let node = undefined;
|
|
1052
|
-
if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
|
|
1052
|
+
if (mode === 0 /* TextModes.DATA */ || mode === 1 /* TextModes.RCDATA */) {
|
|
1053
1053
|
if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
|
|
1054
1054
|
// '{{'
|
|
1055
1055
|
node = parseInterpolation(context, mode);
|
|
1056
1056
|
}
|
|
1057
|
-
else if (mode === 0 /* DATA */ && s[0] === '<') {
|
|
1057
|
+
else if (mode === 0 /* TextModes.DATA */ && s[0] === '<') {
|
|
1058
1058
|
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
|
|
1059
1059
|
if (s.length === 1) {
|
|
1060
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
|
|
1060
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 1);
|
|
1061
1061
|
}
|
|
1062
1062
|
else if (s[1] === '!') {
|
|
1063
1063
|
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
|
|
@@ -1069,57 +1069,57 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1069
1069
|
node = parseBogusComment(context);
|
|
1070
1070
|
}
|
|
1071
1071
|
else if (startsWith(s, '<![CDATA[')) {
|
|
1072
|
-
if (ns !== 0 /* HTML */) {
|
|
1072
|
+
if (ns !== 0 /* Namespaces.HTML */) {
|
|
1073
1073
|
node = parseCDATA(context, ancestors);
|
|
1074
1074
|
}
|
|
1075
1075
|
else {
|
|
1076
|
-
emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
|
|
1076
|
+
emitError(context, 1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */);
|
|
1077
1077
|
node = parseBogusComment(context);
|
|
1078
1078
|
}
|
|
1079
1079
|
}
|
|
1080
1080
|
else {
|
|
1081
|
-
emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
|
|
1081
|
+
emitError(context, 11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */);
|
|
1082
1082
|
node = parseBogusComment(context);
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
else if (s[1] === '/') {
|
|
1086
1086
|
// https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
|
|
1087
1087
|
if (s.length === 2) {
|
|
1088
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
|
|
1088
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 2);
|
|
1089
1089
|
}
|
|
1090
1090
|
else if (s[2] === '>') {
|
|
1091
|
-
emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
|
|
1091
|
+
emitError(context, 14 /* ErrorCodes.MISSING_END_TAG_NAME */, 2);
|
|
1092
1092
|
advanceBy(context, 3);
|
|
1093
1093
|
continue;
|
|
1094
1094
|
}
|
|
1095
1095
|
else if (/[a-z]/i.test(s[2])) {
|
|
1096
|
-
emitError(context, 23 /* X_INVALID_END_TAG */);
|
|
1097
|
-
parseTag(context, 1 /* End */, parent);
|
|
1096
|
+
emitError(context, 23 /* ErrorCodes.X_INVALID_END_TAG */);
|
|
1097
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
1098
1098
|
continue;
|
|
1099
1099
|
}
|
|
1100
1100
|
else {
|
|
1101
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
1101
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
1102
1102
|
node = parseBogusComment(context);
|
|
1103
1103
|
}
|
|
1104
1104
|
}
|
|
1105
1105
|
else if (/[a-z]/i.test(s[1])) {
|
|
1106
1106
|
node = parseElement(context, ancestors);
|
|
1107
1107
|
// 2.x <template> with no directive compat
|
|
1108
|
-
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
1108
|
+
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
1109
1109
|
node &&
|
|
1110
1110
|
node.tag === 'template' &&
|
|
1111
|
-
!node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
1111
|
+
!node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
1112
1112
|
isSpecialTemplateDirective(p.name))) {
|
|
1113
|
-
warnDeprecation("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context, node.loc);
|
|
1113
|
+
warnDeprecation("COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */, context, node.loc);
|
|
1114
1114
|
node = node.children;
|
|
1115
1115
|
}
|
|
1116
1116
|
}
|
|
1117
1117
|
else if (s[1] === '?') {
|
|
1118
|
-
emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
1118
|
+
emitError(context, 21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
1119
1119
|
node = parseBogusComment(context);
|
|
1120
1120
|
}
|
|
1121
1121
|
else {
|
|
1122
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
1122
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
1123
1123
|
}
|
|
1124
1124
|
}
|
|
1125
1125
|
}
|
|
@@ -1137,11 +1137,11 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1137
1137
|
}
|
|
1138
1138
|
// Whitespace handling strategy like v2
|
|
1139
1139
|
let removedWhitespace = false;
|
|
1140
|
-
if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
|
|
1140
|
+
if (mode !== 2 /* TextModes.RAWTEXT */ && mode !== 1 /* TextModes.RCDATA */) {
|
|
1141
1141
|
const shouldCondense = context.options.whitespace !== 'preserve';
|
|
1142
1142
|
for (let i = 0; i < nodes.length; i++) {
|
|
1143
1143
|
const node = nodes[i];
|
|
1144
|
-
if (!context.inPre && node.type === 2 /* TEXT */) {
|
|
1144
|
+
if (!context.inPre && node.type === 2 /* NodeTypes.TEXT */) {
|
|
1145
1145
|
if (!/[^\t\r\n\f ]/.test(node.content)) {
|
|
1146
1146
|
const prev = nodes[i - 1];
|
|
1147
1147
|
const next = nodes[i + 1];
|
|
@@ -1152,10 +1152,10 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1152
1152
|
if (!prev ||
|
|
1153
1153
|
!next ||
|
|
1154
1154
|
(shouldCondense &&
|
|
1155
|
-
(prev.type === 3 /* COMMENT */ ||
|
|
1156
|
-
next.type === 3 /* COMMENT */ ||
|
|
1157
|
-
(prev.type === 1 /* ELEMENT */ &&
|
|
1158
|
-
next.type === 1 /* ELEMENT */ &&
|
|
1155
|
+
(prev.type === 3 /* NodeTypes.COMMENT */ ||
|
|
1156
|
+
next.type === 3 /* NodeTypes.COMMENT */ ||
|
|
1157
|
+
(prev.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1158
|
+
next.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1159
1159
|
/[\r\n]/.test(node.content))))) {
|
|
1160
1160
|
removedWhitespace = true;
|
|
1161
1161
|
nodes[i] = null;
|
|
@@ -1172,7 +1172,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
1174
|
// Remove comment nodes if desired by configuration.
|
|
1175
|
-
else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
|
|
1175
|
+
else if (node.type === 3 /* NodeTypes.COMMENT */ && !context.options.comments) {
|
|
1176
1176
|
removedWhitespace = true;
|
|
1177
1177
|
nodes[i] = null;
|
|
1178
1178
|
}
|
|
@@ -1181,7 +1181,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1181
1181
|
// remove leading newline per html spec
|
|
1182
1182
|
// https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
|
|
1183
1183
|
const first = nodes[0];
|
|
1184
|
-
if (first && first.type === 2 /* TEXT */) {
|
|
1184
|
+
if (first && first.type === 2 /* NodeTypes.TEXT */) {
|
|
1185
1185
|
first.content = first.content.replace(/^\r?\n/, '');
|
|
1186
1186
|
}
|
|
1187
1187
|
}
|
|
@@ -1189,12 +1189,12 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1189
1189
|
return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
|
1190
1190
|
}
|
|
1191
1191
|
function pushNode(nodes, node) {
|
|
1192
|
-
if (node.type === 2 /* TEXT */) {
|
|
1192
|
+
if (node.type === 2 /* NodeTypes.TEXT */) {
|
|
1193
1193
|
const prev = last(nodes);
|
|
1194
1194
|
// Merge if both this and the previous node are text and those are
|
|
1195
1195
|
// consecutive. This happens for cases like "a < b".
|
|
1196
1196
|
if (prev &&
|
|
1197
|
-
prev.type === 2 /* TEXT */ &&
|
|
1197
|
+
prev.type === 2 /* NodeTypes.TEXT */ &&
|
|
1198
1198
|
prev.loc.end.offset === node.loc.start.offset) {
|
|
1199
1199
|
prev.content += node.content;
|
|
1200
1200
|
prev.loc.end = node.loc.end;
|
|
@@ -1206,9 +1206,9 @@ function pushNode(nodes, node) {
|
|
|
1206
1206
|
}
|
|
1207
1207
|
function parseCDATA(context, ancestors) {
|
|
1208
1208
|
advanceBy(context, 9);
|
|
1209
|
-
const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
|
|
1209
|
+
const nodes = parseChildren(context, 3 /* TextModes.CDATA */, ancestors);
|
|
1210
1210
|
if (context.source.length === 0) {
|
|
1211
|
-
emitError(context, 6 /* EOF_IN_CDATA */);
|
|
1211
|
+
emitError(context, 6 /* ErrorCodes.EOF_IN_CDATA */);
|
|
1212
1212
|
}
|
|
1213
1213
|
else {
|
|
1214
1214
|
advanceBy(context, 3);
|
|
@@ -1223,14 +1223,14 @@ function parseComment(context) {
|
|
|
1223
1223
|
if (!match) {
|
|
1224
1224
|
content = context.source.slice(4);
|
|
1225
1225
|
advanceBy(context, context.source.length);
|
|
1226
|
-
emitError(context, 7 /* EOF_IN_COMMENT */);
|
|
1226
|
+
emitError(context, 7 /* ErrorCodes.EOF_IN_COMMENT */);
|
|
1227
1227
|
}
|
|
1228
1228
|
else {
|
|
1229
1229
|
if (match.index <= 3) {
|
|
1230
|
-
emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1230
|
+
emitError(context, 0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1231
1231
|
}
|
|
1232
1232
|
if (match[1]) {
|
|
1233
|
-
emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
|
|
1233
|
+
emitError(context, 10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */);
|
|
1234
1234
|
}
|
|
1235
1235
|
content = context.source.slice(4, match.index);
|
|
1236
1236
|
// Advancing with reporting nested comments.
|
|
@@ -1239,14 +1239,14 @@ function parseComment(context) {
|
|
|
1239
1239
|
while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
|
|
1240
1240
|
advanceBy(context, nestedIndex - prevIndex + 1);
|
|
1241
1241
|
if (nestedIndex + 4 < s.length) {
|
|
1242
|
-
emitError(context, 16 /* NESTED_COMMENT */);
|
|
1242
|
+
emitError(context, 16 /* ErrorCodes.NESTED_COMMENT */);
|
|
1243
1243
|
}
|
|
1244
1244
|
prevIndex = nestedIndex + 1;
|
|
1245
1245
|
}
|
|
1246
1246
|
advanceBy(context, match.index + match[0].length - prevIndex + 1);
|
|
1247
1247
|
}
|
|
1248
1248
|
return {
|
|
1249
|
-
type: 3 /* COMMENT */,
|
|
1249
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1250
1250
|
content,
|
|
1251
1251
|
loc: getSelection(context, start)
|
|
1252
1252
|
};
|
|
@@ -1265,7 +1265,7 @@ function parseBogusComment(context) {
|
|
|
1265
1265
|
advanceBy(context, closeIndex + 1);
|
|
1266
1266
|
}
|
|
1267
1267
|
return {
|
|
1268
|
-
type: 3 /* COMMENT */,
|
|
1268
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1269
1269
|
content,
|
|
1270
1270
|
loc: getSelection(context, start)
|
|
1271
1271
|
};
|
|
@@ -1275,7 +1275,7 @@ function parseElement(context, ancestors) {
|
|
|
1275
1275
|
const wasInPre = context.inPre;
|
|
1276
1276
|
const wasInVPre = context.inVPre;
|
|
1277
1277
|
const parent = last(ancestors);
|
|
1278
|
-
const element = parseTag(context, 0 /* Start */, parent);
|
|
1278
|
+
const element = parseTag(context, 0 /* TagType.Start */, parent);
|
|
1279
1279
|
const isPreBoundary = context.inPre && !wasInPre;
|
|
1280
1280
|
const isVPreBoundary = context.inVPre && !wasInVPre;
|
|
1281
1281
|
if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
|
|
@@ -1295,12 +1295,12 @@ function parseElement(context, ancestors) {
|
|
|
1295
1295
|
ancestors.pop();
|
|
1296
1296
|
// 2.x inline-template compat
|
|
1297
1297
|
{
|
|
1298
|
-
const inlineTemplateProp = element.props.find(p => p.type === 6 /* ATTRIBUTE */ && p.name === 'inline-template');
|
|
1298
|
+
const inlineTemplateProp = element.props.find(p => p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'inline-template');
|
|
1299
1299
|
if (inlineTemplateProp &&
|
|
1300
|
-
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1300
|
+
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1301
1301
|
const loc = getSelection(context, element.loc.end);
|
|
1302
1302
|
inlineTemplateProp.value = {
|
|
1303
|
-
type: 2 /* TEXT */,
|
|
1303
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1304
1304
|
content: loc.source,
|
|
1305
1305
|
loc
|
|
1306
1306
|
};
|
|
@@ -1309,14 +1309,14 @@ function parseElement(context, ancestors) {
|
|
|
1309
1309
|
element.children = children;
|
|
1310
1310
|
// End tag.
|
|
1311
1311
|
if (startsWithEndTagOpen(context.source, element.tag)) {
|
|
1312
|
-
parseTag(context, 1 /* End */, parent);
|
|
1312
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
1313
1313
|
}
|
|
1314
1314
|
else {
|
|
1315
|
-
emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1315
|
+
emitError(context, 24 /* ErrorCodes.X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1316
1316
|
if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
|
|
1317
1317
|
const first = children[0];
|
|
1318
1318
|
if (first && startsWith(first.loc.source, '<!--')) {
|
|
1319
|
-
emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1319
|
+
emitError(context, 8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1320
1320
|
}
|
|
1321
1321
|
}
|
|
1322
1322
|
}
|
|
@@ -1348,9 +1348,9 @@ function parseTag(context, type, parent) {
|
|
|
1348
1348
|
// Attributes.
|
|
1349
1349
|
let props = parseAttributes(context, type);
|
|
1350
1350
|
// check v-pre
|
|
1351
|
-
if (type === 0 /* Start */ &&
|
|
1351
|
+
if (type === 0 /* TagType.Start */ &&
|
|
1352
1352
|
!context.inVPre &&
|
|
1353
|
-
props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
|
|
1353
|
+
props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'pre')) {
|
|
1354
1354
|
context.inVPre = true;
|
|
1355
1355
|
// reset context
|
|
1356
1356
|
extend(context, cursor);
|
|
@@ -1361,25 +1361,25 @@ function parseTag(context, type, parent) {
|
|
|
1361
1361
|
// Tag close.
|
|
1362
1362
|
let isSelfClosing = false;
|
|
1363
1363
|
if (context.source.length === 0) {
|
|
1364
|
-
emitError(context, 9 /* EOF_IN_TAG */);
|
|
1364
|
+
emitError(context, 9 /* ErrorCodes.EOF_IN_TAG */);
|
|
1365
1365
|
}
|
|
1366
1366
|
else {
|
|
1367
1367
|
isSelfClosing = startsWith(context.source, '/>');
|
|
1368
|
-
if (type === 1 /* End */ && isSelfClosing) {
|
|
1369
|
-
emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1368
|
+
if (type === 1 /* TagType.End */ && isSelfClosing) {
|
|
1369
|
+
emitError(context, 4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1370
1370
|
}
|
|
1371
1371
|
advanceBy(context, isSelfClosing ? 2 : 1);
|
|
1372
1372
|
}
|
|
1373
|
-
if (type === 1 /* End */) {
|
|
1373
|
+
if (type === 1 /* TagType.End */) {
|
|
1374
1374
|
return;
|
|
1375
1375
|
}
|
|
1376
1376
|
// 2.x deprecation checks
|
|
1377
|
-
if (isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context)) {
|
|
1377
|
+
if (isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */, context)) {
|
|
1378
1378
|
let hasIf = false;
|
|
1379
1379
|
let hasFor = false;
|
|
1380
1380
|
for (let i = 0; i < props.length; i++) {
|
|
1381
1381
|
const p = props[i];
|
|
1382
|
-
if (p.type === 7 /* DIRECTIVE */) {
|
|
1382
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1383
1383
|
if (p.name === 'if') {
|
|
1384
1384
|
hasIf = true;
|
|
1385
1385
|
}
|
|
@@ -1388,27 +1388,27 @@ function parseTag(context, type, parent) {
|
|
|
1388
1388
|
}
|
|
1389
1389
|
}
|
|
1390
1390
|
if (hasIf && hasFor) {
|
|
1391
|
-
warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context, getSelection(context, start));
|
|
1391
|
+
warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */, context, getSelection(context, start));
|
|
1392
1392
|
break;
|
|
1393
1393
|
}
|
|
1394
1394
|
}
|
|
1395
1395
|
}
|
|
1396
|
-
let tagType = 0 /* ELEMENT */;
|
|
1396
|
+
let tagType = 0 /* ElementTypes.ELEMENT */;
|
|
1397
1397
|
if (!context.inVPre) {
|
|
1398
1398
|
if (tag === 'slot') {
|
|
1399
|
-
tagType = 2 /* SLOT */;
|
|
1399
|
+
tagType = 2 /* ElementTypes.SLOT */;
|
|
1400
1400
|
}
|
|
1401
1401
|
else if (tag === 'template') {
|
|
1402
|
-
if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1403
|
-
tagType = 3 /* TEMPLATE */;
|
|
1402
|
+
if (props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1403
|
+
tagType = 3 /* ElementTypes.TEMPLATE */;
|
|
1404
1404
|
}
|
|
1405
1405
|
}
|
|
1406
1406
|
else if (isComponent(tag, props, context)) {
|
|
1407
|
-
tagType = 1 /* COMPONENT */;
|
|
1407
|
+
tagType = 1 /* ElementTypes.COMPONENT */;
|
|
1408
1408
|
}
|
|
1409
1409
|
}
|
|
1410
1410
|
return {
|
|
1411
|
-
type: 1 /* ELEMENT */,
|
|
1411
|
+
type: 1 /* NodeTypes.ELEMENT */,
|
|
1412
1412
|
ns,
|
|
1413
1413
|
tag,
|
|
1414
1414
|
tagType,
|
|
@@ -1435,12 +1435,12 @@ function isComponent(tag, props, context) {
|
|
|
1435
1435
|
// casting
|
|
1436
1436
|
for (let i = 0; i < props.length; i++) {
|
|
1437
1437
|
const p = props[i];
|
|
1438
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
1438
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
1439
1439
|
if (p.name === 'is' && p.value) {
|
|
1440
1440
|
if (p.value.content.startsWith('vue:')) {
|
|
1441
1441
|
return true;
|
|
1442
1442
|
}
|
|
1443
|
-
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1443
|
+
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1444
1444
|
return true;
|
|
1445
1445
|
}
|
|
1446
1446
|
}
|
|
@@ -1456,7 +1456,7 @@ function isComponent(tag, props, context) {
|
|
|
1456
1456
|
p.name === 'bind' &&
|
|
1457
1457
|
isStaticArgOf(p.arg, 'is') &&
|
|
1458
1458
|
true &&
|
|
1459
|
-
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1459
|
+
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1460
1460
|
return true;
|
|
1461
1461
|
}
|
|
1462
1462
|
}
|
|
@@ -1469,27 +1469,27 @@ function parseAttributes(context, type) {
|
|
|
1469
1469
|
!startsWith(context.source, '>') &&
|
|
1470
1470
|
!startsWith(context.source, '/>')) {
|
|
1471
1471
|
if (startsWith(context.source, '/')) {
|
|
1472
|
-
emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1472
|
+
emitError(context, 22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1473
1473
|
advanceBy(context, 1);
|
|
1474
1474
|
advanceSpaces(context);
|
|
1475
1475
|
continue;
|
|
1476
1476
|
}
|
|
1477
|
-
if (type === 1 /* End */) {
|
|
1478
|
-
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1477
|
+
if (type === 1 /* TagType.End */) {
|
|
1478
|
+
emitError(context, 3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */);
|
|
1479
1479
|
}
|
|
1480
1480
|
const attr = parseAttribute(context, attributeNames);
|
|
1481
1481
|
// Trim whitespace between class
|
|
1482
1482
|
// https://github.com/vuejs/core/issues/4251
|
|
1483
|
-
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1483
|
+
if (attr.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
1484
1484
|
attr.value &&
|
|
1485
1485
|
attr.name === 'class') {
|
|
1486
1486
|
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1487
1487
|
}
|
|
1488
|
-
if (type === 0 /* Start */) {
|
|
1488
|
+
if (type === 0 /* TagType.Start */) {
|
|
1489
1489
|
props.push(attr);
|
|
1490
1490
|
}
|
|
1491
1491
|
if (/^[^\t\r\n\f />]/.test(context.source)) {
|
|
1492
|
-
emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1492
|
+
emitError(context, 15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1493
1493
|
}
|
|
1494
1494
|
advanceSpaces(context);
|
|
1495
1495
|
}
|
|
@@ -1501,17 +1501,17 @@ function parseAttribute(context, nameSet) {
|
|
|
1501
1501
|
const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
|
|
1502
1502
|
const name = match[0];
|
|
1503
1503
|
if (nameSet.has(name)) {
|
|
1504
|
-
emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
|
|
1504
|
+
emitError(context, 2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */);
|
|
1505
1505
|
}
|
|
1506
1506
|
nameSet.add(name);
|
|
1507
1507
|
if (name[0] === '=') {
|
|
1508
|
-
emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1508
|
+
emitError(context, 19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1509
1509
|
}
|
|
1510
1510
|
{
|
|
1511
1511
|
const pattern = /["'<]/g;
|
|
1512
1512
|
let m;
|
|
1513
1513
|
while ((m = pattern.exec(name))) {
|
|
1514
|
-
emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1514
|
+
emitError(context, 17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1515
1515
|
}
|
|
1516
1516
|
}
|
|
1517
1517
|
advanceBy(context, name.length);
|
|
@@ -1523,7 +1523,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1523
1523
|
advanceSpaces(context);
|
|
1524
1524
|
value = parseAttributeValue(context);
|
|
1525
1525
|
if (!value) {
|
|
1526
|
-
emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
|
|
1526
|
+
emitError(context, 13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */);
|
|
1527
1527
|
}
|
|
1528
1528
|
}
|
|
1529
1529
|
const loc = getSelection(context, start);
|
|
@@ -1546,7 +1546,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1546
1546
|
if (content.startsWith('[')) {
|
|
1547
1547
|
isStatic = false;
|
|
1548
1548
|
if (!content.endsWith(']')) {
|
|
1549
|
-
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1549
|
+
emitError(context, 27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1550
1550
|
content = content.slice(1);
|
|
1551
1551
|
}
|
|
1552
1552
|
else {
|
|
@@ -1560,12 +1560,12 @@ function parseAttribute(context, nameSet) {
|
|
|
1560
1560
|
content += match[3] || '';
|
|
1561
1561
|
}
|
|
1562
1562
|
arg = {
|
|
1563
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1563
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1564
1564
|
content,
|
|
1565
1565
|
isStatic,
|
|
1566
1566
|
constType: isStatic
|
|
1567
|
-
? 3 /* CAN_STRINGIFY */
|
|
1568
|
-
: 0 /* NOT_CONSTANT */,
|
|
1567
|
+
? 3 /* ConstantTypes.CAN_STRINGIFY */
|
|
1568
|
+
: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1569
1569
|
loc
|
|
1570
1570
|
};
|
|
1571
1571
|
}
|
|
@@ -1582,24 +1582,24 @@ function parseAttribute(context, nameSet) {
|
|
|
1582
1582
|
// 2.x compat v-bind:foo.sync -> v-model:foo
|
|
1583
1583
|
if (dirName === 'bind' && arg) {
|
|
1584
1584
|
if (modifiers.includes('sync') &&
|
|
1585
|
-
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1585
|
+
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1586
1586
|
dirName = 'model';
|
|
1587
1587
|
modifiers.splice(modifiers.indexOf('sync'), 1);
|
|
1588
1588
|
}
|
|
1589
1589
|
if (modifiers.includes('prop')) {
|
|
1590
|
-
checkCompatEnabled("COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */, context, loc);
|
|
1590
|
+
checkCompatEnabled("COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */, context, loc);
|
|
1591
1591
|
}
|
|
1592
1592
|
}
|
|
1593
1593
|
return {
|
|
1594
|
-
type: 7 /* DIRECTIVE */,
|
|
1594
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
1595
1595
|
name: dirName,
|
|
1596
1596
|
exp: value && {
|
|
1597
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1597
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1598
1598
|
content: value.content,
|
|
1599
1599
|
isStatic: false,
|
|
1600
1600
|
// Treat as non-constant by default. This can be potentially set to
|
|
1601
1601
|
// other values by `transformExpression` to make it eligible for hoisting.
|
|
1602
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1602
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1603
1603
|
loc: value.loc
|
|
1604
1604
|
},
|
|
1605
1605
|
arg,
|
|
@@ -1609,13 +1609,13 @@ function parseAttribute(context, nameSet) {
|
|
|
1609
1609
|
}
|
|
1610
1610
|
// missing directive name or illegal directive name
|
|
1611
1611
|
if (!context.inVPre && startsWith(name, 'v-')) {
|
|
1612
|
-
emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
|
|
1612
|
+
emitError(context, 26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */);
|
|
1613
1613
|
}
|
|
1614
1614
|
return {
|
|
1615
|
-
type: 6 /* ATTRIBUTE */,
|
|
1615
|
+
type: 6 /* NodeTypes.ATTRIBUTE */,
|
|
1616
1616
|
name,
|
|
1617
1617
|
value: value && {
|
|
1618
|
-
type: 2 /* TEXT */,
|
|
1618
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1619
1619
|
content: value.content,
|
|
1620
1620
|
loc: value.loc
|
|
1621
1621
|
},
|
|
@@ -1632,10 +1632,10 @@ function parseAttributeValue(context) {
|
|
|
1632
1632
|
advanceBy(context, 1);
|
|
1633
1633
|
const endIndex = context.source.indexOf(quote);
|
|
1634
1634
|
if (endIndex === -1) {
|
|
1635
|
-
content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
|
|
1635
|
+
content = parseTextData(context, context.source.length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1636
1636
|
}
|
|
1637
1637
|
else {
|
|
1638
|
-
content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
|
|
1638
|
+
content = parseTextData(context, endIndex, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1639
1639
|
advanceBy(context, 1);
|
|
1640
1640
|
}
|
|
1641
1641
|
}
|
|
@@ -1648,9 +1648,9 @@ function parseAttributeValue(context) {
|
|
|
1648
1648
|
const unexpectedChars = /["'<=`]/g;
|
|
1649
1649
|
let m;
|
|
1650
1650
|
while ((m = unexpectedChars.exec(match[0]))) {
|
|
1651
|
-
emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1651
|
+
emitError(context, 18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1652
1652
|
}
|
|
1653
|
-
content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
|
|
1653
|
+
content = parseTextData(context, match[0].length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1654
1654
|
}
|
|
1655
1655
|
return { content, isQuoted, loc: getSelection(context, start) };
|
|
1656
1656
|
}
|
|
@@ -1658,7 +1658,7 @@ function parseInterpolation(context, mode) {
|
|
|
1658
1658
|
const [open, close] = context.options.delimiters;
|
|
1659
1659
|
const closeIndex = context.source.indexOf(close, open.length);
|
|
1660
1660
|
if (closeIndex === -1) {
|
|
1661
|
-
emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
|
|
1661
|
+
emitError(context, 25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */);
|
|
1662
1662
|
return undefined;
|
|
1663
1663
|
}
|
|
1664
1664
|
const start = getCursor(context);
|
|
@@ -1677,12 +1677,12 @@ function parseInterpolation(context, mode) {
|
|
|
1677
1677
|
advancePositionWithMutation(innerEnd, rawContent, endOffset);
|
|
1678
1678
|
advanceBy(context, close.length);
|
|
1679
1679
|
return {
|
|
1680
|
-
type: 5 /* INTERPOLATION */,
|
|
1680
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
1681
1681
|
content: {
|
|
1682
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1682
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1683
1683
|
isStatic: false,
|
|
1684
1684
|
// Set `isConstant` to false by default and will decide in transformExpression
|
|
1685
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1685
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1686
1686
|
content,
|
|
1687
1687
|
loc: getSelection(context, innerStart, innerEnd)
|
|
1688
1688
|
},
|
|
@@ -1690,7 +1690,7 @@ function parseInterpolation(context, mode) {
|
|
|
1690
1690
|
};
|
|
1691
1691
|
}
|
|
1692
1692
|
function parseText(context, mode) {
|
|
1693
|
-
const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1693
|
+
const endTokens = mode === 3 /* TextModes.CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1694
1694
|
let endIndex = context.source.length;
|
|
1695
1695
|
for (let i = 0; i < endTokens.length; i++) {
|
|
1696
1696
|
const index = context.source.indexOf(endTokens[i], 1);
|
|
@@ -1701,7 +1701,7 @@ function parseText(context, mode) {
|
|
|
1701
1701
|
const start = getCursor(context);
|
|
1702
1702
|
const content = parseTextData(context, endIndex, mode);
|
|
1703
1703
|
return {
|
|
1704
|
-
type: 2 /* TEXT */,
|
|
1704
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1705
1705
|
content,
|
|
1706
1706
|
loc: getSelection(context, start)
|
|
1707
1707
|
};
|
|
@@ -1713,14 +1713,14 @@ function parseText(context, mode) {
|
|
|
1713
1713
|
function parseTextData(context, length, mode) {
|
|
1714
1714
|
const rawText = context.source.slice(0, length);
|
|
1715
1715
|
advanceBy(context, length);
|
|
1716
|
-
if (mode === 2 /* RAWTEXT */ ||
|
|
1717
|
-
mode === 3 /* CDATA */ ||
|
|
1716
|
+
if (mode === 2 /* TextModes.RAWTEXT */ ||
|
|
1717
|
+
mode === 3 /* TextModes.CDATA */ ||
|
|
1718
1718
|
!rawText.includes('&')) {
|
|
1719
1719
|
return rawText;
|
|
1720
1720
|
}
|
|
1721
1721
|
else {
|
|
1722
1722
|
// DATA or RCDATA containing "&"". Entity decoding required.
|
|
1723
|
-
return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
|
|
1723
|
+
return context.options.decodeEntities(rawText, mode === 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1724
1724
|
}
|
|
1725
1725
|
}
|
|
1726
1726
|
function getCursor(context) {
|
|
@@ -1769,7 +1769,7 @@ function emitError(context, code, offset, loc = getCursor(context)) {
|
|
|
1769
1769
|
function isEnd(context, mode, ancestors) {
|
|
1770
1770
|
const s = context.source;
|
|
1771
1771
|
switch (mode) {
|
|
1772
|
-
case 0 /* DATA */:
|
|
1772
|
+
case 0 /* TextModes.DATA */:
|
|
1773
1773
|
if (startsWith(s, '</')) {
|
|
1774
1774
|
// TODO: probably bad performance
|
|
1775
1775
|
for (let i = ancestors.length - 1; i >= 0; --i) {
|
|
@@ -1779,15 +1779,15 @@ function isEnd(context, mode, ancestors) {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
}
|
|
1781
1781
|
break;
|
|
1782
|
-
case 1 /* RCDATA */:
|
|
1783
|
-
case 2 /* RAWTEXT */: {
|
|
1782
|
+
case 1 /* TextModes.RCDATA */:
|
|
1783
|
+
case 2 /* TextModes.RAWTEXT */: {
|
|
1784
1784
|
const parent = last(ancestors);
|
|
1785
1785
|
if (parent && startsWithEndTagOpen(s, parent.tag)) {
|
|
1786
1786
|
return true;
|
|
1787
1787
|
}
|
|
1788
1788
|
break;
|
|
1789
1789
|
}
|
|
1790
|
-
case 3 /* CDATA */:
|
|
1790
|
+
case 3 /* TextModes.CDATA */:
|
|
1791
1791
|
if (startsWith(s, ']]>')) {
|
|
1792
1792
|
return true;
|
|
1793
1793
|
}
|
|
@@ -1810,7 +1810,7 @@ function hoistStatic(root, context) {
|
|
|
1810
1810
|
function isSingleElementRoot(root, child) {
|
|
1811
1811
|
const { children } = root;
|
|
1812
1812
|
return (children.length === 1 &&
|
|
1813
|
-
child.type === 1 /* ELEMENT */ &&
|
|
1813
|
+
child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1814
1814
|
!isSlotOutlet(child));
|
|
1815
1815
|
}
|
|
1816
1816
|
function walk(node, context, doNotHoistNode = false) {
|
|
@@ -1820,15 +1820,15 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1820
1820
|
for (let i = 0; i < children.length; i++) {
|
|
1821
1821
|
const child = children[i];
|
|
1822
1822
|
// only plain elements & text calls are eligible for hoisting.
|
|
1823
|
-
if (child.type === 1 /* ELEMENT */ &&
|
|
1824
|
-
child.tagType === 0 /* ELEMENT */) {
|
|
1823
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1824
|
+
child.tagType === 0 /* ElementTypes.ELEMENT */) {
|
|
1825
1825
|
const constantType = doNotHoistNode
|
|
1826
|
-
? 0 /* NOT_CONSTANT */
|
|
1826
|
+
? 0 /* ConstantTypes.NOT_CONSTANT */
|
|
1827
1827
|
: getConstantType(child, context);
|
|
1828
|
-
if (constantType > 0 /* NOT_CONSTANT */) {
|
|
1829
|
-
if (constantType >= 2 /* CAN_HOIST */) {
|
|
1828
|
+
if (constantType > 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1829
|
+
if (constantType >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1830
1830
|
child.codegenNode.patchFlag =
|
|
1831
|
-
-1 /* HOISTED */ + (` /* HOISTED */` );
|
|
1831
|
+
-1 /* PatchFlags.HOISTED */ + (` /* HOISTED */` );
|
|
1832
1832
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1833
1833
|
hoistedCount++;
|
|
1834
1834
|
continue;
|
|
@@ -1838,13 +1838,13 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1838
1838
|
// node may contain dynamic children, but its props may be eligible for
|
|
1839
1839
|
// hoisting.
|
|
1840
1840
|
const codegenNode = child.codegenNode;
|
|
1841
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1841
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1842
1842
|
const flag = getPatchFlag(codegenNode);
|
|
1843
1843
|
if ((!flag ||
|
|
1844
|
-
flag === 512 /* NEED_PATCH */ ||
|
|
1845
|
-
flag === 1 /* TEXT */) &&
|
|
1844
|
+
flag === 512 /* PatchFlags.NEED_PATCH */ ||
|
|
1845
|
+
flag === 1 /* PatchFlags.TEXT */) &&
|
|
1846
1846
|
getGeneratedPropsConstantType(child, context) >=
|
|
1847
|
-
2 /* CAN_HOIST */) {
|
|
1847
|
+
2 /* ConstantTypes.CAN_HOIST */) {
|
|
1848
1848
|
const props = getNodeProps(child);
|
|
1849
1849
|
if (props) {
|
|
1850
1850
|
codegenNode.props = context.hoist(props);
|
|
@@ -1856,14 +1856,14 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1856
1856
|
}
|
|
1857
1857
|
}
|
|
1858
1858
|
}
|
|
1859
|
-
else if (child.type === 12 /* TEXT_CALL */ &&
|
|
1860
|
-
getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
|
|
1859
|
+
else if (child.type === 12 /* NodeTypes.TEXT_CALL */ &&
|
|
1860
|
+
getConstantType(child.content, context) >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1861
1861
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1862
1862
|
hoistedCount++;
|
|
1863
1863
|
}
|
|
1864
1864
|
// walk further
|
|
1865
|
-
if (child.type === 1 /* ELEMENT */) {
|
|
1866
|
-
const isComponent = child.tagType === 1 /* COMPONENT */;
|
|
1865
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */) {
|
|
1866
|
+
const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
1867
1867
|
if (isComponent) {
|
|
1868
1868
|
context.scopes.vSlot++;
|
|
1869
1869
|
}
|
|
@@ -1872,11 +1872,11 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1872
1872
|
context.scopes.vSlot--;
|
|
1873
1873
|
}
|
|
1874
1874
|
}
|
|
1875
|
-
else if (child.type === 11 /* FOR */) {
|
|
1875
|
+
else if (child.type === 11 /* NodeTypes.FOR */) {
|
|
1876
1876
|
// Do not hoist v-for single child because it has to be a block
|
|
1877
1877
|
walk(child, context, child.children.length === 1);
|
|
1878
1878
|
}
|
|
1879
|
-
else if (child.type === 9 /* IF */) {
|
|
1879
|
+
else if (child.type === 9 /* NodeTypes.IF */) {
|
|
1880
1880
|
for (let i = 0; i < child.branches.length; i++) {
|
|
1881
1881
|
// Do not hoist v-if single child because it has to be a block
|
|
1882
1882
|
walk(child.branches[i], context, child.branches[i].children.length === 1);
|
|
@@ -1889,10 +1889,10 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1889
1889
|
// all children were hoisted - the entire children array is hoistable.
|
|
1890
1890
|
if (hoistedCount &&
|
|
1891
1891
|
hoistedCount === originalCount &&
|
|
1892
|
-
node.type === 1 /* ELEMENT */ &&
|
|
1893
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
1892
|
+
node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1893
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
1894
1894
|
node.codegenNode &&
|
|
1895
|
-
node.codegenNode.type === 13 /* VNODE_CALL */ &&
|
|
1895
|
+
node.codegenNode.type === 13 /* NodeTypes.VNODE_CALL */ &&
|
|
1896
1896
|
isArray(node.codegenNode.children)) {
|
|
1897
1897
|
node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
|
|
1898
1898
|
}
|
|
@@ -1900,35 +1900,35 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1900
1900
|
function getConstantType(node, context) {
|
|
1901
1901
|
const { constantCache } = context;
|
|
1902
1902
|
switch (node.type) {
|
|
1903
|
-
case 1 /* ELEMENT */:
|
|
1904
|
-
if (node.tagType !== 0 /* ELEMENT */) {
|
|
1905
|
-
return 0 /* NOT_CONSTANT */;
|
|
1903
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
1904
|
+
if (node.tagType !== 0 /* ElementTypes.ELEMENT */) {
|
|
1905
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1906
1906
|
}
|
|
1907
1907
|
const cached = constantCache.get(node);
|
|
1908
1908
|
if (cached !== undefined) {
|
|
1909
1909
|
return cached;
|
|
1910
1910
|
}
|
|
1911
1911
|
const codegenNode = node.codegenNode;
|
|
1912
|
-
if (codegenNode.type !== 13 /* VNODE_CALL */) {
|
|
1913
|
-
return 0 /* NOT_CONSTANT */;
|
|
1912
|
+
if (codegenNode.type !== 13 /* NodeTypes.VNODE_CALL */) {
|
|
1913
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1914
1914
|
}
|
|
1915
1915
|
if (codegenNode.isBlock &&
|
|
1916
1916
|
node.tag !== 'svg' &&
|
|
1917
1917
|
node.tag !== 'foreignObject') {
|
|
1918
|
-
return 0 /* NOT_CONSTANT */;
|
|
1918
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1919
1919
|
}
|
|
1920
1920
|
const flag = getPatchFlag(codegenNode);
|
|
1921
1921
|
if (!flag) {
|
|
1922
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1922
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1923
1923
|
// Element itself has no patch flag. However we still need to check:
|
|
1924
1924
|
// 1. Even for a node with no patch flag, it is possible for it to contain
|
|
1925
1925
|
// non-hoistable expressions that refers to scope variables, e.g. compiler
|
|
1926
1926
|
// injected keys or cached event handlers. Therefore we need to always
|
|
1927
1927
|
// check the codegenNode's props to be sure.
|
|
1928
1928
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
1929
|
-
if (generatedPropsType === 0 /* NOT_CONSTANT */) {
|
|
1930
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1931
|
-
return 0 /* NOT_CONSTANT */;
|
|
1929
|
+
if (generatedPropsType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1930
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1931
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1932
1932
|
}
|
|
1933
1933
|
if (generatedPropsType < returnType) {
|
|
1934
1934
|
returnType = generatedPropsType;
|
|
@@ -1936,9 +1936,9 @@ function getConstantType(node, context) {
|
|
|
1936
1936
|
// 2. its children.
|
|
1937
1937
|
for (let i = 0; i < node.children.length; i++) {
|
|
1938
1938
|
const childType = getConstantType(node.children[i], context);
|
|
1939
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1940
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1941
|
-
return 0 /* NOT_CONSTANT */;
|
|
1939
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1940
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1941
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1942
1942
|
}
|
|
1943
1943
|
if (childType < returnType) {
|
|
1944
1944
|
returnType = childType;
|
|
@@ -1948,14 +1948,14 @@ function getConstantType(node, context) {
|
|
|
1948
1948
|
// type, check if any of the props can cause the type to be lowered
|
|
1949
1949
|
// we can skip can_patch because it's guaranteed by the absence of a
|
|
1950
1950
|
// patchFlag.
|
|
1951
|
-
if (returnType > 1 /* CAN_SKIP_PATCH */) {
|
|
1951
|
+
if (returnType > 1 /* ConstantTypes.CAN_SKIP_PATCH */) {
|
|
1952
1952
|
for (let i = 0; i < node.props.length; i++) {
|
|
1953
1953
|
const p = node.props[i];
|
|
1954
|
-
if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1954
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1955
1955
|
const expType = getConstantType(p.exp, context);
|
|
1956
|
-
if (expType === 0 /* NOT_CONSTANT */) {
|
|
1957
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1958
|
-
return 0 /* NOT_CONSTANT */;
|
|
1956
|
+
if (expType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1957
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1958
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1959
1959
|
}
|
|
1960
1960
|
if (expType < returnType) {
|
|
1961
1961
|
returnType = expType;
|
|
@@ -1967,6 +1967,14 @@ function getConstantType(node, context) {
|
|
|
1967
1967
|
// static then they don't need to be blocks since there will be no
|
|
1968
1968
|
// nested updates.
|
|
1969
1969
|
if (codegenNode.isBlock) {
|
|
1970
|
+
// except set custom directives.
|
|
1971
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
1972
|
+
const p = node.props[i];
|
|
1973
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1974
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1975
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1970
1978
|
context.removeHelper(OPEN_BLOCK);
|
|
1971
1979
|
context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
|
|
1972
1980
|
codegenNode.isBlock = false;
|
|
@@ -1976,31 +1984,31 @@ function getConstantType(node, context) {
|
|
|
1976
1984
|
return returnType;
|
|
1977
1985
|
}
|
|
1978
1986
|
else {
|
|
1979
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1980
|
-
return 0 /* NOT_CONSTANT */;
|
|
1981
|
-
}
|
|
1982
|
-
case 2 /* TEXT */:
|
|
1983
|
-
case 3 /* COMMENT */:
|
|
1984
|
-
return 3 /* CAN_STRINGIFY */;
|
|
1985
|
-
case 9 /* IF */:
|
|
1986
|
-
case 11 /* FOR */:
|
|
1987
|
-
case 10 /* IF_BRANCH */:
|
|
1988
|
-
return 0 /* NOT_CONSTANT */;
|
|
1989
|
-
case 5 /* INTERPOLATION */:
|
|
1990
|
-
case 12 /* TEXT_CALL */:
|
|
1987
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1988
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1989
|
+
}
|
|
1990
|
+
case 2 /* NodeTypes.TEXT */:
|
|
1991
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
1992
|
+
return 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1993
|
+
case 9 /* NodeTypes.IF */:
|
|
1994
|
+
case 11 /* NodeTypes.FOR */:
|
|
1995
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
1996
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1997
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
1998
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
1991
1999
|
return getConstantType(node.content, context);
|
|
1992
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
2000
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
1993
2001
|
return node.constType;
|
|
1994
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
1995
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
2002
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
2003
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1996
2004
|
for (let i = 0; i < node.children.length; i++) {
|
|
1997
2005
|
const child = node.children[i];
|
|
1998
2006
|
if (isString(child) || isSymbol(child)) {
|
|
1999
2007
|
continue;
|
|
2000
2008
|
}
|
|
2001
2009
|
const childType = getConstantType(child, context);
|
|
2002
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
2003
|
-
return 0 /* NOT_CONSTANT */;
|
|
2010
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
2011
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
2004
2012
|
}
|
|
2005
2013
|
else if (childType < returnType) {
|
|
2006
2014
|
returnType = childType;
|
|
@@ -2008,7 +2016,7 @@ function getConstantType(node, context) {
|
|
|
2008
2016
|
}
|
|
2009
2017
|
return returnType;
|
|
2010
2018
|
default:
|
|
2011
|
-
return 0 /* NOT_CONSTANT */;
|
|
2019
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
2012
2020
|
}
|
|
2013
2021
|
}
|
|
2014
2022
|
const allowHoistedHelperSet = new Set([
|
|
@@ -2018,48 +2026,48 @@ const allowHoistedHelperSet = new Set([
|
|
|
2018
2026
|
GUARD_REACTIVE_PROPS
|
|
2019
2027
|
]);
|
|
2020
2028
|
function getConstantTypeOfHelperCall(value, context) {
|
|
2021
|
-
if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
|
|
2029
|
+
if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
|
|
2022
2030
|
!isString(value.callee) &&
|
|
2023
2031
|
allowHoistedHelperSet.has(value.callee)) {
|
|
2024
2032
|
const arg = value.arguments[0];
|
|
2025
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2033
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2026
2034
|
return getConstantType(arg, context);
|
|
2027
2035
|
}
|
|
2028
|
-
else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
2036
|
+
else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
2029
2037
|
// in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
|
|
2030
2038
|
return getConstantTypeOfHelperCall(arg, context);
|
|
2031
2039
|
}
|
|
2032
2040
|
}
|
|
2033
|
-
return 0 /* NOT_CONSTANT */;
|
|
2041
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
2034
2042
|
}
|
|
2035
2043
|
function getGeneratedPropsConstantType(node, context) {
|
|
2036
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
2044
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
2037
2045
|
const props = getNodeProps(node);
|
|
2038
|
-
if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
2046
|
+
if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
2039
2047
|
const { properties } = props;
|
|
2040
2048
|
for (let i = 0; i < properties.length; i++) {
|
|
2041
2049
|
const { key, value } = properties[i];
|
|
2042
2050
|
const keyType = getConstantType(key, context);
|
|
2043
|
-
if (keyType === 0 /* NOT_CONSTANT */) {
|
|
2051
|
+
if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
2044
2052
|
return keyType;
|
|
2045
2053
|
}
|
|
2046
2054
|
if (keyType < returnType) {
|
|
2047
2055
|
returnType = keyType;
|
|
2048
2056
|
}
|
|
2049
2057
|
let valueType;
|
|
2050
|
-
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2058
|
+
if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2051
2059
|
valueType = getConstantType(value, context);
|
|
2052
2060
|
}
|
|
2053
|
-
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
2061
|
+
else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
2054
2062
|
// some helper calls can be hoisted,
|
|
2055
2063
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
2056
2064
|
// in this case we need to respect the ConstantType of the helper's arguments
|
|
2057
2065
|
valueType = getConstantTypeOfHelperCall(value, context);
|
|
2058
2066
|
}
|
|
2059
2067
|
else {
|
|
2060
|
-
valueType = 0 /* NOT_CONSTANT */;
|
|
2068
|
+
valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
2061
2069
|
}
|
|
2062
|
-
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
2070
|
+
if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
2063
2071
|
return valueType;
|
|
2064
2072
|
}
|
|
2065
2073
|
if (valueType < returnType) {
|
|
@@ -2071,7 +2079,7 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
2071
2079
|
}
|
|
2072
2080
|
function getNodeProps(node) {
|
|
2073
2081
|
const codegenNode = node.codegenNode;
|
|
2074
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
2082
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
2075
2083
|
return codegenNode.props;
|
|
2076
2084
|
}
|
|
2077
2085
|
}
|
|
@@ -2196,7 +2204,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
2196
2204
|
if (isString(exp))
|
|
2197
2205
|
exp = createSimpleExpression(exp);
|
|
2198
2206
|
context.hoists.push(exp);
|
|
2199
|
-
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
|
|
2207
|
+
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* ConstantTypes.CAN_HOIST */);
|
|
2200
2208
|
identifier.hoisted = exp;
|
|
2201
2209
|
return identifier;
|
|
2202
2210
|
},
|
|
@@ -2240,7 +2248,7 @@ function createRootCodegen(root, context) {
|
|
|
2240
2248
|
// single element root is never hoisted so codegenNode will never be
|
|
2241
2249
|
// SimpleExpressionNode
|
|
2242
2250
|
const codegenNode = child.codegenNode;
|
|
2243
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
2251
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
2244
2252
|
makeBlock(codegenNode, context);
|
|
2245
2253
|
}
|
|
2246
2254
|
root.codegenNode = codegenNode;
|
|
@@ -2254,13 +2262,13 @@ function createRootCodegen(root, context) {
|
|
|
2254
2262
|
}
|
|
2255
2263
|
else if (children.length > 1) {
|
|
2256
2264
|
// root has multiple nodes - return a fragment block.
|
|
2257
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
2258
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
2265
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
2266
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
2259
2267
|
// check if the fragment actually contains a single valid child with
|
|
2260
2268
|
// the rest being comments
|
|
2261
|
-
if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
2262
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
2263
|
-
patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
|
|
2269
|
+
if (children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
|
|
2270
|
+
patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
|
|
2271
|
+
patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
|
|
2264
2272
|
}
|
|
2265
2273
|
root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
|
|
2266
2274
|
}
|
|
@@ -2306,29 +2314,29 @@ function traverseNode(node, context) {
|
|
|
2306
2314
|
}
|
|
2307
2315
|
}
|
|
2308
2316
|
switch (node.type) {
|
|
2309
|
-
case 3 /* COMMENT */:
|
|
2317
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2310
2318
|
if (!context.ssr) {
|
|
2311
2319
|
// inject import for the Comment symbol, which is needed for creating
|
|
2312
2320
|
// comment nodes with `createVNode`
|
|
2313
2321
|
context.helper(CREATE_COMMENT);
|
|
2314
2322
|
}
|
|
2315
2323
|
break;
|
|
2316
|
-
case 5 /* INTERPOLATION */:
|
|
2324
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2317
2325
|
// no need to traverse, but we need to inject toString helper
|
|
2318
2326
|
if (!context.ssr) {
|
|
2319
2327
|
context.helper(TO_DISPLAY_STRING);
|
|
2320
2328
|
}
|
|
2321
2329
|
break;
|
|
2322
2330
|
// for container types, further traverse downwards
|
|
2323
|
-
case 9 /* IF */:
|
|
2331
|
+
case 9 /* NodeTypes.IF */:
|
|
2324
2332
|
for (let i = 0; i < node.branches.length; i++) {
|
|
2325
2333
|
traverseNode(node.branches[i], context);
|
|
2326
2334
|
}
|
|
2327
2335
|
break;
|
|
2328
|
-
case 10 /* IF_BRANCH */:
|
|
2329
|
-
case 11 /* FOR */:
|
|
2330
|
-
case 1 /* ELEMENT */:
|
|
2331
|
-
case 0 /* ROOT */:
|
|
2336
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2337
|
+
case 11 /* NodeTypes.FOR */:
|
|
2338
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2339
|
+
case 0 /* NodeTypes.ROOT */:
|
|
2332
2340
|
traverseChildren(node, context);
|
|
2333
2341
|
break;
|
|
2334
2342
|
}
|
|
@@ -2344,17 +2352,17 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
2344
2352
|
? (n) => n === name
|
|
2345
2353
|
: (n) => name.test(n);
|
|
2346
2354
|
return (node, context) => {
|
|
2347
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
2355
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2348
2356
|
const { props } = node;
|
|
2349
2357
|
// structural directive transforms are not concerned with slots
|
|
2350
2358
|
// as they are handled separately in vSlot.ts
|
|
2351
|
-
if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
|
|
2359
|
+
if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
|
|
2352
2360
|
return;
|
|
2353
2361
|
}
|
|
2354
2362
|
const exitFns = [];
|
|
2355
2363
|
for (let i = 0; i < props.length; i++) {
|
|
2356
2364
|
const prop = props[i];
|
|
2357
|
-
if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
|
|
2365
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
|
|
2358
2366
|
// structural directives are removed to avoid infinite recursion
|
|
2359
2367
|
// also we remove them *before* applying so that it can further
|
|
2360
2368
|
// traverse itself in case it moves the node around
|
|
@@ -2577,10 +2585,10 @@ function genHoists(hoists, context) {
|
|
|
2577
2585
|
}
|
|
2578
2586
|
function isText$1(n) {
|
|
2579
2587
|
return (isString(n) ||
|
|
2580
|
-
n.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
2581
|
-
n.type === 2 /* TEXT */ ||
|
|
2582
|
-
n.type === 5 /* INTERPOLATION */ ||
|
|
2583
|
-
n.type === 8 /* COMPOUND_EXPRESSION */);
|
|
2588
|
+
n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
2589
|
+
n.type === 2 /* NodeTypes.TEXT */ ||
|
|
2590
|
+
n.type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
2591
|
+
n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
|
|
2584
2592
|
}
|
|
2585
2593
|
function genNodeListAsArray(nodes, context) {
|
|
2586
2594
|
const multilines = nodes.length > 3 ||
|
|
@@ -2625,68 +2633,68 @@ function genNode(node, context) {
|
|
|
2625
2633
|
return;
|
|
2626
2634
|
}
|
|
2627
2635
|
switch (node.type) {
|
|
2628
|
-
case 1 /* ELEMENT */:
|
|
2629
|
-
case 9 /* IF */:
|
|
2630
|
-
case 11 /* FOR */:
|
|
2636
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2637
|
+
case 9 /* NodeTypes.IF */:
|
|
2638
|
+
case 11 /* NodeTypes.FOR */:
|
|
2631
2639
|
assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
|
|
2632
2640
|
`Apply appropriate transforms first.`);
|
|
2633
2641
|
genNode(node.codegenNode, context);
|
|
2634
2642
|
break;
|
|
2635
|
-
case 2 /* TEXT */:
|
|
2643
|
+
case 2 /* NodeTypes.TEXT */:
|
|
2636
2644
|
genText(node, context);
|
|
2637
2645
|
break;
|
|
2638
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
2646
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
2639
2647
|
genExpression(node, context);
|
|
2640
2648
|
break;
|
|
2641
|
-
case 5 /* INTERPOLATION */:
|
|
2649
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2642
2650
|
genInterpolation(node, context);
|
|
2643
2651
|
break;
|
|
2644
|
-
case 12 /* TEXT_CALL */:
|
|
2652
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
2645
2653
|
genNode(node.codegenNode, context);
|
|
2646
2654
|
break;
|
|
2647
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
2655
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
2648
2656
|
genCompoundExpression(node, context);
|
|
2649
2657
|
break;
|
|
2650
|
-
case 3 /* COMMENT */:
|
|
2658
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2651
2659
|
genComment(node, context);
|
|
2652
2660
|
break;
|
|
2653
|
-
case 13 /* VNODE_CALL */:
|
|
2661
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
2654
2662
|
genVNodeCall(node, context);
|
|
2655
2663
|
break;
|
|
2656
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
2664
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
2657
2665
|
genCallExpression(node, context);
|
|
2658
2666
|
break;
|
|
2659
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
2667
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
2660
2668
|
genObjectExpression(node, context);
|
|
2661
2669
|
break;
|
|
2662
|
-
case 17 /* JS_ARRAY_EXPRESSION */:
|
|
2670
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
2663
2671
|
genArrayExpression(node, context);
|
|
2664
2672
|
break;
|
|
2665
|
-
case 18 /* JS_FUNCTION_EXPRESSION */:
|
|
2673
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
2666
2674
|
genFunctionExpression(node, context);
|
|
2667
2675
|
break;
|
|
2668
|
-
case 19 /* JS_CONDITIONAL_EXPRESSION */:
|
|
2676
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
2669
2677
|
genConditionalExpression(node, context);
|
|
2670
2678
|
break;
|
|
2671
|
-
case 20 /* JS_CACHE_EXPRESSION */:
|
|
2679
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
2672
2680
|
genCacheExpression(node, context);
|
|
2673
2681
|
break;
|
|
2674
|
-
case 21 /* JS_BLOCK_STATEMENT */:
|
|
2682
|
+
case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
|
|
2675
2683
|
genNodeList(node.body, context, true, false);
|
|
2676
2684
|
break;
|
|
2677
2685
|
// SSR only types
|
|
2678
|
-
case 22 /* JS_TEMPLATE_LITERAL */:
|
|
2686
|
+
case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
|
|
2679
2687
|
break;
|
|
2680
|
-
case 23 /* JS_IF_STATEMENT */:
|
|
2688
|
+
case 23 /* NodeTypes.JS_IF_STATEMENT */:
|
|
2681
2689
|
break;
|
|
2682
|
-
case 24 /* JS_ASSIGNMENT_EXPRESSION */:
|
|
2690
|
+
case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
|
|
2683
2691
|
break;
|
|
2684
|
-
case 25 /* JS_SEQUENCE_EXPRESSION */:
|
|
2692
|
+
case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
|
|
2685
2693
|
break;
|
|
2686
|
-
case 26 /* JS_RETURN_STATEMENT */:
|
|
2694
|
+
case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
|
|
2687
2695
|
break;
|
|
2688
2696
|
/* istanbul ignore next */
|
|
2689
|
-
case 10 /* IF_BRANCH */:
|
|
2697
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2690
2698
|
// noop
|
|
2691
2699
|
break;
|
|
2692
2700
|
default:
|
|
@@ -2726,7 +2734,7 @@ function genCompoundExpression(node, context) {
|
|
|
2726
2734
|
}
|
|
2727
2735
|
function genExpressionAsPropertyKey(node, context) {
|
|
2728
2736
|
const { push } = context;
|
|
2729
|
-
if (node.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
2737
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
2730
2738
|
push(`[`);
|
|
2731
2739
|
genCompoundExpression(node, context);
|
|
2732
2740
|
push(`]`);
|
|
@@ -2803,7 +2811,7 @@ function genObjectExpression(node, context) {
|
|
|
2803
2811
|
return;
|
|
2804
2812
|
}
|
|
2805
2813
|
const multilines = properties.length > 1 ||
|
|
2806
|
-
(properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
|
|
2814
|
+
(properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
|
|
2807
2815
|
push(multilines ? `{` : `{ `);
|
|
2808
2816
|
multilines && indent();
|
|
2809
2817
|
for (let i = 0; i < properties.length; i++) {
|
|
@@ -2872,7 +2880,7 @@ function genFunctionExpression(node, context) {
|
|
|
2872
2880
|
function genConditionalExpression(node, context) {
|
|
2873
2881
|
const { test, consequent, alternate, newline: needNewline } = node;
|
|
2874
2882
|
const { push, indent, deindent, newline } = context;
|
|
2875
|
-
if (test.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2883
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2876
2884
|
const needsParens = !isSimpleIdentifier(test.content);
|
|
2877
2885
|
needsParens && push(`(`);
|
|
2878
2886
|
genExpression(test, context);
|
|
@@ -2892,7 +2900,7 @@ function genConditionalExpression(node, context) {
|
|
|
2892
2900
|
needNewline && newline();
|
|
2893
2901
|
needNewline || push(` `);
|
|
2894
2902
|
push(`: `);
|
|
2895
|
-
const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
|
|
2903
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
2896
2904
|
if (!isNested) {
|
|
2897
2905
|
context.indentLevel++;
|
|
2898
2906
|
}
|
|
@@ -3056,32 +3064,32 @@ function validateBrowserExpression(node, context, asParams = false, asRawStateme
|
|
|
3056
3064
|
if (keywordMatch) {
|
|
3057
3065
|
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
|
3058
3066
|
}
|
|
3059
|
-
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
3067
|
+
context.onError(createCompilerError(44 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
3060
3068
|
}
|
|
3061
3069
|
}
|
|
3062
3070
|
|
|
3063
3071
|
const transformExpression = (node, context) => {
|
|
3064
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
3072
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
3065
3073
|
node.content = processExpression(node.content, context);
|
|
3066
3074
|
}
|
|
3067
|
-
else if (node.type === 1 /* ELEMENT */) {
|
|
3075
|
+
else if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3068
3076
|
// handle directives on element
|
|
3069
3077
|
for (let i = 0; i < node.props.length; i++) {
|
|
3070
3078
|
const dir = node.props[i];
|
|
3071
3079
|
// do not process for v-on & v-for since they are special handled
|
|
3072
|
-
if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
|
|
3080
|
+
if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
|
|
3073
3081
|
const exp = dir.exp;
|
|
3074
3082
|
const arg = dir.arg;
|
|
3075
3083
|
// do not process exp if this is v-on:arg - we need special handling
|
|
3076
3084
|
// for wrapping inline statements.
|
|
3077
3085
|
if (exp &&
|
|
3078
|
-
exp.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3086
|
+
exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3079
3087
|
!(dir.name === 'on' && arg)) {
|
|
3080
3088
|
dir.exp = processExpression(exp, context,
|
|
3081
3089
|
// slot args must be processed as function params
|
|
3082
3090
|
dir.name === 'slot');
|
|
3083
3091
|
}
|
|
3084
|
-
if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
3092
|
+
if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
3085
3093
|
dir.arg = processExpression(arg, context);
|
|
3086
3094
|
}
|
|
3087
3095
|
}
|
|
@@ -3116,7 +3124,7 @@ const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (n
|
|
|
3116
3124
|
let key = 0;
|
|
3117
3125
|
while (i-- >= 0) {
|
|
3118
3126
|
const sibling = siblings[i];
|
|
3119
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3127
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
3120
3128
|
key += sibling.branches.length;
|
|
3121
3129
|
}
|
|
3122
3130
|
}
|
|
@@ -3139,7 +3147,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3139
3147
|
if (dir.name !== 'else' &&
|
|
3140
3148
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
3141
3149
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3142
|
-
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3150
|
+
context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3143
3151
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
3144
3152
|
}
|
|
3145
3153
|
if (dir.exp) {
|
|
@@ -3148,7 +3156,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3148
3156
|
if (dir.name === 'if') {
|
|
3149
3157
|
const branch = createIfBranch(node, dir);
|
|
3150
3158
|
const ifNode = {
|
|
3151
|
-
type: 9 /* IF */,
|
|
3159
|
+
type: 9 /* NodeTypes.IF */,
|
|
3152
3160
|
loc: node.loc,
|
|
3153
3161
|
branches: [branch]
|
|
3154
3162
|
};
|
|
@@ -3164,22 +3172,22 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3164
3172
|
let i = siblings.indexOf(node);
|
|
3165
3173
|
while (i-- >= -1) {
|
|
3166
3174
|
const sibling = siblings[i];
|
|
3167
|
-
if (sibling && sibling.type === 3 /* COMMENT */) {
|
|
3175
|
+
if (sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
|
|
3168
3176
|
context.removeNode(sibling);
|
|
3169
3177
|
comments.unshift(sibling);
|
|
3170
3178
|
continue;
|
|
3171
3179
|
}
|
|
3172
3180
|
if (sibling &&
|
|
3173
|
-
sibling.type === 2 /* TEXT */ &&
|
|
3181
|
+
sibling.type === 2 /* NodeTypes.TEXT */ &&
|
|
3174
3182
|
!sibling.content.trim().length) {
|
|
3175
3183
|
context.removeNode(sibling);
|
|
3176
3184
|
continue;
|
|
3177
3185
|
}
|
|
3178
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3186
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
3179
3187
|
// Check if v-else was followed by v-else-if
|
|
3180
3188
|
if (dir.name === 'else-if' &&
|
|
3181
3189
|
sibling.branches[sibling.branches.length - 1].condition === undefined) {
|
|
3182
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3190
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3183
3191
|
}
|
|
3184
3192
|
// move the node to the if node's branches
|
|
3185
3193
|
context.removeNode();
|
|
@@ -3187,7 +3195,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3187
3195
|
if (comments.length &&
|
|
3188
3196
|
// #3619 ignore comments if the v-if is direct child of <transition>
|
|
3189
3197
|
!(context.parent &&
|
|
3190
|
-
context.parent.type === 1 /* ELEMENT */ &&
|
|
3198
|
+
context.parent.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3191
3199
|
isBuiltInType(context.parent.tag, 'transition'))) {
|
|
3192
3200
|
branch.children = [...comments, ...branch.children];
|
|
3193
3201
|
}
|
|
@@ -3197,7 +3205,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3197
3205
|
if (key) {
|
|
3198
3206
|
sibling.branches.forEach(({ userKey }) => {
|
|
3199
3207
|
if (isSameKey(userKey, key)) {
|
|
3200
|
-
context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3208
|
+
context.onError(createCompilerError(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3201
3209
|
}
|
|
3202
3210
|
});
|
|
3203
3211
|
}
|
|
@@ -3215,16 +3223,16 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3215
3223
|
context.currentNode = null;
|
|
3216
3224
|
}
|
|
3217
3225
|
else {
|
|
3218
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3226
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3219
3227
|
}
|
|
3220
3228
|
break;
|
|
3221
3229
|
}
|
|
3222
3230
|
}
|
|
3223
3231
|
}
|
|
3224
3232
|
function createIfBranch(node, dir) {
|
|
3225
|
-
const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
|
|
3233
|
+
const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
|
|
3226
3234
|
return {
|
|
3227
|
-
type: 10 /* IF_BRANCH */,
|
|
3235
|
+
type: 10 /* NodeTypes.IF_BRANCH */,
|
|
3228
3236
|
loc: node.loc,
|
|
3229
3237
|
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
3230
3238
|
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
|
|
@@ -3248,26 +3256,26 @@ function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
|
3248
3256
|
}
|
|
3249
3257
|
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
3250
3258
|
const { helper } = context;
|
|
3251
|
-
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
|
|
3259
|
+
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
|
|
3252
3260
|
const { children } = branch;
|
|
3253
3261
|
const firstChild = children[0];
|
|
3254
|
-
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
|
|
3262
|
+
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
|
|
3255
3263
|
if (needFragmentWrapper) {
|
|
3256
|
-
if (children.length === 1 && firstChild.type === 11 /* FOR */) {
|
|
3264
|
+
if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
|
|
3257
3265
|
// optimize away nested fragments when child is a ForNode
|
|
3258
3266
|
const vnodeCall = firstChild.codegenNode;
|
|
3259
3267
|
injectProp(vnodeCall, keyProperty, context);
|
|
3260
3268
|
return vnodeCall;
|
|
3261
3269
|
}
|
|
3262
3270
|
else {
|
|
3263
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
3264
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
3271
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
3272
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
3265
3273
|
// check if the fragment actually contains a single valid child with
|
|
3266
3274
|
// the rest being comments
|
|
3267
3275
|
if (!branch.isTemplateIf &&
|
|
3268
|
-
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
3269
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
3270
|
-
patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
|
|
3276
|
+
children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
|
|
3277
|
+
patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
|
|
3278
|
+
patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
|
|
3271
3279
|
}
|
|
3272
3280
|
return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
|
|
3273
3281
|
}
|
|
@@ -3276,7 +3284,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
3276
3284
|
const ret = firstChild.codegenNode;
|
|
3277
3285
|
const vnodeCall = getMemoedVNodeCall(ret);
|
|
3278
3286
|
// Change createVNode to createBlock.
|
|
3279
|
-
if (vnodeCall.type === 13 /* VNODE_CALL */) {
|
|
3287
|
+
if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
3280
3288
|
makeBlock(vnodeCall, context);
|
|
3281
3289
|
}
|
|
3282
3290
|
// inject branch key
|
|
@@ -3288,7 +3296,7 @@ function isSameKey(a, b) {
|
|
|
3288
3296
|
if (!a || a.type !== b.type) {
|
|
3289
3297
|
return false;
|
|
3290
3298
|
}
|
|
3291
|
-
if (a.type === 6 /* ATTRIBUTE */) {
|
|
3299
|
+
if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3292
3300
|
if (a.value.content !== b.value.content) {
|
|
3293
3301
|
return false;
|
|
3294
3302
|
}
|
|
@@ -3300,7 +3308,7 @@ function isSameKey(a, b) {
|
|
|
3300
3308
|
if (exp.type !== branchExp.type) {
|
|
3301
3309
|
return false;
|
|
3302
3310
|
}
|
|
3303
|
-
if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3311
|
+
if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3304
3312
|
exp.isStatic !== branchExp.isStatic ||
|
|
3305
3313
|
exp.content !== branchExp.content) {
|
|
3306
3314
|
return false;
|
|
@@ -3310,15 +3318,15 @@ function isSameKey(a, b) {
|
|
|
3310
3318
|
}
|
|
3311
3319
|
function getParentCondition(node) {
|
|
3312
3320
|
while (true) {
|
|
3313
|
-
if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3314
|
-
if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3321
|
+
if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3322
|
+
if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3315
3323
|
node = node.alternate;
|
|
3316
3324
|
}
|
|
3317
3325
|
else {
|
|
3318
3326
|
return node;
|
|
3319
3327
|
}
|
|
3320
3328
|
}
|
|
3321
|
-
else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
|
|
3329
|
+
else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
3322
3330
|
node = node.value;
|
|
3323
3331
|
}
|
|
3324
3332
|
}
|
|
@@ -3336,17 +3344,17 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3336
3344
|
const memo = findDir(node, 'memo');
|
|
3337
3345
|
const keyProp = findProp(node, `key`);
|
|
3338
3346
|
const keyExp = keyProp &&
|
|
3339
|
-
(keyProp.type === 6 /* ATTRIBUTE */
|
|
3347
|
+
(keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3340
3348
|
? createSimpleExpression(keyProp.value.content, true)
|
|
3341
3349
|
: keyProp.exp);
|
|
3342
3350
|
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
|
3343
|
-
const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3344
|
-
forNode.source.constType > 0 /* NOT_CONSTANT */;
|
|
3351
|
+
const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3352
|
+
forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
3345
3353
|
const fragmentFlag = isStableFragment
|
|
3346
|
-
? 64 /* STABLE_FRAGMENT */
|
|
3354
|
+
? 64 /* PatchFlags.STABLE_FRAGMENT */
|
|
3347
3355
|
: keyProp
|
|
3348
|
-
? 128 /* KEYED_FRAGMENT */
|
|
3349
|
-
: 256 /* UNKEYED_FRAGMENT */;
|
|
3356
|
+
? 128 /* PatchFlags.KEYED_FRAGMENT */
|
|
3357
|
+
: 256 /* PatchFlags.UNKEYED_FRAGMENT */;
|
|
3350
3358
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
|
|
3351
3359
|
(` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
|
|
3352
3360
|
return () => {
|
|
@@ -3356,16 +3364,16 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3356
3364
|
// check <template v-for> key placement
|
|
3357
3365
|
if (isTemplate) {
|
|
3358
3366
|
node.children.some(c => {
|
|
3359
|
-
if (c.type === 1 /* ELEMENT */) {
|
|
3367
|
+
if (c.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3360
3368
|
const key = findProp(c, 'key');
|
|
3361
3369
|
if (key) {
|
|
3362
|
-
context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3370
|
+
context.onError(createCompilerError(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3363
3371
|
return true;
|
|
3364
3372
|
}
|
|
3365
3373
|
}
|
|
3366
3374
|
});
|
|
3367
3375
|
}
|
|
3368
|
-
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
|
|
3376
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
|
|
3369
3377
|
const slotOutlet = isSlotOutlet(node)
|
|
3370
3378
|
? node
|
|
3371
3379
|
: isTemplate &&
|
|
@@ -3386,8 +3394,8 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3386
3394
|
else if (needFragmentWrapper) {
|
|
3387
3395
|
// <template v-for="..."> with text or multi-elements
|
|
3388
3396
|
// should generate a fragment block for each loop
|
|
3389
|
-
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
|
|
3390
|
-
(` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
|
|
3397
|
+
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
|
|
3398
|
+
(` /* ${PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`
|
|
3391
3399
|
), undefined, undefined, true, undefined, false /* isComponent */);
|
|
3392
3400
|
}
|
|
3393
3401
|
else {
|
|
@@ -3444,7 +3452,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3444
3452
|
// target-agnostic transform used for both Client and SSR
|
|
3445
3453
|
function processFor(node, dir, context, processCodegen) {
|
|
3446
3454
|
if (!dir.exp) {
|
|
3447
|
-
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3455
|
+
context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3448
3456
|
return;
|
|
3449
3457
|
}
|
|
3450
3458
|
const parseResult = parseForExpression(
|
|
@@ -3452,13 +3460,13 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3452
3460
|
// before expression transform.
|
|
3453
3461
|
dir.exp, context);
|
|
3454
3462
|
if (!parseResult) {
|
|
3455
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3463
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3456
3464
|
return;
|
|
3457
3465
|
}
|
|
3458
3466
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
3459
3467
|
const { source, value, key, index } = parseResult;
|
|
3460
3468
|
const forNode = {
|
|
3461
|
-
type: 11 /* FOR */,
|
|
3469
|
+
type: 11 /* NodeTypes.FOR */,
|
|
3462
3470
|
loc: dir.loc,
|
|
3463
3471
|
source,
|
|
3464
3472
|
valueAlias: value,
|
|
@@ -3558,9 +3566,9 @@ const defaultFallback = createSimpleExpression(`undefined`, false);
|
|
|
3558
3566
|
// Note the exit callback is executed before buildSlots() on the same node,
|
|
3559
3567
|
// so only nested slots see positive numbers.
|
|
3560
3568
|
const trackSlotScopes = (node, context) => {
|
|
3561
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
3562
|
-
(node.tagType === 1 /* COMPONENT */ ||
|
|
3563
|
-
node.tagType === 3 /* TEMPLATE */)) {
|
|
3569
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3570
|
+
(node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
3571
|
+
node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
|
|
3564
3572
|
// We are only checking non-empty v-slot here
|
|
3565
3573
|
// since we only care about slots that introduce scope variables.
|
|
3566
3574
|
const vSlot = findDir(node, 'slot');
|
|
@@ -3622,20 +3630,21 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3622
3630
|
let hasNamedDefaultSlot = false;
|
|
3623
3631
|
const implicitDefaultChildren = [];
|
|
3624
3632
|
const seenSlotNames = new Set();
|
|
3633
|
+
let conditionalBranchIndex = 0;
|
|
3625
3634
|
for (let i = 0; i < children.length; i++) {
|
|
3626
3635
|
const slotElement = children[i];
|
|
3627
3636
|
let slotDir;
|
|
3628
3637
|
if (!isTemplateNode(slotElement) ||
|
|
3629
3638
|
!(slotDir = findDir(slotElement, 'slot', true))) {
|
|
3630
3639
|
// not a <template v-slot>, skip.
|
|
3631
|
-
if (slotElement.type !== 3 /* COMMENT */) {
|
|
3640
|
+
if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3632
3641
|
implicitDefaultChildren.push(slotElement);
|
|
3633
3642
|
}
|
|
3634
3643
|
continue;
|
|
3635
3644
|
}
|
|
3636
3645
|
if (onComponentSlot) {
|
|
3637
3646
|
// already has on-component slot - this is incorrect usage.
|
|
3638
|
-
context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3647
|
+
context.onError(createCompilerError(37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3639
3648
|
break;
|
|
3640
3649
|
}
|
|
3641
3650
|
hasTemplateSlots = true;
|
|
@@ -3656,7 +3665,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3656
3665
|
let vFor;
|
|
3657
3666
|
if ((vIf = findDir(slotElement, 'if'))) {
|
|
3658
3667
|
hasDynamicSlots = true;
|
|
3659
|
-
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
|
|
3668
|
+
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
|
|
3660
3669
|
}
|
|
3661
3670
|
else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
|
|
3662
3671
|
// find adjacent v-if
|
|
@@ -3664,7 +3673,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3664
3673
|
let prev;
|
|
3665
3674
|
while (j--) {
|
|
3666
3675
|
prev = children[j];
|
|
3667
|
-
if (prev.type !== 3 /* COMMENT */) {
|
|
3676
|
+
if (prev.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3668
3677
|
break;
|
|
3669
3678
|
}
|
|
3670
3679
|
}
|
|
@@ -3674,15 +3683,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3674
3683
|
i--;
|
|
3675
3684
|
// attach this slot to previous conditional
|
|
3676
3685
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
3677
|
-
while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3686
|
+
while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3678
3687
|
conditional = conditional.alternate;
|
|
3679
3688
|
}
|
|
3680
3689
|
conditional.alternate = vElse.exp
|
|
3681
|
-
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
|
|
3682
|
-
: buildDynamicSlot(slotName, slotFunction);
|
|
3690
|
+
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
|
|
3691
|
+
: buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
|
3683
3692
|
}
|
|
3684
3693
|
else {
|
|
3685
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
3694
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
3686
3695
|
}
|
|
3687
3696
|
}
|
|
3688
3697
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -3698,14 +3707,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3698
3707
|
]));
|
|
3699
3708
|
}
|
|
3700
3709
|
else {
|
|
3701
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3710
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3702
3711
|
}
|
|
3703
3712
|
}
|
|
3704
3713
|
else {
|
|
3705
3714
|
// check duplicate static names
|
|
3706
3715
|
if (staticSlotName) {
|
|
3707
3716
|
if (seenSlotNames.has(staticSlotName)) {
|
|
3708
|
-
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3717
|
+
context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3709
3718
|
continue;
|
|
3710
3719
|
}
|
|
3711
3720
|
seenSlotNames.add(staticSlotName);
|
|
@@ -3735,7 +3744,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3735
3744
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
3736
3745
|
// implicit default slot (mixed with named slots)
|
|
3737
3746
|
if (hasNamedDefaultSlot) {
|
|
3738
|
-
context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
3747
|
+
context.onError(createCompilerError(39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
3739
3748
|
}
|
|
3740
3749
|
else {
|
|
3741
3750
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -3743,10 +3752,10 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3743
3752
|
}
|
|
3744
3753
|
}
|
|
3745
3754
|
const slotFlag = hasDynamicSlots
|
|
3746
|
-
? 2 /* DYNAMIC */
|
|
3755
|
+
? 2 /* SlotFlags.DYNAMIC */
|
|
3747
3756
|
: hasForwardedSlots(node.children)
|
|
3748
|
-
? 3 /* FORWARDED */
|
|
3749
|
-
: 1 /* STABLE */;
|
|
3757
|
+
? 3 /* SlotFlags.FORWARDED */
|
|
3758
|
+
: 1 /* SlotFlags.STABLE */;
|
|
3750
3759
|
let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
|
|
3751
3760
|
// 2 = compiled but dynamic = can skip normalization, but must run diff
|
|
3752
3761
|
// 1 = compiled and static = can skip normalization AND diff as optimized
|
|
@@ -3762,28 +3771,32 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3762
3771
|
hasDynamicSlots
|
|
3763
3772
|
};
|
|
3764
3773
|
}
|
|
3765
|
-
function buildDynamicSlot(name, fn) {
|
|
3766
|
-
|
|
3774
|
+
function buildDynamicSlot(name, fn, index) {
|
|
3775
|
+
const props = [
|
|
3767
3776
|
createObjectProperty(`name`, name),
|
|
3768
3777
|
createObjectProperty(`fn`, fn)
|
|
3769
|
-
]
|
|
3778
|
+
];
|
|
3779
|
+
if (index != null) {
|
|
3780
|
+
props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
|
|
3781
|
+
}
|
|
3782
|
+
return createObjectExpression(props);
|
|
3770
3783
|
}
|
|
3771
3784
|
function hasForwardedSlots(children) {
|
|
3772
3785
|
for (let i = 0; i < children.length; i++) {
|
|
3773
3786
|
const child = children[i];
|
|
3774
3787
|
switch (child.type) {
|
|
3775
|
-
case 1 /* ELEMENT */:
|
|
3776
|
-
if (child.tagType === 2 /* SLOT */ ||
|
|
3788
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
3789
|
+
if (child.tagType === 2 /* ElementTypes.SLOT */ ||
|
|
3777
3790
|
hasForwardedSlots(child.children)) {
|
|
3778
3791
|
return true;
|
|
3779
3792
|
}
|
|
3780
3793
|
break;
|
|
3781
|
-
case 9 /* IF */:
|
|
3794
|
+
case 9 /* NodeTypes.IF */:
|
|
3782
3795
|
if (hasForwardedSlots(child.branches))
|
|
3783
3796
|
return true;
|
|
3784
3797
|
break;
|
|
3785
|
-
case 10 /* IF_BRANCH */:
|
|
3786
|
-
case 11 /* FOR */:
|
|
3798
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
3799
|
+
case 11 /* NodeTypes.FOR */:
|
|
3787
3800
|
if (hasForwardedSlots(child.children))
|
|
3788
3801
|
return true;
|
|
3789
3802
|
break;
|
|
@@ -3792,9 +3805,9 @@ function hasForwardedSlots(children) {
|
|
|
3792
3805
|
return false;
|
|
3793
3806
|
}
|
|
3794
3807
|
function isNonWhitespaceContent(node) {
|
|
3795
|
-
if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
|
|
3808
|
+
if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
|
|
3796
3809
|
return true;
|
|
3797
|
-
return node.type === 2 /* TEXT */
|
|
3810
|
+
return node.type === 2 /* NodeTypes.TEXT */
|
|
3798
3811
|
? !!node.content.trim()
|
|
3799
3812
|
: isNonWhitespaceContent(node.content);
|
|
3800
3813
|
}
|
|
@@ -3808,13 +3821,13 @@ const transformElement = (node, context) => {
|
|
|
3808
3821
|
// processed and merged.
|
|
3809
3822
|
return function postTransformElement() {
|
|
3810
3823
|
node = context.currentNode;
|
|
3811
|
-
if (!(node.type === 1 /* ELEMENT */ &&
|
|
3812
|
-
(node.tagType === 0 /* ELEMENT */ ||
|
|
3813
|
-
node.tagType === 1 /* COMPONENT */))) {
|
|
3824
|
+
if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3825
|
+
(node.tagType === 0 /* ElementTypes.ELEMENT */ ||
|
|
3826
|
+
node.tagType === 1 /* ElementTypes.COMPONENT */))) {
|
|
3814
3827
|
return;
|
|
3815
3828
|
}
|
|
3816
3829
|
const { tag, props } = node;
|
|
3817
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
3830
|
+
const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
3818
3831
|
// The goal of the transform is to create a codegenNode implementing the
|
|
3819
3832
|
// VNodeCall interface.
|
|
3820
3833
|
let vnodeTag = isComponent
|
|
@@ -3865,9 +3878,9 @@ const transformElement = (node, context) => {
|
|
|
3865
3878
|
// collected by a parent block.
|
|
3866
3879
|
shouldUseBlock = true;
|
|
3867
3880
|
// 2. Force keep-alive to always be updated, since it uses raw children.
|
|
3868
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3881
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3869
3882
|
if (node.children.length > 1) {
|
|
3870
|
-
context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3883
|
+
context.onError(createCompilerError(45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3871
3884
|
start: node.children[0].loc.start,
|
|
3872
3885
|
end: node.children[node.children.length - 1].loc.end,
|
|
3873
3886
|
source: ''
|
|
@@ -3883,22 +3896,22 @@ const transformElement = (node, context) => {
|
|
|
3883
3896
|
const { slots, hasDynamicSlots } = buildSlots(node, context);
|
|
3884
3897
|
vnodeChildren = slots;
|
|
3885
3898
|
if (hasDynamicSlots) {
|
|
3886
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3899
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3887
3900
|
}
|
|
3888
3901
|
}
|
|
3889
3902
|
else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
|
3890
3903
|
const child = node.children[0];
|
|
3891
3904
|
const type = child.type;
|
|
3892
3905
|
// check for dynamic text children
|
|
3893
|
-
const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
|
|
3894
|
-
type === 8 /* COMPOUND_EXPRESSION */;
|
|
3906
|
+
const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
3907
|
+
type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
|
|
3895
3908
|
if (hasDynamicTextChild &&
|
|
3896
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
3897
|
-
patchFlag |= 1 /* TEXT */;
|
|
3909
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
3910
|
+
patchFlag |= 1 /* PatchFlags.TEXT */;
|
|
3898
3911
|
}
|
|
3899
3912
|
// pass directly if the only child is a text node
|
|
3900
3913
|
// (plain / interpolation / expression)
|
|
3901
|
-
if (hasDynamicTextChild || type === 2 /* TEXT */) {
|
|
3914
|
+
if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
|
|
3902
3915
|
vnodeChildren = child;
|
|
3903
3916
|
}
|
|
3904
3917
|
else {
|
|
@@ -3940,8 +3953,8 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3940
3953
|
const isProp = findProp(node, 'is');
|
|
3941
3954
|
if (isProp) {
|
|
3942
3955
|
if (isExplicitDynamic ||
|
|
3943
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))) {
|
|
3944
|
-
const exp = isProp.type === 6 /* ATTRIBUTE */
|
|
3956
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))) {
|
|
3957
|
+
const exp = isProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3945
3958
|
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
|
3946
3959
|
: isProp.exp;
|
|
3947
3960
|
if (exp) {
|
|
@@ -3950,7 +3963,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3950
3963
|
]);
|
|
3951
3964
|
}
|
|
3952
3965
|
}
|
|
3953
|
-
else if (isProp.type === 6 /* ATTRIBUTE */ &&
|
|
3966
|
+
else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
3954
3967
|
isProp.value.content.startsWith('vue:')) {
|
|
3955
3968
|
// <button is="vue:xxx">
|
|
3956
3969
|
// if not <component>, only is value that starts with "vue:" will be
|
|
@@ -4014,9 +4027,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4014
4027
|
if (isEventHandler && isReservedProp(name)) {
|
|
4015
4028
|
hasVnodeHook = true;
|
|
4016
4029
|
}
|
|
4017
|
-
if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
|
|
4018
|
-
((value.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
4019
|
-
value.type === 8 /* COMPOUND_EXPRESSION */) &&
|
|
4030
|
+
if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */ ||
|
|
4031
|
+
((value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
4032
|
+
value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) &&
|
|
4020
4033
|
getConstantType(value, context) > 0)) {
|
|
4021
4034
|
// skip if the prop is a cached handler or has constant value
|
|
4022
4035
|
return;
|
|
@@ -4047,7 +4060,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4047
4060
|
for (let i = 0; i < props.length; i++) {
|
|
4048
4061
|
// static attribute
|
|
4049
4062
|
const prop = props[i];
|
|
4050
|
-
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
4063
|
+
if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4051
4064
|
const { loc, name, value } = prop;
|
|
4052
4065
|
let isStatic = true;
|
|
4053
4066
|
if (name === 'ref') {
|
|
@@ -4060,7 +4073,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4060
4073
|
if (name === 'is' &&
|
|
4061
4074
|
(isComponentTag(tag) ||
|
|
4062
4075
|
(value && value.content.startsWith('vue:')) ||
|
|
4063
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4076
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4064
4077
|
continue;
|
|
4065
4078
|
}
|
|
4066
4079
|
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
|
|
@@ -4073,7 +4086,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4073
4086
|
// skip v-slot - it is handled by its dedicated transform.
|
|
4074
4087
|
if (name === 'slot') {
|
|
4075
4088
|
if (!isComponent) {
|
|
4076
|
-
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
4089
|
+
context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
|
|
4077
4090
|
}
|
|
4078
4091
|
continue;
|
|
4079
4092
|
}
|
|
@@ -4086,7 +4099,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4086
4099
|
(isVBind &&
|
|
4087
4100
|
isStaticArgOf(arg, 'is') &&
|
|
4088
4101
|
(isComponentTag(tag) ||
|
|
4089
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
4102
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
4090
4103
|
continue;
|
|
4091
4104
|
}
|
|
4092
4105
|
// skip v-on in SSR compilation
|
|
@@ -4117,9 +4130,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4117
4130
|
// 2.x v-bind object order compat
|
|
4118
4131
|
{
|
|
4119
4132
|
const hasOverridableKeys = mergeArgs.some(arg => {
|
|
4120
|
-
if (arg.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
4133
|
+
if (arg.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
4121
4134
|
return arg.properties.some(({ key }) => {
|
|
4122
|
-
if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
4135
|
+
if (key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
4123
4136
|
!key.isStatic) {
|
|
4124
4137
|
return true;
|
|
4125
4138
|
}
|
|
@@ -4134,10 +4147,10 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4134
4147
|
}
|
|
4135
4148
|
});
|
|
4136
4149
|
if (hasOverridableKeys) {
|
|
4137
|
-
checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context, loc);
|
|
4150
|
+
checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */, context, loc);
|
|
4138
4151
|
}
|
|
4139
4152
|
}
|
|
4140
|
-
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
4153
|
+
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
4141
4154
|
mergeArgs.unshift(exp);
|
|
4142
4155
|
continue;
|
|
4143
4156
|
}
|
|
@@ -4147,17 +4160,17 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4147
4160
|
else {
|
|
4148
4161
|
// v-on="obj" -> toHandlers(obj)
|
|
4149
4162
|
mergeArgs.push({
|
|
4150
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
4163
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
4151
4164
|
loc,
|
|
4152
4165
|
callee: context.helper(TO_HANDLERS),
|
|
4153
|
-
arguments: [exp]
|
|
4166
|
+
arguments: isComponent ? [exp] : [exp, `true`]
|
|
4154
4167
|
});
|
|
4155
4168
|
}
|
|
4156
4169
|
}
|
|
4157
4170
|
else {
|
|
4158
4171
|
context.onError(createCompilerError(isVBind
|
|
4159
|
-
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
4160
|
-
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4172
|
+
? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
|
|
4173
|
+
: 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4161
4174
|
}
|
|
4162
4175
|
continue;
|
|
4163
4176
|
}
|
|
@@ -4204,31 +4217,31 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4204
4217
|
}
|
|
4205
4218
|
// patchFlag analysis
|
|
4206
4219
|
if (hasDynamicKeys) {
|
|
4207
|
-
patchFlag |= 16 /* FULL_PROPS */;
|
|
4220
|
+
patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
|
|
4208
4221
|
}
|
|
4209
4222
|
else {
|
|
4210
4223
|
if (hasClassBinding && !isComponent) {
|
|
4211
|
-
patchFlag |= 2 /* CLASS */;
|
|
4224
|
+
patchFlag |= 2 /* PatchFlags.CLASS */;
|
|
4212
4225
|
}
|
|
4213
4226
|
if (hasStyleBinding && !isComponent) {
|
|
4214
|
-
patchFlag |= 4 /* STYLE */;
|
|
4227
|
+
patchFlag |= 4 /* PatchFlags.STYLE */;
|
|
4215
4228
|
}
|
|
4216
4229
|
if (dynamicPropNames.length) {
|
|
4217
|
-
patchFlag |= 8 /* PROPS */;
|
|
4230
|
+
patchFlag |= 8 /* PatchFlags.PROPS */;
|
|
4218
4231
|
}
|
|
4219
4232
|
if (hasHydrationEventBinding) {
|
|
4220
|
-
patchFlag |= 32 /* HYDRATE_EVENTS */;
|
|
4233
|
+
patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
|
|
4221
4234
|
}
|
|
4222
4235
|
}
|
|
4223
4236
|
if (!shouldUseBlock &&
|
|
4224
|
-
(patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
|
|
4237
|
+
(patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
|
|
4225
4238
|
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
|
4226
|
-
patchFlag |= 512 /* NEED_PATCH */;
|
|
4239
|
+
patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
|
|
4227
4240
|
}
|
|
4228
4241
|
// pre-normalize props, SSR is skipped for now
|
|
4229
4242
|
if (!context.inSSR && propsExpression) {
|
|
4230
4243
|
switch (propsExpression.type) {
|
|
4231
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
4244
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
4232
4245
|
// means that there is no v-bind,
|
|
4233
4246
|
// but still need to deal with dynamic key binding
|
|
4234
4247
|
let classKeyIndex = -1;
|
|
@@ -4259,11 +4272,11 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4259
4272
|
// the static style is compiled into an object,
|
|
4260
4273
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4261
4274
|
(hasStyleBinding ||
|
|
4262
|
-
(styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
4275
|
+
(styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
4263
4276
|
styleProp.value.content.trim()[0] === `[`) ||
|
|
4264
4277
|
// v-bind:style and style both exist,
|
|
4265
4278
|
// v-bind:style with static literal object
|
|
4266
|
-
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4279
|
+
styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
|
|
4267
4280
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4268
4281
|
}
|
|
4269
4282
|
}
|
|
@@ -4272,7 +4285,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4272
4285
|
propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
|
|
4273
4286
|
}
|
|
4274
4287
|
break;
|
|
4275
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
4288
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
4276
4289
|
// mergeProps call, do nothing
|
|
4277
4290
|
break;
|
|
4278
4291
|
default:
|
|
@@ -4305,7 +4318,7 @@ function dedupeProperties(properties) {
|
|
|
4305
4318
|
for (let i = 0; i < properties.length; i++) {
|
|
4306
4319
|
const prop = properties[i];
|
|
4307
4320
|
// dynamic keys are always allowed
|
|
4308
|
-
if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4321
|
+
if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4309
4322
|
deduped.push(prop);
|
|
4310
4323
|
continue;
|
|
4311
4324
|
}
|
|
@@ -4325,7 +4338,7 @@ function dedupeProperties(properties) {
|
|
|
4325
4338
|
return deduped;
|
|
4326
4339
|
}
|
|
4327
4340
|
function mergeAsArray(existing, incoming) {
|
|
4328
|
-
if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
|
|
4341
|
+
if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
|
|
4329
4342
|
existing.value.elements.push(incoming.value);
|
|
4330
4343
|
}
|
|
4331
4344
|
else {
|
|
@@ -4414,7 +4427,7 @@ function processSlotOutlet(node, context) {
|
|
|
4414
4427
|
const nonNameProps = [];
|
|
4415
4428
|
for (let i = 0; i < node.props.length; i++) {
|
|
4416
4429
|
const p = node.props[i];
|
|
4417
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
4430
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4418
4431
|
if (p.value) {
|
|
4419
4432
|
if (p.name === 'name') {
|
|
4420
4433
|
slotName = JSON.stringify(p.value.content);
|
|
@@ -4442,7 +4455,7 @@ function processSlotOutlet(node, context) {
|
|
|
4442
4455
|
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
4443
4456
|
slotProps = props;
|
|
4444
4457
|
if (directives.length) {
|
|
4445
|
-
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4458
|
+
context.onError(createCompilerError(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4446
4459
|
}
|
|
4447
4460
|
}
|
|
4448
4461
|
return {
|
|
@@ -4455,18 +4468,26 @@ const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?functio
|
|
|
4455
4468
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4456
4469
|
const { loc, modifiers, arg } = dir;
|
|
4457
4470
|
if (!dir.exp && !modifiers.length) {
|
|
4458
|
-
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4471
|
+
context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4459
4472
|
}
|
|
4460
4473
|
let eventName;
|
|
4461
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4474
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4462
4475
|
if (arg.isStatic) {
|
|
4463
4476
|
let rawName = arg.content;
|
|
4464
4477
|
// TODO deprecate @vnodeXXX usage
|
|
4465
4478
|
if (rawName.startsWith('vue:')) {
|
|
4466
4479
|
rawName = `vnode-${rawName.slice(4)}`;
|
|
4467
4480
|
}
|
|
4468
|
-
|
|
4469
|
-
|
|
4481
|
+
const eventString = node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
4482
|
+
rawName.startsWith('vnode') ||
|
|
4483
|
+
!/[A-Z]/.test(rawName)
|
|
4484
|
+
? // for component and vnode lifecycle event listeners, auto convert
|
|
4485
|
+
// it to camelCase. See issue #2249
|
|
4486
|
+
toHandlerKey(camelize(rawName))
|
|
4487
|
+
// preserve case for plain element listeners that have uppercase
|
|
4488
|
+
// letters, as these may be custom elements' custom events
|
|
4489
|
+
: `on:${rawName}`;
|
|
4490
|
+
eventName = createSimpleExpression(eventString, true, arg.loc);
|
|
4470
4491
|
}
|
|
4471
4492
|
else {
|
|
4472
4493
|
// #2388
|
|
@@ -4533,7 +4554,7 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
4533
4554
|
const transformBind = (dir, _node, context) => {
|
|
4534
4555
|
const { exp, modifiers, loc } = dir;
|
|
4535
4556
|
const arg = dir.arg;
|
|
4536
|
-
if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
|
|
4557
|
+
if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4537
4558
|
arg.children.unshift(`(`);
|
|
4538
4559
|
arg.children.push(`) || ""`);
|
|
4539
4560
|
}
|
|
@@ -4542,7 +4563,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4542
4563
|
}
|
|
4543
4564
|
// .sync is replaced by v-model:arg
|
|
4544
4565
|
if (modifiers.includes('camel')) {
|
|
4545
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4566
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4546
4567
|
if (arg.isStatic) {
|
|
4547
4568
|
arg.content = camelize(arg.content);
|
|
4548
4569
|
}
|
|
@@ -4564,8 +4585,8 @@ const transformBind = (dir, _node, context) => {
|
|
|
4564
4585
|
}
|
|
4565
4586
|
}
|
|
4566
4587
|
if (!exp ||
|
|
4567
|
-
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4568
|
-
context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
|
|
4588
|
+
(exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4589
|
+
context.onError(createCompilerError(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
|
|
4569
4590
|
return {
|
|
4570
4591
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
4571
4592
|
};
|
|
@@ -4575,7 +4596,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4575
4596
|
};
|
|
4576
4597
|
};
|
|
4577
4598
|
const injectPrefix = (arg, prefix) => {
|
|
4578
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4599
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4579
4600
|
if (arg.isStatic) {
|
|
4580
4601
|
arg.content = prefix + arg.content;
|
|
4581
4602
|
}
|
|
@@ -4592,10 +4613,10 @@ const injectPrefix = (arg, prefix) => {
|
|
|
4592
4613
|
// Merge adjacent text nodes and expressions into a single expression
|
|
4593
4614
|
// e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
|
|
4594
4615
|
const transformText = (node, context) => {
|
|
4595
|
-
if (node.type === 0 /* ROOT */ ||
|
|
4596
|
-
node.type === 1 /* ELEMENT */ ||
|
|
4597
|
-
node.type === 11 /* FOR */ ||
|
|
4598
|
-
node.type === 10 /* IF_BRANCH */) {
|
|
4616
|
+
if (node.type === 0 /* NodeTypes.ROOT */ ||
|
|
4617
|
+
node.type === 1 /* NodeTypes.ELEMENT */ ||
|
|
4618
|
+
node.type === 11 /* NodeTypes.FOR */ ||
|
|
4619
|
+
node.type === 10 /* NodeTypes.IF_BRANCH */) {
|
|
4599
4620
|
// perform the transform on node exit so that all expressions have already
|
|
4600
4621
|
// been processed.
|
|
4601
4622
|
return () => {
|
|
@@ -4630,15 +4651,15 @@ const transformText = (node, context) => {
|
|
|
4630
4651
|
// setting textContent of the element.
|
|
4631
4652
|
// for component root it's always normalized anyway.
|
|
4632
4653
|
(children.length === 1 &&
|
|
4633
|
-
(node.type === 0 /* ROOT */ ||
|
|
4634
|
-
(node.type === 1 /* ELEMENT */ &&
|
|
4635
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
4654
|
+
(node.type === 0 /* NodeTypes.ROOT */ ||
|
|
4655
|
+
(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
4656
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
4636
4657
|
// #3756
|
|
4637
4658
|
// custom directives can potentially add DOM elements arbitrarily,
|
|
4638
4659
|
// we need to avoid setting textContent of the element at runtime
|
|
4639
4660
|
// to avoid accidentally overwriting the DOM elements added
|
|
4640
4661
|
// by the user through custom directives.
|
|
4641
|
-
!node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
|
|
4662
|
+
!node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4642
4663
|
!context.directiveTransforms[p.name]) &&
|
|
4643
4664
|
// in compat mode, <template> tags with no special directives
|
|
4644
4665
|
// will be rendered as a fragment so its children must be
|
|
@@ -4650,21 +4671,21 @@ const transformText = (node, context) => {
|
|
|
4650
4671
|
// runtime normalization.
|
|
4651
4672
|
for (let i = 0; i < children.length; i++) {
|
|
4652
4673
|
const child = children[i];
|
|
4653
|
-
if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4674
|
+
if (isText(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4654
4675
|
const callArgs = [];
|
|
4655
4676
|
// createTextVNode defaults to single whitespace, so if it is a
|
|
4656
4677
|
// single space the code could be an empty call to save bytes.
|
|
4657
|
-
if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
|
|
4678
|
+
if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
|
|
4658
4679
|
callArgs.push(child);
|
|
4659
4680
|
}
|
|
4660
4681
|
// mark dynamic text with flag so it gets patched inside a block
|
|
4661
4682
|
if (!context.ssr &&
|
|
4662
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
4663
|
-
callArgs.push(1 /* TEXT */ +
|
|
4664
|
-
(` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
|
|
4683
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
4684
|
+
callArgs.push(1 /* PatchFlags.TEXT */ +
|
|
4685
|
+
(` /* ${PatchFlagNames[1 /* PatchFlags.TEXT */]} */` ));
|
|
4665
4686
|
}
|
|
4666
4687
|
children[i] = {
|
|
4667
|
-
type: 12 /* TEXT_CALL */,
|
|
4688
|
+
type: 12 /* NodeTypes.TEXT_CALL */,
|
|
4668
4689
|
content: child,
|
|
4669
4690
|
loc: child.loc,
|
|
4670
4691
|
codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
|
|
@@ -4677,7 +4698,7 @@ const transformText = (node, context) => {
|
|
|
4677
4698
|
|
|
4678
4699
|
const seen = new WeakSet();
|
|
4679
4700
|
const transformOnce = (node, context) => {
|
|
4680
|
-
if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
|
|
4701
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
|
|
4681
4702
|
if (seen.has(node) || context.inVOnce) {
|
|
4682
4703
|
return;
|
|
4683
4704
|
}
|
|
@@ -4697,18 +4718,18 @@ const transformOnce = (node, context) => {
|
|
|
4697
4718
|
const transformModel = (dir, node, context) => {
|
|
4698
4719
|
const { exp, arg } = dir;
|
|
4699
4720
|
if (!exp) {
|
|
4700
|
-
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4721
|
+
context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4701
4722
|
return createTransformProps();
|
|
4702
4723
|
}
|
|
4703
4724
|
const rawExp = exp.loc.source;
|
|
4704
|
-
const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4725
|
+
const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4705
4726
|
// im SFC <script setup> inline mode, the exp may have been transformed into
|
|
4706
4727
|
// _unref(exp)
|
|
4707
4728
|
context.bindingMetadata[rawExp];
|
|
4708
|
-
const maybeRef = !true /* SETUP_CONST */;
|
|
4729
|
+
const maybeRef = !true /* BindingTypes.SETUP_CONST */;
|
|
4709
4730
|
if (!expString.trim() ||
|
|
4710
4731
|
(!isMemberExpression(expString) && !maybeRef)) {
|
|
4711
|
-
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4732
|
+
context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4712
4733
|
return createTransformProps();
|
|
4713
4734
|
}
|
|
4714
4735
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -4733,7 +4754,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4733
4754
|
createObjectProperty(eventName, assignmentExp)
|
|
4734
4755
|
];
|
|
4735
4756
|
// modelModifiers: { foo: true, "bar-baz": true }
|
|
4736
|
-
if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
|
|
4757
|
+
if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
4737
4758
|
const modifiers = dir.modifiers
|
|
4738
4759
|
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
|
|
4739
4760
|
.join(`, `);
|
|
@@ -4742,7 +4763,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4742
4763
|
? `${arg.content}Modifiers`
|
|
4743
4764
|
: createCompoundExpression([arg, ' + "Modifiers"'])
|
|
4744
4765
|
: `modelModifiers`;
|
|
4745
|
-
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
|
|
4766
|
+
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* ConstantTypes.CAN_HOIST */)));
|
|
4746
4767
|
}
|
|
4747
4768
|
return createTransformProps(props);
|
|
4748
4769
|
};
|
|
@@ -4752,17 +4773,17 @@ function createTransformProps(props = []) {
|
|
|
4752
4773
|
|
|
4753
4774
|
const validDivisionCharRE = /[\w).+\-_$\]]/;
|
|
4754
4775
|
const transformFilter = (node, context) => {
|
|
4755
|
-
if (!isCompatEnabled("COMPILER_FILTER" /* COMPILER_FILTERS */, context)) {
|
|
4776
|
+
if (!isCompatEnabled("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context)) {
|
|
4756
4777
|
return;
|
|
4757
4778
|
}
|
|
4758
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
4779
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4759
4780
|
// filter rewrite is applied before expression transform so only
|
|
4760
4781
|
// simple expressions are possible at this stage
|
|
4761
4782
|
rewriteFilter(node.content, context);
|
|
4762
4783
|
}
|
|
4763
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4784
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4764
4785
|
node.props.forEach((prop) => {
|
|
4765
|
-
if (prop.type === 7 /* DIRECTIVE */ &&
|
|
4786
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4766
4787
|
prop.name !== 'for' &&
|
|
4767
4788
|
prop.exp) {
|
|
4768
4789
|
rewriteFilter(prop.exp, context);
|
|
@@ -4771,7 +4792,7 @@ const transformFilter = (node, context) => {
|
|
|
4771
4792
|
}
|
|
4772
4793
|
};
|
|
4773
4794
|
function rewriteFilter(node, context) {
|
|
4774
|
-
if (node.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4795
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4775
4796
|
parseFilter(node, context);
|
|
4776
4797
|
}
|
|
4777
4798
|
else {
|
|
@@ -4779,13 +4800,13 @@ function rewriteFilter(node, context) {
|
|
|
4779
4800
|
const child = node.children[i];
|
|
4780
4801
|
if (typeof child !== 'object')
|
|
4781
4802
|
continue;
|
|
4782
|
-
if (child.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4803
|
+
if (child.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4783
4804
|
parseFilter(child, context);
|
|
4784
4805
|
}
|
|
4785
|
-
else if (child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4806
|
+
else if (child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4786
4807
|
rewriteFilter(node, context);
|
|
4787
4808
|
}
|
|
4788
|
-
else if (child.type === 5 /* INTERPOLATION */) {
|
|
4809
|
+
else if (child.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4789
4810
|
rewriteFilter(child.content, context);
|
|
4790
4811
|
}
|
|
4791
4812
|
}
|
|
@@ -4893,7 +4914,7 @@ function parseFilter(node, context) {
|
|
|
4893
4914
|
lastFilterIndex = i + 1;
|
|
4894
4915
|
}
|
|
4895
4916
|
if (filters.length) {
|
|
4896
|
-
warnDeprecation("COMPILER_FILTER" /* COMPILER_FILTERS */, context, node.loc);
|
|
4917
|
+
warnDeprecation("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context, node.loc);
|
|
4897
4918
|
for (i = 0; i < filters.length; i++) {
|
|
4898
4919
|
expression = wrapFilter(expression, filters[i], context);
|
|
4899
4920
|
}
|
|
@@ -4917,7 +4938,7 @@ function wrapFilter(exp, filter, context) {
|
|
|
4917
4938
|
|
|
4918
4939
|
const seen$1 = new WeakSet();
|
|
4919
4940
|
const transformMemo = (node, context) => {
|
|
4920
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4941
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4921
4942
|
const dir = findDir(node, 'memo');
|
|
4922
4943
|
if (!dir || seen$1.has(node)) {
|
|
4923
4944
|
return;
|
|
@@ -4926,9 +4947,9 @@ const transformMemo = (node, context) => {
|
|
|
4926
4947
|
return () => {
|
|
4927
4948
|
const codegenNode = node.codegenNode ||
|
|
4928
4949
|
context.currentNode.codegenNode;
|
|
4929
|
-
if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
|
|
4950
|
+
if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
4930
4951
|
// non-component sub tree should be turned into a block
|
|
4931
|
-
if (node.tagType !== 1 /* COMPONENT */) {
|
|
4952
|
+
if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
|
|
4932
4953
|
makeBlock(codegenNode, context);
|
|
4933
4954
|
}
|
|
4934
4955
|
node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
|
@@ -4972,18 +4993,18 @@ function baseCompile(template, options = {}) {
|
|
|
4972
4993
|
/* istanbul ignore if */
|
|
4973
4994
|
{
|
|
4974
4995
|
if (options.prefixIdentifiers === true) {
|
|
4975
|
-
onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4996
|
+
onError(createCompilerError(46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4976
4997
|
}
|
|
4977
4998
|
else if (isModuleMode) {
|
|
4978
|
-
onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4999
|
+
onError(createCompilerError(47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4979
5000
|
}
|
|
4980
5001
|
}
|
|
4981
5002
|
const prefixIdentifiers = !true ;
|
|
4982
5003
|
if (options.cacheHandlers) {
|
|
4983
|
-
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
5004
|
+
onError(createCompilerError(48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
4984
5005
|
}
|
|
4985
5006
|
if (options.scopeId && !isModuleMode) {
|
|
4986
|
-
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
5007
|
+
onError(createCompilerError(49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
|
|
4987
5008
|
}
|
|
4988
5009
|
const ast = isString(template) ? baseParse(template, options) : template;
|
|
4989
5010
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
|
@@ -5058,54 +5079,54 @@ const parserOptions = {
|
|
|
5058
5079
|
},
|
|
5059
5080
|
// https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
|
5060
5081
|
getNamespace(tag, parent) {
|
|
5061
|
-
let ns = parent ? parent.ns : 0 /* HTML */;
|
|
5062
|
-
if (parent && ns === 2 /* MATH_ML */) {
|
|
5082
|
+
let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
|
|
5083
|
+
if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
|
|
5063
5084
|
if (parent.tag === 'annotation-xml') {
|
|
5064
5085
|
if (tag === 'svg') {
|
|
5065
|
-
return 1 /* SVG */;
|
|
5086
|
+
return 1 /* DOMNamespaces.SVG */;
|
|
5066
5087
|
}
|
|
5067
|
-
if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
|
|
5088
|
+
if (parent.props.some(a => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
5068
5089
|
a.name === 'encoding' &&
|
|
5069
5090
|
a.value != null &&
|
|
5070
5091
|
(a.value.content === 'text/html' ||
|
|
5071
5092
|
a.value.content === 'application/xhtml+xml'))) {
|
|
5072
|
-
ns = 0 /* HTML */;
|
|
5093
|
+
ns = 0 /* DOMNamespaces.HTML */;
|
|
5073
5094
|
}
|
|
5074
5095
|
}
|
|
5075
5096
|
else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
|
|
5076
5097
|
tag !== 'mglyph' &&
|
|
5077
5098
|
tag !== 'malignmark') {
|
|
5078
|
-
ns = 0 /* HTML */;
|
|
5099
|
+
ns = 0 /* DOMNamespaces.HTML */;
|
|
5079
5100
|
}
|
|
5080
5101
|
}
|
|
5081
|
-
else if (parent && ns === 1 /* SVG */) {
|
|
5102
|
+
else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
|
|
5082
5103
|
if (parent.tag === 'foreignObject' ||
|
|
5083
5104
|
parent.tag === 'desc' ||
|
|
5084
5105
|
parent.tag === 'title') {
|
|
5085
|
-
ns = 0 /* HTML */;
|
|
5106
|
+
ns = 0 /* DOMNamespaces.HTML */;
|
|
5086
5107
|
}
|
|
5087
5108
|
}
|
|
5088
|
-
if (ns === 0 /* HTML */) {
|
|
5109
|
+
if (ns === 0 /* DOMNamespaces.HTML */) {
|
|
5089
5110
|
if (tag === 'svg') {
|
|
5090
|
-
return 1 /* SVG */;
|
|
5111
|
+
return 1 /* DOMNamespaces.SVG */;
|
|
5091
5112
|
}
|
|
5092
5113
|
if (tag === 'math') {
|
|
5093
|
-
return 2 /* MATH_ML */;
|
|
5114
|
+
return 2 /* DOMNamespaces.MATH_ML */;
|
|
5094
5115
|
}
|
|
5095
5116
|
}
|
|
5096
5117
|
return ns;
|
|
5097
5118
|
},
|
|
5098
5119
|
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
|
|
5099
5120
|
getTextMode({ tag, ns }) {
|
|
5100
|
-
if (ns === 0 /* HTML */) {
|
|
5121
|
+
if (ns === 0 /* DOMNamespaces.HTML */) {
|
|
5101
5122
|
if (tag === 'textarea' || tag === 'title') {
|
|
5102
|
-
return 1 /* RCDATA */;
|
|
5123
|
+
return 1 /* TextModes.RCDATA */;
|
|
5103
5124
|
}
|
|
5104
5125
|
if (isRawTextContainer(tag)) {
|
|
5105
|
-
return 2 /* RAWTEXT */;
|
|
5126
|
+
return 2 /* TextModes.RAWTEXT */;
|
|
5106
5127
|
}
|
|
5107
5128
|
}
|
|
5108
|
-
return 0 /* DATA */;
|
|
5129
|
+
return 0 /* TextModes.DATA */;
|
|
5109
5130
|
}
|
|
5110
5131
|
};
|
|
5111
5132
|
|
|
@@ -5116,12 +5137,12 @@ const parserOptions = {
|
|
|
5116
5137
|
// It is then processed by `transformElement` and included in the generated
|
|
5117
5138
|
// props.
|
|
5118
5139
|
const transformStyle = node => {
|
|
5119
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
5140
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
5120
5141
|
node.props.forEach((p, i) => {
|
|
5121
|
-
if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
|
|
5142
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'style' && p.value) {
|
|
5122
5143
|
// replace p with an expression node
|
|
5123
5144
|
node.props[i] = {
|
|
5124
|
-
type: 7 /* DIRECTIVE */,
|
|
5145
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
5125
5146
|
name: `bind`,
|
|
5126
5147
|
arg: createSimpleExpression(`style`, true, p.loc),
|
|
5127
5148
|
exp: parseInlineCSS(p.value.content, p.loc),
|
|
@@ -5134,33 +5155,33 @@ const transformStyle = node => {
|
|
|
5134
5155
|
};
|
|
5135
5156
|
const parseInlineCSS = (cssText, loc) => {
|
|
5136
5157
|
const normalized = parseStringStyle(cssText);
|
|
5137
|
-
return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
|
|
5158
|
+
return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
5138
5159
|
};
|
|
5139
5160
|
|
|
5140
5161
|
function createDOMCompilerError(code, loc) {
|
|
5141
5162
|
return createCompilerError(code, loc, DOMErrorMessages );
|
|
5142
5163
|
}
|
|
5143
5164
|
const DOMErrorMessages = {
|
|
5144
|
-
[50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
|
|
5145
|
-
[51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
|
|
5146
|
-
[52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
|
|
5147
|
-
[53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
|
|
5148
|
-
[54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
|
5149
|
-
[55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
|
|
5150
|
-
[56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
|
5151
|
-
[57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
|
5152
|
-
[58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
|
|
5153
|
-
[59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
|
|
5154
|
-
[60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
|
5165
|
+
[50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
|
|
5166
|
+
[51 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
|
|
5167
|
+
[52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
|
|
5168
|
+
[53 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
|
|
5169
|
+
[54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
|
5170
|
+
[55 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
|
|
5171
|
+
[56 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
|
5172
|
+
[57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
|
5173
|
+
[58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
|
|
5174
|
+
[59 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
|
|
5175
|
+
[60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
|
5155
5176
|
};
|
|
5156
5177
|
|
|
5157
5178
|
const transformVHtml = (dir, node, context) => {
|
|
5158
5179
|
const { exp, loc } = dir;
|
|
5159
5180
|
if (!exp) {
|
|
5160
|
-
context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
|
|
5181
|
+
context.onError(createDOMCompilerError(50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
|
|
5161
5182
|
}
|
|
5162
5183
|
if (node.children.length) {
|
|
5163
|
-
context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
|
|
5184
|
+
context.onError(createDOMCompilerError(51 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */, loc));
|
|
5164
5185
|
node.children.length = 0;
|
|
5165
5186
|
}
|
|
5166
5187
|
return {
|
|
@@ -5173,10 +5194,10 @@ const transformVHtml = (dir, node, context) => {
|
|
|
5173
5194
|
const transformVText = (dir, node, context) => {
|
|
5174
5195
|
const { exp, loc } = dir;
|
|
5175
5196
|
if (!exp) {
|
|
5176
|
-
context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
|
|
5197
|
+
context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
|
|
5177
5198
|
}
|
|
5178
5199
|
if (node.children.length) {
|
|
5179
|
-
context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
|
|
5200
|
+
context.onError(createDOMCompilerError(53 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */, loc));
|
|
5180
5201
|
node.children.length = 0;
|
|
5181
5202
|
}
|
|
5182
5203
|
return {
|
|
@@ -5193,16 +5214,16 @@ const transformVText = (dir, node, context) => {
|
|
|
5193
5214
|
const transformModel$1 = (dir, node, context) => {
|
|
5194
5215
|
const baseResult = transformModel(dir, node, context);
|
|
5195
5216
|
// base transform has errors OR component v-model (only need props)
|
|
5196
|
-
if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
|
|
5217
|
+
if (!baseResult.props.length || node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
5197
5218
|
return baseResult;
|
|
5198
5219
|
}
|
|
5199
5220
|
if (dir.arg) {
|
|
5200
|
-
context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
|
|
5221
|
+
context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
|
|
5201
5222
|
}
|
|
5202
5223
|
function checkDuplicatedValue() {
|
|
5203
5224
|
const value = findProp(node, 'value');
|
|
5204
5225
|
if (value) {
|
|
5205
|
-
context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
|
|
5226
|
+
context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
|
|
5206
5227
|
}
|
|
5207
5228
|
}
|
|
5208
5229
|
const { tag } = node;
|
|
@@ -5216,7 +5237,7 @@ const transformModel$1 = (dir, node, context) => {
|
|
|
5216
5237
|
if (tag === 'input' || isCustomElement) {
|
|
5217
5238
|
const type = findProp(node, `type`);
|
|
5218
5239
|
if (type) {
|
|
5219
|
-
if (type.type === 7 /* DIRECTIVE */) {
|
|
5240
|
+
if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
5220
5241
|
// :type="foo"
|
|
5221
5242
|
directiveToUse = V_MODEL_DYNAMIC;
|
|
5222
5243
|
}
|
|
@@ -5230,7 +5251,7 @@ const transformModel$1 = (dir, node, context) => {
|
|
|
5230
5251
|
break;
|
|
5231
5252
|
case 'file':
|
|
5232
5253
|
isInvalidType = true;
|
|
5233
|
-
context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
|
|
5254
|
+
context.onError(createDOMCompilerError(56 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
|
|
5234
5255
|
break;
|
|
5235
5256
|
default:
|
|
5236
5257
|
// text type
|
|
@@ -5264,11 +5285,11 @@ const transformModel$1 = (dir, node, context) => {
|
|
|
5264
5285
|
}
|
|
5265
5286
|
}
|
|
5266
5287
|
else {
|
|
5267
|
-
context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
|
|
5288
|
+
context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
|
|
5268
5289
|
}
|
|
5269
5290
|
// native vmodel doesn't need the `modelValue` props since they are also
|
|
5270
5291
|
// passed to the runtime as `binding.value`. removing it reduces code size.
|
|
5271
|
-
baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
5292
|
+
baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
5272
5293
|
p.key.content === 'modelValue'));
|
|
5273
5294
|
return baseResult;
|
|
5274
5295
|
};
|
|
@@ -5291,7 +5312,7 @@ const resolveModifiers = (key, modifiers, context, loc) => {
|
|
|
5291
5312
|
for (let i = 0; i < modifiers.length; i++) {
|
|
5292
5313
|
const modifier = modifiers[i];
|
|
5293
5314
|
if (modifier === 'native' &&
|
|
5294
|
-
checkCompatEnabled("COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */, context, loc)) {
|
|
5315
|
+
checkCompatEnabled("COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */, context, loc)) {
|
|
5295
5316
|
eventOptionModifiers.push(modifier);
|
|
5296
5317
|
}
|
|
5297
5318
|
else if (isEventOptionModifier(modifier)) {
|
|
@@ -5335,7 +5356,7 @@ const transformClick = (key, event) => {
|
|
|
5335
5356
|
const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
|
|
5336
5357
|
return isStaticClick
|
|
5337
5358
|
? createSimpleExpression(event, true)
|
|
5338
|
-
: key.type !== 4 /* SIMPLE_EXPRESSION */
|
|
5359
|
+
: key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
|
|
5339
5360
|
? createCompoundExpression([
|
|
5340
5361
|
`(`,
|
|
5341
5362
|
key,
|
|
@@ -5388,7 +5409,7 @@ const transformOn$1 = (dir, node, context) => {
|
|
|
5388
5409
|
const transformShow = (dir, node, context) => {
|
|
5389
5410
|
const { exp, loc } = dir;
|
|
5390
5411
|
if (!exp) {
|
|
5391
|
-
context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
|
|
5412
|
+
context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
|
|
5392
5413
|
}
|
|
5393
5414
|
return {
|
|
5394
5415
|
props: [],
|
|
@@ -5397,8 +5418,8 @@ const transformShow = (dir, node, context) => {
|
|
|
5397
5418
|
};
|
|
5398
5419
|
|
|
5399
5420
|
const transformTransition = (node, context) => {
|
|
5400
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
5401
|
-
node.tagType === 1 /* COMPONENT */) {
|
|
5421
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
5422
|
+
node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
5402
5423
|
const component = context.isBuiltInComponent(node.tag);
|
|
5403
5424
|
if (component === TRANSITION) {
|
|
5404
5425
|
return () => {
|
|
@@ -5407,7 +5428,7 @@ const transformTransition = (node, context) => {
|
|
|
5407
5428
|
}
|
|
5408
5429
|
// warn multiple transition children
|
|
5409
5430
|
if (hasMultipleChildren(node)) {
|
|
5410
|
-
context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
|
|
5431
|
+
context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */, {
|
|
5411
5432
|
start: node.children[0].loc.start,
|
|
5412
5433
|
end: node.children[node.children.length - 1].loc.end,
|
|
5413
5434
|
source: ''
|
|
@@ -5416,11 +5437,11 @@ const transformTransition = (node, context) => {
|
|
|
5416
5437
|
// check if it's s single child w/ v-show
|
|
5417
5438
|
// if yes, inject "persisted: true" to the transition props
|
|
5418
5439
|
const child = node.children[0];
|
|
5419
|
-
if (child.type === 1 /* ELEMENT */) {
|
|
5440
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */) {
|
|
5420
5441
|
for (const p of child.props) {
|
|
5421
|
-
if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
|
|
5442
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'show') {
|
|
5422
5443
|
node.props.push({
|
|
5423
|
-
type: 6 /* ATTRIBUTE */,
|
|
5444
|
+
type: 6 /* NodeTypes.ATTRIBUTE */,
|
|
5424
5445
|
name: 'persisted',
|
|
5425
5446
|
value: undefined,
|
|
5426
5447
|
loc: node.loc
|
|
@@ -5434,19 +5455,19 @@ const transformTransition = (node, context) => {
|
|
|
5434
5455
|
};
|
|
5435
5456
|
function hasMultipleChildren(node) {
|
|
5436
5457
|
// #1352 filter out potential comment nodes.
|
|
5437
|
-
const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
|
|
5438
|
-
!(c.type === 2 /* TEXT */ && !c.content.trim())));
|
|
5458
|
+
const children = (node.children = node.children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */ &&
|
|
5459
|
+
!(c.type === 2 /* NodeTypes.TEXT */ && !c.content.trim())));
|
|
5439
5460
|
const child = children[0];
|
|
5440
5461
|
return (children.length !== 1 ||
|
|
5441
|
-
child.type === 11 /* FOR */ ||
|
|
5442
|
-
(child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
|
|
5462
|
+
child.type === 11 /* NodeTypes.FOR */ ||
|
|
5463
|
+
(child.type === 9 /* NodeTypes.IF */ && child.branches.some(hasMultipleChildren)));
|
|
5443
5464
|
}
|
|
5444
5465
|
|
|
5445
5466
|
const ignoreSideEffectTags = (node, context) => {
|
|
5446
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
5447
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
5467
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
5468
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
5448
5469
|
(node.tag === 'script' || node.tag === 'style')) {
|
|
5449
|
-
context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
|
|
5470
|
+
context.onError(createDOMCompilerError(60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
|
|
5450
5471
|
context.removeNode();
|
|
5451
5472
|
}
|
|
5452
5473
|
};
|