@vue/compiler-core 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-core.cjs.js +553 -532
- package/dist/compiler-core.cjs.prod.js +532 -511
- package/dist/compiler-core.esm-bundler.js +522 -501
- package/package.json +2 -2
|
@@ -18,65 +18,65 @@ function createCompilerError(code, loc, messages, additionalMessage) {
|
|
|
18
18
|
}
|
|
19
19
|
const errorMessages = {
|
|
20
20
|
// parse errors
|
|
21
|
-
[0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
22
|
-
[1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
23
|
-
[2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
24
|
-
[3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
25
|
-
[4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
26
|
-
[5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
27
|
-
[6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
28
|
-
[7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
29
|
-
[8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
30
|
-
[9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
31
|
-
[10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
32
|
-
[11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
33
|
-
[12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
34
|
-
[13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
35
|
-
[14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
36
|
-
[15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
37
|
-
[16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
38
|
-
[17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
39
|
-
[18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
40
|
-
[19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
41
|
-
[21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
42
|
-
[20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
43
|
-
[22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
21
|
+
[0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
22
|
+
[1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
23
|
+
[2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
24
|
+
[3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
25
|
+
[4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
26
|
+
[5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
27
|
+
[6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
28
|
+
[7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
29
|
+
[8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
30
|
+
[9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
31
|
+
[10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
32
|
+
[11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
33
|
+
[12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
34
|
+
[13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
35
|
+
[14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
36
|
+
[15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
37
|
+
[16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
38
|
+
[17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
39
|
+
[18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
40
|
+
[19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
41
|
+
[21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
42
|
+
[20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
43
|
+
[22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
44
44
|
// Vue-specific parse errors
|
|
45
|
-
[23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
46
|
-
[24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
47
|
-
[25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
48
|
-
[27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
45
|
+
[23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
46
|
+
[24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
47
|
+
[25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
48
|
+
[27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
49
49
|
'Note that dynamic directive argument cannot contain spaces.',
|
|
50
|
-
[26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
50
|
+
[26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
51
51
|
// transform errors
|
|
52
|
-
[28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
53
|
-
[29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
54
|
-
[30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
55
|
-
[31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
56
|
-
[32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
57
|
-
[33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
58
|
-
[34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
59
|
-
[35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
60
|
-
[36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
61
|
-
[37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
52
|
+
[28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
53
|
+
[29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
54
|
+
[30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
55
|
+
[31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
56
|
+
[32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
57
|
+
[33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
58
|
+
[34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
59
|
+
[35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
60
|
+
[36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
61
|
+
[37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
62
62
|
`When there are multiple named slots, all slots should use <template> ` +
|
|
63
63
|
`syntax to avoid scope ambiguity.`,
|
|
64
|
-
[38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
65
|
-
[39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
64
|
+
[38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
65
|
+
[39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
66
66
|
`default slot. These children will be ignored.`,
|
|
67
|
-
[40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
68
|
-
[41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
69
|
-
[42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
70
|
-
[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.`,
|
|
71
|
-
[44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
72
|
-
[45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
67
|
+
[40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
68
|
+
[41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
69
|
+
[42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
70
|
+
[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.`,
|
|
71
|
+
[44 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
72
|
+
[45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
73
73
|
// generic errors
|
|
74
|
-
[46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
75
|
-
[47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
76
|
-
[48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
77
|
-
[49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
74
|
+
[46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
75
|
+
[47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
76
|
+
[48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
77
|
+
[49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
78
78
|
// just to fulfill types
|
|
79
|
-
[50 /* __EXTEND_POINT__ */]: ``
|
|
79
|
+
[50 /* ErrorCodes.__EXTEND_POINT__ */]: ``
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const FRAGMENT = Symbol((process.env.NODE_ENV !== 'production') ? `Fragment` : ``);
|
|
@@ -179,7 +179,7 @@ const locStub = {
|
|
|
179
179
|
};
|
|
180
180
|
function createRoot(children, loc = locStub) {
|
|
181
181
|
return {
|
|
182
|
-
type: 0 /* ROOT */,
|
|
182
|
+
type: 0 /* NodeTypes.ROOT */,
|
|
183
183
|
children,
|
|
184
184
|
helpers: [],
|
|
185
185
|
components: [],
|
|
@@ -206,7 +206,7 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
return {
|
|
209
|
-
type: 13 /* VNODE_CALL */,
|
|
209
|
+
type: 13 /* NodeTypes.VNODE_CALL */,
|
|
210
210
|
tag,
|
|
211
211
|
props,
|
|
212
212
|
children,
|
|
@@ -221,38 +221,38 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
221
221
|
}
|
|
222
222
|
function createArrayExpression(elements, loc = locStub) {
|
|
223
223
|
return {
|
|
224
|
-
type: 17 /* JS_ARRAY_EXPRESSION */,
|
|
224
|
+
type: 17 /* NodeTypes.JS_ARRAY_EXPRESSION */,
|
|
225
225
|
loc,
|
|
226
226
|
elements
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
229
|
function createObjectExpression(properties, loc = locStub) {
|
|
230
230
|
return {
|
|
231
|
-
type: 15 /* JS_OBJECT_EXPRESSION */,
|
|
231
|
+
type: 15 /* NodeTypes.JS_OBJECT_EXPRESSION */,
|
|
232
232
|
loc,
|
|
233
233
|
properties
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
function createObjectProperty(key, value) {
|
|
237
237
|
return {
|
|
238
|
-
type: 16 /* JS_PROPERTY */,
|
|
238
|
+
type: 16 /* NodeTypes.JS_PROPERTY */,
|
|
239
239
|
loc: locStub,
|
|
240
240
|
key: isString(key) ? createSimpleExpression(key, true) : key,
|
|
241
241
|
value
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
-
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
|
|
244
|
+
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
245
245
|
return {
|
|
246
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
246
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
247
247
|
loc,
|
|
248
248
|
content,
|
|
249
249
|
isStatic,
|
|
250
|
-
constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
|
|
250
|
+
constType: isStatic ? 3 /* ConstantTypes.CAN_STRINGIFY */ : constType
|
|
251
251
|
};
|
|
252
252
|
}
|
|
253
253
|
function createInterpolation(content, loc) {
|
|
254
254
|
return {
|
|
255
|
-
type: 5 /* INTERPOLATION */,
|
|
255
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
256
256
|
loc,
|
|
257
257
|
content: isString(content)
|
|
258
258
|
? createSimpleExpression(content, false, loc)
|
|
@@ -261,14 +261,14 @@ function createInterpolation(content, loc) {
|
|
|
261
261
|
}
|
|
262
262
|
function createCompoundExpression(children, loc = locStub) {
|
|
263
263
|
return {
|
|
264
|
-
type: 8 /* COMPOUND_EXPRESSION */,
|
|
264
|
+
type: 8 /* NodeTypes.COMPOUND_EXPRESSION */,
|
|
265
265
|
loc,
|
|
266
266
|
children
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
function createCallExpression(callee, args = [], loc = locStub) {
|
|
270
270
|
return {
|
|
271
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
271
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
272
272
|
loc,
|
|
273
273
|
callee,
|
|
274
274
|
arguments: args
|
|
@@ -276,7 +276,7 @@ function createCallExpression(callee, args = [], loc = locStub) {
|
|
|
276
276
|
}
|
|
277
277
|
function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
|
|
278
278
|
return {
|
|
279
|
-
type: 18 /* JS_FUNCTION_EXPRESSION */,
|
|
279
|
+
type: 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */,
|
|
280
280
|
params,
|
|
281
281
|
returns,
|
|
282
282
|
newline,
|
|
@@ -286,7 +286,7 @@ function createFunctionExpression(params, returns = undefined, newline = false,
|
|
|
286
286
|
}
|
|
287
287
|
function createConditionalExpression(test, consequent, alternate, newline = true) {
|
|
288
288
|
return {
|
|
289
|
-
type: 19 /* JS_CONDITIONAL_EXPRESSION */,
|
|
289
|
+
type: 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */,
|
|
290
290
|
test,
|
|
291
291
|
consequent,
|
|
292
292
|
alternate,
|
|
@@ -296,7 +296,7 @@ function createConditionalExpression(test, consequent, alternate, newline = true
|
|
|
296
296
|
}
|
|
297
297
|
function createCacheExpression(index, value, isVNode = false) {
|
|
298
298
|
return {
|
|
299
|
-
type: 20 /* JS_CACHE_EXPRESSION */,
|
|
299
|
+
type: 20 /* NodeTypes.JS_CACHE_EXPRESSION */,
|
|
300
300
|
index,
|
|
301
301
|
value,
|
|
302
302
|
isVNode,
|
|
@@ -305,21 +305,21 @@ function createCacheExpression(index, value, isVNode = false) {
|
|
|
305
305
|
}
|
|
306
306
|
function createBlockStatement(body) {
|
|
307
307
|
return {
|
|
308
|
-
type: 21 /* JS_BLOCK_STATEMENT */,
|
|
308
|
+
type: 21 /* NodeTypes.JS_BLOCK_STATEMENT */,
|
|
309
309
|
body,
|
|
310
310
|
loc: locStub
|
|
311
311
|
};
|
|
312
312
|
}
|
|
313
313
|
function createTemplateLiteral(elements) {
|
|
314
314
|
return {
|
|
315
|
-
type: 22 /* JS_TEMPLATE_LITERAL */,
|
|
315
|
+
type: 22 /* NodeTypes.JS_TEMPLATE_LITERAL */,
|
|
316
316
|
elements,
|
|
317
317
|
loc: locStub
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
320
|
function createIfStatement(test, consequent, alternate) {
|
|
321
321
|
return {
|
|
322
|
-
type: 23 /* JS_IF_STATEMENT */,
|
|
322
|
+
type: 23 /* NodeTypes.JS_IF_STATEMENT */,
|
|
323
323
|
test,
|
|
324
324
|
consequent,
|
|
325
325
|
alternate,
|
|
@@ -328,7 +328,7 @@ function createIfStatement(test, consequent, alternate) {
|
|
|
328
328
|
}
|
|
329
329
|
function createAssignmentExpression(left, right) {
|
|
330
330
|
return {
|
|
331
|
-
type: 24 /* JS_ASSIGNMENT_EXPRESSION */,
|
|
331
|
+
type: 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */,
|
|
332
332
|
left,
|
|
333
333
|
right,
|
|
334
334
|
loc: locStub
|
|
@@ -336,20 +336,20 @@ function createAssignmentExpression(left, right) {
|
|
|
336
336
|
}
|
|
337
337
|
function createSequenceExpression(expressions) {
|
|
338
338
|
return {
|
|
339
|
-
type: 25 /* JS_SEQUENCE_EXPRESSION */,
|
|
339
|
+
type: 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */,
|
|
340
340
|
expressions,
|
|
341
341
|
loc: locStub
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
344
|
function createReturnStatement(returns) {
|
|
345
345
|
return {
|
|
346
|
-
type: 26 /* JS_RETURN_STATEMENT */,
|
|
346
|
+
type: 26 /* NodeTypes.JS_RETURN_STATEMENT */,
|
|
347
347
|
returns,
|
|
348
348
|
loc: locStub
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
|
|
352
|
+
const isStaticExp = (p) => p.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && p.isStatic;
|
|
353
353
|
const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
|
|
354
354
|
function isCoreComponent(tag) {
|
|
355
355
|
if (isBuiltInType(tag, 'Teleport')) {
|
|
@@ -379,7 +379,7 @@ const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
|
|
379
379
|
const isMemberExpressionBrowser = (path) => {
|
|
380
380
|
// remove whitespaces around . or [ first
|
|
381
381
|
path = path.trim().replace(whitespaceRE, s => s.trim());
|
|
382
|
-
let state = 0 /* inMemberExp */;
|
|
382
|
+
let state = 0 /* MemberExpLexState.inMemberExp */;
|
|
383
383
|
let stateStack = [];
|
|
384
384
|
let currentOpenBracketCount = 0;
|
|
385
385
|
let currentOpenParensCount = 0;
|
|
@@ -387,25 +387,25 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
387
387
|
for (let i = 0; i < path.length; i++) {
|
|
388
388
|
const char = path.charAt(i);
|
|
389
389
|
switch (state) {
|
|
390
|
-
case 0 /* inMemberExp */:
|
|
390
|
+
case 0 /* MemberExpLexState.inMemberExp */:
|
|
391
391
|
if (char === '[') {
|
|
392
392
|
stateStack.push(state);
|
|
393
|
-
state = 1 /* inBrackets */;
|
|
393
|
+
state = 1 /* MemberExpLexState.inBrackets */;
|
|
394
394
|
currentOpenBracketCount++;
|
|
395
395
|
}
|
|
396
396
|
else if (char === '(') {
|
|
397
397
|
stateStack.push(state);
|
|
398
|
-
state = 2 /* inParens */;
|
|
398
|
+
state = 2 /* MemberExpLexState.inParens */;
|
|
399
399
|
currentOpenParensCount++;
|
|
400
400
|
}
|
|
401
401
|
else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
|
|
402
402
|
return false;
|
|
403
403
|
}
|
|
404
404
|
break;
|
|
405
|
-
case 1 /* inBrackets */:
|
|
405
|
+
case 1 /* MemberExpLexState.inBrackets */:
|
|
406
406
|
if (char === `'` || char === `"` || char === '`') {
|
|
407
407
|
stateStack.push(state);
|
|
408
|
-
state = 3 /* inString */;
|
|
408
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
409
409
|
currentStringType = char;
|
|
410
410
|
}
|
|
411
411
|
else if (char === `[`) {
|
|
@@ -417,10 +417,10 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
break;
|
|
420
|
-
case 2 /* inParens */:
|
|
420
|
+
case 2 /* MemberExpLexState.inParens */:
|
|
421
421
|
if (char === `'` || char === `"` || char === '`') {
|
|
422
422
|
stateStack.push(state);
|
|
423
|
-
state = 3 /* inString */;
|
|
423
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
424
424
|
currentStringType = char;
|
|
425
425
|
}
|
|
426
426
|
else if (char === `(`) {
|
|
@@ -436,7 +436,7 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
break;
|
|
439
|
-
case 3 /* inString */:
|
|
439
|
+
case 3 /* MemberExpLexState.inString */:
|
|
440
440
|
if (char === currentStringType) {
|
|
441
441
|
state = stateStack.pop();
|
|
442
442
|
currentStringType = null;
|
|
@@ -493,7 +493,7 @@ function assert(condition, msg) {
|
|
|
493
493
|
function findDir(node, name, allowEmpty = false) {
|
|
494
494
|
for (let i = 0; i < node.props.length; i++) {
|
|
495
495
|
const p = node.props[i];
|
|
496
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
496
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
497
497
|
(allowEmpty || p.exp) &&
|
|
498
498
|
(isString(name) ? p.name === name : name.test(p.name))) {
|
|
499
499
|
return p;
|
|
@@ -503,7 +503,7 @@ function findDir(node, name, allowEmpty = false) {
|
|
|
503
503
|
function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
504
504
|
for (let i = 0; i < node.props.length; i++) {
|
|
505
505
|
const p = node.props[i];
|
|
506
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
506
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
507
507
|
if (dynamicOnly)
|
|
508
508
|
continue;
|
|
509
509
|
if (p.name === name && (p.value || allowEmpty)) {
|
|
@@ -521,24 +521,24 @@ function isStaticArgOf(arg, name) {
|
|
|
521
521
|
return !!(arg && isStaticExp(arg) && arg.content === name);
|
|
522
522
|
}
|
|
523
523
|
function hasDynamicKeyVBind(node) {
|
|
524
|
-
return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
524
|
+
return node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
525
525
|
p.name === 'bind' &&
|
|
526
526
|
(!p.arg || // v-bind="obj"
|
|
527
|
-
p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
527
|
+
p.arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
528
528
|
!p.arg.isStatic) // v-bind:[foo]
|
|
529
529
|
);
|
|
530
530
|
}
|
|
531
531
|
function isText(node) {
|
|
532
|
-
return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
|
|
532
|
+
return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
|
|
533
533
|
}
|
|
534
534
|
function isVSlot(p) {
|
|
535
|
-
return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
|
|
535
|
+
return p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'slot';
|
|
536
536
|
}
|
|
537
537
|
function isTemplateNode(node) {
|
|
538
|
-
return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
|
|
538
|
+
return (node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 3 /* ElementTypes.TEMPLATE */);
|
|
539
539
|
}
|
|
540
540
|
function isSlotOutlet(node) {
|
|
541
|
-
return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
|
|
541
|
+
return node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 2 /* ElementTypes.SLOT */;
|
|
542
542
|
}
|
|
543
543
|
function getVNodeHelper(ssr, isComponent) {
|
|
544
544
|
return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
|
@@ -550,7 +550,7 @@ const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
|
|
550
550
|
function getUnnormalizedProps(props, callPath = []) {
|
|
551
551
|
if (props &&
|
|
552
552
|
!isString(props) &&
|
|
553
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
553
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
554
554
|
const callee = props.callee;
|
|
555
555
|
if (!isString(callee) && propsHelperSet.has(callee)) {
|
|
556
556
|
return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
|
|
@@ -568,12 +568,12 @@ function injectProp(node, prop, context) {
|
|
|
568
568
|
*
|
|
569
569
|
* we need to get the real props before normalization
|
|
570
570
|
*/
|
|
571
|
-
let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
|
|
571
|
+
let props = node.type === 13 /* NodeTypes.VNODE_CALL */ ? node.props : node.arguments[2];
|
|
572
572
|
let callPath = [];
|
|
573
573
|
let parentCall;
|
|
574
574
|
if (props &&
|
|
575
575
|
!isString(props) &&
|
|
576
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
576
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
577
577
|
const ret = getUnnormalizedProps(props);
|
|
578
578
|
props = ret[0];
|
|
579
579
|
callPath = ret[1];
|
|
@@ -582,12 +582,12 @@ function injectProp(node, prop, context) {
|
|
|
582
582
|
if (props == null || isString(props)) {
|
|
583
583
|
propsWithInjection = createObjectExpression([prop]);
|
|
584
584
|
}
|
|
585
|
-
else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
585
|
+
else if (props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
586
586
|
// merged props... add ours
|
|
587
587
|
// only inject key to object literal if it's the first argument so that
|
|
588
588
|
// if doesn't override user provided keys
|
|
589
589
|
const first = props.arguments[0];
|
|
590
|
-
if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
590
|
+
if (!isString(first) && first.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
591
591
|
first.properties.unshift(prop);
|
|
592
592
|
}
|
|
593
593
|
else {
|
|
@@ -604,12 +604,12 @@ function injectProp(node, prop, context) {
|
|
|
604
604
|
}
|
|
605
605
|
!propsWithInjection && (propsWithInjection = props);
|
|
606
606
|
}
|
|
607
|
-
else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
607
|
+
else if (props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
608
608
|
let alreadyExists = false;
|
|
609
609
|
// check existing key to avoid overriding user provided keys
|
|
610
|
-
if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
610
|
+
if (prop.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
611
611
|
const propKeyName = prop.key.content;
|
|
612
|
-
alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
612
|
+
alreadyExists = props.properties.some(p => p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
613
613
|
p.key.content === propKeyName);
|
|
614
614
|
}
|
|
615
615
|
if (!alreadyExists) {
|
|
@@ -630,7 +630,7 @@ function injectProp(node, prop, context) {
|
|
|
630
630
|
parentCall = callPath[callPath.length - 2];
|
|
631
631
|
}
|
|
632
632
|
}
|
|
633
|
-
if (node.type === 13 /* VNODE_CALL */) {
|
|
633
|
+
if (node.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
634
634
|
if (parentCall) {
|
|
635
635
|
parentCall.arguments[0] = propsWithInjection;
|
|
636
636
|
}
|
|
@@ -659,38 +659,38 @@ function hasScopeRef(node, ids) {
|
|
|
659
659
|
return false;
|
|
660
660
|
}
|
|
661
661
|
switch (node.type) {
|
|
662
|
-
case 1 /* ELEMENT */:
|
|
662
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
663
663
|
for (let i = 0; i < node.props.length; i++) {
|
|
664
664
|
const p = node.props[i];
|
|
665
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
665
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
666
666
|
(hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
|
|
667
667
|
return true;
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
671
|
-
case 11 /* FOR */:
|
|
671
|
+
case 11 /* NodeTypes.FOR */:
|
|
672
672
|
if (hasScopeRef(node.source, ids)) {
|
|
673
673
|
return true;
|
|
674
674
|
}
|
|
675
675
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
676
|
-
case 9 /* IF */:
|
|
676
|
+
case 9 /* NodeTypes.IF */:
|
|
677
677
|
return node.branches.some(b => hasScopeRef(b, ids));
|
|
678
|
-
case 10 /* IF_BRANCH */:
|
|
678
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
679
679
|
if (hasScopeRef(node.condition, ids)) {
|
|
680
680
|
return true;
|
|
681
681
|
}
|
|
682
682
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
683
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
683
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
684
684
|
return (!node.isStatic &&
|
|
685
685
|
isSimpleIdentifier(node.content) &&
|
|
686
686
|
!!ids[node.content]);
|
|
687
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
687
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
688
688
|
return node.children.some(c => isObject(c) && hasScopeRef(c, ids));
|
|
689
|
-
case 5 /* INTERPOLATION */:
|
|
690
|
-
case 12 /* TEXT_CALL */:
|
|
689
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
690
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
691
691
|
return hasScopeRef(node.content, ids);
|
|
692
|
-
case 2 /* TEXT */:
|
|
693
|
-
case 3 /* COMMENT */:
|
|
692
|
+
case 2 /* NodeTypes.TEXT */:
|
|
693
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
694
694
|
return false;
|
|
695
695
|
default:
|
|
696
696
|
if ((process.env.NODE_ENV !== 'production')) ;
|
|
@@ -698,7 +698,7 @@ function hasScopeRef(node, ids) {
|
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
700
|
function getMemoedVNodeCall(node) {
|
|
701
|
-
if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
701
|
+
if (node.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
702
702
|
return node.arguments[1].returns;
|
|
703
703
|
}
|
|
704
704
|
else {
|
|
@@ -715,23 +715,23 @@ function makeBlock(node, { helper, removeHelper, inSSR }) {
|
|
|
715
715
|
}
|
|
716
716
|
|
|
717
717
|
const deprecationData = {
|
|
718
|
-
["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
|
|
718
|
+
["COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */]: {
|
|
719
719
|
message: `Platform-native elements with "is" prop will no longer be ` +
|
|
720
720
|
`treated as components in Vue 3 unless the "is" value is explicitly ` +
|
|
721
721
|
`prefixed with "vue:".`,
|
|
722
722
|
link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
|
723
723
|
},
|
|
724
|
-
["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
|
|
724
|
+
["COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */]: {
|
|
725
725
|
message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
|
|
726
726
|
`argument instead. \`v-bind:${key}.sync\` should be changed to ` +
|
|
727
727
|
`\`v-model:${key}\`.`,
|
|
728
728
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
|
729
729
|
},
|
|
730
|
-
["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
|
|
730
|
+
["COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */]: {
|
|
731
731
|
message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
|
|
732
732
|
`Vue 3 will automatically set a binding as DOM property when appropriate.`
|
|
733
733
|
},
|
|
734
|
-
["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
734
|
+
["COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
735
735
|
message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
|
|
736
736
|
`object spread: it will now overwrite an existing non-mergeable attribute ` +
|
|
737
737
|
`that appears before v-bind in the case of conflict. ` +
|
|
@@ -739,11 +739,11 @@ const deprecationData = {
|
|
|
739
739
|
`You can also suppress this warning if the usage is intended.`,
|
|
740
740
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
|
741
741
|
},
|
|
742
|
-
["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
|
|
742
|
+
["COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */]: {
|
|
743
743
|
message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
|
744
744
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
|
745
745
|
},
|
|
746
|
-
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
746
|
+
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
747
747
|
message: `v-if / v-for precedence when used on the same element has changed ` +
|
|
748
748
|
`in Vue 3: v-if now takes higher precedence and will no longer have ` +
|
|
749
749
|
`access to v-for scope variables. It is best to avoid the ambiguity ` +
|
|
@@ -751,15 +751,15 @@ const deprecationData = {
|
|
|
751
751
|
`data source.`,
|
|
752
752
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
|
753
753
|
},
|
|
754
|
-
["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
|
|
754
|
+
["COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */]: {
|
|
755
755
|
message: `<template> with no special directives will render as a native template ` +
|
|
756
756
|
`element instead of its inner content in Vue 3.`
|
|
757
757
|
},
|
|
758
|
-
["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
|
|
758
|
+
["COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */]: {
|
|
759
759
|
message: `"inline-template" has been removed in Vue 3.`,
|
|
760
760
|
link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
|
761
761
|
},
|
|
762
|
-
["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
|
|
762
|
+
["COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */]: {
|
|
763
763
|
message: `filters have been removed in Vue 3. ` +
|
|
764
764
|
`The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
|
|
765
765
|
`Use method calls or computed properties instead.`,
|
|
@@ -819,8 +819,8 @@ const decodeMap = {
|
|
|
819
819
|
};
|
|
820
820
|
const defaultParserOptions = {
|
|
821
821
|
delimiters: [`{{`, `}}`],
|
|
822
|
-
getNamespace: () => 0 /* HTML */,
|
|
823
|
-
getTextMode: () => 0 /* DATA */,
|
|
822
|
+
getNamespace: () => 0 /* Namespaces.HTML */,
|
|
823
|
+
getTextMode: () => 0 /* TextModes.DATA */,
|
|
824
824
|
isVoidTag: NO,
|
|
825
825
|
isPreTag: NO,
|
|
826
826
|
isCustomElement: NO,
|
|
@@ -832,7 +832,7 @@ const defaultParserOptions = {
|
|
|
832
832
|
function baseParse(content, options = {}) {
|
|
833
833
|
const context = createParserContext(content, options);
|
|
834
834
|
const start = getCursor(context);
|
|
835
|
-
return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
|
|
835
|
+
return createRoot(parseChildren(context, 0 /* TextModes.DATA */, []), getSelection(context, start));
|
|
836
836
|
}
|
|
837
837
|
function createParserContext(content, rawOptions) {
|
|
838
838
|
const options = extend({}, defaultParserOptions);
|
|
@@ -858,20 +858,20 @@ function createParserContext(content, rawOptions) {
|
|
|
858
858
|
}
|
|
859
859
|
function parseChildren(context, mode, ancestors) {
|
|
860
860
|
const parent = last(ancestors);
|
|
861
|
-
const ns = parent ? parent.ns : 0 /* HTML */;
|
|
861
|
+
const ns = parent ? parent.ns : 0 /* Namespaces.HTML */;
|
|
862
862
|
const nodes = [];
|
|
863
863
|
while (!isEnd(context, mode, ancestors)) {
|
|
864
864
|
const s = context.source;
|
|
865
865
|
let node = undefined;
|
|
866
|
-
if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
|
|
866
|
+
if (mode === 0 /* TextModes.DATA */ || mode === 1 /* TextModes.RCDATA */) {
|
|
867
867
|
if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
|
|
868
868
|
// '{{'
|
|
869
869
|
node = parseInterpolation(context, mode);
|
|
870
870
|
}
|
|
871
|
-
else if (mode === 0 /* DATA */ && s[0] === '<') {
|
|
871
|
+
else if (mode === 0 /* TextModes.DATA */ && s[0] === '<') {
|
|
872
872
|
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
|
|
873
873
|
if (s.length === 1) {
|
|
874
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
|
|
874
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 1);
|
|
875
875
|
}
|
|
876
876
|
else if (s[1] === '!') {
|
|
877
877
|
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
|
|
@@ -883,58 +883,58 @@ function parseChildren(context, mode, ancestors) {
|
|
|
883
883
|
node = parseBogusComment(context);
|
|
884
884
|
}
|
|
885
885
|
else if (startsWith(s, '<![CDATA[')) {
|
|
886
|
-
if (ns !== 0 /* HTML */) {
|
|
886
|
+
if (ns !== 0 /* Namespaces.HTML */) {
|
|
887
887
|
node = parseCDATA(context, ancestors);
|
|
888
888
|
}
|
|
889
889
|
else {
|
|
890
|
-
emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
|
|
890
|
+
emitError(context, 1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */);
|
|
891
891
|
node = parseBogusComment(context);
|
|
892
892
|
}
|
|
893
893
|
}
|
|
894
894
|
else {
|
|
895
|
-
emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
|
|
895
|
+
emitError(context, 11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */);
|
|
896
896
|
node = parseBogusComment(context);
|
|
897
897
|
}
|
|
898
898
|
}
|
|
899
899
|
else if (s[1] === '/') {
|
|
900
900
|
// https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
|
|
901
901
|
if (s.length === 2) {
|
|
902
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
|
|
902
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 2);
|
|
903
903
|
}
|
|
904
904
|
else if (s[2] === '>') {
|
|
905
|
-
emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
|
|
905
|
+
emitError(context, 14 /* ErrorCodes.MISSING_END_TAG_NAME */, 2);
|
|
906
906
|
advanceBy(context, 3);
|
|
907
907
|
continue;
|
|
908
908
|
}
|
|
909
909
|
else if (/[a-z]/i.test(s[2])) {
|
|
910
|
-
emitError(context, 23 /* X_INVALID_END_TAG */);
|
|
911
|
-
parseTag(context, 1 /* End */, parent);
|
|
910
|
+
emitError(context, 23 /* ErrorCodes.X_INVALID_END_TAG */);
|
|
911
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
912
912
|
continue;
|
|
913
913
|
}
|
|
914
914
|
else {
|
|
915
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
915
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
916
916
|
node = parseBogusComment(context);
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
919
|
else if (/[a-z]/i.test(s[1])) {
|
|
920
920
|
node = parseElement(context, ancestors);
|
|
921
921
|
// 2.x <template> with no directive compat
|
|
922
|
-
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
922
|
+
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
923
923
|
node &&
|
|
924
924
|
node.tag === 'template' &&
|
|
925
|
-
!node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
925
|
+
!node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
926
926
|
isSpecialTemplateDirective(p.name))) {
|
|
927
927
|
(process.env.NODE_ENV !== 'production') &&
|
|
928
|
-
warnDeprecation("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context, node.loc);
|
|
928
|
+
warnDeprecation("COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */, context, node.loc);
|
|
929
929
|
node = node.children;
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
else if (s[1] === '?') {
|
|
933
|
-
emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
933
|
+
emitError(context, 21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
934
934
|
node = parseBogusComment(context);
|
|
935
935
|
}
|
|
936
936
|
else {
|
|
937
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
937
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
940
|
}
|
|
@@ -952,11 +952,11 @@ function parseChildren(context, mode, ancestors) {
|
|
|
952
952
|
}
|
|
953
953
|
// Whitespace handling strategy like v2
|
|
954
954
|
let removedWhitespace = false;
|
|
955
|
-
if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
|
|
955
|
+
if (mode !== 2 /* TextModes.RAWTEXT */ && mode !== 1 /* TextModes.RCDATA */) {
|
|
956
956
|
const shouldCondense = context.options.whitespace !== 'preserve';
|
|
957
957
|
for (let i = 0; i < nodes.length; i++) {
|
|
958
958
|
const node = nodes[i];
|
|
959
|
-
if (!context.inPre && node.type === 2 /* TEXT */) {
|
|
959
|
+
if (!context.inPre && node.type === 2 /* NodeTypes.TEXT */) {
|
|
960
960
|
if (!/[^\t\r\n\f ]/.test(node.content)) {
|
|
961
961
|
const prev = nodes[i - 1];
|
|
962
962
|
const next = nodes[i + 1];
|
|
@@ -967,10 +967,10 @@ function parseChildren(context, mode, ancestors) {
|
|
|
967
967
|
if (!prev ||
|
|
968
968
|
!next ||
|
|
969
969
|
(shouldCondense &&
|
|
970
|
-
(prev.type === 3 /* COMMENT */ ||
|
|
971
|
-
next.type === 3 /* COMMENT */ ||
|
|
972
|
-
(prev.type === 1 /* ELEMENT */ &&
|
|
973
|
-
next.type === 1 /* ELEMENT */ &&
|
|
970
|
+
(prev.type === 3 /* NodeTypes.COMMENT */ ||
|
|
971
|
+
next.type === 3 /* NodeTypes.COMMENT */ ||
|
|
972
|
+
(prev.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
973
|
+
next.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
974
974
|
/[\r\n]/.test(node.content))))) {
|
|
975
975
|
removedWhitespace = true;
|
|
976
976
|
nodes[i] = null;
|
|
@@ -987,7 +987,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
987
987
|
}
|
|
988
988
|
}
|
|
989
989
|
// Remove comment nodes if desired by configuration.
|
|
990
|
-
else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
|
|
990
|
+
else if (node.type === 3 /* NodeTypes.COMMENT */ && !context.options.comments) {
|
|
991
991
|
removedWhitespace = true;
|
|
992
992
|
nodes[i] = null;
|
|
993
993
|
}
|
|
@@ -996,7 +996,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
996
996
|
// remove leading newline per html spec
|
|
997
997
|
// https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
|
|
998
998
|
const first = nodes[0];
|
|
999
|
-
if (first && first.type === 2 /* TEXT */) {
|
|
999
|
+
if (first && first.type === 2 /* NodeTypes.TEXT */) {
|
|
1000
1000
|
first.content = first.content.replace(/^\r?\n/, '');
|
|
1001
1001
|
}
|
|
1002
1002
|
}
|
|
@@ -1004,12 +1004,12 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1004
1004
|
return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
|
1005
1005
|
}
|
|
1006
1006
|
function pushNode(nodes, node) {
|
|
1007
|
-
if (node.type === 2 /* TEXT */) {
|
|
1007
|
+
if (node.type === 2 /* NodeTypes.TEXT */) {
|
|
1008
1008
|
const prev = last(nodes);
|
|
1009
1009
|
// Merge if both this and the previous node are text and those are
|
|
1010
1010
|
// consecutive. This happens for cases like "a < b".
|
|
1011
1011
|
if (prev &&
|
|
1012
|
-
prev.type === 2 /* TEXT */ &&
|
|
1012
|
+
prev.type === 2 /* NodeTypes.TEXT */ &&
|
|
1013
1013
|
prev.loc.end.offset === node.loc.start.offset) {
|
|
1014
1014
|
prev.content += node.content;
|
|
1015
1015
|
prev.loc.end = node.loc.end;
|
|
@@ -1021,9 +1021,9 @@ function pushNode(nodes, node) {
|
|
|
1021
1021
|
}
|
|
1022
1022
|
function parseCDATA(context, ancestors) {
|
|
1023
1023
|
advanceBy(context, 9);
|
|
1024
|
-
const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
|
|
1024
|
+
const nodes = parseChildren(context, 3 /* TextModes.CDATA */, ancestors);
|
|
1025
1025
|
if (context.source.length === 0) {
|
|
1026
|
-
emitError(context, 6 /* EOF_IN_CDATA */);
|
|
1026
|
+
emitError(context, 6 /* ErrorCodes.EOF_IN_CDATA */);
|
|
1027
1027
|
}
|
|
1028
1028
|
else {
|
|
1029
1029
|
advanceBy(context, 3);
|
|
@@ -1038,14 +1038,14 @@ function parseComment(context) {
|
|
|
1038
1038
|
if (!match) {
|
|
1039
1039
|
content = context.source.slice(4);
|
|
1040
1040
|
advanceBy(context, context.source.length);
|
|
1041
|
-
emitError(context, 7 /* EOF_IN_COMMENT */);
|
|
1041
|
+
emitError(context, 7 /* ErrorCodes.EOF_IN_COMMENT */);
|
|
1042
1042
|
}
|
|
1043
1043
|
else {
|
|
1044
1044
|
if (match.index <= 3) {
|
|
1045
|
-
emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1045
|
+
emitError(context, 0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1046
1046
|
}
|
|
1047
1047
|
if (match[1]) {
|
|
1048
|
-
emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
|
|
1048
|
+
emitError(context, 10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */);
|
|
1049
1049
|
}
|
|
1050
1050
|
content = context.source.slice(4, match.index);
|
|
1051
1051
|
// Advancing with reporting nested comments.
|
|
@@ -1054,14 +1054,14 @@ function parseComment(context) {
|
|
|
1054
1054
|
while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
|
|
1055
1055
|
advanceBy(context, nestedIndex - prevIndex + 1);
|
|
1056
1056
|
if (nestedIndex + 4 < s.length) {
|
|
1057
|
-
emitError(context, 16 /* NESTED_COMMENT */);
|
|
1057
|
+
emitError(context, 16 /* ErrorCodes.NESTED_COMMENT */);
|
|
1058
1058
|
}
|
|
1059
1059
|
prevIndex = nestedIndex + 1;
|
|
1060
1060
|
}
|
|
1061
1061
|
advanceBy(context, match.index + match[0].length - prevIndex + 1);
|
|
1062
1062
|
}
|
|
1063
1063
|
return {
|
|
1064
|
-
type: 3 /* COMMENT */,
|
|
1064
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1065
1065
|
content,
|
|
1066
1066
|
loc: getSelection(context, start)
|
|
1067
1067
|
};
|
|
@@ -1080,7 +1080,7 @@ function parseBogusComment(context) {
|
|
|
1080
1080
|
advanceBy(context, closeIndex + 1);
|
|
1081
1081
|
}
|
|
1082
1082
|
return {
|
|
1083
|
-
type: 3 /* COMMENT */,
|
|
1083
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1084
1084
|
content,
|
|
1085
1085
|
loc: getSelection(context, start)
|
|
1086
1086
|
};
|
|
@@ -1090,7 +1090,7 @@ function parseElement(context, ancestors) {
|
|
|
1090
1090
|
const wasInPre = context.inPre;
|
|
1091
1091
|
const wasInVPre = context.inVPre;
|
|
1092
1092
|
const parent = last(ancestors);
|
|
1093
|
-
const element = parseTag(context, 0 /* Start */, parent);
|
|
1093
|
+
const element = parseTag(context, 0 /* TagType.Start */, parent);
|
|
1094
1094
|
const isPreBoundary = context.inPre && !wasInPre;
|
|
1095
1095
|
const isVPreBoundary = context.inVPre && !wasInVPre;
|
|
1096
1096
|
if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
|
|
@@ -1110,12 +1110,12 @@ function parseElement(context, ancestors) {
|
|
|
1110
1110
|
ancestors.pop();
|
|
1111
1111
|
// 2.x inline-template compat
|
|
1112
1112
|
{
|
|
1113
|
-
const inlineTemplateProp = element.props.find(p => p.type === 6 /* ATTRIBUTE */ && p.name === 'inline-template');
|
|
1113
|
+
const inlineTemplateProp = element.props.find(p => p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'inline-template');
|
|
1114
1114
|
if (inlineTemplateProp &&
|
|
1115
|
-
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1115
|
+
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1116
1116
|
const loc = getSelection(context, element.loc.end);
|
|
1117
1117
|
inlineTemplateProp.value = {
|
|
1118
|
-
type: 2 /* TEXT */,
|
|
1118
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1119
1119
|
content: loc.source,
|
|
1120
1120
|
loc
|
|
1121
1121
|
};
|
|
@@ -1124,14 +1124,14 @@ function parseElement(context, ancestors) {
|
|
|
1124
1124
|
element.children = children;
|
|
1125
1125
|
// End tag.
|
|
1126
1126
|
if (startsWithEndTagOpen(context.source, element.tag)) {
|
|
1127
|
-
parseTag(context, 1 /* End */, parent);
|
|
1127
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
1128
1128
|
}
|
|
1129
1129
|
else {
|
|
1130
|
-
emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1130
|
+
emitError(context, 24 /* ErrorCodes.X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1131
1131
|
if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
|
|
1132
1132
|
const first = children[0];
|
|
1133
1133
|
if (first && startsWith(first.loc.source, '<!--')) {
|
|
1134
|
-
emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1134
|
+
emitError(context, 8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1135
1135
|
}
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
@@ -1163,9 +1163,9 @@ function parseTag(context, type, parent) {
|
|
|
1163
1163
|
// Attributes.
|
|
1164
1164
|
let props = parseAttributes(context, type);
|
|
1165
1165
|
// check v-pre
|
|
1166
|
-
if (type === 0 /* Start */ &&
|
|
1166
|
+
if (type === 0 /* TagType.Start */ &&
|
|
1167
1167
|
!context.inVPre &&
|
|
1168
|
-
props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
|
|
1168
|
+
props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'pre')) {
|
|
1169
1169
|
context.inVPre = true;
|
|
1170
1170
|
// reset context
|
|
1171
1171
|
extend(context, cursor);
|
|
@@ -1176,26 +1176,26 @@ function parseTag(context, type, parent) {
|
|
|
1176
1176
|
// Tag close.
|
|
1177
1177
|
let isSelfClosing = false;
|
|
1178
1178
|
if (context.source.length === 0) {
|
|
1179
|
-
emitError(context, 9 /* EOF_IN_TAG */);
|
|
1179
|
+
emitError(context, 9 /* ErrorCodes.EOF_IN_TAG */);
|
|
1180
1180
|
}
|
|
1181
1181
|
else {
|
|
1182
1182
|
isSelfClosing = startsWith(context.source, '/>');
|
|
1183
|
-
if (type === 1 /* End */ && isSelfClosing) {
|
|
1184
|
-
emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1183
|
+
if (type === 1 /* TagType.End */ && isSelfClosing) {
|
|
1184
|
+
emitError(context, 4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1185
1185
|
}
|
|
1186
1186
|
advanceBy(context, isSelfClosing ? 2 : 1);
|
|
1187
1187
|
}
|
|
1188
|
-
if (type === 1 /* End */) {
|
|
1188
|
+
if (type === 1 /* TagType.End */) {
|
|
1189
1189
|
return;
|
|
1190
1190
|
}
|
|
1191
1191
|
// 2.x deprecation checks
|
|
1192
1192
|
if ((process.env.NODE_ENV !== 'production') &&
|
|
1193
|
-
isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context)) {
|
|
1193
|
+
isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */, context)) {
|
|
1194
1194
|
let hasIf = false;
|
|
1195
1195
|
let hasFor = false;
|
|
1196
1196
|
for (let i = 0; i < props.length; i++) {
|
|
1197
1197
|
const p = props[i];
|
|
1198
|
-
if (p.type === 7 /* DIRECTIVE */) {
|
|
1198
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1199
1199
|
if (p.name === 'if') {
|
|
1200
1200
|
hasIf = true;
|
|
1201
1201
|
}
|
|
@@ -1204,27 +1204,27 @@ function parseTag(context, type, parent) {
|
|
|
1204
1204
|
}
|
|
1205
1205
|
}
|
|
1206
1206
|
if (hasIf && hasFor) {
|
|
1207
|
-
warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */, context, getSelection(context, start));
|
|
1207
|
+
warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */, context, getSelection(context, start));
|
|
1208
1208
|
break;
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
1211
1211
|
}
|
|
1212
|
-
let tagType = 0 /* ELEMENT */;
|
|
1212
|
+
let tagType = 0 /* ElementTypes.ELEMENT */;
|
|
1213
1213
|
if (!context.inVPre) {
|
|
1214
1214
|
if (tag === 'slot') {
|
|
1215
|
-
tagType = 2 /* SLOT */;
|
|
1215
|
+
tagType = 2 /* ElementTypes.SLOT */;
|
|
1216
1216
|
}
|
|
1217
1217
|
else if (tag === 'template') {
|
|
1218
|
-
if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1219
|
-
tagType = 3 /* TEMPLATE */;
|
|
1218
|
+
if (props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1219
|
+
tagType = 3 /* ElementTypes.TEMPLATE */;
|
|
1220
1220
|
}
|
|
1221
1221
|
}
|
|
1222
1222
|
else if (isComponent(tag, props, context)) {
|
|
1223
|
-
tagType = 1 /* COMPONENT */;
|
|
1223
|
+
tagType = 1 /* ElementTypes.COMPONENT */;
|
|
1224
1224
|
}
|
|
1225
1225
|
}
|
|
1226
1226
|
return {
|
|
1227
|
-
type: 1 /* ELEMENT */,
|
|
1227
|
+
type: 1 /* NodeTypes.ELEMENT */,
|
|
1228
1228
|
ns,
|
|
1229
1229
|
tag,
|
|
1230
1230
|
tagType,
|
|
@@ -1251,12 +1251,12 @@ function isComponent(tag, props, context) {
|
|
|
1251
1251
|
// casting
|
|
1252
1252
|
for (let i = 0; i < props.length; i++) {
|
|
1253
1253
|
const p = props[i];
|
|
1254
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
1254
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
1255
1255
|
if (p.name === 'is' && p.value) {
|
|
1256
1256
|
if (p.value.content.startsWith('vue:')) {
|
|
1257
1257
|
return true;
|
|
1258
1258
|
}
|
|
1259
|
-
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1259
|
+
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1260
1260
|
return true;
|
|
1261
1261
|
}
|
|
1262
1262
|
}
|
|
@@ -1272,7 +1272,7 @@ function isComponent(tag, props, context) {
|
|
|
1272
1272
|
p.name === 'bind' &&
|
|
1273
1273
|
isStaticArgOf(p.arg, 'is') &&
|
|
1274
1274
|
true &&
|
|
1275
|
-
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1275
|
+
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1276
1276
|
return true;
|
|
1277
1277
|
}
|
|
1278
1278
|
}
|
|
@@ -1285,27 +1285,27 @@ function parseAttributes(context, type) {
|
|
|
1285
1285
|
!startsWith(context.source, '>') &&
|
|
1286
1286
|
!startsWith(context.source, '/>')) {
|
|
1287
1287
|
if (startsWith(context.source, '/')) {
|
|
1288
|
-
emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1288
|
+
emitError(context, 22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1289
1289
|
advanceBy(context, 1);
|
|
1290
1290
|
advanceSpaces(context);
|
|
1291
1291
|
continue;
|
|
1292
1292
|
}
|
|
1293
|
-
if (type === 1 /* End */) {
|
|
1294
|
-
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1293
|
+
if (type === 1 /* TagType.End */) {
|
|
1294
|
+
emitError(context, 3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */);
|
|
1295
1295
|
}
|
|
1296
1296
|
const attr = parseAttribute(context, attributeNames);
|
|
1297
1297
|
// Trim whitespace between class
|
|
1298
1298
|
// https://github.com/vuejs/core/issues/4251
|
|
1299
|
-
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1299
|
+
if (attr.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
1300
1300
|
attr.value &&
|
|
1301
1301
|
attr.name === 'class') {
|
|
1302
1302
|
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1303
1303
|
}
|
|
1304
|
-
if (type === 0 /* Start */) {
|
|
1304
|
+
if (type === 0 /* TagType.Start */) {
|
|
1305
1305
|
props.push(attr);
|
|
1306
1306
|
}
|
|
1307
1307
|
if (/^[^\t\r\n\f />]/.test(context.source)) {
|
|
1308
|
-
emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1308
|
+
emitError(context, 15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1309
1309
|
}
|
|
1310
1310
|
advanceSpaces(context);
|
|
1311
1311
|
}
|
|
@@ -1317,17 +1317,17 @@ function parseAttribute(context, nameSet) {
|
|
|
1317
1317
|
const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
|
|
1318
1318
|
const name = match[0];
|
|
1319
1319
|
if (nameSet.has(name)) {
|
|
1320
|
-
emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
|
|
1320
|
+
emitError(context, 2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */);
|
|
1321
1321
|
}
|
|
1322
1322
|
nameSet.add(name);
|
|
1323
1323
|
if (name[0] === '=') {
|
|
1324
|
-
emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1324
|
+
emitError(context, 19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1325
1325
|
}
|
|
1326
1326
|
{
|
|
1327
1327
|
const pattern = /["'<]/g;
|
|
1328
1328
|
let m;
|
|
1329
1329
|
while ((m = pattern.exec(name))) {
|
|
1330
|
-
emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1330
|
+
emitError(context, 17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1331
1331
|
}
|
|
1332
1332
|
}
|
|
1333
1333
|
advanceBy(context, name.length);
|
|
@@ -1339,7 +1339,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1339
1339
|
advanceSpaces(context);
|
|
1340
1340
|
value = parseAttributeValue(context);
|
|
1341
1341
|
if (!value) {
|
|
1342
|
-
emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
|
|
1342
|
+
emitError(context, 13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */);
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
1345
|
const loc = getSelection(context, start);
|
|
@@ -1362,7 +1362,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1362
1362
|
if (content.startsWith('[')) {
|
|
1363
1363
|
isStatic = false;
|
|
1364
1364
|
if (!content.endsWith(']')) {
|
|
1365
|
-
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1365
|
+
emitError(context, 27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1366
1366
|
content = content.slice(1);
|
|
1367
1367
|
}
|
|
1368
1368
|
else {
|
|
@@ -1376,12 +1376,12 @@ function parseAttribute(context, nameSet) {
|
|
|
1376
1376
|
content += match[3] || '';
|
|
1377
1377
|
}
|
|
1378
1378
|
arg = {
|
|
1379
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1379
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1380
1380
|
content,
|
|
1381
1381
|
isStatic,
|
|
1382
1382
|
constType: isStatic
|
|
1383
|
-
? 3 /* CAN_STRINGIFY */
|
|
1384
|
-
: 0 /* NOT_CONSTANT */,
|
|
1383
|
+
? 3 /* ConstantTypes.CAN_STRINGIFY */
|
|
1384
|
+
: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1385
1385
|
loc
|
|
1386
1386
|
};
|
|
1387
1387
|
}
|
|
@@ -1398,24 +1398,24 @@ function parseAttribute(context, nameSet) {
|
|
|
1398
1398
|
// 2.x compat v-bind:foo.sync -> v-model:foo
|
|
1399
1399
|
if (dirName === 'bind' && arg) {
|
|
1400
1400
|
if (modifiers.includes('sync') &&
|
|
1401
|
-
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1401
|
+
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1402
1402
|
dirName = 'model';
|
|
1403
1403
|
modifiers.splice(modifiers.indexOf('sync'), 1);
|
|
1404
1404
|
}
|
|
1405
1405
|
if ((process.env.NODE_ENV !== 'production') && modifiers.includes('prop')) {
|
|
1406
|
-
checkCompatEnabled("COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */, context, loc);
|
|
1406
|
+
checkCompatEnabled("COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */, context, loc);
|
|
1407
1407
|
}
|
|
1408
1408
|
}
|
|
1409
1409
|
return {
|
|
1410
|
-
type: 7 /* DIRECTIVE */,
|
|
1410
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
1411
1411
|
name: dirName,
|
|
1412
1412
|
exp: value && {
|
|
1413
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1413
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1414
1414
|
content: value.content,
|
|
1415
1415
|
isStatic: false,
|
|
1416
1416
|
// Treat as non-constant by default. This can be potentially set to
|
|
1417
1417
|
// other values by `transformExpression` to make it eligible for hoisting.
|
|
1418
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1418
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1419
1419
|
loc: value.loc
|
|
1420
1420
|
},
|
|
1421
1421
|
arg,
|
|
@@ -1425,13 +1425,13 @@ function parseAttribute(context, nameSet) {
|
|
|
1425
1425
|
}
|
|
1426
1426
|
// missing directive name or illegal directive name
|
|
1427
1427
|
if (!context.inVPre && startsWith(name, 'v-')) {
|
|
1428
|
-
emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
|
|
1428
|
+
emitError(context, 26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */);
|
|
1429
1429
|
}
|
|
1430
1430
|
return {
|
|
1431
|
-
type: 6 /* ATTRIBUTE */,
|
|
1431
|
+
type: 6 /* NodeTypes.ATTRIBUTE */,
|
|
1432
1432
|
name,
|
|
1433
1433
|
value: value && {
|
|
1434
|
-
type: 2 /* TEXT */,
|
|
1434
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1435
1435
|
content: value.content,
|
|
1436
1436
|
loc: value.loc
|
|
1437
1437
|
},
|
|
@@ -1448,10 +1448,10 @@ function parseAttributeValue(context) {
|
|
|
1448
1448
|
advanceBy(context, 1);
|
|
1449
1449
|
const endIndex = context.source.indexOf(quote);
|
|
1450
1450
|
if (endIndex === -1) {
|
|
1451
|
-
content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
|
|
1451
|
+
content = parseTextData(context, context.source.length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1452
1452
|
}
|
|
1453
1453
|
else {
|
|
1454
|
-
content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
|
|
1454
|
+
content = parseTextData(context, endIndex, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1455
1455
|
advanceBy(context, 1);
|
|
1456
1456
|
}
|
|
1457
1457
|
}
|
|
@@ -1464,9 +1464,9 @@ function parseAttributeValue(context) {
|
|
|
1464
1464
|
const unexpectedChars = /["'<=`]/g;
|
|
1465
1465
|
let m;
|
|
1466
1466
|
while ((m = unexpectedChars.exec(match[0]))) {
|
|
1467
|
-
emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1467
|
+
emitError(context, 18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1468
1468
|
}
|
|
1469
|
-
content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
|
|
1469
|
+
content = parseTextData(context, match[0].length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1470
1470
|
}
|
|
1471
1471
|
return { content, isQuoted, loc: getSelection(context, start) };
|
|
1472
1472
|
}
|
|
@@ -1474,7 +1474,7 @@ function parseInterpolation(context, mode) {
|
|
|
1474
1474
|
const [open, close] = context.options.delimiters;
|
|
1475
1475
|
const closeIndex = context.source.indexOf(close, open.length);
|
|
1476
1476
|
if (closeIndex === -1) {
|
|
1477
|
-
emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
|
|
1477
|
+
emitError(context, 25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */);
|
|
1478
1478
|
return undefined;
|
|
1479
1479
|
}
|
|
1480
1480
|
const start = getCursor(context);
|
|
@@ -1493,12 +1493,12 @@ function parseInterpolation(context, mode) {
|
|
|
1493
1493
|
advancePositionWithMutation(innerEnd, rawContent, endOffset);
|
|
1494
1494
|
advanceBy(context, close.length);
|
|
1495
1495
|
return {
|
|
1496
|
-
type: 5 /* INTERPOLATION */,
|
|
1496
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
1497
1497
|
content: {
|
|
1498
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1498
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1499
1499
|
isStatic: false,
|
|
1500
1500
|
// Set `isConstant` to false by default and will decide in transformExpression
|
|
1501
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1501
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1502
1502
|
content,
|
|
1503
1503
|
loc: getSelection(context, innerStart, innerEnd)
|
|
1504
1504
|
},
|
|
@@ -1506,7 +1506,7 @@ function parseInterpolation(context, mode) {
|
|
|
1506
1506
|
};
|
|
1507
1507
|
}
|
|
1508
1508
|
function parseText(context, mode) {
|
|
1509
|
-
const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1509
|
+
const endTokens = mode === 3 /* TextModes.CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1510
1510
|
let endIndex = context.source.length;
|
|
1511
1511
|
for (let i = 0; i < endTokens.length; i++) {
|
|
1512
1512
|
const index = context.source.indexOf(endTokens[i], 1);
|
|
@@ -1517,7 +1517,7 @@ function parseText(context, mode) {
|
|
|
1517
1517
|
const start = getCursor(context);
|
|
1518
1518
|
const content = parseTextData(context, endIndex, mode);
|
|
1519
1519
|
return {
|
|
1520
|
-
type: 2 /* TEXT */,
|
|
1520
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1521
1521
|
content,
|
|
1522
1522
|
loc: getSelection(context, start)
|
|
1523
1523
|
};
|
|
@@ -1529,14 +1529,14 @@ function parseText(context, mode) {
|
|
|
1529
1529
|
function parseTextData(context, length, mode) {
|
|
1530
1530
|
const rawText = context.source.slice(0, length);
|
|
1531
1531
|
advanceBy(context, length);
|
|
1532
|
-
if (mode === 2 /* RAWTEXT */ ||
|
|
1533
|
-
mode === 3 /* CDATA */ ||
|
|
1532
|
+
if (mode === 2 /* TextModes.RAWTEXT */ ||
|
|
1533
|
+
mode === 3 /* TextModes.CDATA */ ||
|
|
1534
1534
|
!rawText.includes('&')) {
|
|
1535
1535
|
return rawText;
|
|
1536
1536
|
}
|
|
1537
1537
|
else {
|
|
1538
1538
|
// DATA or RCDATA containing "&"". Entity decoding required.
|
|
1539
|
-
return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
|
|
1539
|
+
return context.options.decodeEntities(rawText, mode === 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1540
1540
|
}
|
|
1541
1541
|
}
|
|
1542
1542
|
function getCursor(context) {
|
|
@@ -1585,7 +1585,7 @@ function emitError(context, code, offset, loc = getCursor(context)) {
|
|
|
1585
1585
|
function isEnd(context, mode, ancestors) {
|
|
1586
1586
|
const s = context.source;
|
|
1587
1587
|
switch (mode) {
|
|
1588
|
-
case 0 /* DATA */:
|
|
1588
|
+
case 0 /* TextModes.DATA */:
|
|
1589
1589
|
if (startsWith(s, '</')) {
|
|
1590
1590
|
// TODO: probably bad performance
|
|
1591
1591
|
for (let i = ancestors.length - 1; i >= 0; --i) {
|
|
@@ -1595,15 +1595,15 @@ function isEnd(context, mode, ancestors) {
|
|
|
1595
1595
|
}
|
|
1596
1596
|
}
|
|
1597
1597
|
break;
|
|
1598
|
-
case 1 /* RCDATA */:
|
|
1599
|
-
case 2 /* RAWTEXT */: {
|
|
1598
|
+
case 1 /* TextModes.RCDATA */:
|
|
1599
|
+
case 2 /* TextModes.RAWTEXT */: {
|
|
1600
1600
|
const parent = last(ancestors);
|
|
1601
1601
|
if (parent && startsWithEndTagOpen(s, parent.tag)) {
|
|
1602
1602
|
return true;
|
|
1603
1603
|
}
|
|
1604
1604
|
break;
|
|
1605
1605
|
}
|
|
1606
|
-
case 3 /* CDATA */:
|
|
1606
|
+
case 3 /* TextModes.CDATA */:
|
|
1607
1607
|
if (startsWith(s, ']]>')) {
|
|
1608
1608
|
return true;
|
|
1609
1609
|
}
|
|
@@ -1626,7 +1626,7 @@ function hoistStatic(root, context) {
|
|
|
1626
1626
|
function isSingleElementRoot(root, child) {
|
|
1627
1627
|
const { children } = root;
|
|
1628
1628
|
return (children.length === 1 &&
|
|
1629
|
-
child.type === 1 /* ELEMENT */ &&
|
|
1629
|
+
child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1630
1630
|
!isSlotOutlet(child));
|
|
1631
1631
|
}
|
|
1632
1632
|
function walk(node, context, doNotHoistNode = false) {
|
|
@@ -1636,15 +1636,15 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1636
1636
|
for (let i = 0; i < children.length; i++) {
|
|
1637
1637
|
const child = children[i];
|
|
1638
1638
|
// only plain elements & text calls are eligible for hoisting.
|
|
1639
|
-
if (child.type === 1 /* ELEMENT */ &&
|
|
1640
|
-
child.tagType === 0 /* ELEMENT */) {
|
|
1639
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1640
|
+
child.tagType === 0 /* ElementTypes.ELEMENT */) {
|
|
1641
1641
|
const constantType = doNotHoistNode
|
|
1642
|
-
? 0 /* NOT_CONSTANT */
|
|
1642
|
+
? 0 /* ConstantTypes.NOT_CONSTANT */
|
|
1643
1643
|
: getConstantType(child, context);
|
|
1644
|
-
if (constantType > 0 /* NOT_CONSTANT */) {
|
|
1645
|
-
if (constantType >= 2 /* CAN_HOIST */) {
|
|
1644
|
+
if (constantType > 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1645
|
+
if (constantType >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1646
1646
|
child.codegenNode.patchFlag =
|
|
1647
|
-
-1 /* HOISTED */ + ((process.env.NODE_ENV !== 'production') ? ` /* HOISTED */` : ``);
|
|
1647
|
+
-1 /* PatchFlags.HOISTED */ + ((process.env.NODE_ENV !== 'production') ? ` /* HOISTED */` : ``);
|
|
1648
1648
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1649
1649
|
hoistedCount++;
|
|
1650
1650
|
continue;
|
|
@@ -1654,13 +1654,13 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1654
1654
|
// node may contain dynamic children, but its props may be eligible for
|
|
1655
1655
|
// hoisting.
|
|
1656
1656
|
const codegenNode = child.codegenNode;
|
|
1657
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1657
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1658
1658
|
const flag = getPatchFlag(codegenNode);
|
|
1659
1659
|
if ((!flag ||
|
|
1660
|
-
flag === 512 /* NEED_PATCH */ ||
|
|
1661
|
-
flag === 1 /* TEXT */) &&
|
|
1660
|
+
flag === 512 /* PatchFlags.NEED_PATCH */ ||
|
|
1661
|
+
flag === 1 /* PatchFlags.TEXT */) &&
|
|
1662
1662
|
getGeneratedPropsConstantType(child, context) >=
|
|
1663
|
-
2 /* CAN_HOIST */) {
|
|
1663
|
+
2 /* ConstantTypes.CAN_HOIST */) {
|
|
1664
1664
|
const props = getNodeProps(child);
|
|
1665
1665
|
if (props) {
|
|
1666
1666
|
codegenNode.props = context.hoist(props);
|
|
@@ -1672,14 +1672,14 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1672
1672
|
}
|
|
1673
1673
|
}
|
|
1674
1674
|
}
|
|
1675
|
-
else if (child.type === 12 /* TEXT_CALL */ &&
|
|
1676
|
-
getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
|
|
1675
|
+
else if (child.type === 12 /* NodeTypes.TEXT_CALL */ &&
|
|
1676
|
+
getConstantType(child.content, context) >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1677
1677
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1678
1678
|
hoistedCount++;
|
|
1679
1679
|
}
|
|
1680
1680
|
// walk further
|
|
1681
|
-
if (child.type === 1 /* ELEMENT */) {
|
|
1682
|
-
const isComponent = child.tagType === 1 /* COMPONENT */;
|
|
1681
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */) {
|
|
1682
|
+
const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
1683
1683
|
if (isComponent) {
|
|
1684
1684
|
context.scopes.vSlot++;
|
|
1685
1685
|
}
|
|
@@ -1688,11 +1688,11 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1688
1688
|
context.scopes.vSlot--;
|
|
1689
1689
|
}
|
|
1690
1690
|
}
|
|
1691
|
-
else if (child.type === 11 /* FOR */) {
|
|
1691
|
+
else if (child.type === 11 /* NodeTypes.FOR */) {
|
|
1692
1692
|
// Do not hoist v-for single child because it has to be a block
|
|
1693
1693
|
walk(child, context, child.children.length === 1);
|
|
1694
1694
|
}
|
|
1695
|
-
else if (child.type === 9 /* IF */) {
|
|
1695
|
+
else if (child.type === 9 /* NodeTypes.IF */) {
|
|
1696
1696
|
for (let i = 0; i < child.branches.length; i++) {
|
|
1697
1697
|
// Do not hoist v-if single child because it has to be a block
|
|
1698
1698
|
walk(child.branches[i], context, child.branches[i].children.length === 1);
|
|
@@ -1705,10 +1705,10 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1705
1705
|
// all children were hoisted - the entire children array is hoistable.
|
|
1706
1706
|
if (hoistedCount &&
|
|
1707
1707
|
hoistedCount === originalCount &&
|
|
1708
|
-
node.type === 1 /* ELEMENT */ &&
|
|
1709
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
1708
|
+
node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1709
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
1710
1710
|
node.codegenNode &&
|
|
1711
|
-
node.codegenNode.type === 13 /* VNODE_CALL */ &&
|
|
1711
|
+
node.codegenNode.type === 13 /* NodeTypes.VNODE_CALL */ &&
|
|
1712
1712
|
isArray(node.codegenNode.children)) {
|
|
1713
1713
|
node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
|
|
1714
1714
|
}
|
|
@@ -1716,35 +1716,35 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1716
1716
|
function getConstantType(node, context) {
|
|
1717
1717
|
const { constantCache } = context;
|
|
1718
1718
|
switch (node.type) {
|
|
1719
|
-
case 1 /* ELEMENT */:
|
|
1720
|
-
if (node.tagType !== 0 /* ELEMENT */) {
|
|
1721
|
-
return 0 /* NOT_CONSTANT */;
|
|
1719
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
1720
|
+
if (node.tagType !== 0 /* ElementTypes.ELEMENT */) {
|
|
1721
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1722
1722
|
}
|
|
1723
1723
|
const cached = constantCache.get(node);
|
|
1724
1724
|
if (cached !== undefined) {
|
|
1725
1725
|
return cached;
|
|
1726
1726
|
}
|
|
1727
1727
|
const codegenNode = node.codegenNode;
|
|
1728
|
-
if (codegenNode.type !== 13 /* VNODE_CALL */) {
|
|
1729
|
-
return 0 /* NOT_CONSTANT */;
|
|
1728
|
+
if (codegenNode.type !== 13 /* NodeTypes.VNODE_CALL */) {
|
|
1729
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1730
1730
|
}
|
|
1731
1731
|
if (codegenNode.isBlock &&
|
|
1732
1732
|
node.tag !== 'svg' &&
|
|
1733
1733
|
node.tag !== 'foreignObject') {
|
|
1734
|
-
return 0 /* NOT_CONSTANT */;
|
|
1734
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1735
1735
|
}
|
|
1736
1736
|
const flag = getPatchFlag(codegenNode);
|
|
1737
1737
|
if (!flag) {
|
|
1738
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1738
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1739
1739
|
// Element itself has no patch flag. However we still need to check:
|
|
1740
1740
|
// 1. Even for a node with no patch flag, it is possible for it to contain
|
|
1741
1741
|
// non-hoistable expressions that refers to scope variables, e.g. compiler
|
|
1742
1742
|
// injected keys or cached event handlers. Therefore we need to always
|
|
1743
1743
|
// check the codegenNode's props to be sure.
|
|
1744
1744
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
1745
|
-
if (generatedPropsType === 0 /* NOT_CONSTANT */) {
|
|
1746
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1747
|
-
return 0 /* NOT_CONSTANT */;
|
|
1745
|
+
if (generatedPropsType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1746
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1747
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1748
1748
|
}
|
|
1749
1749
|
if (generatedPropsType < returnType) {
|
|
1750
1750
|
returnType = generatedPropsType;
|
|
@@ -1752,9 +1752,9 @@ function getConstantType(node, context) {
|
|
|
1752
1752
|
// 2. its children.
|
|
1753
1753
|
for (let i = 0; i < node.children.length; i++) {
|
|
1754
1754
|
const childType = getConstantType(node.children[i], context);
|
|
1755
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1756
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1757
|
-
return 0 /* NOT_CONSTANT */;
|
|
1755
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1756
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1757
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1758
1758
|
}
|
|
1759
1759
|
if (childType < returnType) {
|
|
1760
1760
|
returnType = childType;
|
|
@@ -1764,14 +1764,14 @@ function getConstantType(node, context) {
|
|
|
1764
1764
|
// type, check if any of the props can cause the type to be lowered
|
|
1765
1765
|
// we can skip can_patch because it's guaranteed by the absence of a
|
|
1766
1766
|
// patchFlag.
|
|
1767
|
-
if (returnType > 1 /* CAN_SKIP_PATCH */) {
|
|
1767
|
+
if (returnType > 1 /* ConstantTypes.CAN_SKIP_PATCH */) {
|
|
1768
1768
|
for (let i = 0; i < node.props.length; i++) {
|
|
1769
1769
|
const p = node.props[i];
|
|
1770
|
-
if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1770
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1771
1771
|
const expType = getConstantType(p.exp, context);
|
|
1772
|
-
if (expType === 0 /* NOT_CONSTANT */) {
|
|
1773
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1774
|
-
return 0 /* NOT_CONSTANT */;
|
|
1772
|
+
if (expType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1773
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1774
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1775
1775
|
}
|
|
1776
1776
|
if (expType < returnType) {
|
|
1777
1777
|
returnType = expType;
|
|
@@ -1783,6 +1783,14 @@ function getConstantType(node, context) {
|
|
|
1783
1783
|
// static then they don't need to be blocks since there will be no
|
|
1784
1784
|
// nested updates.
|
|
1785
1785
|
if (codegenNode.isBlock) {
|
|
1786
|
+
// except set custom directives.
|
|
1787
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
1788
|
+
const p = node.props[i];
|
|
1789
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1790
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1791
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1786
1794
|
context.removeHelper(OPEN_BLOCK);
|
|
1787
1795
|
context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
|
|
1788
1796
|
codegenNode.isBlock = false;
|
|
@@ -1792,31 +1800,31 @@ function getConstantType(node, context) {
|
|
|
1792
1800
|
return returnType;
|
|
1793
1801
|
}
|
|
1794
1802
|
else {
|
|
1795
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1796
|
-
return 0 /* NOT_CONSTANT */;
|
|
1797
|
-
}
|
|
1798
|
-
case 2 /* TEXT */:
|
|
1799
|
-
case 3 /* COMMENT */:
|
|
1800
|
-
return 3 /* CAN_STRINGIFY */;
|
|
1801
|
-
case 9 /* IF */:
|
|
1802
|
-
case 11 /* FOR */:
|
|
1803
|
-
case 10 /* IF_BRANCH */:
|
|
1804
|
-
return 0 /* NOT_CONSTANT */;
|
|
1805
|
-
case 5 /* INTERPOLATION */:
|
|
1806
|
-
case 12 /* TEXT_CALL */:
|
|
1803
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1804
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1805
|
+
}
|
|
1806
|
+
case 2 /* NodeTypes.TEXT */:
|
|
1807
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
1808
|
+
return 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1809
|
+
case 9 /* NodeTypes.IF */:
|
|
1810
|
+
case 11 /* NodeTypes.FOR */:
|
|
1811
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
1812
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1813
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
1814
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
1807
1815
|
return getConstantType(node.content, context);
|
|
1808
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
1816
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
1809
1817
|
return node.constType;
|
|
1810
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
1811
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1818
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
1819
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1812
1820
|
for (let i = 0; i < node.children.length; i++) {
|
|
1813
1821
|
const child = node.children[i];
|
|
1814
1822
|
if (isString(child) || isSymbol(child)) {
|
|
1815
1823
|
continue;
|
|
1816
1824
|
}
|
|
1817
1825
|
const childType = getConstantType(child, context);
|
|
1818
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1819
|
-
return 0 /* NOT_CONSTANT */;
|
|
1826
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1827
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1820
1828
|
}
|
|
1821
1829
|
else if (childType < returnType) {
|
|
1822
1830
|
returnType = childType;
|
|
@@ -1825,7 +1833,7 @@ function getConstantType(node, context) {
|
|
|
1825
1833
|
return returnType;
|
|
1826
1834
|
default:
|
|
1827
1835
|
if ((process.env.NODE_ENV !== 'production')) ;
|
|
1828
|
-
return 0 /* NOT_CONSTANT */;
|
|
1836
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1829
1837
|
}
|
|
1830
1838
|
}
|
|
1831
1839
|
const allowHoistedHelperSet = new Set([
|
|
@@ -1835,48 +1843,48 @@ const allowHoistedHelperSet = new Set([
|
|
|
1835
1843
|
GUARD_REACTIVE_PROPS
|
|
1836
1844
|
]);
|
|
1837
1845
|
function getConstantTypeOfHelperCall(value, context) {
|
|
1838
|
-
if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
|
|
1846
|
+
if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
|
|
1839
1847
|
!isString(value.callee) &&
|
|
1840
1848
|
allowHoistedHelperSet.has(value.callee)) {
|
|
1841
1849
|
const arg = value.arguments[0];
|
|
1842
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1850
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1843
1851
|
return getConstantType(arg, context);
|
|
1844
1852
|
}
|
|
1845
|
-
else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1853
|
+
else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1846
1854
|
// in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
|
|
1847
1855
|
return getConstantTypeOfHelperCall(arg, context);
|
|
1848
1856
|
}
|
|
1849
1857
|
}
|
|
1850
|
-
return 0 /* NOT_CONSTANT */;
|
|
1858
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1851
1859
|
}
|
|
1852
1860
|
function getGeneratedPropsConstantType(node, context) {
|
|
1853
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1861
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1854
1862
|
const props = getNodeProps(node);
|
|
1855
|
-
if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
1863
|
+
if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
1856
1864
|
const { properties } = props;
|
|
1857
1865
|
for (let i = 0; i < properties.length; i++) {
|
|
1858
1866
|
const { key, value } = properties[i];
|
|
1859
1867
|
const keyType = getConstantType(key, context);
|
|
1860
|
-
if (keyType === 0 /* NOT_CONSTANT */) {
|
|
1868
|
+
if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1861
1869
|
return keyType;
|
|
1862
1870
|
}
|
|
1863
1871
|
if (keyType < returnType) {
|
|
1864
1872
|
returnType = keyType;
|
|
1865
1873
|
}
|
|
1866
1874
|
let valueType;
|
|
1867
|
-
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1875
|
+
if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1868
1876
|
valueType = getConstantType(value, context);
|
|
1869
1877
|
}
|
|
1870
|
-
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1878
|
+
else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1871
1879
|
// some helper calls can be hoisted,
|
|
1872
1880
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1873
1881
|
// in this case we need to respect the ConstantType of the helper's arguments
|
|
1874
1882
|
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1875
1883
|
}
|
|
1876
1884
|
else {
|
|
1877
|
-
valueType = 0 /* NOT_CONSTANT */;
|
|
1885
|
+
valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1878
1886
|
}
|
|
1879
|
-
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1887
|
+
if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1880
1888
|
return valueType;
|
|
1881
1889
|
}
|
|
1882
1890
|
if (valueType < returnType) {
|
|
@@ -1888,7 +1896,7 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1888
1896
|
}
|
|
1889
1897
|
function getNodeProps(node) {
|
|
1890
1898
|
const codegenNode = node.codegenNode;
|
|
1891
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1899
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1892
1900
|
return codegenNode.props;
|
|
1893
1901
|
}
|
|
1894
1902
|
}
|
|
@@ -2013,7 +2021,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
2013
2021
|
if (isString(exp))
|
|
2014
2022
|
exp = createSimpleExpression(exp);
|
|
2015
2023
|
context.hoists.push(exp);
|
|
2016
|
-
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
|
|
2024
|
+
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* ConstantTypes.CAN_HOIST */);
|
|
2017
2025
|
identifier.hoisted = exp;
|
|
2018
2026
|
return identifier;
|
|
2019
2027
|
},
|
|
@@ -2057,7 +2065,7 @@ function createRootCodegen(root, context) {
|
|
|
2057
2065
|
// single element root is never hoisted so codegenNode will never be
|
|
2058
2066
|
// SimpleExpressionNode
|
|
2059
2067
|
const codegenNode = child.codegenNode;
|
|
2060
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
2068
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
2061
2069
|
makeBlock(codegenNode, context);
|
|
2062
2070
|
}
|
|
2063
2071
|
root.codegenNode = codegenNode;
|
|
@@ -2071,14 +2079,14 @@ function createRootCodegen(root, context) {
|
|
|
2071
2079
|
}
|
|
2072
2080
|
else if (children.length > 1) {
|
|
2073
2081
|
// root has multiple nodes - return a fragment block.
|
|
2074
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
2075
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
2082
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
2083
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
2076
2084
|
// check if the fragment actually contains a single valid child with
|
|
2077
2085
|
// the rest being comments
|
|
2078
2086
|
if ((process.env.NODE_ENV !== 'production') &&
|
|
2079
|
-
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
2080
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
2081
|
-
patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
|
|
2087
|
+
children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
|
|
2088
|
+
patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
|
|
2089
|
+
patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
|
|
2082
2090
|
}
|
|
2083
2091
|
root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
2084
2092
|
}
|
|
@@ -2124,29 +2132,29 @@ function traverseNode(node, context) {
|
|
|
2124
2132
|
}
|
|
2125
2133
|
}
|
|
2126
2134
|
switch (node.type) {
|
|
2127
|
-
case 3 /* COMMENT */:
|
|
2135
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2128
2136
|
if (!context.ssr) {
|
|
2129
2137
|
// inject import for the Comment symbol, which is needed for creating
|
|
2130
2138
|
// comment nodes with `createVNode`
|
|
2131
2139
|
context.helper(CREATE_COMMENT);
|
|
2132
2140
|
}
|
|
2133
2141
|
break;
|
|
2134
|
-
case 5 /* INTERPOLATION */:
|
|
2142
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2135
2143
|
// no need to traverse, but we need to inject toString helper
|
|
2136
2144
|
if (!context.ssr) {
|
|
2137
2145
|
context.helper(TO_DISPLAY_STRING);
|
|
2138
2146
|
}
|
|
2139
2147
|
break;
|
|
2140
2148
|
// for container types, further traverse downwards
|
|
2141
|
-
case 9 /* IF */:
|
|
2149
|
+
case 9 /* NodeTypes.IF */:
|
|
2142
2150
|
for (let i = 0; i < node.branches.length; i++) {
|
|
2143
2151
|
traverseNode(node.branches[i], context);
|
|
2144
2152
|
}
|
|
2145
2153
|
break;
|
|
2146
|
-
case 10 /* IF_BRANCH */:
|
|
2147
|
-
case 11 /* FOR */:
|
|
2148
|
-
case 1 /* ELEMENT */:
|
|
2149
|
-
case 0 /* ROOT */:
|
|
2154
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2155
|
+
case 11 /* NodeTypes.FOR */:
|
|
2156
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2157
|
+
case 0 /* NodeTypes.ROOT */:
|
|
2150
2158
|
traverseChildren(node, context);
|
|
2151
2159
|
break;
|
|
2152
2160
|
}
|
|
@@ -2162,17 +2170,17 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
2162
2170
|
? (n) => n === name
|
|
2163
2171
|
: (n) => name.test(n);
|
|
2164
2172
|
return (node, context) => {
|
|
2165
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
2173
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2166
2174
|
const { props } = node;
|
|
2167
2175
|
// structural directive transforms are not concerned with slots
|
|
2168
2176
|
// as they are handled separately in vSlot.ts
|
|
2169
|
-
if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
|
|
2177
|
+
if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
|
|
2170
2178
|
return;
|
|
2171
2179
|
}
|
|
2172
2180
|
const exitFns = [];
|
|
2173
2181
|
for (let i = 0; i < props.length; i++) {
|
|
2174
2182
|
const prop = props[i];
|
|
2175
|
-
if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
|
|
2183
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
|
|
2176
2184
|
// structural directives are removed to avoid infinite recursion
|
|
2177
2185
|
// also we remove them *before* applying so that it can further
|
|
2178
2186
|
// traverse itself in case it moves the node around
|
|
@@ -2395,10 +2403,10 @@ function genHoists(hoists, context) {
|
|
|
2395
2403
|
}
|
|
2396
2404
|
function isText$1(n) {
|
|
2397
2405
|
return (isString(n) ||
|
|
2398
|
-
n.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
2399
|
-
n.type === 2 /* TEXT */ ||
|
|
2400
|
-
n.type === 5 /* INTERPOLATION */ ||
|
|
2401
|
-
n.type === 8 /* COMPOUND_EXPRESSION */);
|
|
2406
|
+
n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
2407
|
+
n.type === 2 /* NodeTypes.TEXT */ ||
|
|
2408
|
+
n.type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
2409
|
+
n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
|
|
2402
2410
|
}
|
|
2403
2411
|
function genNodeListAsArray(nodes, context) {
|
|
2404
2412
|
const multilines = nodes.length > 3 ||
|
|
@@ -2443,69 +2451,69 @@ function genNode(node, context) {
|
|
|
2443
2451
|
return;
|
|
2444
2452
|
}
|
|
2445
2453
|
switch (node.type) {
|
|
2446
|
-
case 1 /* ELEMENT */:
|
|
2447
|
-
case 9 /* IF */:
|
|
2448
|
-
case 11 /* FOR */:
|
|
2454
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2455
|
+
case 9 /* NodeTypes.IF */:
|
|
2456
|
+
case 11 /* NodeTypes.FOR */:
|
|
2449
2457
|
(process.env.NODE_ENV !== 'production') &&
|
|
2450
2458
|
assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
|
|
2451
2459
|
`Apply appropriate transforms first.`);
|
|
2452
2460
|
genNode(node.codegenNode, context);
|
|
2453
2461
|
break;
|
|
2454
|
-
case 2 /* TEXT */:
|
|
2462
|
+
case 2 /* NodeTypes.TEXT */:
|
|
2455
2463
|
genText(node, context);
|
|
2456
2464
|
break;
|
|
2457
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
2465
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
2458
2466
|
genExpression(node, context);
|
|
2459
2467
|
break;
|
|
2460
|
-
case 5 /* INTERPOLATION */:
|
|
2468
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2461
2469
|
genInterpolation(node, context);
|
|
2462
2470
|
break;
|
|
2463
|
-
case 12 /* TEXT_CALL */:
|
|
2471
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
2464
2472
|
genNode(node.codegenNode, context);
|
|
2465
2473
|
break;
|
|
2466
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
2474
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
2467
2475
|
genCompoundExpression(node, context);
|
|
2468
2476
|
break;
|
|
2469
|
-
case 3 /* COMMENT */:
|
|
2477
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2470
2478
|
genComment(node, context);
|
|
2471
2479
|
break;
|
|
2472
|
-
case 13 /* VNODE_CALL */:
|
|
2480
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
2473
2481
|
genVNodeCall(node, context);
|
|
2474
2482
|
break;
|
|
2475
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
2483
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
2476
2484
|
genCallExpression(node, context);
|
|
2477
2485
|
break;
|
|
2478
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
2486
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
2479
2487
|
genObjectExpression(node, context);
|
|
2480
2488
|
break;
|
|
2481
|
-
case 17 /* JS_ARRAY_EXPRESSION */:
|
|
2489
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
2482
2490
|
genArrayExpression(node, context);
|
|
2483
2491
|
break;
|
|
2484
|
-
case 18 /* JS_FUNCTION_EXPRESSION */:
|
|
2492
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
2485
2493
|
genFunctionExpression(node, context);
|
|
2486
2494
|
break;
|
|
2487
|
-
case 19 /* JS_CONDITIONAL_EXPRESSION */:
|
|
2495
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
2488
2496
|
genConditionalExpression(node, context);
|
|
2489
2497
|
break;
|
|
2490
|
-
case 20 /* JS_CACHE_EXPRESSION */:
|
|
2498
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
2491
2499
|
genCacheExpression(node, context);
|
|
2492
2500
|
break;
|
|
2493
|
-
case 21 /* JS_BLOCK_STATEMENT */:
|
|
2501
|
+
case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
|
|
2494
2502
|
genNodeList(node.body, context, true, false);
|
|
2495
2503
|
break;
|
|
2496
2504
|
// SSR only types
|
|
2497
|
-
case 22 /* JS_TEMPLATE_LITERAL */:
|
|
2505
|
+
case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
|
|
2498
2506
|
break;
|
|
2499
|
-
case 23 /* JS_IF_STATEMENT */:
|
|
2507
|
+
case 23 /* NodeTypes.JS_IF_STATEMENT */:
|
|
2500
2508
|
break;
|
|
2501
|
-
case 24 /* JS_ASSIGNMENT_EXPRESSION */:
|
|
2509
|
+
case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
|
|
2502
2510
|
break;
|
|
2503
|
-
case 25 /* JS_SEQUENCE_EXPRESSION */:
|
|
2511
|
+
case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
|
|
2504
2512
|
break;
|
|
2505
|
-
case 26 /* JS_RETURN_STATEMENT */:
|
|
2513
|
+
case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
|
|
2506
2514
|
break;
|
|
2507
2515
|
/* istanbul ignore next */
|
|
2508
|
-
case 10 /* IF_BRANCH */:
|
|
2516
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2509
2517
|
// noop
|
|
2510
2518
|
break;
|
|
2511
2519
|
default:
|
|
@@ -2545,7 +2553,7 @@ function genCompoundExpression(node, context) {
|
|
|
2545
2553
|
}
|
|
2546
2554
|
function genExpressionAsPropertyKey(node, context) {
|
|
2547
2555
|
const { push } = context;
|
|
2548
|
-
if (node.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
2556
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
2549
2557
|
push(`[`);
|
|
2550
2558
|
genCompoundExpression(node, context);
|
|
2551
2559
|
push(`]`);
|
|
@@ -2623,7 +2631,7 @@ function genObjectExpression(node, context) {
|
|
|
2623
2631
|
}
|
|
2624
2632
|
const multilines = properties.length > 1 ||
|
|
2625
2633
|
(((process.env.NODE_ENV !== 'production')) &&
|
|
2626
|
-
properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
|
|
2634
|
+
properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
|
|
2627
2635
|
push(multilines ? `{` : `{ `);
|
|
2628
2636
|
multilines && indent();
|
|
2629
2637
|
for (let i = 0; i < properties.length; i++) {
|
|
@@ -2692,7 +2700,7 @@ function genFunctionExpression(node, context) {
|
|
|
2692
2700
|
function genConditionalExpression(node, context) {
|
|
2693
2701
|
const { test, consequent, alternate, newline: needNewline } = node;
|
|
2694
2702
|
const { push, indent, deindent, newline } = context;
|
|
2695
|
-
if (test.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2703
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2696
2704
|
const needsParens = !isSimpleIdentifier(test.content);
|
|
2697
2705
|
needsParens && push(`(`);
|
|
2698
2706
|
genExpression(test, context);
|
|
@@ -2712,7 +2720,7 @@ function genConditionalExpression(node, context) {
|
|
|
2712
2720
|
needNewline && newline();
|
|
2713
2721
|
needNewline || push(` `);
|
|
2714
2722
|
push(`: `);
|
|
2715
|
-
const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
|
|
2723
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
2716
2724
|
if (!isNested) {
|
|
2717
2725
|
context.indentLevel++;
|
|
2718
2726
|
}
|
|
@@ -2876,32 +2884,32 @@ function validateBrowserExpression(node, context, asParams = false, asRawStateme
|
|
|
2876
2884
|
if (keywordMatch) {
|
|
2877
2885
|
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
|
2878
2886
|
}
|
|
2879
|
-
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
2887
|
+
context.onError(createCompilerError(44 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
2880
2888
|
}
|
|
2881
2889
|
}
|
|
2882
2890
|
|
|
2883
2891
|
const transformExpression = (node, context) => {
|
|
2884
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
2892
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
2885
2893
|
node.content = processExpression(node.content, context);
|
|
2886
2894
|
}
|
|
2887
|
-
else if (node.type === 1 /* ELEMENT */) {
|
|
2895
|
+
else if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2888
2896
|
// handle directives on element
|
|
2889
2897
|
for (let i = 0; i < node.props.length; i++) {
|
|
2890
2898
|
const dir = node.props[i];
|
|
2891
2899
|
// do not process for v-on & v-for since they are special handled
|
|
2892
|
-
if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
|
|
2900
|
+
if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
|
|
2893
2901
|
const exp = dir.exp;
|
|
2894
2902
|
const arg = dir.arg;
|
|
2895
2903
|
// do not process exp if this is v-on:arg - we need special handling
|
|
2896
2904
|
// for wrapping inline statements.
|
|
2897
2905
|
if (exp &&
|
|
2898
|
-
exp.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
2906
|
+
exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
2899
2907
|
!(dir.name === 'on' && arg)) {
|
|
2900
2908
|
dir.exp = processExpression(exp, context,
|
|
2901
2909
|
// slot args must be processed as function params
|
|
2902
2910
|
dir.name === 'slot');
|
|
2903
2911
|
}
|
|
2904
|
-
if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
2912
|
+
if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
2905
2913
|
dir.arg = processExpression(arg, context);
|
|
2906
2914
|
}
|
|
2907
2915
|
}
|
|
@@ -2936,7 +2944,7 @@ const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (n
|
|
|
2936
2944
|
let key = 0;
|
|
2937
2945
|
while (i-- >= 0) {
|
|
2938
2946
|
const sibling = siblings[i];
|
|
2939
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
2947
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
2940
2948
|
key += sibling.branches.length;
|
|
2941
2949
|
}
|
|
2942
2950
|
}
|
|
@@ -2959,7 +2967,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2959
2967
|
if (dir.name !== 'else' &&
|
|
2960
2968
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
2961
2969
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
2962
|
-
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
2970
|
+
context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
2963
2971
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
2964
2972
|
}
|
|
2965
2973
|
if ((process.env.NODE_ENV !== 'production') && true && dir.exp) {
|
|
@@ -2968,7 +2976,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2968
2976
|
if (dir.name === 'if') {
|
|
2969
2977
|
const branch = createIfBranch(node, dir);
|
|
2970
2978
|
const ifNode = {
|
|
2971
|
-
type: 9 /* IF */,
|
|
2979
|
+
type: 9 /* NodeTypes.IF */,
|
|
2972
2980
|
loc: node.loc,
|
|
2973
2981
|
branches: [branch]
|
|
2974
2982
|
};
|
|
@@ -2984,22 +2992,22 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2984
2992
|
let i = siblings.indexOf(node);
|
|
2985
2993
|
while (i-- >= -1) {
|
|
2986
2994
|
const sibling = siblings[i];
|
|
2987
|
-
if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* COMMENT */) {
|
|
2995
|
+
if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
|
|
2988
2996
|
context.removeNode(sibling);
|
|
2989
2997
|
comments.unshift(sibling);
|
|
2990
2998
|
continue;
|
|
2991
2999
|
}
|
|
2992
3000
|
if (sibling &&
|
|
2993
|
-
sibling.type === 2 /* TEXT */ &&
|
|
3001
|
+
sibling.type === 2 /* NodeTypes.TEXT */ &&
|
|
2994
3002
|
!sibling.content.trim().length) {
|
|
2995
3003
|
context.removeNode(sibling);
|
|
2996
3004
|
continue;
|
|
2997
3005
|
}
|
|
2998
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3006
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
2999
3007
|
// Check if v-else was followed by v-else-if
|
|
3000
3008
|
if (dir.name === 'else-if' &&
|
|
3001
3009
|
sibling.branches[sibling.branches.length - 1].condition === undefined) {
|
|
3002
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3010
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3003
3011
|
}
|
|
3004
3012
|
// move the node to the if node's branches
|
|
3005
3013
|
context.removeNode();
|
|
@@ -3008,7 +3016,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3008
3016
|
comments.length &&
|
|
3009
3017
|
// #3619 ignore comments if the v-if is direct child of <transition>
|
|
3010
3018
|
!(context.parent &&
|
|
3011
|
-
context.parent.type === 1 /* ELEMENT */ &&
|
|
3019
|
+
context.parent.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3012
3020
|
isBuiltInType(context.parent.tag, 'transition'))) {
|
|
3013
3021
|
branch.children = [...comments, ...branch.children];
|
|
3014
3022
|
}
|
|
@@ -3018,7 +3026,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3018
3026
|
if (key) {
|
|
3019
3027
|
sibling.branches.forEach(({ userKey }) => {
|
|
3020
3028
|
if (isSameKey(userKey, key)) {
|
|
3021
|
-
context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3029
|
+
context.onError(createCompilerError(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3022
3030
|
}
|
|
3023
3031
|
});
|
|
3024
3032
|
}
|
|
@@ -3036,16 +3044,16 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3036
3044
|
context.currentNode = null;
|
|
3037
3045
|
}
|
|
3038
3046
|
else {
|
|
3039
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3047
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3040
3048
|
}
|
|
3041
3049
|
break;
|
|
3042
3050
|
}
|
|
3043
3051
|
}
|
|
3044
3052
|
}
|
|
3045
3053
|
function createIfBranch(node, dir) {
|
|
3046
|
-
const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
|
|
3054
|
+
const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
|
|
3047
3055
|
return {
|
|
3048
|
-
type: 10 /* IF_BRANCH */,
|
|
3056
|
+
type: 10 /* NodeTypes.IF_BRANCH */,
|
|
3049
3057
|
loc: node.loc,
|
|
3050
3058
|
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
3051
3059
|
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
|
|
@@ -3069,27 +3077,27 @@ function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
|
3069
3077
|
}
|
|
3070
3078
|
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
3071
3079
|
const { helper } = context;
|
|
3072
|
-
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
|
|
3080
|
+
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
|
|
3073
3081
|
const { children } = branch;
|
|
3074
3082
|
const firstChild = children[0];
|
|
3075
|
-
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
|
|
3083
|
+
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
|
|
3076
3084
|
if (needFragmentWrapper) {
|
|
3077
|
-
if (children.length === 1 && firstChild.type === 11 /* FOR */) {
|
|
3085
|
+
if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
|
|
3078
3086
|
// optimize away nested fragments when child is a ForNode
|
|
3079
3087
|
const vnodeCall = firstChild.codegenNode;
|
|
3080
3088
|
injectProp(vnodeCall, keyProperty, context);
|
|
3081
3089
|
return vnodeCall;
|
|
3082
3090
|
}
|
|
3083
3091
|
else {
|
|
3084
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
3085
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
3092
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
3093
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
3086
3094
|
// check if the fragment actually contains a single valid child with
|
|
3087
3095
|
// the rest being comments
|
|
3088
3096
|
if ((process.env.NODE_ENV !== 'production') &&
|
|
3089
3097
|
!branch.isTemplateIf &&
|
|
3090
|
-
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
3091
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
3092
|
-
patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
|
|
3098
|
+
children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
|
|
3099
|
+
patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
|
|
3100
|
+
patchFlagText += `, ${PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
|
|
3093
3101
|
}
|
|
3094
3102
|
return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, false, false /* isComponent */, branch.loc);
|
|
3095
3103
|
}
|
|
@@ -3098,7 +3106,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
3098
3106
|
const ret = firstChild.codegenNode;
|
|
3099
3107
|
const vnodeCall = getMemoedVNodeCall(ret);
|
|
3100
3108
|
// Change createVNode to createBlock.
|
|
3101
|
-
if (vnodeCall.type === 13 /* VNODE_CALL */) {
|
|
3109
|
+
if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
3102
3110
|
makeBlock(vnodeCall, context);
|
|
3103
3111
|
}
|
|
3104
3112
|
// inject branch key
|
|
@@ -3110,7 +3118,7 @@ function isSameKey(a, b) {
|
|
|
3110
3118
|
if (!a || a.type !== b.type) {
|
|
3111
3119
|
return false;
|
|
3112
3120
|
}
|
|
3113
|
-
if (a.type === 6 /* ATTRIBUTE */) {
|
|
3121
|
+
if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3114
3122
|
if (a.value.content !== b.value.content) {
|
|
3115
3123
|
return false;
|
|
3116
3124
|
}
|
|
@@ -3122,7 +3130,7 @@ function isSameKey(a, b) {
|
|
|
3122
3130
|
if (exp.type !== branchExp.type) {
|
|
3123
3131
|
return false;
|
|
3124
3132
|
}
|
|
3125
|
-
if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3133
|
+
if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3126
3134
|
exp.isStatic !== branchExp.isStatic ||
|
|
3127
3135
|
exp.content !== branchExp.content) {
|
|
3128
3136
|
return false;
|
|
@@ -3132,15 +3140,15 @@ function isSameKey(a, b) {
|
|
|
3132
3140
|
}
|
|
3133
3141
|
function getParentCondition(node) {
|
|
3134
3142
|
while (true) {
|
|
3135
|
-
if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3136
|
-
if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3143
|
+
if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3144
|
+
if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3137
3145
|
node = node.alternate;
|
|
3138
3146
|
}
|
|
3139
3147
|
else {
|
|
3140
3148
|
return node;
|
|
3141
3149
|
}
|
|
3142
3150
|
}
|
|
3143
|
-
else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
|
|
3151
|
+
else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
3144
3152
|
node = node.value;
|
|
3145
3153
|
}
|
|
3146
3154
|
}
|
|
@@ -3158,17 +3166,17 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3158
3166
|
const memo = findDir(node, 'memo');
|
|
3159
3167
|
const keyProp = findProp(node, `key`);
|
|
3160
3168
|
const keyExp = keyProp &&
|
|
3161
|
-
(keyProp.type === 6 /* ATTRIBUTE */
|
|
3169
|
+
(keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3162
3170
|
? createSimpleExpression(keyProp.value.content, true)
|
|
3163
3171
|
: keyProp.exp);
|
|
3164
3172
|
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
|
3165
|
-
const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3166
|
-
forNode.source.constType > 0 /* NOT_CONSTANT */;
|
|
3173
|
+
const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3174
|
+
forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
3167
3175
|
const fragmentFlag = isStableFragment
|
|
3168
|
-
? 64 /* STABLE_FRAGMENT */
|
|
3176
|
+
? 64 /* PatchFlags.STABLE_FRAGMENT */
|
|
3169
3177
|
: keyProp
|
|
3170
|
-
? 128 /* KEYED_FRAGMENT */
|
|
3171
|
-
: 256 /* UNKEYED_FRAGMENT */;
|
|
3178
|
+
? 128 /* PatchFlags.KEYED_FRAGMENT */
|
|
3179
|
+
: 256 /* PatchFlags.UNKEYED_FRAGMENT */;
|
|
3172
3180
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
|
|
3173
3181
|
((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
|
|
3174
3182
|
return () => {
|
|
@@ -3178,16 +3186,16 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3178
3186
|
// check <template v-for> key placement
|
|
3179
3187
|
if (((process.env.NODE_ENV !== 'production') || !true) && isTemplate) {
|
|
3180
3188
|
node.children.some(c => {
|
|
3181
|
-
if (c.type === 1 /* ELEMENT */) {
|
|
3189
|
+
if (c.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3182
3190
|
const key = findProp(c, 'key');
|
|
3183
3191
|
if (key) {
|
|
3184
|
-
context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3192
|
+
context.onError(createCompilerError(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3185
3193
|
return true;
|
|
3186
3194
|
}
|
|
3187
3195
|
}
|
|
3188
3196
|
});
|
|
3189
3197
|
}
|
|
3190
|
-
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
|
|
3198
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
|
|
3191
3199
|
const slotOutlet = isSlotOutlet(node)
|
|
3192
3200
|
? node
|
|
3193
3201
|
: isTemplate &&
|
|
@@ -3208,9 +3216,9 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3208
3216
|
else if (needFragmentWrapper) {
|
|
3209
3217
|
// <template v-for="..."> with text or multi-elements
|
|
3210
3218
|
// should generate a fragment block for each loop
|
|
3211
|
-
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
|
|
3219
|
+
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
|
|
3212
3220
|
((process.env.NODE_ENV !== 'production')
|
|
3213
|
-
? ` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
|
|
3221
|
+
? ` /* ${PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`
|
|
3214
3222
|
: ``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
3215
3223
|
}
|
|
3216
3224
|
else {
|
|
@@ -3267,7 +3275,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3267
3275
|
// target-agnostic transform used for both Client and SSR
|
|
3268
3276
|
function processFor(node, dir, context, processCodegen) {
|
|
3269
3277
|
if (!dir.exp) {
|
|
3270
|
-
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3278
|
+
context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3271
3279
|
return;
|
|
3272
3280
|
}
|
|
3273
3281
|
const parseResult = parseForExpression(
|
|
@@ -3275,13 +3283,13 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3275
3283
|
// before expression transform.
|
|
3276
3284
|
dir.exp, context);
|
|
3277
3285
|
if (!parseResult) {
|
|
3278
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3286
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3279
3287
|
return;
|
|
3280
3288
|
}
|
|
3281
3289
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
3282
3290
|
const { source, value, key, index } = parseResult;
|
|
3283
3291
|
const forNode = {
|
|
3284
|
-
type: 11 /* FOR */,
|
|
3292
|
+
type: 11 /* NodeTypes.FOR */,
|
|
3285
3293
|
loc: dir.loc,
|
|
3286
3294
|
source,
|
|
3287
3295
|
valueAlias: value,
|
|
@@ -3381,9 +3389,9 @@ const defaultFallback = createSimpleExpression(`undefined`, false);
|
|
|
3381
3389
|
// Note the exit callback is executed before buildSlots() on the same node,
|
|
3382
3390
|
// so only nested slots see positive numbers.
|
|
3383
3391
|
const trackSlotScopes = (node, context) => {
|
|
3384
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
3385
|
-
(node.tagType === 1 /* COMPONENT */ ||
|
|
3386
|
-
node.tagType === 3 /* TEMPLATE */)) {
|
|
3392
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3393
|
+
(node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
3394
|
+
node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
|
|
3387
3395
|
// We are only checking non-empty v-slot here
|
|
3388
3396
|
// since we only care about slots that introduce scope variables.
|
|
3389
3397
|
const vSlot = findDir(node, 'slot');
|
|
@@ -3445,20 +3453,21 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3445
3453
|
let hasNamedDefaultSlot = false;
|
|
3446
3454
|
const implicitDefaultChildren = [];
|
|
3447
3455
|
const seenSlotNames = new Set();
|
|
3456
|
+
let conditionalBranchIndex = 0;
|
|
3448
3457
|
for (let i = 0; i < children.length; i++) {
|
|
3449
3458
|
const slotElement = children[i];
|
|
3450
3459
|
let slotDir;
|
|
3451
3460
|
if (!isTemplateNode(slotElement) ||
|
|
3452
3461
|
!(slotDir = findDir(slotElement, 'slot', true))) {
|
|
3453
3462
|
// not a <template v-slot>, skip.
|
|
3454
|
-
if (slotElement.type !== 3 /* COMMENT */) {
|
|
3463
|
+
if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3455
3464
|
implicitDefaultChildren.push(slotElement);
|
|
3456
3465
|
}
|
|
3457
3466
|
continue;
|
|
3458
3467
|
}
|
|
3459
3468
|
if (onComponentSlot) {
|
|
3460
3469
|
// already has on-component slot - this is incorrect usage.
|
|
3461
|
-
context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3470
|
+
context.onError(createCompilerError(37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3462
3471
|
break;
|
|
3463
3472
|
}
|
|
3464
3473
|
hasTemplateSlots = true;
|
|
@@ -3479,7 +3488,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3479
3488
|
let vFor;
|
|
3480
3489
|
if ((vIf = findDir(slotElement, 'if'))) {
|
|
3481
3490
|
hasDynamicSlots = true;
|
|
3482
|
-
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
|
|
3491
|
+
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
|
|
3483
3492
|
}
|
|
3484
3493
|
else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
|
|
3485
3494
|
// find adjacent v-if
|
|
@@ -3487,7 +3496,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3487
3496
|
let prev;
|
|
3488
3497
|
while (j--) {
|
|
3489
3498
|
prev = children[j];
|
|
3490
|
-
if (prev.type !== 3 /* COMMENT */) {
|
|
3499
|
+
if (prev.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3491
3500
|
break;
|
|
3492
3501
|
}
|
|
3493
3502
|
}
|
|
@@ -3497,15 +3506,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3497
3506
|
i--;
|
|
3498
3507
|
// attach this slot to previous conditional
|
|
3499
3508
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
3500
|
-
while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3509
|
+
while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3501
3510
|
conditional = conditional.alternate;
|
|
3502
3511
|
}
|
|
3503
3512
|
conditional.alternate = vElse.exp
|
|
3504
|
-
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
|
|
3505
|
-
: buildDynamicSlot(slotName, slotFunction);
|
|
3513
|
+
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
|
|
3514
|
+
: buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
|
3506
3515
|
}
|
|
3507
3516
|
else {
|
|
3508
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
3517
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
3509
3518
|
}
|
|
3510
3519
|
}
|
|
3511
3520
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -3521,14 +3530,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3521
3530
|
]));
|
|
3522
3531
|
}
|
|
3523
3532
|
else {
|
|
3524
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3533
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3525
3534
|
}
|
|
3526
3535
|
}
|
|
3527
3536
|
else {
|
|
3528
3537
|
// check duplicate static names
|
|
3529
3538
|
if (staticSlotName) {
|
|
3530
3539
|
if (seenSlotNames.has(staticSlotName)) {
|
|
3531
|
-
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3540
|
+
context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3532
3541
|
continue;
|
|
3533
3542
|
}
|
|
3534
3543
|
seenSlotNames.add(staticSlotName);
|
|
@@ -3558,7 +3567,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3558
3567
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
3559
3568
|
// implicit default slot (mixed with named slots)
|
|
3560
3569
|
if (hasNamedDefaultSlot) {
|
|
3561
|
-
context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
3570
|
+
context.onError(createCompilerError(39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
3562
3571
|
}
|
|
3563
3572
|
else {
|
|
3564
3573
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -3566,10 +3575,10 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3566
3575
|
}
|
|
3567
3576
|
}
|
|
3568
3577
|
const slotFlag = hasDynamicSlots
|
|
3569
|
-
? 2 /* DYNAMIC */
|
|
3578
|
+
? 2 /* SlotFlags.DYNAMIC */
|
|
3570
3579
|
: hasForwardedSlots(node.children)
|
|
3571
|
-
? 3 /* FORWARDED */
|
|
3572
|
-
: 1 /* STABLE */;
|
|
3580
|
+
? 3 /* SlotFlags.FORWARDED */
|
|
3581
|
+
: 1 /* SlotFlags.STABLE */;
|
|
3573
3582
|
let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
|
|
3574
3583
|
// 2 = compiled but dynamic = can skip normalization, but must run diff
|
|
3575
3584
|
// 1 = compiled and static = can skip normalization AND diff as optimized
|
|
@@ -3585,28 +3594,32 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3585
3594
|
hasDynamicSlots
|
|
3586
3595
|
};
|
|
3587
3596
|
}
|
|
3588
|
-
function buildDynamicSlot(name, fn) {
|
|
3589
|
-
|
|
3597
|
+
function buildDynamicSlot(name, fn, index) {
|
|
3598
|
+
const props = [
|
|
3590
3599
|
createObjectProperty(`name`, name),
|
|
3591
3600
|
createObjectProperty(`fn`, fn)
|
|
3592
|
-
]
|
|
3601
|
+
];
|
|
3602
|
+
if (index != null) {
|
|
3603
|
+
props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
|
|
3604
|
+
}
|
|
3605
|
+
return createObjectExpression(props);
|
|
3593
3606
|
}
|
|
3594
3607
|
function hasForwardedSlots(children) {
|
|
3595
3608
|
for (let i = 0; i < children.length; i++) {
|
|
3596
3609
|
const child = children[i];
|
|
3597
3610
|
switch (child.type) {
|
|
3598
|
-
case 1 /* ELEMENT */:
|
|
3599
|
-
if (child.tagType === 2 /* SLOT */ ||
|
|
3611
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
3612
|
+
if (child.tagType === 2 /* ElementTypes.SLOT */ ||
|
|
3600
3613
|
hasForwardedSlots(child.children)) {
|
|
3601
3614
|
return true;
|
|
3602
3615
|
}
|
|
3603
3616
|
break;
|
|
3604
|
-
case 9 /* IF */:
|
|
3617
|
+
case 9 /* NodeTypes.IF */:
|
|
3605
3618
|
if (hasForwardedSlots(child.branches))
|
|
3606
3619
|
return true;
|
|
3607
3620
|
break;
|
|
3608
|
-
case 10 /* IF_BRANCH */:
|
|
3609
|
-
case 11 /* FOR */:
|
|
3621
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
3622
|
+
case 11 /* NodeTypes.FOR */:
|
|
3610
3623
|
if (hasForwardedSlots(child.children))
|
|
3611
3624
|
return true;
|
|
3612
3625
|
break;
|
|
@@ -3615,9 +3628,9 @@ function hasForwardedSlots(children) {
|
|
|
3615
3628
|
return false;
|
|
3616
3629
|
}
|
|
3617
3630
|
function isNonWhitespaceContent(node) {
|
|
3618
|
-
if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
|
|
3631
|
+
if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
|
|
3619
3632
|
return true;
|
|
3620
|
-
return node.type === 2 /* TEXT */
|
|
3633
|
+
return node.type === 2 /* NodeTypes.TEXT */
|
|
3621
3634
|
? !!node.content.trim()
|
|
3622
3635
|
: isNonWhitespaceContent(node.content);
|
|
3623
3636
|
}
|
|
@@ -3631,13 +3644,13 @@ const transformElement = (node, context) => {
|
|
|
3631
3644
|
// processed and merged.
|
|
3632
3645
|
return function postTransformElement() {
|
|
3633
3646
|
node = context.currentNode;
|
|
3634
|
-
if (!(node.type === 1 /* ELEMENT */ &&
|
|
3635
|
-
(node.tagType === 0 /* ELEMENT */ ||
|
|
3636
|
-
node.tagType === 1 /* COMPONENT */))) {
|
|
3647
|
+
if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3648
|
+
(node.tagType === 0 /* ElementTypes.ELEMENT */ ||
|
|
3649
|
+
node.tagType === 1 /* ElementTypes.COMPONENT */))) {
|
|
3637
3650
|
return;
|
|
3638
3651
|
}
|
|
3639
3652
|
const { tag, props } = node;
|
|
3640
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
3653
|
+
const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
3641
3654
|
// The goal of the transform is to create a codegenNode implementing the
|
|
3642
3655
|
// VNodeCall interface.
|
|
3643
3656
|
let vnodeTag = isComponent
|
|
@@ -3688,9 +3701,9 @@ const transformElement = (node, context) => {
|
|
|
3688
3701
|
// collected by a parent block.
|
|
3689
3702
|
shouldUseBlock = true;
|
|
3690
3703
|
// 2. Force keep-alive to always be updated, since it uses raw children.
|
|
3691
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3704
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3692
3705
|
if ((process.env.NODE_ENV !== 'production') && node.children.length > 1) {
|
|
3693
|
-
context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3706
|
+
context.onError(createCompilerError(45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3694
3707
|
start: node.children[0].loc.start,
|
|
3695
3708
|
end: node.children[node.children.length - 1].loc.end,
|
|
3696
3709
|
source: ''
|
|
@@ -3706,22 +3719,22 @@ const transformElement = (node, context) => {
|
|
|
3706
3719
|
const { slots, hasDynamicSlots } = buildSlots(node, context);
|
|
3707
3720
|
vnodeChildren = slots;
|
|
3708
3721
|
if (hasDynamicSlots) {
|
|
3709
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3722
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3710
3723
|
}
|
|
3711
3724
|
}
|
|
3712
3725
|
else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
|
3713
3726
|
const child = node.children[0];
|
|
3714
3727
|
const type = child.type;
|
|
3715
3728
|
// check for dynamic text children
|
|
3716
|
-
const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
|
|
3717
|
-
type === 8 /* COMPOUND_EXPRESSION */;
|
|
3729
|
+
const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
3730
|
+
type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
|
|
3718
3731
|
if (hasDynamicTextChild &&
|
|
3719
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
3720
|
-
patchFlag |= 1 /* TEXT */;
|
|
3732
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
3733
|
+
patchFlag |= 1 /* PatchFlags.TEXT */;
|
|
3721
3734
|
}
|
|
3722
3735
|
// pass directly if the only child is a text node
|
|
3723
3736
|
// (plain / interpolation / expression)
|
|
3724
|
-
if (hasDynamicTextChild || type === 2 /* TEXT */) {
|
|
3737
|
+
if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
|
|
3725
3738
|
vnodeChildren = child;
|
|
3726
3739
|
}
|
|
3727
3740
|
else {
|
|
@@ -3766,8 +3779,8 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3766
3779
|
const isProp = findProp(node, 'is');
|
|
3767
3780
|
if (isProp) {
|
|
3768
3781
|
if (isExplicitDynamic ||
|
|
3769
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))) {
|
|
3770
|
-
const exp = isProp.type === 6 /* ATTRIBUTE */
|
|
3782
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))) {
|
|
3783
|
+
const exp = isProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3771
3784
|
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
|
3772
3785
|
: isProp.exp;
|
|
3773
3786
|
if (exp) {
|
|
@@ -3776,7 +3789,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3776
3789
|
]);
|
|
3777
3790
|
}
|
|
3778
3791
|
}
|
|
3779
|
-
else if (isProp.type === 6 /* ATTRIBUTE */ &&
|
|
3792
|
+
else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
3780
3793
|
isProp.value.content.startsWith('vue:')) {
|
|
3781
3794
|
// <button is="vue:xxx">
|
|
3782
3795
|
// if not <component>, only is value that starts with "vue:" will be
|
|
@@ -3840,9 +3853,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3840
3853
|
if (isEventHandler && isReservedProp(name)) {
|
|
3841
3854
|
hasVnodeHook = true;
|
|
3842
3855
|
}
|
|
3843
|
-
if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
|
|
3844
|
-
((value.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
3845
|
-
value.type === 8 /* COMPOUND_EXPRESSION */) &&
|
|
3856
|
+
if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */ ||
|
|
3857
|
+
((value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3858
|
+
value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) &&
|
|
3846
3859
|
getConstantType(value, context) > 0)) {
|
|
3847
3860
|
// skip if the prop is a cached handler or has constant value
|
|
3848
3861
|
return;
|
|
@@ -3873,7 +3886,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3873
3886
|
for (let i = 0; i < props.length; i++) {
|
|
3874
3887
|
// static attribute
|
|
3875
3888
|
const prop = props[i];
|
|
3876
|
-
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
3889
|
+
if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3877
3890
|
const { loc, name, value } = prop;
|
|
3878
3891
|
let isStatic = true;
|
|
3879
3892
|
if (name === 'ref') {
|
|
@@ -3886,7 +3899,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3886
3899
|
if (name === 'is' &&
|
|
3887
3900
|
(isComponentTag(tag) ||
|
|
3888
3901
|
(value && value.content.startsWith('vue:')) ||
|
|
3889
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
3902
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
3890
3903
|
continue;
|
|
3891
3904
|
}
|
|
3892
3905
|
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
|
|
@@ -3899,7 +3912,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3899
3912
|
// skip v-slot - it is handled by its dedicated transform.
|
|
3900
3913
|
if (name === 'slot') {
|
|
3901
3914
|
if (!isComponent) {
|
|
3902
|
-
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
3915
|
+
context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
|
|
3903
3916
|
}
|
|
3904
3917
|
continue;
|
|
3905
3918
|
}
|
|
@@ -3912,7 +3925,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3912
3925
|
(isVBind &&
|
|
3913
3926
|
isStaticArgOf(arg, 'is') &&
|
|
3914
3927
|
(isComponentTag(tag) ||
|
|
3915
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
3928
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
3916
3929
|
continue;
|
|
3917
3930
|
}
|
|
3918
3931
|
// skip v-on in SSR compilation
|
|
@@ -3943,9 +3956,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3943
3956
|
// 2.x v-bind object order compat
|
|
3944
3957
|
if ((process.env.NODE_ENV !== 'production')) {
|
|
3945
3958
|
const hasOverridableKeys = mergeArgs.some(arg => {
|
|
3946
|
-
if (arg.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
3959
|
+
if (arg.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
3947
3960
|
return arg.properties.some(({ key }) => {
|
|
3948
|
-
if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3961
|
+
if (key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3949
3962
|
!key.isStatic) {
|
|
3950
3963
|
return true;
|
|
3951
3964
|
}
|
|
@@ -3960,10 +3973,10 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3960
3973
|
}
|
|
3961
3974
|
});
|
|
3962
3975
|
if (hasOverridableKeys) {
|
|
3963
|
-
checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context, loc);
|
|
3976
|
+
checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */, context, loc);
|
|
3964
3977
|
}
|
|
3965
3978
|
}
|
|
3966
|
-
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
3979
|
+
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
3967
3980
|
mergeArgs.unshift(exp);
|
|
3968
3981
|
continue;
|
|
3969
3982
|
}
|
|
@@ -3973,17 +3986,17 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3973
3986
|
else {
|
|
3974
3987
|
// v-on="obj" -> toHandlers(obj)
|
|
3975
3988
|
mergeArgs.push({
|
|
3976
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
3989
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
3977
3990
|
loc,
|
|
3978
3991
|
callee: context.helper(TO_HANDLERS),
|
|
3979
|
-
arguments: [exp]
|
|
3992
|
+
arguments: isComponent ? [exp] : [exp, `true`]
|
|
3980
3993
|
});
|
|
3981
3994
|
}
|
|
3982
3995
|
}
|
|
3983
3996
|
else {
|
|
3984
3997
|
context.onError(createCompilerError(isVBind
|
|
3985
|
-
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
3986
|
-
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
3998
|
+
? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
|
|
3999
|
+
: 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
3987
4000
|
}
|
|
3988
4001
|
continue;
|
|
3989
4002
|
}
|
|
@@ -4030,31 +4043,31 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4030
4043
|
}
|
|
4031
4044
|
// patchFlag analysis
|
|
4032
4045
|
if (hasDynamicKeys) {
|
|
4033
|
-
patchFlag |= 16 /* FULL_PROPS */;
|
|
4046
|
+
patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
|
|
4034
4047
|
}
|
|
4035
4048
|
else {
|
|
4036
4049
|
if (hasClassBinding && !isComponent) {
|
|
4037
|
-
patchFlag |= 2 /* CLASS */;
|
|
4050
|
+
patchFlag |= 2 /* PatchFlags.CLASS */;
|
|
4038
4051
|
}
|
|
4039
4052
|
if (hasStyleBinding && !isComponent) {
|
|
4040
|
-
patchFlag |= 4 /* STYLE */;
|
|
4053
|
+
patchFlag |= 4 /* PatchFlags.STYLE */;
|
|
4041
4054
|
}
|
|
4042
4055
|
if (dynamicPropNames.length) {
|
|
4043
|
-
patchFlag |= 8 /* PROPS */;
|
|
4056
|
+
patchFlag |= 8 /* PatchFlags.PROPS */;
|
|
4044
4057
|
}
|
|
4045
4058
|
if (hasHydrationEventBinding) {
|
|
4046
|
-
patchFlag |= 32 /* HYDRATE_EVENTS */;
|
|
4059
|
+
patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
|
|
4047
4060
|
}
|
|
4048
4061
|
}
|
|
4049
4062
|
if (!shouldUseBlock &&
|
|
4050
|
-
(patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
|
|
4063
|
+
(patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
|
|
4051
4064
|
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
|
4052
|
-
patchFlag |= 512 /* NEED_PATCH */;
|
|
4065
|
+
patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
|
|
4053
4066
|
}
|
|
4054
4067
|
// pre-normalize props, SSR is skipped for now
|
|
4055
4068
|
if (!context.inSSR && propsExpression) {
|
|
4056
4069
|
switch (propsExpression.type) {
|
|
4057
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
4070
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
4058
4071
|
// means that there is no v-bind,
|
|
4059
4072
|
// but still need to deal with dynamic key binding
|
|
4060
4073
|
let classKeyIndex = -1;
|
|
@@ -4085,11 +4098,11 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4085
4098
|
// the static style is compiled into an object,
|
|
4086
4099
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4087
4100
|
(hasStyleBinding ||
|
|
4088
|
-
(styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
4101
|
+
(styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
4089
4102
|
styleProp.value.content.trim()[0] === `[`) ||
|
|
4090
4103
|
// v-bind:style and style both exist,
|
|
4091
4104
|
// v-bind:style with static literal object
|
|
4092
|
-
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4105
|
+
styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
|
|
4093
4106
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4094
4107
|
}
|
|
4095
4108
|
}
|
|
@@ -4098,7 +4111,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4098
4111
|
propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
|
|
4099
4112
|
}
|
|
4100
4113
|
break;
|
|
4101
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
4114
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
4102
4115
|
// mergeProps call, do nothing
|
|
4103
4116
|
break;
|
|
4104
4117
|
default:
|
|
@@ -4131,7 +4144,7 @@ function dedupeProperties(properties) {
|
|
|
4131
4144
|
for (let i = 0; i < properties.length; i++) {
|
|
4132
4145
|
const prop = properties[i];
|
|
4133
4146
|
// dynamic keys are always allowed
|
|
4134
|
-
if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4147
|
+
if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4135
4148
|
deduped.push(prop);
|
|
4136
4149
|
continue;
|
|
4137
4150
|
}
|
|
@@ -4151,7 +4164,7 @@ function dedupeProperties(properties) {
|
|
|
4151
4164
|
return deduped;
|
|
4152
4165
|
}
|
|
4153
4166
|
function mergeAsArray(existing, incoming) {
|
|
4154
|
-
if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
|
|
4167
|
+
if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
|
|
4155
4168
|
existing.value.elements.push(incoming.value);
|
|
4156
4169
|
}
|
|
4157
4170
|
else {
|
|
@@ -4259,7 +4272,7 @@ function processSlotOutlet(node, context) {
|
|
|
4259
4272
|
const nonNameProps = [];
|
|
4260
4273
|
for (let i = 0; i < node.props.length; i++) {
|
|
4261
4274
|
const p = node.props[i];
|
|
4262
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
4275
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4263
4276
|
if (p.value) {
|
|
4264
4277
|
if (p.name === 'name') {
|
|
4265
4278
|
slotName = JSON.stringify(p.value.content);
|
|
@@ -4287,7 +4300,7 @@ function processSlotOutlet(node, context) {
|
|
|
4287
4300
|
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
4288
4301
|
slotProps = props;
|
|
4289
4302
|
if (directives.length) {
|
|
4290
|
-
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4303
|
+
context.onError(createCompilerError(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4291
4304
|
}
|
|
4292
4305
|
}
|
|
4293
4306
|
return {
|
|
@@ -4300,18 +4313,26 @@ const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?functio
|
|
|
4300
4313
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4301
4314
|
const { loc, modifiers, arg } = dir;
|
|
4302
4315
|
if (!dir.exp && !modifiers.length) {
|
|
4303
|
-
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4316
|
+
context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4304
4317
|
}
|
|
4305
4318
|
let eventName;
|
|
4306
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4319
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4307
4320
|
if (arg.isStatic) {
|
|
4308
4321
|
let rawName = arg.content;
|
|
4309
4322
|
// TODO deprecate @vnodeXXX usage
|
|
4310
4323
|
if (rawName.startsWith('vue:')) {
|
|
4311
4324
|
rawName = `vnode-${rawName.slice(4)}`;
|
|
4312
4325
|
}
|
|
4313
|
-
|
|
4314
|
-
|
|
4326
|
+
const eventString = node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
4327
|
+
rawName.startsWith('vnode') ||
|
|
4328
|
+
!/[A-Z]/.test(rawName)
|
|
4329
|
+
? // for component and vnode lifecycle event listeners, auto convert
|
|
4330
|
+
// it to camelCase. See issue #2249
|
|
4331
|
+
toHandlerKey(camelize$1(rawName))
|
|
4332
|
+
// preserve case for plain element listeners that have uppercase
|
|
4333
|
+
// letters, as these may be custom elements' custom events
|
|
4334
|
+
: `on:${rawName}`;
|
|
4335
|
+
eventName = createSimpleExpression(eventString, true, arg.loc);
|
|
4315
4336
|
}
|
|
4316
4337
|
else {
|
|
4317
4338
|
// #2388
|
|
@@ -4378,7 +4399,7 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
4378
4399
|
const transformBind = (dir, _node, context) => {
|
|
4379
4400
|
const { exp, modifiers, loc } = dir;
|
|
4380
4401
|
const arg = dir.arg;
|
|
4381
|
-
if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
|
|
4402
|
+
if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4382
4403
|
arg.children.unshift(`(`);
|
|
4383
4404
|
arg.children.push(`) || ""`);
|
|
4384
4405
|
}
|
|
@@ -4387,7 +4408,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4387
4408
|
}
|
|
4388
4409
|
// .sync is replaced by v-model:arg
|
|
4389
4410
|
if (modifiers.includes('camel')) {
|
|
4390
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4411
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4391
4412
|
if (arg.isStatic) {
|
|
4392
4413
|
arg.content = camelize$1(arg.content);
|
|
4393
4414
|
}
|
|
@@ -4409,8 +4430,8 @@ const transformBind = (dir, _node, context) => {
|
|
|
4409
4430
|
}
|
|
4410
4431
|
}
|
|
4411
4432
|
if (!exp ||
|
|
4412
|
-
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4413
|
-
context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
|
|
4433
|
+
(exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4434
|
+
context.onError(createCompilerError(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
|
|
4414
4435
|
return {
|
|
4415
4436
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
4416
4437
|
};
|
|
@@ -4420,7 +4441,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4420
4441
|
};
|
|
4421
4442
|
};
|
|
4422
4443
|
const injectPrefix = (arg, prefix) => {
|
|
4423
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4444
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4424
4445
|
if (arg.isStatic) {
|
|
4425
4446
|
arg.content = prefix + arg.content;
|
|
4426
4447
|
}
|
|
@@ -4437,10 +4458,10 @@ const injectPrefix = (arg, prefix) => {
|
|
|
4437
4458
|
// Merge adjacent text nodes and expressions into a single expression
|
|
4438
4459
|
// e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
|
|
4439
4460
|
const transformText = (node, context) => {
|
|
4440
|
-
if (node.type === 0 /* ROOT */ ||
|
|
4441
|
-
node.type === 1 /* ELEMENT */ ||
|
|
4442
|
-
node.type === 11 /* FOR */ ||
|
|
4443
|
-
node.type === 10 /* IF_BRANCH */) {
|
|
4461
|
+
if (node.type === 0 /* NodeTypes.ROOT */ ||
|
|
4462
|
+
node.type === 1 /* NodeTypes.ELEMENT */ ||
|
|
4463
|
+
node.type === 11 /* NodeTypes.FOR */ ||
|
|
4464
|
+
node.type === 10 /* NodeTypes.IF_BRANCH */) {
|
|
4444
4465
|
// perform the transform on node exit so that all expressions have already
|
|
4445
4466
|
// been processed.
|
|
4446
4467
|
return () => {
|
|
@@ -4475,15 +4496,15 @@ const transformText = (node, context) => {
|
|
|
4475
4496
|
// setting textContent of the element.
|
|
4476
4497
|
// for component root it's always normalized anyway.
|
|
4477
4498
|
(children.length === 1 &&
|
|
4478
|
-
(node.type === 0 /* ROOT */ ||
|
|
4479
|
-
(node.type === 1 /* ELEMENT */ &&
|
|
4480
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
4499
|
+
(node.type === 0 /* NodeTypes.ROOT */ ||
|
|
4500
|
+
(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
4501
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
4481
4502
|
// #3756
|
|
4482
4503
|
// custom directives can potentially add DOM elements arbitrarily,
|
|
4483
4504
|
// we need to avoid setting textContent of the element at runtime
|
|
4484
4505
|
// to avoid accidentally overwriting the DOM elements added
|
|
4485
4506
|
// by the user through custom directives.
|
|
4486
|
-
!node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
|
|
4507
|
+
!node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4487
4508
|
!context.directiveTransforms[p.name]) &&
|
|
4488
4509
|
// in compat mode, <template> tags with no special directives
|
|
4489
4510
|
// will be rendered as a fragment so its children must be
|
|
@@ -4495,21 +4516,21 @@ const transformText = (node, context) => {
|
|
|
4495
4516
|
// runtime normalization.
|
|
4496
4517
|
for (let i = 0; i < children.length; i++) {
|
|
4497
4518
|
const child = children[i];
|
|
4498
|
-
if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4519
|
+
if (isText(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4499
4520
|
const callArgs = [];
|
|
4500
4521
|
// createTextVNode defaults to single whitespace, so if it is a
|
|
4501
4522
|
// single space the code could be an empty call to save bytes.
|
|
4502
|
-
if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
|
|
4523
|
+
if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
|
|
4503
4524
|
callArgs.push(child);
|
|
4504
4525
|
}
|
|
4505
4526
|
// mark dynamic text with flag so it gets patched inside a block
|
|
4506
4527
|
if (!context.ssr &&
|
|
4507
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
4508
|
-
callArgs.push(1 /* TEXT */ +
|
|
4509
|
-
((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[1 /* TEXT */]} */` : ``));
|
|
4528
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
4529
|
+
callArgs.push(1 /* PatchFlags.TEXT */ +
|
|
4530
|
+
((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[1 /* PatchFlags.TEXT */]} */` : ``));
|
|
4510
4531
|
}
|
|
4511
4532
|
children[i] = {
|
|
4512
|
-
type: 12 /* TEXT_CALL */,
|
|
4533
|
+
type: 12 /* NodeTypes.TEXT_CALL */,
|
|
4513
4534
|
content: child,
|
|
4514
4535
|
loc: child.loc,
|
|
4515
4536
|
codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
|
|
@@ -4522,7 +4543,7 @@ const transformText = (node, context) => {
|
|
|
4522
4543
|
|
|
4523
4544
|
const seen = new WeakSet();
|
|
4524
4545
|
const transformOnce = (node, context) => {
|
|
4525
|
-
if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
|
|
4546
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
|
|
4526
4547
|
if (seen.has(node) || context.inVOnce) {
|
|
4527
4548
|
return;
|
|
4528
4549
|
}
|
|
@@ -4542,18 +4563,18 @@ const transformOnce = (node, context) => {
|
|
|
4542
4563
|
const transformModel = (dir, node, context) => {
|
|
4543
4564
|
const { exp, arg } = dir;
|
|
4544
4565
|
if (!exp) {
|
|
4545
|
-
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4566
|
+
context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4546
4567
|
return createTransformProps();
|
|
4547
4568
|
}
|
|
4548
4569
|
const rawExp = exp.loc.source;
|
|
4549
|
-
const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4570
|
+
const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4550
4571
|
// im SFC <script setup> inline mode, the exp may have been transformed into
|
|
4551
4572
|
// _unref(exp)
|
|
4552
4573
|
context.bindingMetadata[rawExp];
|
|
4553
|
-
const maybeRef = !true /* SETUP_CONST */;
|
|
4574
|
+
const maybeRef = !true /* BindingTypes.SETUP_CONST */;
|
|
4554
4575
|
if (!expString.trim() ||
|
|
4555
4576
|
(!isMemberExpression(expString) && !maybeRef)) {
|
|
4556
|
-
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4577
|
+
context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4557
4578
|
return createTransformProps();
|
|
4558
4579
|
}
|
|
4559
4580
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -4578,7 +4599,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4578
4599
|
createObjectProperty(eventName, assignmentExp)
|
|
4579
4600
|
];
|
|
4580
4601
|
// modelModifiers: { foo: true, "bar-baz": true }
|
|
4581
|
-
if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
|
|
4602
|
+
if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
4582
4603
|
const modifiers = dir.modifiers
|
|
4583
4604
|
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
|
|
4584
4605
|
.join(`, `);
|
|
@@ -4587,7 +4608,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4587
4608
|
? `${arg.content}Modifiers`
|
|
4588
4609
|
: createCompoundExpression([arg, ' + "Modifiers"'])
|
|
4589
4610
|
: `modelModifiers`;
|
|
4590
|
-
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
|
|
4611
|
+
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* ConstantTypes.CAN_HOIST */)));
|
|
4591
4612
|
}
|
|
4592
4613
|
return createTransformProps(props);
|
|
4593
4614
|
};
|
|
@@ -4597,17 +4618,17 @@ function createTransformProps(props = []) {
|
|
|
4597
4618
|
|
|
4598
4619
|
const validDivisionCharRE = /[\w).+\-_$\]]/;
|
|
4599
4620
|
const transformFilter = (node, context) => {
|
|
4600
|
-
if (!isCompatEnabled("COMPILER_FILTER" /* COMPILER_FILTERS */, context)) {
|
|
4621
|
+
if (!isCompatEnabled("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context)) {
|
|
4601
4622
|
return;
|
|
4602
4623
|
}
|
|
4603
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
4624
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4604
4625
|
// filter rewrite is applied before expression transform so only
|
|
4605
4626
|
// simple expressions are possible at this stage
|
|
4606
4627
|
rewriteFilter(node.content, context);
|
|
4607
4628
|
}
|
|
4608
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4629
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4609
4630
|
node.props.forEach((prop) => {
|
|
4610
|
-
if (prop.type === 7 /* DIRECTIVE */ &&
|
|
4631
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4611
4632
|
prop.name !== 'for' &&
|
|
4612
4633
|
prop.exp) {
|
|
4613
4634
|
rewriteFilter(prop.exp, context);
|
|
@@ -4616,7 +4637,7 @@ const transformFilter = (node, context) => {
|
|
|
4616
4637
|
}
|
|
4617
4638
|
};
|
|
4618
4639
|
function rewriteFilter(node, context) {
|
|
4619
|
-
if (node.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4640
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4620
4641
|
parseFilter(node, context);
|
|
4621
4642
|
}
|
|
4622
4643
|
else {
|
|
@@ -4624,13 +4645,13 @@ function rewriteFilter(node, context) {
|
|
|
4624
4645
|
const child = node.children[i];
|
|
4625
4646
|
if (typeof child !== 'object')
|
|
4626
4647
|
continue;
|
|
4627
|
-
if (child.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4648
|
+
if (child.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4628
4649
|
parseFilter(child, context);
|
|
4629
4650
|
}
|
|
4630
|
-
else if (child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4651
|
+
else if (child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4631
4652
|
rewriteFilter(node, context);
|
|
4632
4653
|
}
|
|
4633
|
-
else if (child.type === 5 /* INTERPOLATION */) {
|
|
4654
|
+
else if (child.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4634
4655
|
rewriteFilter(child.content, context);
|
|
4635
4656
|
}
|
|
4636
4657
|
}
|
|
@@ -4739,7 +4760,7 @@ function parseFilter(node, context) {
|
|
|
4739
4760
|
}
|
|
4740
4761
|
if (filters.length) {
|
|
4741
4762
|
(process.env.NODE_ENV !== 'production') &&
|
|
4742
|
-
warnDeprecation("COMPILER_FILTER" /* COMPILER_FILTERS */, context, node.loc);
|
|
4763
|
+
warnDeprecation("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context, node.loc);
|
|
4743
4764
|
for (i = 0; i < filters.length; i++) {
|
|
4744
4765
|
expression = wrapFilter(expression, filters[i], context);
|
|
4745
4766
|
}
|
|
@@ -4763,7 +4784,7 @@ function wrapFilter(exp, filter, context) {
|
|
|
4763
4784
|
|
|
4764
4785
|
const seen$1 = new WeakSet();
|
|
4765
4786
|
const transformMemo = (node, context) => {
|
|
4766
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4787
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4767
4788
|
const dir = findDir(node, 'memo');
|
|
4768
4789
|
if (!dir || seen$1.has(node)) {
|
|
4769
4790
|
return;
|
|
@@ -4772,9 +4793,9 @@ const transformMemo = (node, context) => {
|
|
|
4772
4793
|
return () => {
|
|
4773
4794
|
const codegenNode = node.codegenNode ||
|
|
4774
4795
|
context.currentNode.codegenNode;
|
|
4775
|
-
if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
|
|
4796
|
+
if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
4776
4797
|
// non-component sub tree should be turned into a block
|
|
4777
|
-
if (node.tagType !== 1 /* COMPONENT */) {
|
|
4798
|
+
if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
|
|
4778
4799
|
makeBlock(codegenNode, context);
|
|
4779
4800
|
}
|
|
4780
4801
|
node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
|
@@ -4819,18 +4840,18 @@ function baseCompile(template, options = {}) {
|
|
|
4819
4840
|
/* istanbul ignore if */
|
|
4820
4841
|
{
|
|
4821
4842
|
if (options.prefixIdentifiers === true) {
|
|
4822
|
-
onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4843
|
+
onError(createCompilerError(46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4823
4844
|
}
|
|
4824
4845
|
else if (isModuleMode) {
|
|
4825
|
-
onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4846
|
+
onError(createCompilerError(47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4826
4847
|
}
|
|
4827
4848
|
}
|
|
4828
4849
|
const prefixIdentifiers = !true ;
|
|
4829
4850
|
if (options.cacheHandlers) {
|
|
4830
|
-
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
4851
|
+
onError(createCompilerError(48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
4831
4852
|
}
|
|
4832
4853
|
if (options.scopeId && !isModuleMode) {
|
|
4833
|
-
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
4854
|
+
onError(createCompilerError(49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
|
|
4834
4855
|
}
|
|
4835
4856
|
const ast = isString(template) ? baseParse(template, options) : template;
|
|
4836
4857
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|