@vue/compiler-core 3.2.8 → 3.2.12
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 +177 -12
- package/dist/compiler-core.cjs.prod.js +177 -12
- package/dist/compiler-core.d.ts +8 -8
- package/dist/compiler-core.esm-bundler.js +13 -3
- 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
|
|
|
@@ -1298,6 +1297,13 @@ function parseAttributes(context, type) {
|
|
|
1298
1297
|
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1299
1298
|
}
|
|
1300
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
|
+
}
|
|
1301
1307
|
if (type === 0 /* Start */) {
|
|
1302
1308
|
props.push(attr);
|
|
1303
1309
|
}
|
|
@@ -1360,8 +1366,11 @@ function parseAttribute(context, nameSet) {
|
|
|
1360
1366
|
isStatic = false;
|
|
1361
1367
|
if (!content.endsWith(']')) {
|
|
1362
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);
|
|
1363
1373
|
}
|
|
1364
|
-
content = content.substr(1, content.length - 2);
|
|
1365
1374
|
}
|
|
1366
1375
|
else if (isSlot) {
|
|
1367
1376
|
// #1241 special case for v-slot: vuetify relies extensively on slot
|
|
@@ -3032,7 +3041,7 @@ function isReferencedIdentifier(id, parent, parentStack) {
|
|
|
3032
3041
|
if (id.name === 'arguments') {
|
|
3033
3042
|
return false;
|
|
3034
3043
|
}
|
|
3035
|
-
if (
|
|
3044
|
+
if (isReferenced(id, parent)) {
|
|
3036
3045
|
return true;
|
|
3037
3046
|
}
|
|
3038
3047
|
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
@@ -3145,7 +3154,159 @@ const isFunctionType = (node) => {
|
|
|
3145
3154
|
const isStaticProperty = (node) => node &&
|
|
3146
3155
|
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3147
3156
|
!node.computed;
|
|
3148
|
-
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
|
+
}
|
|
3149
3310
|
|
|
3150
3311
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
3151
3312
|
const transformExpression = (node, context) => {
|
|
@@ -3184,7 +3345,7 @@ function processExpression(node, context,
|
|
|
3184
3345
|
// function params
|
|
3185
3346
|
asParams = false,
|
|
3186
3347
|
// v-on handler values may contain multiple statements
|
|
3187
|
-
asRawStatements = false) {
|
|
3348
|
+
asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
3188
3349
|
if (!context.prefixIdentifiers || !node.content.trim()) {
|
|
3189
3350
|
return node;
|
|
3190
3351
|
}
|
|
@@ -3198,7 +3359,7 @@ asRawStatements = false) {
|
|
|
3198
3359
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
3199
3360
|
// ({ x } = y)
|
|
3200
3361
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
3201
|
-
if (type === "setup-const" /* SETUP_CONST */) {
|
|
3362
|
+
if (type === "setup-const" /* SETUP_CONST */ || localVars[raw]) {
|
|
3202
3363
|
return raw;
|
|
3203
3364
|
}
|
|
3204
3365
|
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
@@ -3222,7 +3383,7 @@ asRawStatements = false) {
|
|
|
3222
3383
|
// x = y --> isRef(x) ? x.value = y : x = y
|
|
3223
3384
|
const { right: rVal, operator } = parent;
|
|
3224
3385
|
const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
|
|
3225
|
-
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context));
|
|
3386
|
+
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context, false, false, knownIds));
|
|
3226
3387
|
return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore\n` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
|
|
3227
3388
|
}
|
|
3228
3389
|
else if (isUpdateArg) {
|
|
@@ -4443,7 +4604,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4443
4604
|
// acrtual ref instead.
|
|
4444
4605
|
if (context.inline && (value === null || value === void 0 ? void 0 : value.content)) {
|
|
4445
4606
|
valueNode = createFunctionExpression(['_value', '_refs']);
|
|
4446
|
-
valueNode.body = createBlockStatement(processInlineRef(context
|
|
4607
|
+
valueNode.body = createBlockStatement(processInlineRef(context, value.content));
|
|
4447
4608
|
}
|
|
4448
4609
|
}
|
|
4449
4610
|
// skip is on <component>, or is="vue:xxx"
|
|
@@ -4763,14 +4924,18 @@ function stringifyDynamicPropNames(props) {
|
|
|
4763
4924
|
function isComponentTag(tag) {
|
|
4764
4925
|
return tag[0].toLowerCase() + tag.slice(1) === 'component';
|
|
4765
4926
|
}
|
|
4766
|
-
function processInlineRef(
|
|
4927
|
+
function processInlineRef(context, raw) {
|
|
4767
4928
|
const body = [createSimpleExpression(`_refs['${raw}'] = _value`)];
|
|
4768
|
-
const
|
|
4929
|
+
const { bindingMetadata, helperString } = context;
|
|
4930
|
+
const type = bindingMetadata[raw];
|
|
4769
4931
|
if (type === "setup-ref" /* SETUP_REF */) {
|
|
4770
4932
|
body.push(createSimpleExpression(`${raw}.value = _value`));
|
|
4771
4933
|
}
|
|
4934
|
+
else if (type === "setup-maybe-ref" /* SETUP_MAYBE_REF */) {
|
|
4935
|
+
body.push(createSimpleExpression(`${helperString(IS_REF)}(${raw}) && (${raw}.value = _value)`));
|
|
4936
|
+
}
|
|
4772
4937
|
else if (type === "setup-let" /* SETUP_LET */) {
|
|
4773
|
-
body.push(createSimpleExpression(`${raw} = _value`));
|
|
4938
|
+
body.push(createSimpleExpression(`${helperString(IS_REF)}(${raw}) ? ${raw}.value = _value : ${raw} = _value`));
|
|
4774
4939
|
}
|
|
4775
4940
|
return body;
|
|
4776
4941
|
}
|
|
@@ -4865,7 +5030,7 @@ function processSlotOutlet(node, context) {
|
|
|
4865
5030
|
};
|
|
4866
5031
|
}
|
|
4867
5032
|
|
|
4868
|
-
const fnExpRE = /^\s*([\w$_]
|
|
5033
|
+
const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
4869
5034
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4870
5035
|
const { loc, modifiers, arg } = dir;
|
|
4871
5036
|
if (!dir.exp && !modifiers.length) {
|
|
@@ -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
|
|
|
@@ -1274,6 +1273,13 @@ function parseAttributes(context, type) {
|
|
|
1274
1273
|
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1275
1274
|
}
|
|
1276
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
|
+
}
|
|
1277
1283
|
if (type === 0 /* Start */) {
|
|
1278
1284
|
props.push(attr);
|
|
1279
1285
|
}
|
|
@@ -1336,8 +1342,11 @@ function parseAttribute(context, nameSet) {
|
|
|
1336
1342
|
isStatic = false;
|
|
1337
1343
|
if (!content.endsWith(']')) {
|
|
1338
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);
|
|
1339
1349
|
}
|
|
1340
|
-
content = content.substr(1, content.length - 2);
|
|
1341
1350
|
}
|
|
1342
1351
|
else if (isSlot) {
|
|
1343
1352
|
// #1241 special case for v-slot: vuetify relies extensively on slot
|
|
@@ -2970,7 +2979,7 @@ function isReferencedIdentifier(id, parent, parentStack) {
|
|
|
2970
2979
|
if (id.name === 'arguments') {
|
|
2971
2980
|
return false;
|
|
2972
2981
|
}
|
|
2973
|
-
if (
|
|
2982
|
+
if (isReferenced(id, parent)) {
|
|
2974
2983
|
return true;
|
|
2975
2984
|
}
|
|
2976
2985
|
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
@@ -3083,7 +3092,159 @@ const isFunctionType = (node) => {
|
|
|
3083
3092
|
const isStaticProperty = (node) => node &&
|
|
3084
3093
|
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3085
3094
|
!node.computed;
|
|
3086
|
-
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
|
+
}
|
|
3087
3248
|
|
|
3088
3249
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
3089
3250
|
const transformExpression = (node, context) => {
|
|
@@ -3122,7 +3283,7 @@ function processExpression(node, context,
|
|
|
3122
3283
|
// function params
|
|
3123
3284
|
asParams = false,
|
|
3124
3285
|
// v-on handler values may contain multiple statements
|
|
3125
|
-
asRawStatements = false) {
|
|
3286
|
+
asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
3126
3287
|
if (!context.prefixIdentifiers || !node.content.trim()) {
|
|
3127
3288
|
return node;
|
|
3128
3289
|
}
|
|
@@ -3136,7 +3297,7 @@ asRawStatements = false) {
|
|
|
3136
3297
|
const isUpdateArg = parent && parent.type === 'UpdateExpression' && parent.argument === id;
|
|
3137
3298
|
// ({ x } = y)
|
|
3138
3299
|
const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack);
|
|
3139
|
-
if (type === "setup-const" /* SETUP_CONST */) {
|
|
3300
|
+
if (type === "setup-const" /* SETUP_CONST */ || localVars[raw]) {
|
|
3140
3301
|
return raw;
|
|
3141
3302
|
}
|
|
3142
3303
|
else if (type === "setup-ref" /* SETUP_REF */) {
|
|
@@ -3160,7 +3321,7 @@ asRawStatements = false) {
|
|
|
3160
3321
|
// x = y --> isRef(x) ? x.value = y : x = y
|
|
3161
3322
|
const { right: rVal, operator } = parent;
|
|
3162
3323
|
const rExp = rawExp.slice(rVal.start - 1, rVal.end - 1);
|
|
3163
|
-
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context));
|
|
3324
|
+
const rExpString = stringifyExpression(processExpression(createSimpleExpression(rExp, false), context, false, false, knownIds));
|
|
3164
3325
|
return `${context.helperString(IS_REF)}(${raw})${context.isTS ? ` //@ts-ignore\n` : ``} ? ${raw}.value ${operator} ${rExpString} : ${raw}`;
|
|
3165
3326
|
}
|
|
3166
3327
|
else if (isUpdateArg) {
|
|
@@ -4342,7 +4503,7 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4342
4503
|
// acrtual ref instead.
|
|
4343
4504
|
if (context.inline && (value === null || value === void 0 ? void 0 : value.content)) {
|
|
4344
4505
|
valueNode = createFunctionExpression(['_value', '_refs']);
|
|
4345
|
-
valueNode.body = createBlockStatement(processInlineRef(context
|
|
4506
|
+
valueNode.body = createBlockStatement(processInlineRef(context, value.content));
|
|
4346
4507
|
}
|
|
4347
4508
|
}
|
|
4348
4509
|
// skip is on <component>, or is="vue:xxx"
|
|
@@ -4639,14 +4800,18 @@ function stringifyDynamicPropNames(props) {
|
|
|
4639
4800
|
function isComponentTag(tag) {
|
|
4640
4801
|
return tag[0].toLowerCase() + tag.slice(1) === 'component';
|
|
4641
4802
|
}
|
|
4642
|
-
function processInlineRef(
|
|
4803
|
+
function processInlineRef(context, raw) {
|
|
4643
4804
|
const body = [createSimpleExpression(`_refs['${raw}'] = _value`)];
|
|
4644
|
-
const
|
|
4805
|
+
const { bindingMetadata, helperString } = context;
|
|
4806
|
+
const type = bindingMetadata[raw];
|
|
4645
4807
|
if (type === "setup-ref" /* SETUP_REF */) {
|
|
4646
4808
|
body.push(createSimpleExpression(`${raw}.value = _value`));
|
|
4647
4809
|
}
|
|
4810
|
+
else if (type === "setup-maybe-ref" /* SETUP_MAYBE_REF */) {
|
|
4811
|
+
body.push(createSimpleExpression(`${helperString(IS_REF)}(${raw}) && (${raw}.value = _value)`));
|
|
4812
|
+
}
|
|
4648
4813
|
else if (type === "setup-let" /* SETUP_LET */) {
|
|
4649
|
-
body.push(createSimpleExpression(`${raw} = _value`));
|
|
4814
|
+
body.push(createSimpleExpression(`${helperString(IS_REF)}(${raw}) ? ${raw}.value = _value : ${raw} = _value`));
|
|
4650
4815
|
}
|
|
4651
4816
|
return body;
|
|
4652
4817
|
}
|
|
@@ -4738,7 +4903,7 @@ function processSlotOutlet(node, context) {
|
|
|
4738
4903
|
};
|
|
4739
4904
|
}
|
|
4740
4905
|
|
|
4741
|
-
const fnExpRE = /^\s*([\w$_]
|
|
4906
|
+
const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
4742
4907
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4743
4908
|
const { loc, modifiers, arg } = dir;
|
|
4744
4909
|
if (!dir.exp && !modifiers.length) {
|
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
|
/**
|
|
@@ -782,7 +782,7 @@ export declare interface Position {
|
|
|
782
782
|
column: number;
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
-
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;
|
|
786
786
|
|
|
787
787
|
export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
|
|
788
788
|
|
|
@@ -1295,6 +1295,13 @@ function parseAttributes(context, type) {
|
|
|
1295
1295
|
emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
|
|
1296
1296
|
}
|
|
1297
1297
|
const attr = parseAttribute(context, attributeNames);
|
|
1298
|
+
// Trim whitespace between class
|
|
1299
|
+
// https://github.com/vuejs/vue-next/issues/4251
|
|
1300
|
+
if (attr.type === 6 /* ATTRIBUTE */ &&
|
|
1301
|
+
attr.value &&
|
|
1302
|
+
attr.name === 'class') {
|
|
1303
|
+
attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
|
|
1304
|
+
}
|
|
1298
1305
|
if (type === 0 /* Start */) {
|
|
1299
1306
|
props.push(attr);
|
|
1300
1307
|
}
|
|
@@ -1357,8 +1364,11 @@ function parseAttribute(context, nameSet) {
|
|
|
1357
1364
|
isStatic = false;
|
|
1358
1365
|
if (!content.endsWith(']')) {
|
|
1359
1366
|
emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
|
|
1367
|
+
content = content.substr(1);
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
content = content.substr(1, content.length - 2);
|
|
1360
1371
|
}
|
|
1361
|
-
content = content.substr(1, content.length - 2);
|
|
1362
1372
|
}
|
|
1363
1373
|
else if (isSlot) {
|
|
1364
1374
|
// #1241 special case for v-slot: vuetify relies extensively on slot
|
|
@@ -2921,7 +2931,7 @@ function processExpression(node, context,
|
|
|
2921
2931
|
// function params
|
|
2922
2932
|
asParams = false,
|
|
2923
2933
|
// v-on handler values may contain multiple statements
|
|
2924
|
-
asRawStatements = false) {
|
|
2934
|
+
asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
2925
2935
|
{
|
|
2926
2936
|
if ((process.env.NODE_ENV !== 'production')) {
|
|
2927
2937
|
// simple in-browser validation (same logic in 2.x)
|
|
@@ -4280,7 +4290,7 @@ function processSlotOutlet(node, context) {
|
|
|
4280
4290
|
};
|
|
4281
4291
|
}
|
|
4282
4292
|
|
|
4283
|
-
const fnExpRE = /^\s*([\w$_]
|
|
4293
|
+
const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
4284
4294
|
const transformOn = (dir, node, context, augmentor) => {
|
|
4285
4295
|
const { loc, modifiers, arg } = dir;
|
|
4286
4296
|
if (!dir.exp && !modifiers.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.12",
|
|
4
4
|
"description": "@vue/compiler-core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/compiler-core.esm-bundler.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-core#readme",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vue/shared": "3.2.
|
|
35
|
+
"@vue/shared": "3.2.12",
|
|
36
36
|
"@babel/parser": "^7.15.0",
|
|
37
37
|
"@babel/types": "^7.15.0",
|
|
38
38
|
"estree-walker": "^2.0.2",
|