@vue/compiler-sfc 3.2.33 → 3.2.35

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.
@@ -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 noramlizeExpression(exp) {
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 = noramlizeExpression(match[1]);
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, noramlizeExpression($1), isProd)})`;
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 Object.assign(Object.assign({}, defaultAssetUrlOptions), { tags: options });
1014
+ return {
1015
+ ...defaultAssetUrlOptions,
1016
+ tags: options
1017
+ };
1015
1018
  }
1016
- return Object.assign(Object.assign({}, defaultAssetUrlOptions), options);
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(compilerCore.createSimpleExpression(hashExp, false, loc, 3 /* CAN_STRINGIFY */));
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 hasQualifiedUrl = imageCandidates.some(({ url }) => {
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 (!hasQualifiedUrl) {
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
- imageCandidates.forEach(({ url, descriptor }) => {
1178
+ let needImportTransform = false;
1179
+ imageCandidates.forEach(candidate => {
1180
+ let { url, descriptor } = candidate;
1169
1181
  descriptor = descriptor ? ` ${descriptor}` : ``;
1170
- if (isRelativeUrl(url)) {
1171
- set.push((path__default.posix || path__default).join(base, url) + descriptor);
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
- attr.value.content = set.join(', ');
1178
- return;
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 (!isExternalUrl(url) &&
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
- const hoisted = context.hoist(compoundExpression);
1215
- hoisted.constType = 3 /* CAN_STRINGIFY */;
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: hoisted,
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, Object.assign({ filename }, preprocessOptions), (_err, _res) => {
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(Object.assign(Object.assign({}, options), { source: preprocess(options, preprocessor) }));
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, Object.assign(Object.assign({ mode: 'module', prefixIdentifiers: true, hoistStatic: true, cacheHandlers: true, ssrCssVars: ssr && ssrCssVars && ssrCssVars.length
3145
- ? genCssVarsFromList(ssrCssVars, shortId, isProd)
3146
- : '', scopeId: scoped ? longId : undefined, slotted, sourceMap: true }, compilerOptions), { nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []), filename, onError: e => errors.push(e), onWarn: w => warnings.push(w) }));
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.
@@ -3228,7 +3264,7 @@ function patchErrors(errors, source, inMap) {
3228
3264
  }
3229
3265
 
3230
3266
  const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/;
3231
- const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s;
3267
+ const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)(?:as)?(\s*)default/s;
3232
3268
  const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/;
3233
3269
  /**
3234
3270
  * Utility for rewriting `export default` in a script block into a variable
@@ -3259,25 +3295,61 @@ function rewriteDefault(input, as, parserPlugins) {
3259
3295
  plugins: parserPlugins
3260
3296
  }).program.body;
3261
3297
  ast.forEach(node => {
3298
+ var _a;
3262
3299
  if (node.type === 'ExportDefaultDeclaration') {
3263
3300
  s.overwrite(node.start, node.declaration.start, `const ${as} = `);
3264
3301
  }
3265
3302
  if (node.type === 'ExportNamedDeclaration') {
3266
- node.specifiers.forEach(specifier => {
3303
+ for (const specifier of node.specifiers) {
3267
3304
  if (specifier.type === 'ExportSpecifier' &&
3268
3305
  specifier.exported.type === 'Identifier' &&
3269
3306
  specifier.exported.name === 'default') {
3270
- const end = specifier.end;
3271
- s.overwrite(specifier.start, input.charAt(end) === ',' ? end + 1 : end, ``);
3307
+ if (node.source) {
3308
+ if (specifier.local.name === 'default') {
3309
+ const end = specifierEnd(input, specifier.local.end, node.end);
3310
+ s.prepend(`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`);
3311
+ s.overwrite(specifier.start, end, ``);
3312
+ s.append(`\nconst ${as} = __VUE_DEFAULT__`);
3313
+ continue;
3314
+ }
3315
+ else {
3316
+ const end = specifierEnd(input, specifier.exported.end, node.end);
3317
+ s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${(_a = node.source) === null || _a === void 0 ? void 0 : _a.value}'\n`);
3318
+ s.overwrite(specifier.start, end, ``);
3319
+ s.append(`\nconst ${as} = ${specifier.local.name}`);
3320
+ continue;
3321
+ }
3322
+ }
3323
+ const end = specifierEnd(input, specifier.end, node.end);
3324
+ s.overwrite(specifier.start, end, ``);
3272
3325
  s.append(`\nconst ${as} = ${specifier.local.name}`);
