@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
|
|
|
@@ -50,37 +49,38 @@ const errorMessages = {
|
|
|
50
49
|
[23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
51
50
|
[24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
52
51
|
[25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
53
|
-
[
|
|
52
|
+
[27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
54
53
|
'Note that dynamic directive argument cannot contain spaces.',
|
|
54
|
+
[26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
55
55
|
// transform errors
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
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.`,
|
|
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>.` +
|
|
66
66
|
`When there are multiple named slots, all slots should use <template> ` +
|
|
67
67
|
`syntax to avoid scope ambiguity.`,
|
|
68
|
-
[
|
|
69
|
-
[
|
|
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 ` +
|
|
70
70
|
`default slot. These children will be ignored.`,
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
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.`,
|
|
77
77
|
// generic errors
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
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.`,
|
|
82
82
|
// just to fullfill types
|
|
83
|
-
[
|
|
83
|
+
[50 /* __EXTEND_POINT__ */]: ``
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
const FRAGMENT = Symbol(``);
|
|
@@ -1273,6 +1273,13 @@ function parseAttributes(context, type) {
|
|
|
1273
1273
|
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1274
1274
|
}
|
|
1275
1275
|
const attr = parseAttribute(context, attributeNames);
|
|
1276
|
+
// Trim whitespace between class
|
|
1277
|
+
// https://github.com/vuejs/vue-next/issues/4251
|
|
1278
|
+
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1279
|
+
attr.value &&
|
|
1280
|
+
attr.name === 'class') {
|
|
1281
|
+
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1282
|
+
}
|
|
1276
1283
|
if (type === 0 /* Start */) {
|
|
1277
1284
|
props.push(attr);
|
|
1278
1285
|
}
|
|
@@ -1315,7 +1322,7 @@ function parseAttribute(context, nameSet) {
|
|
|
1315
1322
|
}
|
|
1316
1323
|
}
|
|
1317
1324
|
const loc = getSelection(context, start);
|
|
1318
|
-
if (!context.inVPre && /^(v
|
|
1325
|
+
if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
|
|
1319
1326
|
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
|
|
1320
1327
|
let isPropShorthand = startsWith(name, '.');
|
|
1321
1328
|
let dirName = match[1] ||
|
|
@@ -1334,9 +1341,12 @@ function parseAttribute(context, nameSet) {
|
|
|
1334
1341
|
if (content.startsWith('[')) {
|
|
1335
1342
|
isStatic = false;
|
|
1336
1343
|
if (!content.endsWith(']')) {
|
|
1337
|
-
emitError(context,
|
|
1344
|
+
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1345
|
+
content = content.substr(1);
|
|
1346
|
+
}
|
|
1347
|
+
else {
|
|
1348
|
+
content = content.substr(1, content.length - 2);
|
|
1338
1349
|
}
|
|
1339
|
-
content = content.substr(1, content.length - 2);
|
|
1340
1350
|
}
|
|
1341
1351
|
else if (isSlot) {
|
|
1342
1352
|
// #1241 special case for v-slot: vuetify relies extensively on slot
|
|
@@ -1389,6 +1399,10 @@ function parseAttribute(context, nameSet) {
|
|
|
1389
1399
|
loc
|
|
1390
1400
|
};
|
|
1391
1401
|
}
|
|
1402
|
+
// missing directive name or illegal directive name
|
|
1403
|
+
if (!context.inVPre && startsWith(name, 'v-')) {
|
|
1404
|
+
emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
|
|
1405
|
+
}
|
|
1392
1406
|
return {
|
|
1393
1407
|
type: 6 /* ATTRIBUTE */,
|
|
1394
1408
|
name,
|
|
@@ -2965,7 +2979,7 @@ function isReferencedIdentifier(id, parent, parentStack) {
|
|
|
2965
2979
|
if (id.name === 'arguments') {
|
|
2966
2980
|
return false;
|
|
2967
2981
|
}
|
|
2968
|
-
if (
|
|
2982
|
+
if (isReferenced(id, parent)) {
|
|
2969
2983
|
return true;
|
|
2970
2984
|
}
|
|
2971
2985
|
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
@@ -3078,7 +3092,159 @@ const isFunctionType = (node) => {
|
|
|
3078
3092
|
const isStaticProperty = (node) => node &&
|
|
3079
3093
|
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3080
3094
|
!node.computed;
|
|
3081
|
-
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3095
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3096
|
+
/**
|
|
3097
|
+
* Copied from https://github.com/babel/babel/blob/main/packages/babel-types/src/validators/isReferenced.ts
|
|
3098
|
+
* To avoid runtime dependency on @babel/types (which includes process references)
|
|
3099
|
+
* This file should not change very often in babel but we may need to keep it
|
|
3100
|
+
* up-to-date from time to time.
|
|
3101
|
+
*
|
|
3102
|
+
* https://github.com/babel/babel/blob/main/LICENSE
|
|
3103
|
+
*
|
|
3104
|
+
*/
|
|
3105
|
+
function isReferenced(node, parent, grandparent) {
|
|
3106
|
+
switch (parent.type) {
|
|
3107
|
+
// yes: PARENT[NODE]
|
|
3108
|
+
// yes: NODE.child
|
|
3109
|
+
// no: parent.NODE
|
|
3110
|
+
case 'MemberExpression':
|
|
3111
|
+
case 'OptionalMemberExpression':
|
|
3112
|
+
if (parent.property === node) {
|
|
3113
|
+
return !!parent.computed;
|
|
3114
|
+
}
|
|
3115
|
+
return parent.object === node;
|
|
3116
|
+
case 'JSXMemberExpression':
|
|
3117
|
+
return parent.object === node;
|
|
3118
|
+
// no: let NODE = init;
|
|
3119
|
+
// yes: let id = NODE;
|
|
3120
|
+
case 'VariableDeclarator':
|
|
3121
|
+
return parent.init === node;
|
|
3122
|
+
// yes: () => NODE
|
|
3123
|
+
// no: (NODE) => {}
|
|
3124
|
+
case 'ArrowFunctionExpression':
|
|
3125
|
+
return parent.body === node;
|
|
3126
|
+
// no: class { #NODE; }
|
|
3127
|
+
// no: class { get #NODE() {} }
|
|
3128
|
+
// no: class { #NODE() {} }
|
|
3129
|
+
// no: class { fn() { return this.#NODE; } }
|
|
3130
|
+
case 'PrivateName':
|
|
3131
|
+
return false;
|
|
3132
|
+
// no: class { NODE() {} }
|
|
3133
|
+
// yes: class { [NODE]() {} }
|
|
3134
|
+
// no: class { foo(NODE) {} }
|
|
3135
|
+
case 'ClassMethod':
|
|
3136
|
+
case 'ClassPrivateMethod':
|
|
3137
|
+
case 'ObjectMethod':
|
|
3138
|
+
if (parent.key === node) {
|
|
3139
|
+
return !!parent.computed;
|
|
3140
|
+
}
|
|
3141
|
+
return false;
|
|
3142
|
+
// yes: { [NODE]: "" }
|
|
3143
|
+
// no: { NODE: "" }
|
|
3144
|
+
// depends: { NODE }
|
|
3145
|
+
// depends: { key: NODE }
|
|
3146
|
+
case 'ObjectProperty':
|
|
3147
|
+
if (parent.key === node) {
|
|
3148
|
+
return !!parent.computed;
|
|
3149
|
+
}
|
|
3150
|
+
// parent.value === node
|
|
3151
|
+
return !grandparent || grandparent.type !== 'ObjectPattern';
|
|
3152
|
+
// no: class { NODE = value; }
|
|
3153
|
+
// yes: class { [NODE] = value; }
|
|
3154
|
+
// yes: class { key = NODE; }
|
|
3155
|
+
case 'ClassProperty':
|
|
3156
|
+
if (parent.key === node) {
|
|
3157
|
+
return !!parent.computed;
|
|
3158
|
+
}
|
|
3159
|
+
return true;
|
|
3160
|
+
case 'ClassPrivateProperty':
|
|
3161
|
+
return parent.key !== node;
|
|
3162
|
+
// no: class NODE {}
|
|
3163
|
+
// yes: class Foo extends NODE {}
|
|
3164
|
+
case 'ClassDeclaration':
|
|
3165
|
+
case 'ClassExpression':
|
|
3166
|
+
return parent.superClass === node;
|
|
3167
|
+
// yes: left = NODE;
|
|
3168
|
+
// no: NODE = right;
|
|
3169
|
+
case 'AssignmentExpression':
|
|
3170
|
+
return parent.right === node;
|
|
3171
|
+
// no: [NODE = foo] = [];
|
|
3172
|
+
// yes: [foo = NODE] = [];
|
|
3173
|
+
case 'AssignmentPattern':
|
|
3174
|
+
return parent.right === node;
|
|
3175
|
+
// no: NODE: for (;;) {}
|
|
3176
|
+
case 'LabeledStatement':
|
|
3177
|
+
return false;
|
|
3178
|
+
// no: try {} catch (NODE) {}
|
|
3179
|
+
case 'CatchClause':
|
|
3180
|
+
return false;
|
|
3181
|
+
// no: function foo(...NODE) {}
|
|
3182
|
+
case 'RestElement':
|
|
3183
|
+
return false;
|
|
3184
|
+
case 'BreakStatement':
|
|
3185
|
+
case 'ContinueStatement':
|
|
3186
|
+
return false;
|
|
3187
|
+
// no: function NODE() {}
|
|
3188
|
+
// no: function foo(NODE) {}
|
|
3189
|
+
case 'FunctionDeclaration':
|
|
3190
|
+
case 'FunctionExpression':
|
|
3191
|
+
return false;
|
|
3192
|
+
// no: export NODE from "foo";
|
|
3193
|
+
// no: export * as NODE from "foo";
|
|
3194
|
+
case 'ExportNamespaceSpecifier':
|
|
3195
|
+
case 'ExportDefaultSpecifier':
|
|
3196
|
+
return false;
|
|
3197
|
+
// no: export { foo as NODE };
|
|
3198
|
+
// yes: export { NODE as foo };
|
|
3199
|
+
// no: export { NODE as foo } from "foo";
|
|
3200
|
+
case 'ExportSpecifier':
|
|
3201
|
+
// @ts-expect-error
|
|
3202
|
+
if (grandparent === null || grandparent === void 0 ? void 0 : grandparent.source) {
|
|
3203
|
+
return false;
|
|
3204
|
+
}
|
|
3205
|
+
return parent.local === node;
|
|
3206
|
+
// no: import NODE from "foo";
|
|
3207
|
+
// no: import * as NODE from "foo";
|
|
3208
|
+
// no: import { NODE as foo } from "foo";
|
|
3209
|
+
// no: import { foo as NODE } from "foo";
|
|
3210
|
+
// no: import NODE from "bar";
|
|
3211
|
+
case 'ImportDefaultSpecifier':
|
|
3212
|
+
case 'ImportNamespaceSpecifier':
|
|
3213
|
+
case 'ImportSpecifier':
|
|
3214
|
+
return false;
|
|
3215
|
+
// no: import "foo" assert { NODE: "json" }
|
|
3216
|
+
case 'ImportAttribute':
|
|
3217
|
+
return false;
|
|
3218
|
+
// no: <div NODE="foo" />
|
|
3219
|
+
case 'JSXAttribute':
|
|
3220
|
+
return false;
|
|
3221
|
+
// no: [NODE] = [];
|
|
3222
|
+
// no: ({ NODE }) = [];
|
|
3223
|
+
case 'ObjectPattern':
|
|
3224
|
+
case 'ArrayPattern':
|
|
3225
|
+
return false;
|
|
3226
|
+
// no: new.NODE
|
|
3227
|
+
// no: NODE.target
|
|
3228
|
+
case 'MetaProperty':
|
|
3229
|
+
return false;
|
|
3230
|
+
// yes: type X = { somePropert: NODE }
|
|
3231
|
+
// no: type X = { NODE: OtherType }
|
|
3232
|
+
case 'ObjectTypeProperty':
|
|
3233
|
+
return parent.key !== node;
|
|
3234
|
+
// yes: enum X { Foo = NODE }
|
|
3235
|
+
// no: enum X { NODE }
|
|
3236
|
+
case 'TSEnumMember':
|
|
3237
|
+
return parent.id !== node;
|
|
3238
|
+
// yes: { [NODE]: value }
|
|
3239
|
+
// no: { NODE: value }
|
|
3240
|
+
case 'TSPropertySignature':
|
|
3241
|
+
if (parent.key === node) {
|
|
3242
|
+
return !!parent.computed;
|
|
3243
|
+
}
|
|
3244
|
+
return true;
|
|
3245
|
+
}
|
|
3246
|
+
return true;
|
|
3247
|
+
}
|
|
3082
3248
|
|
|
3083
3249
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
3084
3250
|
const transformExpression = (node, context) => {
|
|
@@ -3117,7 +3283,7 @@ function processExpression(node, context,
|
|
|
3117
3283
|
// function params
|
|
3118
3284
|
asParams = false,
|
|
3119
3285
|
// v-on handler values may contain multiple statements
|
|
3120
|
-
asRawStatements = false) {
|
|
3286
|
+
asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
3121
3287
|
if (!context.prefixIdentifiers || !node.content.trim()) {
|
|
3122
3288
|
return node;
|
|
3123
3289
|
}
|
|
@@ -3131,7 +3297,7 @@ asRawStatements = false) {
|
|
|
3131
3297
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
3132
3298
|
// ({ x } = y)
|
|
3133
3299
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
3134
|
-
if (type === "setup-const" /* SETUP_CONST */) {
|
|
3300
|
+
if (type === "setup-const" /* SETUP_CONST */ || localVars[raw]) {
|
|
3135
3301
|
return raw;
|
|
3136
3302
|
}
|
|
3137
3303
|
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
@@ -3155,7 +3321,7 @@ asRawStatements = false) {
|
|
|
3155
3321
|
// x = y --> isRef(x) ? x.value = y : x = y
|
|
3156
3322
|
const { right: rVal, operator } = parent;
|
|
3157
3323
|
const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
|
|
3158
|
-
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context));
|
|
3324
|
+
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context, false, false, knownIds));
|
|
3159
3325
|
return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore\n` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
|
|
3160
3326
|
}
|
|
3161
3327
|
else if (isUpdateArg) {
|
|
@@ -3241,7 +3407,7 @@ asRawStatements = false) {
|
|
|
3241
3407
|
}).program;
|
|
3242
3408
|
}
|
|
3243
3409
|
catch (e) {
|
|
3244
|
-
context.onError(createCompilerError(
|
|
3410
|
+
context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, e.message));
|
|
3245
3411
|
return node;
|
|
3246
3412
|
}
|
|
3247
3413
|
const ids = [];
|
|
@@ -3371,7 +3537,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3371
3537
|
if (dir.name !== 'else' &&
|
|
3372
3538
|
(!dir.exp || !dir.exp.content.trim())) {
|
|
3373
3539
|
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3374
|
-
context.onError(createCompilerError(
|
|
3540
|
+
context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
3375
3541
|
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
3376
3542
|
}
|
|
3377
3543
|
if (context.prefixIdentifiers && dir.exp) {
|
|
@@ -3413,7 +3579,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3413
3579
|
if (key) {
|
|
3414
3580
|
sibling.branches.forEach(({ userKey }) => {
|
|
3415
3581
|
if (isSameKey(userKey, key)) {
|
|
3416
|
-
context.onError(createCompilerError(
|
|
3582
|
+
context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
3417
3583
|
}
|
|
3418
3584
|
});
|
|
3419
3585
|
}
|
|
@@ -3431,7 +3597,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
3431
3597
|
context.currentNode = null;
|
|
3432
3598
|
}
|
|
3433
3599
|
else {
|
|
3434
|
-
context.onError(createCompilerError(
|
|
3600
|
+
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
3435
3601
|
}
|
|
3436
3602
|
break;
|
|
3437
3603
|
}
|
|
@@ -3576,7 +3742,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3576
3742
|
if (c.type === 1 /* ELEMENT */) {
|
|
3577
3743
|
const key = findProp(c, 'key');
|
|
3578
3744
|
if (key) {
|
|
3579
|
-
context.onError(createCompilerError(
|
|
3745
|
+
context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
3580
3746
|
return true;
|
|
3581
3747
|
}
|
|
3582
3748
|
}
|
|
@@ -3660,7 +3826,7 @@ const transformFor = createStructuralDirectiveTransform('for', (node, dir, conte
|
|
|
3660
3826
|
// target-agnostic transform used for both Client and SSR
|
|
3661
3827
|
function processFor(node, dir, context, processCodegen) {
|
|
3662
3828
|
if (!dir.exp) {
|
|
3663
|
-
context.onError(createCompilerError(
|
|
3829
|
+
context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
3664
3830
|
return;
|
|
3665
3831
|
}
|
|
3666
3832
|
const parseResult = parseForExpression(
|
|
@@ -3668,7 +3834,7 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
3668
3834
|
// before expression transform.
|
|
3669
3835
|
dir.exp, context);
|
|
3670
3836
|
if (!parseResult) {
|
|
3671
|
-
context.onError(createCompilerError(
|
|
3837
|
+
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
3672
3838
|
return;
|
|
3673
3839
|
}
|
|
3674
3840
|
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
@@ -3874,7 +4040,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3874
4040
|
}
|
|
3875
4041
|
if (onComponentSlot) {
|
|
3876
4042
|
// already has on-component slot - this is incorrect usage.
|
|
3877
|
-
context.onError(createCompilerError(
|
|
4043
|
+
context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
|
|
3878
4044
|
break;
|
|
3879
4045
|
}
|
|
3880
4046
|
hasTemplateSlots = true;
|
|
@@ -3921,7 +4087,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3921
4087
|
: buildDynamicSlot(slotName, slotFunction);
|
|
3922
4088
|
}
|
|
3923
4089
|
else {
|
|
3924
|
-
context.onError(createCompilerError(
|
|
4090
|
+
context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
|
|
3925
4091
|
}
|
|
3926
4092
|
}
|
|
3927
4093
|
else if ((vFor = findDir(slotElement, 'for'))) {
|
|
@@ -3937,14 +4103,14 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3937
4103
|
]));
|
|
3938
4104
|
}
|
|
3939
4105
|
else {
|
|
3940
|
-
context.onError(createCompilerError(
|
|
4106
|
+
context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
|
|
3941
4107
|
}
|
|
3942
4108
|
}
|
|
3943
4109
|
else {
|
|
3944
4110
|
// check duplicate static names
|
|
3945
4111
|
if (staticSlotName) {
|
|
3946
4112
|
if (seenSlotNames.has(staticSlotName)) {
|
|
3947
|
-
context.onError(createCompilerError(
|
|
4113
|
+
context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
|
|
3948
4114
|
continue;
|
|
3949
4115
|
}
|
|
3950
4116
|
seenSlotNames.add(staticSlotName);
|
|
@@ -3974,7 +4140,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
3974
4140
|
implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
|
|
3975
4141
|
// implicit default slot (mixed with named slots)
|
|
3976
4142
|
if (hasNamedDefaultSlot) {
|
|
3977
|
-
context.onError(createCompilerError(
|
|
4143
|
+
context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
|
|
3978
4144
|
}
|
|
3979
4145
|
else {
|
|
3980
4146
|
slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
|
|
@@ -4329,16 +4495,15 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4329
4495
|
const prop = props[i];
|
|
4330
4496
|
if (prop.type === 6 /* ATTRIBUTE */) {
|
|
4331
4497
|
const { loc, name, value } = prop;
|
|
4332
|
-
let
|
|
4498
|
+
let valueNode = createSimpleExpression(value ? value.content : '', true, value ? value.loc : loc);
|
|
4333
4499
|
if (name === 'ref') {
|
|
4334
4500
|
hasRef = true;
|
|
4335
4501
|
// in inline mode there is no setupState object, so we can't use string
|
|
4336
4502
|
// keys to set the ref. Instead, we need to transform it to pass the
|
|
4337
4503
|
// acrtual ref instead.
|
|
4338
|
-
if (value
|
|
4339
|
-
|
|
4340
|
-
context.bindingMetadata
|
|
4341
|
-
isStatic = false;
|
|
4504
|
+
if (context.inline && (value === null || value === void 0 ? void 0 : value.content)) {
|
|
4505
|
+
valueNode = createFunctionExpression(['_value', '_refs']);
|
|
4506
|
+
valueNode.body = createBlockStatement(processInlineRef(context.bindingMetadata, value.content));
|
|
4342
4507
|
}
|
|
4343
4508
|
}
|
|
4344
4509
|
// skip is on <component>, or is="vue:xxx"
|
|
@@ -4348,7 +4513,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4348
4513
|
(isCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context)))) {
|
|
4349
4514
|
continue;
|
|
4350
4515
|
}
|
|
4351
|
-
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)),
|
|
4516
|
+
properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), valueNode));
|
|
4352
4517
|
}
|
|
4353
4518
|
else {
|
|
4354
4519
|
// directives
|
|
@@ -4358,7 +4523,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4358
4523
|
// skip v-slot - it is handled by its dedicated transform.
|
|
4359
4524
|
if (name === 'slot') {
|
|
4360
4525
|
if (!isComponent) {
|
|
4361
|
-
context.onError(createCompilerError(
|
|
4526
|
+
context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
|
|
4362
4527
|
}
|
|
4363
4528
|
continue;
|
|
4364
4529
|
}
|
|
@@ -4407,8 +4572,8 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4407
4572
|
}
|
|
4408
4573
|
else {
|
|
4409
4574
|
context.onError(createCompilerError(isVBind
|
|
4410
|
-
?
|
|
4411
|
-
:
|
|
4575
|
+
? 34 /* X_V_BIND_NO_EXPRESSION */
|
|
4576
|
+
: 35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4412
4577
|
}
|
|
4413
4578
|
continue;
|
|
4414
4579
|
}
|
|
@@ -4634,6 +4799,17 @@ function stringifyDynamicPropNames(props) {
|
|
|
4634
4799
|
}
|
|
4635
4800
|
function isComponentTag(tag) {
|
|
4636
4801
|
return tag[0].toLowerCase() + tag.slice(1) === 'component';
|
|
4802
|
+
}
|
|
4803
|
+
function processInlineRef(bindings, raw) {
|
|
4804
|
+
const body = [createSimpleExpression(`_refs['${raw}'] = _value`)];
|
|
4805
|
+
const type = bindings[raw];
|
|
4806
|
+
if (type === "setup-ref" /* SETUP_REF */) {
|
|
4807
|
+
body.push(createSimpleExpression(`${raw}.value = _value`));
|
|
4808
|
+
}
|
|
4809
|
+
else if (type === "setup-let" /* SETUP_LET */) {
|
|
4810
|
+
body.push(createSimpleExpression(`${raw} = _value`));
|
|
4811
|
+
}
|
|
4812
|
+
return body;
|
|
4637
4813
|
}
|
|
4638
4814
|
|
|
4639
4815
|
const cacheStringFunction = (fn) => {
|
|
@@ -4714,7 +4890,7 @@ function processSlotOutlet(node, context) {
|
|
|
4714
4890
|
const { props, directives } = buildProps(node, context, nonNameProps);
|
|
4715
4891
|
slotProps = props;
|
|
4716
4892
|
if (directives.length) {
|
|
4717
|
-
context.onError(createCompilerError(
|
|
4893
|
+
context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
|
|
4718
4894
|
}
|
|
4719
4895
|
}
|
|
4720
4896
|
return {
|
|
@@ -4727,7 +4903,7 @@ const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
|
|
|
4727
4903
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4728
4904
|
const { loc, modifiers, arg } = dir;
|
|
4729
4905
|
if (!dir.exp && !modifiers.length) {
|
|
4730
|
-
context.onError(createCompilerError(
|
|
4906
|
+
context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
|
|
4731
4907
|
}
|
|
4732
4908
|
let eventName;
|
|
4733
4909
|
if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
@@ -4868,7 +5044,7 @@ const transformBind = (dir, _node, context) => {
|
|
|
4868
5044
|
}
|
|
4869
5045
|
if (!exp ||
|
|
4870
5046
|
(exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
|
|
4871
|
-
context.onError(createCompilerError(
|
|
5047
|
+
context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
|
|
4872
5048
|
return {
|
|
4873
5049
|
props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
|
|
4874
5050
|
};
|
|
@@ -5004,7 +5180,7 @@ const transformOnce = (node, context) => {
|
|
|
5004
5180
|
const transformModel = (dir, node, context) => {
|
|
5005
5181
|
const { exp, arg } = dir;
|
|
5006
5182
|
if (!exp) {
|
|
5007
|
-
context.onError(createCompilerError(
|
|
5183
|
+
context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
|
|
5008
5184
|
return createTransformProps();
|
|
5009
5185
|
}
|
|
5010
5186
|
const rawExp = exp.loc.source;
|
|
@@ -5016,13 +5192,13 @@ const transformModel = (dir, node, context) => {
|
|
|
5016
5192
|
bindingType &&
|
|
5017
5193
|
bindingType !== "setup-const" /* SETUP_CONST */;
|
|
5018
5194
|
if (!expString.trim() || (!isMemberExpression(expString) && !maybeRef)) {
|
|
5019
|
-
context.onError(createCompilerError(
|
|
5195
|
+
context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
|
|
5020
5196
|
return createTransformProps();
|
|
5021
5197
|
}
|
|
5022
5198
|
if (context.prefixIdentifiers &&
|
|
5023
5199
|
isSimpleIdentifier(expString) &&
|
|
5024
5200
|
context.identifiers[expString]) {
|
|
5025
|
-
context.onError(createCompilerError(
|
|
5201
|
+
context.onError(createCompilerError(43 /* X_V_MODEL_ON_SCOPE_VARIABLE */, exp.loc));
|
|
5026
5202
|
return createTransformProps();
|
|
5027
5203
|
}
|
|
5028
5204
|
const propName = arg ? arg : createSimpleExpression('modelValue', true);
|
|
@@ -5316,10 +5492,10 @@ function baseCompile(template, options = {}) {
|
|
|
5316
5492
|
const isModuleMode = options.mode === 'module';
|
|
5317
5493
|
const prefixIdentifiers = (options.prefixIdentifiers === true || isModuleMode);
|
|
5318
5494
|
if (!prefixIdentifiers && options.cacheHandlers) {
|
|
5319
|
-
onError(createCompilerError(
|
|
5495
|
+
onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
|
|
5320
5496
|
}
|
|
5321
5497
|
if (options.scopeId && !isModuleMode) {
|
|
5322
|
-
onError(createCompilerError(
|
|
5498
|
+
onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
|
|
5323
5499
|
}
|
|
5324
5500
|
const ast = shared.isString(template) ? baseParse(template, options) : template;
|
|
5325
5501
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
|
package/dist/compiler-core.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BlockStatement as BlockStatement_2 } from '@babel/types';
|
|
2
|
-
import { Function as Function_2 } from '@babel/types';
|
|
1
|
+
import type { BlockStatement as BlockStatement_2 } from '@babel/types';
|
|
2
|
+
import type { Function as Function_2 } from '@babel/types';
|
|
3
3
|
import { generateCodeFrame } from '@vue/shared';
|
|
4
|
-
import { Identifier } from '@babel/types';
|
|
5
|
-
import { Node as Node_3 } from '@babel/types';
|
|
6
|
-
import { ObjectProperty } from '@babel/types';
|
|
4
|
+
import type { Identifier } from '@babel/types';
|
|
5
|
+
import type { Node as Node_3 } from '@babel/types';
|
|
6
|
+
import type { ObjectProperty } from '@babel/types';
|
|
7
7
|
import { ParserPlugin } from '@babel/parser';
|
|
8
|
-
import { Program } from '@babel/types';
|
|
8
|
+
import type { Program } from '@babel/types';
|
|
9
9
|
import { RawSourceMap } from 'source-map';
|
|
10
10
|
import { SourceMapGenerator } from 'source-map';
|
|
11
11
|
|
|
@@ -60,7 +60,7 @@ export declare const enum BindingTypes {
|
|
|
60
60
|
*/
|
|
61
61
|
DATA = "data",
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* declared as a prop
|
|
64
64
|
*/
|
|
65
65
|
PROPS = "props",
|
|
66
66
|
/**
|
|
@@ -411,30 +411,31 @@ export declare const enum ErrorCodes {
|
|
|
411
411
|
X_INVALID_END_TAG = 23,
|
|
412
412
|
X_MISSING_END_TAG = 24,
|
|
413
413
|
X_MISSING_INTERPOLATION_END = 25,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
414
|
+
X_MISSING_DIRECTIVE_NAME = 26,
|
|
415
|
+
X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END = 27,
|
|
416
|
+
X_V_IF_NO_EXPRESSION = 28,
|
|
417
|
+
X_V_IF_SAME_KEY = 29,
|
|
418
|
+
X_V_ELSE_NO_ADJACENT_IF = 30,
|
|
419
|
+
X_V_FOR_NO_EXPRESSION = 31,
|
|
420
|
+
X_V_FOR_MALFORMED_EXPRESSION = 32,
|
|
421
|
+
X_V_FOR_TEMPLATE_KEY_PLACEMENT = 33,
|
|
422
|
+
X_V_BIND_NO_EXPRESSION = 34,
|
|
423
|
+
X_V_ON_NO_EXPRESSION = 35,
|
|
424
|
+
X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET = 36,
|
|
425
|
+
X_V_SLOT_MIXED_SLOT_USAGE = 37,
|
|
426
|
+
X_V_SLOT_DUPLICATE_SLOT_NAMES = 38,
|
|
427
|
+
X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN = 39,
|
|
428
|
+
X_V_SLOT_MISPLACED = 40,
|
|
429
|
+
X_V_MODEL_NO_EXPRESSION = 41,
|
|
430
|
+
X_V_MODEL_MALFORMED_EXPRESSION = 42,
|
|
431
|
+
X_V_MODEL_ON_SCOPE_VARIABLE = 43,
|
|
432
|
+
X_INVALID_EXPRESSION = 44,
|
|
433
|
+
X_KEEP_ALIVE_INVALID_CHILDREN = 45,
|
|
434
|
+
X_PREFIX_ID_NOT_SUPPORTED = 46,
|
|
435
|
+
X_MODULE_MODE_NOT_SUPPORTED = 47,
|
|
436
|
+
X_CACHE_HANDLER_NOT_SUPPORTED = 48,
|
|
437
|
+
X_SCOPE_ID_NOT_SUPPORTED = 49,
|
|
438
|
+
__EXTEND_POINT__ = 50
|
|
438
439
|
}
|
|
439
440
|
|
|
440
441
|
declare interface ErrorHandlingOptions {
|
|
@@ -781,7 +782,7 @@ export declare interface Position {
|
|
|
781
782
|
column: number;
|
|
782
783
|
}
|
|
783
784
|
|
|
784
|
-
export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean): ExpressionNode;
|
|
785
|
+
export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
|
|
785
786
|
|
|
786
787
|
export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
|
|
787
788
|
|