@vue/compiler-sfc 3.5.0-alpha.2 → 3.5.0-alpha.3

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.5.0-alpha.2
2
+ * @vue/compiler-sfc v3.5.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -44,8 +44,7 @@ function resolveObjectKey(node, computed) {
44
44
  case "NumericLiteral":
45
45
  return String(node.value);
46
46
  case "Identifier":
47
- if (!computed)
48
- return node.name;
47
+ if (!computed) return node.name;
49
48
  }
50
49
  return void 0;
51
50
  }
@@ -64,8 +63,7 @@ function toRuntimeTypeString(types) {
64
63
  function getImportedName(specifier) {
65
64
  if (specifier.type === "ImportSpecifier")
66
65
  return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
67
- else if (specifier.type === "ImportNamespaceSpecifier")
68
- return "*";
66
+ else if (specifier.type === "ImportNamespaceSpecifier") return "*";
69
67
  return "default";
70
68
  }
71
69
  function getId(node) {
@@ -1764,8 +1762,7 @@ function resolveTemplateUsedIdentifiers(sfc) {
1764
1762
  switch (node.type) {
1765
1763
  case 1:
1766
1764
  let tag = node.tag;
1767
- if (tag.includes("."))
1768
- tag = tag.split(".")[0].trim();
1765
+ if (tag.includes(".")) tag = tag.split(".")[0].trim();
1769
1766
  if (!CompilerDOM.parserOptions.isNativeTag(tag) && !CompilerDOM.parserOptions.isBuiltInComponent(tag)) {
1770
1767
  ids.add(shared.camelize(tag));
1771
1768
  ids.add(shared.capitalize(shared.camelize(tag)));
@@ -2257,11 +2254,9 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
2257
2254
  if (srcsetTags.includes(node.tag) && node.props.length) {
2258
2255
  node.props.forEach((attr, index) => {
2259
2256
  if (attr.name === "srcset" && attr.type === 6) {
2260
- if (!attr.value)
2261
- return;
2257
+ if (!attr.value) return;
2262
2258
  const value = attr.value.content;
2263
- if (!value)
2264
- return;
2259
+ if (!value) return;
2265
2260
  const imageCandidates = value.split(",").map((s) => {
2266
2261
  const [url, descriptor] = s.replace(escapedSpaceCharacters, " ").trim().split(" ", 2);
2267
2262
  return { url, descriptor };
@@ -4192,13 +4187,11 @@ function preprocess$1({ source, filename, preprocessOptions }, preprocessor) {
4192
4187
  source,
4193
4188
  { filename, ...preprocessOptions },
4194
4189
  (_err, _res) => {
4195
- if (_err)
4196
- err = _err;
4190
+ if (_err) err = _err;
4197
4191
  res = _res;
4198
4192
  }
4199
4193
  );
4200
- if (err)
4201
- throw err;
4194
+ if (err) throw err;
4202
4195
  return res;
4203
4196
  }
4204
4197
  function compileTemplate(options) {
@@ -4264,11 +4257,11 @@ function doCompileTemplate({
4264
4257
  }
4265
4258
  if (ssr && !ssrCssVars) {
4266
4259
  warnOnce(
4267
- `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.\`.`
4260
+ `compileTemplate is called with \`ssr: true\` but no corresponding \`cssVars\` option.`
4268
4261
  );
4269
4262
  }
4270
4263
  if (!id) {
4271
- warnOnce(`compileTemplate now requires the \`id\` option.\`.`);
4264
+ warnOnce(`compileTemplate now requires the \`id\` option.`);
4272
4265
  id = "";
4273
4266
  }
4274
4267
  const shortId = id.replace(/^data-v-/, "");
@@ -4329,10 +4322,8 @@ ${shared.generateCodeFrame(
4329
4322
  return { code, ast, preamble, source, errors, tips, map };
4330
4323
  }
4331
4324
  function mapLines(oldMap, newMap) {
4332
- if (!oldMap)
4333
- return newMap;
4334
- if (!newMap)
4335
- return oldMap;
4325
+ if (!oldMap) return newMap;
4326
+ if (!newMap) return oldMap;
4336
4327
  const oldMapConsumer = new sourceMapJs.SourceMapConsumer(oldMap);
4337
4328
  const newMapConsumer = new sourceMapJs.SourceMapConsumer(newMap);
4338
4329
  const mergedMapGenerator = new sourceMapJs.SourceMapGenerator();
@@ -4397,10 +4388,8 @@ const trimPlugin = () => {
4397
4388
  Once(root) {
4398
4389
  root.walk(({ type, raws }) => {
4399
4390
  if (type === "rule" || type === "atrule") {
4400
- if (raws.before)
4401
- raws.before = "\n";
4402
- if ("after" in raws && raws.after)
4403
- raws.after = "\n";
4391
+ if (raws.before) raws.before = "\n";
4392
+ if ("after" in raws && raws.after) raws.after = "\n";
4404
4393
  }
4405
4394
  });
4406
4395
  }
@@ -6583,7 +6572,8 @@ tokenTypes.combinator = combinator$1;
6583
6572
  line: 1,
6584
6573
  column: 1
6585
6574
  }
6586
- }
6575
+ },
6576
+ sourceIndex: 0
6587
6577
  });
6588
6578
  this.root.append(selector);
6589
6579
  this.current = selector;
@@ -7042,7 +7032,8 @@ tokenTypes.combinator = combinator$1;
7042
7032
  var selector = new _selector["default"]({
7043
7033
  source: {
7044
7034
  start: tokenStart(this.tokens[this.position + 1])
7045
- }
7035
+ },
7036
+ sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
7046
7037
  });
7047
7038
  this.current.parent.append(selector);
7048
7039
  this.current = selector;
@@ -7111,8 +7102,9 @@ tokenTypes.combinator = combinator$1;
7111
7102
  if (last && last.type === types.PSEUDO) {
7112
7103
  var selector = new _selector["default"]({
7113
7104
  source: {
7114
- start: tokenStart(this.tokens[this.position - 1])
7115
- }
7105
+ start: tokenStart(this.tokens[this.position])
7106
+ },
7107
+ sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
7116
7108
  });
7117
7109
  var cache = this.current;
7118
7110
  last.append(selector);
@@ -7960,8 +7952,7 @@ function rewriteSelector(id, selector, selectorRoot, slotted = false) {
7960
7952
  return false;
7961
7953
  }
7962
7954
  }
7963
- if (node)
7964
- return;
7955
+ if (node) return;
7965
7956
  }
7966
7957
  if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
7967
7958
  node = n;
@@ -11274,8 +11265,7 @@ const less = (source, map, options, load = require) => {
11274
11265
  result = output;
11275
11266
  }
11276
11267
  );
11277
- if (error)
11278
- return { code: "", errors: [error], dependencies: [] };
11268
+ if (error) return { code: "", errors: [error], dependencies: [] };
11279
11269
  const dependencies = result.imports;
11280
11270
  if (map) {
11281
11271
  return {
@@ -11295,8 +11285,7 @@ const styl = (source, map, options, load = require) => {
11295
11285
  const nodeStylus = load("stylus");
11296
11286
  try {
11297
11287
  const ref = nodeStylus(source, options);
11298
- if (map)
11299
- ref.set("sourcemap", { inline: false, comment: false });
11288
+ if (map) ref.set("sourcemap", { inline: false, comment: false });
11300
11289
  const result = ref.render();
11301
11290
  const dependencies = ref.deps();
11302
11291
  if (map) {
@@ -11313,8 +11302,7 @@ const styl = (source, map, options, load = require) => {
11313
11302
  }
11314
11303
  };
11315
11304
  function getSource(source, filename, additionalData) {
11316
- if (!additionalData)
11317
- return source;
11305
+ if (!additionalData) return source;
11318
11306
  if (shared.isFunction(additionalData)) {
11319
11307
  return additionalData(source, filename);
11320
11308
  }
@@ -13337,12 +13325,17 @@ function getHashDigest$1(buffer, algorithm, digestType, maxLength) {
13337
13325
  digestType === "base49" ||
13338
13326
  digestType === "base52" ||
13339
13327
  digestType === "base58" ||
13340
- digestType === "base62"
13328
+ digestType === "base62" ||
13329
+ digestType === "base64safe"
13341
13330
  ) {
13342
- return encodeBufferToBase(hash.digest(), digestType.substr(4), maxLength);
13343
- } else {
13344
- return hash.digest(digestType || "hex").substr(0, maxLength);
13331
+ return encodeBufferToBase(
13332
+ hash.digest(),
13333
+ digestType === "base64safe" ? 64 : digestType.substr(4),
13334
+ maxLength
13335
+ );
13345
13336
  }
13337
+
13338
+ return hash.digest(digestType || "hex").substr(0, maxLength);
13346
13339
  }
13347
13340
 
13348
13341
  var getHashDigest_1 = getHashDigest$1;
@@ -13398,9 +13391,10 @@ function interpolateName$1(loaderContext, name, options = {}) {
13398
13391
  directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
13399
13392
  }
13400
13393
 
13401
- if (directory.length === 1) {
13394
+ if (directory.length <= 1) {
13402
13395
  directory = "";
13403
- } else if (directory.length > 1) {
13396
+ } else {
13397
+ // directory.length > 1
13404
13398
  folder = path$2.basename(directory);
13405
13399
  }
13406
13400
  }
@@ -13423,7 +13417,7 @@ function interpolateName$1(loaderContext, name, options = {}) {
13423
13417
  // `hash` and `contenthash` are same in `loader-utils` context
13424
13418
  // let's keep `hash` for backward compatibility
13425
13419
  .replace(
13426
- /\[(?:([^[:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi,
13420
+ /\[(?:([^[:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*(?:safe)?))?(?::(\d+))?\]/gi,
13427
13421
  (all, hashType, digestType, maxLength) =>
13428
13422
  getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
13429
13423
  );
@@ -15604,11 +15598,9 @@ function analyzeBindingsFromOptions(node) {
15604
15598
  function getObjectExpressionKeys(node) {
15605
15599
  const keys = [];
15606
15600
  for (const prop of node.properties) {
15607
- if (prop.type === "SpreadElement")
15608
- continue;
15601
+ if (prop.type === "SpreadElement") continue;
15609
15602
  const key = resolveObjectKey(prop.key, prop.computed);
15610
- if (key)
15611
- keys.push(String(key));
15603
+ if (key) keys.push(String(key));
15612
15604
  }
15613
15605
  return keys;
15614
15606
  }
@@ -15722,12 +15714,12 @@ function resolveParserPlugins(lang, userPlugins, dts = false) {
15722
15714
  )) {
15723
15715
  plugins.push("importAttributes");
15724
15716
  }
15725
- if (lang === "jsx" || lang === "tsx") {
15717
+ if (lang === "jsx" || lang === "tsx" || lang === "mtsx") {
15726
15718
  plugins.push("jsx");
15727
15719
  } else if (userPlugins) {
15728
15720
  userPlugins = userPlugins.filter((p) => p !== "jsx");
15729
15721
  }
15730
- if (lang === "ts" || lang === "tsx") {
15722
+ if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "mtsx") {
15731
15723
  plugins.push(["typescript", { dts }], "explicitResourceManagement");
15732
15724
  if (!userPlugins || !userPlugins.includes("decorators")) {
15733
15725
  plugins.push("decorators-legacy");
@@ -17441,10 +17433,11 @@ class Minimatch {
17441
17433
  for (let i = 0; i < globParts.length - 1; i++) {
17442
17434
  for (let j = i + 1; j < globParts.length; j++) {
17443
17435
  const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
17444
- if (!matched)
17445
- continue;
17446
- globParts[i] = matched;
17447
- globParts[j] = [];
17436
+ if (matched) {
17437
+ globParts[i] = [];
17438
+ globParts[j] = matched;
17439
+ break;
17440
+ }
17448
17441
  }
17449
17442
  }
17450
17443
  return globParts.filter(gs => gs.length);
@@ -17945,12 +17938,16 @@ function resolveTypeElements(ctx, node, scope, typeParameters) {
17945
17938
  }
17946
17939
  function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17947
17940
  var _a, _b;
17941
+ if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
17942
+ return { props: {} };
17943
+ }
17948
17944
  switch (node.type) {
17949
17945
  case "TSTypeLiteral":
17950
17946
  return typeElementsToMap(ctx, node.members, scope, typeParameters);
17951
17947
  case "TSInterfaceDeclaration":
17952
17948
  return resolveInterfaceMembers(ctx, node, scope, typeParameters);
17953
17949
  case "TSTypeAliasDeclaration":
17950
+ case "TSTypeAnnotation":
17954
17951
  case "TSParenthesizedType":
17955
17952
  return resolveTypeElements(
17956
17953
  ctx,
@@ -17968,7 +17965,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17968
17965
  node.type
17969
17966
  );
17970
17967
  case "TSMappedType":
17971
- return resolveMappedType(ctx, node, scope);
17968
+ return resolveMappedType(ctx, node, scope, typeParameters);
17972
17969
  case "TSIndexedAccessType": {
17973
17970
  const types = resolveIndexType(ctx, node, scope);
17974
17971
  return mergeElements(
@@ -17997,8 +17994,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17997
17994
  typeParams = /* @__PURE__ */ Object.create(null);
17998
17995
  resolved.typeParameters.params.forEach((p, i) => {
17999
17996
  let param = typeParameters && typeParameters[p.name];
18000
- if (!param)
18001
- param = node.typeParameters.params[i];
17997
+ if (!param) param = node.typeParameters.params[i];
18002
17998
  typeParams[p.name] = param;
18003
17999
  });
18004
18000
  }
@@ -18108,8 +18104,7 @@ function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameter
18108
18104
  return res;
18109
18105
  }
18110
18106
  function mergeElements(maps, type) {
18111
- if (maps.length === 1)
18112
- return maps[0];
18107
+ if (maps.length === 1) return maps[0];
18113
18108
  const res = { props: {} };
18114
18109
  const { props: baseProps } = res;
18115
18110
  for (const { props, calls } of maps) {
@@ -18157,9 +18152,6 @@ function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
18157
18152
  );
18158
18153
  if (node.extends) {
18159
18154
  for (const ext of node.extends) {
18160
- if (ext.leadingComments && ext.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
18161
- continue;
18162
- }
18163
18155
  try {
18164
18156
  const { props, calls } = resolveTypeElements(ctx, ext, scope);
18165
18157
  for (const key in props) {
@@ -18179,16 +18171,25 @@ If this previously worked in 3.2, you can instruct the compiler to ignore this e
18179
18171
  interface Props extends /* @vue-ignore */ Base {}
18180
18172
 
18181
18173
  Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
18182
- ext
18174
+ ext,
18175
+ scope
18183
18176
  );
18184
18177
  }
18185
18178
  }
18186
18179
  }
18187
18180
  return base;
18188
18181
  }
18189
- function resolveMappedType(ctx, node, scope) {
18182
+ function resolveMappedType(ctx, node, scope, typeParameters) {
18190
18183
  const res = { props: {} };
18191
- const keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
18184
+ let keys;
18185
+ if (node.nameType) {
18186
+ const { name, constraint } = node.typeParameter;
18187
+ scope = createChildScope(scope);
18188
+ Object.assign(scope.types, { ...typeParameters, [name]: constraint });
18189
+ keys = resolveStringType(ctx, node.nameType, scope);
18190
+ } else {
18191
+ keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
18192
+ }
18192
18193
  for (const key of keys) {
18193
18194
  res.props[key] = createProperty(
18194
18195
  {
@@ -18533,13 +18534,12 @@ function importSourceToScope(ctx, node, scope, source) {
18533
18534
  const osSpecificJoinFn = process__namespace.platform === "win32" ? path$3.join : joinPaths;
18534
18535
  const filename = osSpecificJoinFn(path$3.dirname(scope.filename), source);
18535
18536
  resolved = resolveExt(filename, fs);
18536
- } else if (source.startsWith(".")) {
18537
+ } else if (source[0] === ".") {
18537
18538
  const filename = joinPaths(path$3.dirname(scope.filename), source);
18538
18539
  resolved = resolveExt(filename, fs);
18539
18540
  } else {
18540
18541
  if (!ts) {
18541
- if (loadTS)
18542
- ts = loadTS();
18542
+ if (loadTS) ts = loadTS();
18543
18543
  if (!ts) {
18544
18544
  return ctx.error(
18545
18545
  `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.`,
@@ -18568,8 +18568,7 @@ function importSourceToScope(ctx, node, scope, source) {
18568
18568
  function resolveExt(filename, fs) {
18569
18569
  filename = filename.replace(/\.js$/, "");
18570
18570
  const tryResolve = (filename2) => {
18571
- if (fs.fileExists(filename2))
18572
- return filename2;
18571
+ if (fs.fileExists(filename2)) return filename2;
18573
18572
  };
18574
18573
  return tryResolve(filename) || tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.tsx`)) || tryResolve(joinPaths(filename, `index.d.ts`));
18575
18574
  }
@@ -18600,7 +18599,7 @@ function resolveWithTS(containingFile, source, ts2, fs) {
18600
18599
  );
18601
18600
  const included = (_a = c.config.raw) == null ? void 0 : _a.include;
18602
18601
  const excluded = (_b = c.config.raw) == null ? void 0 : _b.exclude;
18603
- if (!included && (!base || containingFile.startsWith(base)) || included.some((p) => minimatch(containingFile, joinPaths(base, p)))) {
18602
+ if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile, joinPaths(base, p))))) {
18604
18603
  if (excluded && excluded.some((p) => minimatch(containingFile, joinPaths(base, p)))) {
18605
18604
  continue;
18606
18605
  }
@@ -18648,8 +18647,12 @@ function loadTSConfig(configPath, ts2, fs) {
18648
18647
  const res = [config];
18649
18648
  if (config.projectReferences) {
18650
18649
  for (const ref of config.projectReferences) {
18651
- tsConfigRefMap.set(ref.path, configPath);
18652
- res.unshift(...loadTSConfig(ref.path, ts2, fs));
18650
+ const refPath = ts2.resolveProjectReferencePath(ref);
18651
+ if (!fs.fileExists(refPath)) {
18652
+ continue;
18653
+ }
18654
+ tsConfigRefMap.set(refPath, configPath);
18655
+ res.unshift(...loadTSConfig(refPath, ts2, fs));
18653
18656
  }
18654
18657
  }
18655
18658
  return res;
@@ -18660,8 +18663,7 @@ function invalidateTypeCache(filename) {
18660
18663
  fileToScopeCache.delete(filename);
18661
18664
  tsConfigCache.delete(filename);
18662
18665
  const affectedConfig = tsConfigRefMap.get(filename);
18663
- if (affectedConfig)
18664
- tsConfigCache.delete(affectedConfig);
18666
+ if (affectedConfig) tsConfigCache.delete(affectedConfig);
18665
18667
  }
18666
18668
  function fileToScope(ctx, filename, asGlobal = false) {
18667
18669
  const cached = fileToScopeCache.get(filename);
@@ -18678,12 +18680,12 @@ function fileToScope(ctx, filename, asGlobal = false) {
18678
18680
  }
18679
18681
  function parseFile(filename, content, parserPlugins) {
18680
18682
  const ext = path$3.extname(filename);
18681
- if (ext === ".ts" || ext === ".tsx") {
18683
+ if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
18682
18684
  return parser$1.parse(content, {
18683
18685
  plugins: resolveParserPlugins(
18684
18686
  ext.slice(1),
18685
18687
  parserPlugins,
18686
- filename.endsWith(".d.ts")
18688
+ /\.d\.m?ts$/.test(filename)
18687
18689
  ),
18688
18690
  sourceType: "module"
18689
18691
  }).program.body;
@@ -18824,8 +18826,7 @@ function recordTypes(ctx, body, scope, asGlobal = false) {
18824
18826
  for (const key of Object.keys(types)) {
18825
18827
  const node = types[key];
18826
18828
  node._ownerScope = scope;
18827
- if (node._ns)
18828
- node._ns._ownerScope = scope;
18829
+ if (node._ns) node._ns._ownerScope = scope;
18829
18830
  }
18830
18831
  for (const key of Object.keys(declares)) {
18831
18832
  declares[key]._ownerScope = scope;
@@ -18866,15 +18867,13 @@ function recordType(node, types, declares, overwriteId) {
18866
18867
  break;
18867
18868
  }
18868
18869
  case "ClassDeclaration":
18869
- if (overwriteId || node.id)
18870
- types[overwriteId || getId(node.id)] = node;
18870
+ if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
18871
18871
  break;
18872
18872
  case "TSTypeAliasDeclaration":
18873
18873
  types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
18874
18874
  break;
18875
18875
  case "TSDeclareFunction":
18876
- if (node.id)
18877
- declares[node.id.name] = node;
18876
+ if (node.id) declares[node.id.name] = node;
18878
18877
  break;
18879
18878
  case "VariableDeclaration": {
18880
18879
  if (node.declare) {
@@ -18938,7 +18937,7 @@ function recordImport(node, imports) {
18938
18937
  };
18939
18938
  }
18940
18939
  }
18941
- function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)) {
18940
+ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false) {
18942
18941
  try {
18943
18942
  switch (node.type) {
18944
18943
  case "TSStringKeyword":
@@ -18956,13 +18955,30 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
18956
18955
  const types = /* @__PURE__ */ new Set();
18957
18956
  const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
18958
18957
  for (const m of members) {
18959
- if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
18958
+ if (isKeyOf) {
18959
+ if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
18960
+ types.add("Number");
18961
+ } else if (m.type === "TSIndexSignature") {
18962
+ const annotation = m.parameters[0].typeAnnotation;
18963
+ if (annotation && annotation.type !== "Noop") {
18964
+ const type = inferRuntimeType(
18965
+ ctx,
18966
+ annotation.typeAnnotation,
18967
+ scope
18968
+ )[0];
18969
+ if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
18970
+ types.add(type);
18971
+ }
18972
+ } else {
18973
+ types.add("String");
18974
+ }
18975
+ } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
18960
18976
  types.add("Function");
18961
18977
  } else {
18962
18978
  types.add("Object");
18963
18979
  }
18964
18980
  }
18965
- return types.size ? Array.from(types) : ["Object"];
18981
+ return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
18966
18982
  }
18967
18983
  case "TSPropertySignature":
18968
18984
  if (node.typeAnnotation) {
@@ -18994,70 +19010,121 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
18994
19010
  case "TSTypeReference": {
18995
19011
  const resolved = resolveTypeReference(ctx, node, scope);
18996
19012
  if (resolved) {
18997
- return inferRuntimeType(ctx, resolved, resolved._ownerScope);
19013
+ return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
18998
19014
  }
18999
19015
  if (node.typeName.type === "Identifier") {
19000
- switch (node.typeName.name) {
19001
- case "Array":
19002
- case "Function":
19003
- case "Object":
19004
- case "Set":
19005
- case "Map":
19006
- case "WeakSet":
19007
- case "WeakMap":
19008
- case "Date":
19009
- case "Promise":
19010
- case "Error":
19011
- return [node.typeName.name];
19012
- case "Partial":
19013
- case "Required":
19014
- case "Readonly":
19015
- case "Record":
19016
- case "Pick":
19017
- case "Omit":
19018
- case "InstanceType":
19019
- return ["Object"];
19020
- case "Uppercase":
19021
- case "Lowercase":
19022
- case "Capitalize":
19023
- case "Uncapitalize":
19024
- return ["String"];
19025
- case "Parameters":
19026
- case "ConstructorParameters":
19027
- case "ReadonlyArray":
19028
- return ["Array"];
19029
- case "ReadonlyMap":
19030
- return ["Map"];
19031
- case "ReadonlySet":
19032
- return ["Set"];
19033
- case "NonNullable":
19034
- if (node.typeParameters && node.typeParameters.params[0]) {
19035
- return inferRuntimeType(
19036
- ctx,
19037
- node.typeParameters.params[0],
19038
- scope
19039
- ).filter((t) => t !== "null");
19040
- }
19041
- break;
19042
- case "Extract":
19043
- if (node.typeParameters && node.typeParameters.params[1]) {
19044
- return inferRuntimeType(
19045
- ctx,
19046
- node.typeParameters.params[1],
19047
- scope
19048
- );
19049
- }
19050
- break;
19051
- case "Exclude":
19052
- case "OmitThisParameter":
19053
- if (node.typeParameters && node.typeParameters.params[0]) {
19054
- return inferRuntimeType(
19055
- ctx,
19056
- node.typeParameters.params[0],
19057
- scope
19058
- );
19059
- }
19060
- break;
19016
+ if (isKeyOf) {
19017
+ switch (node.typeName.name) {
19018
+ case "String":
19019
+ case "Array":
19020
+ case "ArrayLike":
19021
+ case "Parameters":
19022
+ case "ConstructorParameters":
19023
+ case "ReadonlyArray":
19024
+ return ["String", "Number"];
19025
+ case "Record":
19026
+ case "Partial":
19027
+ case "Required":
19028
+ case "Readonly":
19029
+ if (node.typeParameters && node.typeParameters.params[0]) {
19030
+ return inferRuntimeType(
19031
+ ctx,
19032
+ node.typeParameters.params[0],
19033
+ scope,
19034
+ true
19035
+ );
19036
+ }
19037
+ break;
19038
+ case "Pick":
19039
+ case "Extract":
19040
+ if (node.typeParameters && node.typeParameters.params[1]) {
19041
+ return inferRuntimeType(
19042
+ ctx,
19043
+ node.typeParameters.params[1],
19044
+ scope
19045
+ );
19046
+ }
19047
+ break;
19048
+ case "Function":
19049
+ case "Object":
19050
+ case "Set":
19051
+ case "Map":
19052
+ case "WeakSet":
19053
+ case "WeakMap":
19054
+ case "Date":
19055
+ case "Promise":
19056
+ case "Error":
19057
+ case "Uppercase":
19058
+ case "Lowercase":
19059
+ case "Capitalize":
19060
+ case "Uncapitalize":
19061
+ case "ReadonlyMap":
19062
+ case "ReadonlySet":
19063
+ return ["String"];
19064
+ }
19065
+ } else {
19066
+ switch (node.typeName.name) {
19067
+ case "Array":
19068
+ case "Function":
19069
+ case "Object":
19070
+ case "Set":
19071
+ case "Map":
19072
+ case "WeakSet":
19073
+ case "WeakMap":
19074
+ case "Date":
19075
+ case "Promise":
19076
+ case "Error":
19077
+ return [node.typeName.name];
19078
+ case "Partial":
19079
+ case "Required":
19080
+ case "Readonly":
19081
+ case "Record":
19082
+ case "Pick":
19083
+ case "Omit":
19084
+ case "InstanceType":
19085
+ return ["Object"];
19086
+ case "Uppercase":
19087
+ case "Lowercase":
19088
+ case "Capitalize":
19089
+ case "Uncapitalize":
19090
+ return ["String"];
19091
+ case "Parameters":
19092
+ case "ConstructorParameters":
19093
+ case "ReadonlyArray":
19094
+ return ["Array"];
19095
+ case "ReadonlyMap":
19096
+ return ["Map"];
19097
+ case "ReadonlySet":
19098
+ return ["Set"];
19099
+ case "NonNullable":
19100
+ if (node.typeParameters && node.typeParameters.params[0]) {
19101
+ return inferRuntimeType(
19102
+ ctx,
19103
+ node.typeParameters.params[0],
19104
+ scope
19105
+ ).filter((t) => t !== "null");
19106
+ }
19107
+ break;
19108
+ case "Extract":
19109
+ if (node.typeParameters && node.typeParameters.params[1]) {
19110
+ return inferRuntimeType(
19111
+ ctx,
19112
+ node.typeParameters.params[1],
19113
+ scope
19114
+ );
19115
+ }
19116
+ break;
19117
+ case "Exclude":
19118
+ case "OmitThisParameter":
19119
+ if (node.typeParameters && node.typeParameters.params[0]) {
19120
+ return inferRuntimeType(
19121
+ ctx,
19122
+ node.typeParameters.params[0],
19123
+ scope
19124
+ );
19125
+ }
19126
+ break;
19127
+ }
19061
19128
  }
19062
19129
  }
19063
19130
  break;
@@ -19065,9 +19132,9 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19065
19132
  case "TSParenthesizedType":
19066
19133
  return inferRuntimeType(ctx, node.typeAnnotation, scope);
19067
19134
  case "TSUnionType":
19068
- return flattenTypes(ctx, node.types, scope);
19135
+ return flattenTypes(ctx, node.types, scope, isKeyOf);
19069
19136
  case "TSIntersectionType": {
19070
- return flattenTypes(ctx, node.types, scope).filter(
19137
+ return flattenTypes(ctx, node.types, scope, isKeyOf).filter(
19071
19138
  (t) => t !== UNKNOWN_TYPE
19072
19139
  );
19073
19140
  }
@@ -19099,27 +19166,38 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19099
19166
  if (id.type === "Identifier") {
19100
19167
  const matched = scope.declares[id.name];
19101
19168
  if (matched) {
19102
- return inferRuntimeType(ctx, matched, matched._ownerScope);
19169
+ return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
19103
19170
  }
19104
19171
  }
19105
19172
  break;
19106
19173
  }
19107
19174
  case "TSTypeOperator": {
19108
- return inferRuntimeType(ctx, node.typeAnnotation, scope);
19175
+ return inferRuntimeType(
19176
+ ctx,
19177
+ node.typeAnnotation,
19178
+ scope,
19179
+ node.operator === "keyof"
19180
+ );
19181
+ }
19182
+ case "TSAnyKeyword": {
19183
+ if (isKeyOf) {
19184
+ return ["String", "Number", "Symbol"];
19185
+ }
19186
+ break;
19109
19187
  }
19110
19188
  }
19111
19189
  } catch (e) {
19112
19190
  }
19113
19191
  return [UNKNOWN_TYPE];
19114
19192
  }
19115
- function flattenTypes(ctx, types, scope) {
19193
+ function flattenTypes(ctx, types, scope, isKeyOf = false) {
19116
19194
  if (types.length === 1) {
19117
- return inferRuntimeType(ctx, types[0], scope);
19195
+ return inferRuntimeType(ctx, types[0], scope, isKeyOf);
19118
19196
  }
19119
19197
  return [
19120
19198
  ...new Set(
19121
19199
  [].concat(
19122
- ...types.map((t) => inferRuntimeType(ctx, t, scope))
19200
+ ...types.map((t) => inferRuntimeType(ctx, t, scope, isKeyOf))
19123
19201
  )
19124
19202
  )
19125
19203
  ];
@@ -19175,8 +19253,7 @@ function reverseInferType(key, node, scope, optional = true, checkObjectSyntax =
19175
19253
  if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
19176
19254
  for (const t of node.typeParameters.params) {
19177
19255
  const inferred = reverseInferType(key, t, scope, optional);
19178
- if (inferred)
19179
- return inferred;
19256
+ if (inferred) return inferred;
19180
19257
  }
19181
19258
  }
19182
19259
  return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
@@ -19216,8 +19293,7 @@ function resolveReturnType(ctx, arg, scope) {
19216
19293
  if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
19217
19294
  resolved = resolveTypeReference(ctx, arg, scope);
19218
19295
  }
19219
- if (!resolved)
19220
- return;
19296
+ if (!resolved) return;
19221
19297
  if (resolved.type === "TSFunctionType") {
19222
19298
  return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
19223
19299
  }
@@ -19228,8 +19304,7 @@ function resolveReturnType(ctx, arg, scope) {
19228
19304
  function resolveUnionType(ctx, node, scope) {
19229
19305
  if (node.type === "TSTypeReference") {
19230
19306
  const resolved = resolveTypeReference(ctx, node, scope);
19231
- if (resolved)
19232
- node = resolved;
19307
+ if (resolved) node = resolved;
19233
19308
  }
19234
19309
  let types;
19235
19310
  if (node.type === "TSUnionType") {
@@ -19306,8 +19381,7 @@ function processDefineModel(ctx, node, declId) {
19306
19381
  return true;
19307
19382
  }
19308
19383
  function genModelProps(ctx) {
19309
- if (!ctx.hasDefineModelCall)
19310
- return;
19384
+ if (!ctx.hasDefineModelCall) return;
19311
19385
  const isProd = !!ctx.options.isProd;
19312
19386
  let modelPropsDecl = "";
19313
19387
  for (const [name, { type, options: runtimeOptions }] of Object.entries(
@@ -19509,8 +19583,7 @@ function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStat
19509
19583
  } else if (hasStaticDefaults) {
19510
19584
  const prop = ctx.propsRuntimeDefaults.properties.find(
19511
19585
  (node) => {
19512
- if (node.type === "SpreadElement")
19513
- return false;
19586
+ if (node.type === "SpreadElement") return false;
19514
19587
  return resolveObjectKey(node.key, node.computed) === key;
19515
19588
  }
19516
19589
  );
@@ -19680,8 +19753,7 @@ function transformDestructuredProps(ctx, vueImportAliases) {
19680
19753
  if (stmt.type === "VariableDeclaration") {
19681
19754
  walkVariableDeclaration(stmt, isRoot);
19682
19755
  } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
19683
- if (stmt.declare || !stmt.id)
19684
- continue;
19756
+ if (stmt.declare || !stmt.id) continue;
19685
19757
  registerLocalBinding(stmt.id);
19686
19758
  } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
19687
19759
  walkVariableDeclaration(stmt.left);
@@ -19907,8 +19979,7 @@ function processDefineOptions(ctx, node) {
19907
19979
  if (node.typeParameters) {
19908
19980
  ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
19909
19981
  }
19910
- if (!node.arguments[0])
19911
- return true;
19982
+ if (!node.arguments[0]) return true;
19912
19983
  ctx.hasDefineOptionsCall = true;
19913
19984
  ctx.optionsRuntimeDecl = CompilerDOM.unwrapTSNode(node.arguments[0]);
19914
19985
  let propsOption = void 0;
@@ -19918,14 +19989,20 @@ function processDefineOptions(ctx, node) {
19918
19989
  if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
19919
19990
  for (const prop of ctx.optionsRuntimeDecl.properties) {
19920
19991
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
19921
- if (prop.key.name === "props")
19922
- propsOption = prop;
19923
- if (prop.key.name === "emits")
19924
- emitsOption = prop;
19925
- if (prop.key.name === "expose")
19926
- exposeOption = prop;
19927
- if (prop.key.name === "slots")
19928
- slotsOption = prop;
19992
+ switch (prop.key.name) {
19993
+ case "props":
19994
+ propsOption = prop;
19995
+ break;
19996
+ case "emits":
19997
+ emitsOption = prop;
19998
+ break;
19999
+ case "expose":
20000
+ exposeOption = prop;
20001
+ break;
20002
+ case "slots":
20003
+ slotsOption = prop;
20004
+ break;
20005
+ }
19929
20006
  }
19930
20007
  }
19931
20008
  }
@@ -19982,6 +20059,15 @@ function processAwait(ctx, node, needSemi, isStatement) {
19982
20059
  );
19983
20060
  }
19984
20061
 
20062
+ const MACROS = [
20063
+ DEFINE_PROPS,
20064
+ DEFINE_EMITS,
20065
+ DEFINE_EXPOSE,
20066
+ DEFINE_OPTIONS,
20067
+ DEFINE_SLOTS,
20068
+ DEFINE_MODEL,
20069
+ WITH_DEFAULTS
20070
+ ];
19985
20071
  function compileScript(sfc, options) {
19986
20072
  var _a, _b, _c;
19987
20073
  if (!options.id) {
@@ -20049,8 +20135,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20049
20135
  };
20050
20136
  }
20051
20137
  function checkInvalidScopeReference(node, method) {
20052
- if (!node)
20053
- return;
20138
+ if (!node) return;
20054
20139
  CompilerDOM.walkIdentifiers(node, (id) => {
20055
20140
  const binding = setupBindings[id.name];
20056
20141
  if (binding && binding !== "literal-const") {
@@ -20100,10 +20185,17 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20100
20185
  const imported = getImportedName(specifier);
20101
20186
  const source2 = node.source.value;
20102
20187
  const existing = ctx.userImports[local];
20103
- if (source2 === "vue" && (imported === DEFINE_PROPS || imported === DEFINE_EMITS || imported === DEFINE_EXPOSE)) {
20104
- warnOnce(
20105
- `\`${imported}\` is a compiler macro and no longer needs to be imported.`
20106
- );
20188
+ if (source2 === "vue" && MACROS.includes(imported)) {
20189
+ if (local === imported) {
20190
+ warnOnce(
20191
+ `\`${imported}\` is a compiler macro and no longer needs to be imported.`
20192
+ );
20193
+ } else {
20194
+ ctx.error(
20195
+ `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
20196
+ specifier
20197
+ );
20198
+ }
20107
20199
  removeSpecifier(i);
20108
20200
  } else if (existing) {
20109
20201
  if (existing.source === source2 && existing.imported === imported) {
@@ -20133,8 +20225,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20133
20225
  const vueImportAliases = {};
20134
20226
  for (const key in ctx.userImports) {
20135
20227
  const { source: source2, imported, local } = ctx.userImports[key];
20136
- if (source2 === "vue")
20137
- vueImportAliases[imported] = local;
20228
+ if (source2 === "vue") vueImportAliases[imported] = local;
20138
20229
  }
20139
20230
  if (script && scriptAst) {
20140
20231
  for (const node of scriptAst.body) {
@@ -20248,6 +20339,9 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20248
20339
  );
20249
20340
  }
20250
20341
  const isDefineProps = processDefineProps(ctx, init, decl.id);
20342
+ if (ctx.propsDestructureRestId) {
20343
+ setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
20344
+ }
20251
20345
  const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
20252
20346
  !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
20253
20347
  if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
@@ -20283,7 +20377,8 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20283
20377
  node,
20284
20378
  setupBindings,
20285
20379
  vueImportAliases,
20286
- hoistStatic
20380
+ hoistStatic,
20381
+ !!ctx.propsDestructureDecl
20287
20382
  );
20288
20383
  }
20289
20384
  if (hoistStatic && isAllLiteral) {
@@ -20314,8 +20409,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20314
20409
  }
20315
20410
  },
20316
20411
  exit(node2) {
20317
- if (node2.type === "BlockStatement")
20318
- scope.pop();
20412
+ if (node2.type === "BlockStatement") scope.pop();
20319
20413
  }
20320
20414
  });
20321
20415
  }
@@ -20366,8 +20460,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20366
20460
  for (const [key, { isType, imported, source: source2 }] of Object.entries(
20367
20461
  ctx.userImports
20368
20462
  )) {
20369
- if (isType)
20370
- continue;
20463
+ if (isType) continue;
20371
20464
  ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
20372
20465
  }
20373
20466
  for (const key in scriptBindings) {
@@ -20538,12 +20631,10 @@ return ${returned}
20538
20631
  __ssrInlineRender: true,`;
20539
20632
  }
20540
20633
  const propsDecl = genRuntimeProps(ctx);
20541
- if (propsDecl)
20542
- runtimeOptions += `
20634
+ if (propsDecl) runtimeOptions += `
20543
20635
  props: ${propsDecl},`;
20544
20636
  const emitsDecl = genRuntimeEmits(ctx);
20545
- if (emitsDecl)
20546
- runtimeOptions += `
20637
+ if (emitsDecl) runtimeOptions += `
20547
20638
  emits: ${emitsDecl},`;
20548
20639
  let definedOptions = "";
20549
20640
  if (ctx.optionsRuntimeDecl) {
@@ -20612,7 +20703,7 @@ ${exposeCall}`
20612
20703
  function registerBinding(bindings, node, type) {
20613
20704
  bindings[node.name] = type;
20614
20705
  }
20615
- function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20706
+ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, isPropsDestructureEnabled = false) {
20616
20707
  let isAllLiteral = false;
20617
20708
  if (node.type === "VariableDeclaration") {
20618
20709
  const isConst = node.kind === "const";
@@ -20621,10 +20712,10 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20621
20712
  );
20622
20713
  for (const { id, init: _init } of node.declarations) {
20623
20714
  const init = _init && CompilerDOM.unwrapTSNode(_init);
20624
- const isDefineCall = !!(isConst && isCallOf(
20715
+ const isConstMacroCall = isConst && isCallOf(
20625
20716
  init,
20626
- (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
20627
- ));
20717
+ (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
20718
+ );
20628
20719
  if (id.type === "Identifier") {
20629
20720
  let bindingType;
20630
20721
  const userReactiveBinding = userImportAliases["reactive"];
@@ -20635,7 +20726,7 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20635
20726
  } else if (
20636
20727
  // if a declaration is a const literal, we can mark it so that
20637
20728
  // the generated render fn code doesn't need to unref() it
20638
- isDefineCall || isConst && canNeverBeRef(init, userReactiveBinding)
20729
+ isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
20639
20730
  ) {
20640
20731
  bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
20641
20732
  } else if (isConst) {
@@ -20652,13 +20743,13 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20652
20743
  }
20653
20744
  registerBinding(bindings, id, bindingType);
20654
20745
  } else {
20655
- if (isCallOf(init, DEFINE_PROPS)) {
20746
+ if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
20656
20747
  continue;
20657
20748
  }
20658
20749
  if (id.type === "ObjectPattern") {
20659
- walkObjectPattern(id, bindings, isConst, isDefineCall);
20750
+ walkObjectPattern(id, bindings, isConst, isConstMacroCall);
20660
20751
  } else if (id.type === "ArrayPattern") {
20661
- walkArrayPattern(id, bindings, isConst, isDefineCall);
20752
+ walkArrayPattern(id, bindings, isConst, isConstMacroCall);
20662
20753
  }
20663
20754
  }
20664
20755
  }
@@ -20765,7 +20856,7 @@ function isStaticNode(node) {
20765
20856
  return false;
20766
20857
  }
20767
20858
 
20768
- const version = "3.5.0-alpha.2";
20859
+ const version = "3.5.0-alpha.3";
20769
20860
  const parseCache = parseCache$1;
20770
20861
  const errorMessages = {
20771
20862
  ...CompilerDOM.errorMessages,