@vue/compiler-sfc 3.4.26 → 3.4.28

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.4.26
2
+ * @vue/compiler-sfc v3.4.28
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
  }
@@ -4826,7 +4815,7 @@ types$1.UNIVERSAL = UNIVERSAL;
4826
4815
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
4827
4816
  function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike ) { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4828
4817
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4829
- function _arrayLikeToArray(arr, len) { len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
4818
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
4830
4819
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4831
4820
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4832
4821
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
@@ -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
  }
@@ -12000,6 +11988,10 @@ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
12000
11988
  function baseSlice(array, start, end) {
12001
11989
  var index = -1,
12002
11990
  length = array.length;
11991
+
11992
+ if (start < 0) {
11993
+ start = -start > length ? 0 : (length + start);
11994
+ }
12003
11995
  end = end > length ? length : end;
12004
11996
  if (end < 0) {
12005
11997
  end += length;
@@ -12046,7 +12038,7 @@ function baseToString(value) {
12046
12038
  function castSlice(array, start, end) {
12047
12039
  var length = array.length;
12048
12040
  end = end === undefined ? length : end;
12049
- return baseSlice(array, start, end);
12041
+ return (!start && end >= length) ? array : baseSlice(array, start, end);
12050
12042
  }
12051
12043
 
12052
12044
  /**
@@ -15600,11 +15592,9 @@ function analyzeBindingsFromOptions(node) {
15600
15592
  function getObjectExpressionKeys(node) {
15601
15593
  const keys = [];
15602
15594
  for (const prop of node.properties) {
15603
- if (prop.type === "SpreadElement")
15604
- continue;
15595
+ if (prop.type === "SpreadElement") continue;
15605
15596
  const key = resolveObjectKey(prop.key, prop.computed);
15606
- if (key)
15607
- keys.push(String(key));
15597
+ if (key) keys.push(String(key));
15608
15598
  }
15609
15599
  return keys;
15610
15600
  }
@@ -17964,7 +17954,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17964
17954
  node.type
17965
17955
  );
17966
17956
  case "TSMappedType":
17967
- return resolveMappedType(ctx, node, scope);
17957
+ return resolveMappedType(ctx, node, scope, typeParameters);
17968
17958
  case "TSIndexedAccessType": {
17969
17959
  const types = resolveIndexType(ctx, node, scope);
17970
17960
  return mergeElements(
@@ -17993,8 +17983,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17993
17983
  typeParams = /* @__PURE__ */ Object.create(null);
17994
17984
  resolved.typeParameters.params.forEach((p, i) => {
17995
17985
  let param = typeParameters && typeParameters[p.name];
17996
- if (!param)
17997
- param = node.typeParameters.params[i];
17986
+ if (!param) param = node.typeParameters.params[i];
17998
17987
  typeParams[p.name] = param;
17999
17988
  });
18000
17989
  }
@@ -18104,8 +18093,7 @@ function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameter
18104
18093
  return res;
18105
18094
  }
18106
18095
  function mergeElements(maps, type) {
18107
- if (maps.length === 1)
18108
- return maps[0];
18096
+ if (maps.length === 1) return maps[0];
18109
18097
  const res = { props: {} };
18110
18098
  const { props: baseProps } = res;
18111
18099
  for (const { props, calls } of maps) {
@@ -18182,9 +18170,17 @@ Note: both in 3.2 or with the ignore, the properties in the base type are treate
18182
18170
  }
18183
18171
  return base;
18184
18172
  }
18185
- function resolveMappedType(ctx, node, scope) {
18173
+ function resolveMappedType(ctx, node, scope, typeParameters) {
18186
18174
  const res = { props: {} };
18187
- const keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
18175
+ let keys;
18176
+ if (node.nameType) {
18177
+ const { name, constraint } = node.typeParameter;
18178
+ scope = createChildScope(scope);
18179
+ Object.assign(scope.types, { ...typeParameters, [name]: constraint });
18180
+ keys = resolveStringType(ctx, node.nameType, scope);
18181
+ } else {
18182
+ keys = resolveStringType(ctx, node.typeParameter.constraint, scope);
18183
+ }
18188
18184
  for (const key of keys) {
18189
18185
  res.props[key] = createProperty(
18190
18186
  {
@@ -18529,13 +18525,12 @@ function importSourceToScope(ctx, node, scope, source) {
18529
18525
  const osSpecificJoinFn = process__namespace.platform === "win32" ? path$3.join : joinPaths;
18530
18526
  const filename = osSpecificJoinFn(path$3.dirname(scope.filename), source);
18531
18527
  resolved = resolveExt(filename, fs);
18532
- } else if (source.startsWith(".")) {
18528
+ } else if (source[0] === ".") {
18533
18529
  const filename = joinPaths(path$3.dirname(scope.filename), source);
18534
18530
  resolved = resolveExt(filename, fs);
18535
18531
  } else {
18536
18532
  if (!ts) {
18537
- if (loadTS)
18538
- ts = loadTS();
18533
+ if (loadTS) ts = loadTS();
18539
18534
  if (!ts) {
18540
18535
  return ctx.error(
18541
18536
  `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.`,
@@ -18564,8 +18559,7 @@ function importSourceToScope(ctx, node, scope, source) {
18564
18559
  function resolveExt(filename, fs) {
18565
18560
  filename = filename.replace(/\.js$/, "");
18566
18561
  const tryResolve = (filename2) => {
18567
- if (fs.fileExists(filename2))
18568
- return filename2;
18562
+ if (fs.fileExists(filename2)) return filename2;
18569
18563
  };
18570
18564
  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`));
18571
18565
  }
@@ -18596,7 +18590,7 @@ function resolveWithTS(containingFile, source, ts2, fs) {
18596
18590
  );
18597
18591
  const included = (_a = c.config.raw) == null ? void 0 : _a.include;
18598
18592
  const excluded = (_b = c.config.raw) == null ? void 0 : _b.exclude;
18599
- if (!included && (!base || containingFile.startsWith(base)) || included.some((p) => minimatch(containingFile, joinPaths(base, p)))) {
18593
+ if (!included && (!base || containingFile.startsWith(base)) || (included == null ? void 0 : included.some((p) => minimatch(containingFile, joinPaths(base, p))))) {
18600
18594
  if (excluded && excluded.some((p) => minimatch(containingFile, joinPaths(base, p)))) {
18601
18595
  continue;
18602
18596
  }
@@ -18644,8 +18638,12 @@ function loadTSConfig(configPath, ts2, fs) {
18644
18638
  const res = [config];
18645
18639
  if (config.projectReferences) {
18646
18640
  for (const ref of config.projectReferences) {
18647
- tsConfigRefMap.set(ref.path, configPath);
18648
- res.unshift(...loadTSConfig(ref.path, ts2, fs));
18641
+ const refPath = ts2.resolveProjectReferencePath(ref);
18642
+ if (!fs.fileExists(refPath)) {
18643
+ continue;
18644
+ }
18645
+ tsConfigRefMap.set(refPath, configPath);
18646
+ res.unshift(...loadTSConfig(refPath, ts2, fs));
18649
18647
  }
18650
18648
  }
18651
18649
  return res;
@@ -18656,8 +18654,7 @@ function invalidateTypeCache(filename) {
18656
18654
  fileToScopeCache.delete(filename);
18657
18655
  tsConfigCache.delete(filename);
18658
18656
  const affectedConfig = tsConfigRefMap.get(filename);
18659
- if (affectedConfig)
18660
- tsConfigCache.delete(affectedConfig);
18657
+ if (affectedConfig) tsConfigCache.delete(affectedConfig);
18661
18658
  }
18662
18659
  function fileToScope(ctx, filename, asGlobal = false) {
18663
18660
  const cached = fileToScopeCache.get(filename);
@@ -18820,8 +18817,7 @@ function recordTypes(ctx, body, scope, asGlobal = false) {
18820
18817
  for (const key of Object.keys(types)) {
18821
18818
  const node = types[key];
18822
18819
  node._ownerScope = scope;
18823
- if (node._ns)
18824
- node._ns._ownerScope = scope;
18820
+ if (node._ns) node._ns._ownerScope = scope;
18825
18821
  }
18826
18822
  for (const key of Object.keys(declares)) {
18827
18823
  declares[key]._ownerScope = scope;
@@ -18862,15 +18858,13 @@ function recordType(node, types, declares, overwriteId) {
18862
18858
  break;
18863
18859
  }
18864
18860
  case "ClassDeclaration":
18865
- if (overwriteId || node.id)
18866
- types[overwriteId || getId(node.id)] = node;
18861
+ if (overwriteId || node.id) types[overwriteId || getId(node.id)] = node;
18867
18862
  break;
18868
18863
  case "TSTypeAliasDeclaration":
18869
18864
  types[node.id.name] = node.typeParameters ? node : node.typeAnnotation;
18870
18865
  break;
18871
18866
  case "TSDeclareFunction":
18872
- if (node.id)
18873
- declares[node.id.name] = node;
18867
+ if (node.id) declares[node.id.name] = node;
18874
18868
  break;
18875
18869
  case "VariableDeclaration": {
18876
18870
  if (node.declare) {
@@ -18934,7 +18928,7 @@ function recordImport(node, imports) {
18934
18928
  };
18935
18929
  }
18936
18930
  }
18937
- function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)) {
18931
+ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false) {
18938
18932
  try {
18939
18933
  switch (node.type) {
18940
18934
  case "TSStringKeyword":
@@ -18952,13 +18946,30 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
18952
18946
  const types = /* @__PURE__ */ new Set();
18953
18947
  const members = node.type === "TSTypeLiteral" ? node.members : node.body.body;
18954
18948
  for (const m of members) {
18955
- if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
18949
+ if (isKeyOf) {
18950
+ if (m.type === "TSPropertySignature" && m.key.type === "NumericLiteral") {
18951
+ types.add("Number");
18952
+ } else if (m.type === "TSIndexSignature") {
18953
+ const annotation = m.parameters[0].typeAnnotation;
18954
+ if (annotation && annotation.type !== "Noop") {
18955
+ const type = inferRuntimeType(
18956
+ ctx,
18957
+ annotation.typeAnnotation,
18958
+ scope
18959
+ )[0];
18960
+ if (type === UNKNOWN_TYPE) return [UNKNOWN_TYPE];
18961
+ types.add(type);
18962
+ }
18963
+ } else {
18964
+ types.add("String");
18965
+ }
18966
+ } else if (m.type === "TSCallSignatureDeclaration" || m.type === "TSConstructSignatureDeclaration") {
18956
18967
  types.add("Function");
18957
18968
  } else {
18958
18969
  types.add("Object");
18959
18970
  }
18960
18971
  }
18961
- return types.size ? Array.from(types) : ["Object"];
18972
+ return types.size ? Array.from(types) : [isKeyOf ? UNKNOWN_TYPE : "Object"];
18962
18973
  }
18963
18974
  case "TSPropertySignature":
18964
18975
  if (node.typeAnnotation) {
@@ -18990,70 +19001,121 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
18990
19001
  case "TSTypeReference": {
18991
19002
  const resolved = resolveTypeReference(ctx, node, scope);
18992
19003
  if (resolved) {
18993
- return inferRuntimeType(ctx, resolved, resolved._ownerScope);
19004
+ return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
18994
19005
  }
18995
19006
  if (node.typeName.type === "Identifier") {
18996
- switch (node.typeName.name) {
18997
- case "Array":
18998
- case "Function":
18999
- case "Object":
19000
- case "Set":
19001
- case "Map":
19002
- case "WeakSet":
19003
- case "WeakMap":
19004
- case "Date":
19005
- case "Promise":
19006
- case "Error":
19007
- return [node.typeName.name];
19008
- case "Partial":
19009
- case "Required":
19010
- case "Readonly":
19011
- case "Record":
19012
- case "Pick":
19013
- case "Omit":
19014
- case "InstanceType":
19015
- return ["Object"];
19016
- case "Uppercase":
19017
- case "Lowercase":
19018
- case "Capitalize":
19019
- case "Uncapitalize":
19020
- return ["String"];
19021
- case "Parameters":
19022
- case "ConstructorParameters":
19023
- case "ReadonlyArray":
19024
- return ["Array"];
19025
- case "ReadonlyMap":
19026
- return ["Map"];
19027
- case "ReadonlySet":
19028
- return ["Set"];
19029
- case "NonNullable":
19030
- if (node.typeParameters && node.typeParameters.params[0]) {
19031
- return inferRuntimeType(
19032
- ctx,
19033
- node.typeParameters.params[0],
19034
- scope
19035
- ).filter((t) => t !== "null");
19036
- }
19037
- break;
19038
- case "Extract":
19039
- if (node.typeParameters && node.typeParameters.params[1]) {
19040
- return inferRuntimeType(
19041
- ctx,
19042
- node.typeParameters.params[1],
19043
- scope
19044
- );
19045
- }
19046
- break;
19047
- case "Exclude":
19048
- case "OmitThisParameter":
19049
- if (node.typeParameters && node.typeParameters.params[0]) {
19050
- return inferRuntimeType(
19051
- ctx,
19052
- node.typeParameters.params[0],
19053
- scope
19054
- );
19055
- }
19056
- break;
19007
+ if (isKeyOf) {
19008
+ switch (node.typeName.name) {
19009
+ case "String":
19010
+ case "Array":
19011
+ case "ArrayLike":
19012
+ case "Parameters":
19013
+ case "ConstructorParameters":
19014
+ case "ReadonlyArray":
19015
+ return ["String", "Number"];
19016
+ case "Record":
19017
+ case "Partial":
19018
+ case "Required":
19019
+ case "Readonly":
19020
+ if (node.typeParameters && node.typeParameters.params[0]) {
19021
+ return inferRuntimeType(
19022
+ ctx,
19023
+ node.typeParameters.params[0],
19024
+ scope,
19025
+ true
19026
+ );
19027
+ }
19028
+ break;
19029
+ case "Pick":
19030
+ case "Extract":
19031
+ if (node.typeParameters && node.typeParameters.params[1]) {
19032
+ return inferRuntimeType(
19033
+ ctx,
19034
+ node.typeParameters.params[1],
19035
+ scope
19036
+ );
19037
+ }
19038
+ break;
19039
+ case "Function":
19040
+ case "Object":
19041
+ case "Set":
19042
+ case "Map":
19043
+ case "WeakSet":
19044
+ case "WeakMap":
19045
+ case "Date":
19046
+ case "Promise":
19047
+ case "Error":
19048
+ case "Uppercase":
19049
+ case "Lowercase":
19050
+ case "Capitalize":
19051
+ case "Uncapitalize":
19052
+ case "ReadonlyMap":
19053
+ case "ReadonlySet":
19054
+ return ["String"];
19055
+ }
19056
+ } else {
19057
+ switch (node.typeName.name) {
19058
+ case "Array":
19059
+ case "Function":
19060
+ case "Object":
19061
+ case "Set":
19062
+ case "Map":
19063
+ case "WeakSet":
19064
+ case "WeakMap":
19065
+ case "Date":
19066
+ case "Promise":
19067
+ case "Error":
19068
+ return [node.typeName.name];
19069
+ case "Partial":
19070
+ case "Required":
19071
+ case "Readonly":
19072
+ case "Record":
19073
+ case "Pick":
19074
+ case "Omit":
19075
+ case "InstanceType":
19076
+ return ["Object"];
19077
+ case "Uppercase":
19078
+ case "Lowercase":
19079
+ case "Capitalize":
19080
+ case "Uncapitalize":
19081
+ return ["String"];
19082
+ case "Parameters":
19083
+ case "ConstructorParameters":
19084
+ case "ReadonlyArray":
19085
+ return ["Array"];
19086
+ case "ReadonlyMap":
19087
+ return ["Map"];
19088
+ case "ReadonlySet":
19089
+ return ["Set"];
19090
+ case "NonNullable":
19091
+ if (node.typeParameters && node.typeParameters.params[0]) {
19092
+ return inferRuntimeType(
19093
+ ctx,
19094
+ node.typeParameters.params[0],
19095
+ scope
19096
+ ).filter((t) => t !== "null");
19097
+ }
19098
+ break;
19099
+ case "Extract":
19100
+ if (node.typeParameters && node.typeParameters.params[1]) {
19101
+ return inferRuntimeType(
19102
+ ctx,
19103
+ node.typeParameters.params[1],
19104
+ scope
19105
+ );
19106
+ }
19107
+ break;
19108
+ case "Exclude":
19109
+ case "OmitThisParameter":
19110
+ if (node.typeParameters && node.typeParameters.params[0]) {
19111
+ return inferRuntimeType(
19112
+ ctx,
19113
+ node.typeParameters.params[0],
19114
+ scope
19115
+ );
19116
+ }
19117
+ break;
19118
+ }
19057
19119
  }
19058
19120
  }
19059
19121
  break;
@@ -19061,9 +19123,9 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19061
19123
  case "TSParenthesizedType":
19062
19124
  return inferRuntimeType(ctx, node.typeAnnotation, scope);
19063
19125
  case "TSUnionType":
19064
- return flattenTypes(ctx, node.types, scope);
19126
+ return flattenTypes(ctx, node.types, scope, isKeyOf);
19065
19127
  case "TSIntersectionType": {
19066
- return flattenTypes(ctx, node.types, scope).filter(
19128
+ return flattenTypes(ctx, node.types, scope, isKeyOf).filter(
19067
19129
  (t) => t !== UNKNOWN_TYPE
19068
19130
  );
19069
19131
  }
@@ -19095,27 +19157,38 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19095
19157
  if (id.type === "Identifier") {
19096
19158
  const matched = scope.declares[id.name];
19097
19159
  if (matched) {
19098
- return inferRuntimeType(ctx, matched, matched._ownerScope);
19160
+ return inferRuntimeType(ctx, matched, matched._ownerScope, isKeyOf);
19099
19161
  }
19100
19162
  }
19101
19163
  break;
19102
19164
  }
19103
19165
  case "TSTypeOperator": {
19104
- return inferRuntimeType(ctx, node.typeAnnotation, scope);
19166
+ return inferRuntimeType(
19167
+ ctx,
19168
+ node.typeAnnotation,
19169
+ scope,
19170
+ node.operator === "keyof"
19171
+ );
19172
+ }
19173
+ case "TSAnyKeyword": {
19174
+ if (isKeyOf) {
19175
+ return ["String", "Number", "Symbol"];
19176
+ }
19177
+ break;
19105
19178
  }
19106
19179
  }
19107
19180
  } catch (e) {
19108
19181
  }
19109
19182
  return [UNKNOWN_TYPE];
19110
19183
  }
19111
- function flattenTypes(ctx, types, scope) {
19184
+ function flattenTypes(ctx, types, scope, isKeyOf = false) {
19112
19185
  if (types.length === 1) {
19113
- return inferRuntimeType(ctx, types[0], scope);
19186
+ return inferRuntimeType(ctx, types[0], scope, isKeyOf);
19114
19187
  }
19115
19188
  return [
19116
19189
  ...new Set(
19117
19190
  [].concat(
19118
- ...types.map((t) => inferRuntimeType(ctx, t, scope))
19191
+ ...types.map((t) => inferRuntimeType(ctx, t, scope, isKeyOf))
19119
19192
  )
19120
19193
  )
19121
19194
  ];
@@ -19171,8 +19244,7 @@ function reverseInferType(key, node, scope, optional = true, checkObjectSyntax =
19171
19244
  if ((node.type === "TSTypeReference" || node.type === "TSImportType") && node.typeParameters) {
19172
19245
  for (const t of node.typeParameters.params) {
19173
19246
  const inferred = reverseInferType(key, t, scope, optional);
19174
- if (inferred)
19175
- return inferred;
19247
+ if (inferred) return inferred;
19176
19248
  }
19177
19249
  }
19178
19250
  return createProperty(key, { type: `TSNullKeyword` }, scope, optional);
@@ -19212,8 +19284,7 @@ function resolveReturnType(ctx, arg, scope) {
19212
19284
  if (arg.type === "TSTypeReference" || arg.type === "TSTypeQuery" || arg.type === "TSImportType") {
19213
19285
  resolved = resolveTypeReference(ctx, arg, scope);
19214
19286
  }
19215
- if (!resolved)
19216
- return;
19287
+ if (!resolved) return;
19217
19288
  if (resolved.type === "TSFunctionType") {
19218
19289
  return (_a = resolved.typeAnnotation) == null ? void 0 : _a.typeAnnotation;
19219
19290
  }
@@ -19224,8 +19295,7 @@ function resolveReturnType(ctx, arg, scope) {
19224
19295
  function resolveUnionType(ctx, node, scope) {
19225
19296
  if (node.type === "TSTypeReference") {
19226
19297
  const resolved = resolveTypeReference(ctx, node, scope);
19227
- if (resolved)
19228
- node = resolved;
19298
+ if (resolved) node = resolved;
19229
19299
  }
19230
19300
  let types;
19231
19301
  if (node.type === "TSUnionType") {
@@ -19302,8 +19372,7 @@ function processDefineModel(ctx, node, declId) {
19302
19372
  return true;
19303
19373
  }
19304
19374
  function genModelProps(ctx) {
19305
- if (!ctx.hasDefineModelCall)
19306
- return;
19375
+ if (!ctx.hasDefineModelCall) return;
19307
19376
  const isProd = !!ctx.options.isProd;
19308
19377
  let modelPropsDecl = "";
19309
19378
  for (const [name, { type, options: runtimeOptions }] of Object.entries(
@@ -19505,8 +19574,7 @@ function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStat
19505
19574
  } else if (hasStaticDefaults) {
19506
19575
  const prop = ctx.propsRuntimeDefaults.properties.find(
19507
19576
  (node) => {
19508
- if (node.type === "SpreadElement")
19509
- return false;
19577
+ if (node.type === "SpreadElement") return false;
19510
19578
  return resolveObjectKey(node.key, node.computed) === key;
19511
19579
  }
19512
19580
  );
@@ -19678,8 +19746,7 @@ function transformDestructuredProps(ctx, vueImportAliases) {
19678
19746
  if (stmt.type === "VariableDeclaration") {
19679
19747
  walkVariableDeclaration(stmt, isRoot);
19680
19748
  } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
19681
- if (stmt.declare || !stmt.id)
19682
- continue;
19749
+ if (stmt.declare || !stmt.id) continue;
19683
19750
  registerLocalBinding(stmt.id);
19684
19751
  } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
19685
19752
  walkVariableDeclaration(stmt.left);
@@ -19905,8 +19972,7 @@ function processDefineOptions(ctx, node) {
19905
19972
  if (node.typeParameters) {
19906
19973
  ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node);
19907
19974
  }
19908
- if (!node.arguments[0])
19909
- return true;
19975
+ if (!node.arguments[0]) return true;
19910
19976
  ctx.hasDefineOptionsCall = true;
19911
19977
  ctx.optionsRuntimeDecl = CompilerDOM.unwrapTSNode(node.arguments[0]);
19912
19978
  let propsOption = void 0;
@@ -19916,14 +19982,20 @@ function processDefineOptions(ctx, node) {
19916
19982
  if (ctx.optionsRuntimeDecl.type === "ObjectExpression") {
19917
19983
  for (const prop of ctx.optionsRuntimeDecl.properties) {
19918
19984
  if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
19919
- if (prop.key.name === "props")
19920
- propsOption = prop;
19921
- if (prop.key.name === "emits")
19922
- emitsOption = prop;
19923
- if (prop.key.name === "expose")
19924
- exposeOption = prop;
19925
- if (prop.key.name === "slots")
19926
- slotsOption = prop;
19985
+ switch (prop.key.name) {
19986
+ case "props":
19987
+ propsOption = prop;
19988
+ break;
19989
+ case "emits":
19990
+ emitsOption = prop;
19991
+ break;
19992
+ case "expose":
19993
+ exposeOption = prop;
19994
+ break;
19995
+ case "slots":
19996
+ slotsOption = prop;
19997
+ break;
19998
+ }
19927
19999
  }
19928
20000
  }
19929
20001
  }
@@ -19980,6 +20052,15 @@ function processAwait(ctx, node, needSemi, isStatement) {
19980
20052
  );
19981
20053
  }
19982
20054
 
20055
+ const MACROS = [
20056
+ DEFINE_PROPS,
20057
+ DEFINE_EMITS,
20058
+ DEFINE_EXPOSE,
20059
+ DEFINE_OPTIONS,
20060
+ DEFINE_SLOTS,
20061
+ DEFINE_MODEL,
20062
+ WITH_DEFAULTS
20063
+ ];
19983
20064
  function compileScript(sfc, options) {
19984
20065
  var _a, _b, _c;
19985
20066
  if (!options.id) {
@@ -20047,8 +20128,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20047
20128
  };
20048
20129
  }
20049
20130
  function checkInvalidScopeReference(node, method) {
20050
- if (!node)
20051
- return;
20131
+ if (!node) return;
20052
20132
  CompilerDOM.walkIdentifiers(node, (id) => {
20053
20133
  const binding = setupBindings[id.name];
20054
20134
  if (binding && binding !== "literal-const") {
@@ -20098,10 +20178,17 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20098
20178
  const imported = getImportedName(specifier);
20099
20179
  const source2 = node.source.value;
20100
20180
  const existing = ctx.userImports[local];
20101
- if (source2 === "vue" && (imported === DEFINE_PROPS || imported === DEFINE_EMITS || imported === DEFINE_EXPOSE)) {
20102
- warnOnce(
20103
- `\`${imported}\` is a compiler macro and no longer needs to be imported.`
20104
- );
20181
+ if (source2 === "vue" && MACROS.includes(imported)) {
20182
+ if (local === imported) {
20183
+ warnOnce(
20184
+ `\`${imported}\` is a compiler macro and no longer needs to be imported.`
20185
+ );
20186
+ } else {
20187
+ ctx.error(
20188
+ `\`${imported}\` is a compiler macro and cannot be aliased to a different name.`,
20189
+ specifier
20190
+ );
20191
+ }
20105
20192
  removeSpecifier(i);
20106
20193
  } else if (existing) {
20107
20194
  if (existing.source === source2 && existing.imported === imported) {
@@ -20131,8 +20218,7 @@ Upgrade your vite or vue-loader version for compatibility with the latest experi
20131
20218
  const vueImportAliases = {};
20132
20219
  for (const key in ctx.userImports) {
20133
20220
  const { source: source2, imported, local } = ctx.userImports[key];
20134
- if (source2 === "vue")
20135
- vueImportAliases[imported] = local;
20221
+ if (source2 === "vue") vueImportAliases[imported] = local;
20136
20222
  }
20137
20223
  if (script && scriptAst) {
20138
20224
  for (const node of scriptAst.body) {
@@ -20246,6 +20332,9 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20246
20332
  );
20247
20333
  }
20248
20334
  const isDefineProps = processDefineProps(ctx, init, decl.id);
20335
+ if (ctx.propsDestructureRestId) {
20336
+ setupBindings[ctx.propsDestructureRestId] = "setup-reactive-const";
20337
+ }
20249
20338
  const isDefineEmits = !isDefineProps && processDefineEmits(ctx, init, decl.id);
20250
20339
  !isDefineEmits && (processDefineSlots(ctx, init, decl.id) || processDefineModel(ctx, init, decl.id));
20251
20340
  if (isDefineProps && !ctx.propsDestructureRestId && ctx.propsDestructureDecl) {
@@ -20312,8 +20401,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20312
20401
  }
20313
20402
  },
20314
20403
  exit(node2) {
20315
- if (node2.type === "BlockStatement")
20316
- scope.pop();
20404
+ if (node2.type === "BlockStatement") scope.pop();
20317
20405
  }
20318
20406
  });
20319
20407
  }
@@ -20364,8 +20452,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
20364
20452
  for (const [key, { isType, imported, source: source2 }] of Object.entries(
20365
20453
  ctx.userImports
20366
20454
  )) {
20367
- if (isType)
20368
- continue;
20455
+ if (isType) continue;
20369
20456
  ctx.bindingMetadata[key] = imported === "*" || imported === "default" && source2.endsWith(".vue") || source2 === "vue" ? "setup-const" : "setup-maybe-ref";
20370
20457
  }
20371
20458
  for (const key in scriptBindings) {
@@ -20536,12 +20623,10 @@ return ${returned}
20536
20623
  __ssrInlineRender: true,`;
20537
20624
  }
20538
20625
  const propsDecl = genRuntimeProps(ctx);
20539
- if (propsDecl)
20540
- runtimeOptions += `
20626
+ if (propsDecl) runtimeOptions += `
20541
20627
  props: ${propsDecl},`;
20542
20628
  const emitsDecl = genRuntimeEmits(ctx);
20543
- if (emitsDecl)
20544
- runtimeOptions += `
20629
+ if (emitsDecl) runtimeOptions += `
20545
20630
  emits: ${emitsDecl},`;
20546
20631
  let definedOptions = "";
20547
20632
  if (ctx.optionsRuntimeDecl) {
@@ -20619,10 +20704,10 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20619
20704
  );
20620
20705
  for (const { id, init: _init } of node.declarations) {
20621
20706
  const init = _init && CompilerDOM.unwrapTSNode(_init);
20622
- const isDefineCall = !!(isConst && isCallOf(
20707
+ const isConstMacroCall = isConst && isCallOf(
20623
20708
  init,
20624
- (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS
20625
- ));
20709
+ (c) => c === DEFINE_PROPS || c === DEFINE_EMITS || c === WITH_DEFAULTS || c === DEFINE_SLOTS
20710
+ );
20626
20711
  if (id.type === "Identifier") {
20627
20712
  let bindingType;
20628
20713
  const userReactiveBinding = userImportAliases["reactive"];
@@ -20633,7 +20718,7 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20633
20718
  } else if (
20634
20719
  // if a declaration is a const literal, we can mark it so that
20635
20720
  // the generated render fn code doesn't need to unref() it
20636
- isDefineCall || isConst && canNeverBeRef(init, userReactiveBinding)
20721
+ isConstMacroCall || isConst && canNeverBeRef(init, userReactiveBinding)
20637
20722
  ) {
20638
20723
  bindingType = isCallOf(init, DEFINE_PROPS) ? "setup-reactive-const" : "setup-const";
20639
20724
  } else if (isConst) {
@@ -20654,9 +20739,9 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic) {
20654
20739
  continue;
20655
20740
  }
20656
20741
  if (id.type === "ObjectPattern") {
20657
- walkObjectPattern(id, bindings, isConst, isDefineCall);
20742
+ walkObjectPattern(id, bindings, isConst, isConstMacroCall);
20658
20743
  } else if (id.type === "ArrayPattern") {
20659
- walkArrayPattern(id, bindings, isConst, isDefineCall);
20744
+ walkArrayPattern(id, bindings, isConst, isConstMacroCall);
20660
20745
  }
20661
20746
  }
20662
20747
  }
@@ -20763,7 +20848,7 @@ function isStaticNode(node) {
20763
20848
  return false;
20764
20849
  }
20765
20850
 
20766
- const version = "3.4.26";
20851
+ const version = "3.4.28";
20767
20852
  const parseCache = parseCache$1;
20768
20853
  const errorMessages = {
20769
20854
  ...CompilerDOM.errorMessages,