3273
3326
  }
3274
- });
3327
+ }
3275
3328
  }
3276
3329
  });
3277
3330
  return s.toString();
3278
3331
  }
3279
3332
  function hasDefaultExport(input) {
3280
3333
  return defaultExportRE.test(input) || namedDefaultExportRE.test(input);
3334
+ }
3335
+ function specifierEnd(input, end, nodeEnd) {
3336
+ // export { default , foo } ...
3337
+ let hasCommas = false;
3338
+ let oldEnd = end;
3339
+ while (end < nodeEnd) {
3340
+ if (/\s/.test(input.charAt(end))) {
3341
+ end++;
3342
+ }
3343
+ else if (input.charAt(end) === ',') {
3344
+ end++;
3345
+ hasCommas = true;
3346
+ break;
3347
+ }
3348
+ else if (input.charAt(end) === '}') {
3349
+ break;
3350
+ }
3351
+ }
3352
+ return hasCommas ? end : oldEnd;
3281
3353
  }
3282
3354
 
3283
3355
  // Special compiler macros
@@ -3287,13 +3359,14 @@ const DEFINE_EXPOSE = 'defineExpose';
3287
3359
  const WITH_DEFAULTS = 'withDefaults';
3288
3360
  // constants
3289
3361
  const DEFAULT_VAR = `__default__`;
