@vue/compiler-sfc 3.6.0-alpha.2 → 3.6.0-alpha.4

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-sfc v3.6.0-alpha.2
2
+ * @vue/compiler-sfc v3.6.0-alpha.4
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -142,7 +142,7 @@ function genCssVarsFromList(vars, id, isProd, isSSR = false) {
142
142
  }
143
143
  function genVarName(id, raw, isProd, isSSR = false) {
144
144
  if (isProd) {
145
- return hash(id + raw);
145
+ return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
146
146
  } else {
147
147
  return `${id}-${shared.getEscapedCssVarName(raw, isSSR)}`;
148
148
  }
@@ -1705,8 +1705,8 @@ function createCache(max = 500) {
1705
1705
  return new LRUCache({ max });
1706
1706
  }
1707
1707
 
1708
- function isImportUsed(local, sfc) {
1709
- return resolveTemplateUsedIdentifiers(sfc).has(local);
1708
+ function isUsedInTemplate(identifier, sfc) {
1709
+ return resolveTemplateUsedIdentifiers(sfc).has(identifier);
1710
1710
  }
1711
1711
  const templateUsageCheckCache = createCache();
1712
1712
  function resolveTemplateUsedIdentifiers(sfc) {
@@ -2031,7 +2031,7 @@ function hmrShouldReload(prevImports, next) {
2031
2031
  return false;
2032
2032
  }
2033
2033
  for (const key in prevImports) {
2034
- if (!prevImports[key].isUsedInTemplate && isImportUsed(key, next)) {
2034
+ if (!prevImports[key].isUsedInTemplate && isUsedInTemplate(key, next)) {
2035
2035
  return true;
2036
2036
  }
2037
2037
  }
@@ -2062,7 +2062,7 @@ function isRelativeUrl(url) {
2062
2062
  const firstChar = url.charAt(0);
2063
2063
  return firstChar === "." || firstChar === "~" || firstChar === "@";
2064
2064
  }
2065
- const externalRE = /^(https?:)?\/\//;
2065
+ const externalRE = /^(?:https?:)?\/\//;
2066
2066
  function isExternalUrl(url) {
2067
2067
  return externalRE.test(url);
2068
2068
  }
@@ -2221,7 +2221,7 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
2221
2221
  }
2222
2222
  }
2223
2223
  const shouldProcessUrl = (url) => {
2224
- return !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
2224
+ return url && !isExternalUrl(url) && !isDataUrl(url) && (options.includeAbsolute || isRelativeUrl(url));
2225
2225
  };
2226
2226
  if (!imageCandidates.some(({ url }) => shouldProcessUrl(url))) {
2227
2227
  return;
@@ -2247,54 +2247,49 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
2247
2247
  return;
2248
2248
  }
2249
2249
  }
2250
- const compoundExpression = compilerCore.createCompoundExpression([], attr.loc);
2250
+ let content = "";
2251
2251
  imageCandidates.forEach(({ url, descriptor }, index2) => {
2252
2252
  if (shouldProcessUrl(url)) {
2253
2253
  const { path: path2 } = parseUrl(url);
2254
- let exp2;
2255
2254
  if (path2) {
2255
+ let exp2 = "";
2256
2256
  const existingImportsIndex = context.imports.findIndex(
2257
2257
  (i) => i.path === path2
2258
2258
  );
2259
2259
  if (existingImportsIndex > -1) {
2260
- exp2 = compilerCore.createSimpleExpression(
2261
- `_imports_${existingImportsIndex}`,
2262
- false,
2263
- attr.loc,
2264
- 3
2265
- );
2260
+ exp2 = `_imports_${existingImportsIndex}`;
2266
2261
  } else {
2267
- exp2 = compilerCore.createSimpleExpression(
2268
- `_imports_${context.imports.length}`,
2269
- false,
2270
- attr.loc,
2271
- 3
2272
- );
2273
- context.imports.push({ exp: exp2, path: path2 });
2262
+ exp2 = `_imports_${context.imports.length}`;
2263
+ context.imports.push({
2264
+ exp: compilerCore.createSimpleExpression(
2265
+ exp2,
2266
+ false,
2267
+ attr.loc,
2268
+ 3
2269
+ ),
2270
+ path: path2
2271
+ });
2274
2272
  }
2275
- compoundExpression.children.push(exp2);
2273
+ content += exp2;
2276
2274
  }
2277
2275
  } else {
2278
- const exp2 = compilerCore.createSimpleExpression(
2279
- `"${url}"`,
2280
- false,
2281
- attr.loc,
2282
- 3
2283
- );
2284
- compoundExpression.children.push(exp2);
2276
+ content += `"${url}"`;
2285
2277
  }
2286
2278
  const isNotLast = imageCandidates.length - 1 > index2;
2287
- if (descriptor && isNotLast) {
2288
- compoundExpression.children.push(` + ' ${descriptor}, ' + `);
2289
- } else if (descriptor) {
2290
- compoundExpression.children.push(` + ' ${descriptor}'`);
2279
+ if (descriptor) {
2280
+ content += ` + ' ${descriptor}${isNotLast ? ", " : ""}'${isNotLast ? " + " : ""}`;
2291
2281
  } else if (isNotLast) {
2292
- compoundExpression.children.push(` + ', ' + `);
2282
+ content += ` + ', ' + `;
2293
2283
  }
2294
2284
  });
2295
- let exp = compoundExpression;
2285
+ let exp = compilerCore.createSimpleExpression(
2286
+ content,
2287
+ false,
2288
+ attr.loc,
2289
+ 3
2290
+ );
2296
2291
  if (context.hoistStatic) {
2297
- exp = context.hoist(compoundExpression);
2292
+ exp = context.hoist(exp);
2298
2293
  exp.constType = 3;
2299
2294
  }
2300
2295
  node.props[index] = {
@@ -8001,8 +7996,9 @@ function requireDist () {
8001
7996
  var distExports = /*@__PURE__*/ requireDist();
8002
7997
  var selectorParser = /*@__PURE__*/getDefaultExportFromCjs(distExports);
8003
7998
 
8004
- const animationNameRE = /^(-\w+-)?animation-name$/;
8005
- const animationRE = /^(-\w+-)?animation$/;
7999
+ const animationNameRE = /^(?:-\w+-)?animation-name$/;
8000
+ const animationRE = /^(?:-\w+-)?animation$/;
8001
+ const keyframesRE = /^(?:-\w+-)?keyframes$/;
8006
8002
  const scopedPlugin = (id = "") => {
8007
8003
  const keyframes = /* @__PURE__ */ Object.create(null);
8008
8004
  const shortId = id.replace(/^data-v-/, "");
@@ -8012,7 +8008,7 @@ const scopedPlugin = (id = "") => {
8012
8008
  processRule(id, rule);
8013
8009
  },
8014
8010
  AtRule(node) {
8015
- if (/-?keyframes$/.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
8011
+ if (keyframesRE.test(node.name) && !node.params.endsWith(`-${shortId}`)) {
8016
8012
  keyframes[node.params] = node.params = node.params + "-" + shortId;
8017
8013
  }
8018
8014
  },
@@ -8041,7 +8037,7 @@ const scopedPlugin = (id = "") => {
8041
8037
  };
8042
8038
  const processedRules = /* @__PURE__ */ new WeakSet();
8043
8039
  function processRule(id, rule) {
8044
- if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && /-?keyframes$/.test(rule.parent.name)) {
8040
+ if (processedRules.has(rule) || rule.parent && rule.parent.type === "atrule" && keyframesRE.test(rule.parent.name)) {
8045
8041
  return;
8046
8042
  }
8047
8043
  processedRules.add(rule);
@@ -16232,6 +16228,9 @@ function getImportedName(specifier) {
16232
16228
  function getId(node) {
16233
16229
  return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
16234
16230
  }
16231
+ function getStringLiteralKey(node) {
16232
+ return node.computed ? node.key.type === "TemplateLiteral" && !node.key.expressions.length ? node.key.quasis.map((q) => q.value.cooked).join("") : null : node.key.type === "Identifier" ? node.key.name : node.key.type === "StringLiteral" ? node.key.value : node.key.type === "NumericLiteral" ? String(node.key.value) : null;
16233
+ }
16235
16234
  const identity = (str) => str;
16236
16235
  const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_\. ]+/g;
16237
16236
  const toLowerCase = (str) => str.toLowerCase();
@@ -16251,6 +16250,8 @@ const propNameEscapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~\-]/;
16251
16250
  function getEscapedPropName(key) {
16252
16251
  return propNameEscapeSymbolsRE.test(key) ? JSON.stringify(key) : key;
16253
16252
  }
16253
+ const isJS = (...langs) => langs.some((lang) => lang === "js" || lang === "jsx");
16254
+ const isTS = (...langs) => langs.some((lang) => lang === "ts" || lang === "tsx");
16254
16255
 
16255
16256
  function analyzeScriptBindings(ast) {
16256
16257
  for (const node of ast) {
@@ -16351,8 +16352,8 @@ class ScriptCompileContext {
16351
16352
  const { script, scriptSetup } = descriptor;
16352
16353
  const scriptLang = script && script.lang;
16353
16354
  const scriptSetupLang = scriptSetup && scriptSetup.lang;
16354
- this.isJS = scriptLang === "js" || scriptLang === "jsx" || scriptSetupLang === "js" || scriptSetupLang === "jsx";
16355
- this.isTS = scriptLang === "ts" || scriptLang === "tsx" || scriptSetupLang === "ts" || scriptSetupLang === "tsx";
16355
+ this.isJS = isJS(scriptLang, scriptSetupLang);
16356
+ this.isTS = isTS(scriptLang, scriptSetupLang);
16356
16357
  const customElement = options.customElement;
16357
16358
  const filename = this.descriptor.filename;
16358
16359
  if (customElement) {
@@ -16531,9 +16532,6 @@ const normalScriptDefaultVar = `__default__`;
16531
16532
  function processNormalScript(ctx, scopeId) {
16532
16533
  var _a;
16533
16534
  const script = ctx.descriptor.script;
16534
- if (script.lang && !ctx.isJS && !ctx.isTS) {
16535
- return script;
16536
- }
16537
16535
  try {
16538
16536
  let content = script.content;
16539
16537
  let map = script.map;
@@ -16978,21 +16976,35 @@ const parseClass = (glob, position) => {
16978
16976
  /**
16979
16977
  * Un-escape a string that has been escaped with {@link escape}.
16980
16978
  *
16981
- * If the {@link windowsPathsNoEscape} option is used, then square-brace
16982
- * escapes are removed, but not backslash escapes. For example, it will turn
16983
- * the string `'[*]'` into `*`, but it will not turn `'\\*'` into `'*'`,
16984
- * becuase `\` is a path separator in `windowsPathsNoEscape` mode.
16979
+ * If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
16980
+ * square-bracket escapes are removed, but not backslash escapes.
16981
+ *
16982
+ * For example, it will turn the string `'[*]'` into `*`, but it will not
16983
+ * turn `'\\*'` into `'*'`, because `\` is a path separator in
16984
+ * `windowsPathsNoEscape` mode.
16985
16985
  *
16986
- * When `windowsPathsNoEscape` is not set, then both brace escapes and
16986
+ * When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
16987
16987
  * backslash escapes are removed.
16988
16988
  *
16989
16989
  * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
16990
16990
  * or unescaped.
16991
+ *
16992
+ * When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
16993
+ * unescaped.
16991
16994
  */
16992
- const unescape = (s, { windowsPathsNoEscape = false, } = {}) => {
16995
+ const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true, } = {}) => {
16996
+ if (magicalBraces) {
16997
+ return windowsPathsNoEscape
16998
+ ? s.replace(/\[([^\/\\])\]/g, '$1')
16999
+ : s
17000
+ .replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2')
17001
+ .replace(/\\([^\/])/g, '$1');
17002
+ }
16993
17003
  return windowsPathsNoEscape
16994
- ? s.replace(/\[([^\/\\])\]/g, '$1')
16995
- : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
17004
+ ? s.replace(/\[([^\/\\{}])\]/g, '$1')
17005
+ : s
17006
+ .replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2')
17007
+ .replace(/\\([^\/{}])/g, '$1');
16996
17008
  };
16997
17009
 
16998
17010
  // parse a single path portion
@@ -17407,7 +17419,9 @@ class AST {
17407
17419
  if (this.#root === this)
17408
17420
  this.#fillNegs();
17409
17421
  if (!this.type) {
17410
- const noEmpty = this.isStart() && this.isEnd();
17422
+ const noEmpty = this.isStart() &&
17423
+ this.isEnd() &&
17424
+ !this.#parts.some(s => typeof s !== 'string');
17411
17425
  const src = this.#parts
17412
17426
  .map(p => {
17413
17427
  const [re, _, hasMagic, uflag] = typeof p === 'string'
@@ -17563,10 +17577,7 @@ class AST {
17563
17577
  }
17564
17578
  }
17565
17579
  if (c === '*') {
17566
- if (noEmpty && glob === '*')
17567
- re += starNoEmpty;
17568
- else
17569
- re += star$1;
17580
+ re += noEmpty && glob === '*' ? starNoEmpty : star$1;
17570
17581
  hasMagic = true;
17571
17582
  continue;
17572
17583
  }
@@ -17584,16 +17595,24 @@ class AST {
17584
17595
  /**
17585
17596
  * Escape all magic characters in a glob pattern.
17586
17597
  *
17587
- * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
17598
+ * If the {@link MinimatchOptions.windowsPathsNoEscape}
17588
17599
  * option is used, then characters are escaped by wrapping in `[]`, because
17589
17600
  * a magic character wrapped in a character class can only be satisfied by
17590
17601
  * that exact character. In this mode, `\` is _not_ escaped, because it is
17591
17602
  * not interpreted as a magic character, but instead as a path separator.
17603
+ *
17604
+ * If the {@link MinimatchOptions.magicalBraces} option is used,
17605
+ * then braces (`{` and `}`) will be escaped.
17592
17606
  */
17593
- const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
17607
+ const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => {
17594
17608
  // don't need to escape +@! because we escape the parens
17595
17609
  // that make those magic, and escaping ! as [!] isn't valid,
17596
17610
  // because [!]] is a valid glob class meaning not ']'.
17611
+ if (magicalBraces) {
17612
+ return windowsPathsNoEscape
17613
+ ? s.replace(/[?*()[\]{}]/g, '[$&]')
17614
+ : s.replace(/[?*()[\]\\{}]/g, '\\$&');
17615
+ }
17597
17616
  return windowsPathsNoEscape
17598
17617
  ? s.replace(/[?*()[\]]/g, '[$&]')
17599
17618
  : s.replace(/[?*()[\]\\]/g, '\\$&');
@@ -18227,7 +18246,7 @@ class Minimatch {
18227
18246
  }
18228
18247
  }
18229
18248
  // resolve and reduce . and .. portions in the file as well.
18230
- // dont' need to do the second phase, because it's only one string[]
18249
+ // don't need to do the second phase, because it's only one string[]
18231
18250
  const { optimizationLevel = 1 } = this.options;
18232
18251
  if (optimizationLevel >= 2) {
18233
18252
  file = this.levelTwoFileOptimize(file);
@@ -18480,14 +18499,25 @@ class Minimatch {
18480
18499
  }
18481
18500
  }
18482
18501
  else if (next === undefined) {
18483
- pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?';
18502
+ pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?';
18484
18503
  }
18485
18504
  else if (next !== GLOBSTAR) {
18486
18505
  pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
18487
18506
  pp[i + 1] = GLOBSTAR;
18488
18507
  }
18489
18508
  });
18490
- return pp.filter(p => p !== GLOBSTAR).join('/');
18509
+ const filtered = pp.filter(p => p !== GLOBSTAR);
18510
+ // For partial matches, we need to make the pattern match
18511
+ // any prefix of the full path. We do this by generating
18512
+ // alternative patterns that match progressively longer prefixes.
18513
+ if (this.partial && filtered.length >= 1) {
18514
+ const prefixes = [];
18515
+ for (let i = 1; i <= filtered.length; i++) {
18516
+ prefixes.push(filtered.slice(0, i).join('/'));
18517
+ }
18518
+ return '(?:' + prefixes.join('|') + ')';
18519
+ }
18520
+ return filtered.join('/');
18491
18521
  })
18492
18522
  .join('|');
18493
18523
  // need to wrap in parens if we had more than one thing with |,
@@ -18496,6 +18526,10 @@ class Minimatch {
18496
18526
  // must match entire pattern
18497
18527
  // ending in a * or ** will make it less strict.
18498
18528
  re = '^' + open + re + close + '$';
18529
+ // In partial mode, '/' should always match as it's a valid prefix for any pattern
18530
+ if (this.partial) {
18531
+ re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$';
18532
+ }
18499
18533
  // can match anything, as long as it's not this.
18500
18534
  if (this.negate)
18501
18535
  re = '^(?!' + re + ').+$';
@@ -18766,13 +18800,9 @@ function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameter
18766
18800
  Object.assign(scope.types, typeParameters);
18767
18801
  }
18768
18802
  e._ownerScope = scope;
18769
- const name = getId(e.key);
18770
- if (name && !e.computed) {
18803
+ const name = getStringLiteralKey(e);
18804
+ if (name !== null) {
18771
18805
  res.props[name] = e;
18772
- } else if (e.key.type === "TemplateLiteral") {
18773
- for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
18774
- res.props[key] = e;
18775
- }
18776
18806
  } else {
18777
18807
  ctx.error(
18778
18808
  `Unsupported computed key in type referenced by a macro`,
@@ -19171,7 +19201,7 @@ function registerTS(_loadTS) {
19171
19201
  } catch (err) {
19172
19202
  if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
19173
19203
  throw new Error(
19174
- 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "typescript" is installed as a project dependency.'
19204
+ 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
19175
19205
  );
19176
19206
  } else {
19177
19207
  throw new Error(
@@ -19241,7 +19271,7 @@ function importSourceToScope(ctx, node, scope, source) {
19241
19271
  if (loadTS) ts = loadTS();
19242
19272
  if (!ts) {
19243
19273
  return ctx.error(
19244
- `Failed to resolve import source ${JSON.stringify(source)}. typescript is required as a peer dep for vue in order to support resolving types from module imports.`,
19274
+ `Failed to resolve import source ${JSON.stringify(source)}. TypeScript is required as a peer dep for vue in order to support resolving types from module imports.`,
19245
19275
  node,
19246
19276
  scope
19247
19277
  );
@@ -19292,14 +19322,19 @@ function resolveWithTS(containingFile, source, ts2, fs) {
19292
19322
  if (configs.length === 1) {
19293
19323
  matchedConfig = configs[0];
19294
19324
  } else {
19325
+ const [major, minor] = ts2.versionMajorMinor.split(".").map(Number);
19326
+ const getPattern = (base, p) => {
19327
+ const supportsConfigDir = major > 5 || major === 5 && minor >= 5;
19328
+ return p.startsWith("${configDir}") && supportsConfigDir ? normalizePath(p.replace("${configDir}", path$1.dirname(configPath))) : joinPaths(base, p);
19329
+ };
19295
19330
  for (const c of configs) {
19296
19331
  const base = normalizePath(
19297
19332
  c.config.options.pathsBasePath || path$1.dirname(c.config.options.configFilePath)
19298
19333
  );
19299
19334
  const included = (_a = c.config.raw) == null ? void 0 : _a.include;
19300
19335
  const excluded = (_b = c.config.raw) == null ? void 0 : _b.exclude;
19301
- if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile, joinPaths(base, p))))) {
19302
- if (excluded && excluded.some((p) => minimatch(containingFile, joinPaths(base, p)))) {
19336
+ if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile, getPattern(base, p))))) {
19337
+ if (excluded && excluded.some((p) => minimatch(containingFile, getPattern(base, p)))) {
19303
19338
  continue;
19304
19339
  }
19305
19340
  matchedConfig = c;
@@ -19473,7 +19508,11 @@ function recordTypes(ctx, body, scope, asGlobal = false) {
19473
19508
  }
19474
19509
  } else if (stmt.type === "TSModuleDeclaration" && stmt.global) {
19475
19510
  for (const s of stmt.body.body) {
19476
- recordType(s, types, declares);
19511
+ if (s.type === "ExportNamedDeclaration" && s.declaration) {
19512
+ recordType(s.declaration, types, declares);
19513
+ } else {
19514
+ recordType(s, types, declares);
19515
+ }
19477
19516
  }
19478
19517
  }
19479
19518
  } else {
@@ -19647,7 +19686,10 @@ function recordImport(node, imports) {
19647
19686
  };
19648
19687
  }
19649
19688
  }
19650
- function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false) {
19689
+ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
19690
+ if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
19691
+ return [UNKNOWN_TYPE];
19692
+ }
19651
19693
  try {
19652
19694
  switch (node.type) {
19653
19695
  case "TSStringKeyword":
@@ -19720,12 +19762,38 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19720
19762
  case "TSTypeReference": {
19721
19763
  const resolved = resolveTypeReference(ctx, node, scope);
19722
19764
  if (resolved) {
19723
- if (resolved.type === "TSTypeAliasDeclaration" && resolved.typeAnnotation.type === "TSFunctionType") {
19724
- return ["Function"];
19765
+ if (resolved.type === "TSTypeAliasDeclaration") {
19766
+ if (resolved.typeAnnotation.type === "TSFunctionType") {
19767
+ return ["Function"];
19768
+ }
19769
+ if (node.typeParameters) {
19770
+ const typeParams = /* @__PURE__ */ Object.create(null);
19771
+ if (resolved.typeParameters) {
19772
+ resolved.typeParameters.params.forEach((p, i) => {
19773
+ typeParams[p.name] = node.typeParameters.params[i];
19774
+ });
19775
+ }
19776
+ return inferRuntimeType(
19777
+ ctx,
19778
+ resolved.typeAnnotation,
19779
+ resolved._ownerScope,
19780
+ isKeyOf,
19781
+ typeParams
19782
+ );
19783
+ }
19725
19784
  }
19726
19785
  return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
19727
19786
  }
19728
19787
  if (node.typeName.type === "Identifier") {
19788
+ if (typeParameters && typeParameters[node.typeName.name]) {
19789
+ return inferRuntimeType(
19790
+ ctx,
19791
+ typeParameters[node.typeName.name],
19792
+ scope,
19793
+ isKeyOf,
19794
+ typeParameters
19795
+ );
19796
+ }
19729
19797
  if (isKeyOf) {
19730
19798
  switch (node.typeName.name) {
19731
19799
  case "String":
@@ -19848,11 +19916,33 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19848
19916
  case "TSParenthesizedType":
19849
19917
  return inferRuntimeType(ctx, node.typeAnnotation, scope);
19850
19918
  case "TSUnionType":
19851
- return flattenTypes(ctx, node.types, scope, isKeyOf);
19919
+ return flattenTypes(ctx, node.types, scope, isKeyOf, typeParameters);
19852
19920
  case "TSIntersectionType": {
19853
- return flattenTypes(ctx, node.types, scope, isKeyOf).filter(
19854
- (t) => t !== UNKNOWN_TYPE
19855
- );
19921
+ return flattenTypes(
19922
+ ctx,
19923
+ node.types,
19924
+ scope,
19925
+ isKeyOf,
19926
+ typeParameters
19927
+ ).filter((t) => t !== UNKNOWN_TYPE);
19928
+ }
19929
+ case "TSMappedType": {
19930
+ const { typeAnnotation, typeParameter } = node;
19931
+ if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
19932
+ const constraint = typeParameter.constraint;
19933
+ if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
19934
+ const typeName = constraint.typeAnnotation.typeName.name;
19935
+ const index = typeAnnotation.indexType;
19936
+ const obj = typeAnnotation.objectType;
19937
+ if (obj && obj.type === "TSTypeReference" && obj.typeName.type === "Identifier" && obj.typeName.name === typeName && index && index.type === "TSTypeReference" && index.typeName.type === "Identifier" && index.typeName.name === typeParameter.name) {
19938
+ const targetType = typeParameters[typeName];
19939
+ if (targetType) {
19940
+ return inferRuntimeType(ctx, targetType, scope);
19941
+ }
19942
+ }
19943
+ }
19944
+ }
19945
+ return [UNKNOWN_TYPE];
19856
19946
  }
19857
19947
  case "TSEnumDeclaration":
19858
19948
  return inferEnumType(node);
@@ -19907,14 +19997,16 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19907
19997
  }
19908
19998
  return [UNKNOWN_TYPE];
19909
19999
  }
19910
- function flattenTypes(ctx, types, scope, isKeyOf = false) {
20000
+ function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
19911
20001
  if (types.length === 1) {
19912
- return inferRuntimeType(ctx, types[0], scope, isKeyOf);
20002
+ return inferRuntimeType(ctx, types[0], scope, isKeyOf, typeParameters);
19913
20003
  }
19914
20004
  return [
19915
20005
  ...new Set(
19916
20006
  [].concat(
19917
- ...types.map((t) => inferRuntimeType(ctx, t, scope, isKeyOf))
20007
+ ...types.map(
20008
+ (t) => inferRuntimeType(ctx, t, scope, isKeyOf, typeParameters)
20009
+ )
19918
20010
  )
19919
20011
  )
19920
20012
  ];
@@ -20000,7 +20092,7 @@ function ctorToType(ctorType) {
20000
20092
  }
20001
20093
  function findStaticPropertyType(node, key) {
20002
20094
  const prop = node.members.find(
20003
- (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
20095
+ (m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
20004
20096
  );
20005
20097
  return prop && prop.typeAnnotation.typeAnnotation;
20006
20098
  }
@@ -20137,9 +20229,7 @@ function genModelProps(ctx) {
20137
20229
  }
20138
20230
  modelPropsDecl += `
20139
20231
  ${JSON.stringify(name)}: ${decl},`;
20140
- const modifierPropName = JSON.stringify(
20141
- name === "modelValue" ? `modelModifiers` : `${name}Modifiers`
20142
- );
20232
+ const modifierPropName = JSON.stringify(shared.getModifierPropName(name));
20143
20233
  modelPropsDecl += `
20144
20234
  ${modifierPropName}: {},`;
20145
20235
  }
@@ -20804,7 +20894,6 @@ function compileScript(sfc, options) {
20804
20894
  Upgrade your vite or vue-loader version for compatibility with the latest experimental proposals.`
20805
20895
  );
20806
20896
  }
20807
- const ctx = new ScriptCompileContext(sfc, options);
20808
20897
  const { script, scriptSetup, source, filename } = sfc;
20809
20898
  const hoistStatic = options.hoistStatic !== false && !script;
20810
20899
  const scopeId = options.id ? options.id.replace(/^data-v-/, "") : "";
@@ -20812,20 +20901,27 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20812
20901
  const scriptSetupLang = scriptSetup && scriptSetup.lang;
20813
20902
  const vapor = sfc.vapor || options.vapor;
20814
20903
  const ssr = (_a = options.templateOptions) == null ? void 0 : _a.ssr;
20904
+ const setupPreambleLines = [];
20905
+ const isJSOrTS = isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang);
20906
+ if (script && scriptSetup && scriptLang !== scriptSetupLang) {
20907
+ throw new Error(
20908
+ `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
20909
+ );
20910
+ }
20815
20911
  if (!scriptSetup) {
20816
20912
  if (!script) {
20817
20913
  throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
20818
20914
  }
20819
- return processNormalScript(ctx, scopeId);
20820
- }
20821
- if (script && scriptLang !== scriptSetupLang) {
20822
- throw new Error(
20823
- `[@vue/compiler-sfc] <script> and <script setup> must have the same language type.`
20824
- );
20915
+ if (script.lang && !isJSOrTS) {
20916
+ return script;
20917
+ }
20918
+ const ctx2 = new ScriptCompileContext(sfc, options);
20919
+ return processNormalScript(ctx2, scopeId);
20825
20920
  }
20826
- if (scriptSetupLang && !ctx.isJS && !ctx.isTS) {
20921
+ if (scriptSetupLang && !isJSOrTS) {
20827
20922
  return scriptSetup;
20828
20923
  }
20924
+ const ctx = new ScriptCompileContext(sfc, options);
20829
20925
  const scriptBindings = /* @__PURE__ */ Object.create(null);
20830
20926
  const setupBindings = /* @__PURE__ */ Object.create(null);
20831
20927
  let defaultExport;
@@ -20851,9 +20947,9 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20851
20947
  ctx.s.move(start, end, 0);
20852
20948
  }
20853
20949
  function registerUserImport(source2, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
20854
- let isUsedInTemplate = needTemplateUsageCheck;
20950
+ let isImportUsed = needTemplateUsageCheck;
20855
20951
  if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
20856
- isUsedInTemplate = isImportUsed(local, sfc);
20952
+ isImportUsed = isUsedInTemplate(local, sfc);
20857
20953
  }
20858
20954
  ctx.userImports[local] = {
20859
20955
  isType,
@@ -20861,7 +20957,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20861
20957
  local,
20862
20958
  source: source2,
20863
20959
  isFromSetup,
20864
- isUsedInTemplate
20960
+ isUsedInTemplate: isImportUsed
20865
20961
  };
20866
20962
  }
20867
20963
  function checkInvalidScopeReference(node, method) {
@@ -20876,8 +20972,36 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20876
20972
  }
20877
20973
  });
20878
20974
  }
20975
+ function buildDestructureElements() {
20976
+ if (!sfc.template || !sfc.template.ast) return;
20977
+ const builtins = {
20978
+ $props: {
20979
+ bindingType: "setup-reactive-const",
20980
+ setup: () => setupPreambleLines.push(`const $props = __props`)
20981
+ },
20982
+ $emit: {
20983
+ bindingType: "setup-const",
20984
+ setup: () => ctx.emitDecl ? setupPreambleLines.push(`const $emit = __emit`) : destructureElements.push("emit: $emit")
20985
+ },
20986
+ $attrs: {
20987
+ bindingType: "setup-reactive-const",
20988
+ setup: () => destructureElements.push("attrs: $attrs")
20989
+ },
20990
+ $slots: {
20991
+ bindingType: "setup-reactive-const",
20992
+ setup: () => destructureElements.push("slots: $slots")
20993
+ }
20994
+ };
20995
+ for (const [name, config] of Object.entries(builtins)) {
20996
+ if (isUsedInTemplate(name, sfc) && !ctx.bindingMetadata[name]) {
20997
+ config.setup();
20998
+ ctx.bindingMetadata[name] = config.bindingType;
20999
+ }
21000
+ }
21001
+ }
20879
21002
  const scriptAst = ctx.scriptAst;
20880
21003
  const scriptSetupAst = ctx.scriptSetupAst;
21004
+ const inlineMode = options.inlineTemplate;
20881
21005
  if (scriptAst) {
20882
21006
  for (const node of scriptAst.body) {
20883
21007
  if (node.type === "ImportDeclaration") {
@@ -20889,7 +21013,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20889
21013
  imported,
20890
21014
  node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
20891
21015
  false,
20892
- !options.inlineTemplate
21016
+ !inlineMode
20893
21017
  );
20894
21018
  }
20895
21019
  }
@@ -20914,6 +21038,13 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20914
21038
  const local = specifier.local.name;
20915
21039
  const imported = getImportedName(specifier);
20916
21040
  const source2 = node.source.value;
21041
+ if (vapor && ssr && specifier.type === "ImportSpecifier" && source2 === "vue" && imported === "defineVaporAsyncComponent") {
21042
+ ctx.s.overwrite(
21043
+ specifier.start + startOffset,
21044
+ specifier.end + startOffset,
21045
+ `defineAsyncComponent as ${local}`
21046
+ );
21047
+ }
20917
21048
  const existing = ctx.userImports[local];
20918
21049
  if (source2 === "vue" && MACROS.includes(imported)) {
20919
21050
  if (local === imported) {
@@ -20943,7 +21074,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20943
21074
  imported,
20944
21075
  node.importKind === "type" || specifier.type === "ImportSpecifier" && specifier.importKind === "type",
20945
21076
  true,
20946
- !options.inlineTemplate
21077
+ !inlineMode
20947
21078
  );
20948
21079
  }
20949
21080
  }
@@ -21247,16 +21378,20 @@ ${genCssVarsCode(
21247
21378
  let __temp${any}, __restore${any}
21248
21379
  `);
21249
21380
  }
21250
- const destructureElements = ctx.hasDefineExposeCall || !options.inlineTemplate ? [`expose: __expose`] : [];
21381
+ const destructureElements = ctx.hasDefineExposeCall || !inlineMode ? [`expose: __expose`] : [];
21251
21382
  if (ctx.emitDecl) {
21252
21383
  destructureElements.push(`emit: __emit`);
21253
21384
  }
21385
+ if (inlineMode) {
21386
+ buildDestructureElements();
21387
+ }
21254
21388
  if (destructureElements.length) {
21255
21389
  args += `, { ${destructureElements.join(", ")} }`;
21256
21390
  }
21257
21391
  let templateMap;
21258
21392
  let returned;
21259
- if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
21393
+ const propsDecl = genRuntimeProps(ctx);
21394
+ if (!inlineMode || !sfc.template && ctx.hasDefaultExportRender) {
21260
21395
  const allBindings = {
21261
21396
  ...scriptBindings,
21262
21397
  ...setupBindings
@@ -21332,7 +21467,7 @@ let __temp${any}, __restore${any}
21332
21467
  returned = `() => {}`;
21333
21468
  }
21334
21469
  }
21335
- if (!options.inlineTemplate && true) {
21470
+ if (!inlineMode && true) {
21336
21471
  ctx.s.appendRight(
21337
21472
  endOffset,
21338
21473
  `
@@ -21367,7 +21502,6 @@ ${vapor && !ssr ? `` : `return `}${returned}
21367
21502
  runtimeOptions += `
21368
21503
  __ssrInlineRender: true,`;
21369
21504
  }
21370
- const propsDecl = genRuntimeProps(ctx);
21371
21505
  if (propsDecl) runtimeOptions += `
21372
21506
  props: ${propsDecl},`;
21373
21507
  const emitsDecl = genRuntimeEmits(ctx);
@@ -21377,9 +21511,15 @@ ${vapor && !ssr ? `` : `return `}${returned}
21377
21511
  if (ctx.optionsRuntimeDecl) {
21378
21512
  definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
21379
21513
  }
21380
- const exposeCall = ctx.hasDefineExposeCall || options.inlineTemplate ? `` : ` __expose();
21381
- `;
21514
+ if (!ctx.hasDefineExposeCall && !inlineMode)
21515
+ setupPreambleLines.push(`__expose();`);
21516
+ const setupPreamble = setupPreambleLines.length ? ` ${setupPreambleLines.join("\n ")}
21517
+ ` : "";
21382
21518
  if (ctx.isTS) {
21519
+ if (ssr && vapor) {
21520
+ runtimeOptions += `
21521
+ __vapor: true,`;
21522
+ }
21383
21523
  const def = (defaultExport ? `
21384
21524
  ...${normalScriptDefaultVar},` : ``) + (definedOptions ? `
21385
21525
  ...${definedOptions},` : "");
@@ -21390,7 +21530,7 @@ ${genDefaultAs} /*@__PURE__*/${ctx.helper(
21390
21530
  vapor && !ssr ? `defineVaporComponent` : `defineComponent`
21391
21531
  )}({${def}${runtimeOptions}
21392
21532
  ${hasAwait ? `async ` : ``}setup(${args}) {
21393
- ${exposeCall}`
21533
+ ${setupPreamble}`
21394
21534
  );
21395
21535
  ctx.s.appendRight(endOffset, `})`);
21396
21536
  } else {
@@ -21404,7 +21544,7 @@ ${exposeCall}`
21404
21544
  `
21405
21545
  ${genDefaultAs} /*@__PURE__*/Object.assign(${defaultExport ? `${normalScriptDefaultVar}, ` : ""}${definedOptions ? `${definedOptions}, ` : ""}{${runtimeOptions}
21406
21546
  ${hasAwait ? `async ` : ``}setup(${args}) {
21407
- ${exposeCall}`
21547
+ ${setupPreamble}`
21408
21548
  );
21409
21549
  ctx.s.appendRight(endOffset, `})`);
21410
21550
  } else {
@@ -21413,7 +21553,7 @@ ${exposeCall}`
21413
21553
  `
21414
21554
  ${genDefaultAs} {${runtimeOptions}
21415
21555
  ${hasAwait ? `async ` : ``}setup(${args}) {
21416
- ${exposeCall}`
21556
+ ${setupPreamble}`
21417
21557
  );
21418
21558
  ctx.s.appendRight(endOffset, `}`);
21419
21559
  }
@@ -21612,7 +21752,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
21612
21752
  return generator.toJSON();
21613
21753
  }
21614
21754
 
21615
- const version = "3.6.0-alpha.2";
21755
+ const version = "3.6.0-alpha.4";
21616
21756
  const parseCache = parseCache$1;
21617
21757
  const errorMessages = {
21618
21758
  ...CompilerDOM.errorMessages,