@vue/compiler-sfc 3.2.33 → 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.
@@ -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.
@@ -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 Object.assign(Object.assign({}, script), { content,
3412
+ return {
3413
+ ...script,
3414
+ content,
3372
3415
  map,
3373
- bindings, scriptAst: scriptAst.body });
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
- let isUsedInTemplate = true;
3447
- if (isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
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.name;
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) {
@@ -3765,12 +3820,40 @@ function compileScript(sfc, options) {
3765
3820
  specifier.imported.name;
3766
3821
  registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type' ||
3767
3822
  (specifier.type === 'ImportSpecifier' &&
3768
- specifier.importKind === 'type'), false);
3823
+ specifier.importKind === 'type'), false, !options.inlineTemplate);
3769
3824
  }
3770
3825
  }
3771
3826
  else if (node.type === 'ExportDefaultDeclaration') {
3772
3827
  // export default
3773
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
+ }
3774
3857
  // export default { ... } --> const __default__ = { ... }
3775
3858
  const start = node.start + scriptStartOffset;
3776
3859
  const end = node.declaration.start + scriptStartOffset;
@@ -3823,6 +3906,10 @@ function compileScript(sfc, options) {
3823
3906
  // we need to move the block up so that `const __default__` is
3824
3907
  // declared before being used in the actual component definition
3825
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
+ }
3826
3913
  s.move(scriptStartOffset, scriptEndOffset, 0);
3827
3914
  }
3828
3915
  }
