@vue/compiler-core 3.2.36 → 3.2.39
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 +548 -535
- package/dist/compiler-core.cjs.prod.js +527 -514
- package/dist/compiler-core.esm-bundler.js +517 -504
- 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;
|
|
@@ -1786,9 +1786,9 @@ function getConstantType(node, context) {
|
|
|
1786
1786
|
// except set custom directives.
|
|
1787
1787
|
for (let i = 0; i < node.props.length; i++) {
|
|
1788
1788
|
const p = node.props[i];
|
|
1789
|
-
if (p.type === 7 /* DIRECTIVE */) {
|
|
1790
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1791
|
-
return 0 /* NOT_CONSTANT */;
|
|
1789
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1790
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1791
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1792
1792
|
}
|
|
1793
1793
|
}
|
|
1794
1794
|
context.removeHelper(OPEN_BLOCK);
|
|
@@ -1800,31 +1800,31 @@ function getConstantType(node, context) {
|
|
|
1800
1800
|
return returnType;
|
|
1801
1801
|
}
|
|
1802
1802
|
else {
|
|
1803
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1804
|
-
return 0 /* NOT_CONSTANT */;
|
|
1805
|
-
}
|
|
1806
|
-
case 2 /* TEXT */:
|
|
1807
|
-
case 3 /* COMMENT */:
|
|
1808
|
-
return 3 /* CAN_STRINGIFY */;
|
|
1809
|
-
case 9 /* IF */:
|
|
1810
|
-
case 11 /* FOR */:
|
|
1811
|
-
case 10 /* IF_BRANCH */:
|
|
1812
|
-
return 0 /* NOT_CONSTANT */;
|
|
1813
|
-
case 5 /* INTERPOLATION */:
|
|
1814
|
-
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 */:
|
|
1815
1815
|
return getConstantType(node.content, context);
|
|
1816
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
1816
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
1817
1817
|
return node.constType;
|
|
1818
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
1819
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1818
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
1819
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1820
1820
|
for (let i = 0; i < node.children.length; i++) {
|
|
1821
1821
|
const child = node.children[i];
|
|
1822
1822
|
if (isString(child) || isSymbol(child)) {
|
|
1823
1823
|
continue;
|
|
1824
1824
|
}
|
|
1825
1825
|
const childType = getConstantType(child, context);
|
|
1826
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1827
|
-
return 0 /* NOT_CONSTANT */;
|
|
1826
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1827
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1828
1828
|
}
|
|
1829
1829
|
else if (childType < returnType) {
|
|
1830
1830
|
returnType = childType;
|
|
@@ -1833,7 +1833,7 @@ function getConstantType(node, context) {
|
|
|
1833
1833
|
return returnType;
|
|
1834
1834
|
default:
|
|
1835
1835
|
if ((process.env.NODE_ENV !== 'production')) ;
|
|
1836
|
-
return 0 /* NOT_CONSTANT */;
|
|
1836
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1837
1837
|
}
|
|
1838
1838
|
}
|
|
1839
1839
|
const allowHoistedHelperSet = new Set([
|
|
@@ -1843,48 +1843,48 @@ const allowHoistedHelperSet = new Set([
|
|
|
1843
1843
|
GUARD_REACTIVE_PROPS
|
|
1844
1844
|
]);
|
|
1845
1845
|
function getConstantTypeOfHelperCall(value, context) {
|
|
1846
|
-
if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
|
|
1846
|
+
if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
|
|
1847
1847
|
!isString(value.callee) &&
|
|
1848
1848
|
allowHoistedHelperSet.has(value.callee)) {
|
|
1849
1849
|
const arg = value.arguments[0];
|
|
1850
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1850
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1851
1851
|
return getConstantType(arg, context);
|
|
1852
1852
|
}
|
|
1853
|
-
else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1853
|
+
else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1854
1854
|
// in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
|
|
1855
1855
|
return getConstantTypeOfHelperCall(arg, context);
|
|
1856
1856
|
}
|
|
1857
1857
|
}
|
|
1858
|
-
return 0 /* NOT_CONSTANT */;
|
|
1858
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1859
1859
|
}
|
|
1860
1860
|
function getGeneratedPropsConstantType(node, context) {
|
|
1861
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1861
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1862
1862
|
const props = getNodeProps(node);
|
|
1863
|
-
if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
1863
|
+
if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
1864
1864
|
const { properties } = props;
|
|
1865
1865
|
for (let i = 0; i < properties.length; i++) {
|
|
1866
1866
|
const { key, value } = properties[i];
|
|
1867
1867
|
const keyType = getConstantType(key, context);
|
|
1868
|
-
if (keyType === 0 /* NOT_CONSTANT */) {
|
|
1868
|
+
if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1869
1869
|
return keyType;
|
|
1870
1870
|
}
|
|
1871
1871
|
if (keyType < returnType) {
|
|
1872
1872
|
returnType = keyType;
|
|
1873
1873
|
}
|
|
1874
1874
|
let valueType;
|
|
1875
|
-
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1875
|
+
if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1876
1876
|
valueType = getConstantType(value, context);
|
|
1877
1877
|
}
|
|
1878
|
-
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1878
|
+
else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1879
1879
|
// some helper calls can be hoisted,
|
|
1880
1880
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1881
1881
|
// in this case we need to respect the ConstantType of the helper's arguments
|
|
1882
1882
|
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1883
1883
|
}
|
|
1884
1884
|
else {
|
|
1885
|
-
valueType = 0 /* NOT_CONSTANT */;
|
|
1885
|
+
valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1886
1886
|
}
|
|
1887
|
-
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1887
|
+
if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1888
1888
|
return valueType;
|
|
1889
1889
|
}
|
|
1890
1890
|
if (valueType < returnType) {
|
|
@@ -1896,7 +1896,7 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1896
1896
|
}
|
|
1897
1897
|
function getNodeProps(node) {
|
|
1898
1898
|
const codegenNode = node.codegenNode;
|
|
1899
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1899
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1900
1900
|
return codegenNode.props;
|
|
1901
1901
|
}
|
|
1902
1902
|
}
|
|
@@ -2021,7 +2021,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
2021
2021
|
if (isString(exp))
|
|
2022
2022
|
exp = createSimpleExpression(exp);
|
|
2023
2023
|
context.hoists.push(exp);
|
|
2024
|
-
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 */);
|
|
2025
2025
|
identifier.hoisted = exp;
|
|
2026
2026
|
return identifier;
|
|
2027
2027
|
},
|
|
@@ -2065,7 +2065,7 @@ function createRootCodegen(root, context) {
|
|
|
2065
2065
|
// single element root is never hoisted so codegenNode will never be
|
|
2066
2066
|
// SimpleExpressionNode
|
|
2067
2067
|
const codegenNode = child.codegenNode;
|
|
2068
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
2068
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
2069
2069
|
makeBlock(codegenNode, context);
|
|
2070
2070
|
}
|
|
2071
2071
|
root.codegenNode = codegenNode;
|
|
@@ -2079,14 +2079,14 @@ function createRootCodegen(root, context) {
|
|
|
2079
2079
|
}
|
|
2080
2080
|
else if (children.length > 1) {
|
|
2081
2081
|
// root has multiple nodes - return a fragment block.
|
|
2082
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
2083
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
2082
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
2083
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
2084
2084
|
// check if the fragment actually contains a single valid child with
|
|
2085
2085
|
// the rest being comments
|
|
2086
2086
|
if ((process.env.NODE_ENV !== 'production') &&
|
|
2087
|
-
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
2088
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
2089
|
-
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 */]}`;
|
|
2090
2090
|
}
|
|
2091
2091
|
root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
2092
2092
|
}
|
|
@@ -2132,29 +2132,29 @@ function traverseNode(node, context) {
|
|
|
2132
2132
|
}
|
|
2133
2133
|
}
|
|
2134
2134
|
switch (node.type) {
|
|
2135
|
-
case 3 /* COMMENT */:
|
|
2135
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2136
2136
|
if (!context.ssr) {
|
|
2137
2137
|
// inject import for the Comment symbol, which is needed for creating
|
|
2138
2138
|
// comment nodes with `createVNode`
|
|
2139
2139
|
context.helper(CREATE_COMMENT);
|
|
2140
2140
|
}
|
|
2141
2141
|
break;
|
|
2142
|
-
case 5 /* INTERPOLATION */:
|
|
2142
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2143
2143
|
// no need to traverse, but we need to inject toString helper
|
|
2144
2144
|
if (!context.ssr) {
|
|
2145
2145
|
context.helper(TO_DISPLAY_STRING);
|
|
2146
2146
|
}
|
|
2147
2147
|
break;
|
|
2148
2148
|
// for container types, further traverse downwards
|
|
2149
|
-
case 9 /* IF */:
|
|
2149
|
+
case 9 /* NodeTypes.IF */:
|
|
2150
2150
|
for (let i = 0; i < node.branches.length; i++) {
|
|
2151
2151
|
traverseNode(node.branches[i], context);
|
|
2152
2152
|
}
|
|
2153
2153
|
break;
|
|
2154
|
-
case 10 /* IF_BRANCH */:
|
|
2155
|
-
case 11 /* FOR */:
|
|
2156
|
-
case 1 /* ELEMENT */:
|
|
2157
|
-
case 0 /* ROOT */:
|
|
2154
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2155
|
+
case 11 /* NodeTypes.FOR */:
|
|
2156
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2157
|
+
case 0 /* NodeTypes.ROOT */:
|
|
2158
2158
|
traverseChildren(node, context);
|
|
2159
2159
|
break;
|
|
2160
2160
|
}
|
|
@@ -2170,17 +2170,17 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
2170
2170
|
? (n) => n === name
|
|
2171
2171
|
: (n) => name.test(n);
|
|
2172
2172
|
return (node, context) => {
|
|
2173
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
2173
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2174
2174
|
const { props } = node;
|
|
2175
2175
|
// structural directive transforms are not concerned with slots
|
|
2176
2176
|
// as they are handled separately in vSlot.ts
|
|
2177
|
-
if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
|
|
2177
|
+
if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
|
|
2178
2178
|
return;
|
|
2179
2179
|
}
|
|
2180
2180
|
const exitFns = [];
|
|
2181
2181
|
for (let i = 0; i < props.length; i++) {
|
|
2182
2182
|
const prop = props[i];
|
|
2183
|
-
if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
|
|
2183
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
|
|
2184
2184
|
// structural directives are removed to avoid infinite recursion
|
|
2185
2185
|
// also we remove them *before* applying so that it can further
|
|
2186
2186
|
// traverse itself in case it moves the node around
|
|
@@ -2403,10 +2403,10 @@ function genHoists(hoists, context) {
|
|
|
2403
2403
|
}
|
|
2404
2404
|
function isText$1(n) {
|
|
2405
2405
|
return (isString(n) ||
|
|
2406
|
-
n.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
2407
|
-
n.type === 2 /* TEXT */ ||
|
|
2408
|
-
n.type === 5 /* INTERPOLATION */ ||
|
|
2409
|
-
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 */);
|
|
2410
2410
|
}
|
|
2411
2411
|
function genNodeListAsArray(nodes, context) {
|
|
2412
2412
|
const multilines = nodes.length > 3 ||
|
|
@@ -2451,69 +2451,69 @@ function genNode(node, context) {
|
|
|
2451
2451
|
return;
|
|
2452
2452
|
}
|
|
2453
2453
|
switch (node.type) {
|
|
2454
|
-
case 1 /* ELEMENT */:
|
|
2455
|
-
case 9 /* IF */:
|
|
2456
|
-
case 11 /* FOR */:
|
|
2454
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2455
|
+
case 9 /* NodeTypes.IF */:
|
|
2456
|
+
case 11 /* NodeTypes.FOR */:
|
|
2457
2457
|
(process.env.NODE_ENV !== 'production') &&
|
|
2458
2458
|
assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
|
|
2459
2459
|
`Apply appropriate transforms first.`);
|
|
2460
2460
|
genNode(node.codegenNode, context);
|
|
2461
2461
|
break;
|
|
2462
|
-
case 2 /* TEXT */:
|
|
2462
|
+
case 2 /* NodeTypes.TEXT */:
|
|
2463
2463
|
genText(node, context);
|
|
2464
2464
|
break;
|
|
2465
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
2465
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
2466
2466
|
genExpression(node, context);
|
|
2467
2467
|
break;
|
|
2468
|
-
case 5 /* INTERPOLATION */:
|
|
2468
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2469
2469
|
genInterpolation(node, context);
|
|
2470
2470
|
break;
|
|
2471
|
-
case 12 /* TEXT_CALL */:
|
|
2471
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
2472
2472
|
genNode(node.codegenNode, context);
|
|
2473
2473
|
break;
|
|
2474
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
2474
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
2475
2475
|
genCompoundExpression(node, context);
|
|
2476
2476
|
break;
|
|
2477
|
-
case 3 /* COMMENT */:
|
|
2477
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2478
2478
|
genComment(node, context);
|
|
2479
2479
|
break;
|
|
2480
|
-
case 13 /* VNODE_CALL */:
|
|
2480
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
2481
2481
|
genVNodeCall(node, context);
|
|
2482
2482
|
break;
|
|
2483
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
2483
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
2484
2484
|
genCallExpression(node, context);
|
|
2485
2485
|
break;
|
|
2486
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
2486
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
2487
2487
|
genObjectExpression(node, context);
|
|
2488
2488
|
break;
|
|
2489
|
-
case 17 /* JS_ARRAY_EXPRESSION */:
|
|
2489
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
2490
2490
|
genArrayExpression(node, context);
|
|
2491
2491
|
break;
|
|
2492
|
-
case 18 /* JS_FUNCTION_EXPRESSION */:
|
|
2492
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
2493
2493
|
genFunctionExpression(node, context);
|
|
2494
2494
|
break;
|
|
2495
|
-
case 19 /* JS_CONDITIONAL_EXPRESSION */:
|
|
2495
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
2496
2496
|
genConditionalExpression(node, context);
|
|
2497
2497
|
break;
|
|
2498
|
-
case 20 /* JS_CACHE_EXPRESSION */:
|
|
2498
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
2499
2499
|
genCacheExpression(node, context);
|
|
2500
2500
|
break;
|
|
2501
|
-
case 21 /* JS_BLOCK_STATEMENT */:
|
|
2501
|
+
case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
|
|
2502
2502
|
genNodeList(node.body, context, true, false);
|
|
2503
2503
|
break;
|
|
2504
2504
|
// SSR only types
|
|
2505
|
-
case 22 /* JS_TEMPLATE_LITERAL */:
|
|
2505
|
+
case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
|
|
2506
2506
|
break;
|
|
2507
|
-
case 23 /* JS_IF_STATEMENT */:
|
|
2507
|
+
case 23 /* NodeTypes.JS_IF_STATEMENT */:
|
|
2508
2508
|
break;
|
|
2509
|
-
case 24 /* JS_ASSIGNMENT_EXPRESSION */:
|
|
2509
|
+
case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
|
|
2510
2510
|
break;
|
|
2511
|
-
case 25 /* JS_SEQUENCE_EXPRESSION */:
|
|
2511
|
+
case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
|
|
2512
2512
|
break;
|
|
2513
|
-
case 26 /* JS_RETURN_STATEMENT */:
|
|
2513
|
+
case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
|
|
2514
2514
|
break;
|
|
2515
2515
|
/* istanbul ignore next */
|
|
2516
|
-
case 10 /* IF_BRANCH */:
|
|
2516
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2517
2517
|
// noop
|
|
2518
2518
|
break;
|
|
2519
2519
|
default:
|
|
@@ -2553,7 +2553,7 @@ function genCompoundExpression(node, context) {
|
|
|
2553
2553
|
}
|
|
2554
2554
|
function genExpressionAsPropertyKey(node, context) {
|
|
2555
2555
|
const { push } = context;
|
|
2556
|
-
if (node.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
2556
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
2557
2557
|
push(`[`);
|
|
2558
2558
|
genCompoundExpression(node, context);
|
|
2559
2559
|
push(`]`);
|
|
@@ -2631,7 +2631,7 @@ function genObjectExpression(node, context) {
|
|
|
2631
2631
|
}
|
|
2632
2632
|
const multilines = properties.length > 1 ||
|
|
2633
2633
|
(((process.env.NODE_ENV !== 'production')) &&
|
|
2634
|
-
properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
|
|
2634
|
+
properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
|
|
2635
2635
|
push(multilines ? `{` : `{ `);
|
|
2636
2636
|
multilines && indent();
|
|
2637
2637
|
for (let i = 0; i < properties.length; i++) {
|
|
@@ -2700,7 +2700,7 @@ function genFunctionExpression(node, context) {
|
|
|
2700
2700
|
function genConditionalExpression(node, context) {
|
|
2701
2701
|
const { test, consequent, alternate, newline: needNewline } = node;
|
|
2702
2702
|
const { push, indent, deindent, newline } = context;
|
|
2703
|
-
if (test.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2703
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2704
2704
|
const needsParens = !isSimpleIdentifier(test.content);
|
|
2705
2705
|
needsParens && push(`(`);
|
|
2706
2706
|
genExpression(test, context);
|
|
@@ -2720,7 +2720,7 @@ function genConditionalExpression(node, context) {
|
|
|
2720
2720
|
needNewline && newline();
|
|
2721
2721
|
needNewline || push(` `);
|
|
2722
2722
|
push(`: `);
|
|
2723
|
-
const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
|
|
2723
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
2724
2724
|
if (!isNested) {
|
|
2725
2725
|
context.indentLevel++;
|
|
2726
2726
|
}
|
|
@@ -2884,32 +2884,32 @@ function validateBrowserExpression(node, context, asParams = false, asRawStateme
|
|
|
2884
2884
|
if (keywordMatch) {
|
|
2885
2885
|
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
|
2886
2886
|
}
|
|
2887
|
-
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
2887
|
+
context.onError(createCompilerError(44 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, message));
|
|
2888
2888
|
}
|
|
2889
2889
|
}
|
|
2890
2890
|
|
|
2891
2891
|
const transformExpression = (node, context) => {
|
|
2892
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
2892
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
2893
2893
|
node.content = processExpression(node.content, context);
|
|
2894
2894
|
}
|
|
2895
|
-
else if (node.type === 1 /* ELEMENT */) {
|
|
2895
|
+
else if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2896
2896
|
// handle directives on element
|
|
2897
2897
|
for (let i = 0; i < node.props.length; i++) {
|
|
2898
2898
|
const dir = node.props[i];
|
|
2899
2899
|
// do not process for v-on & v-for since they are special handled
|
|
2900
|
-
if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
|
|
2900
|
+
if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
|
|
2901
2901
|
const exp = dir.exp;
|
|
2902
2902
|
const arg = dir.arg;
|
|
2903
2903
|
// do not process exp if this is v-on:arg - we need special handling
|
|
2904
2904
|
// for wrapping inline statements.
|
|
2905
2905
|
if (exp &&
|
|
2906
|
-
exp.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
2906
|
+
exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
2907
2907
|
!(dir.name === 'on' && arg)) {
|
|
2908
2908
|
dir.exp = processExpression(exp, context,
|
|
2909
2909
|
// slot args must be processed as function params
|
|
2910
2910
|
dir.name === 'slot');
|
|
2911
2911
|
}
|
|
2912
|
-
if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
2912
|
+
if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
2913
2913
|
dir.arg = processExpression(arg, context);
|
|
2914
2914
|
}
|
|
2915
2915
|
}
|
|
@@ -2944,7 +2944,7 @@ const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (n
|
|
|
2944
2944
|
let key = 0;
|
|
2945
2945
|
while (i-- >= 0) {
|
|
2946
2946
|
const sibling = siblings[i];
|
|
2947
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
2947
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
2948
2948
|
key += sibling.branches.length;
|
|
2949
2949
|
}
|
|
2950
2950
|
}
|
|
@@ -2967,7 +2967,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2967
2967
|
if (dir.name !== 'else' &&
|
|
2968
2968
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
2969
2969
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
2970
|
-
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
2970
|
+
context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
2971
2971
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
2972
2972
|
}
|
|
2973
2973
|
if ((process.env.NODE_ENV !== 'production') && true && dir.exp) {
|
|
@@ -2976,7 +2976,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2976
2976
|
if (dir.name === 'if') {
|
|
2977
2977
|
const branch = createIfBranch(node, dir);
|
|
2978
2978
|
const ifNode = {
|
|
2979
|
-
type: 9 /* IF */,
|
|
2979
|
+
type: 9 /* NodeTypes.IF */,
|
|
2980
2980
|
loc: node.loc,
|
|
2981
2981
|
branches: [branch]
|
|
2982
2982
|
};
|
|
@@ -2992,22 +2992,22 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
2992
2992
|
let i = siblings.indexOf(node);
|
|
2993
2993
|
while (i-- >= -1) {
|
|
2994
2994
|
const sibling = siblings[i];
|
|
2995
|
-
if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* COMMENT */) {
|
|
2995
|
+
if ((process.env.NODE_ENV !== 'production') && sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
|
|
2996
2996
|
context.removeNode(sibling);
|
|
2997
2997
|
comments.unshift(sibling);
|
|
2998
2998
|
continue;
|
|
2999
2999
|
}
|
|
3000
3000
|
if (sibling &&
|
|
3001
|
-
sibling.type === 2 /* TEXT */ &&
|
|
3001
|
+
sibling.type === 2 /* NodeTypes.TEXT */ &&
|
|
3002
3002
|
!sibling.content.trim().length) {
|
|
3003
3003
|
context.removeNode(sibling);
|
|
3004
3004
|
continue;
|
|
3005
3005
|
}
|
|
3006
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3006
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
3007
3007
|
// Check if v-else was followed by v-else-if
|
|
3008
3008
|
if (dir.name === 'else-if' &&
|
|
3009
3009
|
sibling.branches[sibling.branches.length - 1].condition === undefined) {
|
|
3010
|
-
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));
|
|
3011
3011
|
}
|
|
3012
3012
|
// move the node to the if node's branches
|
|
3013
3013
|
context.removeNode();
|
|
@@ -3016,7 +3016,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3016
3016
|
comments.length &&
|
|
3017
3017
|
// #3619 ignore comments if the v-if is direct child of <transition>
|
|
3018
3018
|
!(context.parent &&
|
|
3019
|
-
context.parent.type === 1 /* ELEMENT */ &&
|
|
3019
|
+
context.parent.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3020
3020
|
isBuiltInType(context.parent.tag, 'transition'))) {
|
|
3021
3021
|
branch.children = [...comments, ...branch.children];
|
|
3022
3022
|
}
|
|
@@ -3026,7 +3026,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3026
3026
|
if (key) {
|
|
3027
3027
|
sibling.branches.forEach(({ userKey }) => {
|
|
3028
3028
|
if (isSameKey(userKey, key)) {
|
|
3029
|
-
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));
|
|
3030
3030
|
}
|
|
3031
3031
|
});
|
|
3032
3032
|
}
|
|
@@ -3044,16 +3044,16 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3044
3044
|
context.currentNode = null;
|
|
3045
3045
|
}
|
|
3046
3046
|
else {
|
|
3047
|
-
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));
|
|
3048
3048
|
}
|
|
3049
3049
|
break;
|
|
3050
3050
|
}
|
|
3051
3051
|
}
|
|
3052
3052
|
}
|
|
3053
3053
|
function createIfBranch(node, dir) {
|
|
3054
|
-
const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
|
|
3054
|
+
const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
|
|
3055
3055
|
return {
|
|
3056
|
-
type: 10 /* IF_BRANCH */,
|
|
3056
|
+
type: 10 /* NodeTypes.IF_BRANCH */,
|
|
3057
3057
|
loc: node.loc,
|
|
3058
3058
|
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
3059
3059
|
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
|
|
@@ -3077,27 +3077,27 @@ function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
|
3077
3077
|
}
|
|
3078
3078
|
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
3079
3079
|
const { helper } = context;
|
|
3080
|
-
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
|
|
3080
|
+
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
|
|
3081
3081
|
const { children } = branch;
|
|
3082
3082
|
const firstChild = children[0];
|
|
3083
|
-
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
|
|
3083
|
+
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
|
|
3084
3084
|
if (needFragmentWrapper) {
|
|
3085
|
-
if (children.length === 1 && firstChild.type === 11 /* FOR */) {
|
|
3085
|
+
if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
|
|
3086
3086
|
// optimize away nested fragments when child is a ForNode
|
|
3087
3087
|
const vnodeCall = firstChild.codegenNode;
|
|
3088
3088
|
injectProp(vnodeCall, keyProperty, context);
|
|
3089
3089
|
return vnodeCall;
|
|
3090
3090
|
}
|
|
3091
3091
|
else {
|
|
3092
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
3093
|
-
let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
3092
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
3093
|
+
let patchFlagText = PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
3094
3094
|
// check if the fragment actually contains a single valid child with
|
|
3095
3095
|
// the rest being comments
|
|
3096
3096
|
if ((process.env.NODE_ENV !== 'production') &&
|
|
3097
3097
|
!branch.isTemplateIf &&
|
|
3098
|
-
children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
|
|
3099
|
-
patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
|
|
3100
|
-
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 */]}`;
|
|
3101
3101
|
}
|
|
3102
3102
|
return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + ((process.env.NODE_ENV !== 'production') ? ` /* ${patchFlagText} */` : ``), undefined, undefined, true, false, false /* isComponent */, branch.loc);
|
|
3103
3103
|
}
|
|
@@ -3106,7 +3106,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
3106
3106
|
const ret = firstChild.codegenNode;
|
|
3107
3107
|
const vnodeCall = getMemoedVNodeCall(ret);
|
|
3108
3108
|
// Change createVNode to createBlock.
|
|
3109
|
-
if (vnodeCall.type === 13 /* VNODE_CALL */) {
|
|
3109
|
+
if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
3110
3110
|
makeBlock(vnodeCall, context);
|
|
3111
3111
|
}
|
|
3112
3112
|
// inject branch key
|
|
@@ -3118,7 +3118,7 @@ function isSameKey(a, b) {
|
|
|
3118
3118
|
if (!a || a.type !== b.type) {
|
|
3119
3119
|
return false;
|
|
3120
3120
|
}
|
|
3121
|
-
if (a.type === 6 /* ATTRIBUTE */) {
|
|
3121
|
+
if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3122
3122
|
if (a.value.content !== b.value.content) {
|
|
3123
3123
|
return false;
|
|
3124
3124
|
}
|
|
@@ -3130,7 +3130,7 @@ function isSameKey(a, b) {
|
|
|
3130
3130
|
if (exp.type !== branchExp.type) {
|
|
3131
3131
|
return false;
|
|
3132
3132
|
}
|
|
3133
|
-
if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3133
|
+
if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3134
3134
|
exp.isStatic !== branchExp.isStatic ||
|
|
3135
3135
|
exp.content !== branchExp.content) {
|
|
3136
3136
|
return false;
|
|
@@ -3140,15 +3140,15 @@ function isSameKey(a, b) {
|
|
|
3140
3140
|
}
|
|
3141
3141
|
function getParentCondition(node) {
|
|
3142
3142
|
while (true) {
|
|
3143
|
-
if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3144
|
-
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 */) {
|
|
3145
3145
|
node = node.alternate;
|
|
3146
3146
|
}
|
|
3147
3147
|
else {
|
|
3148
3148
|
return node;
|
|
3149
3149
|
}
|
|
3150
3150
|
}
|
|
3151
|
-
else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
|
|
3151
|
+
else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
3152
3152
|
node = node.value;
|
|
3153
3153
|
}
|
|
3154
3154
|
}
|
|
@@ -3166,17 +3166,17 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3166
3166
|
const memo = findDir(node, 'memo');
|
|
3167
3167
|
const keyProp = findProp(node, `key`);
|
|
3168
3168
|
const keyExp = keyProp &&
|
|
3169
|
-
(keyProp.type === 6 /* ATTRIBUTE */
|
|
3169
|
+
(keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3170
3170
|
? createSimpleExpression(keyProp.value.content, true)
|
|
3171
3171
|
: keyProp.exp);
|
|
3172
3172
|
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
|
3173
|
-
const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3174
|
-
forNode.source.constType > 0 /* NOT_CONSTANT */;
|
|
3173
|
+
const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3174
|
+
forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
3175
3175
|
const fragmentFlag = isStableFragment
|
|
3176
|
-
? 64 /* STABLE_FRAGMENT */
|
|
3176
|
+
? 64 /* PatchFlags.STABLE_FRAGMENT */
|
|
3177
3177
|
: keyProp
|
|
3178
|
-
? 128 /* KEYED_FRAGMENT */
|
|
3179
|
-
: 256 /* UNKEYED_FRAGMENT */;
|
|
3178
|
+
? 128 /* PatchFlags.KEYED_FRAGMENT */
|
|
3179
|
+
: 256 /* PatchFlags.UNKEYED_FRAGMENT */;
|
|
3180
3180
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
|
|
3181
3181
|
((process.env.NODE_ENV !== 'production') ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
|
|
3182
3182
|
return () => {
|
|
@@ -3186,16 +3186,16 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3186
3186
|
// check <template v-for> key placement
|
|
3187
3187
|
if (((process.env.NODE_ENV !== 'production') || !true) && isTemplate) {
|
|
3188
3188
|
node.children.some(c => {
|
|
3189
|
-
if (c.type === 1 /* ELEMENT */) {
|
|
3189
|
+
if (c.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3190
3190
|
const key = findProp(c, 'key');
|
|
3191
3191
|
if (key) {
|
|
3192
|
-
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));
|
|
3193
3193
|
return true;
|
|
3194
3194
|
}
|
|
3195
3195
|
}
|
|
3196
3196
|
});
|
|
3197
3197
|
}
|
|
3198
|
-
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
|
|
3198
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
|
|
3199
3199
|
const slotOutlet = isSlotOutlet(node)
|
|
3200
3200
|
? node
|
|
3201
3201
|
: isTemplate &&
|
|
@@ -3216,9 +3216,9 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3216
3216
|
else if (needFragmentWrapper) {
|
|
3217
3217
|
// <template v-for="..."> with text or multi-elements
|
|
3218
3218
|
// should generate a fragment block for each loop
|
|
3219
|
-
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 */ +
|
|
3220
3220
|
((process.env.NODE_ENV !== 'production')
|
|
3221
|
-
? ` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
|
|
3221
|
+
? ` /* ${PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`
|
|
3222
3222
|
: ``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
3223
3223
|
}
|
|
3224
3224
|
else {
|
|
@@ -3275,7 +3275,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3275
3275
|
// target-agnostic transform used for both Client and SSR
|
|
3276
3276
|
function processFor(node, dir, context, processCodegen) {
|
|
3277
3277
|
if (!dir.exp) {
|
|
3278
|
-
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3278
|
+
context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3279
3279
|
return;
|
|
3280
3280
|
}
|
|
3281
3281
|
const parseResult = parseForExpression(
|
|
@@ -3283,13 +3283,13 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3283
3283
|
// before expression transform.
|
|
3284
3284
|
dir.exp, context);
|
|
3285
3285
|
if (!parseResult) {
|
|
3286
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3286
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3287
3287
|
return;
|
|
3288
3288
|
}
|
|
3289
3289
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
3290
3290
|
const { source, value, key, index } = parseResult;
|
|
3291
3291
|
const forNode = {
|
|
3292
|
-
type: 11 /* FOR */,
|
|
3292
|
+
type: 11 /* NodeTypes.FOR */,
|
|
3293
3293
|
loc: dir.loc,
|
|
3294
3294
|
source,
|
|
3295
3295
|
valueAlias: value,
|
|
@@ -3389,9 +3389,9 @@ const defaultFallback = createSimpleExpression(`undefined`, false);
|
|
|
3389
3389
|
// Note the exit callback is executed before buildSlots() on the same node,
|
|
3390
3390
|
// so only nested slots see positive numbers.
|
|
3391
3391
|
const trackSlotScopes = (node, context) => {
|
|
3392
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
3393
|
-
(node.tagType === 1 /* COMPONENT */ ||
|
|
3394
|
-
node.tagType === 3 /* TEMPLATE */)) {
|
|
3392
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3393
|
+
(node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
3394
|
+
node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
|
|
3395
3395
|
// We are only checking non-empty v-slot here
|
|
3396
3396
|
// since we only care about slots that introduce scope variables.
|
|
3397
3397
|
const vSlot = findDir(node, 'slot');
|
|
@@ -3453,20 +3453,21 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3453
3453
|
let hasNamedDefaultSlot = false;
|
|
3454
3454
|
const implicitDefaultChildren = [];
|
|
3455
3455
|
const seenSlotNames = new Set();
|
|
3456
|
+
let conditionalBranchIndex = 0;
|
|
3456
3457
|
for (let i = 0; i < children.length; i++) {
|
|
3457
3458
|
const slotElement = children[i];
|
|
3458
3459
|
let slotDir;
|
|
3459
3460
|
if (!isTemplateNode(slotElement) ||
|
|
3460
3461
|
!(slotDir = findDir(slotElement, 'slot', true))) {
|
|
3461
3462
|
// not a <template v-slot>, skip.
|
|
3462
|
-
if (slotElement.type !== 3 /* COMMENT */) {
|
|
3463
|
+
if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3463
3464
|
implicitDefaultChildren.push(slotElement);
|
|
3464
3465
|
}
|
|
3465
3466
|
continue;
|
|
3466
3467
|
}
|
|
3467
3468
|
if (onComponentSlot) {
|
|
3468
3469
|
// already has on-component slot - this is incorrect usage.
|
|
3469
|
-
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));
|
|
3470
3471
|
break;
|
|
3471
3472
|
}
|
|
3472
3473
|
hasTemplateSlots = true;
|
|
@@ -3487,7 +3488,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3487
3488
|
let vFor;
|
|
3488
3489
|
if ((vIf = findDir(slotElement, 'if'))) {
|
|
3489
3490
|
hasDynamicSlots = true;
|
|
3490
|
-
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
|
|
3491
|
+
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
|
|
3491
3492
|
}
|
|
3492
3493
|
else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
|
|
3493
3494
|
// find adjacent v-if
|
|
@@ -3495,7 +3496,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3495
3496
|
let prev;
|
|
3496
3497
|
while (j--) {
|
|
3497
3498
|
prev = children[j];
|
|
3498
|
-
if (prev.type !== 3 /* COMMENT */) {
|
|
3499
|
+
if (prev.type !== 3 /* NodeTypes.COMMENT */) {
|
|
3499
3500
|
break;
|
|
3500
3501
|
}
|
|
3501
3502
|
}
|
|
@@ -3505,15 +3506,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3505
3506
|
i--;
|
|
3506
3507
|
// attach this slot to previous conditional
|
|
3507
3508
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
3508
|
-
while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3509
|
+
while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3509
3510
|
conditional = conditional.alternate;
|
|
3510
3511
|
}
|
|
3511
3512
|
conditional.alternate = vElse.exp
|
|
3512
|
-
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
|
|
3513
|
-
: buildDynamicSlot(slotName, slotFunction);
|
|
3513
|
+
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
|
|
3514
|
+
: buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
|
3514
3515
|
}
|
|
3515
3516
|
else {
|
|
3516
|
-
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));
|
|
3517
3518
|
}
|
|
3518
3519
|
}
|
|
3519
3520
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -3529,14 +3530,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3529
3530
|
]));
|
|
3530
3531
|
}
|
|
3531
3532
|
else {
|
|
3532
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3533
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3533
3534
|
}
|
|
3534
3535
|
}
|
|
3535
3536
|
else {
|
|
3536
3537
|
// check duplicate static names
|
|
3537
3538
|
if (staticSlotName) {
|
|
3538
3539
|
if (seenSlotNames.has(staticSlotName)) {
|
|
3539
|
-
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3540
|
+
context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3540
3541
|
continue;
|
|
3541
3542
|
}
|
|
3542
3543
|
seenSlotNames.add(staticSlotName);
|
|
@@ -3566,7 +3567,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3566
3567
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
3567
3568
|
// implicit default slot (mixed with named slots)
|
|
3568
3569
|
if (hasNamedDefaultSlot) {
|
|
3569
|
-
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));
|
|
3570
3571
|
}
|
|
3571
3572
|
else {
|
|
3572
3573
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -3574,10 +3575,10 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3574
3575
|
}
|
|
3575
3576
|
}
|
|
3576
3577
|
const slotFlag = hasDynamicSlots
|
|
3577
|
-
? 2 /* DYNAMIC */
|
|
3578
|
+
? 2 /* SlotFlags.DYNAMIC */
|
|
3578
3579
|
: hasForwardedSlots(node.children)
|
|
3579
|
-
? 3 /* FORWARDED */
|
|
3580
|
-
: 1 /* STABLE */;
|
|
3580
|
+
? 3 /* SlotFlags.FORWARDED */
|
|
3581
|
+
: 1 /* SlotFlags.STABLE */;
|
|
3581
3582
|
let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
|
|
3582
3583
|
// 2 = compiled but dynamic = can skip normalization, but must run diff
|
|
3583
3584
|
// 1 = compiled and static = can skip normalization AND diff as optimized
|
|
@@ -3593,28 +3594,32 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3593
3594
|
hasDynamicSlots
|
|
3594
3595
|
};
|
|
3595
3596
|
}
|
|
3596
|
-
function buildDynamicSlot(name, fn) {
|
|
3597
|
-
|
|
3597
|
+
function buildDynamicSlot(name, fn, index) {
|
|
3598
|
+
const props = [
|
|
3598
3599
|
createObjectProperty(`name`, name),
|
|
3599
3600
|
createObjectProperty(`fn`, fn)
|
|
3600
|
-
]
|
|
3601
|
+
];
|
|
3602
|
+
if (index != null) {
|
|
3603
|
+
props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
|
|
3604
|
+
}
|
|
3605
|
+
return createObjectExpression(props);
|
|
3601
3606
|
}
|
|
3602
3607
|
function hasForwardedSlots(children) {
|
|
3603
3608
|
for (let i = 0; i < children.length; i++) {
|
|
3604
3609
|
const child = children[i];
|
|
3605
3610
|
switch (child.type) {
|
|
3606
|
-
case 1 /* ELEMENT */:
|
|
3607
|
-
if (child.tagType === 2 /* SLOT */ ||
|
|
3611
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
3612
|
+
if (child.tagType === 2 /* ElementTypes.SLOT */ ||
|
|
3608
3613
|
hasForwardedSlots(child.children)) {
|
|
3609
3614
|
return true;
|
|
3610
3615
|
}
|
|
3611
3616
|
break;
|
|
3612
|
-
case 9 /* IF */:
|
|
3617
|
+
case 9 /* NodeTypes.IF */:
|
|
3613
3618
|
if (hasForwardedSlots(child.branches))
|
|
3614
3619
|
return true;
|
|
3615
3620
|
break;
|
|
3616
|
-
case 10 /* IF_BRANCH */:
|
|
3617
|
-
case 11 /* FOR */:
|
|
3621
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
3622
|
+
case 11 /* NodeTypes.FOR */:
|
|
3618
3623
|
if (hasForwardedSlots(child.children))
|
|
3619
3624
|
return true;
|
|
3620
3625
|
break;
|
|
@@ -3623,9 +3628,9 @@ function hasForwardedSlots(children) {
|
|
|
3623
3628
|
return false;
|
|
3624
3629
|
}
|
|
3625
3630
|
function isNonWhitespaceContent(node) {
|
|
3626
|
-
if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
|
|
3631
|
+
if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
|
|
3627
3632
|
return true;
|
|
3628
|
-
return node.type === 2 /* TEXT */
|
|
3633
|
+
return node.type === 2 /* NodeTypes.TEXT */
|
|
3629
3634
|
? !!node.content.trim()
|
|
3630
3635
|
: isNonWhitespaceContent(node.content);
|
|
3631
3636
|
}
|
|
@@ -3639,13 +3644,13 @@ const transformElement = (node, context) => {
|
|
|
3639
3644
|
// processed and merged.
|
|
3640
3645
|
return function postTransformElement() {
|
|
3641
3646
|
node = context.currentNode;
|
|
3642
|
-
if (!(node.type === 1 /* ELEMENT */ &&
|
|
3643
|
-
(node.tagType === 0 /* ELEMENT */ ||
|
|
3644
|
-
node.tagType === 1 /* COMPONENT */))) {
|
|
3647
|
+
if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3648
|
+
(node.tagType === 0 /* ElementTypes.ELEMENT */ ||
|
|
3649
|
+
node.tagType === 1 /* ElementTypes.COMPONENT */))) {
|
|
3645
3650
|
return;
|
|
3646
3651
|
}
|
|
3647
3652
|
const { tag, props } = node;
|
|
3648
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
3653
|
+
const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
3649
3654
|
// The goal of the transform is to create a codegenNode implementing the
|
|
3650
3655
|
// VNodeCall interface.
|
|
3651
3656
|
let vnodeTag = isComponent
|
|
@@ -3696,9 +3701,9 @@ const transformElement = (node, context) => {
|
|
|
3696
3701
|
// collected by a parent block.
|
|
3697
3702
|
shouldUseBlock = true;
|
|
3698
3703
|
// 2. Force keep-alive to always be updated, since it uses raw children.
|
|
3699
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3704
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3700
3705
|
if ((process.env.NODE_ENV !== 'production') && node.children.length > 1) {
|
|
3701
|
-
context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3706
|
+
context.onError(createCompilerError(45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
3702
3707
|
start: node.children[0].loc.start,
|
|
3703
3708
|
end: node.children[node.children.length - 1].loc.end,
|
|
3704
3709
|
source: ''
|
|
@@ -3714,22 +3719,22 @@ const transformElement = (node, context) => {
|
|
|
3714
3719
|
const { slots, hasDynamicSlots } = buildSlots(node, context);
|
|
3715
3720
|
vnodeChildren = slots;
|
|
3716
3721
|
if (hasDynamicSlots) {
|
|
3717
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
3722
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
3718
3723
|
}
|
|
3719
3724
|
}
|
|
3720
3725
|
else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
|
3721
3726
|
const child = node.children[0];
|
|
3722
3727
|
const type = child.type;
|
|
3723
3728
|
// check for dynamic text children
|
|
3724
|
-
const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
|
|
3725
|
-
type === 8 /* COMPOUND_EXPRESSION */;
|
|
3729
|
+
const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
3730
|
+
type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
|
|
3726
3731
|
if (hasDynamicTextChild &&
|
|
3727
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
3728
|
-
patchFlag |= 1 /* TEXT */;
|
|
3732
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
3733
|
+
patchFlag |= 1 /* PatchFlags.TEXT */;
|
|
3729
3734
|
}
|
|
3730
3735
|
// pass directly if the only child is a text node
|
|
3731
3736
|
// (plain / interpolation / expression)
|
|
3732
|
-
if (hasDynamicTextChild || type === 2 /* TEXT */) {
|
|
3737
|
+
if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
|
|
3733
3738
|
vnodeChildren = child;
|
|
3734
3739
|
}
|
|
3735
3740
|
else {
|
|
@@ -3774,8 +3779,8 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3774
3779
|
const isProp = findProp(node, 'is');
|
|
3775
3780
|
if (isProp) {
|
|
3776
3781
|
if (isExplicitDynamic ||
|
|
3777
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))) {
|
|
3778
|
-
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 */
|
|
3779
3784
|
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
|
3780
3785
|
: isProp.exp;
|
|
3781
3786
|
if (exp) {
|
|
@@ -3784,7 +3789,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
3784
3789
|
]);
|
|
3785
3790
|
}
|
|
3786
3791
|
}
|
|
3787
|
-
else if (isProp.type === 6 /* ATTRIBUTE */ &&
|
|
3792
|
+
else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
3788
3793
|
isProp.value.content.startsWith('vue:')) {
|
|
3789
3794
|
// <button is="vue:xxx">
|
|
3790
3795
|
// if not <component>, only is value that starts with "vue:" will be
|
|
@@ -3848,9 +3853,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3848
3853
|
if (isEventHandler && isReservedProp(name)) {
|
|
3849
3854
|
hasVnodeHook = true;
|
|
3850
3855
|
}
|
|
3851
|
-
if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
|
|
3852
|
-
((value.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
3853
|
-
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 */) &&
|
|
3854
3859
|
getConstantType(value, context) > 0)) {
|
|
3855
3860
|
// skip if the prop is a cached handler or has constant value
|
|
3856
3861
|
return;
|
|
@@ -3881,7 +3886,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3881
3886
|
for (let i = 0; i < props.length; i++) {
|
|
3882
3887
|
// static attribute
|
|
3883
3888
|
const prop = props[i];
|
|
3884
|
-
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
3889
|
+
if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3885
3890
|
const { loc, name, value } = prop;
|
|
3886
3891
|
let isStatic = true;
|
|
3887
3892
|
if (name === 'ref') {
|
|
@@ -3894,7 +3899,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3894
3899
|
if (name === 'is' &&
|
|
3895
3900
|
(isComponentTag(tag) ||
|
|
3896
3901
|
(value && value.content.startsWith('vue:')) ||
|
|
3897
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
3902
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
3898
3903
|
continue;
|
|
3899
3904
|
}
|
|
3900
3905
|
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
|
|
@@ -3907,7 +3912,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3907
3912
|
// skip v-slot - it is handled by its dedicated transform.
|
|
3908
3913
|
if (name === 'slot') {
|
|
3909
3914
|
if (!isComponent) {
|
|
3910
|
-
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
3915
|
+
context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
|
|
3911
3916
|
}
|
|
3912
3917
|
continue;
|
|
3913
3918
|
}
|
|
@@ -3920,7 +3925,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3920
3925
|
(isVBind &&
|
|
3921
3926
|
isStaticArgOf(arg, 'is') &&
|
|
3922
3927
|
(isComponentTag(tag) ||
|
|
3923
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
3928
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
3924
3929
|
continue;
|
|
3925
3930
|
}
|
|
3926
3931
|
// skip v-on in SSR compilation
|
|
@@ -3951,9 +3956,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3951
3956
|
// 2.x v-bind object order compat
|
|
3952
3957
|
if ((process.env.NODE_ENV !== 'production')) {
|
|
3953
3958
|
const hasOverridableKeys = mergeArgs.some(arg => {
|
|
3954
|
-
if (arg.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
3959
|
+
if (arg.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
3955
3960
|
return arg.properties.some(({ key }) => {
|
|
3956
|
-
if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3961
|
+
if (key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3957
3962
|
!key.isStatic) {
|
|
3958
3963
|
return true;
|
|
3959
3964
|
}
|
|
@@ -3968,10 +3973,10 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3968
3973
|
}
|
|
3969
3974
|
});
|
|
3970
3975
|
if (hasOverridableKeys) {
|
|
3971
|
-
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);
|
|
3972
3977
|
}
|
|
3973
3978
|
}
|
|
3974
|
-
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)) {
|
|
3975
3980
|
mergeArgs.unshift(exp);
|
|
3976
3981
|
continue;
|
|
3977
3982
|
}
|
|
@@ -3981,17 +3986,17 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
3981
3986
|
else {
|
|
3982
3987
|
// v-on="obj" -> toHandlers(obj)
|
|
3983
3988
|
mergeArgs.push({
|
|
3984
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
3989
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
3985
3990
|
loc,
|
|
3986
3991
|
callee: context.helper(TO_HANDLERS),
|
|
3987
|
-
arguments: [exp]
|
|
3992
|
+
arguments: isComponent ? [exp] : [exp, `true`]
|
|
3988
3993
|
});
|
|
3989
3994
|
}
|
|
3990
3995
|
}
|
|
3991
3996
|
else {
|
|
3992
3997
|
context.onError(createCompilerError(isVBind
|
|
3993
|
-
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
3994
|
-
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
3998
|
+
? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
|
|
3999
|
+
: 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
3995
4000
|
}
|
|
3996
4001
|
continue;
|
|
3997
4002
|
}
|
|
@@ -4038,31 +4043,31 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4038
4043
|
}
|
|
4039
4044
|
// patchFlag analysis
|
|
4040
4045
|
if (hasDynamicKeys) {
|
|
4041
|
-
patchFlag |= 16 /* FULL_PROPS */;
|
|
4046
|
+
patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
|
|
4042
4047
|
}
|
|
4043
4048
|
else {
|
|
4044
4049
|
if (hasClassBinding && !isComponent) {
|
|
4045
|
-
patchFlag |= 2 /* CLASS */;
|
|
4050
|
+
patchFlag |= 2 /* PatchFlags.CLASS */;
|
|
4046
4051
|
}
|
|
4047
4052
|
if (hasStyleBinding && !isComponent) {
|
|
4048
|
-
patchFlag |= 4 /* STYLE */;
|
|
4053
|
+
patchFlag |= 4 /* PatchFlags.STYLE */;
|
|
4049
4054
|
}
|
|
4050
4055
|
if (dynamicPropNames.length) {
|
|
4051
|
-
patchFlag |= 8 /* PROPS */;
|
|
4056
|
+
patchFlag |= 8 /* PatchFlags.PROPS */;
|
|
4052
4057
|
}
|
|
4053
4058
|
if (hasHydrationEventBinding) {
|
|
4054
|
-
patchFlag |= 32 /* HYDRATE_EVENTS */;
|
|
4059
|
+
patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
|
|
4055
4060
|
}
|
|
4056
4061
|
}
|
|
4057
4062
|
if (!shouldUseBlock &&
|
|
4058
|
-
(patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
|
|
4063
|
+
(patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
|
|
4059
4064
|
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
|
4060
|
-
patchFlag |= 512 /* NEED_PATCH */;
|
|
4065
|
+
patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
|
|
4061
4066
|
}
|
|
4062
4067
|
// pre-normalize props, SSR is skipped for now
|
|
4063
4068
|
if (!context.inSSR && propsExpression) {
|
|
4064
4069
|
switch (propsExpression.type) {
|
|
4065
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
4070
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
4066
4071
|
// means that there is no v-bind,
|
|
4067
4072
|
// but still need to deal with dynamic key binding
|
|
4068
4073
|
let classKeyIndex = -1;
|
|
@@ -4093,11 +4098,11 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4093
4098
|
// the static style is compiled into an object,
|
|
4094
4099
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4095
4100
|
(hasStyleBinding ||
|
|
4096
|
-
(styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
4101
|
+
(styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
4097
4102
|
styleProp.value.content.trim()[0] === `[`) ||
|
|
4098
4103
|
// v-bind:style and style both exist,
|
|
4099
4104
|
// v-bind:style with static literal object
|
|
4100
|
-
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4105
|
+
styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
|
|
4101
4106
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4102
4107
|
}
|
|
4103
4108
|
}
|
|
@@ -4106,7 +4111,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4106
4111
|
propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
|
|
4107
4112
|
}
|
|
4108
4113
|
break;
|
|
4109
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
4114
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
4110
4115
|
// mergeProps call, do nothing
|
|
4111
4116
|
break;
|
|
4112
4117
|
default:
|
|
@@ -4139,7 +4144,7 @@ function dedupeProperties(properties) {
|
|
|
4139
4144
|
for (let i = 0; i < properties.length; i++) {
|
|
4140
4145
|
const prop = properties[i];
|
|
4141
4146
|
// dynamic keys are always allowed
|
|
4142
|
-
if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4147
|
+
if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4143
4148
|
deduped.push(prop);
|
|
4144
4149
|
continue;
|
|
4145
4150
|
}
|
|
@@ -4159,7 +4164,7 @@ function dedupeProperties(properties) {
|
|
|
4159
4164
|
return deduped;
|
|
4160
4165
|
}
|
|
4161
4166
|
function mergeAsArray(existing, incoming) {
|
|
4162
|
-
if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
|
|
4167
|
+
if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
|
|
4163
4168
|
existing.value.elements.push(incoming.value);
|
|
4164
4169
|
}
|
|
4165
4170
|
else {
|
|
@@ -4267,7 +4272,7 @@ function processSlotOutlet(node, context) {
|
|
|
4267
4272
|
const nonNameProps = [];
|
|
4268
4273
|
for (let i = 0; i < node.props.length; i++) {
|
|
4269
4274
|
const p = node.props[i];
|
|
4270
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
4275
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4271
4276
|
if (p.value) {
|
|
4272
4277
|
if (p.name === 'name') {
|
|
4273
4278
|
slotName = JSON.stringify(p.value.content);
|
|
@@ -4295,7 +4300,7 @@ function processSlotOutlet(node, context) {
|
|
|
4295
4300
|
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
4296
4301
|
slotProps = props;
|
|
4297
4302
|
if (directives.length) {
|
|
4298
|
-
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));
|
|
4299
4304
|
}
|
|
4300
4305
|
}
|
|
4301
4306
|
return {
|
|
@@ -4308,18 +4313,26 @@ const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?functio
|
|
|
4308
4313
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4309
4314
|
const { loc, modifiers, arg } = dir;
|
|
4310
4315
|
if (!dir.exp && !modifiers.length) {
|
|
4311
|
-
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4316
|
+
context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4312
4317
|
}
|
|
4313
4318
|
let eventName;
|
|
4314
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4319
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4315
4320
|
if (arg.isStatic) {
|
|
4316
4321
|
let rawName = arg.content;
|
|
4317
4322
|
// TODO deprecate @vnodeXXX usage
|
|
4318
4323
|
if (rawName.startsWith('vue:')) {
|
|
4319
4324
|
rawName = `vnode-${rawName.slice(4)}`;
|
|
4320
4325
|
}
|
|
4321
|
-
|
|
4322
|
-
|
|
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);
|
|
4323
4336
|
}
|
|
4324
4337
|
else {
|
|
4325
4338
|
// #2388
|
|
@@ -4386,7 +4399,7 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
4386
4399
|
const transformBind = (dir, _node, context) => {
|
|
4387
4400
|
const { exp, modifiers, loc } = dir;
|
|
4388
4401
|
const arg = dir.arg;
|
|
4389
|
-
if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
|
|
4402
|
+
if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4390
4403
|
arg.children.unshift(`(`);
|
|
4391
4404
|
arg.children.push(`) || ""`);
|
|
4392
4405
|
}
|
|
@@ -4395,7 +4408,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4395
4408
|
}
|
|
4396
4409
|
// .sync is replaced by v-model:arg
|
|
4397
4410
|
if (modifiers.includes('camel')) {
|
|
4398
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4411
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4399
4412
|
if (arg.isStatic) {
|
|
4400
4413
|
arg.content = camelize$1(arg.content);
|
|
4401
4414
|
}
|
|
@@ -4417,8 +4430,8 @@ const transformBind = (dir, _node, context) => {
|
|
|
4417
4430
|
}
|
|
4418
4431
|
}
|
|
4419
4432
|
if (!exp ||
|
|
4420
|
-
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4421
|
-
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));
|
|
4422
4435
|
return {
|
|
4423
4436
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
4424
4437
|
};
|
|
@@ -4428,7 +4441,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4428
4441
|
};
|
|
4429
4442
|
};
|
|
4430
4443
|
const injectPrefix = (arg, prefix) => {
|
|
4431
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4444
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4432
4445
|
if (arg.isStatic) {
|
|
4433
4446
|
arg.content = prefix + arg.content;
|
|
4434
4447
|
}
|
|
@@ -4445,10 +4458,10 @@ const injectPrefix = (arg, prefix) => {
|
|
|
4445
4458
|
// Merge adjacent text nodes and expressions into a single expression
|
|
4446
4459
|
// e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
|
|
4447
4460
|
const transformText = (node, context) => {
|
|
4448
|
-
if (node.type === 0 /* ROOT */ ||
|
|
4449
|
-
node.type === 1 /* ELEMENT */ ||
|
|
4450
|
-
node.type === 11 /* FOR */ ||
|
|
4451
|
-
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 */) {
|
|
4452
4465
|
// perform the transform on node exit so that all expressions have already
|
|
4453
4466
|
// been processed.
|
|
4454
4467
|
return () => {
|
|
@@ -4483,15 +4496,15 @@ const transformText = (node, context) => {
|
|
|
4483
4496
|
// setting textContent of the element.
|
|
4484
4497
|
// for component root it's always normalized anyway.
|
|
4485
4498
|
(children.length === 1 &&
|
|
4486
|
-
(node.type === 0 /* ROOT */ ||
|
|
4487
|
-
(node.type === 1 /* ELEMENT */ &&
|
|
4488
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
4499
|
+
(node.type === 0 /* NodeTypes.ROOT */ ||
|
|
4500
|
+
(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
4501
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
4489
4502
|
// #3756
|
|
4490
4503
|
// custom directives can potentially add DOM elements arbitrarily,
|
|
4491
4504
|
// we need to avoid setting textContent of the element at runtime
|
|
4492
4505
|
// to avoid accidentally overwriting the DOM elements added
|
|
4493
4506
|
// by the user through custom directives.
|
|
4494
|
-
!node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
|
|
4507
|
+
!node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4495
4508
|
!context.directiveTransforms[p.name]) &&
|
|
4496
4509
|
// in compat mode, <template> tags with no special directives
|
|
4497
4510
|
// will be rendered as a fragment so its children must be
|
|
@@ -4503,21 +4516,21 @@ const transformText = (node, context) => {
|
|
|
4503
4516
|
// runtime normalization.
|
|
4504
4517
|
for (let i = 0; i < children.length; i++) {
|
|
4505
4518
|
const child = children[i];
|
|
4506
|
-
if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4519
|
+
if (isText(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4507
4520
|
const callArgs = [];
|
|
4508
4521
|
// createTextVNode defaults to single whitespace, so if it is a
|
|
4509
4522
|
// single space the code could be an empty call to save bytes.
|
|
4510
|
-
if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
|
|
4523
|
+
if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
|
|
4511
4524
|
callArgs.push(child);
|
|
4512
4525
|
}
|
|
4513
4526
|
// mark dynamic text with flag so it gets patched inside a block
|
|
4514
4527
|
if (!context.ssr &&
|
|
4515
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
4516
|
-
callArgs.push(1 /* TEXT */ +
|
|
4517
|
-
((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 */]} */` : ``));
|
|
4518
4531
|
}
|
|
4519
4532
|
children[i] = {
|
|
4520
|
-
type: 12 /* TEXT_CALL */,
|
|
4533
|
+
type: 12 /* NodeTypes.TEXT_CALL */,
|
|
4521
4534
|
content: child,
|
|
4522
4535
|
loc: child.loc,
|
|
4523
4536
|
codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
|
|
@@ -4530,7 +4543,7 @@ const transformText = (node, context) => {
|
|
|
4530
4543
|
|
|
4531
4544
|
const seen = new WeakSet();
|
|
4532
4545
|
const transformOnce = (node, context) => {
|
|
4533
|
-
if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
|
|
4546
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
|
|
4534
4547
|
if (seen.has(node) || context.inVOnce) {
|
|
4535
4548
|
return;
|
|
4536
4549
|
}
|
|
@@ -4550,18 +4563,18 @@ const transformOnce = (node, context) => {
|
|
|
4550
4563
|
const transformModel = (dir, node, context) => {
|
|
4551
4564
|
const { exp, arg } = dir;
|
|
4552
4565
|
if (!exp) {
|
|
4553
|
-
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4566
|
+
context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
4554
4567
|
return createTransformProps();
|
|
4555
4568
|
}
|
|
4556
4569
|
const rawExp = exp.loc.source;
|
|
4557
|
-
const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4570
|
+
const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
4558
4571
|
// im SFC <script setup> inline mode, the exp may have been transformed into
|
|
4559
4572
|
// _unref(exp)
|
|
4560
4573
|
context.bindingMetadata[rawExp];
|
|
4561
|
-
const maybeRef = !true /* SETUP_CONST */;
|
|
4574
|
+
const maybeRef = !true /* BindingTypes.SETUP_CONST */;
|
|
4562
4575
|
if (!expString.trim() ||
|
|
4563
4576
|
(!isMemberExpression(expString) && !maybeRef)) {
|
|
4564
|
-
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4577
|
+
context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
4565
4578
|
return createTransformProps();
|
|
4566
4579
|
}
|
|
4567
4580
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -4586,7 +4599,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4586
4599
|
createObjectProperty(eventName, assignmentExp)
|
|
4587
4600
|
];
|
|
4588
4601
|
// modelModifiers: { foo: true, "bar-baz": true }
|
|
4589
|
-
if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
|
|
4602
|
+
if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
4590
4603
|
const modifiers = dir.modifiers
|
|
4591
4604
|
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
|
|
4592
4605
|
.join(`, `);
|
|
@@ -4595,7 +4608,7 @@ const transformModel = (dir, node, context) => {
|
|
|
4595
4608
|
? `${arg.content}Modifiers`
|
|
4596
4609
|
: createCompoundExpression([arg, ' + "Modifiers"'])
|
|
4597
4610
|
: `modelModifiers`;
|
|
4598
|
-
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 */)));
|
|
4599
4612
|
}
|
|
4600
4613
|
return createTransformProps(props);
|
|
4601
4614
|
};
|
|
@@ -4605,17 +4618,17 @@ function createTransformProps(props = []) {
|
|
|
4605
4618
|
|
|
4606
4619
|
const validDivisionCharRE = /[\w).+\-_$\]]/;
|
|
4607
4620
|
const transformFilter = (node, context) => {
|
|
4608
|
-
if (!isCompatEnabled("COMPILER_FILTER" /* COMPILER_FILTERS */, context)) {
|
|
4621
|
+
if (!isCompatEnabled("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context)) {
|
|
4609
4622
|
return;
|
|
4610
4623
|
}
|
|
4611
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
4624
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4612
4625
|
// filter rewrite is applied before expression transform so only
|
|
4613
4626
|
// simple expressions are possible at this stage
|
|
4614
4627
|
rewriteFilter(node.content, context);
|
|
4615
4628
|
}
|
|
4616
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4629
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4617
4630
|
node.props.forEach((prop) => {
|
|
4618
|
-
if (prop.type === 7 /* DIRECTIVE */ &&
|
|
4631
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
4619
4632
|
prop.name !== 'for' &&
|
|
4620
4633
|
prop.exp) {
|
|
4621
4634
|
rewriteFilter(prop.exp, context);
|
|
@@ -4624,7 +4637,7 @@ const transformFilter = (node, context) => {
|
|
|
4624
4637
|
}
|
|
4625
4638
|
};
|
|
4626
4639
|
function rewriteFilter(node, context) {
|
|
4627
|
-
if (node.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4640
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4628
4641
|
parseFilter(node, context);
|
|
4629
4642
|
}
|
|
4630
4643
|
else {
|
|
@@ -4632,13 +4645,13 @@ function rewriteFilter(node, context) {
|
|
|
4632
4645
|
const child = node.children[i];
|
|
4633
4646
|
if (typeof child !== 'object')
|
|
4634
4647
|
continue;
|
|
4635
|
-
if (child.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4648
|
+
if (child.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4636
4649
|
parseFilter(child, context);
|
|
4637
4650
|
}
|
|
4638
|
-
else if (child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
4651
|
+
else if (child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
4639
4652
|
rewriteFilter(node, context);
|
|
4640
4653
|
}
|
|
4641
|
-
else if (child.type === 5 /* INTERPOLATION */) {
|
|
4654
|
+
else if (child.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4642
4655
|
rewriteFilter(child.content, context);
|
|
4643
4656
|
}
|
|
4644
4657
|
}
|
|
@@ -4747,7 +4760,7 @@ function parseFilter(node, context) {
|
|
|
4747
4760
|
}
|
|
4748
4761
|
if (filters.length) {
|
|
4749
4762
|
(process.env.NODE_ENV !== 'production') &&
|
|
4750
|
-
warnDeprecation("COMPILER_FILTER" /* COMPILER_FILTERS */, context, node.loc);
|
|
4763
|
+
warnDeprecation("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context, node.loc);
|
|
4751
4764
|
for (i = 0; i < filters.length; i++) {
|
|
4752
4765
|
expression = wrapFilter(expression, filters[i], context);
|
|
4753
4766
|
}
|
|
@@ -4771,7 +4784,7 @@ function wrapFilter(exp, filter, context) {
|
|
|
4771
4784
|
|
|
4772
4785
|
const seen$1 = new WeakSet();
|
|
4773
4786
|
const transformMemo = (node, context) => {
|
|
4774
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4787
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4775
4788
|
const dir = findDir(node, 'memo');
|
|
4776
4789
|
if (!dir || seen$1.has(node)) {
|
|
4777
4790
|
return;
|
|
@@ -4780,9 +4793,9 @@ const transformMemo = (node, context) => {
|
|
|
4780
4793
|
return () => {
|
|
4781
4794
|
const codegenNode = node.codegenNode ||
|
|
4782
4795
|
context.currentNode.codegenNode;
|
|
4783
|
-
if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
|
|
4796
|
+
if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
4784
4797
|
// non-component sub tree should be turned into a block
|
|
4785
|
-
if (node.tagType !== 1 /* COMPONENT */) {
|
|
4798
|
+
if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
|
|
4786
4799
|
makeBlock(codegenNode, context);
|
|
4787
4800
|
}
|
|
4788
4801
|
node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
|
@@ -4827,18 +4840,18 @@ function baseCompile(template, options = {}) {
|
|
|
4827
4840
|
/* istanbul ignore if */
|
|
4828
4841
|
{
|
|
4829
4842
|
if (options.prefixIdentifiers === true) {
|
|
4830
|
-
onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4843
|
+
onError(createCompilerError(46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */));
|
|
4831
4844
|
}
|
|
4832
4845
|
else if (isModuleMode) {
|
|
4833
|
-
onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4846
|
+
onError(createCompilerError(47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */));
|
|
4834
4847
|
}
|
|
4835
4848
|
}
|
|
4836
4849
|
const prefixIdentifiers = !true ;
|
|
4837
4850
|
if (options.cacheHandlers) {
|
|
4838
|
-
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
4851
|
+
onError(createCompilerError(48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
4839
4852
|
}
|
|
4840
4853
|
if (options.scopeId && !isModuleMode) {
|
|
4841
|
-
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
4854
|
+
onError(createCompilerError(49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
|
|
4842
4855
|
}
|
|
4843
4856
|
const ast = isString(template) ? baseParse(template, options) : template;
|
|
4844
4857
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|