@vue/compiler-core 3.2.7 → 3.2.11
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 +239 -63
- package/dist/compiler-core.cjs.prod.js +238 -62
- package/dist/compiler-core.d.ts +33 -32
- package/dist/compiler-core.esm-bundler.js +70 -55
- package/package.json +2 -2
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var shared = require('@vue/shared');
|
|
6
6
|
var sourceMap = require('source-map');
|
|
7
|
-
var types = require('@babel/types');
|
|
8
7
|
var estreeWalker = require('estree-walker');
|
|
9
8
|
var parser = require('@babel/parser');
|
|
10
9
|
|
|
@@ -51,37 +50,38 @@ const errorMessages = {
|
|
|
51
50
|
[23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
52
51
|
[24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
53
52
|
[25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
54
|
-
[
|
|
53
|
+
[27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
55
54
|
'Note that dynamic directive argument cannot contain spaces.',
|
|
55
|
+
[26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
56
56
|
// transform errors
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
57
|
+
[28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
58
|
+
[29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
59
|
+
[30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
|
|
60
|
+
[31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
61
|
+
[32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
62
|
+
[33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
63
|
+
[34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
64
|
+
[35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
65
|
+
[36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
66
|
+
[37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
|
|
67
67
|
`When there are multiple named slots, all slots should use <template> ` +
|
|
68
68
|
`syntax to avoid scope ambiguity.`,
|
|
69
|
-
[
|
|
70
|
-
[
|
|
69
|
+
[38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
70
|
+
[39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
71
71
|
`default slot. These children will be ignored.`,
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
72
|
+
[40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
73
|
+
[41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
74
|
+
[42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
75
|
+
[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.`,
|
|
76
|
+
[44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
77
|
+
[45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
78
78
|
// generic errors
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
79
|
+
[46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
80
|
+
[47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
81
|
+
[48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
82
|
+
[49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
83
83
|
// just to fullfill types
|
|
84
|
-
[
|
|
84
|
+
[50 /* __EXTEND_POINT__ */]: ``
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
const FRAGMENT = Symbol(`Fragment` );
|
|
@@ -1297,6 +1297,13 @@ function parseAttributes(context, type) {
|
|
|
1297
1297
|
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1298
1298
|
}
|
|
1299
1299
|
const attr = parseAttribute(context, attributeNames);
|
|
1300
|
+
// Trim whitespace between class
|
|
1301
|
+
// https://github.com/vuejs/vue-next/issues/4251
|
|
1302
|
+
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1303
|
+
attr.value &&
|
|
1304
|
+
attr.name === 'class') {
|
|
1305
|
+
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1306
|
+
}
|
|
1300
1307
|
if (type === 0 /* Start */) {
|
|
1301
1308
|
props.push(attr);
|
|
1302
1309
|
}
|
|
@@ -1339,7 +1346,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1339
1346
|
}
|
|
1340
1347
|
}
|
|
1341
1348
|
const loc = getSelection(context, start);
|
|
1342
|
-
if (!context.inVPre && /^(v
|
|
1349
|
+
if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
|
|
1343
1350
|
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
|
|
1344
1351
|
let isPropShorthand = startsWith(name, '.');
|
|
1345
1352
|
let dirName = match[1] ||
|
|
@@ -1358,9 +1365,12 @@ function parseAttribute(context, nameSet) {
|
|
|
1358
1365
|
if (content.startsWith('[')) {
|
|
1359
1366
|
isStatic = false;
|
|
1360
1367
|
if (!content.endsWith(']')) {
|
|
1361
|
-
emitError(context,
|
|
1368
|
+
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1369
|
+
content = content.substr(1);
|
|
1370
|
+
}
|
|
1371
|
+
else {
|
|
1372
|
+
content = content.substr(1, content.length - 2);
|
|
1362
1373
|
}
|
|
1363
|
-
content = content.substr(1, content.length - 2);
|
|
1364
1374
|
}
|
|
1365
1375
|
else if (isSlot) {
|
|
1366
1376
|
// #1241 special case for v-slot: vuetify relies extensively on slot
|
|
@@ -1416,6 +1426,10 @@ function parseAttribute(context, nameSet) {
|
|
|
1416
1426
|
loc
|
|
1417
1427
|
};
|
|
1418
1428
|
}
|
|
1429
|
+
// missing directive name or illegal directive name
|
|
1430
|
+
if (!context.inVPre && startsWith(name, 'v-')) {
|
|
1431
|
+
emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
|
|
1432
|
+
}
|
|
1419
1433
|
return {
|
|
1420
1434
|
type: 6 /* ATTRIBUTE */,
|
|
1421
1435
|
name,
|
|
@@ -3027,7 +3041,7 @@ function isReferencedIdentifier(id, parent, parentStack) {
|
|
|
3027
3041
|
if (id.name === 'arguments') {
|
|
3028
3042
|
return false;
|
|
3029
3043
|
}
|
|
3030
|
-
if (
|
|
3044
|
+
if (isReferenced(id, parent)) {
|
|
3031
3045
|
return true;
|
|
3032
3046
|
}
|
|
3033
3047
|
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
@@ -3140,7 +3154,159 @@ const isFunctionType = (node) => {
|
|
|
3140
3154
|
const isStaticProperty = (node) => node &&
|
|
3141
3155
|
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3142
3156
|
!node.computed;
|
|
3143
|
-
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3157
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3158
|
+
/**
|
|
3159
|
+
* Copied from https://github.com/babel/babel/blob/main/packages/babel-types/src/validators/isReferenced.ts
|
|
3160
|
+
* To avoid runtime dependency on @babel/types (which includes process references)
|
|
3161
|
+
* This file should not change very often in babel but we may need to keep it
|
|
3162
|
+
* up-to-date from time to time.
|
|
3163
|
+
*
|
|
3164
|
+
* https://github.com/babel/babel/blob/main/LICENSE
|
|
3165
|
+
*
|
|
3166
|
+
*/
|
|
3167
|
+
function isReferenced(node, parent, grandparent) {
|
|
3168
|
+
switch (parent.type) {
|
|
3169
|
+
// yes: PARENT[NODE]
|
|
3170
|
+
// yes: NODE.child
|
|
3171
|
+
// no: parent.NODE
|
|
3172
|
+
case 'MemberExpression':
|
|
3173
|
+
case 'OptionalMemberExpression':
|
|
3174
|
+
if (parent.property === node) {
|
|
3175
|
+
return !!parent.computed;
|
|
3176
|
+
}
|
|
3177
|
+
return parent.object === node;
|
|
3178
|
+
case 'JSXMemberExpression':
|
|
3179
|
+
return parent.object === node;
|
|
3180
|
+
// no: let NODE = init;
|
|
3181
|
+
// yes: let id = NODE;
|
|
3182
|
+
case 'VariableDeclarator':
|
|
3183
|
+
return parent.init === node;
|
|
3184
|
+
// yes: () => NODE
|
|
3185
|
+
// no: (NODE) => {}
|
|
3186
|
+
case 'ArrowFunctionExpression':
|
|
3187
|
+
return parent.body === node;
|
|
3188
|
+
// no: class { #NODE; }
|
|
3189
|
+
// no: class { get #NODE() {} }
|
|
3190
|
+
// no: class { #NODE() {} }
|
|
3191
|
+
// no: class { fn() { return this.#NODE; } }
|
|
3192
|
+
case 'PrivateName':
|
|
3193
|
+
return false;
|
|
3194
|
+
// no: class { NODE() {} }
|
|
3195
|
+
// yes: class { [NODE]() {} }
|
|
3196
|
+
// no: class { foo(NODE) {} }
|
|
3197
|
+
case 'ClassMethod':
|
|
3198
|
+
case 'ClassPrivateMethod':
|
|
3199
|
+
case 'ObjectMethod':
|
|
3200
|
+
if (parent.key === node) {
|
|
3201
|
+
return !!parent.computed;
|
|
3202
|
+
}
|
|
3203
|
+
return false;
|
|
3204
|
+
// yes: { [NODE]: "" }
|
|
3205
|
+
// no: { NODE: "" }
|
|
3206
|
+
// depends: { NODE }
|
|
3207
|
+
// depends: { key: NODE }
|
|
3208
|
+
case 'ObjectProperty':
|
|
3209
|
+
if (parent.key === node) {
|
|
3210
|
+
return !!parent.computed;
|
|
3211
|
+
}
|
|
3212
|
+
// parent.value === node
|
|
3213
|
+
return !grandparent || grandparent.type !== 'ObjectPattern';
|
|
3214
|
+
// no: class { NODE = value; }
|
|
3215
|
+
// yes: class { [NODE] = value; }
|
|
3216
|
+
// yes: class { key = NODE; }
|
|
3217
|
+
case 'ClassProperty':
|
|
3218
|
+
if (parent.key === node) {
|
|
3219
|
+
return !!parent.computed;
|
|
3220
|
+
}
|
|
3221
|
+
return true;
|
|
3222
|
+
case 'ClassPrivateProperty':
|
|
3223
|
+
return parent.key !== node;
|
|
3224
|
+
// no: class NODE {}
|
|
3225
|
+
// yes: class Foo extends NODE {}
|
|
3226
|
+
case 'ClassDeclaration':
|
|
3227
|
+
case 'ClassExpression':
|
|
3228
|
+
return parent.superClass === node;
|
|
3229
|
+
// yes: left = NODE;
|
|
3230
|
+
// no: NODE = right;
|
|
3231
|
+
case 'AssignmentExpression':
|
|
3232
|
+
return parent.right === node;
|
|
3233
|
+
// no: [NODE = foo] = [];
|
|
3234
|
+
// yes: [foo = NODE] = [];
|
|
3235
|
+
case 'AssignmentPattern':
|
|
3236
|
+
return parent.right === node;
|
|
3237
|
+
// no: NODE: for (;;) {}
|
|
3238
|
+
case 'LabeledStatement':
|
|
3239
|
+
return false;
|
|
3240
|
+
// no: try {} catch (NODE) {}
|
|
3241
|
+
case 'CatchClause':
|
|
3242
|
+
return false;
|
|
3243
|
+
// no: function foo(...NODE) {}
|
|
3244
|
+
case 'RestElement':
|
|
3245
|
+
return false;
|
|
3246
|
+
case 'BreakStatement':
|
|
3247
|
+
case 'ContinueStatement':
|
|
3248
|
+
return false;
|
|
3249
|
+
// no: function NODE() {}
|
|
3250
|
+
// no: function foo(NODE) {}
|
|
3251
|
+
case 'FunctionDeclaration':
|
|
3252
|
+
case 'FunctionExpression':
|
|
3253
|
+
return false;
|
|
3254
|
+
// no: export NODE from "foo";
|
|
3255
|
+
// no: export * as NODE from "foo";
|
|
3256
|
+
case 'ExportNamespaceSpecifier':
|
|
3257
|
+
case 'ExportDefaultSpecifier':
|
|
3258
|
+
return false;
|
|
3259
|
+
// no: export { foo as NODE };
|
|
3260
|
+
// yes: export { NODE as foo };
|
|
3261
|
+
// no: export { NODE as foo } from "foo";
|
|
3262
|
+
case 'ExportSpecifier':
|
|
3263
|
+
// @ts-expect-error
|
|
3264
|
+
if (grandparent === null || grandparent === void 0 ? void 0 : grandparent.source) {
|
|
3265
|
+
return false;
|
|
3266
|
+
}
|
|
3267
|
+
return parent.local === node;
|
|
3268
|
+
// no: import NODE from "foo";
|
|
3269
|
+
// no: import * as NODE from "foo";
|
|
3270
|
+
// no: import { NODE as foo } from "foo";
|
|
3271
|
+
// no: import { foo as NODE } from "foo";
|
|
3272
|
+
// no: import NODE from "bar";
|
|
3273
|
+
case 'ImportDefaultSpecifier':
|
|
3274
|
+
case 'ImportNamespaceSpecifier':
|
|
3275
|
+
case 'ImportSpecifier':
|
|
3276
|
+
return false;
|
|
3277
|
+
// no: import "foo" assert { NODE: "json" }
|
|
3278
|
+
case 'ImportAttribute':
|
|
3279
|
+
return false;
|
|
3280
|
+
// no: <div NODE="foo" />
|
|
3281
|
+
case 'JSXAttribute':
|
|
3282
|
+
return false;
|
|
3283
|
+
// no: [NODE] = [];
|
|
3284
|
+
// no: ({ NODE }) = [];
|
|
3285
|
+
case 'ObjectPattern':
|
|
3286
|
+
case 'ArrayPattern':
|
|
3287
|
+
return false;
|
|
3288
|
+
// no: new.NODE
|
|
3289
|
+
// no: NODE.target
|
|
3290
|
+
case 'MetaProperty':
|
|
3291
|
+
return false;
|
|
3292
|
+
// yes: type X = { somePropert: NODE }
|
|
3293
|
+
// no: type X = { NODE: OtherType }
|
|
3294
|
+
case 'ObjectTypeProperty':
|
|
3295
|
+
return parent.key !== node;
|
|
3296
|
+
// yes: enum X { Foo = NODE }
|
|
3297
|
+
// no: enum X { NODE }
|
|
3298
|
+
case 'TSEnumMember':
|
|
3299
|
+
return parent.id !== node;
|
|
3300
|
+
// yes: { [NODE]: value }
|
|
3301
|
+
// no: { NODE: value }
|
|
3302
|
+
case 'TSPropertySignature':
|
|
3303
|
+
if (parent.key === node) {
|
|
3304
|
+
return !!parent.computed;
|
|
3305
|
+
}
|
|
3306
|
+
return true;
|
|
3307
|
+
}
|
|
3308
|
+
return true;
|
|
3309
|
+
}
|
|
3144
3310
|
|
|
3145
3311
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
3146
3312
|
const transformExpression = (node, context) => {
|
|
@@ -3179,7 +3345,7 @@ function processExpression(node, context,
|
|
|
3179
3345
|
// function params
|
|
3180
3346
|
asParams = false,
|
|
3181
3347
|
// v-on handler values may contain multiple statements
|
|
3182
|
-
asRawStatements = false) {
|
|
3348
|
+
asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
3183
3349
|
if (!context.prefixIdentifiers || !node.content.trim()) {
|
|
3184
3350
|
return node;
|
|
3185
3351
|
}
|
|
@@ -3193,7 +3359,7 @@ asRawStatements = false) {
|
|
|
3193
3359
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
3194
3360
|
// ({ x } = y)
|
|
3195
3361
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
3196
|
-
if (type === "setup-const" /* SETUP_CONST */) {
|
|
3362
|
+
if (type === "setup-const" /* SETUP_CONST */ || localVars[raw]) {
|
|
3197
3363
|
return raw;
|
|
3198
3364
|
}
|
|
3199
3365
|
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
@@ -3217,7 +3383,7 @@ asRawStatements = false) {
|
|
|
3217
3383
|
// x = y --> isRef(x) ? x.value = y : x = y
|
|
3218
3384
|
const { right: rVal, operator } = parent;
|
|
3219
3385
|
const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
|
|
3220
|
-
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context));
|
|
3386
|
+
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context, false, false, knownIds));
|
|
3221
3387
|
return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore\n` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
|
|
3222
3388
|
}
|
|
3223
3389
|
else if (isUpdateArg) {
|
|
@@ -3303,7 +3469,7 @@ asRawStatements = false) {
|
|
|
3303
3469
|
}).program;
|
|
3304
3470
|
}
|
|
3305
3471
|
catch (e) {
|
|
3306
|
-
context.onError(createCompilerError(
|
|
3472
|
+
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, e.message));
|
|
3307
3473
|
return node;
|
|
3308
3474
|
}
|
|
3309
3475
|
const ids = [];
|
|
@@ -3433,7 +3599,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3433
3599
|
if (dir.name !== 'else' &&
|
|
3434
3600
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
3435
3601
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3436
|
-
context.onError(createCompilerError(
|
|
3602
|
+
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3437
3603
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
3438
3604
|
}
|
|
3439
3605
|
if (context.prefixIdentifiers && dir.exp) {
|
|
@@ -3488,7 +3654,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3488
3654
|
if (key) {
|
|
3489
3655
|
sibling.branches.forEach(({ userKey }) => {
|
|
3490
3656
|
if (isSameKey(userKey, key)) {
|
|
3491
|
-
context.onError(createCompilerError(
|
|
3657
|
+
context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3492
3658
|
}
|
|
3493
3659
|
});
|
|
3494
3660
|
}
|
|
@@ -3506,7 +3672,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3506
3672
|
context.currentNode = null;
|
|
3507
3673
|
}
|
|
3508
3674
|
else {
|
|
3509
|
-
context.onError(createCompilerError(
|
|
3675
|
+
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3510
3676
|
}
|
|
3511
3677
|
break;
|
|
3512
3678
|
}
|
|
@@ -3657,7 +3823,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3657
3823
|
if (c.type === 1 /* ELEMENT */) {
|
|
3658
3824
|
const key = findProp(c, 'key');
|
|
3659
3825
|
if (key) {
|
|
3660
|
-
context.onError(createCompilerError(
|
|
3826
|
+
context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3661
3827
|
return true;
|
|
3662
3828
|
}
|
|
3663
3829
|
}
|
|
@@ -3742,7 +3908,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3742
3908
|
// target-agnostic transform used for both Client and SSR
|
|
3743
3909
|
function processFor(node, dir, context, processCodegen) {
|
|
3744
3910
|
if (!dir.exp) {
|
|
3745
|
-
context.onError(createCompilerError(
|
|
3911
|
+
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3746
3912
|
return;
|
|
3747
3913
|
}
|
|
3748
3914
|
const parseResult = parseForExpression(
|
|
@@ -3750,7 +3916,7 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3750
3916
|
// before expression transform.
|
|
3751
3917
|
dir.exp, context);
|
|
3752
3918
|
if (!parseResult) {
|
|
3753
|
-
context.onError(createCompilerError(
|
|
3919
|
+
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3754
3920
|
return;
|
|
3755
3921
|
}
|
|
3756
3922
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
@@ -3956,7 +4122,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3956
4122
|
}
|
|
3957
4123
|
if (onComponentSlot) {
|
|
3958
4124
|
// already has on-component slot - this is incorrect usage.
|
|
3959
|
-
context.onError(createCompilerError(
|
|
4125
|
+
context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3960
4126
|
break;
|
|
3961
4127
|
}
|
|
3962
4128
|
hasTemplateSlots = true;
|
|
@@ -4003,7 +4169,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4003
4169
|
: buildDynamicSlot(slotName, slotFunction);
|
|
4004
4170
|
}
|
|
4005
4171
|
else {
|
|
4006
|
-
context.onError(createCompilerError(
|
|
4172
|
+
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
4007
4173
|
}
|
|
4008
4174
|
}
|
|
4009
4175
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -4019,14 +4185,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4019
4185
|
]));
|
|
4020
4186
|
}
|
|
4021
4187
|
else {
|
|
4022
|
-
context.onError(createCompilerError(
|
|
4188
|
+
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
4023
4189
|
}
|
|
4024
4190
|
}
|
|
4025
4191
|
else {
|
|
4026
4192
|
// check duplicate static names
|
|
4027
4193
|
if (staticSlotName) {
|
|
4028
4194
|
if (seenSlotNames.has(staticSlotName)) {
|
|
4029
|
-
context.onError(createCompilerError(
|
|
4195
|
+
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
4030
4196
|
continue;
|
|
4031
4197
|
}
|
|
4032
4198
|
seenSlotNames.add(staticSlotName);
|
|
@@ -4056,7 +4222,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4056
4222
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
4057
4223
|
// implicit default slot (mixed with named slots)
|
|
4058
4224
|
if (hasNamedDefaultSlot) {
|
|
4059
|
-
context.onError(createCompilerError(
|
|
4225
|
+
context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
4060
4226
|
}
|
|
4061
4227
|
else {
|
|
4062
4228
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -4188,7 +4354,7 @@ const transformElement = (node, context) => {
|
|
|
4188
4354
|
// 2. Force keep-alive to always be updated, since it uses raw children.
|
|
4189
4355
|
patchFlag |= 1024 /* DYNAMIC_SLOTS */;
|
|
4190
4356
|
if (node.children.length > 1) {
|
|
4191
|
-
context.onError(createCompilerError(
|
|
4357
|
+
context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
|
|
4192
4358
|
start: node.children[0].loc.start,
|
|
4193
4359
|
end: node.children[node.children.length - 1].loc.end,
|
|
4194
4360
|
source: ''
|
|
@@ -4430,16 +4596,15 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4430
4596
|
const prop = props[i];
|
|
4431
4597
|
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
4432
4598
|
const { loc, name, value } = prop;
|
|
4433
|
-
let
|
|
4599
|
+
let valueNode = createSimpleExpression(value ? value.content : '', true, value ? value.loc : loc);
|
|
4434
4600
|
if (name === 'ref') {
|
|
4435
4601
|
hasRef = true;
|
|
4436
4602
|
// in inline mode there is no setupState object, so we can't use string
|
|
4437
4603
|
// keys to set the ref. Instead, we need to transform it to pass the
|
|
4438
4604
|
// acrtual ref instead.
|
|
4439
|
-
if (value
|
|
4440
|
-
|
|
4441
|
-
context.bindingMetadata
|
|
4442
|
-
isStatic = false;
|
|
4605
|
+
if (context.inline && (value === null || value === void 0 ? void 0 : value.content)) {
|
|
4606
|
+
valueNode = createFunctionExpression(['_value', '_refs']);
|
|
4607
|
+
valueNode.body = createBlockStatement(processInlineRef(context.bindingMetadata, value.content));
|
|
4443
4608
|
}
|
|
4444
4609
|
}
|
|
4445
4610
|
// skip is on <component>, or is="vue:xxx"
|
|
@@ -4449,7 +4614,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4449
4614
|
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4450
4615
|
continue;
|
|
4451
4616
|
}
|
|
4452
|
-
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)),
|
|
4617
|
+
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), valueNode));
|
|
4453
4618
|
}
|
|
4454
4619
|
else {
|
|
4455
4620
|
// directives
|
|
@@ -4459,7 +4624,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4459
4624
|
// skip v-slot - it is handled by its dedicated transform.
|
|
4460
4625
|
if (name === 'slot') {
|
|
4461
4626
|
if (!isComponent) {
|
|
4462
|
-
context.onError(createCompilerError(
|
|
4627
|
+
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
4463
4628
|
}
|
|
4464
4629
|
continue;
|
|
4465
4630
|
}
|
|
@@ -4531,8 +4696,8 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4531
4696
|
}
|
|
4532
4697
|
else {
|
|
4533
4698
|
context.onError(createCompilerError(isVBind
|
|
4534
|
-
?
|
|
4535
|
-
:
|
|
4699
|
+
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
4700
|
+
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4536
4701
|
}
|
|
4537
4702
|
continue;
|
|
4538
4703
|
}
|
|
@@ -4758,6 +4923,17 @@ function stringifyDynamicPropNames(props) {
|
|
|
4758
4923
|
}
|
|
4759
4924
|
function isComponentTag(tag) {
|
|
4760
4925
|
return tag[0].toLowerCase() + tag.slice(1) === 'component';
|
|
4926
|
+
}
|
|
4927
|
+
function processInlineRef(bindings, raw) {
|
|
4928
|
+
const body = [createSimpleExpression(`_refs['${raw}'] = _value`)];
|
|
4929
|
+
const type = bindings[raw];
|
|
4930
|
+
if (type === "setup-ref" /* SETUP_REF */) {
|
|
4931
|
+
body.push(createSimpleExpression(`${raw}.value = _value`));
|
|
4932
|
+
}
|
|
4933
|
+
else if (type === "setup-let" /* SETUP_LET */) {
|
|
4934
|
+
body.push(createSimpleExpression(`${raw} = _value`));
|
|
4935
|
+
}
|
|
4936
|
+
return body;
|
|
4761
4937
|
}
|
|
4762
4938
|
|
|
4763
4939
|
Object.freeze({})
|
|
@@ -4841,7 +5017,7 @@ function processSlotOutlet(node, context) {
|
|
|
4841
5017
|
const { props, directives } = buildProps(node, context, nonNameProps);
|
|
4842
5018
|
slotProps = props;
|
|
4843
5019
|
if (directives.length) {
|
|
4844
|
-
context.onError(createCompilerError(
|
|
5020
|
+
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4845
5021
|
}
|
|
4846
5022
|
}
|
|
4847
5023
|
return {
|
|
@@ -4854,7 +5030,7 @@ const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
|
|
|
4854
5030
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4855
5031
|
const { loc, modifiers, arg } = dir;
|
|
4856
5032
|
if (!dir.exp && !modifiers.length) {
|
|
4857
|
-
context.onError(createCompilerError(
|
|
5033
|
+
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4858
5034
|
}
|
|
4859
5035
|
let eventName;
|
|
4860
5036
|
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
@@ -4995,7 +5171,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4995
5171
|
}
|
|
4996
5172
|
if (!exp ||
|
|
4997
5173
|
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4998
|
-
context.onError(createCompilerError(
|
|
5174
|
+
context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
|
|
4999
5175
|
return {
|
|
5000
5176
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
5001
5177
|
};
|
|
@@ -5131,7 +5307,7 @@ const transformOnce = (node, context) => {
|
|
|
5131
5307
|
const transformModel = (dir, node, context) => {
|
|
5132
5308
|
const { exp, arg } = dir;
|
|
5133
5309
|
if (!exp) {
|
|
5134
|
-
context.onError(createCompilerError(
|
|
5310
|
+
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
5135
5311
|
return createTransformProps();
|
|
5136
5312
|
}
|
|
5137
5313
|
const rawExp = exp.loc.source;
|
|
@@ -5143,13 +5319,13 @@ const transformModel = (dir, node, context) => {
|
|
|
5143
5319
|
bindingType &&
|
|
5144
5320
|
bindingType !== "setup-const" /* SETUP_CONST */;
|
|
5145
5321
|
if (!expString.trim() || (!isMemberExpression(expString) && !maybeRef)) {
|
|
5146
|
-
context.onError(createCompilerError(
|
|
5322
|
+
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
5147
5323
|
return createTransformProps();
|
|
5148
5324
|
}
|
|
5149
5325
|
if (context.prefixIdentifiers &&
|
|
5150
5326
|
isSimpleIdentifier(expString) &&
|
|
5151
5327
|
context.identifiers[expString]) {
|
|
5152
|
-
context.onError(createCompilerError(
|
|
5328
|
+
context.onError(createCompilerError(43 /* X_V_MODEL_ON_SCOPE_VARIABLE */, exp.loc));
|
|
5153
5329
|
return createTransformProps();
|
|
5154
5330
|
}
|
|
5155
5331
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -5444,10 +5620,10 @@ function baseCompile(template, options = {}) {
|
|
|
5444
5620
|
const isModuleMode = options.mode === 'module';
|
|
5445
5621
|
const prefixIdentifiers = (options.prefixIdentifiers === true || isModuleMode);
|
|
5446
5622
|
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
5447
|
-
onError(createCompilerError(
|
|
5623
|
+
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
5448
5624
|
}
|
|
5449
5625
|
if (options.scopeId && !isModuleMode) {
|
|
5450
|
-
onError(createCompilerError(
|
|
5626
|
+
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
5451
5627
|
}
|
|
5452
5628
|
const ast = shared.isString(template) ? baseParse(template, options) : template;
|
|
5453
5629
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
|