@vue/compiler-core 3.2.37 → 3.2.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-core.cjs.js +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
|
@@ -22,65 +22,65 @@ function createCompilerError(code, loc, messages, additionalMessage) {
|
|
|
22
22
|
}
|
|
23
23
|
const errorMessages = {
|
|
24
24
|
// parse errors
|
|
25
|
-
[0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
26
|
-
[1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
27
|
-
[2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
28
|
-
[3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
29
|
-
[4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
30
|
-
[5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
31
|
-
[6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
32
|
-
[7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
33
|
-
[8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
34
|
-
[9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
35
|
-
[10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
36
|
-
[11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
37
|
-
[12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
38
|
-
[13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
39
|
-
[14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
40
|
-
[15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
41
|
-
[16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
42
|
-
[17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
43
|
-
[18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
44
|
-
[19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
45
|
-
[21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
46
|
-
[20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
47
|
-
[22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
25
|
+
[0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
26
|
+
[1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
27
|
+
[2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
28
|
+
[3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
29
|
+
[4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
30
|
+
[5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
31
|
+
[6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
32
|
+
[7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
33
|
+
[8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
34
|
+
[9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
35
|
+
[10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
36
|
+
[11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
37
|
+
[12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
38
|
+
[13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
39
|
+
[14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
40
|
+
[15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
41
|
+
[16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
42
|
+
[17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
43
|
+
[18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
44
|
+
[19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
45
|
+
[21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
46
|
+
[20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
47
|
+
[22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
48
48
|
// Vue-specific parse errors
|
|
49
|
-
[23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
50
|
-
[24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
51
|
-
[25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
52
|
-
[27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
49
|
+
[23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
50
|
+
[24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
51
|
+
[25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
52
|
+
[27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
53
53
|
'Note that dynamic directive argument cannot contain spaces.',
|
|
54
|
-
[26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
54
|
+
[26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
55
55
|
// transform errors
|
|
56
|
-
[28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
57
|
-
[29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
58
|
-
[30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
59
|
-
[31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
60
|
-
[32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
61
|
-
[33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
62
|
-
[34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
63
|
-
[35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
64
|
-
[36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
65
|
-
[37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
56
|
+
[28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
57
|
+
[29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
58
|
+
[30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
59
|
+
[31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
60
|
+
[32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
61
|
+
[33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
62
|
+
[34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
63
|
+
[35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
64
|
+
[36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
65
|
+
[37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
66
66
|
`When there are multiple named slots, all slots should use <template> ` +
|
|
67
67
|
`syntax to avoid scope ambiguity.`,
|
|
68
|
-
[38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
69
|
-
[39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
68
|
+
[38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
69
|
+
[39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
70
70
|
`default slot. These children will be ignored.`,
|
|
71
|
-
[40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
72
|
-
[41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
73
|
-
[42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
74
|
-
[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.`,
|
|
75
|
-
[44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
76
|
-
[45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
71
|
+
[40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
72
|
+
[41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
73
|
+
[42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
74
|
+
[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.`,
|
|
75
|
+
[44 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
76
|
+
[45 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
77
77
|
// generic errors
|
|
78
|
-
[46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
79
|
-
[47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
80
|
-
[48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
81
|
-
[49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
78
|
+
[46 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
79
|
+
[47 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
80
|
+
[48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
81
|
+
[49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
82
82
|
// just to fulfill types
|
|
83
|
-
[50 /* __EXTEND_POINT__ */]: ``
|
|
83
|
+
[50 /* ErrorCodes.__EXTEND_POINT__ */]: ``
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
const FRAGMENT = Symbol(``);
|
|
@@ -183,7 +183,7 @@ const locStub = {
|
|
|
183
183
|
};
|
|
184
184
|
function createRoot(children, loc = locStub) {
|
|
185
185
|
return {
|
|
186
|
-
type: 0 /* ROOT */,
|
|
186
|
+
type: 0 /* NodeTypes.ROOT */,
|
|
187
187
|
children,
|
|
188
188
|
helpers: [],
|
|
189
189
|
components: [],
|
|
@@ -210,7 +210,7 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
return {
|
|
213
|
-
type: 13 /* VNODE_CALL */,
|
|
213
|
+
type: 13 /* NodeTypes.VNODE_CALL */,
|
|
214
214
|
tag,
|
|
215
215
|
props,
|
|
216
216
|
children,
|
|
@@ -225,38 +225,38 @@ function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps,
|
|
|
225
225
|
}
|
|
226
226
|
function createArrayExpression(elements, loc = locStub) {
|
|
227
227
|
return {
|
|
228
|
-
type: 17 /* JS_ARRAY_EXPRESSION */,
|
|
228
|
+
type: 17 /* NodeTypes.JS_ARRAY_EXPRESSION */,
|
|
229
229
|
loc,
|
|
230
230
|
elements
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
233
|
function createObjectExpression(properties, loc = locStub) {
|
|
234
234
|
return {
|
|
235
|
-
type: 15 /* JS_OBJECT_EXPRESSION */,
|
|
235
|
+
type: 15 /* NodeTypes.JS_OBJECT_EXPRESSION */,
|
|
236
236
|
loc,
|
|
237
237
|
properties
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
function createObjectProperty(key, value) {
|
|
241
241
|
return {
|
|
242
|
-
type: 16 /* JS_PROPERTY */,
|
|
242
|
+
type: 16 /* NodeTypes.JS_PROPERTY */,
|
|
243
243
|
loc: locStub,
|
|
244
244
|
key: shared.isString(key) ? createSimpleExpression(key, true) : key,
|
|
245
245
|
value
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
|
-
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
|
|
248
|
+
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
249
249
|
return {
|
|
250
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
250
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
251
251
|
loc,
|
|
252
252
|
content,
|
|
253
253
|
isStatic,
|
|
254
|
-
constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
|
|
254
|
+
constType: isStatic ? 3 /* ConstantTypes.CAN_STRINGIFY */ : constType
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
257
|
function createInterpolation(content, loc) {
|
|
258
258
|
return {
|
|
259
|
-
type: 5 /* INTERPOLATION */,
|
|
259
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
260
260
|
loc,
|
|
261
261
|
content: shared.isString(content)
|
|
262
262
|
? createSimpleExpression(content, false, loc)
|
|
@@ -265,14 +265,14 @@ function createInterpolation(content, loc) {
|
|
|
265
265
|
}
|
|
266
266
|
function createCompoundExpression(children, loc = locStub) {
|
|
267
267
|
return {
|
|
268
|
-
type: 8 /* COMPOUND_EXPRESSION */,
|
|
268
|
+
type: 8 /* NodeTypes.COMPOUND_EXPRESSION */,
|
|
269
269
|
loc,
|
|
270
270
|
children
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
function createCallExpression(callee, args = [], loc = locStub) {
|
|
274
274
|
return {
|
|
275
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
275
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
276
276
|
loc,
|
|
277
277
|
callee,
|
|
278
278
|
arguments: args
|
|
@@ -280,7 +280,7 @@ function createCallExpression(callee, args = [], loc = locStub) {
|
|
|
280
280
|
}
|
|
281
281
|
function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
|
|
282
282
|
return {
|
|
283
|
-
type: 18 /* JS_FUNCTION_EXPRESSION */,
|
|
283
|
+
type: 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */,
|
|
284
284
|
params,
|
|
285
285
|
returns,
|
|
286
286
|
newline,
|
|
@@ -290,7 +290,7 @@ function createFunctionExpression(params, returns = undefined, newline = false,
|
|
|
290
290
|
}
|
|
291
291
|
function createConditionalExpression(test, consequent, alternate, newline = true) {
|
|
292
292
|
return {
|
|
293
|
-
type: 19 /* JS_CONDITIONAL_EXPRESSION */,
|
|
293
|
+
type: 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */,
|
|
294
294
|
test,
|
|
295
295
|
consequent,
|
|
296
296
|
alternate,
|
|
@@ -300,7 +300,7 @@ function createConditionalExpression(test, consequent, alternate, newline = true
|
|
|
300
300
|
}
|
|
301
301
|
function createCacheExpression(index, value, isVNode = false) {
|
|
302
302
|
return {
|
|
303
|
-
type: 20 /* JS_CACHE_EXPRESSION */,
|
|
303
|
+
type: 20 /* NodeTypes.JS_CACHE_EXPRESSION */,
|
|
304
304
|
index,
|
|
305
305
|
value,
|
|
306
306
|
isVNode,
|
|
@@ -309,21 +309,21 @@ function createCacheExpression(index, value, isVNode = false) {
|
|
|
309
309
|
}
|
|
310
310
|
function createBlockStatement(body) {
|
|
311
311
|
return {
|
|
312
|
-
type: 21 /* JS_BLOCK_STATEMENT */,
|
|
312
|
+
type: 21 /* NodeTypes.JS_BLOCK_STATEMENT */,
|
|
313
313
|
body,
|
|
314
314
|
loc: locStub
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
function createTemplateLiteral(elements) {
|
|
318
318
|
return {
|
|
319
|
-
type: 22 /* JS_TEMPLATE_LITERAL */,
|
|
319
|
+
type: 22 /* NodeTypes.JS_TEMPLATE_LITERAL */,
|
|
320
320
|
elements,
|
|
321
321
|
loc: locStub
|
|
322
322
|
};
|
|
323
323
|
}
|
|
324
324
|
function createIfStatement(test, consequent, alternate) {
|
|
325
325
|
return {
|
|
326
|
-
type: 23 /* JS_IF_STATEMENT */,
|
|
326
|
+
type: 23 /* NodeTypes.JS_IF_STATEMENT */,
|
|
327
327
|
test,
|
|
328
328
|
consequent,
|
|
329
329
|
alternate,
|
|
@@ -332,7 +332,7 @@ function createIfStatement(test, consequent, alternate) {
|
|
|
332
332
|
}
|
|
333
333
|
function createAssignmentExpression(left, right) {
|
|
334
334
|
return {
|
|
335
|
-
type: 24 /* JS_ASSIGNMENT_EXPRESSION */,
|
|
335
|
+
type: 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */,
|
|
336
336
|
left,
|
|
337
337
|
right,
|
|
338
338
|
loc: locStub
|
|
@@ -340,20 +340,20 @@ function createAssignmentExpression(left, right) {
|
|
|
340
340
|
}
|
|
341
341
|
function createSequenceExpression(expressions) {
|
|
342
342
|
return {
|
|
343
|
-
type: 25 /* JS_SEQUENCE_EXPRESSION */,
|
|
343
|
+
type: 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */,
|
|
344
344
|
expressions,
|
|
345
345
|
loc: locStub
|
|
346
346
|
};
|
|
347
347
|
}
|
|
348
348
|
function createReturnStatement(returns) {
|
|
349
349
|
return {
|
|
350
|
-
type: 26 /* JS_RETURN_STATEMENT */,
|
|
350
|
+
type: 26 /* NodeTypes.JS_RETURN_STATEMENT */,
|
|
351
351
|
returns,
|
|
352
352
|
loc: locStub
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
|
|
356
|
+
const isStaticExp = (p) => p.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && p.isStatic;
|
|
357
357
|
const isBuiltInType = (tag, expected) => tag === expected || tag === shared.hyphenate(expected);
|
|
358
358
|
function isCoreComponent(tag) {
|
|
359
359
|
if (isBuiltInType(tag, 'Teleport')) {
|
|
@@ -383,7 +383,7 @@ const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
|
|
383
383
|
const isMemberExpressionBrowser = (path) => {
|
|
384
384
|
// remove whitespaces around . or [ first
|
|
385
385
|
path = path.trim().replace(whitespaceRE, s => s.trim());
|
|
386
|
-
let state = 0 /* inMemberExp */;
|
|
386
|
+
let state = 0 /* MemberExpLexState.inMemberExp */;
|
|
387
387
|
let stateStack = [];
|
|
388
388
|
let currentOpenBracketCount = 0;
|
|
389
389
|
let currentOpenParensCount = 0;
|
|
@@ -391,25 +391,25 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
391
391
|
for (let i = 0; i < path.length; i++) {
|
|
392
392
|
const char = path.charAt(i);
|
|
393
393
|
switch (state) {
|
|
394
|
-
case 0 /* inMemberExp */:
|
|
394
|
+
case 0 /* MemberExpLexState.inMemberExp */:
|
|
395
395
|
if (char === '[') {
|
|
396
396
|
stateStack.push(state);
|
|
397
|
-
state = 1 /* inBrackets */;
|
|
397
|
+
state = 1 /* MemberExpLexState.inBrackets */;
|
|
398
398
|
currentOpenBracketCount++;
|
|
399
399
|
}
|
|
400
400
|
else if (char === '(') {
|
|
401
401
|
stateStack.push(state);
|
|
402
|
-
state = 2 /* inParens */;
|
|
402
|
+
state = 2 /* MemberExpLexState.inParens */;
|
|
403
403
|
currentOpenParensCount++;
|
|
404
404
|
}
|
|
405
405
|
else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
|
|
406
406
|
return false;
|
|
407
407
|
}
|
|
408
408
|
break;
|
|
409
|
-
case 1 /* inBrackets */:
|
|
409
|
+
case 1 /* MemberExpLexState.inBrackets */:
|
|
410
410
|
if (char === `'` || char === `"` || char === '`') {
|
|
411
411
|
stateStack.push(state);
|
|
412
|
-
state = 3 /* inString */;
|
|
412
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
413
413
|
currentStringType = char;
|
|
414
414
|
}
|
|
415
415
|
else if (char === `[`) {
|
|
@@ -421,10 +421,10 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
break;
|
|
424
|
-
case 2 /* inParens */:
|
|
424
|
+
case 2 /* MemberExpLexState.inParens */:
|
|
425
425
|
if (char === `'` || char === `"` || char === '`') {
|
|
426
426
|
stateStack.push(state);
|
|
427
|
-
state = 3 /* inString */;
|
|
427
|
+
state = 3 /* MemberExpLexState.inString */;
|
|
428
428
|
currentStringType = char;
|
|
429
429
|
}
|
|
430
430
|
else if (char === `(`) {
|
|
@@ -440,7 +440,7 @@ const isMemberExpressionBrowser = (path) => {
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
break;
|
|
443
|
-
case 3 /* inString */:
|
|
443
|
+
case 3 /* MemberExpLexState.inString */:
|
|
444
444
|
if (char === currentStringType) {
|
|
445
445
|
state = stateStack.pop();
|
|
446
446
|
currentStringType = null;
|
|
@@ -510,7 +510,7 @@ function assert(condition, msg) {
|
|
|
510
510
|
function findDir(node, name, allowEmpty = false) {
|
|
511
511
|
for (let i = 0; i < node.props.length; i++) {
|
|
512
512
|
const p = node.props[i];
|
|
513
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
513
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
514
514
|
(allowEmpty || p.exp) &&
|
|
515
515
|
(shared.isString(name) ? p.name === name : name.test(p.name))) {
|
|
516
516
|
return p;
|
|
@@ -520,7 +520,7 @@ function findDir(node, name, allowEmpty = false) {
|
|
|
520
520
|
function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
521
521
|
for (let i = 0; i < node.props.length; i++) {
|
|
522
522
|
const p = node.props[i];
|
|
523
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
523
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
524
524
|
if (dynamicOnly)
|
|
525
525
|
continue;
|
|
526
526
|
if (p.name === name && (p.value || allowEmpty)) {
|
|
@@ -538,24 +538,24 @@ function isStaticArgOf(arg, name) {
|
|
|
538
538
|
return !!(arg && isStaticExp(arg) && arg.content === name);
|
|
539
539
|
}
|
|
540
540
|
function hasDynamicKeyVBind(node) {
|
|
541
|
-
return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
541
|
+
return node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
542
542
|
p.name === 'bind' &&
|
|
543
543
|
(!p.arg || // v-bind="obj"
|
|
544
|
-
p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
544
|
+
p.arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
|
|
545
545
|
!p.arg.isStatic) // v-bind:[foo]
|
|
546
546
|
);
|
|
547
547
|
}
|
|
548
548
|
function isText(node) {
|
|
549
|
-
return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
|
|
549
|
+
return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
|
|
550
550
|
}
|
|
551
551
|
function isVSlot(p) {
|
|
552
|
-
return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
|
|
552
|
+
return p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'slot';
|
|
553
553
|
}
|
|
554
554
|
function isTemplateNode(node) {
|
|
555
|
-
return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
|
|
555
|
+
return (node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 3 /* ElementTypes.TEMPLATE */);
|
|
556
556
|
}
|
|
557
557
|
function isSlotOutlet(node) {
|
|
558
|
-
return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
|
|
558
|
+
return node.type === 1 /* NodeTypes.ELEMENT */ && node.tagType === 2 /* ElementTypes.SLOT */;
|
|
559
559
|
}
|
|
560
560
|
function getVNodeHelper(ssr, isComponent) {
|
|
561
561
|
return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
|
@@ -567,7 +567,7 @@ const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
|
|
567
567
|
function getUnnormalizedProps(props, callPath = []) {
|
|
568
568
|
if (props &&
|
|
569
569
|
!shared.isString(props) &&
|
|
570
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
570
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
571
571
|
const callee = props.callee;
|
|
572
572
|
if (!shared.isString(callee) && propsHelperSet.has(callee)) {
|
|
573
573
|
return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
|
|
@@ -585,12 +585,12 @@ function injectProp(node, prop, context) {
|
|
|
585
585
|
*
|
|
586
586
|
* we need to get the real props before normalization
|
|
587
587
|
*/
|
|
588
|
-
let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
|
|
588
|
+
let props = node.type === 13 /* NodeTypes.VNODE_CALL */ ? node.props : node.arguments[2];
|
|
589
589
|
let callPath = [];
|
|
590
590
|
let parentCall;
|
|
591
591
|
if (props &&
|
|
592
592
|
!shared.isString(props) &&
|
|
593
|
-
props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
593
|
+
props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
594
594
|
const ret = getUnnormalizedProps(props);
|
|
595
595
|
props = ret[0];
|
|
596
596
|
callPath = ret[1];
|
|
@@ -599,12 +599,12 @@ function injectProp(node, prop, context) {
|
|
|
599
599
|
if (props == null || shared.isString(props)) {
|
|
600
600
|
propsWithInjection = createObjectExpression([prop]);
|
|
601
601
|
}
|
|
602
|
-
else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
602
|
+
else if (props.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
603
603
|
// merged props... add ours
|
|
604
604
|
// only inject key to object literal if it's the first argument so that
|
|
605
605
|
// if doesn't override user provided keys
|
|
606
606
|
const first = props.arguments[0];
|
|
607
|
-
if (!shared.isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
607
|
+
if (!shared.isString(first) && first.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
608
608
|
first.properties.unshift(prop);
|
|
609
609
|
}
|
|
610
610
|
else {
|
|
@@ -621,12 +621,12 @@ function injectProp(node, prop, context) {
|
|
|
621
621
|
}
|
|
622
622
|
!propsWithInjection && (propsWithInjection = props);
|
|
623
623
|
}
|
|
624
|
-
else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
624
|
+
else if (props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
625
625
|
let alreadyExists = false;
|
|
626
626
|
// check existing key to avoid overriding user provided keys
|
|
627
|
-
if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
627
|
+
if (prop.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
628
628
|
const propKeyName = prop.key.content;
|
|
629
|
-
alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
629
|
+
alreadyExists = props.properties.some(p => p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
630
630
|
p.key.content === propKeyName);
|
|
631
631
|
}
|
|
632
632
|
if (!alreadyExists) {
|
|
@@ -647,7 +647,7 @@ function injectProp(node, prop, context) {
|
|
|
647
647
|
parentCall = callPath[callPath.length - 2];
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
|
-
if (node.type === 13 /* VNODE_CALL */) {
|
|
650
|
+
if (node.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
651
651
|
if (parentCall) {
|
|
652
652
|
parentCall.arguments[0] = propsWithInjection;
|
|
653
653
|
}
|
|
@@ -676,45 +676,45 @@ function hasScopeRef(node, ids) {
|
|
|
676
676
|
return false;
|
|
677
677
|
}
|
|
678
678
|
switch (node.type) {
|
|
679
|
-
case 1 /* ELEMENT */:
|
|
679
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
680
680
|
for (let i = 0; i < node.props.length; i++) {
|
|
681
681
|
const p = node.props[i];
|
|
682
|
-
if (p.type === 7 /* DIRECTIVE */ &&
|
|
682
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
683
683
|
(hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
|
|
684
684
|
return true;
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
687
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
688
|
-
case 11 /* FOR */:
|
|
688
|
+
case 11 /* NodeTypes.FOR */:
|
|
689
689
|
if (hasScopeRef(node.source, ids)) {
|
|
690
690
|
return true;
|
|
691
691
|
}
|
|
692
692
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
693
|
-
case 9 /* IF */:
|
|
693
|
+
case 9 /* NodeTypes.IF */:
|
|
694
694
|
return node.branches.some(b => hasScopeRef(b, ids));
|
|
695
|
-
case 10 /* IF_BRANCH */:
|
|
695
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
696
696
|
if (hasScopeRef(node.condition, ids)) {
|
|
697
697
|
return true;
|
|
698
698
|
}
|
|
699
699
|
return node.children.some(c => hasScopeRef(c, ids));
|
|
700
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
700
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
701
701
|
return (!node.isStatic &&
|
|
702
702
|
isSimpleIdentifier(node.content) &&
|
|
703
703
|
!!ids[node.content]);
|
|
704
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
704
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
705
705
|
return node.children.some(c => shared.isObject(c) && hasScopeRef(c, ids));
|
|
706
|
-
case 5 /* INTERPOLATION */:
|
|
707
|
-
case 12 /* TEXT_CALL */:
|
|
706
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
707
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
708
708
|
return hasScopeRef(node.content, ids);
|
|
709
|
-
case 2 /* TEXT */:
|
|
710
|
-
case 3 /* COMMENT */:
|
|
709
|
+
case 2 /* NodeTypes.TEXT */:
|
|
710
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
711
711
|
return false;
|
|
712
712
|
default:
|
|
713
713
|
return false;
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
function getMemoedVNodeCall(node) {
|
|
717
|
-
if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
717
|
+
if (node.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
|
|
718
718
|
return node.arguments[1].returns;
|
|
719
719
|
}
|
|
720
720
|
else {
|
|
@@ -731,23 +731,23 @@ function makeBlock(node, { helper, removeHelper, inSSR }) {
|
|
|
731
731
|
}
|
|
732
732
|
|
|
733
733
|
const deprecationData = {
|
|
734
|
-
["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
|
|
734
|
+
["COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */]: {
|
|
735
735
|
message: `Platform-native elements with "is" prop will no longer be ` +
|
|
736
736
|
`treated as components in Vue 3 unless the "is" value is explicitly ` +
|
|
737
737
|
`prefixed with "vue:".`,
|
|
738
738
|
link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
|
739
739
|
},
|
|
740
|
-
["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
|
|
740
|
+
["COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */]: {
|
|
741
741
|
message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
|
|
742
742
|
`argument instead. \`v-bind:${key}.sync\` should be changed to ` +
|
|
743
743
|
`\`v-model:${key}\`.`,
|
|
744
744
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
|
745
745
|
},
|
|
746
|
-
["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
|
|
746
|
+
["COMPILER_V_BIND_PROP" /* CompilerDeprecationTypes.COMPILER_V_BIND_PROP */]: {
|
|
747
747
|
message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
|
|
748
748
|
`Vue 3 will automatically set a binding as DOM property when appropriate.`
|
|
749
749
|
},
|
|
750
|
-
["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
750
|
+
["COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */]: {
|
|
751
751
|
message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
|
|
752
752
|
`object spread: it will now overwrite an existing non-mergeable attribute ` +
|
|
753
753
|
`that appears before v-bind in the case of conflict. ` +
|
|
@@ -755,11 +755,11 @@ const deprecationData = {
|
|
|
755
755
|
`You can also suppress this warning if the usage is intended.`,
|
|
756
756
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
|
757
757
|
},
|
|
758
|
-
["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
|
|
758
|
+
["COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */]: {
|
|
759
759
|
message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
|
760
760
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
|
761
761
|
},
|
|
762
|
-
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
762
|
+
["COMPILER_V_IF_V_FOR_PRECEDENCE" /* CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
|
|
763
763
|
message: `v-if / v-for precedence when used on the same element has changed ` +
|
|
764
764
|
`in Vue 3: v-if now takes higher precedence and will no longer have ` +
|
|
765
765
|
`access to v-for scope variables. It is best to avoid the ambiguity ` +
|
|
@@ -767,15 +767,15 @@ const deprecationData = {
|
|
|
767
767
|
`data source.`,
|
|
768
768
|
link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
|
769
769
|
},
|
|
770
|
-
["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
|
|
770
|
+
["COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */]: {
|
|
771
771
|
message: `<template> with no special directives will render as a native template ` +
|
|
772
772
|
`element instead of its inner content in Vue 3.`
|
|
773
773
|
},
|
|
774
|
-
["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
|
|
774
|
+
["COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */]: {
|
|
775
775
|
message: `"inline-template" has been removed in Vue 3.`,
|
|
776
776
|
link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
|
777
777
|
},
|
|
778
|
-
["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
|
|
778
|
+
["COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */]: {
|
|
779
779
|
message: `filters have been removed in Vue 3. ` +
|
|
780
780
|
`The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
|
|
781
781
|
`Use method calls or computed properties instead.`,
|
|
@@ -832,8 +832,8 @@ const decodeMap = {
|
|
|
832
832
|
};
|
|
833
833
|
const defaultParserOptions = {
|
|
834
834
|
delimiters: [`{{`, `}}`],
|
|
835
|
-
getNamespace: () => 0 /* HTML */,
|
|
836
|
-
getTextMode: () => 0 /* DATA */,
|
|
835
|
+
getNamespace: () => 0 /* Namespaces.HTML */,
|
|
836
|
+
getTextMode: () => 0 /* TextModes.DATA */,
|
|
837
837
|
isVoidTag: shared.NO,
|
|
838
838
|
isPreTag: shared.NO,
|
|
839
839
|
isCustomElement: shared.NO,
|
|
@@ -845,7 +845,7 @@ const defaultParserOptions = {
|
|
|
845
845
|
function baseParse(content, options = {}) {
|
|
846
846
|
const context = createParserContext(content, options);
|
|
847
847
|
const start = getCursor(context);
|
|
848
|
-
return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
|
|
848
|
+
return createRoot(parseChildren(context, 0 /* TextModes.DATA */, []), getSelection(context, start));
|
|
849
849
|
}
|
|
850
850
|
function createParserContext(content, rawOptions) {
|
|
851
851
|
const options = shared.extend({}, defaultParserOptions);
|
|
@@ -871,20 +871,20 @@ function createParserContext(content, rawOptions) {
|
|
|
871
871
|
}
|
|
872
872
|
function parseChildren(context, mode, ancestors) {
|
|
873
873
|
const parent = last(ancestors);
|
|
874
|
-
const ns = parent ? parent.ns : 0 /* HTML */;
|
|
874
|
+
const ns = parent ? parent.ns : 0 /* Namespaces.HTML */;
|
|
875
875
|
const nodes = [];
|
|
876
876
|
while (!isEnd(context, mode, ancestors)) {
|
|
877
877
|
const s = context.source;
|
|
878
878
|
let node = undefined;
|
|
879
|
-
if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
|
|
879
|
+
if (mode === 0 /* TextModes.DATA */ || mode === 1 /* TextModes.RCDATA */) {
|
|
880
880
|
if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
|
|
881
881
|
// '{{'
|
|
882
882
|
node = parseInterpolation(context, mode);
|
|
883
883
|
}
|
|
884
|
-
else if (mode === 0 /* DATA */ && s[0] === '<') {
|
|
884
|
+
else if (mode === 0 /* TextModes.DATA */ && s[0] === '<') {
|
|
885
885
|
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
|
|
886
886
|
if (s.length === 1) {
|
|
887
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
|
|
887
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 1);
|
|
888
888
|
}
|
|
889
889
|
else if (s[1] === '!') {
|
|
890
890
|
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
|
|
@@ -896,56 +896,56 @@ function parseChildren(context, mode, ancestors) {
|
|
|
896
896
|
node = parseBogusComment(context);
|
|
897
897
|
}
|
|
898
898
|
else if (startsWith(s, '<![CDATA[')) {
|
|
899
|
-
if (ns !== 0 /* HTML */) {
|
|
899
|
+
if (ns !== 0 /* Namespaces.HTML */) {
|
|
900
900
|
node = parseCDATA(context, ancestors);
|
|
901
901
|
}
|
|
902
902
|
else {
|
|
903
|
-
emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
|
|
903
|
+
emitError(context, 1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */);
|
|
904
904
|
node = parseBogusComment(context);
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
else {
|
|
908
|
-
emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
|
|
908
|
+
emitError(context, 11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */);
|
|
909
909
|
node = parseBogusComment(context);
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
else if (s[1] === '/') {
|
|
913
913
|
// https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
|
|
914
914
|
if (s.length === 2) {
|
|
915
|
-
emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
|
|
915
|
+
emitError(context, 5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */, 2);
|
|
916
916
|
}
|
|
917
917
|
else if (s[2] === '>') {
|
|
918
|
-
emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
|
|
918
|
+
emitError(context, 14 /* ErrorCodes.MISSING_END_TAG_NAME */, 2);
|
|
919
919
|
advanceBy(context, 3);
|
|
920
920
|
continue;
|
|
921
921
|
}
|
|
922
922
|
else if (/[a-z]/i.test(s[2])) {
|
|
923
|
-
emitError(context, 23 /* X_INVALID_END_TAG */);
|
|
924
|
-
parseTag(context, 1 /* End */, parent);
|
|
923
|
+
emitError(context, 23 /* ErrorCodes.X_INVALID_END_TAG */);
|
|
924
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
925
925
|
continue;
|
|
926
926
|
}
|
|
927
927
|
else {
|
|
928
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
928
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
|
|
929
929
|
node = parseBogusComment(context);
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
else if (/[a-z]/i.test(s[1])) {
|
|
933
933
|
node = parseElement(context, ancestors);
|
|
934
934
|
// 2.x <template> with no directive compat
|
|
935
|
-
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
935
|
+
if (isCompatEnabled("COMPILER_NATIVE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE */, context) &&
|
|
936
936
|
node &&
|
|
937
937
|
node.tag === 'template' &&
|
|
938
|
-
!node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
|
|
938
|
+
!node.props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
939
939
|
isSpecialTemplateDirective(p.name))) {
|
|
940
940
|
node = node.children;
|
|
941
941
|
}
|
|
942
942
|
}
|
|
943
943
|
else if (s[1] === '?') {
|
|
944
|
-
emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
944
|
+
emitError(context, 21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
|
|
945
945
|
node = parseBogusComment(context);
|
|
946
946
|
}
|
|
947
947
|
else {
|
|
948
|
-
emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
948
|
+
emitError(context, 12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
|
|
949
949
|
}
|
|
950
950
|
}
|
|
951
951
|
}
|
|
@@ -963,11 +963,11 @@ function parseChildren(context, mode, ancestors) {
|
|
|
963
963
|
}
|
|
964
964
|
// Whitespace handling strategy like v2
|
|
965
965
|
let removedWhitespace = false;
|
|
966
|
-
if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
|
|
966
|
+
if (mode !== 2 /* TextModes.RAWTEXT */ && mode !== 1 /* TextModes.RCDATA */) {
|
|
967
967
|
const shouldCondense = context.options.whitespace !== 'preserve';
|
|
968
968
|
for (let i = 0; i < nodes.length; i++) {
|
|
969
969
|
const node = nodes[i];
|
|
970
|
-
if (!context.inPre && node.type === 2 /* TEXT */) {
|
|
970
|
+
if (!context.inPre && node.type === 2 /* NodeTypes.TEXT */) {
|
|
971
971
|
if (!/[^\t\r\n\f ]/.test(node.content)) {
|
|
972
972
|
const prev = nodes[i - 1];
|
|
973
973
|
const next = nodes[i + 1];
|
|
@@ -978,10 +978,10 @@ function parseChildren(context, mode, ancestors) {
|
|
|
978
978
|
if (!prev ||
|
|
979
979
|
!next ||
|
|
980
980
|
(shouldCondense &&
|
|
981
|
-
(prev.type === 3 /* COMMENT */ ||
|
|
982
|
-
next.type === 3 /* COMMENT */ ||
|
|
983
|
-
(prev.type === 1 /* ELEMENT */ &&
|
|
984
|
-
next.type === 1 /* ELEMENT */ &&
|
|
981
|
+
(prev.type === 3 /* NodeTypes.COMMENT */ ||
|
|
982
|
+
next.type === 3 /* NodeTypes.COMMENT */ ||
|
|
983
|
+
(prev.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
984
|
+
next.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
985
985
|
/[\r\n]/.test(node.content))))) {
|
|
986
986
|
removedWhitespace = true;
|
|
987
987
|
nodes[i] = null;
|
|
@@ -998,7 +998,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
998
998
|
}
|
|
999
999
|
}
|
|
1000
1000
|
// Remove comment nodes if desired by configuration.
|
|
1001
|
-
else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
|
|
1001
|
+
else if (node.type === 3 /* NodeTypes.COMMENT */ && !context.options.comments) {
|
|
1002
1002
|
removedWhitespace = true;
|
|
1003
1003
|
nodes[i] = null;
|
|
1004
1004
|
}
|
|
@@ -1007,7 +1007,7 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1007
1007
|
// remove leading newline per html spec
|
|
1008
1008
|
// https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
|
|
1009
1009
|
const first = nodes[0];
|
|
1010
|
-
if (first && first.type === 2 /* TEXT */) {
|
|
1010
|
+
if (first && first.type === 2 /* NodeTypes.TEXT */) {
|
|
1011
1011
|
first.content = first.content.replace(/^\r?\n/, '');
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
@@ -1015,12 +1015,12 @@ function parseChildren(context, mode, ancestors) {
|
|
|
1015
1015
|
return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
|
1016
1016
|
}
|
|
1017
1017
|
function pushNode(nodes, node) {
|
|
1018
|
-
if (node.type === 2 /* TEXT */) {
|
|
1018
|
+
if (node.type === 2 /* NodeTypes.TEXT */) {
|
|
1019
1019
|
const prev = last(nodes);
|
|
1020
1020
|
// Merge if both this and the previous node are text and those are
|
|
1021
1021
|
// consecutive. This happens for cases like "a < b".
|
|
1022
1022
|
if (prev &&
|
|
1023
|
-
prev.type === 2 /* TEXT */ &&
|
|
1023
|
+
prev.type === 2 /* NodeTypes.TEXT */ &&
|
|
1024
1024
|
prev.loc.end.offset === node.loc.start.offset) {
|
|
1025
1025
|
prev.content += node.content;
|
|
1026
1026
|
prev.loc.end = node.loc.end;
|
|
@@ -1032,9 +1032,9 @@ function pushNode(nodes, node) {
|
|
|
1032
1032
|
}
|
|
1033
1033
|
function parseCDATA(context, ancestors) {
|
|
1034
1034
|
advanceBy(context, 9);
|
|
1035
|
-
const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
|
|
1035
|
+
const nodes = parseChildren(context, 3 /* TextModes.CDATA */, ancestors);
|
|
1036
1036
|
if (context.source.length === 0) {
|
|
1037
|
-
emitError(context, 6 /* EOF_IN_CDATA */);
|
|
1037
|
+
emitError(context, 6 /* ErrorCodes.EOF_IN_CDATA */);
|
|
1038
1038
|
}
|
|
1039
1039
|
else {
|
|
1040
1040
|
advanceBy(context, 3);
|
|
@@ -1049,14 +1049,14 @@ function parseComment(context) {
|
|
|
1049
1049
|
if (!match) {
|
|
1050
1050
|
content = context.source.slice(4);
|
|
1051
1051
|
advanceBy(context, context.source.length);
|
|
1052
|
-
emitError(context, 7 /* EOF_IN_COMMENT */);
|
|
1052
|
+
emitError(context, 7 /* ErrorCodes.EOF_IN_COMMENT */);
|
|
1053
1053
|
}
|
|
1054
1054
|
else {
|
|
1055
1055
|
if (match.index <= 3) {
|
|
1056
|
-
emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1056
|
+
emitError(context, 0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
|
|
1057
1057
|
}
|
|
1058
1058
|
if (match[1]) {
|
|
1059
|
-
emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
|
|
1059
|
+
emitError(context, 10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */);
|
|
1060
1060
|
}
|
|
1061
1061
|
content = context.source.slice(4, match.index);
|
|
1062
1062
|
// Advancing with reporting nested comments.
|
|
@@ -1065,14 +1065,14 @@ function parseComment(context) {
|
|
|
1065
1065
|
while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
|
|
1066
1066
|
advanceBy(context, nestedIndex - prevIndex + 1);
|
|
1067
1067
|
if (nestedIndex + 4 < s.length) {
|
|
1068
|
-
emitError(context, 16 /* NESTED_COMMENT */);
|
|
1068
|
+
emitError(context, 16 /* ErrorCodes.NESTED_COMMENT */);
|
|
1069
1069
|
}
|
|
1070
1070
|
prevIndex = nestedIndex + 1;
|
|
1071
1071
|
}
|
|
1072
1072
|
advanceBy(context, match.index + match[0].length - prevIndex + 1);
|
|
1073
1073
|
}
|
|
1074
1074
|
return {
|
|
1075
|
-
type: 3 /* COMMENT */,
|
|
1075
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1076
1076
|
content,
|
|
1077
1077
|
loc: getSelection(context, start)
|
|
1078
1078
|
};
|
|
@@ -1091,7 +1091,7 @@ function parseBogusComment(context) {
|
|
|
1091
1091
|
advanceBy(context, closeIndex + 1);
|
|
1092
1092
|
}
|
|
1093
1093
|
return {
|
|
1094
|
-
type: 3 /* COMMENT */,
|
|
1094
|
+
type: 3 /* NodeTypes.COMMENT */,
|
|
1095
1095
|
content,
|
|
1096
1096
|
loc: getSelection(context, start)
|
|
1097
1097
|
};
|
|
@@ -1101,7 +1101,7 @@ function parseElement(context, ancestors) {
|
|
|
1101
1101
|
const wasInPre = context.inPre;
|
|
1102
1102
|
const wasInVPre = context.inVPre;
|
|
1103
1103
|
const parent = last(ancestors);
|
|
1104
|
-
const element = parseTag(context, 0 /* Start */, parent);
|
|
1104
|
+
const element = parseTag(context, 0 /* TagType.Start */, parent);
|
|
1105
1105
|
const isPreBoundary = context.inPre && !wasInPre;
|
|
1106
1106
|
const isVPreBoundary = context.inVPre && !wasInVPre;
|
|
1107
1107
|
if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
|
|
@@ -1121,12 +1121,12 @@ function parseElement(context, ancestors) {
|
|
|
1121
1121
|
ancestors.pop();
|
|
1122
1122
|
// 2.x inline-template compat
|
|
1123
1123
|
{
|
|
1124
|
-
const inlineTemplateProp = element.props.find(p => p.type === 6 /* ATTRIBUTE */ && p.name === 'inline-template');
|
|
1124
|
+
const inlineTemplateProp = element.props.find(p => p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'inline-template');
|
|
1125
1125
|
if (inlineTemplateProp &&
|
|
1126
|
-
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1126
|
+
checkCompatEnabled("COMPILER_INLINE_TEMPLATE" /* CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE */, context, inlineTemplateProp.loc)) {
|
|
1127
1127
|
const loc = getSelection(context, element.loc.end);
|
|
1128
1128
|
inlineTemplateProp.value = {
|
|
1129
|
-
type: 2 /* TEXT */,
|
|
1129
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1130
1130
|
content: loc.source,
|
|
1131
1131
|
loc
|
|
1132
1132
|
};
|
|
@@ -1135,14 +1135,14 @@ function parseElement(context, ancestors) {
|
|
|
1135
1135
|
element.children = children;
|
|
1136
1136
|
// End tag.
|
|
1137
1137
|
if (startsWithEndTagOpen(context.source, element.tag)) {
|
|
1138
|
-
parseTag(context, 1 /* End */, parent);
|
|
1138
|
+
parseTag(context, 1 /* TagType.End */, parent);
|
|
1139
1139
|
}
|
|
1140
1140
|
else {
|
|
1141
|
-
emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1141
|
+
emitError(context, 24 /* ErrorCodes.X_MISSING_END_TAG */, 0, element.loc.start);
|
|
1142
1142
|
if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
|
|
1143
1143
|
const first = children[0];
|
|
1144
1144
|
if (first && startsWith(first.loc.source, '<!--')) {
|
|
1145
|
-
emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1145
|
+
emitError(context, 8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
|
|
1146
1146
|
}
|
|
1147
1147
|
}
|
|
1148
1148
|
}
|
|
@@ -1174,9 +1174,9 @@ function parseTag(context, type, parent) {
|
|
|
1174
1174
|
// Attributes.
|
|
1175
1175
|
let props = parseAttributes(context, type);
|
|
1176
1176
|
// check v-pre
|
|
1177
|
-
if (type === 0 /* Start */ &&
|
|
1177
|
+
if (type === 0 /* TagType.Start */ &&
|
|
1178
1178
|
!context.inVPre &&
|
|
1179
|
-
props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
|
|
1179
|
+
props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'pre')) {
|
|
1180
1180
|
context.inVPre = true;
|
|
1181
1181
|
// reset context
|
|
1182
1182
|
shared.extend(context, cursor);
|
|
@@ -1187,34 +1187,34 @@ function parseTag(context, type, parent) {
|
|
|
1187
1187
|
// Tag close.
|
|
1188
1188
|
let isSelfClosing = false;
|
|
1189
1189
|
if (context.source.length === 0) {
|
|
1190
|
-
emitError(context, 9 /* EOF_IN_TAG */);
|
|
1190
|
+
emitError(context, 9 /* ErrorCodes.EOF_IN_TAG */);
|
|
1191
1191
|
}
|
|
1192
1192
|
else {
|
|
1193
1193
|
isSelfClosing = startsWith(context.source, '/>');
|
|
1194
|
-
if (type === 1 /* End */ && isSelfClosing) {
|
|
1195
|
-
emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1194
|
+
if (type === 1 /* TagType.End */ && isSelfClosing) {
|
|
1195
|
+
emitError(context, 4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */);
|
|
1196
1196
|
}
|
|
1197
1197
|
advanceBy(context, isSelfClosing ? 2 : 1);
|
|
1198
1198
|
}
|
|
1199
|
-
if (type === 1 /* End */) {
|
|
1199
|
+
if (type === 1 /* TagType.End */) {
|
|
1200
1200
|
return;
|
|
1201
1201
|
}
|
|
1202
|
-
let tagType = 0 /* ELEMENT */;
|
|
1202
|
+
let tagType = 0 /* ElementTypes.ELEMENT */;
|
|
1203
1203
|
if (!context.inVPre) {
|
|
1204
1204
|
if (tag === 'slot') {
|
|
1205
|
-
tagType = 2 /* SLOT */;
|
|
1205
|
+
tagType = 2 /* ElementTypes.SLOT */;
|
|
1206
1206
|
}
|
|
1207
1207
|
else if (tag === 'template') {
|
|
1208
|
-
if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1209
|
-
tagType = 3 /* TEMPLATE */;
|
|
1208
|
+
if (props.some(p => p.type === 7 /* NodeTypes.DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
|
|
1209
|
+
tagType = 3 /* ElementTypes.TEMPLATE */;
|
|
1210
1210
|
}
|
|
1211
1211
|
}
|
|
1212
1212
|
else if (isComponent(tag, props, context)) {
|
|
1213
|
-
tagType = 1 /* COMPONENT */;
|
|
1213
|
+
tagType = 1 /* ElementTypes.COMPONENT */;
|
|
1214
1214
|
}
|
|
1215
1215
|
}
|
|
1216
1216
|
return {
|
|
1217
|
-
type: 1 /* ELEMENT */,
|
|
1217
|
+
type: 1 /* NodeTypes.ELEMENT */,
|
|
1218
1218
|
ns,
|
|
1219
1219
|
tag,
|
|
1220
1220
|
tagType,
|
|
@@ -1241,12 +1241,12 @@ function isComponent(tag, props, context) {
|
|
|
1241
1241
|
// casting
|
|
1242
1242
|
for (let i = 0; i < props.length; i++) {
|
|
1243
1243
|
const p = props[i];
|
|
1244
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
1244
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
1245
1245
|
if (p.name === 'is' && p.value) {
|
|
1246
1246
|
if (p.value.content.startsWith('vue:')) {
|
|
1247
1247
|
return true;
|
|
1248
1248
|
}
|
|
1249
|
-
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1249
|
+
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1250
1250
|
return true;
|
|
1251
1251
|
}
|
|
1252
1252
|
}
|
|
@@ -1262,7 +1262,7 @@ function isComponent(tag, props, context) {
|
|
|
1262
1262
|
p.name === 'bind' &&
|
|
1263
1263
|
isStaticArgOf(p.arg, 'is') &&
|
|
1264
1264
|
true &&
|
|
1265
|
-
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1265
|
+
checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
|
|
1266
1266
|
return true;
|
|
1267
1267
|
}
|
|
1268
1268
|
}
|
|
@@ -1275,27 +1275,27 @@ function parseAttributes(context, type) {
|
|
|
1275
1275
|
!startsWith(context.source, '>') &&
|
|
1276
1276
|
!startsWith(context.source, '/>')) {
|
|
1277
1277
|
if (startsWith(context.source, '/')) {
|
|
1278
|
-
emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1278
|
+
emitError(context, 22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */);
|
|
1279
1279
|
advanceBy(context, 1);
|
|
1280
1280
|
advanceSpaces(context);
|
|
1281
1281
|
continue;
|
|
1282
1282
|
}
|
|
1283
|
-
if (type === 1 /* End */) {
|
|
1284
|
-
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1283
|
+
if (type === 1 /* TagType.End */) {
|
|
1284
|
+
emitError(context, 3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */);
|
|
1285
1285
|
}
|
|
1286
1286
|
const attr = parseAttribute(context, attributeNames);
|
|
1287
1287
|
// Trim whitespace between class
|
|
1288
1288
|
// https://github.com/vuejs/core/issues/4251
|
|
1289
|
-
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1289
|
+
if (attr.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
1290
1290
|
attr.value &&
|
|
1291
1291
|
attr.name === 'class') {
|
|
1292
1292
|
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1293
1293
|
}
|
|
1294
|
-
if (type === 0 /* Start */) {
|
|
1294
|
+
if (type === 0 /* TagType.Start */) {
|
|
1295
1295
|
props.push(attr);
|
|
1296
1296
|
}
|
|
1297
1297
|
if (/^[^\t\r\n\f />]/.test(context.source)) {
|
|
1298
|
-
emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1298
|
+
emitError(context, 15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
|
|
1299
1299
|
}
|
|
1300
1300
|
advanceSpaces(context);
|
|
1301
1301
|
}
|
|
@@ -1307,17 +1307,17 @@ function parseAttribute(context, nameSet) {
|
|
|
1307
1307
|
const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
|
|
1308
1308
|
const name = match[0];
|
|
1309
1309
|
if (nameSet.has(name)) {
|
|
1310
|
-
emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
|
|
1310
|
+
emitError(context, 2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */);
|
|
1311
1311
|
}
|
|
1312
1312
|
nameSet.add(name);
|
|
1313
1313
|
if (name[0] === '=') {
|
|
1314
|
-
emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1314
|
+
emitError(context, 19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
|
|
1315
1315
|
}
|
|
1316
1316
|
{
|
|
1317
1317
|
const pattern = /["'<]/g;
|
|
1318
1318
|
let m;
|
|
1319
1319
|
while ((m = pattern.exec(name))) {
|
|
1320
|
-
emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1320
|
+
emitError(context, 17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
|
|
1321
1321
|
}
|
|
1322
1322
|
}
|
|
1323
1323
|
advanceBy(context, name.length);
|
|
@@ -1329,7 +1329,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1329
1329
|
advanceSpaces(context);
|
|
1330
1330
|
value = parseAttributeValue(context);
|
|
1331
1331
|
if (!value) {
|
|
1332
|
-
emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
|
|
1332
|
+
emitError(context, 13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */);
|
|
1333
1333
|
}
|
|
1334
1334
|
}
|
|
1335
1335
|
const loc = getSelection(context, start);
|
|
@@ -1352,7 +1352,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1352
1352
|
if (content.startsWith('[')) {
|
|
1353
1353
|
isStatic = false;
|
|
1354
1354
|
if (!content.endsWith(']')) {
|
|
1355
|
-
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1355
|
+
emitError(context, 27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1356
1356
|
content = content.slice(1);
|
|
1357
1357
|
}
|
|
1358
1358
|
else {
|
|
@@ -1366,12 +1366,12 @@ function parseAttribute(context, nameSet) {
|
|
|
1366
1366
|
content += match[3] || '';
|
|
1367
1367
|
}
|
|
1368
1368
|
arg = {
|
|
1369
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1369
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1370
1370
|
content,
|
|
1371
1371
|
isStatic,
|
|
1372
1372
|
constType: isStatic
|
|
1373
|
-
? 3 /* CAN_STRINGIFY */
|
|
1374
|
-
: 0 /* NOT_CONSTANT */,
|
|
1373
|
+
? 3 /* ConstantTypes.CAN_STRINGIFY */
|
|
1374
|
+
: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1375
1375
|
loc
|
|
1376
1376
|
};
|
|
1377
1377
|
}
|
|
@@ -1388,21 +1388,21 @@ function parseAttribute(context, nameSet) {
|
|
|
1388
1388
|
// 2.x compat v-bind:foo.sync -> v-model:foo
|
|
1389
1389
|
if (dirName === 'bind' && arg) {
|
|
1390
1390
|
if (modifiers.includes('sync') &&
|
|
1391
|
-
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1391
|
+
checkCompatEnabled("COMPILER_V_BIND_SYNC" /* CompilerDeprecationTypes.COMPILER_V_BIND_SYNC */, context, loc, arg.loc.source)) {
|
|
1392
1392
|
dirName = 'model';
|
|
1393
1393
|
modifiers.splice(modifiers.indexOf('sync'), 1);
|
|
1394
1394
|
}
|
|
1395
1395
|
}
|
|
1396
1396
|
return {
|
|
1397
|
-
type: 7 /* DIRECTIVE */,
|
|
1397
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
1398
1398
|
name: dirName,
|
|
1399
1399
|
exp: value && {
|
|
1400
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1400
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1401
1401
|
content: value.content,
|
|
1402
1402
|
isStatic: false,
|
|
1403
1403
|
// Treat as non-constant by default. This can be potentially set to
|
|
1404
1404
|
// other values by `transformExpression` to make it eligible for hoisting.
|
|
1405
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1405
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1406
1406
|
loc: value.loc
|
|
1407
1407
|
},
|
|
1408
1408
|
arg,
|
|
@@ -1412,13 +1412,13 @@ function parseAttribute(context, nameSet) {
|
|
|
1412
1412
|
}
|
|
1413
1413
|
// missing directive name or illegal directive name
|
|
1414
1414
|
if (!context.inVPre && startsWith(name, 'v-')) {
|
|
1415
|
-
emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
|
|
1415
|
+
emitError(context, 26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */);
|
|
1416
1416
|
}
|
|
1417
1417
|
return {
|
|
1418
|
-
type: 6 /* ATTRIBUTE */,
|
|
1418
|
+
type: 6 /* NodeTypes.ATTRIBUTE */,
|
|
1419
1419
|
name,
|
|
1420
1420
|
value: value && {
|
|
1421
|
-
type: 2 /* TEXT */,
|
|
1421
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1422
1422
|
content: value.content,
|
|
1423
1423
|
loc: value.loc
|
|
1424
1424
|
},
|
|
@@ -1435,10 +1435,10 @@ function parseAttributeValue(context) {
|
|
|
1435
1435
|
advanceBy(context, 1);
|
|
1436
1436
|
const endIndex = context.source.indexOf(quote);
|
|
1437
1437
|
if (endIndex === -1) {
|
|
1438
|
-
content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
|
|
1438
|
+
content = parseTextData(context, context.source.length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1439
1439
|
}
|
|
1440
1440
|
else {
|
|
1441
|
-
content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
|
|
1441
|
+
content = parseTextData(context, endIndex, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1442
1442
|
advanceBy(context, 1);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
@@ -1451,9 +1451,9 @@ function parseAttributeValue(context) {
|
|
|
1451
1451
|
const unexpectedChars = /["'<=`]/g;
|
|
1452
1452
|
let m;
|
|
1453
1453
|
while ((m = unexpectedChars.exec(match[0]))) {
|
|
1454
|
-
emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1454
|
+
emitError(context, 18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
|
|
1455
1455
|
}
|
|
1456
|
-
content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
|
|
1456
|
+
content = parseTextData(context, match[0].length, 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1457
1457
|
}
|
|
1458
1458
|
return { content, isQuoted, loc: getSelection(context, start) };
|
|
1459
1459
|
}
|
|
@@ -1461,7 +1461,7 @@ function parseInterpolation(context, mode) {
|
|
|
1461
1461
|
const [open, close] = context.options.delimiters;
|
|
1462
1462
|
const closeIndex = context.source.indexOf(close, open.length);
|
|
1463
1463
|
if (closeIndex === -1) {
|
|
1464
|
-
emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
|
|
1464
|
+
emitError(context, 25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */);
|
|
1465
1465
|
return undefined;
|
|
1466
1466
|
}
|
|
1467
1467
|
const start = getCursor(context);
|
|
@@ -1480,12 +1480,12 @@ function parseInterpolation(context, mode) {
|
|
|
1480
1480
|
advancePositionWithMutation(innerEnd, rawContent, endOffset);
|
|
1481
1481
|
advanceBy(context, close.length);
|
|
1482
1482
|
return {
|
|
1483
|
-
type: 5 /* INTERPOLATION */,
|
|
1483
|
+
type: 5 /* NodeTypes.INTERPOLATION */,
|
|
1484
1484
|
content: {
|
|
1485
|
-
type: 4 /* SIMPLE_EXPRESSION */,
|
|
1485
|
+
type: 4 /* NodeTypes.SIMPLE_EXPRESSION */,
|
|
1486
1486
|
isStatic: false,
|
|
1487
1487
|
// Set `isConstant` to false by default and will decide in transformExpression
|
|
1488
|
-
constType: 0 /* NOT_CONSTANT */,
|
|
1488
|
+
constType: 0 /* ConstantTypes.NOT_CONSTANT */,
|
|
1489
1489
|
content,
|
|
1490
1490
|
loc: getSelection(context, innerStart, innerEnd)
|
|
1491
1491
|
},
|
|
@@ -1493,7 +1493,7 @@ function parseInterpolation(context, mode) {
|
|
|
1493
1493
|
};
|
|
1494
1494
|
}
|
|
1495
1495
|
function parseText(context, mode) {
|
|
1496
|
-
const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1496
|
+
const endTokens = mode === 3 /* TextModes.CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
|
|
1497
1497
|
let endIndex = context.source.length;
|
|
1498
1498
|
for (let i = 0; i < endTokens.length; i++) {
|
|
1499
1499
|
const index = context.source.indexOf(endTokens[i], 1);
|
|
@@ -1504,7 +1504,7 @@ function parseText(context, mode) {
|
|
|
1504
1504
|
const start = getCursor(context);
|
|
1505
1505
|
const content = parseTextData(context, endIndex, mode);
|
|
1506
1506
|
return {
|
|
1507
|
-
type: 2 /* TEXT */,
|
|
1507
|
+
type: 2 /* NodeTypes.TEXT */,
|
|
1508
1508
|
content,
|
|
1509
1509
|
loc: getSelection(context, start)
|
|
1510
1510
|
};
|
|
@@ -1516,14 +1516,14 @@ function parseText(context, mode) {
|
|
|
1516
1516
|
function parseTextData(context, length, mode) {
|
|
1517
1517
|
const rawText = context.source.slice(0, length);
|
|
1518
1518
|
advanceBy(context, length);
|
|
1519
|
-
if (mode === 2 /* RAWTEXT */ ||
|
|
1520
|
-
mode === 3 /* CDATA */ ||
|
|
1519
|
+
if (mode === 2 /* TextModes.RAWTEXT */ ||
|
|
1520
|
+
mode === 3 /* TextModes.CDATA */ ||
|
|
1521
1521
|
!rawText.includes('&')) {
|
|
1522
1522
|
return rawText;
|
|
1523
1523
|
}
|
|
1524
1524
|
else {
|
|
1525
1525
|
// DATA or RCDATA containing "&"". Entity decoding required.
|
|
1526
|
-
return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
|
|
1526
|
+
return context.options.decodeEntities(rawText, mode === 4 /* TextModes.ATTRIBUTE_VALUE */);
|
|
1527
1527
|
}
|
|
1528
1528
|
}
|
|
1529
1529
|
function getCursor(context) {
|
|
@@ -1572,7 +1572,7 @@ function emitError(context, code, offset, loc = getCursor(context)) {
|
|
|
1572
1572
|
function isEnd(context, mode, ancestors) {
|
|
1573
1573
|
const s = context.source;
|
|
1574
1574
|
switch (mode) {
|
|
1575
|
-
case 0 /* DATA */:
|
|
1575
|
+
case 0 /* TextModes.DATA */:
|
|
1576
1576
|
if (startsWith(s, '</')) {
|
|
1577
1577
|
// TODO: probably bad performance
|
|
1578
1578
|
for (let i = ancestors.length - 1; i >= 0; --i) {
|
|
@@ -1582,15 +1582,15 @@ function isEnd(context, mode, ancestors) {
|
|
|
1582
1582
|
}
|
|
1583
1583
|
}
|
|
1584
1584
|
break;
|
|
1585
|
-
case 1 /* RCDATA */:
|
|
1586
|
-
case 2 /* RAWTEXT */: {
|
|
1585
|
+
case 1 /* TextModes.RCDATA */:
|
|
1586
|
+
case 2 /* TextModes.RAWTEXT */: {
|
|
1587
1587
|
const parent = last(ancestors);
|
|
1588
1588
|
if (parent && startsWithEndTagOpen(s, parent.tag)) {
|
|
1589
1589
|
return true;
|
|
1590
1590
|
}
|
|
1591
1591
|
break;
|
|
1592
1592
|
}
|
|
1593
|
-
case 3 /* CDATA */:
|
|
1593
|
+
case 3 /* TextModes.CDATA */:
|
|
1594
1594
|
if (startsWith(s, ']]>')) {
|
|
1595
1595
|
return true;
|
|
1596
1596
|
}
|
|
@@ -1613,7 +1613,7 @@ function hoistStatic(root, context) {
|
|
|
1613
1613
|
function isSingleElementRoot(root, child) {
|
|
1614
1614
|
const { children } = root;
|
|
1615
1615
|
return (children.length === 1 &&
|
|
1616
|
-
child.type === 1 /* ELEMENT */ &&
|
|
1616
|
+
child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1617
1617
|
!isSlotOutlet(child));
|
|
1618
1618
|
}
|
|
1619
1619
|
function walk(node, context, doNotHoistNode = false) {
|
|
@@ -1623,15 +1623,15 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1623
1623
|
for (let i = 0; i < children.length; i++) {
|
|
1624
1624
|
const child = children[i];
|
|
1625
1625
|
// only plain elements & text calls are eligible for hoisting.
|
|
1626
|
-
if (child.type === 1 /* ELEMENT */ &&
|
|
1627
|
-
child.tagType === 0 /* ELEMENT */) {
|
|
1626
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1627
|
+
child.tagType === 0 /* ElementTypes.ELEMENT */) {
|
|
1628
1628
|
const constantType = doNotHoistNode
|
|
1629
|
-
? 0 /* NOT_CONSTANT */
|
|
1629
|
+
? 0 /* ConstantTypes.NOT_CONSTANT */
|
|
1630
1630
|
: getConstantType(child, context);
|
|
1631
|
-
if (constantType > 0 /* NOT_CONSTANT */) {
|
|
1632
|
-
if (constantType >= 2 /* CAN_HOIST */) {
|
|
1631
|
+
if (constantType > 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1632
|
+
if (constantType >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1633
1633
|
child.codegenNode.patchFlag =
|
|
1634
|
-
-1 /* HOISTED */ + (``);
|
|
1634
|
+
-1 /* PatchFlags.HOISTED */ + (``);
|
|
1635
1635
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1636
1636
|
hoistedCount++;
|
|
1637
1637
|
continue;
|
|
@@ -1641,13 +1641,13 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1641
1641
|
// node may contain dynamic children, but its props may be eligible for
|
|
1642
1642
|
// hoisting.
|
|
1643
1643
|
const codegenNode = child.codegenNode;
|
|
1644
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1644
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1645
1645
|
const flag = getPatchFlag(codegenNode);
|
|
1646
1646
|
if ((!flag ||
|
|
1647
|
-
flag === 512 /* NEED_PATCH */ ||
|
|
1648
|
-
flag === 1 /* TEXT */) &&
|
|
1647
|
+
flag === 512 /* PatchFlags.NEED_PATCH */ ||
|
|
1648
|
+
flag === 1 /* PatchFlags.TEXT */) &&
|
|
1649
1649
|
getGeneratedPropsConstantType(child, context) >=
|
|
1650
|
-
2 /* CAN_HOIST */) {
|
|
1650
|
+
2 /* ConstantTypes.CAN_HOIST */) {
|
|
1651
1651
|
const props = getNodeProps(child);
|
|
1652
1652
|
if (props) {
|
|
1653
1653
|
codegenNode.props = context.hoist(props);
|
|
@@ -1659,14 +1659,14 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1659
1659
|
}
|
|
1660
1660
|
}
|
|
1661
1661
|
}
|
|
1662
|
-
else if (child.type === 12 /* TEXT_CALL */ &&
|
|
1663
|
-
getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
|
|
1662
|
+
else if (child.type === 12 /* NodeTypes.TEXT_CALL */ &&
|
|
1663
|
+
getConstantType(child.content, context) >= 2 /* ConstantTypes.CAN_HOIST */) {
|
|
1664
1664
|
child.codegenNode = context.hoist(child.codegenNode);
|
|
1665
1665
|
hoistedCount++;
|
|
1666
1666
|
}
|
|
1667
1667
|
// walk further
|
|
1668
|
-
if (child.type === 1 /* ELEMENT */) {
|
|
1669
|
-
const isComponent = child.tagType === 1 /* COMPONENT */;
|
|
1668
|
+
if (child.type === 1 /* NodeTypes.ELEMENT */) {
|
|
1669
|
+
const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
1670
1670
|
if (isComponent) {
|
|
1671
1671
|
context.scopes.vSlot++;
|
|
1672
1672
|
}
|
|
@@ -1675,11 +1675,11 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1675
1675
|
context.scopes.vSlot--;
|
|
1676
1676
|
}
|
|
1677
1677
|
}
|
|
1678
|
-
else if (child.type === 11 /* FOR */) {
|
|
1678
|
+
else if (child.type === 11 /* NodeTypes.FOR */) {
|
|
1679
1679
|
// Do not hoist v-for single child because it has to be a block
|
|
1680
1680
|
walk(child, context, child.children.length === 1);
|
|
1681
1681
|
}
|
|
1682
|
-
else if (child.type === 9 /* IF */) {
|
|
1682
|
+
else if (child.type === 9 /* NodeTypes.IF */) {
|
|
1683
1683
|
for (let i = 0; i < child.branches.length; i++) {
|
|
1684
1684
|
// Do not hoist v-if single child because it has to be a block
|
|
1685
1685
|
walk(child.branches[i], context, child.branches[i].children.length === 1);
|
|
@@ -1692,10 +1692,10 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1692
1692
|
// all children were hoisted - the entire children array is hoistable.
|
|
1693
1693
|
if (hoistedCount &&
|
|
1694
1694
|
hoistedCount === originalCount &&
|
|
1695
|
-
node.type === 1 /* ELEMENT */ &&
|
|
1696
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
1695
|
+
node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
1696
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
1697
1697
|
node.codegenNode &&
|
|
1698
|
-
node.codegenNode.type === 13 /* VNODE_CALL */ &&
|
|
1698
|
+
node.codegenNode.type === 13 /* NodeTypes.VNODE_CALL */ &&
|
|
1699
1699
|
shared.isArray(node.codegenNode.children)) {
|
|
1700
1700
|
node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
|
|
1701
1701
|
}
|
|
@@ -1703,35 +1703,35 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
1703
1703
|
function getConstantType(node, context) {
|
|
1704
1704
|
const { constantCache } = context;
|
|
1705
1705
|
switch (node.type) {
|
|
1706
|
-
case 1 /* ELEMENT */:
|
|
1707
|
-
if (node.tagType !== 0 /* ELEMENT */) {
|
|
1708
|
-
return 0 /* NOT_CONSTANT */;
|
|
1706
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
1707
|
+
if (node.tagType !== 0 /* ElementTypes.ELEMENT */) {
|
|
1708
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1709
1709
|
}
|
|
1710
1710
|
const cached = constantCache.get(node);
|
|
1711
1711
|
if (cached !== undefined) {
|
|
1712
1712
|
return cached;
|
|
1713
1713
|
}
|
|
1714
1714
|
const codegenNode = node.codegenNode;
|
|
1715
|
-
if (codegenNode.type !== 13 /* VNODE_CALL */) {
|
|
1716
|
-
return 0 /* NOT_CONSTANT */;
|
|
1715
|
+
if (codegenNode.type !== 13 /* NodeTypes.VNODE_CALL */) {
|
|
1716
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1717
1717
|
}
|
|
1718
1718
|
if (codegenNode.isBlock &&
|
|
1719
1719
|
node.tag !== 'svg' &&
|
|
1720
1720
|
node.tag !== 'foreignObject') {
|
|
1721
|
-
return 0 /* NOT_CONSTANT */;
|
|
1721
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1722
1722
|
}
|
|
1723
1723
|
const flag = getPatchFlag(codegenNode);
|
|
1724
1724
|
if (!flag) {
|
|
1725
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1725
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1726
1726
|
// Element itself has no patch flag. However we still need to check:
|
|
1727
1727
|
// 1. Even for a node with no patch flag, it is possible for it to contain
|
|
1728
1728
|
// non-hoistable expressions that refers to scope variables, e.g. compiler
|
|
1729
1729
|
// injected keys or cached event handlers. Therefore we need to always
|
|
1730
1730
|
// check the codegenNode's props to be sure.
|
|
1731
1731
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
1732
|
-
if (generatedPropsType === 0 /* NOT_CONSTANT */) {
|
|
1733
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1734
|
-
return 0 /* NOT_CONSTANT */;
|
|
1732
|
+
if (generatedPropsType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1733
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1734
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1735
1735
|
}
|
|
1736
1736
|
if (generatedPropsType < returnType) {
|
|
1737
1737
|
returnType = generatedPropsType;
|
|
@@ -1739,9 +1739,9 @@ function getConstantType(node, context) {
|
|
|
1739
1739
|
// 2. its children.
|
|
1740
1740
|
for (let i = 0; i < node.children.length; i++) {
|
|
1741
1741
|
const childType = getConstantType(node.children[i], context);
|
|
1742
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1743
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1744
|
-
return 0 /* NOT_CONSTANT */;
|
|
1742
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1743
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1744
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1745
1745
|
}
|
|
1746
1746
|
if (childType < returnType) {
|
|
1747
1747
|
returnType = childType;
|
|
@@ -1751,14 +1751,14 @@ function getConstantType(node, context) {
|
|
|
1751
1751
|
// type, check if any of the props can cause the type to be lowered
|
|
1752
1752
|
// we can skip can_patch because it's guaranteed by the absence of a
|
|
1753
1753
|
// patchFlag.
|
|
1754
|
-
if (returnType > 1 /* CAN_SKIP_PATCH */) {
|
|
1754
|
+
if (returnType > 1 /* ConstantTypes.CAN_SKIP_PATCH */) {
|
|
1755
1755
|
for (let i = 0; i < node.props.length; i++) {
|
|
1756
1756
|
const p = node.props[i];
|
|
1757
|
-
if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1757
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'bind' && p.exp) {
|
|
1758
1758
|
const expType = getConstantType(p.exp, context);
|
|
1759
|
-
if (expType === 0 /* NOT_CONSTANT */) {
|
|
1760
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1761
|
-
return 0 /* NOT_CONSTANT */;
|
|
1759
|
+
if (expType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1760
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1761
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1762
1762
|
}
|
|
1763
1763
|
if (expType < returnType) {
|
|
1764
1764
|
returnType = expType;
|
|
@@ -1773,9 +1773,9 @@ function getConstantType(node, context) {
|
|
|
1773
1773
|
// except set custom directives.
|
|
1774
1774
|
for (let i = 0; i < node.props.length; i++) {
|
|
1775
1775
|
const p = node.props[i];
|
|
1776
|
-
if (p.type === 7 /* DIRECTIVE */) {
|
|
1777
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1778
|
-
return 0 /* NOT_CONSTANT */;
|
|
1776
|
+
if (p.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
1777
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1778
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1779
1779
|
}
|
|
1780
1780
|
}
|
|
1781
1781
|
context.removeHelper(OPEN_BLOCK);
|
|
@@ -1787,31 +1787,31 @@ function getConstantType(node, context) {
|
|
|
1787
1787
|
return returnType;
|
|
1788
1788
|
}
|
|
1789
1789
|
else {
|
|
1790
|
-
constantCache.set(node, 0 /* NOT_CONSTANT */);
|
|
1791
|
-
return 0 /* NOT_CONSTANT */;
|
|
1792
|
-
}
|
|
1793
|
-
case 2 /* TEXT */:
|
|
1794
|
-
case 3 /* COMMENT */:
|
|
1795
|
-
return 3 /* CAN_STRINGIFY */;
|
|
1796
|
-
case 9 /* IF */:
|
|
1797
|
-
case 11 /* FOR */:
|
|
1798
|
-
case 10 /* IF_BRANCH */:
|
|
1799
|
-
return 0 /* NOT_CONSTANT */;
|
|
1800
|
-
case 5 /* INTERPOLATION */:
|
|
1801
|
-
case 12 /* TEXT_CALL */:
|
|
1790
|
+
constantCache.set(node, 0 /* ConstantTypes.NOT_CONSTANT */);
|
|
1791
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1792
|
+
}
|
|
1793
|
+
case 2 /* NodeTypes.TEXT */:
|
|
1794
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
1795
|
+
return 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1796
|
+
case 9 /* NodeTypes.IF */:
|
|
1797
|
+
case 11 /* NodeTypes.FOR */:
|
|
1798
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
1799
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1800
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
1801
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
1802
1802
|
return getConstantType(node.content, context);
|
|
1803
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
1803
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
1804
1804
|
return node.constType;
|
|
1805
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
1806
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1805
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
1806
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1807
1807
|
for (let i = 0; i < node.children.length; i++) {
|
|
1808
1808
|
const child = node.children[i];
|
|
1809
1809
|
if (shared.isString(child) || shared.isSymbol(child)) {
|
|
1810
1810
|
continue;
|
|
1811
1811
|
}
|
|
1812
1812
|
const childType = getConstantType(child, context);
|
|
1813
|
-
if (childType === 0 /* NOT_CONSTANT */) {
|
|
1814
|
-
return 0 /* NOT_CONSTANT */;
|
|
1813
|
+
if (childType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1814
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1815
1815
|
}
|
|
1816
1816
|
else if (childType < returnType) {
|
|
1817
1817
|
returnType = childType;
|
|
@@ -1819,7 +1819,7 @@ function getConstantType(node, context) {
|
|
|
1819
1819
|
}
|
|
1820
1820
|
return returnType;
|
|
1821
1821
|
default:
|
|
1822
|
-
return 0 /* NOT_CONSTANT */;
|
|
1822
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1823
1823
|
}
|
|
1824
1824
|
}
|
|
1825
1825
|
const allowHoistedHelperSet = new Set([
|
|
@@ -1829,48 +1829,48 @@ const allowHoistedHelperSet = new Set([
|
|
|
1829
1829
|
GUARD_REACTIVE_PROPS
|
|
1830
1830
|
]);
|
|
1831
1831
|
function getConstantTypeOfHelperCall(value, context) {
|
|
1832
|
-
if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
|
|
1832
|
+
if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */ &&
|
|
1833
1833
|
!shared.isString(value.callee) &&
|
|
1834
1834
|
allowHoistedHelperSet.has(value.callee)) {
|
|
1835
1835
|
const arg = value.arguments[0];
|
|
1836
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1836
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1837
1837
|
return getConstantType(arg, context);
|
|
1838
1838
|
}
|
|
1839
|
-
else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1839
|
+
else if (arg.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1840
1840
|
// in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
|
|
1841
1841
|
return getConstantTypeOfHelperCall(arg, context);
|
|
1842
1842
|
}
|
|
1843
1843
|
}
|
|
1844
|
-
return 0 /* NOT_CONSTANT */;
|
|
1844
|
+
return 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1845
1845
|
}
|
|
1846
1846
|
function getGeneratedPropsConstantType(node, context) {
|
|
1847
|
-
let returnType = 3 /* CAN_STRINGIFY */;
|
|
1847
|
+
let returnType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1848
1848
|
const props = getNodeProps(node);
|
|
1849
|
-
if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
|
|
1849
|
+
if (props && props.type === 15 /* NodeTypes.JS_OBJECT_EXPRESSION */) {
|
|
1850
1850
|
const { properties } = props;
|
|
1851
1851
|
for (let i = 0; i < properties.length; i++) {
|
|
1852
1852
|
const { key, value } = properties[i];
|
|
1853
1853
|
const keyType = getConstantType(key, context);
|
|
1854
|
-
if (keyType === 0 /* NOT_CONSTANT */) {
|
|
1854
|
+
if (keyType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1855
1855
|
return keyType;
|
|
1856
1856
|
}
|
|
1857
1857
|
if (keyType < returnType) {
|
|
1858
1858
|
returnType = keyType;
|
|
1859
1859
|
}
|
|
1860
1860
|
let valueType;
|
|
1861
|
-
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1861
|
+
if (value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1862
1862
|
valueType = getConstantType(value, context);
|
|
1863
1863
|
}
|
|
1864
|
-
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1864
|
+
else if (value.type === 14 /* NodeTypes.JS_CALL_EXPRESSION */) {
|
|
1865
1865
|
// some helper calls can be hoisted,
|
|
1866
1866
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1867
1867
|
// in this case we need to respect the ConstantType of the helper's arguments
|
|
1868
1868
|
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1869
1869
|
}
|
|
1870
1870
|
else {
|
|
1871
|
-
valueType = 0 /* NOT_CONSTANT */;
|
|
1871
|
+
valueType = 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
1872
1872
|
}
|
|
1873
|
-
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1873
|
+
if (valueType === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
1874
1874
|
return valueType;
|
|
1875
1875
|
}
|
|
1876
1876
|
if (valueType < returnType) {
|
|
@@ -1882,7 +1882,7 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1882
1882
|
}
|
|
1883
1883
|
function getNodeProps(node) {
|
|
1884
1884
|
const codegenNode = node.codegenNode;
|
|
1885
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
1885
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
1886
1886
|
return codegenNode.props;
|
|
1887
1887
|
}
|
|
1888
1888
|
}
|
|
@@ -1992,7 +1992,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
1992
1992
|
else if (exp.identifiers) {
|
|
1993
1993
|
exp.identifiers.forEach(addId);
|
|
1994
1994
|
}
|
|
1995
|
-
else if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1995
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
1996
1996
|
addId(exp.content);
|
|
1997
1997
|
}
|
|
1998
1998
|
}
|
|
@@ -2005,7 +2005,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
2005
2005
|
else if (exp.identifiers) {
|
|
2006
2006
|
exp.identifiers.forEach(removeId);
|
|
2007
2007
|
}
|
|
2008
|
-
else if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2008
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2009
2009
|
removeId(exp.content);
|
|
2010
2010
|
}
|
|
2011
2011
|
}
|
|
@@ -2014,7 +2014,7 @@ function createTransformContext(root, { filename = '', prefixIdentifiers = false
|
|
|
2014
2014
|
if (shared.isString(exp))
|
|
2015
2015
|
exp = createSimpleExpression(exp);
|
|
2016
2016
|
context.hoists.push(exp);
|
|
2017
|
-
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
|
|
2017
|
+
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* ConstantTypes.CAN_HOIST */);
|
|
2018
2018
|
identifier.hoisted = exp;
|
|
2019
2019
|
return identifier;
|
|
2020
2020
|
},
|
|
@@ -2068,7 +2068,7 @@ function createRootCodegen(root, context) {
|
|
|
2068
2068
|
// single element root is never hoisted so codegenNode will never be
|
|
2069
2069
|
// SimpleExpressionNode
|
|
2070
2070
|
const codegenNode = child.codegenNode;
|
|
2071
|
-
if (codegenNode.type === 13 /* VNODE_CALL */) {
|
|
2071
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
2072
2072
|
makeBlock(codegenNode, context);
|
|
2073
2073
|
}
|
|
2074
2074
|
root.codegenNode = codegenNode;
|
|
@@ -2082,8 +2082,8 @@ function createRootCodegen(root, context) {
|
|
|
2082
2082
|
}
|
|
2083
2083
|
else if (children.length > 1) {
|
|
2084
2084
|
// root has multiple nodes - return a fragment block.
|
|
2085
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
2086
|
-
shared.PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
2085
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
2086
|
+
shared.PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
2087
2087
|
root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
2088
2088
|
}
|
|
2089
2089
|
else ;
|
|
@@ -2128,29 +2128,29 @@ function traverseNode(node, context) {
|
|
|
2128
2128
|
}
|
|
2129
2129
|
}
|
|
2130
2130
|
switch (node.type) {
|
|
2131
|
-
case 3 /* COMMENT */:
|
|
2131
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2132
2132
|
if (!context.ssr) {
|
|
2133
2133
|
// inject import for the Comment symbol, which is needed for creating
|
|
2134
2134
|
// comment nodes with `createVNode`
|
|
2135
2135
|
context.helper(CREATE_COMMENT);
|
|
2136
2136
|
}
|
|
2137
2137
|
break;
|
|
2138
|
-
case 5 /* INTERPOLATION */:
|
|
2138
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2139
2139
|
// no need to traverse, but we need to inject toString helper
|
|
2140
2140
|
if (!context.ssr) {
|
|
2141
2141
|
context.helper(TO_DISPLAY_STRING);
|
|
2142
2142
|
}
|
|
2143
2143
|
break;
|
|
2144
2144
|
// for container types, further traverse downwards
|
|
2145
|
-
case 9 /* IF */:
|
|
2145
|
+
case 9 /* NodeTypes.IF */:
|
|
2146
2146
|
for (let i = 0; i < node.branches.length; i++) {
|
|
2147
2147
|
traverseNode(node.branches[i], context);
|
|
2148
2148
|
}
|
|
2149
2149
|
break;
|
|
2150
|
-
case 10 /* IF_BRANCH */:
|
|
2151
|
-
case 11 /* FOR */:
|
|
2152
|
-
case 1 /* ELEMENT */:
|
|
2153
|
-
case 0 /* ROOT */:
|
|
2150
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
2151
|
+
case 11 /* NodeTypes.FOR */:
|
|
2152
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2153
|
+
case 0 /* NodeTypes.ROOT */:
|
|
2154
2154
|
traverseChildren(node, context);
|
|
2155
2155
|
break;
|
|
2156
2156
|
}
|
|
@@ -2166,17 +2166,17 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
2166
2166
|
? (n) => n === name
|
|
2167
2167
|
: (n) => name.test(n);
|
|
2168
2168
|
return (node, context) => {
|
|
2169
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
2169
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
2170
2170
|
const { props } = node;
|
|
2171
2171
|
// structural directive transforms are not concerned with slots
|
|
2172
2172
|
// as they are handled separately in vSlot.ts
|
|
2173
|
-
if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
|
|
2173
|
+
if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(isVSlot)) {
|
|
2174
2174
|
return;
|
|
2175
2175
|
}
|
|
2176
2176
|
const exitFns = [];
|
|
2177
2177
|
for (let i = 0; i < props.length; i++) {
|
|
2178
2178
|
const prop = props[i];
|
|
2179
|
-
if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
|
|
2179
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
|
|
2180
2180
|
// structural directives are removed to avoid infinite recursion
|
|
2181
2181
|
// also we remove them *before* applying so that it can further
|
|
2182
2182
|
// traverse itself in case it moves the node around
|
|
@@ -2224,7 +2224,7 @@ function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode
|
|
|
2224
2224
|
if (context.map) {
|
|
2225
2225
|
if (node) {
|
|
2226
2226
|
let name;
|
|
2227
|
-
if (node.type === 4 /* SIMPLE_EXPRESSION */ && !node.isStatic) {
|
|
2227
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !node.isStatic) {
|
|
2228
2228
|
const content = node.content.replace(/^_ctx\./, '');
|
|
2229
2229
|
if (content !== node.content && isSimpleIdentifier(content)) {
|
|
2230
2230
|
name = content;
|
|
@@ -2500,7 +2500,7 @@ function genHoists(hoists, context) {
|
|
|
2500
2500
|
for (let i = 0; i < hoists.length; i++) {
|
|
2501
2501
|
const exp = hoists[i];
|
|
2502
2502
|
if (exp) {
|
|
2503
|
-
const needScopeIdWrapper = genScopeId && exp.type === 13 /* VNODE_CALL */;
|
|
2503
|
+
const needScopeIdWrapper = genScopeId && exp.type === 13 /* NodeTypes.VNODE_CALL */;
|
|
2504
2504
|
push(`const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`);
|
|
2505
2505
|
genNode(exp, context);
|
|
2506
2506
|
if (needScopeIdWrapper) {
|
|
@@ -2524,10 +2524,10 @@ function genImports(importsOptions, context) {
|
|
|
2524
2524
|
}
|
|
2525
2525
|
function isText$1(n) {
|
|
2526
2526
|
return (shared.isString(n) ||
|
|
2527
|
-
n.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
2528
|
-
n.type === 2 /* TEXT */ ||
|
|
2529
|
-
n.type === 5 /* INTERPOLATION */ ||
|
|
2530
|
-
n.type === 8 /* COMPOUND_EXPRESSION */);
|
|
2527
|
+
n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
2528
|
+
n.type === 2 /* NodeTypes.TEXT */ ||
|
|
2529
|
+
n.type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
2530
|
+
n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
|
|
2531
2531
|
}
|
|
2532
2532
|
function genNodeListAsArray(nodes, context) {
|
|
2533
2533
|
const multilines = nodes.length > 3 ||
|
|
@@ -2572,67 +2572,67 @@ function genNode(node, context) {
|
|
|
2572
2572
|
return;
|
|
2573
2573
|
}
|
|
2574
2574
|
switch (node.type) {
|
|
2575
|
-
case 1 /* ELEMENT */:
|
|
2576
|
-
case 9 /* IF */:
|
|
2577
|
-
case 11 /* FOR */:
|
|
2575
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
2576
|
+
case 9 /* NodeTypes.IF */:
|
|
2577
|
+
case 11 /* NodeTypes.FOR */:
|
|
2578
2578
|
genNode(node.codegenNode, context);
|
|
2579
2579
|
break;
|
|
2580
|
-
case 2 /* TEXT */:
|
|
2580
|
+
case 2 /* NodeTypes.TEXT */:
|
|
2581
2581
|
genText(node, context);
|
|
2582
2582
|
break;
|
|
2583
|
-
case 4 /* SIMPLE_EXPRESSION */:
|
|
2583
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
2584
2584
|
genExpression(node, context);
|
|
2585
2585
|
break;
|
|
2586
|
-
case 5 /* INTERPOLATION */:
|
|
2586
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
2587
2587
|
genInterpolation(node, context);
|
|
2588
2588
|
break;
|
|
2589
|
-
case 12 /* TEXT_CALL */:
|
|
2589
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
2590
2590
|
genNode(node.codegenNode, context);
|
|
2591
2591
|
break;
|
|
2592
|
-
case 8 /* COMPOUND_EXPRESSION */:
|
|
2592
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
2593
2593
|
genCompoundExpression(node, context);
|
|
2594
2594
|
break;
|
|
2595
|
-
case 3 /* COMMENT */:
|
|
2595
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
2596
2596
|
genComment(node, context);
|
|
2597
2597
|
break;
|
|
2598
|
-
case 13 /* VNODE_CALL */:
|
|
2598
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
2599
2599
|
genVNodeCall(node, context);
|
|
2600
2600
|
break;
|
|
2601
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
2601
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
2602
2602
|
genCallExpression(node, context);
|
|
2603
2603
|
break;
|
|
2604
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
2604
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
2605
2605
|
genObjectExpression(node, context);
|
|
2606
2606
|
break;
|
|
2607
|
-
case 17 /* JS_ARRAY_EXPRESSION */:
|
|
2607
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
2608
2608
|
genArrayExpression(node, context);
|
|
2609
2609
|
break;
|
|
2610
|
-
case 18 /* JS_FUNCTION_EXPRESSION */:
|
|
2610
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
2611
2611
|
genFunctionExpression(node, context);
|
|
2612
2612
|
break;
|
|
2613
|
-
case 19 /* JS_CONDITIONAL_EXPRESSION */:
|
|
2613
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
2614
2614
|
genConditionalExpression(node, context);
|
|
2615
2615
|
break;
|
|
2616
|
-
case 20 /* JS_CACHE_EXPRESSION */:
|
|
2616
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
2617
2617
|
genCacheExpression(node, context);
|
|
2618
2618
|
break;
|
|
2619
|
-
case 21 /* JS_BLOCK_STATEMENT */:
|
|
2619
|
+
case 21 /* NodeTypes.JS_BLOCK_STATEMENT */:
|
|
2620
2620
|
genNodeList(node.body, context, true, false);
|
|
2621
2621
|
break;
|
|
2622
2622
|
// SSR only types
|
|
2623
|
-
case 22 /* JS_TEMPLATE_LITERAL */:
|
|
2623
|
+
case 22 /* NodeTypes.JS_TEMPLATE_LITERAL */:
|
|
2624
2624
|
genTemplateLiteral(node, context);
|
|
2625
2625
|
break;
|
|
2626
|
-
case 23 /* JS_IF_STATEMENT */:
|
|
2626
|
+
case 23 /* NodeTypes.JS_IF_STATEMENT */:
|
|
2627
2627
|
genIfStatement(node, context);
|
|
2628
2628
|
break;
|
|
2629
|
-
case 24 /* JS_ASSIGNMENT_EXPRESSION */:
|
|
2629
|
+
case 24 /* NodeTypes.JS_ASSIGNMENT_EXPRESSION */:
|
|
2630
2630
|
genAssignmentExpression(node, context);
|
|
2631
2631
|
break;
|
|
2632
|
-
case 25 /* JS_SEQUENCE_EXPRESSION */:
|
|
2632
|
+
case 25 /* NodeTypes.JS_SEQUENCE_EXPRESSION */:
|
|
2633
2633
|
genSequenceExpression(node, context);
|
|
2634
2634
|
break;
|
|
2635
|
-
case 26 /* JS_RETURN_STATEMENT */:
|
|
2635
|
+
case 26 /* NodeTypes.JS_RETURN_STATEMENT */:
|
|
2636
2636
|
genReturnStatement(node, context);
|
|
2637
2637
|
break;
|
|
2638
2638
|
}
|
|
@@ -2665,7 +2665,7 @@ function genCompoundExpression(node, context) {
|
|
|
2665
2665
|
}
|
|
2666
2666
|
function genExpressionAsPropertyKey(node, context) {
|
|
2667
2667
|
const { push } = context;
|
|
2668
|
-
if (node.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
2668
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
2669
2669
|
push(`[`);
|
|
2670
2670
|
genCompoundExpression(node, context);
|
|
2671
2671
|
push(`]`);
|
|
@@ -2742,7 +2742,7 @@ function genObjectExpression(node, context) {
|
|
|
2742
2742
|
return;
|
|
2743
2743
|
}
|
|
2744
2744
|
const multilines = properties.length > 1 ||
|
|
2745
|
-
(properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
|
|
2745
|
+
(properties.some(p => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */));
|
|
2746
2746
|
push(multilines ? `{` : `{ `);
|
|
2747
2747
|
multilines && indent();
|
|
2748
2748
|
for (let i = 0; i < properties.length; i++) {
|
|
@@ -2811,7 +2811,7 @@ function genFunctionExpression(node, context) {
|
|
|
2811
2811
|
function genConditionalExpression(node, context) {
|
|
2812
2812
|
const { test, consequent, alternate, newline: needNewline } = node;
|
|
2813
2813
|
const { push, indent, deindent, newline } = context;
|
|
2814
|
-
if (test.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
2814
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
2815
2815
|
const needsParens = !isSimpleIdentifier(test.content);
|
|
2816
2816
|
needsParens && push(`(`);
|
|
2817
2817
|
genExpression(test, context);
|
|
@@ -2831,7 +2831,7 @@ function genConditionalExpression(node, context) {
|
|
|
2831
2831
|
needNewline && newline();
|
|
2832
2832
|
needNewline || push(` `);
|
|
2833
2833
|
push(`: `);
|
|
2834
|
-
const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
|
|
2834
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
2835
2835
|
if (!isNested) {
|
|
2836
2836
|
context.indentLevel++;
|
|
2837
2837
|
}
|
|
@@ -2895,7 +2895,7 @@ function genIfStatement(node, context) {
|
|
|
2895
2895
|
push(`}`);
|
|
2896
2896
|
if (alternate) {
|
|
2897
2897
|
push(` else `);
|
|
2898
|
-
if (alternate.type === 23 /* JS_IF_STATEMENT */) {
|
|
2898
|
+
if (alternate.type === 23 /* NodeTypes.JS_IF_STATEMENT */) {
|
|
2899
2899
|
genIfStatement(alternate, context);
|
|
2900
2900
|
}
|
|
2901
2901
|
else {
|
|
@@ -3252,27 +3252,27 @@ function isReferenced(node, parent, grandparent) {
|
|
|
3252
3252
|
|
|
3253
3253
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
3254
3254
|
const transformExpression = (node, context) => {
|
|
3255
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
3255
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
3256
3256
|
node.content = processExpression(node.content, context);
|
|
3257
3257
|
}
|
|
3258
|
-
else if (node.type === 1 /* ELEMENT */) {
|
|
3258
|
+
else if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3259
3259
|
// handle directives on element
|
|
3260
3260
|
for (let i = 0; i < node.props.length; i++) {
|
|
3261
3261
|
const dir = node.props[i];
|
|
3262
3262
|
// do not process for v-on & v-for since they are special handled
|
|
3263
|
-
if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
|
|
3263
|
+
if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
|
|
3264
3264
|
const exp = dir.exp;
|
|
3265
3265
|
const arg = dir.arg;
|
|
3266
3266
|
// do not process exp if this is v-on:arg - we need special handling
|
|
3267
3267
|
// for wrapping inline statements.
|
|
3268
3268
|
if (exp &&
|
|
3269
|
-
exp.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3269
|
+
exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3270
3270
|
!(dir.name === 'on' && arg)) {
|
|
3271
3271
|
dir.exp = processExpression(exp, context,
|
|
3272
3272
|
// slot args must be processed as function params
|
|
3273
3273
|
dir.name === 'slot');
|
|
3274
3274
|
}
|
|
3275
|
-
if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
3275
|
+
if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
|
|
3276
3276
|
dir.arg = processExpression(arg, context);
|
|
3277
3277
|
}
|
|
3278
3278
|
}
|
|
@@ -3301,15 +3301,15 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3301
3301
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
3302
3302
|
// ({ x } = y)
|
|
3303
3303
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
3304
|
-
if (type === "setup-const" /* SETUP_CONST */ ||
|
|
3305
|
-
type === "setup-reactive-const" /* SETUP_REACTIVE_CONST */ ||
|
|
3304
|
+
if (type === "setup-const" /* BindingTypes.SETUP_CONST */ ||
|
|
3305
|
+
type === "setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */ ||
|
|
3306
3306
|
localVars[raw]) {
|
|
3307
3307
|
return raw;
|
|
3308
3308
|
}
|
|
3309
|
-
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
3309
|
+
else if (type === "setup-ref" /* BindingTypes.SETUP_REF */) {
|
|
3310
3310
|
return `${raw}.value`;
|
|
3311
3311
|
}
|
|
3312
|
-
else if (type === "setup-maybe-ref" /* SETUP_MAYBE_REF */) {
|
|
3312
|
+
else if (type === "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */) {
|
|
3313
3313
|
// const binding that may or may not be ref
|
|
3314
3314
|
// if it's not a ref, then assignments don't make sense -
|
|
3315
3315
|
// so we ignore the non-ref assignment case and generate code
|
|
@@ -3318,7 +3318,7 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3318
3318
|
? `${raw}.value`
|
|
3319
3319
|
: `${context.helperString(UNREF)}(${raw})`;
|
|
3320
3320
|
}
|
|
3321
|
-
else if (type === "setup-let" /* SETUP_LET */) {
|
|
3321
|
+
else if (type === "setup-let" /* BindingTypes.SETUP_LET */) {
|
|
3322
3322
|
if (isAssignmentLVal) {
|
|
3323
3323
|
// let binding.
|
|
3324
3324
|
// this is a bit more tricky as we need to cover the case where
|
|
@@ -3354,12 +3354,12 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3354
3354
|
return `${context.helperString(UNREF)}(${raw})`;
|
|
3355
3355
|
}
|
|
3356
3356
|
}
|
|
3357
|
-
else if (type === "props" /* PROPS */) {
|
|
3357
|
+
else if (type === "props" /* BindingTypes.PROPS */) {
|
|
3358
3358
|
// use __props which is generated by compileScript so in ts mode
|
|
3359
3359
|
// it gets correct type
|
|
3360
3360
|
return shared.genPropsAccessExp(raw);
|
|
3361
3361
|
}
|
|
3362
|
-
else if (type === "props-aliased" /* PROPS_ALIASED */) {
|
|
3362
|
+
else if (type === "props-aliased" /* BindingTypes.PROPS_ALIASED */) {
|
|
3363
3363
|
// prop with a different local alias (from defineProps() destructure)
|
|
3364
3364
|
return shared.genPropsAccessExp(bindingMetadata.__propsAliases[raw]);
|
|
3365
3365
|
}
|
|
@@ -3369,7 +3369,7 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3369
3369
|
// setup bindings in non-inline mode
|
|
3370
3370
|
return `$setup.${raw}`;
|
|
3371
3371
|
}
|
|
3372
|
-
else if (type === "props-aliased" /* PROPS_ALIASED */) {
|
|
3372
|
+
else if (type === "props-aliased" /* BindingTypes.PROPS_ALIASED */) {
|
|
3373
3373
|
return `$props['${bindingMetadata.__propsAliases[raw]}']`;
|
|
3374
3374
|
}
|
|
3375
3375
|
else if (type) {
|
|
@@ -3390,17 +3390,17 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3390
3390
|
if (!asParams && !isScopeVarReference && !isAllowedGlobal && !isLiteral) {
|
|
3391
3391
|
// const bindings exposed from setup can be skipped for patching but
|
|
3392
3392
|
// cannot be hoisted to module scope
|
|
3393
|
-
if (bindingMetadata[node.content] === "setup-const" /* SETUP_CONST */) {
|
|
3394
|
-
node.constType = 1 /* CAN_SKIP_PATCH */;
|
|
3393
|
+
if (bindingMetadata[node.content] === "setup-const" /* BindingTypes.SETUP_CONST */) {
|
|
3394
|
+
node.constType = 1 /* ConstantTypes.CAN_SKIP_PATCH */;
|
|
3395
3395
|
}
|
|
3396
3396
|
node.content = rewriteIdentifier(rawExp);
|
|
3397
3397
|
}
|
|
3398
3398
|
else if (!isScopeVarReference) {
|
|
3399
3399
|
if (isLiteral) {
|
|
3400
|
-
node.constType = 3 /* CAN_STRINGIFY */;
|
|
3400
|
+
node.constType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
3401
3401
|
}
|
|
3402
3402
|
else {
|
|
3403
|
-
node.constType = 2 /* CAN_HOIST */;
|
|
3403
|
+
node.constType = 2 /* ConstantTypes.CAN_HOIST */;
|
|
3404
3404
|
}
|
|
3405
3405
|
}
|
|
3406
3406
|
return node;
|
|
@@ -3420,7 +3420,7 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3420
3420
|
}).program;
|
|
3421
3421
|
}
|
|
3422
3422
|
catch (e) {
|
|
3423
|
-
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, e.message));
|
|
3423
|
+
context.onError(createCompilerError(44 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, e.message));
|
|
3424
3424
|
return node;
|
|
3425
3425
|
}
|
|
3426
3426
|
const ids = [];
|
|
@@ -3474,7 +3474,7 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3474
3474
|
source,
|
|
3475
3475
|
start: advancePositionWithClone(node.loc.start, source, start),
|
|
3476
3476
|
end: advancePositionWithClone(node.loc.start, source, end)
|
|
3477
|
-
}, id.isConstant ? 3 /* CAN_STRINGIFY */ : 0 /* NOT_CONSTANT */));
|
|
3477
|
+
}, id.isConstant ? 3 /* ConstantTypes.CAN_STRINGIFY */ : 0 /* ConstantTypes.NOT_CONSTANT */));
|
|
3478
3478
|
if (i === ids.length - 1 && end < rawExp.length) {
|
|
3479
3479
|
children.push(rawExp.slice(end));
|
|
3480
3480
|
}
|
|
@@ -3486,8 +3486,8 @@ asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
|
3486
3486
|
else {
|
|
3487
3487
|
ret = node;
|
|
3488
3488
|
ret.constType = bailConstant
|
|
3489
|
-
? 0 /* NOT_CONSTANT */
|
|
3490
|
-
: 3 /* CAN_STRINGIFY */;
|
|
3489
|
+
? 0 /* ConstantTypes.NOT_CONSTANT */
|
|
3490
|
+
: 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
3491
3491
|
}
|
|
3492
3492
|
ret.identifiers = Object.keys(knownIds);
|
|
3493
3493
|
return ret;
|
|
@@ -3507,7 +3507,7 @@ function stringifyExpression(exp) {
|
|
|
3507
3507
|
if (shared.isString(exp)) {
|
|
3508
3508
|
return exp;
|
|
3509
3509
|
}
|
|
3510
|
-
else if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
3510
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
3511
3511
|
return exp.content;
|
|
3512
3512
|
}
|
|
3513
3513
|
else {
|
|
@@ -3527,7 +3527,7 @@ const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (n
|
|
|
3527
3527
|
let key = 0;
|
|
3528
3528
|
while (i-- >= 0) {
|
|
3529
3529
|
const sibling = siblings[i];
|
|
3530
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3530
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
3531
3531
|
key += sibling.branches.length;
|
|
3532
3532
|
}
|
|
3533
3533
|
}
|
|
@@ -3550,7 +3550,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3550
3550
|
if (dir.name !== 'else' &&
|
|
3551
3551
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
3552
3552
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3553
|
-
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3553
|
+
context.onError(createCompilerError(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3554
3554
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
3555
3555
|
}
|
|
3556
3556
|
if (context.prefixIdentifiers && dir.exp) {
|
|
@@ -3561,7 +3561,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3561
3561
|
if (dir.name === 'if') {
|
|
3562
3562
|
const branch = createIfBranch(node, dir);
|
|
3563
3563
|
const ifNode = {
|
|
3564
|
-
type: 9 /* IF */,
|
|
3564
|
+
type: 9 /* NodeTypes.IF */,
|
|
3565
3565
|
loc: node.loc,
|
|
3566
3566
|
branches: [branch]
|
|
3567
3567
|
};
|
|
@@ -3577,16 +3577,16 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3577
3577
|
while (i-- >= -1) {
|
|
3578
3578
|
const sibling = siblings[i];
|
|
3579
3579
|
if (sibling &&
|
|
3580
|
-
sibling.type === 2 /* TEXT */ &&
|
|
3580
|
+
sibling.type === 2 /* NodeTypes.TEXT */ &&
|
|
3581
3581
|
!sibling.content.trim().length) {
|
|
3582
3582
|
context.removeNode(sibling);
|
|
3583
3583
|
continue;
|
|
3584
3584
|
}
|
|
3585
|
-
if (sibling && sibling.type === 9 /* IF */) {
|
|
3585
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
3586
3586
|
// Check if v-else was followed by v-else-if
|
|
3587
3587
|
if (dir.name === 'else-if' &&
|
|
3588
3588
|
sibling.branches[sibling.branches.length - 1].condition === undefined) {
|
|
3589
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3589
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3590
3590
|
}
|
|
3591
3591
|
// move the node to the if node's branches
|
|
3592
3592
|
context.removeNode();
|
|
@@ -3597,7 +3597,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3597
3597
|
if (key) {
|
|
3598
3598
|
sibling.branches.forEach(({ userKey }) => {
|
|
3599
3599
|
if (isSameKey(userKey, key)) {
|
|
3600
|
-
context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3600
|
+
context.onError(createCompilerError(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3601
3601
|
}
|
|
3602
3602
|
});
|
|
3603
3603
|
}
|
|
@@ -3615,16 +3615,16 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3615
3615
|
context.currentNode = null;
|
|
3616
3616
|
}
|
|
3617
3617
|
else {
|
|
3618
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3618
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3619
3619
|
}
|
|
3620
3620
|
break;
|
|
3621
3621
|
}
|
|
3622
3622
|
}
|
|
3623
3623
|
}
|
|
3624
3624
|
function createIfBranch(node, dir) {
|
|
3625
|
-
const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
|
|
3625
|
+
const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
|
|
3626
3626
|
return {
|
|
3627
|
-
type: 10 /* IF_BRANCH */,
|
|
3627
|
+
type: 10 /* NodeTypes.IF_BRANCH */,
|
|
3628
3628
|
loc: node.loc,
|
|
3629
3629
|
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
3630
3630
|
children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
|
|
@@ -3648,20 +3648,20 @@ function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
|
3648
3648
|
}
|
|
3649
3649
|
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
3650
3650
|
const { helper } = context;
|
|
3651
|
-
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
|
|
3651
|
+
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* ConstantTypes.CAN_HOIST */));
|
|
3652
3652
|
const { children } = branch;
|
|
3653
3653
|
const firstChild = children[0];
|
|
3654
|
-
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
|
|
3654
|
+
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
|
|
3655
3655
|
if (needFragmentWrapper) {
|
|
3656
|
-
if (children.length === 1 && firstChild.type === 11 /* FOR */) {
|
|
3656
|
+
if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
|
|
3657
3657
|
// optimize away nested fragments when child is a ForNode
|
|
3658
3658
|
const vnodeCall = firstChild.codegenNode;
|
|
3659
3659
|
injectProp(vnodeCall, keyProperty, context);
|
|
3660
3660
|
return vnodeCall;
|
|
3661
3661
|
}
|
|
3662
3662
|
else {
|
|
3663
|
-
let patchFlag = 64 /* STABLE_FRAGMENT */;
|
|
3664
|
-
shared.PatchFlagNames[64 /* STABLE_FRAGMENT */];
|
|
3663
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
3664
|
+
shared.PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
3665
3665
|
return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (``), undefined, undefined, true, false, false /* isComponent */, branch.loc);
|
|
3666
3666
|
}
|
|
3667
3667
|
}
|
|
@@ -3669,7 +3669,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
3669
3669
|
const ret = firstChild.codegenNode;
|
|
3670
3670
|
const vnodeCall = getMemoedVNodeCall(ret);
|
|
3671
3671
|
// Change createVNode to createBlock.
|
|
3672
|
-
if (vnodeCall.type === 13 /* VNODE_CALL */) {
|
|
3672
|
+
if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
3673
3673
|
makeBlock(vnodeCall, context);
|
|
3674
3674
|
}
|
|
3675
3675
|
// inject branch key
|
|
@@ -3681,7 +3681,7 @@ function isSameKey(a, b) {
|
|
|
3681
3681
|
if (!a || a.type !== b.type) {
|
|
3682
3682
|
return false;
|
|
3683
3683
|
}
|
|
3684
|
-
if (a.type === 6 /* ATTRIBUTE */) {
|
|
3684
|
+
if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3685
3685
|
if (a.value.content !== b.value.content) {
|
|
3686
3686
|
return false;
|
|
3687
3687
|
}
|
|
@@ -3693,7 +3693,7 @@ function isSameKey(a, b) {
|
|
|
3693
3693
|
if (exp.type !== branchExp.type) {
|
|
3694
3694
|
return false;
|
|
3695
3695
|
}
|
|
3696
|
-
if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
|
|
3696
|
+
if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
3697
3697
|
exp.isStatic !== branchExp.isStatic ||
|
|
3698
3698
|
exp.content !== branchExp.content) {
|
|
3699
3699
|
return false;
|
|
@@ -3703,15 +3703,15 @@ function isSameKey(a, b) {
|
|
|
3703
3703
|
}
|
|
3704
3704
|
function getParentCondition(node) {
|
|
3705
3705
|
while (true) {
|
|
3706
|
-
if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3707
|
-
if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
3706
|
+
if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3707
|
+
if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
3708
3708
|
node = node.alternate;
|
|
3709
3709
|
}
|
|
3710
3710
|
else {
|
|
3711
3711
|
return node;
|
|
3712
3712
|
}
|
|
3713
3713
|
}
|
|
3714
|
-
else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
|
|
3714
|
+
else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
3715
3715
|
node = node.value;
|
|
3716
3716
|
}
|
|
3717
3717
|
}
|
|
@@ -3729,7 +3729,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3729
3729
|
const memo = findDir(node, 'memo');
|
|
3730
3730
|
const keyProp = findProp(node, `key`);
|
|
3731
3731
|
const keyExp = keyProp &&
|
|
3732
|
-
(keyProp.type === 6 /* ATTRIBUTE */
|
|
3732
|
+
(keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
3733
3733
|
? createSimpleExpression(keyProp.value.content, true)
|
|
3734
3734
|
: keyProp.exp);
|
|
3735
3735
|
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
|
|
@@ -3741,17 +3741,17 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3741
3741
|
if (memo) {
|
|
3742
3742
|
memo.exp = processExpression(memo.exp, context);
|
|
3743
3743
|
}
|
|
3744
|
-
if (keyProperty && keyProp.type !== 6 /* ATTRIBUTE */) {
|
|
3744
|
+
if (keyProperty && keyProp.type !== 6 /* NodeTypes.ATTRIBUTE */) {
|
|
3745
3745
|
keyProperty.value = processExpression(keyProperty.value, context);
|
|
3746
3746
|
}
|
|
3747
3747
|
}
|
|
3748
|
-
const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
3749
|
-
forNode.source.constType > 0 /* NOT_CONSTANT */;
|
|
3748
|
+
const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
3749
|
+
forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
3750
3750
|
const fragmentFlag = isStableFragment
|
|
3751
|
-
? 64 /* STABLE_FRAGMENT */
|
|
3751
|
+
? 64 /* PatchFlags.STABLE_FRAGMENT */
|
|
3752
3752
|
: keyProp
|
|
3753
|
-
? 128 /* KEYED_FRAGMENT */
|
|
3754
|
-
: 256 /* UNKEYED_FRAGMENT */;
|
|
3753
|
+
? 128 /* PatchFlags.KEYED_FRAGMENT */
|
|
3754
|
+
: 256 /* PatchFlags.UNKEYED_FRAGMENT */;
|
|
3755
3755
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
|
|
3756
3756
|
(``), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
|
|
3757
3757
|
return () => {
|
|
@@ -3761,16 +3761,16 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3761
3761
|
// check <template v-for> key placement
|
|
3762
3762
|
if (isTemplate) {
|
|
3763
3763
|
node.children.some(c => {
|
|
3764
|
-
if (c.type === 1 /* ELEMENT */) {
|
|
3764
|
+
if (c.type === 1 /* NodeTypes.ELEMENT */) {
|
|
3765
3765
|
const key = findProp(c, 'key');
|
|
3766
3766
|
if (key) {
|
|
3767
|
-
context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3767
|
+
context.onError(createCompilerError(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3768
3768
|
return true;
|
|
3769
3769
|
}
|
|
3770
3770
|
}
|
|
3771
3771
|
});
|
|
3772
3772
|
}
|
|
3773
|
-
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
|
|
3773
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
|
|
3774
3774
|
const slotOutlet = isSlotOutlet(node)
|
|
3775
3775
|
? node
|
|
3776
3776
|
: isTemplate &&
|
|
@@ -3791,7 +3791,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3791
3791
|
else if (needFragmentWrapper) {
|
|
3792
3792
|
// <template v-for="..."> with text or multi-elements
|
|
3793
3793
|
// should generate a fragment block for each loop
|
|
3794
|
-
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
|
|
3794
|
+
childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
|
|
3795
3795
|
(``), undefined, undefined, true, undefined, false /* isComponent */);
|
|
3796
3796
|
}
|
|
3797
3797
|
else {
|
|
@@ -3848,7 +3848,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3848
3848
|
// target-agnostic transform used for both Client and SSR
|
|
3849
3849
|
function processFor(node, dir, context, processCodegen) {
|
|
3850
3850
|
if (!dir.exp) {
|
|
3851
|
-
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3851
|
+
context.onError(createCompilerError(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3852
3852
|
return;
|
|
3853
3853
|
}
|
|
3854
3854
|
const parseResult = parseForExpression(
|
|
@@ -3856,13 +3856,13 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3856
3856
|
// before expression transform.
|
|
3857
3857
|
dir.exp, context);
|
|
3858
3858
|
if (!parseResult) {
|
|
3859
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3859
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3860
3860
|
return;
|
|
3861
3861
|
}
|
|
3862
3862
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
3863
3863
|
const { source, value, key, index } = parseResult;
|
|
3864
3864
|
const forNode = {
|
|
3865
|
-
type: 11 /* FOR */,
|
|
3865
|
+
type: 11 /* NodeTypes.FOR */,
|
|
3866
3866
|
loc: dir.loc,
|
|
3867
3867
|
source,
|
|
3868
3868
|
valueAlias: value,
|
|
@@ -3974,9 +3974,9 @@ const defaultFallback = createSimpleExpression(`undefined`, false);
|
|
|
3974
3974
|
// Note the exit callback is executed before buildSlots() on the same node,
|
|
3975
3975
|
// so only nested slots see positive numbers.
|
|
3976
3976
|
const trackSlotScopes = (node, context) => {
|
|
3977
|
-
if (node.type === 1 /* ELEMENT */ &&
|
|
3978
|
-
(node.tagType === 1 /* COMPONENT */ ||
|
|
3979
|
-
node.tagType === 3 /* TEMPLATE */)) {
|
|
3977
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
3978
|
+
(node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
3979
|
+
node.tagType === 3 /* ElementTypes.TEMPLATE */)) {
|
|
3980
3980
|
// We are only checking non-empty v-slot here
|
|
3981
3981
|
// since we only care about slots that introduce scope variables.
|
|
3982
3982
|
const vSlot = findDir(node, 'slot');
|
|
@@ -4049,20 +4049,21 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4049
4049
|
let hasNamedDefaultSlot = false;
|
|
4050
4050
|
const implicitDefaultChildren = [];
|
|
4051
4051
|
const seenSlotNames = new Set();
|
|
4052
|
+
let conditionalBranchIndex = 0;
|
|
4052
4053
|
for (let i = 0; i < children.length; i++) {
|
|
4053
4054
|
const slotElement = children[i];
|
|
4054
4055
|
let slotDir;
|
|
4055
4056
|
if (!isTemplateNode(slotElement) ||
|
|
4056
4057
|
!(slotDir = findDir(slotElement, 'slot', true))) {
|
|
4057
4058
|
// not a <template v-slot>, skip.
|
|
4058
|
-
if (slotElement.type !== 3 /* COMMENT */) {
|
|
4059
|
+
if (slotElement.type !== 3 /* NodeTypes.COMMENT */) {
|
|
4059
4060
|
implicitDefaultChildren.push(slotElement);
|
|
4060
4061
|
}
|
|
4061
4062
|
continue;
|
|
4062
4063
|
}
|
|
4063
4064
|
if (onComponentSlot) {
|
|
4064
4065
|
// already has on-component slot - this is incorrect usage.
|
|
4065
|
-
context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
4066
|
+
context.onError(createCompilerError(37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
4066
4067
|
break;
|
|
4067
4068
|
}
|
|
4068
4069
|
hasTemplateSlots = true;
|
|
@@ -4083,7 +4084,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4083
4084
|
let vFor;
|
|
4084
4085
|
if ((vIf = findDir(slotElement, 'if'))) {
|
|
4085
4086
|
hasDynamicSlots = true;
|
|
4086
|
-
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
|
|
4087
|
+
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
|
|
4087
4088
|
}
|
|
4088
4089
|
else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
|
|
4089
4090
|
// find adjacent v-if
|
|
@@ -4091,7 +4092,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4091
4092
|
let prev;
|
|
4092
4093
|
while (j--) {
|
|
4093
4094
|
prev = children[j];
|
|
4094
|
-
if (prev.type !== 3 /* COMMENT */) {
|
|
4095
|
+
if (prev.type !== 3 /* NodeTypes.COMMENT */) {
|
|
4095
4096
|
break;
|
|
4096
4097
|
}
|
|
4097
4098
|
}
|
|
@@ -4101,15 +4102,15 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4101
4102
|
i--;
|
|
4102
4103
|
// attach this slot to previous conditional
|
|
4103
4104
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
4104
|
-
while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
|
|
4105
|
+
while (conditional.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
4105
4106
|
conditional = conditional.alternate;
|
|
4106
4107
|
}
|
|
4107
4108
|
conditional.alternate = vElse.exp
|
|
4108
|
-
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
|
|
4109
|
-
: buildDynamicSlot(slotName, slotFunction);
|
|
4109
|
+
? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback)
|
|
4110
|
+
: buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
|
4110
4111
|
}
|
|
4111
4112
|
else {
|
|
4112
|
-
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
4113
|
+
context.onError(createCompilerError(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
4113
4114
|
}
|
|
4114
4115
|
}
|
|
4115
4116
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -4125,14 +4126,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4125
4126
|
]));
|
|
4126
4127
|
}
|
|
4127
4128
|
else {
|
|
4128
|
-
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
4129
|
+
context.onError(createCompilerError(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
4129
4130
|
}
|
|
4130
4131
|
}
|
|
4131
4132
|
else {
|
|
4132
4133
|
// check duplicate static names
|
|
4133
4134
|
if (staticSlotName) {
|
|
4134
4135
|
if (seenSlotNames.has(staticSlotName)) {
|
|
4135
|
-
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
4136
|
+
context.onError(createCompilerError(38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
4136
4137
|
continue;
|
|
4137
4138
|
}
|
|
4138
4139
|
seenSlotNames.add(staticSlotName);
|
|
@@ -4162,7 +4163,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4162
4163
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
4163
4164
|
// implicit default slot (mixed with named slots)
|
|
4164
4165
|
if (hasNamedDefaultSlot) {
|
|
4165
|
-
context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
4166
|
+
context.onError(createCompilerError(39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
4166
4167
|
}
|
|
4167
4168
|
else {
|
|
4168
4169
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -4170,10 +4171,10 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4170
4171
|
}
|
|
4171
4172
|
}
|
|
4172
4173
|
const slotFlag = hasDynamicSlots
|
|
4173
|
-
? 2 /* DYNAMIC */
|
|
4174
|
+
? 2 /* SlotFlags.DYNAMIC */
|
|
4174
4175
|
: hasForwardedSlots(node.children)
|
|
4175
|
-
? 3 /* FORWARDED */
|
|
4176
|
-
: 1 /* STABLE */;
|
|
4176
|
+
? 3 /* SlotFlags.FORWARDED */
|
|
4177
|
+
: 1 /* SlotFlags.STABLE */;
|
|
4177
4178
|
let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
|
|
4178
4179
|
// 2 = compiled but dynamic = can skip normalization, but must run diff
|
|
4179
4180
|
// 1 = compiled and static = can skip normalization AND diff as optimized
|
|
@@ -4189,28 +4190,32 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4189
4190
|
hasDynamicSlots
|
|
4190
4191
|
};
|
|
4191
4192
|
}
|
|
4192
|
-
function buildDynamicSlot(name, fn) {
|
|
4193
|
-
|
|
4193
|
+
function buildDynamicSlot(name, fn, index) {
|
|
4194
|
+
const props = [
|
|
4194
4195
|
createObjectProperty(`name`, name),
|
|
4195
4196
|
createObjectProperty(`fn`, fn)
|
|
4196
|
-
]
|
|
4197
|
+
];
|
|
4198
|
+
if (index != null) {
|
|
4199
|
+
props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
|
|
4200
|
+
}
|
|
4201
|
+
return createObjectExpression(props);
|
|
4197
4202
|
}
|
|
4198
4203
|
function hasForwardedSlots(children) {
|
|
4199
4204
|
for (let i = 0; i < children.length; i++) {
|
|
4200
4205
|
const child = children[i];
|
|
4201
4206
|
switch (child.type) {
|
|
4202
|
-
case 1 /* ELEMENT */:
|
|
4203
|
-
if (child.tagType === 2 /* SLOT */ ||
|
|
4207
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
4208
|
+
if (child.tagType === 2 /* ElementTypes.SLOT */ ||
|
|
4204
4209
|
hasForwardedSlots(child.children)) {
|
|
4205
4210
|
return true;
|
|
4206
4211
|
}
|
|
4207
4212
|
break;
|
|
4208
|
-
case 9 /* IF */:
|
|
4213
|
+
case 9 /* NodeTypes.IF */:
|
|
4209
4214
|
if (hasForwardedSlots(child.branches))
|
|
4210
4215
|
return true;
|
|
4211
4216
|
break;
|
|
4212
|
-
case 10 /* IF_BRANCH */:
|
|
4213
|
-
case 11 /* FOR */:
|
|
4217
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
4218
|
+
case 11 /* NodeTypes.FOR */:
|
|
4214
4219
|
if (hasForwardedSlots(child.children))
|
|
4215
4220
|
return true;
|
|
4216
4221
|
break;
|
|
@@ -4219,9 +4224,9 @@ function hasForwardedSlots(children) {
|
|
|
4219
4224
|
return false;
|
|
4220
4225
|
}
|
|
4221
4226
|
function isNonWhitespaceContent(node) {
|
|
4222
|
-
if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
|
|
4227
|
+
if (node.type !== 2 /* NodeTypes.TEXT */ && node.type !== 12 /* NodeTypes.TEXT_CALL */)
|
|
4223
4228
|
return true;
|
|
4224
|
-
return node.type === 2 /* TEXT */
|
|
4229
|
+
return node.type === 2 /* NodeTypes.TEXT */
|
|
4225
4230
|
? !!node.content.trim()
|
|
4226
4231
|
: isNonWhitespaceContent(node.content);
|
|
4227
4232
|
}
|
|
@@ -4235,13 +4240,13 @@ const transformElement = (node, context) => {
|
|
|
4235
4240
|
// processed and merged.
|
|
4236
4241
|
return function postTransformElement() {
|
|
4237
4242
|
node = context.currentNode;
|
|
4238
|
-
if (!(node.type === 1 /* ELEMENT */ &&
|
|
4239
|
-
(node.tagType === 0 /* ELEMENT */ ||
|
|
4240
|
-
node.tagType === 1 /* COMPONENT */))) {
|
|
4243
|
+
if (!(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
4244
|
+
(node.tagType === 0 /* ElementTypes.ELEMENT */ ||
|
|
4245
|
+
node.tagType === 1 /* ElementTypes.COMPONENT */))) {
|
|
4241
4246
|
return;
|
|
4242
4247
|
}
|
|
4243
4248
|
const { tag, props } = node;
|
|
4244
|
-
const isComponent = node.tagType === 1 /* COMPONENT */;
|
|
4249
|
+
const isComponent = node.tagType === 1 /* ElementTypes.COMPONENT */;
|
|
4245
4250
|
// The goal of the transform is to create a codegenNode implementing the
|
|
4246
4251
|
// VNodeCall interface.
|
|
4247
4252
|
let vnodeTag = isComponent
|
|
@@ -4292,7 +4297,7 @@ const transformElement = (node, context) => {
|
|
|
4292
4297
|
// collected by a parent block.
|
|
4293
4298
|
shouldUseBlock = true;
|
|
4294
4299
|
// 2. Force keep-alive to always be updated, since it uses raw children.
|
|
4295
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
4300
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
4296
4301
|
}
|
|
4297
4302
|
const shouldBuildAsSlots = isComponent &&
|
|
4298
4303
|
// Teleport is not a real component and has dedicated runtime handling
|
|
@@ -4303,22 +4308,22 @@ const transformElement = (node, context) => {
|
|
|
4303
4308
|
const { slots, hasDynamicSlots } = buildSlots(node, context);
|
|
4304
4309
|
vnodeChildren = slots;
|
|
4305
4310
|
if (hasDynamicSlots) {
|
|
4306
|
-
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
4311
|
+
patchFlag |= 1024 /* PatchFlags.DYNAMIC_SLOTS */;
|
|
4307
4312
|
}
|
|
4308
4313
|
}
|
|
4309
4314
|
else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
|
4310
4315
|
const child = node.children[0];
|
|
4311
4316
|
const type = child.type;
|
|
4312
4317
|
// check for dynamic text children
|
|
4313
|
-
const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
|
|
4314
|
-
type === 8 /* COMPOUND_EXPRESSION */;
|
|
4318
|
+
const hasDynamicTextChild = type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
4319
|
+
type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
|
|
4315
4320
|
if (hasDynamicTextChild &&
|
|
4316
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
4317
|
-
patchFlag |= 1 /* TEXT */;
|
|
4321
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
4322
|
+
patchFlag |= 1 /* PatchFlags.TEXT */;
|
|
4318
4323
|
}
|
|
4319
4324
|
// pass directly if the only child is a text node
|
|
4320
4325
|
// (plain / interpolation / expression)
|
|
4321
|
-
if (hasDynamicTextChild || type === 2 /* TEXT */) {
|
|
4326
|
+
if (hasDynamicTextChild || type === 2 /* NodeTypes.TEXT */) {
|
|
4322
4327
|
vnodeChildren = child;
|
|
4323
4328
|
}
|
|
4324
4329
|
else {
|
|
@@ -4348,8 +4353,8 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
4348
4353
|
const isProp = findProp(node, 'is');
|
|
4349
4354
|
if (isProp) {
|
|
4350
4355
|
if (isExplicitDynamic ||
|
|
4351
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))) {
|
|
4352
|
-
const exp = isProp.type === 6 /* ATTRIBUTE */
|
|
4356
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))) {
|
|
4357
|
+
const exp = isProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
4353
4358
|
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
|
4354
4359
|
: isProp.exp;
|
|
4355
4360
|
if (exp) {
|
|
@@ -4358,7 +4363,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
4358
4363
|
]);
|
|
4359
4364
|
}
|
|
4360
4365
|
}
|
|
4361
|
-
else if (isProp.type === 6 /* ATTRIBUTE */ &&
|
|
4366
|
+
else if (isProp.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
4362
4367
|
isProp.value.content.startsWith('vue:')) {
|
|
4363
4368
|
// <button is="vue:xxx">
|
|
4364
4369
|
// if not <component>, only is value that starts with "vue:" will be
|
|
@@ -4432,17 +4437,17 @@ function resolveSetupReference(name, context) {
|
|
|
4432
4437
|
return PascalName;
|
|
4433
4438
|
}
|
|
4434
4439
|
};
|
|
4435
|
-
const fromConst = checkType("setup-const" /* SETUP_CONST */) ||
|
|
4436
|
-
checkType("setup-reactive-const" /* SETUP_REACTIVE_CONST */);
|
|
4440
|
+
const fromConst = checkType("setup-const" /* BindingTypes.SETUP_CONST */) ||
|
|
4441
|
+
checkType("setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */);
|
|
4437
4442
|
if (fromConst) {
|
|
4438
4443
|
return context.inline
|
|
4439
4444
|
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
|
|
4440
4445
|
fromConst
|
|
4441
4446
|
: `$setup[${JSON.stringify(fromConst)}]`;
|
|
4442
4447
|
}
|
|
4443
|
-
const fromMaybeRef = checkType("setup-let" /* SETUP_LET */) ||
|
|
4444
|
-
checkType("setup-ref" /* SETUP_REF */) ||
|
|
4445
|
-
checkType("setup-maybe-ref" /* SETUP_MAYBE_REF */);
|
|
4448
|
+
const fromMaybeRef = checkType("setup-let" /* BindingTypes.SETUP_LET */) ||
|
|
4449
|
+
checkType("setup-ref" /* BindingTypes.SETUP_REF */) ||
|
|
4450
|
+
checkType("setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */);
|
|
4446
4451
|
if (fromMaybeRef) {
|
|
4447
4452
|
return context.inline
|
|
4448
4453
|
? // setup scope bindings that may be refs need to be unrefed
|
|
@@ -4484,9 +4489,9 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4484
4489
|
if (isEventHandler && shared.isReservedProp(name)) {
|
|
4485
4490
|
hasVnodeHook = true;
|
|
4486
4491
|
}
|
|
4487
|
-
if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
|
|
4488
|
-
((value.type === 4 /* SIMPLE_EXPRESSION */ ||
|
|
4489
|
-
value.type === 8 /* COMPOUND_EXPRESSION */) &&
|
|
4492
|
+
if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */ ||
|
|
4493
|
+
((value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
4494
|
+
value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) &&
|
|
4490
4495
|
getConstantType(value, context) > 0)) {
|
|
4491
4496
|
// skip if the prop is a cached handler or has constant value
|
|
4492
4497
|
return;
|
|
@@ -4517,7 +4522,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4517
4522
|
for (let i = 0; i < props.length; i++) {
|
|
4518
4523
|
// static attribute
|
|
4519
4524
|
const prop = props[i];
|
|
4520
|
-
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
4525
|
+
if (prop.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4521
4526
|
const { loc, name, value } = prop;
|
|
4522
4527
|
let isStatic = true;
|
|
4523
4528
|
if (name === 'ref') {
|
|
@@ -4539,7 +4544,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4539
4544
|
if (name === 'is' &&
|
|
4540
4545
|
(isComponentTag(tag) ||
|
|
4541
4546
|
(value && value.content.startsWith('vue:')) ||
|
|
4542
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4547
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4543
4548
|
continue;
|
|
4544
4549
|
}
|
|
4545
4550
|
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
|
|
@@ -4552,7 +4557,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4552
4557
|
// skip v-slot - it is handled by its dedicated transform.
|
|
4553
4558
|
if (name === 'slot') {
|
|
4554
4559
|
if (!isComponent) {
|
|
4555
|
-
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
4560
|
+
context.onError(createCompilerError(40 /* ErrorCodes.X_V_SLOT_MISPLACED */, loc));
|
|
4556
4561
|
}
|
|
4557
4562
|
continue;
|
|
4558
4563
|
}
|
|
@@ -4565,7 +4570,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4565
4570
|
(isVBind &&
|
|
4566
4571
|
isStaticArgOf(arg, 'is') &&
|
|
4567
4572
|
(isComponentTag(tag) ||
|
|
4568
|
-
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
4573
|
+
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* CompilerDeprecationTypes.COMPILER_IS_ON_ELEMENT */, context))))) {
|
|
4569
4574
|
continue;
|
|
4570
4575
|
}
|
|
4571
4576
|
// skip v-on in SSR compilation
|
|
@@ -4593,7 +4598,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4593
4598
|
}
|
|
4594
4599
|
if (isVBind) {
|
|
4595
4600
|
{
|
|
4596
|
-
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
4601
|
+
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER" /* CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER */, context)) {
|
|
4597
4602
|
mergeArgs.unshift(exp);
|
|
4598
4603
|
continue;
|
|
4599
4604
|
}
|
|
@@ -4603,17 +4608,17 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4603
4608
|
else {
|
|
4604
4609
|
// v-on="obj" -> toHandlers(obj)
|
|
4605
4610
|
mergeArgs.push({
|
|
4606
|
-
type: 14 /* JS_CALL_EXPRESSION */,
|
|
4611
|
+
type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
|
|
4607
4612
|
loc,
|
|
4608
4613
|
callee: context.helper(TO_HANDLERS),
|
|
4609
|
-
arguments: [exp]
|
|
4614
|
+
arguments: isComponent ? [exp] : [exp, `true`]
|
|
4610
4615
|
});
|
|
4611
4616
|
}
|
|
4612
4617
|
}
|
|
4613
4618
|
else {
|
|
4614
4619
|
context.onError(createCompilerError(isVBind
|
|
4615
|
-
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
4616
|
-
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4620
|
+
? 34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */
|
|
4621
|
+
: 35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4617
4622
|
}
|
|
4618
4623
|
continue;
|
|
4619
4624
|
}
|
|
@@ -4660,31 +4665,31 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4660
4665
|
}
|
|
4661
4666
|
// patchFlag analysis
|
|
4662
4667
|
if (hasDynamicKeys) {
|
|
4663
|
-
patchFlag |= 16 /* FULL_PROPS */;
|
|
4668
|
+
patchFlag |= 16 /* PatchFlags.FULL_PROPS */;
|
|
4664
4669
|
}
|
|
4665
4670
|
else {
|
|
4666
4671
|
if (hasClassBinding && !isComponent) {
|
|
4667
|
-
patchFlag |= 2 /* CLASS */;
|
|
4672
|
+
patchFlag |= 2 /* PatchFlags.CLASS */;
|
|
4668
4673
|
}
|
|
4669
4674
|
if (hasStyleBinding && !isComponent) {
|
|
4670
|
-
patchFlag |= 4 /* STYLE */;
|
|
4675
|
+
patchFlag |= 4 /* PatchFlags.STYLE */;
|
|
4671
4676
|
}
|
|
4672
4677
|
if (dynamicPropNames.length) {
|
|
4673
|
-
patchFlag |= 8 /* PROPS */;
|
|
4678
|
+
patchFlag |= 8 /* PatchFlags.PROPS */;
|
|
4674
4679
|
}
|
|
4675
4680
|
if (hasHydrationEventBinding) {
|
|
4676
|
-
patchFlag |= 32 /* HYDRATE_EVENTS */;
|
|
4681
|
+
patchFlag |= 32 /* PatchFlags.HYDRATE_EVENTS */;
|
|
4677
4682
|
}
|
|
4678
4683
|
}
|
|
4679
4684
|
if (!shouldUseBlock &&
|
|
4680
|
-
(patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
|
|
4685
|
+
(patchFlag === 0 || patchFlag === 32 /* PatchFlags.HYDRATE_EVENTS */) &&
|
|
4681
4686
|
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
|
4682
|
-
patchFlag |= 512 /* NEED_PATCH */;
|
|
4687
|
+
patchFlag |= 512 /* PatchFlags.NEED_PATCH */;
|
|
4683
4688
|
}
|
|
4684
4689
|
// pre-normalize props, SSR is skipped for now
|
|
4685
4690
|
if (!context.inSSR && propsExpression) {
|
|
4686
4691
|
switch (propsExpression.type) {
|
|
4687
|
-
case 15 /* JS_OBJECT_EXPRESSION */:
|
|
4692
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
4688
4693
|
// means that there is no v-bind,
|
|
4689
4694
|
// but still need to deal with dynamic key binding
|
|
4690
4695
|
let classKeyIndex = -1;
|
|
@@ -4715,11 +4720,11 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4715
4720
|
// the static style is compiled into an object,
|
|
4716
4721
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4717
4722
|
(hasStyleBinding ||
|
|
4718
|
-
(styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
4723
|
+
(styleProp.value.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
4719
4724
|
styleProp.value.content.trim()[0] === `[`) ||
|
|
4720
4725
|
// v-bind:style and style both exist,
|
|
4721
4726
|
// v-bind:style with static literal object
|
|
4722
|
-
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4727
|
+
styleProp.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */)) {
|
|
4723
4728
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4724
4729
|
}
|
|
4725
4730
|
}
|
|
@@ -4728,7 +4733,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4728
4733
|
propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
|
|
4729
4734
|
}
|
|
4730
4735
|
break;
|
|
4731
|
-
case 14 /* JS_CALL_EXPRESSION */:
|
|
4736
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
4732
4737
|
// mergeProps call, do nothing
|
|
4733
4738
|
break;
|
|
4734
4739
|
default:
|
|
@@ -4761,7 +4766,7 @@ function dedupeProperties(properties) {
|
|
|
4761
4766
|
for (let i = 0; i < properties.length; i++) {
|
|
4762
4767
|
const prop = properties[i];
|
|
4763
4768
|
// dynamic keys are always allowed
|
|
4764
|
-
if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4769
|
+
if (prop.key.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
|
|
4765
4770
|
deduped.push(prop);
|
|
4766
4771
|
continue;
|
|
4767
4772
|
}
|
|
@@ -4781,7 +4786,7 @@ function dedupeProperties(properties) {
|
|
|
4781
4786
|
return deduped;
|
|
4782
4787
|
}
|
|
4783
4788
|
function mergeAsArray(existing, incoming) {
|
|
4784
|
-
if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
|
|
4789
|
+
if (existing.value.type === 17 /* NodeTypes.JS_ARRAY_EXPRESSION */) {
|
|
4785
4790
|
existing.value.elements.push(incoming.value);
|
|
4786
4791
|
}
|
|
4787
4792
|
else {
|
|
@@ -4891,7 +4896,7 @@ function processSlotOutlet(node, context) {
|
|
|
4891
4896
|
const nonNameProps = [];
|
|
4892
4897
|
for (let i = 0; i < node.props.length; i++) {
|
|
4893
4898
|
const p = node.props[i];
|
|
4894
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
4899
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
4895
4900
|
if (p.value) {
|
|
4896
4901
|
if (p.name === 'name') {
|
|
4897
4902
|
slotName = JSON.stringify(p.value.content);
|
|
@@ -4919,7 +4924,7 @@ function processSlotOutlet(node, context) {
|
|
|
4919
4924
|
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
4920
4925
|
slotProps = props;
|
|
4921
4926
|
if (directives.length) {
|
|
4922
|
-
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4927
|
+
context.onError(createCompilerError(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4923
4928
|
}
|
|
4924
4929
|
}
|
|
4925
4930
|
return {
|
|
@@ -4932,18 +4937,26 @@ const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?functio
|
|
|
4932
4937
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4933
4938
|
const { loc, modifiers, arg } = dir;
|
|
4934
4939
|
if (!dir.exp && !modifiers.length) {
|
|
4935
|
-
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4940
|
+
context.onError(createCompilerError(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
4936
4941
|
}
|
|
4937
4942
|
let eventName;
|
|
4938
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
4943
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
4939
4944
|
if (arg.isStatic) {
|
|
4940
4945
|
let rawName = arg.content;
|
|
4941
4946
|
// TODO deprecate @vnodeXXX usage
|
|
4942
4947
|
if (rawName.startsWith('vue:')) {
|
|
4943
4948
|
rawName = `vnode-${rawName.slice(4)}`;
|
|
4944
4949
|
}
|
|
4945
|
-
|
|
4946
|
-
|
|
4950
|
+
const eventString = node.tagType === 1 /* ElementTypes.COMPONENT */ ||
|
|
4951
|
+
rawName.startsWith('vnode') ||
|
|
4952
|
+
!/[A-Z]/.test(rawName)
|
|
4953
|
+
? // for component and vnode lifecycle event listeners, auto convert
|
|
4954
|
+
// it to camelCase. See issue #2249
|
|
4955
|
+
shared.toHandlerKey(shared.camelize(rawName))
|
|
4956
|
+
// preserve case for plain element listeners that have uppercase
|
|
4957
|
+
// letters, as these may be custom elements' custom events
|
|
4958
|
+
: `on:${rawName}`;
|
|
4959
|
+
eventName = createSimpleExpression(eventString, true, arg.loc);
|
|
4947
4960
|
}
|
|
4948
4961
|
else {
|
|
4949
4962
|
// #2388
|
|
@@ -4983,13 +4996,13 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
4983
4996
|
!context.inVOnce &&
|
|
4984
4997
|
// runtime constants don't need to be cached
|
|
4985
4998
|
// (this is analyzed by compileScript in SFC <script setup>)
|
|
4986
|
-
!(exp.type === 4 /* SIMPLE_EXPRESSION */ && exp.constType > 0) &&
|
|
4999
|
+
!(exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && exp.constType > 0) &&
|
|
4987
5000
|
// #1541 bail if this is a member exp handler passed to a component -
|
|
4988
5001
|
// we need to use the original function to preserve arity,
|
|
4989
5002
|
// e.g. <transition> relies on checking cb.length to determine
|
|
4990
5003
|
// transition end handling. Inline function is ok since its arity
|
|
4991
5004
|
// is preserved even when cached.
|
|
4992
|
-
!(isMemberExp && node.tagType === 1 /* COMPONENT */) &&
|
|
5005
|
+
!(isMemberExp && node.tagType === 1 /* ElementTypes.COMPONENT */) &&
|
|
4993
5006
|
// bail if the function references closure variables (v-for, v-slot)
|
|
4994
5007
|
// it must be passed fresh to avoid stale values.
|
|
4995
5008
|
!hasScopeRef(exp, context.identifiers);
|
|
@@ -4998,7 +5011,7 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
4998
5011
|
// below) so that it always accesses the latest value when called - thus
|
|
4999
5012
|
// avoiding the need to be patched.
|
|
5000
5013
|
if (shouldCache && isMemberExp) {
|
|
5001
|
-
if (exp.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
5014
|
+
if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5002
5015
|
exp.content = `${exp.content} && ${exp.content}(...args)`;
|
|
5003
5016
|
}
|
|
5004
5017
|
else {
|
|
@@ -5045,7 +5058,7 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
5045
5058
|
const transformBind = (dir, _node, context) => {
|
|
5046
5059
|
const { exp, modifiers, loc } = dir;
|
|
5047
5060
|
const arg = dir.arg;
|
|
5048
|
-
if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
|
|
5061
|
+
if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5049
5062
|
arg.children.unshift(`(`);
|
|
5050
5063
|
arg.children.push(`) || ""`);
|
|
5051
5064
|
}
|
|
@@ -5054,7 +5067,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
5054
5067
|
}
|
|
5055
5068
|
// .sync is replaced by v-model:arg
|
|
5056
5069
|
if (modifiers.includes('camel')) {
|
|
5057
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
5070
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5058
5071
|
if (arg.isStatic) {
|
|
5059
5072
|
arg.content = shared.camelize(arg.content);
|
|
5060
5073
|
}
|
|
@@ -5076,8 +5089,8 @@ const transformBind = (dir, _node, context) => {
|
|
|
5076
5089
|
}
|
|
5077
5090
|
}
|
|
5078
5091
|
if (!exp ||
|
|
5079
|
-
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
5080
|
-
context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
|
|
5092
|
+
(exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
5093
|
+
context.onError(createCompilerError(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
|
|
5081
5094
|
return {
|
|
5082
5095
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
5083
5096
|
};
|
|
@@ -5087,7 +5100,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
5087
5100
|
};
|
|
5088
5101
|
};
|
|
5089
5102
|
const injectPrefix = (arg, prefix) => {
|
|
5090
|
-
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
5103
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5091
5104
|
if (arg.isStatic) {
|
|
5092
5105
|
arg.content = prefix + arg.content;
|
|
5093
5106
|
}
|
|
@@ -5104,10 +5117,10 @@ const injectPrefix = (arg, prefix) => {
|
|
|
5104
5117
|
// Merge adjacent text nodes and expressions into a single expression
|
|
5105
5118
|
// e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
|
|
5106
5119
|
const transformText = (node, context) => {
|
|
5107
|
-
if (node.type === 0 /* ROOT */ ||
|
|
5108
|
-
node.type === 1 /* ELEMENT */ ||
|
|
5109
|
-
node.type === 11 /* FOR */ ||
|
|
5110
|
-
node.type === 10 /* IF_BRANCH */) {
|
|
5120
|
+
if (node.type === 0 /* NodeTypes.ROOT */ ||
|
|
5121
|
+
node.type === 1 /* NodeTypes.ELEMENT */ ||
|
|
5122
|
+
node.type === 11 /* NodeTypes.FOR */ ||
|
|
5123
|
+
node.type === 10 /* NodeTypes.IF_BRANCH */) {
|
|
5111
5124
|
// perform the transform on node exit so that all expressions have already
|
|
5112
5125
|
// been processed.
|
|
5113
5126
|
return () => {
|
|
@@ -5142,15 +5155,15 @@ const transformText = (node, context) => {
|
|
|
5142
5155
|
// setting textContent of the element.
|
|
5143
5156
|
// for component root it's always normalized anyway.
|
|
5144
5157
|
(children.length === 1 &&
|
|
5145
|
-
(node.type === 0 /* ROOT */ ||
|
|
5146
|
-
(node.type === 1 /* ELEMENT */ &&
|
|
5147
|
-
node.tagType === 0 /* ELEMENT */ &&
|
|
5158
|
+
(node.type === 0 /* NodeTypes.ROOT */ ||
|
|
5159
|
+
(node.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
5160
|
+
node.tagType === 0 /* ElementTypes.ELEMENT */ &&
|
|
5148
5161
|
// #3756
|
|
5149
5162
|
// custom directives can potentially add DOM elements arbitrarily,
|
|
5150
5163
|
// we need to avoid setting textContent of the element at runtime
|
|
5151
5164
|
// to avoid accidentally overwriting the DOM elements added
|
|
5152
5165
|
// by the user through custom directives.
|
|
5153
|
-
!node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
|
|
5166
|
+
!node.props.find(p => p.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
5154
5167
|
!context.directiveTransforms[p.name]) &&
|
|
5155
5168
|
// in compat mode, <template> tags with no special directives
|
|
5156
5169
|
// will be rendered as a fragment so its children must be
|
|
@@ -5162,21 +5175,21 @@ const transformText = (node, context) => {
|
|
|
5162
5175
|
// runtime normalization.
|
|
5163
5176
|
for (let i = 0; i < children.length; i++) {
|
|
5164
5177
|
const child = children[i];
|
|
5165
|
-
if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
5178
|
+
if (isText(child) || child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
5166
5179
|
const callArgs = [];
|
|
5167
5180
|
// createTextVNode defaults to single whitespace, so if it is a
|
|
5168
5181
|
// single space the code could be an empty call to save bytes.
|
|
5169
|
-
if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
|
|
5182
|
+
if (child.type !== 2 /* NodeTypes.TEXT */ || child.content !== ' ') {
|
|
5170
5183
|
callArgs.push(child);
|
|
5171
5184
|
}
|
|
5172
5185
|
// mark dynamic text with flag so it gets patched inside a block
|
|
5173
5186
|
if (!context.ssr &&
|
|
5174
|
-
getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
|
|
5175
|
-
callArgs.push(1 /* TEXT */ +
|
|
5187
|
+
getConstantType(child, context) === 0 /* ConstantTypes.NOT_CONSTANT */) {
|
|
5188
|
+
callArgs.push(1 /* PatchFlags.TEXT */ +
|
|
5176
5189
|
(``));
|
|
5177
5190
|
}
|
|
5178
5191
|
children[i] = {
|
|
5179
|
-
type: 12 /* TEXT_CALL */,
|
|
5192
|
+
type: 12 /* NodeTypes.TEXT_CALL */,
|
|
5180
5193
|
content: child,
|
|
5181
5194
|
loc: child.loc,
|
|
5182
5195
|
codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
|
|
@@ -5189,7 +5202,7 @@ const transformText = (node, context) => {
|
|
|
5189
5202
|
|
|
5190
5203
|
const seen = new WeakSet();
|
|
5191
5204
|
const transformOnce = (node, context) => {
|
|
5192
|
-
if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
|
|
5205
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */ && findDir(node, 'once', true)) {
|
|
5193
5206
|
if (seen.has(node) || context.inVOnce) {
|
|
5194
5207
|
return;
|
|
5195
5208
|
}
|
|
@@ -5209,26 +5222,26 @@ const transformOnce = (node, context) => {
|
|
|
5209
5222
|
const transformModel = (dir, node, context) => {
|
|
5210
5223
|
const { exp, arg } = dir;
|
|
5211
5224
|
if (!exp) {
|
|
5212
|
-
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
5225
|
+
context.onError(createCompilerError(41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
5213
5226
|
return createTransformProps();
|
|
5214
5227
|
}
|
|
5215
5228
|
const rawExp = exp.loc.source;
|
|
5216
|
-
const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
5229
|
+
const expString = exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ? exp.content : rawExp;
|
|
5217
5230
|
// im SFC <script setup> inline mode, the exp may have been transformed into
|
|
5218
5231
|
// _unref(exp)
|
|
5219
5232
|
const bindingType = context.bindingMetadata[rawExp];
|
|
5220
5233
|
const maybeRef = context.inline &&
|
|
5221
5234
|
bindingType &&
|
|
5222
|
-
bindingType !== "setup-const" /* SETUP_CONST */;
|
|
5235
|
+
bindingType !== "setup-const" /* BindingTypes.SETUP_CONST */;
|
|
5223
5236
|
if (!expString.trim() ||
|
|
5224
5237
|
(!isMemberExpression(expString, context) && !maybeRef)) {
|
|
5225
|
-
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
5238
|
+
context.onError(createCompilerError(42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
5226
5239
|
return createTransformProps();
|
|
5227
5240
|
}
|
|
5228
5241
|
if (context.prefixIdentifiers &&
|
|
5229
5242
|
isSimpleIdentifier(expString) &&
|
|
5230
5243
|
context.identifiers[expString]) {
|
|
5231
|
-
context.onError(createCompilerError(43 /* X_V_MODEL_ON_SCOPE_VARIABLE */, exp.loc));
|
|
5244
|
+
context.onError(createCompilerError(43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */, exp.loc));
|
|
5232
5245
|
return createTransformProps();
|
|
5233
5246
|
}
|
|
5234
5247
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -5240,7 +5253,7 @@ const transformModel = (dir, node, context) => {
|
|
|
5240
5253
|
let assignmentExp;
|
|
5241
5254
|
const eventArg = context.isTS ? `($event: any)` : `$event`;
|
|
5242
5255
|
if (maybeRef) {
|
|
5243
|
-
if (bindingType === "setup-ref" /* SETUP_REF */) {
|
|
5256
|
+
if (bindingType === "setup-ref" /* BindingTypes.SETUP_REF */) {
|
|
5244
5257
|
// v-model used on known ref.
|
|
5245
5258
|
assignmentExp = createCompoundExpression([
|
|
5246
5259
|
`${eventArg} => ((`,
|
|
@@ -5251,7 +5264,7 @@ const transformModel = (dir, node, context) => {
|
|
|
5251
5264
|
else {
|
|
5252
5265
|
// v-model used on a potentially ref binding in <script setup> inline mode.
|
|
5253
5266
|
// the assignment needs to check whether the binding is actually a ref.
|
|
5254
|
-
const altAssignment = bindingType === "setup-let" /* SETUP_LET */ ? `${rawExp} = $event` : `null`;
|
|
5267
|
+
const altAssignment = bindingType === "setup-let" /* BindingTypes.SETUP_LET */ ? `${rawExp} = $event` : `null`;
|
|
5255
5268
|
assignmentExp = createCompoundExpression([
|
|
5256
5269
|
`${eventArg} => (${context.helperString(IS_REF)}(${rawExp}) ? (`,
|
|
5257
5270
|
createSimpleExpression(rawExp, false, exp.loc),
|
|
@@ -5280,7 +5293,7 @@ const transformModel = (dir, node, context) => {
|
|
|
5280
5293
|
props[1].value = context.cache(props[1].value);
|
|
5281
5294
|
}
|
|
5282
5295
|
// modelModifiers: { foo: true, "bar-baz": true }
|
|
5283
|
-
if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
|
|
5296
|
+
if (dir.modifiers.length && node.tagType === 1 /* ElementTypes.COMPONENT */) {
|
|
5284
5297
|
const modifiers = dir.modifiers
|
|
5285
5298
|
.map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
|
|
5286
5299
|
.join(`, `);
|
|
@@ -5289,7 +5302,7 @@ const transformModel = (dir, node, context) => {
|
|
|
5289
5302
|
? `${arg.content}Modifiers`
|
|
5290
5303
|
: createCompoundExpression([arg, ' + "Modifiers"'])
|
|
5291
5304
|
: `modelModifiers`;
|
|
5292
|
-
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
|
|
5305
|
+
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* ConstantTypes.CAN_HOIST */)));
|
|
5293
5306
|
}
|
|
5294
5307
|
return createTransformProps(props);
|
|
5295
5308
|
};
|
|
@@ -5299,17 +5312,17 @@ function createTransformProps(props = []) {
|
|
|
5299
5312
|
|
|
5300
5313
|
const validDivisionCharRE = /[\w).+\-_$\]]/;
|
|
5301
5314
|
const transformFilter = (node, context) => {
|
|
5302
|
-
if (!isCompatEnabled("COMPILER_FILTER" /* COMPILER_FILTERS */, context)) {
|
|
5315
|
+
if (!isCompatEnabled("COMPILER_FILTER" /* CompilerDeprecationTypes.COMPILER_FILTERS */, context)) {
|
|
5303
5316
|
return;
|
|
5304
5317
|
}
|
|
5305
|
-
if (node.type === 5 /* INTERPOLATION */) {
|
|
5318
|
+
if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
5306
5319
|
// filter rewrite is applied before expression transform so only
|
|
5307
5320
|
// simple expressions are possible at this stage
|
|
5308
5321
|
rewriteFilter(node.content, context);
|
|
5309
5322
|
}
|
|
5310
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
5323
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
5311
5324
|
node.props.forEach((prop) => {
|
|
5312
|
-
if (prop.type === 7 /* DIRECTIVE */ &&
|
|
5325
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ &&
|
|
5313
5326
|
prop.name !== 'for' &&
|
|
5314
5327
|
prop.exp) {
|
|
5315
5328
|
rewriteFilter(prop.exp, context);
|
|
@@ -5318,7 +5331,7 @@ const transformFilter = (node, context) => {
|
|
|
5318
5331
|
}
|
|
5319
5332
|
};
|
|
5320
5333
|
function rewriteFilter(node, context) {
|
|
5321
|
-
if (node.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
5334
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5322
5335
|
parseFilter(node, context);
|
|
5323
5336
|
}
|
|
5324
5337
|
else {
|
|
@@ -5326,13 +5339,13 @@ function rewriteFilter(node, context) {
|
|
|
5326
5339
|
const child = node.children[i];
|
|
5327
5340
|
if (typeof child !== 'object')
|
|
5328
5341
|
continue;
|
|
5329
|
-
if (child.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
5342
|
+
if (child.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
5330
5343
|
parseFilter(child, context);
|
|
5331
5344
|
}
|
|
5332
|
-
else if (child.type === 8 /* COMPOUND_EXPRESSION */) {
|
|
5345
|
+
else if (child.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
5333
5346
|
rewriteFilter(node, context);
|
|
5334
5347
|
}
|
|
5335
|
-
else if (child.type === 5 /* INTERPOLATION */) {
|
|
5348
|
+
else if (child.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
5336
5349
|
rewriteFilter(child.content, context);
|
|
5337
5350
|
}
|
|
5338
5351
|
}
|
|
@@ -5463,7 +5476,7 @@ function wrapFilter(exp, filter, context) {
|
|
|
5463
5476
|
|
|
5464
5477
|
const seen$1 = new WeakSet();
|
|
5465
5478
|
const transformMemo = (node, context) => {
|
|
5466
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
5479
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
5467
5480
|
const dir = findDir(node, 'memo');
|
|
5468
5481
|
if (!dir || seen$1.has(node)) {
|
|
5469
5482
|
return;
|
|
@@ -5472,9 +5485,9 @@ const transformMemo = (node, context) => {
|
|
|
5472
5485
|
return () => {
|
|
5473
5486
|
const codegenNode = node.codegenNode ||
|
|
5474
5487
|
context.currentNode.codegenNode;
|
|
5475
|
-
if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
|
|
5488
|
+
if (codegenNode && codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
5476
5489
|
// non-component sub tree should be turned into a block
|
|
5477
|
-
if (node.tagType !== 1 /* COMPONENT */) {
|
|
5490
|
+
if (node.tagType !== 1 /* ElementTypes.COMPONENT */) {
|
|
5478
5491
|
makeBlock(codegenNode, context);
|
|
5479
5492
|
}
|
|
5480
5493
|
node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
|
@@ -5522,10 +5535,10 @@ function baseCompile(template, options = {}) {
|
|
|
5522
5535
|
const isModuleMode = options.mode === 'module';
|
|
5523
5536
|
const prefixIdentifiers = (options.prefixIdentifiers === true || isModuleMode);
|
|
5524
5537
|
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
5525
|
-
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
5538
|
+
onError(createCompilerError(48 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
5526
5539
|
}
|
|
5527
5540
|
if (options.scopeId && !isModuleMode) {
|
|
5528
|
-
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
5541
|
+
onError(createCompilerError(49 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */));
|
|
5529
5542
|
}
|
|
5530
5543
|
const ast = shared.isString(template) ? baseParse(template, options) : template;
|
|
5531
5544
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
|