@vue/compiler-sfc 3.2.31 → 3.2.34-beta.1
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-sfc.cjs.js +263 -74
- package/dist/compiler-sfc.esm-browser.js +281 -101
- package/package.json +6 -6
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -111,9 +111,9 @@ var hashSum = sum;
|
|
|
111
111
|
const CSS_VARS_HELPER = `useCssVars`;
|
|
112
112
|
// match v-bind() with max 2-levels of nested parens.
|
|
113
113
|
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
|
|
114
|
-
function genCssVarsFromList(vars, id, isProd) {
|
|
114
|
+
function genCssVarsFromList(vars, id, isProd, isSSR = false) {
|
|
115
115
|
return `{\n ${vars
|
|
116
|
-
.map(key => `"${genVarName(id, key, isProd)}": (${key})`)
|
|
116
|
+
.map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
|
|
117
117
|
.join(',\n ')}\n}`;
|
|
118
118
|
}
|
|
119
119
|
function genVarName(id, raw, isProd) {
|
|
@@ -124,7 +124,7 @@ function genVarName(id, raw, isProd) {
|
|
|
124
124
|
return `${id}-${raw.replace(/([^\w-])/g, '_')}`;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function normalizeExpression(exp) {
|
|
128
128
|
exp = exp.trim();
|
|
129
129
|
if ((exp[0] === `'` && exp[exp.length - 1] === `'`) ||
|
|
130
130
|
(exp[0] === `"` && exp[exp.length - 1] === `"`)) {
|
|
@@ -139,7 +139,7 @@ function parseCssVars(sfc) {
|
|
|
139
139
|
// ignore v-bind() in comments /* ... */
|
|
140
140
|
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
141
141
|
while ((match = cssVarRE.exec(content))) {
|
|
142
|
-
const variable =
|
|
142
|
+
const variable = normalizeExpression(match[1]);
|
|
143
143
|
if (!vars.includes(variable)) {
|
|
144
144
|
vars.push(variable);
|
|
145
145
|
}
|
|
@@ -155,7 +155,7 @@ const cssVarsPlugin = opts => {
|
|
|
155
155
|
// rewrite CSS variables
|
|
156
156
|
if (cssVarRE.test(decl.value)) {
|
|
157
157
|
decl.value = decl.value.replace(cssVarRE, (_, $1) => {
|
|
158
|
-
return `var(--${genVarName(id,
|
|
158
|
+
return `var(--${genVarName(id, normalizeExpression($1), isProd)})`;
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -1011,9 +1011,15 @@ const defaultAssetUrlOptions = {
|
|
|
1011
1011
|
const normalizeOptions = (options) => {
|
|
1012
1012
|
if (Object.keys(options).some(key => shared.isArray(options[key]))) {
|
|
1013
1013
|
// legacy option format which directly passes in tags config
|
|
1014
|
-
return
|
|
1014
|
+
return {
|
|
1015
|
+
...defaultAssetUrlOptions,
|
|
1016
|
+
tags: options
|
|
1017
|
+
};
|
|
1015
1018
|
}
|
|
1016
|
-
return
|
|
1019
|
+
return {
|
|
1020
|
+
...defaultAssetUrlOptions,
|
|
1021
|
+
...options
|
|
1022
|
+
};
|
|
1017
1023
|
};
|
|
1018
1024
|
const createAssetUrlTransformWithOptions = (options) => {
|
|
1019
1025
|
return (node, context) => transformAssetUrl(node, context, options);
|
|
@@ -1102,6 +1108,10 @@ function getImportsExpressionExp(path, hash, loc, context) {
|
|
|
1102
1108
|
return exp;
|
|
1103
1109
|
}
|
|
1104
1110
|
const hashExp = `${name} + '${hash}'`;
|
|
1111
|
+
const finalExp = compilerCore.createSimpleExpression(hashExp, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1112
|
+
if (!context.hoistStatic) {
|
|
1113
|
+
return finalExp;
|
|
1114
|
+
}
|
|
1105
1115
|
const existingHoistIndex = context.hoists.findIndex(h => {
|
|
1106
1116
|
return (h &&
|
|
1107
1117
|
h.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
@@ -1111,7 +1121,7 @@ function getImportsExpressionExp(path, hash, loc, context) {
|
|
|
1111
1121
|
if (existingHoistIndex > -1) {
|
|
1112
1122
|
return compilerCore.createSimpleExpression(`_hoisted_${existingHoistIndex + 1}`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1113
1123
|
}
|
|
1114
|
-
return context.hoist(
|
|
1124
|
+
return context.hoist(finalExp);
|
|
1115
1125
|
}
|
|
1116
1126
|
else {
|
|
1117
1127
|
return compilerCore.createSimpleExpression(`''`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
@@ -1153,35 +1163,41 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1153
1163
|
imageCandidates.splice(i, 1);
|
|
1154
1164
|
}
|
|
1155
1165
|
}
|
|
1156
|
-
const
|
|
1166
|
+
const shouldProcessUrl = (url) => {
|
|
1157
1167
|
return (!isExternalUrl(url) &&
|
|
1158
1168
|
!isDataUrl(url) &&
|
|
1159
1169
|
(options.includeAbsolute || isRelativeUrl(url)));
|
|
1160
|
-
}
|
|
1170
|
+
};
|
|
1161
1171
|
// When srcset does not contain any qualified URLs, skip transforming
|
|
1162
|
-
if (!
|
|
1172
|
+
if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
|
|
1163
1173
|
return;
|
|
1164
1174
|
}
|
|
1165
1175
|
if (options.base) {
|
|
1166
1176
|
const base = options.base;
|
|
1167
1177
|
const set = [];
|
|
1168
|
-
|
|
1178
|
+
let needImportTransform = false;
|
|
1179
|
+
imageCandidates.forEach(candidate => {
|
|
1180
|
+
let { url, descriptor } = candidate;
|
|
1169
1181
|
descriptor = descriptor ? ` ${descriptor}` : ``;
|
|
1170
|
-
if (
|
|
1171
|
-
|
|
1182
|
+
if (url[0] === '.') {
|
|
1183
|
+
candidate.url = (path__default.posix || path__default).join(base, url);
|
|
1184
|
+
set.push(candidate.url + descriptor);
|
|
1185
|
+
}
|
|
1186
|
+
else if (shouldProcessUrl(url)) {
|
|
1187
|
+
needImportTransform = true;
|
|
1172
1188
|
}
|
|
1173
1189
|
else {
|
|
1174
1190
|
set.push(url + descriptor);
|
|
1175
1191
|
}
|
|
1176
1192
|
});
|
|
1177
|
-
|
|
1178
|
-
|
|
1193
|
+
if (!needImportTransform) {
|
|
1194
|
+
attr.value.content = set.join(', ');
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1179
1197
|
}
|
|
1180
1198
|
const compoundExpression = compilerCore.createCompoundExpression([], attr.loc);
|
|
1181
1199
|
imageCandidates.forEach(({ url, descriptor }, index) => {
|
|
1182
|
-
if (
|
|
1183
|
-
!isDataUrl(url) &&
|
|
1184
|
-
(options.includeAbsolute || isRelativeUrl(url))) {
|
|
1200
|
+
if (shouldProcessUrl(url)) {
|
|
1185
1201
|
const { path } = parseUrl(url);
|
|
1186
1202
|
let exp;
|
|
1187
1203
|
if (path) {
|
|
@@ -1211,13 +1227,16 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1211
1227
|
compoundExpression.children.push(` + ', ' + `);
|
|
1212
1228
|
}
|
|
1213
1229
|
});
|
|
1214
|
-
|
|
1215
|
-
|
|
1230
|
+
let exp = compoundExpression;
|
|
1231
|
+
if (context.hoistStatic) {
|
|
1232
|
+
exp = context.hoist(compoundExpression);
|
|
1233
|
+
exp.constType = 3 /* CAN_STRINGIFY */;
|
|
1234
|
+
}
|
|
1216
1235
|
node.props[index] = {
|
|
1217
1236
|
type: 7 /* DIRECTIVE */,
|
|
1218
1237
|
name: 'bind',
|
|
1219
1238
|
arg: compilerCore.createSimpleExpression('srcset', true, attr.loc),
|
|
1220
|
-
exp
|
|
1239
|
+
exp,
|
|
1221
1240
|
modifiers: [],
|
|
1222
1241
|
loc: attr.loc
|
|
1223
1242
|
};
|
|
@@ -3072,7 +3091,7 @@ function preprocess({ source, filename, preprocessOptions }, preprocessor) {
|
|
|
3072
3091
|
// have to be sync because they are applied via Node.js require hooks)
|
|
3073
3092
|
let res = '';
|
|
3074
3093
|
let err = null;
|
|
3075
|
-
preprocessor.render(source,
|
|
3094
|
+
preprocessor.render(source, { filename, ...preprocessOptions }, (_err, _res) => {
|
|
3076
3095
|
if (_err)
|
|
3077
3096
|
err = _err;
|
|
3078
3097
|
res = _res;
|
|
@@ -3090,7 +3109,10 @@ function compileTemplate(options) {
|
|
|
3090
3109
|
: false;
|
|
3091
3110
|
if (preprocessor) {
|
|
3092
3111
|
try {
|
|
3093
|
-
return doCompileTemplate(
|
|
3112
|
+
return doCompileTemplate({
|
|
3113
|
+
...options,
|
|
3114
|
+
source: preprocess(options, preprocessor)
|
|
3115
|
+
});
|
|
3094
3116
|
}
|
|
3095
3117
|
catch (e) {
|
|
3096
3118
|
return {
|
|
@@ -3141,9 +3163,23 @@ function doCompileTemplate({ filename, id, scoped, slotted, inMap, source, ssr =
|
|
|
3141
3163
|
}
|
|
3142
3164
|
const shortId = id.replace(/^data-v-/, '');
|
|
3143
3165
|
const longId = `data-v-${shortId}`;
|
|
3144
|
-
let { code, ast, preamble, map } = compiler.compile(source,
|
|
3145
|
-
|
|
3146
|
-
|
|
3166
|
+
let { code, ast, preamble, map } = compiler.compile(source, {
|
|
3167
|
+
mode: 'module',
|
|
3168
|
+
prefixIdentifiers: true,
|
|
3169
|
+
hoistStatic: true,
|
|
3170
|
+
cacheHandlers: true,
|
|
3171
|
+
ssrCssVars: ssr && ssrCssVars && ssrCssVars.length
|
|
3172
|
+
? genCssVarsFromList(ssrCssVars, shortId, isProd, true)
|
|
3173
|
+
: '',
|
|
3174
|
+
scopeId: scoped ? longId : undefined,
|
|
3175
|
+
slotted,
|
|
3176
|
+
sourceMap: true,
|
|
3177
|
+
...compilerOptions,
|
|
3178
|
+
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
|
|
3179
|
+
filename,
|
|
3180
|
+
onError: e => errors.push(e),
|
|
3181
|
+
onWarn: w => warnings.push(w)
|
|
3182
|
+
});
|
|
3147
3183
|
// inMap should be the map produced by ./parse.ts which is a simple line-only
|
|
3148
3184
|
// mapping. If it is present, we need to adjust the final map and errors to
|
|
3149
3185
|
// reflect the original line numbers.
|
|
@@ -3322,6 +3358,11 @@ function compileScript(sfc, options) {
|
|
|
3322
3358
|
if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
|
|
3323
3359
|
plugins.push('jsx');
|
|
3324
3360
|
}
|
|
3361
|
+
else {
|
|
3362
|
+
// If don't match the case of adding jsx, should remove the jsx from the babelParserPlugins
|
|
3363
|
+
if (options.babelParserPlugins)
|
|
3364
|
+
options.babelParserPlugins = options.babelParserPlugins.filter(n => n !== 'jsx');
|
|
3365
|
+
}
|
|
3325
3366
|
if (options.babelParserPlugins)
|
|
3326
3367
|
plugins.push(...options.babelParserPlugins);
|
|
3327
3368
|
if (isTS)
|
|
@@ -3368,9 +3409,13 @@ function compileScript(sfc, options) {
|
|
|
3368
3409
|
content += genNormalScriptCssVarsCode(cssVars, bindings, scopeId, isProd);
|
|
3369
3410
|
content += `\nexport default ${DEFAULT_VAR}`;
|
|
3370
3411
|
}
|
|
3371
|
-
return
|
|
3412
|
+
return {
|
|
3413
|
+
...script,
|
|
3414
|
+
content,
|
|
3372
3415
|
map,
|
|
3373
|
-
bindings,
|
|
3416
|
+
bindings,
|
|
3417
|
+
scriptAst: scriptAst.body
|
|
3418
|
+
};
|
|
3374
3419
|
}
|
|
3375
3420
|
catch (e) {
|
|
3376
3421
|
// silently fallback if parse fails since user may be using custom
|
|
@@ -3397,6 +3442,8 @@ function compileScript(sfc, options) {
|
|
|
3397
3442
|
let hasDefinePropsCall = false;
|
|
3398
3443
|
let hasDefineEmitCall = false;
|
|
3399
3444
|
let hasDefineExposeCall = false;
|
|
3445
|
+
let hasDefaultExportName = false;
|
|
3446
|
+
let hasDefaultExportRender = false;
|
|
3400
3447
|
let propsRuntimeDecl;
|
|
3401
3448
|
let propsRuntimeDefaults;
|
|
3402
3449
|
let propsDestructureDecl;
|
|
@@ -3439,12 +3486,18 @@ function compileScript(sfc, options) {
|
|
|
3439
3486
|
function error(msg, node, end = node.end + startOffset) {
|
|
3440
3487
|
throw new Error(`[@vue/compiler-sfc] ${msg}\n\n${sfc.filename}\n${shared.generateCodeFrame(source, node.start + startOffset, end)}`);
|
|
3441
3488
|
}
|
|
3442
|
-
function registerUserImport(source, local, imported, isType, isFromSetup) {
|
|
3489
|
+
function registerUserImport(source, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
|
|
3443
3490
|
if (source === 'vue' && imported) {
|
|
3444
3491
|
userImportAlias[imported] = local;
|
|
3445
3492
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3493
|
+
// template usage check is only needed in non-inline mode, so we can skip
|
|
3494
|
+
// the work if inlineTemplate is true.
|
|
3495
|
+
let isUsedInTemplate = needTemplateUsageCheck;
|
|
3496
|
+
if (needTemplateUsageCheck &&
|
|
3497
|
+
isTS &&
|
|
3498
|
+
sfc.template &&
|
|
3499
|
+
!sfc.template.src &&
|
|
3500
|
+
!sfc.template.lang) {
|
|
3448
3501
|
isUsedInTemplate = isImportUsed(local, sfc);
|
|
3449
3502
|
}
|
|
3450
3503
|
userImports[local] = {
|
|
@@ -3486,7 +3539,9 @@ function compileScript(sfc, options) {
|
|
|
3486
3539
|
if (prop.computed) {
|
|
3487
3540
|
error(`${DEFINE_PROPS}() destructure cannot use computed key.`, prop.key);
|
|
3488
3541
|
}
|
|
3489
|
-
const propKey = prop.key.
|
|
3542
|
+
const propKey = prop.key.type === 'StringLiteral'
|
|
3543
|
+
? prop.key.value
|
|
3544
|
+
: prop.key.name;
|
|
3490
3545
|
if (prop.value.type === 'AssignmentPattern') {
|
|
3491
3546
|
// default value { foo = 123 }
|
|
3492
3547
|
const { left, right } = prop.value;
|
|
@@ -3715,7 +3770,7 @@ function compileScript(sfc, options) {
|
|
|
3715
3770
|
if (destructured && destructured.default) {
|
|
3716
3771
|
const value = scriptSetup.content.slice(destructured.default.start, destructured.default.end);
|
|
3717
3772
|
const isLiteral = destructured.default.type.endsWith('Literal');
|
|
3718
|
-
return isLiteral ? value : `() => ${value}`;
|
|
3773
|
+
return isLiteral ? value : `() => (${value})`;
|
|
3719
3774
|
}
|
|
3720
3775
|
}
|
|
3721
3776
|
function genSetupPropsType(node) {
|
|
@@ -3763,12 +3818,42 @@ function compileScript(sfc, options) {
|
|
|
3763
3818
|
const imported = specifier.type === 'ImportSpecifier' &&
|
|
3764
3819
|
specifier.imported.type === 'Identifier' &&
|
|
3765
3820
|
specifier.imported.name;
|
|
3766
|
-
registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type'
|
|
3821
|
+
registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type' ||
|
|
3822
|
+
(specifier.type === 'ImportSpecifier' &&
|
|
3823
|
+
specifier.importKind === 'type'), false, !options.inlineTemplate);
|
|
3767
3824
|
}
|
|
3768
3825
|
}
|
|
3769
3826
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
3770
3827
|
// export default
|
|
3771
3828
|
defaultExport = node;
|
|
3829
|
+
// check if user has manually specified `name` or 'render` option in
|
|
3830
|
+
// export default
|
|
3831
|
+
// if has name, skip name inference
|
|
3832
|
+
// if has render and no template, generate return object instead of
|
|
3833
|
+
// empty render function (#4980)
|
|
3834
|
+
let optionProperties;
|
|
3835
|
+
if (defaultExport.declaration.type === 'ObjectExpression') {
|
|
3836
|
+
optionProperties = defaultExport.declaration.properties;
|
|
3837
|
+
}
|
|
3838
|
+
else if (defaultExport.declaration.type === 'CallExpression' &&
|
|
3839
|
+
defaultExport.declaration.arguments[0].type === 'ObjectExpression') {
|
|
3840
|
+
optionProperties = defaultExport.declaration.arguments[0].properties;
|
|
3841
|
+
}
|
|
3842
|
+
if (optionProperties) {
|
|
3843
|
+
for (const s of optionProperties) {
|
|
3844
|
+
if (s.type === 'ObjectProperty' &&
|
|
3845
|
+
s.key.type === 'Identifier' &&
|
|
3846
|
+
s.key.name === 'name') {
|
|
3847
|
+
hasDefaultExportName = true;
|
|
3848
|
+
}
|
|
3849
|
+
if ((s.type === 'ObjectMethod' || s.type === 'ObjectProperty') &&
|
|
3850
|
+
s.key.type === 'Identifier' &&
|
|
3851
|
+
s.key.name === 'render') {
|
|
3852
|
+
// TODO warn when we provide a better way to do it?
|
|
3853
|
+
hasDefaultExportRender = true;
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3772
3857
|
// export default { ... } --> const __default__ = { ... }
|
|
3773
3858
|
const start = node.start + scriptStartOffset;
|
|
3774
3859
|
const end = node.declaration.start + scriptStartOffset;
|
|
@@ -3821,6 +3906,10 @@ function compileScript(sfc, options) {
|
|
|
3821
3906
|
// we need to move the block up so that `const __default__` is
|
|
3822
3907
|
// declared before being used in the actual component definition
|
|
3823
3908
|
if (scriptStartOffset > startOffset) {
|
|
3909
|
+
// if content doesn't end with newline, add one
|
|
3910
|
+
if (!/\n$/.test(script.content.trim())) {
|
|
3911
|
+
s.appendLeft(scriptEndOffset, `\n`);
|
|
3912
|
+
}
|
|
3824
3913
|
s.move(scriptStartOffset, scriptEndOffset, 0);
|
|
3825
3914
|
}
|
|
3826
3915
|
}
|
|
@@ -3875,9 +3964,12 @@ function compileScript(sfc, options) {
|
|
|
3875
3964
|
for (let i = 0; i < node.specifiers.length; i++) {
|
|
3876
3965
|
const specifier = node.specifiers[i];
|
|
3877
3966
|
const local = specifier.local.name;
|
|
3878
|
-
|
|
3967
|
+
let imported = specifier.type === 'ImportSpecifier' &&
|
|
3879
3968
|
specifier.imported.type === 'Identifier' &&
|
|
3880
3969
|
specifier.imported.name;
|
|
3970
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
3971
|
+
imported = '*';
|
|
3972
|
+
}
|
|
3881
3973
|
const source = node.source.value;
|
|
3882
3974
|
const existing = userImports[local];
|
|
3883
3975
|
if (source === 'vue' &&
|
|
@@ -3897,7 +3989,9 @@ function compileScript(sfc, options) {
|
|
|
3897
3989
|
}
|
|
3898
3990
|
}
|
|
3899
3991
|
else {
|
|
3900
|
-
registerUserImport(source, local, imported, node.importKind === 'type'
|
|
3992
|
+
registerUserImport(source, local, imported, node.importKind === 'type' ||
|
|
3993
|
+
(specifier.type === 'ImportSpecifier' &&
|
|
3994
|
+
specifier.importKind === 'type'), true, !options.inlineTemplate);
|
|
3901
3995
|
}
|
|
3902
3996
|
}
|
|
3903
3997
|
if (node.specifiers.length && removed === node.specifiers.length) {
|
|
@@ -3960,18 +4054,33 @@ function compileScript(sfc, options) {
|
|
|
3960
4054
|
// await
|
|
3961
4055
|
if ((node.type === 'VariableDeclaration' && !node.declare) ||
|
|
3962
4056
|
node.type.endsWith('Statement')) {
|
|
4057
|
+
const scope = [scriptSetupAst.body];
|
|
3963
4058
|
estreeWalker.walk(node, {
|
|
3964
4059
|
enter(child, parent) {
|
|
3965
4060
|
if (CompilerDOM.isFunctionType(child)) {
|
|
3966
4061
|
this.skip();
|
|
3967
4062
|
}
|
|
4063
|
+
if (child.type === 'BlockStatement') {
|
|
4064
|
+
scope.push(child.body);
|
|
4065
|
+
}
|
|
3968
4066
|
if (child.type === 'AwaitExpression') {
|
|
3969
4067
|
hasAwait = true;
|
|
3970
|
-
|
|
3971
|
-
|
|
4068
|
+
// if the await expression is an expression statement and
|
|
4069
|
+
// - is in the root scope
|
|
4070
|
+
// - or is not the first statement in a nested block scope
|
|
4071
|
+
// then it needs a semicolon before the generated code.
|
|
4072
|
+
const currentScope = scope[scope.length - 1];
|
|
4073
|
+
const needsSemi = currentScope.some((n, i) => {
|
|
4074
|
+
return ((scope.length === 1 || i > 0) &&
|
|
4075
|
+
n.type === 'ExpressionStatement' &&
|
|
4076
|
+
n.start === child.start);
|
|
3972
4077
|
});
|
|
3973
4078
|
processAwait(child, needsSemi, parent.type === 'ExpressionStatement');
|
|
3974
4079
|
}
|
|
4080
|
+
},
|
|
4081
|
+
exit(node) {
|
|
4082
|
+
if (node.type === 'BlockStatement')
|
|
4083
|
+
scope.pop();
|
|
3975
4084
|
}
|
|
3976
4085
|
});
|
|
3977
4086
|
}
|
|
@@ -4020,7 +4129,7 @@ function compileScript(sfc, options) {
|
|
|
4020
4129
|
checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
|
|
4021
4130
|
checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
|
|
4022
4131
|
checkInvalidScopeReference(propsDestructureDecl, DEFINE_PROPS);
|
|
4023
|
-
checkInvalidScopeReference(emitsRuntimeDecl,
|
|
4132
|
+
checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_EMITS);
|
|
4024
4133
|
// 6. remove non-script content
|
|
4025
4134
|
if (script) {
|
|
4026
4135
|
if (startOffset < scriptStartOffset) {
|
|
@@ -4056,7 +4165,8 @@ function compileScript(sfc, options) {
|
|
|
4056
4165
|
// props aliases
|
|
4057
4166
|
if (propsDestructureDecl) {
|
|
4058
4167
|
if (propsDestructureRestId) {
|
|
4059
|
-
bindingMetadata[propsDestructureRestId] =
|
|
4168
|
+
bindingMetadata[propsDestructureRestId] =
|
|
4169
|
+
"setup-reactive-const" /* SETUP_REACTIVE_CONST */;
|
|
4060
4170
|
}
|
|
4061
4171
|
for (const key in propsDestructuredBindings) {
|
|
4062
4172
|
const { local } = propsDestructuredBindings[key];
|
|
@@ -4071,7 +4181,9 @@ function compileScript(sfc, options) {
|
|
|
4071
4181
|
if (isType)
|
|
4072
4182
|
continue;
|
|
4073
4183
|
bindingMetadata[key] =
|
|
4074
|
-
|
|
4184
|
+
imported === '*' ||
|
|
4185
|
+
(imported === 'default' && source.endsWith('.vue')) ||
|
|
4186
|
+
source === 'vue'
|
|
4075
4187
|
? "setup-const" /* SETUP_CONST */
|
|
4076
4188
|
: "setup-maybe-ref" /* SETUP_MAYBE_REF */;
|
|
4077
4189
|
}
|
|
@@ -4088,7 +4200,9 @@ function compileScript(sfc, options) {
|
|
|
4088
4200
|
}
|
|
4089
4201
|
}
|
|
4090
4202
|
// 8. inject `useCssVars` calls
|
|
4091
|
-
if (cssVars.length
|
|
4203
|
+
if (cssVars.length &&
|
|
4204
|
+
// no need to do this when targeting SSR
|
|
4205
|
+
!(options.inlineTemplate && options.templateOptions?.ssr)) {
|
|
4092
4206
|
helperImports.add(CSS_VARS_HELPER);
|
|
4093
4207
|
helperImports.add('unref');
|
|
4094
4208
|
s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
|
|
@@ -4127,16 +4241,45 @@ function compileScript(sfc, options) {
|
|
|
4127
4241
|
}
|
|
4128
4242
|
// 10. generate return statement
|
|
4129
4243
|
let returned;
|
|
4130
|
-
if (options.inlineTemplate) {
|
|
4244
|
+
if (!options.inlineTemplate || (!sfc.template && hasDefaultExportRender)) {
|
|
4245
|
+
// non-inline mode, or has manual render in normal <script>
|
|
4246
|
+
// return bindings from script and script setup
|
|
4247
|
+
const allBindings = {
|
|
4248
|
+
...scriptBindings,
|
|
4249
|
+
...setupBindings
|
|
4250
|
+
};
|
|
4251
|
+
for (const key in userImports) {
|
|
4252
|
+
if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
|
|
4253
|
+
allBindings[key] = true;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
returned = `{ ${Object.keys(allBindings).join(', ')} }`;
|
|
4257
|
+
}
|
|
4258
|
+
else {
|
|
4259
|
+
// inline mode
|
|
4131
4260
|
if (sfc.template && !sfc.template.src) {
|
|
4132
4261
|
if (options.templateOptions && options.templateOptions.ssr) {
|
|
4133
4262
|
hasInlinedSsrRenderFn = true;
|
|
4134
4263
|
}
|
|
4135
4264
|
// inline render function mode - we are going to compile the template and
|
|
4136
4265
|
// inline it right here
|
|
4137
|
-
const { code, ast, preamble, tips, errors } = compileTemplate(
|
|
4138
|
-
|
|
4139
|
-
|
|
4266
|
+
const { code, ast, preamble, tips, errors } = compileTemplate({
|
|
4267
|
+
filename,
|
|
4268
|
+
source: sfc.template.content,
|
|
4269
|
+
inMap: sfc.template.map,
|
|
4270
|
+
...options.templateOptions,
|
|
4271
|
+
id: scopeId,
|
|
4272
|
+
scoped: sfc.styles.some(s => s.scoped),
|
|
4273
|
+
isProd: options.isProd,
|
|
4274
|
+
ssrCssVars: sfc.cssVars,
|
|
4275
|
+
compilerOptions: {
|
|
4276
|
+
...(options.templateOptions &&
|
|
4277
|
+
options.templateOptions.compilerOptions),
|
|
4278
|
+
inline: true,
|
|
4279
|
+
isTS,
|
|
4280
|
+
bindingMetadata
|
|
4281
|
+
}
|
|
4282
|
+
});
|
|
4140
4283
|
if (tips.length) {
|
|
4141
4284
|
tips.forEach(warnOnce);
|
|
4142
4285
|
}
|
|
@@ -4170,16 +4313,6 @@ function compileScript(sfc, options) {
|
|
|
4170
4313
|
returned = `() => {}`;
|
|
4171
4314
|
}
|
|
4172
4315
|
}
|
|
4173
|
-
else {
|
|
4174
|
-
// return bindings from script and script setup
|
|
4175
|
-
const allBindings = Object.assign(Object.assign({}, scriptBindings), setupBindings);
|
|
4176
|
-
for (const key in userImports) {
|
|
4177
|
-
if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
|
|
4178
|
-
allBindings[key] = true;
|
|
4179
|
-
}
|
|
4180
|
-
}
|
|
4181
|
-
returned = `{ ${Object.keys(allBindings).join(', ')} }`;
|
|
4182
|
-
}
|
|
4183
4316
|
if (!options.inlineTemplate && !false) {
|
|
4184
4317
|
// in non-inline mode, the `__isScriptSetup: true` flag is used by
|
|
4185
4318
|
// componentPublicInstance proxy to allow properties that start with $ or _
|
|
@@ -4193,6 +4326,12 @@ function compileScript(sfc, options) {
|
|
|
4193
4326
|
}
|
|
4194
4327
|
// 11. finalize default export
|
|
4195
4328
|
let runtimeOptions = ``;
|
|
4329
|
+
if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
|
|
4330
|
+
const match = filename.match(/([^/\\]+)\.\w+$/);
|
|
4331
|
+
if (match) {
|
|
4332
|
+
runtimeOptions += `\n name: '${match[1]}',`;
|
|
4333
|
+
}
|
|
4334
|
+
}
|
|
4196
4335
|
if (hasInlinedSsrRenderFn) {
|
|
4197
4336
|
runtimeOptions += `\n __ssrInlineRender: true,`;
|
|
4198
4337
|
}
|
|
@@ -4259,13 +4398,21 @@ function compileScript(sfc, options) {
|
|
|
4259
4398
|
.join(', ')} } from 'vue'\n`);
|
|
4260
4399
|
}
|
|
4261
4400
|
s.trim();
|
|
4262
|
-
return
|
|
4401
|
+
return {
|
|
4402
|
+
...scriptSetup,
|
|
4403
|
+
bindings: bindingMetadata,
|
|
4404
|
+
imports: userImports,
|
|
4405
|
+
content: s.toString(),
|
|
4406
|
+
map: genSourceMap
|
|
4263
4407
|
? s.generateMap({
|
|
4264
4408
|
source: filename,
|
|
4265
4409
|
hires: true,
|
|
4266
4410
|
includeContent: true
|
|
4267
4411
|
})
|
|
4268
|
-
: undefined,
|
|
4412
|
+
: undefined,
|
|
4413
|
+
scriptAst: scriptAst?.body,
|
|
4414
|
+
scriptSetupAst: scriptSetupAst?.body
|
|
4415
|
+
};
|
|
4269
4416
|
}
|
|
4270
4417
|
function registerBinding(bindings, node, type) {
|
|
4271
4418
|
bindings[node.name] = type;
|
|
@@ -4282,14 +4429,18 @@ function walkDeclaration(node, bindings, userImportAlias) {
|
|
|
4282
4429
|
const userReactiveBinding = userImportAlias['reactive'] || 'reactive';
|
|
4283
4430
|
if (isCallOf(init, userReactiveBinding)) {
|
|
4284
4431
|
// treat reactive() calls as let since it's meant to be mutable
|
|
4285
|
-
bindingType =
|
|
4432
|
+
bindingType = isConst
|
|
4433
|
+
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
4434
|
+
: "setup-let" /* SETUP_LET */;
|
|
4286
4435
|
}
|
|
4287
4436
|
else if (
|
|
4288
4437
|
// if a declaration is a const literal, we can mark it so that
|
|
4289
4438
|
// the generated render fn code doesn't need to unref() it
|
|
4290
4439
|
isDefineCall ||
|
|
4291
4440
|
(isConst && canNeverBeRef(init, userReactiveBinding))) {
|
|
4292
|
-
bindingType =
|
|
4441
|
+
bindingType = isCallOf(init, DEFINE_PROPS)
|
|
4442
|
+
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
4443
|
+
: "setup-const" /* SETUP_CONST */;
|
|
4293
4444
|
}
|
|
4294
4445
|
else if (isConst) {
|
|
4295
4446
|
if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
|
|
@@ -4702,13 +4853,13 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
4702
4853
|
code += `,v${shared.capitalize(shared.camelize(prop.name))}`;
|
|
4703
4854
|
}
|
|
4704
4855
|
if (prop.exp) {
|
|
4705
|
-
code += `,${
|
|
4856
|
+
code += `,${processExp(prop.exp.content)}`;
|
|
4706
4857
|
}
|
|
4707
4858
|
}
|
|
4708
4859
|
}
|
|
4709
4860
|
}
|
|
4710
4861
|
else if (node.type === 5 /* INTERPOLATION */) {
|
|
4711
|
-
code += `,${
|
|
4862
|
+
code += `,${processExp(node.content.content)}`;
|
|
4712
4863
|
}
|
|
4713
4864
|
}
|
|
4714
4865
|
]
|
|
@@ -4717,6 +4868,18 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
4717
4868
|
templateUsageCheckCache.set(content, code);
|
|
4718
4869
|
return code;
|
|
4719
4870
|
}
|
|
4871
|
+
function processExp(exp) {
|
|
4872
|
+
if (/ as \w|<.*>/.test(exp)) {
|
|
4873
|
+
let ret = '';
|
|
4874
|
+
// has potential type cast or generic arguments that uses types
|
|
4875
|
+
const ast = parser$2.parseExpression(exp, { plugins: ['typescript'] });
|
|
4876
|
+
CompilerDOM.walkIdentifiers(ast, node => {
|
|
4877
|
+
ret += `,` + node.name;
|
|
4878
|
+
});
|
|
4879
|
+
return ret;
|
|
4880
|
+
}
|
|
4881
|
+
return stripStrings(exp);
|
|
4882
|
+
}
|
|
4720
4883
|
function stripStrings(exp) {
|
|
4721
4884
|
return exp
|
|
4722
4885
|
.replace(/'[^']*'|"[^"]*"/g, '')
|
|
@@ -4757,8 +4920,9 @@ function hmrShouldReload(prevImports, next) {
|
|
|
4757
4920
|
return false;
|
|
4758
4921
|
}
|
|
4759
4922
|
|
|
4923
|
+
const DEFAULT_FILENAME = 'anonymous.vue';
|
|
4760
4924
|
const sourceToSFC = createCache();
|
|
4761
|
-
function parse(source, { sourceMap = true, filename =
|
|
4925
|
+
function parse(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM__namespace } = {}) {
|
|
4762
4926
|
const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
|
|
4763
4927
|
const cache = sourceToSFC.get(sourceKey);
|
|
4764
4928
|
if (cache) {
|
|
@@ -4917,7 +5081,7 @@ function createBlock(node, source, pad) {
|
|
|
4917
5081
|
offset: start.offset + offset
|
|
4918
5082
|
};
|
|
4919
5083
|
}
|
|
4920
|
-
end =
|
|
5084
|
+
end = { ...start };
|
|
4921
5085
|
}
|
|
4922
5086
|
const loc = {
|
|
4923
5087
|
source: content,
|
|
@@ -9387,7 +9551,13 @@ function merge$1(oldMap, newMap) {
|
|
|
9387
9551
|
// .scss/.sass processor
|
|
9388
9552
|
const scss = (source, map, options, load = require) => {
|
|
9389
9553
|
const nodeSass = load('sass');
|
|
9390
|
-
const finalOptions =
|
|
9554
|
+
const finalOptions = {
|
|
9555
|
+
...options,
|
|
9556
|
+
data: getSource(source, options.filename, options.additionalData),
|
|
9557
|
+
file: options.filename,
|
|
9558
|
+
outFile: options.filename,
|
|
9559
|
+
sourceMap: !!map
|
|
9560
|
+
};
|
|
9391
9561
|
try {
|
|
9392
9562
|
const result = nodeSass.renderSync(finalOptions);
|
|
9393
9563
|
const dependencies = result.stats.includedFiles;
|
|
@@ -9405,13 +9575,16 @@ const scss = (source, map, options, load = require) => {
|
|
|
9405
9575
|
return { code: '', errors: [e], dependencies: [] };
|
|
9406
9576
|
}
|
|
9407
9577
|
};
|
|
9408
|
-
const sass = (source, map, options, load) => scss(source, map,
|
|
9578
|
+
const sass = (source, map, options, load) => scss(source, map, {
|
|
9579
|
+
...options,
|
|
9580
|
+
indentedSyntax: true
|
|
9581
|
+
}, load);
|
|
9409
9582
|
// .less
|
|
9410
9583
|
const less = (source, map, options, load = require) => {
|
|
9411
9584
|
const nodeLess = load('less');
|
|
9412
9585
|
let result;
|
|
9413
9586
|
let error = null;
|
|
9414
|
-
nodeLess.render(getSource(source, options.filename, options.additionalData),
|
|
9587
|
+
nodeLess.render(getSource(source, options.filename, options.additionalData), { ...options, syncImport: true }, (err, output) => {
|
|
9415
9588
|
error = err;
|
|
9416
9589
|
result = output;
|
|
9417
9590
|
});
|
|
@@ -17178,10 +17351,16 @@ var postcss$3 = true;
|
|
|
17178
17351
|
build.postcss = postcss$3;
|
|
17179
17352
|
|
|
17180
17353
|
function compileStyle(options) {
|
|
17181
|
-
return doCompileStyle(
|
|
17354
|
+
return doCompileStyle({
|
|
17355
|
+
...options,
|
|
17356
|
+
isAsync: false
|
|
17357
|
+
});
|
|
17182
17358
|
}
|
|
17183
17359
|
function compileStyleAsync(options) {
|
|
17184
|
-
return doCompileStyle(
|
|
17360
|
+
return doCompileStyle({
|
|
17361
|
+
...options,
|
|
17362
|
+
isAsync: true
|
|
17363
|
+
});
|
|
17185
17364
|
}
|
|
17186
17365
|
function doCompileStyle(options) {
|
|
17187
17366
|
const { filename, id, scoped = false, trim = true, isProd = false, modules = false, modulesOptions = {}, preprocessLang, postcssOptions, postcssPlugins } = options;
|
|
@@ -17206,11 +17385,18 @@ function doCompileStyle(options) {
|
|
|
17206
17385
|
if (!options.isAsync) {
|
|
17207
17386
|
throw new Error('[@vue/compiler-sfc] `modules` option can only be used with compileStyleAsync().');
|
|
17208
17387
|
}
|
|
17209
|
-
plugins.push(build(
|
|
17388
|
+
plugins.push(build({
|
|
17389
|
+
...modulesOptions,
|
|
17390
|
+
getJSON: (_cssFileName, json) => {
|
|
17210
17391
|
cssModules = json;
|
|
17211
|
-
}
|
|
17392
|
+
}
|
|
17393
|
+
}));
|
|
17212
17394
|
}
|
|
17213
|
-
const postCSSOptions =
|
|
17395
|
+
const postCSSOptions = {
|
|
17396
|
+
...postcssOptions,
|
|
17397
|
+
to: filename,
|
|
17398
|
+
from: filename
|
|
17399
|
+
};
|
|
17214
17400
|
if (map) {
|
|
17215
17401
|
postCSSOptions.map = {
|
|
17216
17402
|
inline: false,
|
|
@@ -17276,7 +17462,10 @@ function doCompileStyle(options) {
|
|
|
17276
17462
|
};
|
|
17277
17463
|
}
|
|
17278
17464
|
function preprocess$1(options, preprocessor) {
|
|
17279
|
-
return preprocessor(options.source, options.inMap || options.map,
|
|
17465
|
+
return preprocessor(options.source, options.inMap || options.map, {
|
|
17466
|
+
filename: options.filename,
|
|
17467
|
+
...options.preprocessOptions
|
|
17468
|
+
}, options.preprocessCustomRequire);
|
|
17280
17469
|
}
|
|
17281
17470
|
|
|
17282
17471
|
// API
|