@vue/compiler-core 3.2.2 → 3.2.6
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 +226 -141
- package/dist/compiler-core.cjs.prod.js +226 -141
- package/dist/compiler-core.d.ts +24 -0
- package/dist/compiler-core.esm-bundler.js +115 -9
- package/package.json +5 -5
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var shared = require('@vue/shared');
|
|
6
6
|
var sourceMap = require('source-map');
|
|
7
|
-
var
|
|
7
|
+
var types = require('@babel/types');
|
|
8
8
|
var estreeWalker = require('estree-walker');
|
|
9
|
+
var parser = require('@babel/parser');
|
|
9
10
|
|
|
10
11
|
function defaultOnError(error) {
|
|
11
12
|
throw error;
|
|
@@ -651,7 +652,10 @@ function injectProp(node, prop, context) {
|
|
|
651
652
|
}
|
|
652
653
|
}
|
|
653
654
|
function toValidAssetId(name, type) {
|
|
654
|
-
|
|
655
|
+
// see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
|
|
656
|
+
return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
|
657
|
+
return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
|
|
658
|
+
})}`;
|
|
655
659
|
}
|
|
656
660
|
// Check if a node contains expressions that reference current context scope ids
|
|
657
661
|
function hasScopeRef(node, ids) {
|
|
@@ -1866,16 +1870,19 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1866
1870
|
if (keyType < returnType) {
|
|
1867
1871
|
returnType = keyType;
|
|
1868
1872
|
}
|
|
1869
|
-
|
|
1873
|
+
let valueType;
|
|
1874
|
+
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1875
|
+
valueType = getConstantType(value, context);
|
|
1876
|
+
}
|
|
1877
|
+
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1870
1878
|
// some helper calls can be hoisted,
|
|
1871
1879
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1872
1880
|
// in this case we need to respect the ConstanType of the helper's argments
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1881
|
+
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1882
|
+
}
|
|
1883
|
+
else {
|
|
1884
|
+
valueType = 0 /* NOT_CONSTANT */;
|
|
1877
1885
|
}
|
|
1878
|
-
const valueType = getConstantType(value, context);
|
|
1879
1886
|
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1880
1887
|
return valueType;
|
|
1881
1888
|
}
|
|
@@ -2972,6 +2979,177 @@ function genReturnStatement({ returns }, context) {
|
|
|
2972
2979
|
}
|
|
2973
2980
|
}
|
|
2974
2981
|
|
|
2982
|
+
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = Object.create(null)) {
|
|
2983
|
+
const rootExp = root.type === 'Program' &&
|
|
2984
|
+
root.body[0].type === 'ExpressionStatement' &&
|
|
2985
|
+
root.body[0].expression;
|
|
2986
|
+
estreeWalker.walk(root, {
|
|
2987
|
+
enter(node, parent) {
|
|
2988
|
+
parent && parentStack.push(parent);
|
|
2989
|
+
if (parent &&
|
|
2990
|
+
parent.type.startsWith('TS') &&
|
|
2991
|
+
parent.type !== 'TSAsExpression' &&
|
|
2992
|
+
parent.type !== 'TSNonNullExpression' &&
|
|
2993
|
+
parent.type !== 'TSTypeAssertion') {
|
|
2994
|
+
return this.skip();
|
|
2995
|
+
}
|
|
2996
|
+
if (node.type === 'Identifier') {
|
|
2997
|
+
const isLocal = !!knownIds[node.name];
|
|
2998
|
+
const isRefed = isReferencedIdentifier(node, parent, parentStack);
|
|
2999
|
+
if (includeAll || (isRefed && !isLocal)) {
|
|
3000
|
+
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
else if (node.type === 'ObjectProperty' &&
|
|
3004
|
+
parent.type === 'ObjectPattern') {
|
|
3005
|
+
node.inPattern = true;
|
|
3006
|
+
}
|
|
3007
|
+
else if (isFunctionType(node)) {
|
|
3008
|
+
// walk function expressions and add its arguments to known identifiers
|
|
3009
|
+
// so that we don't prefix them
|
|
3010
|
+
walkFunctionParams(node, id => markScopeIdentifier(node, id, knownIds));
|
|
3011
|
+
}
|
|
3012
|
+
else if (node.type === 'BlockStatement') {
|
|
3013
|
+
// #3445 record block-level local variables
|
|
3014
|
+
walkBlockDeclarations(node, id => markScopeIdentifier(node, id, knownIds));
|
|
3015
|
+
}
|
|
3016
|
+
},
|
|
3017
|
+
leave(node, parent) {
|
|
3018
|
+
parent && parentStack.pop();
|
|
3019
|
+
if (node !== rootExp && node.scopeIds) {
|
|
3020
|
+
for (const id of node.scopeIds) {
|
|
3021
|
+
knownIds[id]--;
|
|
3022
|
+
if (knownIds[id] === 0) {
|
|
3023
|
+
delete knownIds[id];
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
function isReferencedIdentifier(id, parent, parentStack) {
|
|
3031
|
+
if (!parent) {
|
|
3032
|
+
return true;
|
|
3033
|
+
}
|
|
3034
|
+
// is a special keyword but parsed as identifier
|
|
3035
|
+
if (id.name === 'arguments') {
|
|
3036
|
+
return false;
|
|
3037
|
+
}
|
|
3038
|
+
if (types.isReferenced(id, parent)) {
|
|
3039
|
+
return true;
|
|
3040
|
+
}
|
|
3041
|
+
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
3042
|
+
// need to cover those cases here
|
|
3043
|
+
switch (parent.type) {
|
|
3044
|
+
case 'AssignmentExpression':
|
|
3045
|
+
case 'AssignmentPattern':
|
|
3046
|
+
return true;
|
|
3047
|
+
case 'ObjectPattern':
|
|
3048
|
+
case 'ArrayPattern':
|
|
3049
|
+
return isInDestructureAssignment(parent, parentStack);
|
|
3050
|
+
}
|
|
3051
|
+
return false;
|
|
3052
|
+
}
|
|
3053
|
+
function isInDestructureAssignment(parent, parentStack) {
|
|
3054
|
+
if (parent &&
|
|
3055
|
+
(parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
|
|
3056
|
+
let i = parentStack.length;
|
|
3057
|
+
while (i--) {
|
|
3058
|
+
const p = parentStack[i];
|
|
3059
|
+
if (p.type === 'AssignmentExpression') {
|
|
3060
|
+
return true;
|
|
3061
|
+
}
|
|
3062
|
+
else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
|
|
3063
|
+
break;
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
return false;
|
|
3068
|
+
}
|
|
3069
|
+
function walkFunctionParams(node, onIdent) {
|
|
3070
|
+
for (const p of node.params) {
|
|
3071
|
+
for (const id of extractIdentifiers(p)) {
|
|
3072
|
+
onIdent(id);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
function walkBlockDeclarations(block, onIdent) {
|
|
3077
|
+
for (const stmt of block.body) {
|
|
3078
|
+
if (stmt.type === 'VariableDeclaration') {
|
|
3079
|
+
if (stmt.declare)
|
|
3080
|
+
continue;
|
|
3081
|
+
for (const decl of stmt.declarations) {
|
|
3082
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
3083
|
+
onIdent(id);
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
else if (stmt.type === 'FunctionDeclaration' ||
|
|
3088
|
+
stmt.type === 'ClassDeclaration') {
|
|
3089
|
+
if (stmt.declare || !stmt.id)
|
|
3090
|
+
continue;
|
|
3091
|
+
onIdent(stmt.id);
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
function extractIdentifiers(param, nodes = []) {
|
|
3096
|
+
switch (param.type) {
|
|
3097
|
+
case 'Identifier':
|
|
3098
|
+
nodes.push(param);
|
|
3099
|
+
break;
|
|
3100
|
+
case 'MemberExpression':
|
|
3101
|
+
let object = param;
|
|
3102
|
+
while (object.type === 'MemberExpression') {
|
|
3103
|
+
object = object.object;
|
|
3104
|
+
}
|
|
3105
|
+
nodes.push(object);
|
|
3106
|
+
break;
|
|
3107
|
+
case 'ObjectPattern':
|
|
3108
|
+
for (const prop of param.properties) {
|
|
3109
|
+
if (prop.type === 'RestElement') {
|
|
3110
|
+
extractIdentifiers(prop.argument, nodes);
|
|
3111
|
+
}
|
|
3112
|
+
else {
|
|
3113
|
+
extractIdentifiers(prop.value, nodes);
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
break;
|
|
3117
|
+
case 'ArrayPattern':
|
|
3118
|
+
param.elements.forEach(element => {
|
|
3119
|
+
if (element)
|
|
3120
|
+
extractIdentifiers(element, nodes);
|
|
3121
|
+
});
|
|
3122
|
+
break;
|
|
3123
|
+
case 'RestElement':
|
|
3124
|
+
extractIdentifiers(param.argument, nodes);
|
|
3125
|
+
break;
|
|
3126
|
+
case 'AssignmentPattern':
|
|
3127
|
+
extractIdentifiers(param.left, nodes);
|
|
3128
|
+
break;
|
|
3129
|
+
}
|
|
3130
|
+
return nodes;
|
|
3131
|
+
}
|
|
3132
|
+
function markScopeIdentifier(node, child, knownIds) {
|
|
3133
|
+
const { name } = child;
|
|
3134
|
+
if (node.scopeIds && node.scopeIds.has(name)) {
|
|
3135
|
+
return;
|
|
3136
|
+
}
|
|
3137
|
+
if (name in knownIds) {
|
|
3138
|
+
knownIds[name]++;
|
|
3139
|
+
}
|
|
3140
|
+
else {
|
|
3141
|
+
knownIds[name] = 1;
|
|
3142
|
+
}
|
|
3143
|
+
(node.scopeIds || (node.scopeIds = new Set())).add(name);
|
|
3144
|
+
}
|
|
3145
|
+
const isFunctionType = (node) => {
|
|
3146
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
3147
|
+
};
|
|
3148
|
+
const isStaticProperty = (node) => node &&
|
|
3149
|
+
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3150
|
+
!node.computed;
|
|
3151
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3152
|
+
|
|
2975
3153
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
2976
3154
|
const transformExpression = (node, context) => {
|
|
2977
3155
|
if (node.type === 5 /* INTERPOLATION */) {
|
|
@@ -3137,81 +3315,36 @@ asRawStatements = false) {
|
|
|
3137
3315
|
return node;
|
|
3138
3316
|
}
|
|
3139
3317
|
const ids = [];
|
|
3140
|
-
const knownIds = Object.create(context.identifiers);
|
|
3141
|
-
const isDuplicate = (node) => ids.some(id => id.start === node.start);
|
|
3142
3318
|
const parentStack = [];
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
// we rewrite the value
|
|
3157
|
-
node.prefix = `${node.name}: `;
|
|
3158
|
-
}
|
|
3159
|
-
node.name = rewriteIdentifier(node.name, parent, node);
|
|
3160
|
-
ids.push(node);
|
|
3161
|
-
}
|
|
3162
|
-
else if (!isStaticPropertyKey(node, parent)) {
|
|
3163
|
-
// The identifier is considered constant unless it's pointing to a
|
|
3164
|
-
// scope variable (a v-for alias, or a v-slot prop)
|
|
3165
|
-
if (!(needPrefix && knownIds[node.name]) && !bailConstant) {
|
|
3166
|
-
node.isConstant = true;
|
|
3167
|
-
}
|
|
3168
|
-
// also generate sub-expressions for other identifiers for better
|
|
3169
|
-
// source map support. (except for property keys which are static)
|
|
3170
|
-
ids.push(node);
|
|
3171
|
-
}
|
|
3172
|
-
}
|
|
3173
|
-
}
|
|
3174
|
-
else if (isFunction(node)) {
|
|
3175
|
-
// walk function expressions and add its arguments to known identifiers
|
|
3176
|
-
// so that we don't prefix them
|
|
3177
|
-
node.params.forEach(p => estreeWalker.walk(p, {
|
|
3178
|
-
enter(child, parent) {
|
|
3179
|
-
if (child.type === 'Identifier' &&
|
|
3180
|
-
// do not record as scope variable if is a destructured key
|
|
3181
|
-
!isStaticPropertyKey(child, parent) &&
|
|
3182
|
-
// do not record if this is a default value
|
|
3183
|
-
// assignment of a destructured variable
|
|
3184
|
-
!(parent &&
|
|
3185
|
-
parent.type === 'AssignmentPattern' &&
|
|
3186
|
-
parent.right === child)) {
|
|
3187
|
-
const { name } = child;
|
|
3188
|
-
if (node.scopeIds && node.scopeIds.has(name)) {
|
|
3189
|
-
return;
|
|
3190
|
-
}
|
|
3191
|
-
if (name in knownIds) {
|
|
3192
|
-
knownIds[name]++;
|
|
3193
|
-
}
|
|
3194
|
-
else {
|
|
3195
|
-
knownIds[name] = 1;
|
|
3196
|
-
}
|
|
3197
|
-
(node.scopeIds || (node.scopeIds = new Set())).add(name);
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
}));
|
|
3319
|
+
const knownIds = Object.create(context.identifiers);
|
|
3320
|
+
walkIdentifiers(ast, (node, parent, _, isReferenced, isLocal) => {
|
|
3321
|
+
if (isStaticPropertyKey(node, parent)) {
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
// v2 wrapped filter call
|
|
3325
|
+
if (node.name.startsWith('_filter_')) {
|
|
3326
|
+
return;
|
|
3327
|
+
}
|
|
3328
|
+
const needPrefix = isReferenced && canPrefix(node);
|
|
3329
|
+
if (needPrefix && !isLocal) {
|
|
3330
|
+
if (isStaticProperty(parent) && parent.shorthand) {
|
|
3331
|
+
node.prefix = `${node.name}: `;
|
|
3201
3332
|
}
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
}
|
|
3211
|
-
});
|
|
3333
|
+
node.name = rewriteIdentifier(node.name, parent, node);
|
|
3334
|
+
ids.push(node);
|
|
3335
|
+
}
|
|
3336
|
+
else {
|
|
3337
|
+
// The identifier is considered constant unless it's pointing to a
|
|
3338
|
+
// local scope variable (a v-for alias, or a v-slot prop)
|
|
3339
|
+
if (!(needPrefix && isLocal) && !bailConstant) {
|
|
3340
|
+
node.isConstant = true;
|
|
3212
3341
|
}
|
|
3342
|
+
// also generate sub-expressions for other identifiers for better
|
|
3343
|
+
// source map support. (except for property keys which are static)
|
|
3344
|
+
ids.push(node);
|
|
3213
3345
|
}
|
|
3214
|
-
}
|
|
3346
|
+
}, true, // invoke on ALL identifiers
|
|
3347
|
+
parentStack, knownIds);
|
|
3215
3348
|
// We break up the compound expression into an array of strings and sub
|
|
3216
3349
|
// expressions (for identifiers that have been prefixed). In codegen, if
|
|
3217
3350
|
// an ExpressionNode has the `.children` property, it will be used instead of
|
|
@@ -3250,51 +3383,7 @@ asRawStatements = false) {
|
|
|
3250
3383
|
ret.identifiers = Object.keys(knownIds);
|
|
3251
3384
|
return ret;
|
|
3252
3385
|
}
|
|
3253
|
-
|
|
3254
|
-
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
3255
|
-
};
|
|
3256
|
-
const isStaticProperty = (node) => node &&
|
|
3257
|
-
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3258
|
-
!node.computed;
|
|
3259
|
-
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3260
|
-
function shouldPrefix(id, parent, parentStack) {
|
|
3261
|
-
// declaration id
|
|
3262
|
-
if ((parent.type === 'VariableDeclarator' ||
|
|
3263
|
-
parent.type === 'ClassDeclaration') &&
|
|
3264
|
-
parent.id === id) {
|
|
3265
|
-
return false;
|
|
3266
|
-
}
|
|
3267
|
-
if (isFunction(parent)) {
|
|
3268
|
-
// function decalration/expression id
|
|
3269
|
-
if (parent.id === id) {
|
|
3270
|
-
return false;
|
|
3271
|
-
}
|
|
3272
|
-
// params list
|
|
3273
|
-
if (parent.params.includes(id)) {
|
|
3274
|
-
return false;
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
|
-
// property key
|
|
3278
|
-
// this also covers object destructure pattern
|
|
3279
|
-
if (isStaticPropertyKey(id, parent)) {
|
|
3280
|
-
return false;
|
|
3281
|
-
}
|
|
3282
|
-
// non-assignment array destructure pattern
|
|
3283
|
-
if (parent.type === 'ArrayPattern' &&
|
|
3284
|
-
!isInDestructureAssignment(parent, parentStack)) {
|
|
3285
|
-
return false;
|
|
3286
|
-
}
|
|
3287
|
-
// member expression property
|
|
3288
|
-
if ((parent.type === 'MemberExpression' ||
|
|
3289
|
-
parent.type === 'OptionalMemberExpression') &&
|
|
3290
|
-
parent.property === id &&
|
|
3291
|
-
!parent.computed) {
|
|
3292
|
-
return false;
|
|
3293
|
-
}
|
|
3294
|
-
// is a special keyword but parsed as identifier
|
|
3295
|
-
if (id.name === 'arguments') {
|
|
3296
|
-
return false;
|
|
3297
|
-
}
|
|
3386
|
+
function canPrefix(id) {
|
|
3298
3387
|
// skip whitelisted globals
|
|
3299
3388
|
if (shared.isGloballyWhitelisted(id.name)) {
|
|
3300
3389
|
return false;
|
|
@@ -3305,22 +3394,6 @@ function shouldPrefix(id, parent, parentStack) {
|
|
|
3305
3394
|
}
|
|
3306
3395
|
return true;
|
|
3307
3396
|
}
|
|
3308
|
-
function isInDestructureAssignment(parent, parentStack) {
|
|
3309
|
-
if (parent &&
|
|
3310
|
-
(parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
|
|
3311
|
-
let i = parentStack.length;
|
|
3312
|
-
while (i--) {
|
|
3313
|
-
const p = parentStack[i];
|
|
3314
|
-
if (p.type === 'AssignmentExpression') {
|
|
3315
|
-
return true;
|
|
3316
|
-
}
|
|
3317
|
-
else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
|
|
3318
|
-
break;
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
return false;
|
|
3323
|
-
}
|
|
3324
3397
|
function stringifyExpression(exp) {
|
|
3325
3398
|
if (shared.isString(exp)) {
|
|
3326
3399
|
return exp;
|
|
@@ -4567,7 +4640,10 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4567
4640
|
!isStaticExp(styleProp.value) &&
|
|
4568
4641
|
// the static style is compiled into an object,
|
|
4569
4642
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4570
|
-
hasStyleBinding
|
|
4643
|
+
(hasStyleBinding ||
|
|
4644
|
+
// v-bind:style and style both exist,
|
|
4645
|
+
// v-bind:style with static literal object
|
|
4646
|
+
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4571
4647
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4572
4648
|
}
|
|
4573
4649
|
}
|
|
@@ -5468,6 +5544,7 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
|
5468
5544
|
exports.createTemplateLiteral = createTemplateLiteral;
|
|
5469
5545
|
exports.createTransformContext = createTransformContext;
|
|
5470
5546
|
exports.createVNodeCall = createVNodeCall;
|
|
5547
|
+
exports.extractIdentifiers = extractIdentifiers;
|
|
5471
5548
|
exports.findDir = findDir;
|
|
5472
5549
|
exports.findProp = findProp;
|
|
5473
5550
|
exports.generate = generate;
|
|
@@ -5483,10 +5560,15 @@ exports.injectProp = injectProp;
|
|
|
5483
5560
|
exports.isBindKey = isBindKey;
|
|
5484
5561
|
exports.isBuiltInType = isBuiltInType;
|
|
5485
5562
|
exports.isCoreComponent = isCoreComponent;
|
|
5563
|
+
exports.isFunctionType = isFunctionType;
|
|
5564
|
+
exports.isInDestructureAssignment = isInDestructureAssignment;
|
|
5486
5565
|
exports.isMemberExpression = isMemberExpression;
|
|
5566
|
+
exports.isReferencedIdentifier = isReferencedIdentifier;
|
|
5487
5567
|
exports.isSimpleIdentifier = isSimpleIdentifier;
|
|
5488
5568
|
exports.isSlotOutlet = isSlotOutlet;
|
|
5489
5569
|
exports.isStaticExp = isStaticExp;
|
|
5570
|
+
exports.isStaticProperty = isStaticProperty;
|
|
5571
|
+
exports.isStaticPropertyKey = isStaticPropertyKey;
|
|
5490
5572
|
exports.isTemplateNode = isTemplateNode;
|
|
5491
5573
|
exports.isText = isText;
|
|
5492
5574
|
exports.isVSlot = isVSlot;
|
|
@@ -5509,4 +5591,7 @@ exports.transformExpression = transformExpression;
|
|
|
5509
5591
|
exports.transformModel = transformModel;
|
|
5510
5592
|
exports.transformOn = transformOn;
|
|
5511
5593
|
exports.traverseNode = traverseNode;
|
|
5594
|
+
exports.walkBlockDeclarations = walkBlockDeclarations;
|
|
5595
|
+
exports.walkFunctionParams = walkFunctionParams;
|
|
5596
|
+
exports.walkIdentifiers = walkIdentifiers;
|
|
5512
5597
|
exports.warnDeprecation = warnDeprecation;
|
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var shared = require('@vue/shared');
|
|
6
6
|
var sourceMap = require('source-map');
|
|
7
|
-
var
|
|
7
|
+
var types = require('@babel/types');
|
|
8
8
|
var estreeWalker = require('estree-walker');
|
|
9
|
+
var parser = require('@babel/parser');
|
|
9
10
|
|
|
10
11
|
function defaultOnError(error) {
|
|
11
12
|
throw error;
|
|
@@ -650,7 +651,10 @@ function injectProp(node, prop, context) {
|
|
|
650
651
|
}
|
|
651
652
|
}
|
|
652
653
|
function toValidAssetId(name, type) {
|
|
653
|
-
|
|
654
|
+
// see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
|
|
655
|
+
return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
|
656
|
+
return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
|
|
657
|
+
})}`;
|
|
654
658
|
}
|
|
655
659
|
// Check if a node contains expressions that reference current context scope ids
|
|
656
660
|
function hasScopeRef(node, ids) {
|
|
@@ -1839,16 +1843,19 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1839
1843
|
if (keyType < returnType) {
|
|
1840
1844
|
returnType = keyType;
|
|
1841
1845
|
}
|
|
1842
|
-
|
|
1846
|
+
let valueType;
|
|
1847
|
+
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1848
|
+
valueType = getConstantType(value, context);
|
|
1849
|
+
}
|
|
1850
|
+
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1843
1851
|
// some helper calls can be hoisted,
|
|
1844
1852
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1845
1853
|
// in this case we need to respect the ConstanType of the helper's argments
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1854
|
+
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1855
|
+
}
|
|
1856
|
+
else {
|
|
1857
|
+
valueType = 0 /* NOT_CONSTANT */;
|
|
1850
1858
|
}
|
|
1851
|
-
const valueType = getConstantType(value, context);
|
|
1852
1859
|
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1853
1860
|
return valueType;
|
|
1854
1861
|
}
|
|
@@ -2910,6 +2917,177 @@ function genReturnStatement({ returns }, context) {
|
|
|
2910
2917
|
}
|
|
2911
2918
|
}
|
|
2912
2919
|
|
|
2920
|
+
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = Object.create(null)) {
|
|
2921
|
+
const rootExp = root.type === 'Program' &&
|
|
2922
|
+
root.body[0].type === 'ExpressionStatement' &&
|
|
2923
|
+
root.body[0].expression;
|
|
2924
|
+
estreeWalker.walk(root, {
|
|
2925
|
+
enter(node, parent) {
|
|
2926
|
+
parent && parentStack.push(parent);
|
|
2927
|
+
if (parent &&
|
|
2928
|
+
parent.type.startsWith('TS') &&
|
|
2929
|
+
parent.type !== 'TSAsExpression' &&
|
|
2930
|
+
parent.type !== 'TSNonNullExpression' &&
|
|
2931
|
+
parent.type !== 'TSTypeAssertion') {
|
|
2932
|
+
return this.skip();
|
|
2933
|
+
}
|
|
2934
|
+
if (node.type === 'Identifier') {
|
|
2935
|
+
const isLocal = !!knownIds[node.name];
|
|
2936
|
+
const isRefed = isReferencedIdentifier(node, parent, parentStack);
|
|
2937
|
+
if (includeAll || (isRefed && !isLocal)) {
|
|
2938
|
+
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
else if (node.type === 'ObjectProperty' &&
|
|
2942
|
+
parent.type === 'ObjectPattern') {
|
|
2943
|
+
node.inPattern = true;
|
|
2944
|
+
}
|
|
2945
|
+
else if (isFunctionType(node)) {
|
|
2946
|
+
// walk function expressions and add its arguments to known identifiers
|
|
2947
|
+
// so that we don't prefix them
|
|
2948
|
+
walkFunctionParams(node, id => markScopeIdentifier(node, id, knownIds));
|
|
2949
|
+
}
|
|
2950
|
+
else if (node.type === 'BlockStatement') {
|
|
2951
|
+
// #3445 record block-level local variables
|
|
2952
|
+
walkBlockDeclarations(node, id => markScopeIdentifier(node, id, knownIds));
|
|
2953
|
+
}
|
|
2954
|
+
},
|
|
2955
|
+
leave(node, parent) {
|
|
2956
|
+
parent && parentStack.pop();
|
|
2957
|
+
if (node !== rootExp && node.scopeIds) {
|
|
2958
|
+
for (const id of node.scopeIds) {
|
|
2959
|
+
knownIds[id]--;
|
|
2960
|
+
if (knownIds[id] === 0) {
|
|
2961
|
+
delete knownIds[id];
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
}
|
|
2968
|
+
function isReferencedIdentifier(id, parent, parentStack) {
|
|
2969
|
+
if (!parent) {
|
|
2970
|
+
return true;
|
|
2971
|
+
}
|
|
2972
|
+
// is a special keyword but parsed as identifier
|
|
2973
|
+
if (id.name === 'arguments') {
|
|
2974
|
+
return false;
|
|
2975
|
+
}
|
|
2976
|
+
if (types.isReferenced(id, parent)) {
|
|
2977
|
+
return true;
|
|
2978
|
+
}
|
|
2979
|
+
// babel's isReferenced check returns false for ids being assigned to, so we
|
|
2980
|
+
// need to cover those cases here
|
|
2981
|
+
switch (parent.type) {
|
|
2982
|
+
case 'AssignmentExpression':
|
|
2983
|
+
case 'AssignmentPattern':
|
|
2984
|
+
return true;
|
|
2985
|
+
case 'ObjectPattern':
|
|
2986
|
+
case 'ArrayPattern':
|
|
2987
|
+
return isInDestructureAssignment(parent, parentStack);
|
|
2988
|
+
}
|
|
2989
|
+
return false;
|
|
2990
|
+
}
|
|
2991
|
+
function isInDestructureAssignment(parent, parentStack) {
|
|
2992
|
+
if (parent &&
|
|
2993
|
+
(parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
|
|
2994
|
+
let i = parentStack.length;
|
|
2995
|
+
while (i--) {
|
|
2996
|
+
const p = parentStack[i];
|
|
2997
|
+
if (p.type === 'AssignmentExpression') {
|
|
2998
|
+
return true;
|
|
2999
|
+
}
|
|
3000
|
+
else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
|
|
3001
|
+
break;
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
return false;
|
|
3006
|
+
}
|
|
3007
|
+
function walkFunctionParams(node, onIdent) {
|
|
3008
|
+
for (const p of node.params) {
|
|
3009
|
+
for (const id of extractIdentifiers(p)) {
|
|
3010
|
+
onIdent(id);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
function walkBlockDeclarations(block, onIdent) {
|
|
3015
|
+
for (const stmt of block.body) {
|
|
3016
|
+
if (stmt.type === 'VariableDeclaration') {
|
|
3017
|
+
if (stmt.declare)
|
|
3018
|
+
continue;
|
|
3019
|
+
for (const decl of stmt.declarations) {
|
|
3020
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
3021
|
+
onIdent(id);
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
else if (stmt.type === 'FunctionDeclaration' ||
|
|
3026
|
+
stmt.type === 'ClassDeclaration') {
|
|
3027
|
+
if (stmt.declare || !stmt.id)
|
|
3028
|
+
continue;
|
|
3029
|
+
onIdent(stmt.id);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
function extractIdentifiers(param, nodes = []) {
|
|
3034
|
+
switch (param.type) {
|
|
3035
|
+
case 'Identifier':
|
|
3036
|
+
nodes.push(param);
|
|
3037
|
+
break;
|
|
3038
|
+
case 'MemberExpression':
|
|
3039
|
+
let object = param;
|
|
3040
|
+
while (object.type === 'MemberExpression') {
|
|
3041
|
+
object = object.object;
|
|
3042
|
+
}
|
|
3043
|
+
nodes.push(object);
|
|
3044
|
+
break;
|
|
3045
|
+
case 'ObjectPattern':
|
|
3046
|
+
for (const prop of param.properties) {
|
|
3047
|
+
if (prop.type === 'RestElement') {
|
|
3048
|
+
extractIdentifiers(prop.argument, nodes);
|
|
3049
|
+
}
|
|
3050
|
+
else {
|
|
3051
|
+
extractIdentifiers(prop.value, nodes);
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
break;
|
|
3055
|
+
case 'ArrayPattern':
|
|
3056
|
+
param.elements.forEach(element => {
|
|
3057
|
+
if (element)
|
|
3058
|
+
extractIdentifiers(element, nodes);
|
|
3059
|
+
});
|
|
3060
|
+
break;
|
|
3061
|
+
case 'RestElement':
|
|
3062
|
+
extractIdentifiers(param.argument, nodes);
|
|
3063
|
+
break;
|
|
3064
|
+
case 'AssignmentPattern':
|
|
3065
|
+
extractIdentifiers(param.left, nodes);
|
|
3066
|
+
break;
|
|
3067
|
+
}
|
|
3068
|
+
return nodes;
|
|
3069
|
+
}
|
|
3070
|
+
function markScopeIdentifier(node, child, knownIds) {
|
|
3071
|
+
const { name } = child;
|
|
3072
|
+
if (node.scopeIds && node.scopeIds.has(name)) {
|
|
3073
|
+
return;
|
|
3074
|
+
}
|
|
3075
|
+
if (name in knownIds) {
|
|
3076
|
+
knownIds[name]++;
|
|
3077
|
+
}
|
|
3078
|
+
else {
|
|
3079
|
+
knownIds[name] = 1;
|
|
3080
|
+
}
|
|
3081
|
+
(node.scopeIds || (node.scopeIds = new Set())).add(name);
|
|
3082
|
+
}
|
|
3083
|
+
const isFunctionType = (node) => {
|
|
3084
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
3085
|
+
};
|
|
3086
|
+
const isStaticProperty = (node) => node &&
|
|
3087
|
+
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3088
|
+
!node.computed;
|
|
3089
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3090
|
+
|
|
2913
3091
|
const isLiteralWhitelisted = /*#__PURE__*/ shared.makeMap('true,false,null,this');
|
|
2914
3092
|
const transformExpression = (node, context) => {
|
|
2915
3093
|
if (node.type === 5 /* INTERPOLATION */) {
|
|
@@ -3075,81 +3253,36 @@ asRawStatements = false) {
|
|
|
3075
3253
|
return node;
|
|
3076
3254
|
}
|
|
3077
3255
|
const ids = [];
|
|
3078
|
-
const knownIds = Object.create(context.identifiers);
|
|
3079
|
-
const isDuplicate = (node) => ids.some(id => id.start === node.start);
|
|
3080
3256
|
const parentStack = [];
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
// we rewrite the value
|
|
3095
|
-
node.prefix = `${node.name}: `;
|
|
3096
|
-
}
|
|
3097
|
-
node.name = rewriteIdentifier(node.name, parent, node);
|
|
3098
|
-
ids.push(node);
|
|
3099
|
-
}
|
|
3100
|
-
else if (!isStaticPropertyKey(node, parent)) {
|
|
3101
|
-
// The identifier is considered constant unless it's pointing to a
|
|
3102
|
-
// scope variable (a v-for alias, or a v-slot prop)
|
|
3103
|
-
if (!(needPrefix && knownIds[node.name]) && !bailConstant) {
|
|
3104
|
-
node.isConstant = true;
|
|
3105
|
-
}
|
|
3106
|
-
// also generate sub-expressions for other identifiers for better
|
|
3107
|
-
// source map support. (except for property keys which are static)
|
|
3108
|
-
ids.push(node);
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
else if (isFunction(node)) {
|
|
3113
|
-
// walk function expressions and add its arguments to known identifiers
|
|
3114
|
-
// so that we don't prefix them
|
|
3115
|
-
node.params.forEach(p => estreeWalker.walk(p, {
|
|
3116
|
-
enter(child, parent) {
|
|
3117
|
-
if (child.type === 'Identifier' &&
|
|
3118
|
-
// do not record as scope variable if is a destructured key
|
|
3119
|
-
!isStaticPropertyKey(child, parent) &&
|
|
3120
|
-
// do not record if this is a default value
|
|
3121
|
-
// assignment of a destructured variable
|
|
3122
|
-
!(parent &&
|
|
3123
|
-
parent.type === 'AssignmentPattern' &&
|
|
3124
|
-
parent.right === child)) {
|
|
3125
|
-
const { name } = child;
|
|
3126
|
-
if (node.scopeIds && node.scopeIds.has(name)) {
|
|
3127
|
-
return;
|
|
3128
|
-
}
|
|
3129
|
-
if (name in knownIds) {
|
|
3130
|
-
knownIds[name]++;
|
|
3131
|
-
}
|
|
3132
|
-
else {
|
|
3133
|
-
knownIds[name] = 1;
|
|
3134
|
-
}
|
|
3135
|
-
(node.scopeIds || (node.scopeIds = new Set())).add(name);
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
}));
|
|
3257
|
+
const knownIds = Object.create(context.identifiers);
|
|
3258
|
+
walkIdentifiers(ast, (node, parent, _, isReferenced, isLocal) => {
|
|
3259
|
+
if (isStaticPropertyKey(node, parent)) {
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3262
|
+
// v2 wrapped filter call
|
|
3263
|
+
if (node.name.startsWith('_filter_')) {
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
const needPrefix = isReferenced && canPrefix(node);
|
|
3267
|
+
if (needPrefix && !isLocal) {
|
|
3268
|
+
if (isStaticProperty(parent) && parent.shorthand) {
|
|
3269
|
+
node.prefix = `${node.name}: `;
|
|
3139
3270
|
}
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
}
|
|
3149
|
-
});
|
|
3271
|
+
node.name = rewriteIdentifier(node.name, parent, node);
|
|
3272
|
+
ids.push(node);
|
|
3273
|
+
}
|
|
3274
|
+
else {
|
|
3275
|
+
// The identifier is considered constant unless it's pointing to a
|
|
3276
|
+
// local scope variable (a v-for alias, or a v-slot prop)
|
|
3277
|
+
if (!(needPrefix && isLocal) && !bailConstant) {
|
|
3278
|
+
node.isConstant = true;
|
|
3150
3279
|
}
|
|
3280
|
+
// also generate sub-expressions for other identifiers for better
|
|
3281
|
+
// source map support. (except for property keys which are static)
|
|
3282
|
+
ids.push(node);
|
|
3151
3283
|
}
|
|
3152
|
-
}
|
|
3284
|
+
}, true, // invoke on ALL identifiers
|
|
3285
|
+
parentStack, knownIds);
|
|
3153
3286
|
// We break up the compound expression into an array of strings and sub
|
|
3154
3287
|
// expressions (for identifiers that have been prefixed). In codegen, if
|
|
3155
3288
|
// an ExpressionNode has the `.children` property, it will be used instead of
|
|
@@ -3188,51 +3321,7 @@ asRawStatements = false) {
|
|
|
3188
3321
|
ret.identifiers = Object.keys(knownIds);
|
|
3189
3322
|
return ret;
|
|
3190
3323
|
}
|
|
3191
|
-
|
|
3192
|
-
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
3193
|
-
};
|
|
3194
|
-
const isStaticProperty = (node) => node &&
|
|
3195
|
-
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
3196
|
-
!node.computed;
|
|
3197
|
-
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
3198
|
-
function shouldPrefix(id, parent, parentStack) {
|
|
3199
|
-
// declaration id
|
|
3200
|
-
if ((parent.type === 'VariableDeclarator' ||
|
|
3201
|
-
parent.type === 'ClassDeclaration') &&
|
|
3202
|
-
parent.id === id) {
|
|
3203
|
-
return false;
|
|
3204
|
-
}
|
|
3205
|
-
if (isFunction(parent)) {
|
|
3206
|
-
// function decalration/expression id
|
|
3207
|
-
if (parent.id === id) {
|
|
3208
|
-
return false;
|
|
3209
|
-
}
|
|
3210
|
-
// params list
|
|
3211
|
-
if (parent.params.includes(id)) {
|
|
3212
|
-
return false;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
// property key
|
|
3216
|
-
// this also covers object destructure pattern
|
|
3217
|
-
if (isStaticPropertyKey(id, parent)) {
|
|
3218
|
-
return false;
|
|
3219
|
-
}
|
|
3220
|
-
// non-assignment array destructure pattern
|
|
3221
|
-
if (parent.type === 'ArrayPattern' &&
|
|
3222
|
-
!isInDestructureAssignment(parent, parentStack)) {
|
|
3223
|
-
return false;
|
|
3224
|
-
}
|
|
3225
|
-
// member expression property
|
|
3226
|
-
if ((parent.type === 'MemberExpression' ||
|
|
3227
|
-
parent.type === 'OptionalMemberExpression') &&
|
|
3228
|
-
parent.property === id &&
|
|
3229
|
-
!parent.computed) {
|
|
3230
|
-
return false;
|
|
3231
|
-
}
|
|
3232
|
-
// is a special keyword but parsed as identifier
|
|
3233
|
-
if (id.name === 'arguments') {
|
|
3234
|
-
return false;
|
|
3235
|
-
}
|
|
3324
|
+
function canPrefix(id) {
|
|
3236
3325
|
// skip whitelisted globals
|
|
3237
3326
|
if (shared.isGloballyWhitelisted(id.name)) {
|
|
3238
3327
|
return false;
|
|
@@ -3243,22 +3332,6 @@ function shouldPrefix(id, parent, parentStack) {
|
|
|
3243
3332
|
}
|
|
3244
3333
|
return true;
|
|
3245
3334
|
}
|
|
3246
|
-
function isInDestructureAssignment(parent, parentStack) {
|
|
3247
|
-
if (parent &&
|
|
3248
|
-
(parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
|
|
3249
|
-
let i = parentStack.length;
|
|
3250
|
-
while (i--) {
|
|
3251
|
-
const p = parentStack[i];
|
|
3252
|
-
if (p.type === 'AssignmentExpression') {
|
|
3253
|
-
return true;
|
|
3254
|
-
}
|
|
3255
|
-
else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
|
|
3256
|
-
break;
|
|
3257
|
-
}
|
|
3258
|
-
}
|
|
3259
|
-
}
|
|
3260
|
-
return false;
|
|
3261
|
-
}
|
|
3262
3335
|
function stringifyExpression(exp) {
|
|
3263
3336
|
if (shared.isString(exp)) {
|
|
3264
3337
|
return exp;
|
|
@@ -4443,7 +4516,10 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
4443
4516
|
!isStaticExp(styleProp.value) &&
|
|
4444
4517
|
// the static style is compiled into an object,
|
|
4445
4518
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
4446
|
-
hasStyleBinding
|
|
4519
|
+
(hasStyleBinding ||
|
|
4520
|
+
// v-bind:style and style both exist,
|
|
4521
|
+
// v-bind:style with static literal object
|
|
4522
|
+
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
4447
4523
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
4448
4524
|
}
|
|
4449
4525
|
}
|
|
@@ -5340,6 +5416,7 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
|
5340
5416
|
exports.createTemplateLiteral = createTemplateLiteral;
|
|
5341
5417
|
exports.createTransformContext = createTransformContext;
|
|
5342
5418
|
exports.createVNodeCall = createVNodeCall;
|
|
5419
|
+
exports.extractIdentifiers = extractIdentifiers;
|
|
5343
5420
|
exports.findDir = findDir;
|
|
5344
5421
|
exports.findProp = findProp;
|
|
5345
5422
|
exports.generate = generate;
|
|
@@ -5355,10 +5432,15 @@ exports.injectProp = injectProp;
|
|
|
5355
5432
|
exports.isBindKey = isBindKey;
|
|
5356
5433
|
exports.isBuiltInType = isBuiltInType;
|
|
5357
5434
|
exports.isCoreComponent = isCoreComponent;
|
|
5435
|
+
exports.isFunctionType = isFunctionType;
|
|
5436
|
+
exports.isInDestructureAssignment = isInDestructureAssignment;
|
|
5358
5437
|
exports.isMemberExpression = isMemberExpression;
|
|
5438
|
+
exports.isReferencedIdentifier = isReferencedIdentifier;
|
|
5359
5439
|
exports.isSimpleIdentifier = isSimpleIdentifier;
|
|
5360
5440
|
exports.isSlotOutlet = isSlotOutlet;
|
|
5361
5441
|
exports.isStaticExp = isStaticExp;
|
|
5442
|
+
exports.isStaticProperty = isStaticProperty;
|
|
5443
|
+
exports.isStaticPropertyKey = isStaticPropertyKey;
|
|
5362
5444
|
exports.isTemplateNode = isTemplateNode;
|
|
5363
5445
|
exports.isText = isText;
|
|
5364
5446
|
exports.isVSlot = isVSlot;
|
|
@@ -5381,4 +5463,7 @@ exports.transformExpression = transformExpression;
|
|
|
5381
5463
|
exports.transformModel = transformModel;
|
|
5382
5464
|
exports.transformOn = transformOn;
|
|
5383
5465
|
exports.traverseNode = traverseNode;
|
|
5466
|
+
exports.walkBlockDeclarations = walkBlockDeclarations;
|
|
5467
|
+
exports.walkFunctionParams = walkFunctionParams;
|
|
5468
|
+
exports.walkIdentifiers = walkIdentifiers;
|
|
5384
5469
|
exports.warnDeprecation = warnDeprecation;
|
package/dist/compiler-core.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { BlockStatement as BlockStatement_2 } from '@babel/types';
|
|
2
|
+
import { Function as Function_2 } from '@babel/types';
|
|
1
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';
|
|
2
7
|
import { ParserPlugin } from '@babel/parser';
|
|
8
|
+
import { Program } from '@babel/types';
|
|
3
9
|
import { RawSourceMap } from 'source-map';
|
|
4
10
|
import { SourceMapGenerator } from 'source-map';
|
|
5
11
|
|
|
@@ -438,6 +444,8 @@ declare interface ErrorHandlingOptions {
|
|
|
438
444
|
|
|
439
445
|
export declare type ExpressionNode = SimpleExpressionNode | CompoundExpressionNode;
|
|
440
446
|
|
|
447
|
+
export declare function extractIdentifiers(param: Node_3, nodes?: Identifier[]): Identifier[];
|
|
448
|
+
|
|
441
449
|
export declare function findDir(node: ElementNode, name: string | RegExp, allowEmpty?: boolean): DirectiveNode | undefined;
|
|
442
450
|
|
|
443
451
|
export declare function findProp(node: ElementNode, name: string, dynamicOnly?: boolean, allowEmpty?: boolean): ElementNode['props'][0] | undefined;
|
|
@@ -575,6 +583,10 @@ export declare const isBuiltInType: (tag: string, expected: string) => boolean;
|
|
|
575
583
|
|
|
576
584
|
export declare function isCoreComponent(tag: string): symbol | void;
|
|
577
585
|
|
|
586
|
+
export declare const isFunctionType: (node: Node_3) => node is Function_2;
|
|
587
|
+
|
|
588
|
+
export declare function isInDestructureAssignment(parent: Node_3, parentStack: Node_3[]): boolean;
|
|
589
|
+
|
|
578
590
|
/**
|
|
579
591
|
* Simple lexer to check if an expression is a member expression. This is
|
|
580
592
|
* lax and only checks validity at the root level (i.e. does not validate exps
|
|
@@ -583,12 +595,18 @@ export declare function isCoreComponent(tag: string): symbol | void;
|
|
|
583
595
|
*/
|
|
584
596
|
export declare const isMemberExpression: (path: string) => boolean;
|
|
585
597
|
|
|
598
|
+
export declare function isReferencedIdentifier(id: Identifier, parent: Node_3 | null, parentStack: Node_3[]): boolean;
|
|
599
|
+
|
|
586
600
|
export declare const isSimpleIdentifier: (name: string) => boolean;
|
|
587
601
|
|
|
588
602
|
export declare function isSlotOutlet(node: RootNode | TemplateChildNode): node is SlotOutletNode;
|
|
589
603
|
|
|
590
604
|
export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
|
|
591
605
|
|
|
606
|
+
export declare const isStaticProperty: (node: Node_3) => node is ObjectProperty;
|
|
607
|
+
|
|
608
|
+
export declare const isStaticPropertyKey: (node: Node_3, parent: Node_3) => boolean;
|
|
609
|
+
|
|
592
610
|
export declare function isTemplateNode(node: RootNode | TemplateChildNode): node is TemplateNode;
|
|
593
611
|
|
|
594
612
|
export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
|
|
@@ -1138,6 +1156,12 @@ export declare interface VNodeCall extends Node_2 {
|
|
|
1138
1156
|
isComponent: boolean;
|
|
1139
1157
|
}
|
|
1140
1158
|
|
|
1159
|
+
export declare function walkBlockDeclarations(block: BlockStatement_2 | Program, onIdent: (node: Identifier) => void): void;
|
|
1160
|
+
|
|
1161
|
+
export declare function walkFunctionParams(node: Function_2, onIdent: (id: Identifier) => void): void;
|
|
1162
|
+
|
|
1163
|
+
export declare function walkIdentifiers(root: Node_3, onIdentifier: (node: Identifier, parent: Node_3, parentStack: Node_3[], isReference: boolean, isLocal: boolean) => void, includeAll?: boolean, parentStack?: Node_3[], knownIds?: Record<string, number>): void;
|
|
1164
|
+
|
|
1141
1165
|
export declare function warnDeprecation(key: CompilerDeprecationTypes, context: ParserContext | TransformContext, loc: SourceLocation | null, ...args: any[]): void;
|
|
1142
1166
|
|
|
1143
1167
|
export declare const WITH_CTX: unique symbol;
|
|
@@ -646,7 +646,10 @@ function injectProp(node, prop, context) {
|
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
function toValidAssetId(name, type) {
|
|
649
|
-
|
|
649
|
+
// see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
|
|
650
|
+
return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
|
651
|
+
return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
|
|
652
|
+
})}`;
|
|
650
653
|
}
|
|
651
654
|
// Check if a node contains expressions that reference current context scope ids
|
|
652
655
|
function hasScopeRef(node, ids) {
|
|
@@ -1865,16 +1868,19 @@ function getGeneratedPropsConstantType(node, context) {
|
|
|
1865
1868
|
if (keyType < returnType) {
|
|
1866
1869
|
returnType = keyType;
|
|
1867
1870
|
}
|
|
1868
|
-
|
|
1871
|
+
let valueType;
|
|
1872
|
+
if (value.type === 4 /* SIMPLE_EXPRESSION */) {
|
|
1873
|
+
valueType = getConstantType(value, context);
|
|
1874
|
+
}
|
|
1875
|
+
else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
|
|
1869
1876
|
// some helper calls can be hoisted,
|
|
1870
1877
|
// such as the `normalizeProps` generated by the compiler for pre-normalize class,
|
|
1871
1878
|
// in this case we need to respect the ConstanType of the helper's argments
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1879
|
+
valueType = getConstantTypeOfHelperCall(value, context);
|
|
1880
|
+
}
|
|
1881
|
+
else {
|
|
1882
|
+
valueType = 0 /* NOT_CONSTANT */;
|
|
1876
1883
|
}
|
|
1877
|
-
const valueType = getConstantType(value, context);
|
|
1878
1884
|
if (valueType === 0 /* NOT_CONSTANT */) {
|
|
1879
1885
|
return valueType;
|
|
1880
1886
|
}
|
|
@@ -2742,6 +2748,103 @@ function genCacheExpression(node, context) {
|
|
|
2742
2748
|
push(`)`);
|
|
2743
2749
|
}
|
|
2744
2750
|
|
|
2751
|
+
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = Object.create(null)) {
|
|
2752
|
+
{
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function isReferencedIdentifier(id, parent, parentStack) {
|
|
2757
|
+
{
|
|
2758
|
+
return false;
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
function isInDestructureAssignment(parent, parentStack) {
|
|
2762
|
+
if (parent &&
|
|
2763
|
+
(parent.type === 'ObjectProperty' || parent.type === 'ArrayPattern')) {
|
|
2764
|
+
let i = parentStack.length;
|
|
2765
|
+
while (i--) {
|
|
2766
|
+
const p = parentStack[i];
|
|
2767
|
+
if (p.type === 'AssignmentExpression') {
|
|
2768
|
+
return true;
|
|
2769
|
+
}
|
|
2770
|
+
else if (p.type !== 'ObjectProperty' && !p.type.endsWith('Pattern')) {
|
|
2771
|
+
break;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
return false;
|
|
2776
|
+
}
|
|
2777
|
+
function walkFunctionParams(node, onIdent) {
|
|
2778
|
+
for (const p of node.params) {
|
|
2779
|
+
for (const id of extractIdentifiers(p)) {
|
|
2780
|
+
onIdent(id);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
function walkBlockDeclarations(block, onIdent) {
|
|
2785
|
+
for (const stmt of block.body) {
|
|
2786
|
+
if (stmt.type === 'VariableDeclaration') {
|
|
2787
|
+
if (stmt.declare)
|
|
2788
|
+
continue;
|
|
2789
|
+
for (const decl of stmt.declarations) {
|
|
2790
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
2791
|
+
onIdent(id);
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
else if (stmt.type === 'FunctionDeclaration' ||
|
|
2796
|
+
stmt.type === 'ClassDeclaration') {
|
|
2797
|
+
if (stmt.declare || !stmt.id)
|
|
2798
|
+
continue;
|
|
2799
|
+
onIdent(stmt.id);
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function extractIdentifiers(param, nodes = []) {
|
|
2804
|
+
switch (param.type) {
|
|
2805
|
+
case 'Identifier':
|
|
2806
|
+
nodes.push(param);
|
|
2807
|
+
break;
|
|
2808
|
+
case 'MemberExpression':
|
|
2809
|
+
let object = param;
|
|
2810
|
+
while (object.type === 'MemberExpression') {
|
|
2811
|
+
object = object.object;
|
|
2812
|
+
}
|
|
2813
|
+
nodes.push(object);
|
|
2814
|
+
break;
|
|
2815
|
+
case 'ObjectPattern':
|
|
2816
|
+
for (const prop of param.properties) {
|
|
2817
|
+
if (prop.type === 'RestElement') {
|
|
2818
|
+
extractIdentifiers(prop.argument, nodes);
|
|
2819
|
+
}
|
|
2820
|
+
else {
|
|
2821
|
+
extractIdentifiers(prop.value, nodes);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
break;
|
|
2825
|
+
case 'ArrayPattern':
|
|
2826
|
+
param.elements.forEach(element => {
|
|
2827
|
+
if (element)
|
|
2828
|
+
extractIdentifiers(element, nodes);
|
|
2829
|
+
});
|
|
2830
|
+
break;
|
|
2831
|
+
case 'RestElement':
|
|
2832
|
+
extractIdentifiers(param.argument, nodes);
|
|
2833
|
+
break;
|
|
2834
|
+
case 'AssignmentPattern':
|
|
2835
|
+
extractIdentifiers(param.left, nodes);
|
|
2836
|
+
break;
|
|
2837
|
+
}
|
|
2838
|
+
return nodes;
|
|
2839
|
+
}
|
|
2840
|
+
const isFunctionType = (node) => {
|
|
2841
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
2842
|
+
};
|
|
2843
|
+
const isStaticProperty = (node) => node &&
|
|
2844
|
+
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
|
|
2845
|
+
!node.computed;
|
|
2846
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
2847
|
+
|
|
2745
2848
|
// these keywords should not appear inside expressions, but operators like
|
|
2746
2849
|
// typeof, instanceof and in are allowed
|
|
2747
2850
|
const prohibitedKeywordRE = new RegExp('\\b' +
|
|
@@ -3966,7 +4069,10 @@ function buildProps(node, context, props = node.props, ssr = false) {
|
|
|
3966
4069
|
!isStaticExp(styleProp.value) &&
|
|
3967
4070
|
// the static style is compiled into an object,
|
|
3968
4071
|
// so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
|
3969
|
-
hasStyleBinding
|
|
4072
|
+
(hasStyleBinding ||
|
|
4073
|
+
// v-bind:style and style both exist,
|
|
4074
|
+
// v-bind:style with static literal object
|
|
4075
|
+
styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
|
|
3970
4076
|
styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
3971
4077
|
}
|
|
3972
4078
|
}
|
|
@@ -4727,4 +4833,4 @@ function baseCompile(template, options = {}) {
|
|
|
4727
4833
|
|
|
4728
4834
|
const noopDirectiveTransform = () => ({ props: [] });
|
|
4729
4835
|
|
|
4730
|
-
export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, WITH_SCOPE_ID, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildProps, buildSlots, checkCompatEnabled, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, findDir, findProp, generate, getBaseTransformPreset, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBindKey, isBuiltInType, isCoreComponent, isMemberExpression, isSimpleIdentifier, isSlotOutlet, isStaticExp, isTemplateNode, isText, isVSlot, locStub, makeBlock, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, warnDeprecation };
|
|
4836
|
+
export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, WITH_SCOPE_ID, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildProps, buildSlots, checkCompatEnabled, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, extractIdentifiers, findDir, findProp, generate, getBaseTransformPreset, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBindKey, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText, isVSlot, locStub, makeBlock, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"description": "@vue/compiler-core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/compiler-core.esm-bundler.js",
|
|
@@ -32,10 +32,10 @@
|
|
|
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.
|
|
36
|
-
"@babel/parser": "^7.
|
|
37
|
-
"@babel/types": "^7.
|
|
38
|
-
"estree-walker": "^2.0.
|
|
35
|
+
"@vue/shared": "3.2.6",
|
|
36
|
+
"@babel/parser": "^7.15.0",
|
|
37
|
+
"@babel/types": "^7.15.0",
|
|
38
|
+
"estree-walker": "^2.0.2",
|
|
39
39
|
"source-map": "^0.6.1"
|
|
40
40
|
}
|
|
41
41
|
}
|