@@ -3877,9 +3964,12 @@ function compileScript(sfc, options) {
3877
3964
  for (let i = 0; i < node.specifiers.length; i++) {
3878
3965
  const specifier = node.specifiers[i];
3879
3966
  const local = specifier.local.name;
3880
- const imported = specifier.type === 'ImportSpecifier' &&
3967
+ let imported = specifier.type === 'ImportSpecifier' &&
3881
3968
  specifier.imported.type === 'Identifier' &&
3882
3969
  specifier.imported.name;
3970
+ if (specifier.type === 'ImportNamespaceSpecifier') {
3971
+ imported = '*';
3972
+ }
3883
3973
  const source = node.source.value;
3884
3974
  const existing = userImports[local];
3885
3975
  if (source === 'vue' &&
@@ -3901,7 +3991,7 @@ function compileScript(sfc, options) {
3901
3991
  else {
3902
3992
  registerUserImport(source, local, imported, node.importKind === 'type' ||
3903
3993
  (specifier.type === 'ImportSpecifier' &&
3904
- specifier.importKind === 'type'), true);
3994
+ specifier.importKind === 'type'), true, !options.inlineTemplate);
3905
3995
  }
3906
3996
  }
3907
3997
  if (node.specifiers.length && removed === node.specifiers.length) {
@@ -3964,18 +4054,33 @@ function compileScript(sfc, options) {
3964
4054
  // await
3965
4055
  if ((node.type === 'VariableDeclaration' && !node.declare) ||
3966
4056
  node.type.endsWith('Statement')) {
4057
+ const scope = [scriptSetupAst.body];
3967
4058
  estreeWalker.walk(node, {
3968
4059
  enter(child, parent) {
3969
4060
  if (CompilerDOM.isFunctionType(child)) {
3970
4061
  this.skip();
3971
4062
  }
4063
+ if (child.type === 'BlockStatement') {
4064
+ scope.push(child.body);
4065
+ }
3972
4066
  if (child.type === 'AwaitExpression') {
3973
4067
  hasAwait = true;
3974
- const needsSemi = scriptSetupAst.body.some(n => {
3975
- return n.type === 'ExpressionStatement' && n.start === child.start;
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);
3976
4077
  });
3977
4078
  processAwait(child, needsSemi, parent.type === 'ExpressionStatement');
3978
4079
  }
4080
+ },
4081
+ exit(node) {
4082
+ if (node.type === 'BlockStatement')
4083
+ scope.pop();
3979
4084
  }
3980
4085
  });
3981
4086
  }
@@ -4024,7 +4129,7 @@ function compileScript(sfc, options) {
4024
4129
  checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
4025
4130
  checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
4026
4131
  checkInvalidScopeReference(propsDestructureDecl, DEFINE_PROPS);
4027
- checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_PROPS);
4132
+ checkInvalidScopeReference(emitsRuntimeDecl, DEFINE_EMITS);
4028
4133
  // 6. remove non-script content
4029
4134
  if (script) {
4030
4135
  if (startOffset < scriptStartOffset) {
@@ -4060,7 +4165,8 @@ function compileScript(sfc, options) {
4060
4165
  // props aliases
4061
4166
  if (propsDestructureDecl) {
4062
4167
  if (propsDestructureRestId) {
4063
- bindingMetadata[propsDestructureRestId] = "setup-const" /* SETUP_CONST */;
4168
+ bindingMetadata[propsDestructureRestId] =
4169
+ "setup-reactive-const" /* SETUP_REACTIVE_CONST */;
4064
4170
  }
4065
4171
  for (const key in propsDestructuredBindings) {
4066
4172
  const { local } = propsDestructuredBindings[key];
@@ -4075,7 +4181,9 @@ function compileScript(sfc, options) {
4075
4181
  if (isType)
4076
4182
  continue;
4077
4183
  bindingMetadata[key] =
4078
- (imported === 'default' && source.endsWith('.vue')) || source === 'vue'
4184
+ imported === '*' ||
4185
+ (imported === 'default' && source.endsWith('.vue')) ||
4186
+ source === 'vue'
4079
4187
  ? "setup-const" /* SETUP_CONST */
4080
4188
  : "setup-maybe-ref" /* SETUP_MAYBE_REF */;
4081
4189
  }
@@ -4092,7 +4200,9 @@ function compileScript(sfc, options) {
4092
4200
  }
4093
4201
  }
4094
4202
  // 8. inject `useCssVars` calls
4095
- if (cssVars.length) {
4203
+ if (cssVars.length &&
4204
+ // no need to do this when targeting SSR
4205
+ !(options.inlineTemplate && options.templateOptions?.ssr)) {
4096
4206
  helperImports.add(CSS_VARS_HELPER);
4097
4207
  helperImports.add('unref');
4098
4208
  s.prependRight(startOffset, `\n${genCssVarsCode(cssVars, bindingMetadata, scopeId, isProd)}\n`);
@@ -4131,16 +4241,45 @@ function compileScript(sfc, options) {
4131
4241
  }
4132
4242
  // 10. generate return statement
4133
4243
  let returned;
4134
- 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
4135
4260
  if (sfc.template && !sfc.template.src) {
4136
4261
  if (options.templateOptions && options.templateOptions.ssr) {
4137
4262
  hasInlinedSsrRenderFn = true;
4138
4263
  }
4139
4264
  // inline render function mode - we are going to compile the template and
4140
4265
  // 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 }) }));
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
+ });
4144
4283
  if (tips.length) {
4145
4284
  tips.forEach(warnOnce);
4146
4285
  }
@@ -4174,16 +4313,6 @@ function compileScript(sfc, options) {
4174
4313
  returned = `() => {}`;
4175
4314
  }
4176
4315
  }
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
4316
  if (!options.inlineTemplate && !false) {
4188
4317
  // in non-inline mode, the `__isScriptSetup: true` flag is used by
4189
4318
  // componentPublicInstance proxy to allow properties that start with $ or _
@@ -4197,6 +4326,12 @@ function compileScript(sfc, options) {
4197
4326
  }
4198
4327
  // 11. finalize default export
4199
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
+ }
4200
4335
  if (hasInlinedSsrRenderFn) {
4201
4336
  runtimeOptions += `\n __ssrInlineRender: true,`;
4202
4337
  }
@@ -4263,13 +4398,21 @@ function compileScript(sfc, options) {
4263
4398
  .join(', ')} } from 'vue'\n`);
4264
4399
  }
4265
4400
  s.trim();
4266
- return Object.assign(Object.assign({}, scriptSetup), { bindings: bindingMetadata, imports: userImports, content: s.toString(), map: genSourceMap
4401
+ return {
4402
+ ...scriptSetup,
4403
+ bindings: bindingMetadata,
4404
+ imports: userImports,
4405
+ content: s.toString(),
4406
+ map: genSourceMap
4267
4407
  ? s.generateMap({
4268
4408
  source: filename,
4269
4409
  hires: true,
4270
4410
  includeContent: true
4271
4411
  })
4272
- : undefined, scriptAst: scriptAst === null || scriptAst === void 0 ? void 0 : scriptAst.body, scriptSetupAst: scriptSetupAst === null || scriptSetupAst === void 0 ? void 0 : scriptSetupAst.body });
4412
+ : undefined,
4413
+ scriptAst: scriptAst?.body,
4414
+ scriptSetupAst: scriptSetupAst?.body
4415
+ };
4273
4416
  }
4274
4417
  function registerBinding(bindings, node, type) {
4275
4418
  bindings[node.name] = type;
@@ -4286,14 +4429,18 @@ function walkDeclaration(node, bindings, userImportAlias) {
4286
4429
  const userReactiveBinding = userImportAlias['reactive'] || 'reactive';
4287
4430
  if (isCallOf(init, userReactiveBinding)) {
4288
4431
  // treat reactive() calls as let since it's meant to be mutable
4289
- bindingType = "setup-let" /* SETUP_LET */;
4432
+ bindingType = isConst
4433
+ ? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
4434
+ : "setup-let" /* SETUP_LET */;
4290
4435
  }
4291
4436
  else if (
4292
4437
  // if a declaration is a const literal, we can mark it so that
4293
4438
  // the generated render fn code doesn't need to unref() it
4294
4439
  isDefineCall ||
4295
4440
  (isConst && canNeverBeRef(init, userReactiveBinding))) {
4296
- bindingType = "setup-const" /* SETUP_CONST */;
4441
+ bindingType = isCallOf(init, DEFINE_PROPS)
4442
+ ? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
4443
+ : "setup-const" /* SETUP_CONST */;
4297
4444
  }
4298
4445
  else if (isConst) {
4299
4446
  if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
@@ -4706,13 +4853,13 @@ function resolveTemplateUsageCheckString(sfc) {
4706
4853
  code += `,v${shared.capitalize(shared.camelize(prop.name))}`;
4707
4854
  }
4708
4855
  if (prop.exp) {
4709
- code += `,${stripStrings(prop.exp.content)}`;
4856
+ code += `,${processExp(prop.exp.content)}`;
4710
4857
  }
4711
4858
  }
4712
4859
  }
4713
4860
  }
4714
4861
  else if (node.type === 5 /* INTERPOLATION */) {
4715
- code += `,${stripStrings(node.content.content)}`;
4862
+ code += `,${processExp(node.content.content)}`;
4716
4863
  }
4717
4864
  }
4718
4865
  ]
@@ -4721,6 +4868,18 @@ function resolveTemplateUsageCheckString(sfc) {
4721
4868
  templateUsageCheckCache.set(content, code);
4722
4869
  return code;
4723
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
+ }
4724
4883
  function stripStrings(exp) {
4725
4884
  return exp
4726
4885
  .replace(/'[^']*'|"[^"]*"/g, '')
@@ -4761,8 +4920,9 @@ function hmrShouldReload(prevImports, next) {
4761
4920
  return false;
4762
4921
  }
4763
4922
 
4923
+ const DEFAULT_FILENAME = 'anonymous.vue';
4764
4924
  const sourceToSFC = createCache();
4765
- function parse(source, { sourceMap = true, filename = 'anonymous.vue', sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM__namespace } = {}) {
4925
+ function parse(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRoot = '', pad = false, ignoreEmpty = true, compiler = CompilerDOM__namespace } = {}) {
4766
4926
  const sourceKey = source + sourceMap + filename + sourceRoot + pad + compiler.parse;
4767
4927
  const cache = sourceToSFC.get(sourceKey);
4768
4928
  if (cache) {
@@ -4921,7 +5081,7 @@ function createBlock(node, source, pad) {
4921
5081
  offset: start.offset + offset
4922
5082
  };
4923
5083
  }
4924
- end = Object.assign({}, start);
5084
+ end = { ...start };
4925
5085
  }
4926
5086
  const loc = {
4927
5087
  source: content,
@@ -9391,7 +9551,13 @@ function merge$1(oldMap, newMap) {
9391
9551
  // .scss/.sass processor
9392
9552
  const scss = (source, map, options, load = require) => {
9393
9553
  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 });
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
+ };
9395
9561
  try {
9396
9562
  const result = nodeSass.renderSync(finalOptions);
9397
9563
  const dependencies = result.stats.includedFiles;
@@ -9409,13 +9575,16 @@ const scss = (source, map, options, load = require) => {
9409
9575
  return { code: '', errors: [e], dependencies: [] };
9410
9576
  }
9411
9577
  };
9412
- const sass = (source, map, options, load) => scss(source, map, Object.assign(Object.assign({}, options), { indentedSyntax: true }), load);
9578
+ const sass = (source, map, options, load) => scss(source, map, {
9579
+ ...options,
9580
+ indentedSyntax: true
9581
+ }, load);
9413
9582
  // .less
9414
9583
  const less = (source, map, options, load = require) => {
9415
9584
  const nodeLess = load('less');
9416
9585
  let result;
9417
9586
  let error = null;
9418
- nodeLess.render(getSource(source, options.filename, options.additionalData), Object.assign(Object.assign({}, options), { syncImport: true }), (err, output) => {
9587
+ nodeLess.render(getSource(source, options.filename, options.additionalData), { ...options, syncImport: true }, (err, output) => {
9419
9588
  error = err;
9420
9589
  result = output;
9421
9590
  });
@@ -17182,10 +17351,16 @@ var postcss$3 = true;
17182
17351
  build.postcss = postcss$3;
17183
17352
 
17184
17353
  function compileStyle(options) {
17185
- return doCompileStyle(Object.assign(Object.assign({}, options), { isAsync: false }));
17354
+ return doCompileStyle({
17355
+ ...options,
17356
+ isAsync: false
17357
+ });
17186
17358
  }
17187
17359
  function compileStyleAsync(options) {
17188
- return doCompileStyle(Object.assign(Object.assign({}, options), { isAsync: true }));
17360
+ return doCompileStyle({
17361
+ ...options,
17362
+ isAsync: true
17363
+ });
17189
17364
  }
17190
17365
  function doCompileStyle(options) {
17191
17366
  const { filename, id, scoped = false, trim = true, isProd = false, modules = false, modulesOptions = {}, preprocessLang, postcssOptions, postcssPlugins } = options;
@@ -17210,11 +17385,18 @@ function doCompileStyle(options) {
17210
17385
  if (!options.isAsync) {
17211
17386
  throw new Error('[@vue/compiler-sfc] `modules` option can only be used with compileStyleAsync().');
17212
17387
  }
17213
- plugins.push(build(Object.assign(Object.assign({}, modulesOptions), { getJSON: (_cssFileName, json) => {
17388
+ plugins.push(build({
17389
+ ...modulesOptions,
17390
+ getJSON: (_cssFileName, json) => {
17214
17391
  cssModules = json;
17215
- } })));
17392
+ }
17393
+ }));
17216
17394
  }
17217
- const postCSSOptions = Object.assign(Object.assign({}, postcssOptions), { to: filename, from: filename });
17395
+ const postCSSOptions = {
17396
+ ...postcssOptions,
17397
+ to: filename,
17398
+ from: filename
17399
+ };
17218
17400
  if (map) {
17219
17401
  postCSSOptions.map = {
17220
17402
  inline: false,
@@ -17280,7 +17462,10 @@ function doCompileStyle(options) {
17280
17462
  };
17281
17463
  }
17282
17464
  function preprocess$1(options, preprocessor) {
17283
- return preprocessor(options.source, options.inMap || options.map, Object.assign({ filename: options.filename }, options.preprocessOptions), options.preprocessCustomRequire);
17465
+ return preprocessor(options.source, options.inMap || options.map, {
17466
+ filename: options.filename,
17467
+ ...options.preprocessOptions
17468
+ }, options.preprocessCustomRequire);
17284
17469
  }
17285
17470
 
17286
17471
  // API