3290
- const isBuiltInDir = shared.makeMap(`once,memo,if,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
3362
+ const isBuiltInDir = shared.makeMap(`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`);
3291
3363
  /**
3292
3364
  * Compile `<script setup>`
3293
3365
  * It requires the whole SFC descriptor because we need to handle and merge
3294
3366
  * normal `<script>` + `<script setup>` if both are present.
3295
3367
  */
3296
3368
  function compileScript(sfc, options) {
3369
+ var _a;
3297
3370
  let { script, scriptSetup, source, filename } = sfc;
3298
3371
  // feature flags
3299
3372
  // TODO remove support for deprecated options when out of experimental
@@ -3322,6 +3395,11 @@ function compileScript(sfc, options) {
3322
3395
  if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') {
3323
3396
  plugins.push('jsx');
3324
3397
  }
3398
+ else {
3399
+ // If don't match the case of adding jsx, should remove the jsx from the babelParserPlugins
3400
+ if (options.babelParserPlugins)
3401
+ options.babelParserPlugins = options.babelParserPlugins.filter(n => n !== 'jsx');
3402
+ }
3325
3403
  if (options.babelParserPlugins)
3326
3404
  plugins.push(...options.babelParserPlugins);
3327
3405
  if (isTS)
@@ -3368,9 +3446,13 @@ function compileScript(sfc, options) {
3368
3446
  content += genNormalScriptCssVarsCode(cssVars, bindings, scopeId, isProd);
3369
3447
  content += `\nexport default ${DEFAULT_VAR}`;
3370
3448
  }
3371
- return Object.assign(Object.assign({}, script), { content,
3449
+ return {
3450
+ ...script,
3451
+ content,
3372
3452
  map,
3373
- bindings, scriptAst: scriptAst.body });
3453
+ bindings,
3454
+ scriptAst: scriptAst.body
3455
+ };
3374
3456
  }
3375
3457
  catch (e) {
3376
3458
  // silently fallback if parse fails since user may be using custom
@@ -3397,6 +3479,8 @@ function compileScript(sfc, options) {
3397
3479
  let hasDefinePropsCall = false;
3398
3480
  let hasDefineEmitCall = false;
3399
3481
  let hasDefineExposeCall = false;
3482
+ let hasDefaultExportName = false;
3483
+ let hasDefaultExportRender = false;
3400
3484
  let propsRuntimeDecl;
3401
3485
  let propsRuntimeDefaults;
3402
3486
  let propsDestructureDecl;
@@ -3439,12 +3523,18 @@ function compileScript(sfc, options) {
3439
3523
  function error(msg, node, end = node.end + startOffset) {
3440
3524
  throw new Error(`[@vue/compiler-sfc] ${msg}\n\n${sfc.filename}\n${shared.generateCodeFrame(source, node.start + startOffset, end)}`);
3441
3525
  }
3442
- function registerUserImport(source, local, imported, isType, isFromSetup) {
3526
+ function registerUserImport(source, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
3443
3527
  if (source === 'vue' && imported) {
3444
3528
  userImportAlias[imported] = local;
3445
3529
  }
3446
- let isUsedInTemplate = true;
3447
- if (isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
3530
+ // template usage check is only needed in non-inline mode, so we can skip
3531
+ // the work if inlineTemplate is true.
3532
+ let isUsedInTemplate = needTemplateUsageCheck;
3533
+ if (needTemplateUsageCheck &&
3534
+ isTS &&
3535
+ sfc.template &&
3536
+ !sfc.template.src &&
3537
+ !sfc.template.lang) {
3448
3538
  isUsedInTemplate = isImportUsed(local, sfc);
3449
3539
  }
3450
3540
  userImports[local] = {
@@ -3486,7 +3576,9 @@ function compileScript(sfc, options) {
3486
3576
  if (prop.computed) {
3487
3577
  error(`${DEFINE_PROPS}() destructure cannot use computed key.`, prop.key);
3488
3578
  }
3489
- const propKey = prop.key.name;
3579
+ const propKey = prop.key.type === 'StringLiteral'
3580
+ ? prop.key.value
3581
+ : prop.key.name;
3490
3582
  if (prop.value.type === 'AssignmentPattern') {
3491
3583
  // default value { foo = 123 }
3492
3584
  const { left, right } = prop.value;
@@ -3715,7 +3807,7 @@ function compileScript(sfc, options) {
3715
3807
  if (destructured && destructured.default) {
3716
3808
  const value = scriptSetup.content.slice(destructured.default.start, destructured.default.end);
3717
3809
  const isLiteral = destructured.default.type.endsWith('Literal');
3718
- return isLiteral ? value : `() => ${value}`;
3810
+ return isLiteral ? value : `() => (${value})`;
3719
3811
  }
3720
3812
  }
3721
3813
  function genSetupPropsType(node) {
@@ -3765,12 +3857,40 @@ function compileScript(sfc, options) {
3765
3857
  specifier.imported.name;
3766
3858
  registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type' ||
3767
3859
  (specifier.type === 'ImportSpecifier' &&
3768
- specifier.importKind === 'type'), false);
3860
+ specifier.importKind === 'type'), false, !options.inlineTemplate);
3769
3861
  }
3770
3862
  }
3771
3863
  else if (node.type === 'ExportDefaultDeclaration') {
3772
3864
  // export default
3773
3865
  defaultExport = node;
3866
+ // check if user has manually specified `name` or 'render` option in
3867
+ // export default
3868
+ // if has name, skip name inference
3869
+ // if has render and no template, generate return object instead of
3870
+ // empty render function (#4980)
3871
+ let optionProperties;
3872
+ if (defaultExport.declaration.type === 'ObjectExpression') {
3873
+ optionProperties = defaultExport.declaration.properties;
3874
+ }
3875
+ else if (defaultExport.declaration.type === 'CallExpression' &&
3876
+ defaultExport.declaration.arguments[0].type === 'ObjectExpression') {
3877
+ optionProperties = defaultExport.declaration.arguments[0].properties;
3878
+ }
3879
+ if (optionProperties) {
3880
+ for (const s of optionProperties) {
3881
+ if (s.type === 'ObjectProperty' &&
3882
+ s.key.type === 'Identifier' &&
3883
+ s.key.name === 'name') {
3884
+ hasDefaultExportName = true;
3885
+ }
3886
+ if ((s.type === 'ObjectMethod' || s.type === 'ObjectProperty') &&
3887
+ s.key.type === 'Identifier' &&
3888
+ s.key.name === 'render') {
3889
+ // TODO warn when we provide a better way to do it?
3890
+ hasDefaultExportRender = true;
3891
+ }
3892
+ }
3893
+ }
3774
3894
  // export default { ... } --> const __default__ = { ... }
3775
3895
  const start = node.start + scriptStartOffset;
3776
3896
  const end = node.declaration.start + scriptStartOffset;
@@ -3823,6 +3943,10 @@ function compileScript(sfc, options) {
3823
3943
  // we need to move the block up so that `const __default__` is
3824
3944
  // declared before being used in the actual component definition
3825
3945
  if (scriptStartOffset > startOffset) {
3946
+ // if content doesn't end with newline, add one
3947
+ if (!/\n$/.test(script.content.trim())) {
3948
+ s.appendLeft(scriptEndOffset, `\n`);
3949
+ }
3826
3950
  s.move(scriptStartOffset, scriptEndOffset, 0);
3827
3951
  }
3828
3952
  }
@@ -3877,9 +4001,12 @@ function compileScript(sfc, options) {
3877
4001
  for (let i = 0; i < node.specifiers.length; i++) {
3878
4002
  const specifier = node.specifiers[i];
3879
4003
  const local = specifier.local.name;
3880
- const imported = specifier.type === 'ImportSpecifier' &&
4004
+ let imported = specifier.type === 'ImportSpecifier' &&
3881
4005
  specifier.imported.type === 'Identifier' &&
3882
4006
  specifier.imported.name;
4007
+ if (specifier.type === 'ImportNamespaceSpecifier') {
4008
+ imported = '*';
4009
+ }
3883
4010
  const source = node.source.value;
3884
4011
  const existing = userImports[local];
3885
4012
  if (source === 'vue' &&
@@ -3901,7 +4028,7 @@ function compileScript(sfc, options) {
3901
4028
  else {
3902
4029
  registerUserImport(source, local, imported, node.importKind === 'type' ||
3903
4030
  (specifier.type === 'ImportSpecifier' &&
3904
- specifier.importKind === 'type'), true);
4031
+ specifier.importKind === 'type'), true, !options.inlineTemplate);
3905
4032
  }
3906
4033
  }
3907
4034
  if (node.specifiers.length && removed === node.specifiers.length) {
@@ -3964,18 +4091,33 @@ function compileScript(sfc, options) {
3964
4091
  // await
3965
4092
  if ((node.type === 'VariableDeclaration' && !node.declare) ||
3966
4093
  node.type.endsWith('Statement')) {
4094
+ const scope = [scriptSetupAst.body];
3967
4095
  estreeWalker.walk(node, {
3968
4096
  enter(child, parent) {
3969
4097
  if (CompilerDOM.isFunctionType(child)) {
3970
4098
  this.skip();
3971
4099
  }
4100
+ if (child.type === 'BlockStatement') {
4101
+ scope.push(child.body);
4102
+ }
3972
4103
  if (child.type === 'AwaitExpression') {
3973
4104
  hasAwait = true;
3974
- const needsSemi = scriptSetupAst.body.some(n => {
3975
- return n.type === 'ExpressionStatement' && n.start === child.start;
4105
+ // if the await expression is an expression statement and
4106
+ // - is in the root scope
4107
+ // - or is not the first statement in a nested block scope
4108
+ // then it needs a semicolon before the generated code.
4109
+ const currentScope = scope[scope.length - 1];
4110
+ const needsSemi = currentScope.some((n, i) => {
4111
+ return ((scope.length === 1 || i > 0) &&
4112
+ n.type === 'ExpressionStatement' &&
4113
+ n.start === child.start);
3976
4114
  });
3977
4115
  processAwait(child, needsSemi, parent.type === 'ExpressionStatement');
3978
4116
  }
4117
+ },
4118
+ exit(node) {
4119
+ if (node.type === 'BlockStatement')
4120
+ scope.pop();
3979
4121
  }
3980
4122
  });
3981
4123
  }
@@ -4024,7 +4166,7 @@ function compileScript(sfc, options) {
4024
4166
  checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
4025
4167
  checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
4026
4168
  checkInvalidScopeReference(propsDestructureDecl, DEFINE_PROPS);
4027
- checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_PROPS);
4169
+ checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_EMITS);
4028
4170
  // 6. remove non-script content
4029
4171
  if (script) {
4030
4172
  if (startOffset < scriptStartOffset) {
@@ -4060,7 +4202,8 @@ function compileScript(sfc, options) {
4060
4202
  // props aliases
4061
4203
  if (propsDestructureDecl) {
4062
4204
  if (propsDestructureRestId) {
4063
- bindingMetadata[propsDestructureRestId] = "setup-const" /* SETUP_CONST */;
4205
+ bindingMetadata[propsDestructureRestId] =
4206
+ "setup-reactive-const" /* SETUP_REACTIVE_CONST */;
4064
4207
  }
4065
4208
  for (const key in propsDestructuredBindings) {
4066
4209
  const { local } = propsDestructuredBindings[key];
@@ -4075,7 +4218,9 @@ function compileScript(sfc, options) {
4075
4218
  if (isType)
4076
4219
  continue;
4077
4220
  bindingMetadata[key] =
4078
- (imported === 'default' && source.endsWith('.vue')) || source === 'vue'
4221
+ imported === '*' ||
4222
+ (imported === 'default' && source.endsWith('.vue')) ||
4223
+ source === 'vue'
4079
4224
  ? "setup-const" /* SETUP_CONST */
4080
4225
  : "setup-maybe-ref" /* SETUP_MAYBE_REF */;
4081
4226
  }
@@ -4092,7 +4237,9 @@ function compileScript(sfc, options) {
4092
4237
  }
4093
4238
  }
4094
4239
  // 8. inject `useCssVars` calls
4095
- if (cssVars.length) {
4240
+ if (cssVars.length &&
4241
+ // no need to do this when targeting SSR
4242
+ !(options.inlineTemplate && ((_a = options.templateOptions) === null || _a === void 0 ? void 0 : _a.ssr))) {
4096
4243
  helperImports.add(CSS_VARS_HELPER);
4097
4244
  helperImports.add('unref');
4098
4245
  s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
@@ -4131,16 +4278,45 @@ function compileScript(sfc, options) {
4131
4278
  }
4132
4279
  // 10. generate return statement
4133
4280
  let returned;
4134
- if (options.inlineTemplate) {
4281
+ if (!options.inlineTemplate || (!sfc.template && hasDefaultExportRender)) {
4282
+ // non-inline mode, or has manual render in normal <script>
4283
+ // return bindings from script and script setup
4284
+ const allBindings = {
4285
+ ...scriptBindings,
4286
+ ...setupBindings
4287
+ };
4288
+ for (const key in userImports) {
4289
+ if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
4290
+ allBindings[key] = true;
4291
+ }
4292
+ }
4293
+ returned = `{ ${Object.keys(allBindings).join(', ')} }`;
4294
+ }
4295
+ else {
4296
+ // inline mode
4135
4297
  if (sfc.template && !sfc.template.src) {
4136
4298
  if (options.templateOptions && options.templateOptions.ssr) {
4137
4299
  hasInlinedSsrRenderFn = true;
4138
4300
  }
4139
4301
  // inline render function mode - we are going to compile the template and
4140
4302
  // inline it right here
4141
- const { code, ast, preamble, tips, errors } = compileTemplate(Object.assign(Object.assign({ filename, source: sfc.template.content, inMap: sfc.template.map }, options.templateOptions), { id: scopeId, scoped: sfc.styles.some(s => s.scoped), isProd: options.isProd, ssrCssVars: sfc.cssVars, compilerOptions: Object.assign(Object.assign({}, (options.templateOptions &&
4142
- options.templateOptions.compilerOptions)), { inline: true, isTS,
4143
- bindingMetadata }) }));
4303
+ const { code, ast, preamble, tips, errors } = compileTemplate({
4304
+ filename,
4305
+ source: sfc.template.content,
4306
+ inMap: sfc.template.map,
4307
+ ...options.templateOptions,
4308
+ id: scopeId,
4309
+ scoped: sfc.styles.some(s => s.scoped),
4310
+ isProd: options.isProd,
4311
+ ssrCssVars: sfc.cssVars,
4312
+ compilerOptions: {
4313
+ ...(options.templateOptions &&
4314
+ options.templateOptions.compilerOptions),
4315
+ inline: true,
4316
+ isTS,
4317
+ bindingMetadata
4318
+ }
4319
+ });
4144
4320
  if (tips.length) {
4145
4321
  tips.forEach(warnOnce);
4146
4322
  }
@@ -4174,16 +4350,6 @@ function compileScript(sfc, options) {
4174
4350
  returned = `() => {}`;
4175
4351
  }
4176
4352
  }
4177
- else {
4178
- // return bindings from script and script setup
4179
- const allBindings = Object.assign(Object.assign({}, scriptBindings), setupBindings);
4180
- for (const key in userImports) {
4181
- if (!userImports[key].isType && userImports[key].isUsedInTemplate) {
4182
- allBindings[key] = true;
4183
- }
4184
- }
4185
- returned = `{ ${Object.keys(allBindings).join(', ')} }`;
4186
- }
4187
4353
  if (!options.inlineTemplate && !false) {
4188
4354
  // in non-inline mode, the `__isScriptSetup: true` flag is used by
4189
4355
  // componentPublicInstance proxy to allow properties that start with $ or _
@@ -4197,6 +4363,12 @@ function compileScript(sfc, options) {
4197
4363
  }
4198
4364
  // 11. finalize default export
4199
4365
  let runtimeOptions = ``;
4366
+ if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
4367
+ const match = filename.match(/([^/\\]+)\.\w+$/);
4368
+ if (match) {
4369
+ runtimeOptions += `\n name: '${match[1]}',`;
4370
+ }
4371
+ }
4200
4372
  if (hasInlinedSsrRenderFn) {
4201
4373
  runtimeOptions += `\n __ssrInlineRender: true,`;
4202
4374
  }
@@ -4263,13 +4435,21 @@ function compileScript(sfc, options) {
4263
4435
  .join(', ')} } from 'vue'\n`);
4264
4436
  }
4265
4437
  s.trim();
4266
- return Object.assign(Object.assign({}, scriptSetup), { bindings: bindingMetadata, imports: userImports, content: s.toString(), map: genSourceMap
4438
+ return {
4439
+ ...scriptSetup,
4440
+ bindings: bindingMetadata,
4441
+ imports: userImports,
4442
+ content: s.toString(),
4443
+ map: genSourceMap
4267
4444
  ? s.generateMap({
4268
4445
  source: filename,
4269
4446
  hires: true,
4270
4447
  includeContent: true
4271
4448
  })
4272
- : undefined, scriptAst: scriptAst === null || scriptAst === void 0 ? void 0 : scriptAst.body, scriptSetupAst: scriptSetupAst === null || scriptSetupAst === void 0 ? void 0 : scriptSetupAst.body });
4449
+ : undefined,
4450
+ scriptAst: scriptAst === null || scriptAst === void 0 ? void 0 : scriptAst.body,
4451
+ scriptSetupAst: scriptSetupAst === null || scriptSetupAst === void 0 ? void 0 : scriptSetupAst.body
4452
+ };
4273
4453
  }
4274
4454
  function registerBinding(bindings, node, type) {
4275
4455
  bindings[node.name] = type;
@@ -4286,14 +4466,18 @@ function walkDeclaration(node, bindings, userImportAlias) {
4286
4466
  const userReactiveBinding = userImportAlias['reactive'] || 'reactive';
4287
4467
  if (isCallOf(init, userReactiveBinding)) {
4288
4468
  // treat reactive() calls as let since it's meant to be mutable
4289
- bindingType = "setup-let" /* SETUP_LET */;
4469
+ bindingType = isConst
4470
+ ? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
4471
+ : "setup-let" /* SETUP_LET */;
4290
4472
  }
4291
4473
  else if (
4292
4474
  // if a declaration is a const literal, we can mark it so that
4293
4475
  // the generated render fn code doesn't need to unref() it
4294
4476
  isDefineCall ||
4295
4477
  (isConst && canNeverBeRef(init, userReactiveBinding))) {
4296
- bindingType = "setup-const" /* SETUP_CONST */;
4478
+ bindingType = isCallOf(init, DEFINE_PROPS)
4479
+ ? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
4480
+ : "setup-const" /* SETUP_CONST */;
4297
4481
  }
4298
4482
  else if (isConst) {
4299
4483
  if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
@@ -4469,6 +4653,7 @@ function inferRuntimeType(node, declaredTypes) {
4469
4653
  case 'WeakSet':
4470
4654
  case 'WeakMap':
4471
4655
  case 'Date':
4656
+ case 'Promise':
4472
4657
  return [node.typeName.name];
4473
4658
  case 'Record':
4474
4659
  case 'Partial':
@@ -4706,13 +4891,13 @@ function resolveTemplateUsageCheckString(sfc) {
4706
4891
  code += `,v${shared.capitalize(shared.camelize(prop.name))}`;
4707
4892
  }
4708
4893
  if (prop.exp) {
4709
- code += `,${stripStrings(prop.exp.content)}`;
4894
+ code += `,${processExp(prop.exp.content, prop.name)}`;
4710
4895
  }
4711
4896
  }
4712
4897
  }
4713
4898
  }
4714
4899
  else if (node.type === 5 /* INTERPOLATION */) {
4715
- code += `,${stripStrings(node.content.content)}`;
4900
+ code += `,${processExp(node.content.content)}`;
4716
4901
  }
4717
4902
  }
4718
4903
  ]
@@ -4721,6 +4906,29 @@ function resolveTemplateUsageCheckString(sfc) {
4721
4906
  templateUsageCheckCache.set(content, code);
4722
4907
  return code;
4723
4908
  }
4909
+ const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
4910
+ function processExp(exp, dir) {
4911
+ if (/ as\s+\w|<.*>|:/.test(exp)) {
4912
+ if (dir === 'slot') {
4913
+ exp = `(${exp})=>{}`;
4914
+ }
4915
+ else if (dir === 'for') {
4916
+ const inMatch = exp.match(forAliasRE);
4917
+ if (inMatch) {
4918
+ const [, LHS, RHS] = inMatch;
4919
+ return processExp(`(${LHS})=>{}`) + processExp(RHS);
4920
+ }
4921
+ }
4922
+ let ret = '';
4923
+ // has potential type cast or generic arguments that uses types
4924
+ const ast = parser$2.parseExpression(exp, { plugins: ['typescript'] });
4925
+ CompilerDOM.walkIdentifiers(ast, node => {
4926
+ ret += `,` + node.name;
4927
+ });
4928
+ return ret;
4929
+ }
4930
+ return stripStrings(exp);
4931
+ }
4724
4932
  function stripStrings(exp) {
4725
4933
  return exp
4726
4934
  .replace(/'[^']*'|"[^"]*"/g, '')
@@ -4761,8 +4969,9 @@ function hmrShouldReload(prevImports, next) {
4761
4969
  return false;
4762
4970
  }
4763
4971
 
4972
+ const DEFAULT_FILENAME = 'anonymous.vue';
4764
4973
  const sourceToSFC = createCache();
4765
- function parse(source, { sourceMap = true, filename = 'anonymous.vue', sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM__namespace } = {}) {
4974
+ function parse(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM__namespace } = {}) {
4766
4975
  const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
4767
4976
  const cache = sourceToSFC.get(sourceKey);
4768
4977
  if (cache) {
@@ -4921,7 +5130,7 @@ function createBlock(node, source, pad) {
4921
5130
  offset: start.offset + offset
4922
5131
  };
4923
5132
  }
4924
- end = Object.assign({}, start);
5133
+ end = { ...start };
4925
5134
  }
4926
5135
  const loc = {
4927
5136
  source: content,
@@ -9391,7 +9600,13 @@ function merge$1(oldMap, newMap) {
9391
9600
  // .scss/.sass processor
9392
9601
  const scss = (source, map, options, load = require) => {
9393
9602
  const nodeSass = load('sass');
9394
- const finalOptions = Object.assign(Object.assign({}, options), { data: getSource(source, options.filename, options.additionalData), file: options.filename, outFile: options.filename, sourceMap: !!map });
9603
+ const finalOptions = {
9604
+ ...options,
9605
+ data: getSource(source, options.filename, options.additionalData),
9606
+ file: options.filename,
9607
+ outFile: options.filename,
9608
+ sourceMap: !!map
9609
+ };
9395
9610
  try {
9396
9611
  const result = nodeSass.renderSync(finalOptions);
9397
9612
  const dependencies = result.stats.includedFiles;
@@ -9409,13 +9624,16 @@ const scss = (source, map, options, load = require) => {
9409
9624
  return { code: '', errors: [e], dependencies: [] };
9410
9625
  }
9411
9626
  };
9412
- const sass = (source, map, options, load) => scss(source, map, Object.assign(Object.assign({}, options), { indentedSyntax: true }), load);
9627
+ const sass = (source, map, options, load) => scss(source, map, {
9628
+ ...options,
9629
+ indentedSyntax: true
9630
+ }, load);
9413
9631
  // .less
9414
9632
  const less = (source, map, options, load = require) => {
9415
9633
  const nodeLess = load('less');
9416
9634
  let result;
9417
9635
  let error = null;
9418
- nodeLess.render(getSource(source, options.filename, options.additionalData), Object.assign(Object.assign({}, options), { syncImport: true }), (err, output) => {
9636
+ nodeLess.render(getSource(source, options.filename, options.additionalData), { ...options, syncImport: true }, (err, output) => {
9419
9637
  error = err;
9420
9638
  result = output;
9421
9639
  });
@@ -17182,10 +17400,16 @@ var postcss$3 = true;
17182
17400
  build.postcss = postcss$3;
17183
17401
 
17184
17402
  function compileStyle(options) {
17185
- return doCompileStyle(Object.assign(Object.assign({}, options), { isAsync: false }));
17403
+ return doCompileStyle({
17404
+ ...options,
17405
+ isAsync: false
17406
+ });
17186
17407
  }
17187
17408
  function compileStyleAsync(options) {
17188
- return doCompileStyle(Object.assign(Object.assign({}, options), { isAsync: true }));
17409
+ return doCompileStyle({
17410
+ ...options,
17411
+ isAsync: true
17412
+ });
17189
17413
  }
17190
17414
  function doCompileStyle(options) {
17191
17415
  const { filename, id, scoped = false, trim = true, isProd = false, modules = false, modulesOptions = {}, preprocessLang, postcssOptions, postcssPlugins } = options;
@@ -17210,11 +17434,18 @@ function doCompileStyle(options) {
17210
17434
  if (!options.isAsync) {
17211
17435
  throw new Error('[@vue/compiler-sfc] `modules` option can only be used with compileStyleAsync().');
17212
17436
  }
17213
- plugins.push(build(Object.assign(Object.assign({}, modulesOptions), { getJSON: (_cssFileName, json) => {
17437
+ plugins.push(build({
17438
+ ...modulesOptions,
17439
+ getJSON: (_cssFileName, json) => {
17214
17440
  cssModules = json;
17215
- } })));
17441
+ }
17442
+ }));
17216
17443
  }
17217
- const postCSSOptions = Object.assign(Object.assign({}, postcssOptions), { to: filename, from: filename });
17444
+ const postCSSOptions = {
17445
+ ...postcssOptions,
17446
+ to: filename,
17447
+ from: filename
17448
+ };
17218
17449
  if (map) {
17219
17450
  postCSSOptions.map = {
17220
17451
  inline: false,
@@ -17280,7 +17511,10 @@ function doCompileStyle(options) {
17280
17511
  };
17281
17512
  }
17282
17513
  function preprocess$1(options, preprocessor) {
17283
- return preprocessor(options.source, options.inMap || options.map, Object.assign({ filename: options.filename }, options.preprocessOptions), options.preprocessCustomRequire);
17514
+ return preprocessor(options.source, options.inMap || options.map, {
17515
+ filename: options.filename,
17516
+ ...options.preprocessOptions
17517
+ }, options.preprocessCustomRequire);
17284
17518
  }
17285
17519
 
17286
17520
  // API