@vue/compiler-sfc 3.5.26 → 3.5.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.5.26
2
+ * @vue/compiler-sfc v3.5.28
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -7158,7 +7158,7 @@ function requireParser$2 () {
7158
7158
  if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
7159
7159
  spaces.before = _space2.slice(0, _space2.length - 1);
7160
7160
  raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
7161
- } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
7161
+ } else if (_space2[0] === ' ' && _rawSpace2[0] === ' ') {
7162
7162
  spaces.after = _space2.slice(1);
7163
7163
  raws.spaces.after = _rawSpace2.slice(1);
7164
7164
  } else {
@@ -19810,7 +19810,7 @@ function resolveParserPlugins(lang, userPlugins, dts = false) {
19810
19810
  } else if (userPlugins) {
19811
19811
  userPlugins = userPlugins.filter((p) => p !== "jsx");
19812
19812
  }
19813
- if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "mtsx") {
19813
+ if (lang === "ts" || lang === "mts" || lang === "tsx" || lang === "cts" || lang === "mtsx") {
19814
19814
  plugins.push(["typescript", { dts }], "explicitResourceManagement");
19815
19815
  if (!userPlugins || !userPlugins.includes("decorators")) {
19816
19816
  plugins.push("decorators-legacy");
@@ -20025,6 +20025,7 @@ const openPattern = /\\{/g;
20025
20025
  const closePattern = /\\}/g;
20026
20026
  const commaPattern = /\\,/g;
20027
20027
  const periodPattern = /\\./g;
20028
+ const EXPANSION_MAX = 100_000;
20028
20029
  function numeric(str) {
20029
20030
  return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
20030
20031
  }
@@ -20069,10 +20070,11 @@ function parseCommaParts(str) {
20069
20070
  parts.push.apply(parts, p);
20070
20071
  return parts;
20071
20072
  }
20072
- function expand(str) {
20073
+ function expand(str, options = {}) {
20073
20074
  if (!str) {
20074
20075
  return [];
20075
20076
  }
20077
+ const { max = EXPANSION_MAX } = options;
20076
20078
  // I don't know why Bash 4.3 does this, but it does.
20077
20079
  // Anything starting with {} will have the first two bytes preserved
20078
20080
  // but *only* at the top level, so {},a}b will not expand to anything,
@@ -20082,7 +20084,7 @@ function expand(str) {
20082
20084
  if (str.slice(0, 2) === '{}') {
20083
20085
  str = '\\{\\}' + str.slice(2);
20084
20086
  }
20085
- return expand_(escapeBraces(str), true).map(unescapeBraces);
20087
+ return expand_(escapeBraces(str), max, true).map(unescapeBraces);
20086
20088
  }
20087
20089
  function embrace(str) {
20088
20090
  return '{' + str + '}';
@@ -20096,7 +20098,7 @@ function lte(i, y) {
20096
20098
  function gte(i, y) {
20097
20099
  return i >= y;
20098
20100
  }
20099
- function expand_(str, isTop) {
20101
+ function expand_(str, max, isTop) {
20100
20102
  /** @type {string[]} */
20101
20103
  const expansions = [];
20102
20104
  const m = balanced('{', '}', str);
@@ -20104,9 +20106,9 @@ function expand_(str, isTop) {
20104
20106
  return [str];
20105
20107
  // no need to expand pre, since it is guaranteed to be free of brace-sets
20106
20108
  const pre = m.pre;
20107
- const post = m.post.length ? expand_(m.post, false) : [''];
20109
+ const post = m.post.length ? expand_(m.post, max, false) : [''];
20108
20110
  if (/\$$/.test(m.pre)) {
20109
- for (let k = 0; k < post.length; k++) {
20111
+ for (let k = 0; k < post.length && k < max; k++) {
20110
20112
  const expansion = pre + '{' + m.body + '}' + post[k];
20111
20113
  expansions.push(expansion);
20112
20114
  }
@@ -20120,7 +20122,7 @@ function expand_(str, isTop) {
20120
20122
  // {a},b}
20121
20123
  if (m.post.match(/,(?!,).*\}/)) {
20122
20124
  str = m.pre + '{' + m.body + escClose + m.post;
20123
- return expand_(str);
20125
+ return expand_(str, max, true);
20124
20126
  }
20125
20127
  return [str];
20126
20128
  }
@@ -20132,7 +20134,7 @@ function expand_(str, isTop) {
20132
20134
  n = parseCommaParts(m.body);
20133
20135
  if (n.length === 1 && n[0] !== undefined) {
20134
20136
  // x{{a,b}}y ==> x{a}y x{b}y
20135
- n = expand_(n[0], false).map(embrace);
20137
+ n = expand_(n[0], max, false).map(embrace);
20136
20138
  //XXX is this necessary? Can't seem to hit it in tests.
20137
20139
  /* c8 ignore start */
20138
20140
  if (n.length === 1) {
@@ -20186,11 +20188,11 @@ function expand_(str, isTop) {
20186
20188
  else {
20187
20189
  N = [];
20188
20190
  for (let j = 0; j < n.length; j++) {
20189
- N.push.apply(N, expand_(n[j], false));
20191
+ N.push.apply(N, expand_(n[j], max, false));
20190
20192
  }
20191
20193
  }
20192
20194
  for (let j = 0; j < N.length; j++) {
20193
- for (let k = 0; k < post.length; k++) {
20195
+ for (let k = 0; k < post.length && expansions.length < max; k++) {
20194
20196
  const expansion = pre + N[j] + post[k];
20195
20197
  if (!isTop || isSequence || expansion) {
20196
20198
  expansions.push(expansion);
@@ -22263,16 +22265,18 @@ function resolveInterfaceMembers(ctx, node, scope, typeParameters) {
22263
22265
  (base.calls || (base.calls = [])).push(...calls);
22264
22266
  }
22265
22267
  } catch (e) {
22266
- ctx.error(
22267
- `Failed to resolve extends base type.
22268
+ if (!ctx.silentOnExtendsFailure) {
22269
+ ctx.error(
22270
+ `Failed to resolve extends base type.
22268
22271
  If this previously worked in 3.2, you can instruct the compiler to ignore this extend by adding /* @vue-ignore */ before it, for example:
22269
22272
 
22270
22273
  interface Props extends /* @vue-ignore */ Base {}
22271
22274
 
22272
22275
  Note: both in 3.2 or with the ignore, the properties in the base type are treated as fallthrough attrs at runtime.`,
22273
- ext,
22274
- scope
22275
- );
22276
+ ext,
22277
+ scope
22278
+ );
22279
+ }
22276
22280
  }
22277
22281
  }
22278
22282
  }
@@ -22681,11 +22685,21 @@ function importSourceToScope(ctx, node, scope, source) {
22681
22685
  }
22682
22686
  }
22683
22687
  function resolveExt(filename, fs) {
22684
- filename = filename.replace(/\.js$/, "");
22688
+ let moduleType = "u";
22689
+ if (filename.endsWith(".mjs")) {
22690
+ moduleType = "m";
22691
+ } else if (filename.endsWith(".cjs")) {
22692
+ moduleType = "c";
22693
+ }
22694
+ filename = filename.replace(/\.[cm]?jsx?$/, "");
22685
22695
  const tryResolve = (filename2) => {
22686
22696
  if (fs.fileExists(filename2)) return filename2;
22687
22697
  };
22688
- 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`));
22698
+ const resolveTs = () => tryResolve(filename + `.ts`) || tryResolve(filename + `.tsx`) || tryResolve(filename + `.d.ts`);
22699
+ const resolveMts = () => tryResolve(filename + `.mts`) || tryResolve(filename + `.d.mts`);
22700
+ const resolveCts = () => tryResolve(filename + `.cts`) || tryResolve(filename + `.d.cts`);
22701
+ return tryResolve(filename) || // For explicit .mjs/.cjs imports, prefer .mts/.cts declarations first.
22702
+ (moduleType === "m" ? resolveMts() || resolveTs() : moduleType === "c" ? resolveCts() || resolveTs() : resolveTs() || resolveMts() || resolveCts()) || tryResolve(joinPaths(filename, `index.ts`)) || tryResolve(joinPaths(filename, `index.tsx`)) || tryResolve(joinPaths(filename, `index.d.ts`));
22689
22703
  }
22690
22704
  const tsConfigCache = createCache();
22691
22705
  const tsConfigRefMap = /* @__PURE__ */ new Map();
@@ -22801,12 +22815,12 @@ function fileToScope(ctx, filename, asGlobal = false) {
22801
22815
  }
22802
22816
  function parseFile(filename, content, fs, parserPlugins) {
22803
22817
  const ext = path$1.extname(filename);
22804
- if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
22818
+ if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".cts" || ext === ".mtsx") {
22805
22819
  return parser$2.parse(content, {
22806
22820
  plugins: resolveParserPlugins(
22807
22821
  ext.slice(1),
22808
22822
  parserPlugins,
22809
- /\.d\.m?ts$/.test(filename)
22823
+ /\.d\.[cm]?ts$/.test(filename)
22810
22824
  ),
22811
22825
  sourceType: "module"
22812
22826
  }).program.body;
@@ -22972,6 +22986,17 @@ function recordType(node, types, declares, overwriteId) {
22972
22986
  case "TSInterfaceDeclaration":
22973
22987
  case "TSEnumDeclaration":
22974
22988
  case "TSModuleDeclaration": {
22989
+ if (node.type === "TSModuleDeclaration" && node.global) {
22990
+ const body = node.body;
22991
+ for (const s of body.body) {
22992
+ if (s.type === "ExportNamedDeclaration" && s.declaration) {
22993
+ recordType(s.declaration, types, declares);
22994
+ } else {
22995
+ recordType(s, types, declares);
22996
+ }
22997
+ }
22998
+ break;
22999
+ }
22975
23000
  const id = overwriteId || getId(node.id);
22976
23001
  let existing = types[id];
22977
23002
  if (existing) {
@@ -23076,6 +23101,8 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
23076
23101
  if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
23077
23102
  return [UNKNOWN_TYPE];
23078
23103
  }
23104
+ const prevSilent = ctx.silentOnExtendsFailure;
23105
+ ctx.silentOnExtendsFailure = true;
23079
23106
  try {
23080
23107
  switch (node.type) {
23081
23108
  case "TSStringKeyword":
@@ -23380,18 +23407,32 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
23380
23407
  }
23381
23408
  }
23382
23409
  } catch (e) {
23410
+ } finally {
23411
+ ctx.silentOnExtendsFailure = prevSilent;
23383
23412
  }
23384
23413
  return [UNKNOWN_TYPE];
23385
23414
  }
23386
23415
  function flattenTypes(ctx, types, scope, isKeyOf = false, typeParameters = void 0) {
23387
23416
  if (types.length === 1) {
23388
- return inferRuntimeType(ctx, types[0], scope, isKeyOf, typeParameters);
23417
+ return inferRuntimeType(
23418
+ ctx,
23419
+ types[0],
23420
+ types[0]._ownerScope || scope,
23421
+ isKeyOf,
23422
+ typeParameters
23423
+ );
23389
23424
  }
23390
23425
  return [
23391
23426
  ...new Set(
23392
23427
  [].concat(
23393
23428
  ...types.map(
23394
- (t) => inferRuntimeType(ctx, t, scope, isKeyOf, typeParameters)
23429
+ (t) => inferRuntimeType(
23430
+ ctx,
23431
+ t,
23432
+ t._ownerScope || scope,
23433
+ isKeyOf,
23434
+ typeParameters
23435
+ )
23395
23436
  )
23396
23437
  )
23397
23438
  )
@@ -23792,7 +23833,13 @@ function genRuntimePropFromType(ctx, { key, required, type, skipCheck }, hasStat
23792
23833
  if (prop.type === "ObjectProperty") {
23793
23834
  defaultString = `default: ${ctx.getString(prop.value)}`;
23794
23835
  } else {
23795
- defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default() ${ctx.getString(prop.body)}`;
23836
+ let paramsString = "";
23837
+ if (prop.params.length) {
23838
+ const start = prop.params[0].start;
23839
+ const end = prop.params[prop.params.length - 1].end;
23840
+ paramsString = ctx.getString({ start, end });
23841
+ }
23842
+ defaultString = `${prop.async ? "async " : ""}${prop.kind !== "method" ? `${prop.kind} ` : ""}default(${paramsString}) ${ctx.getString(prop.body)}`;
23796
23843
  }
23797
23844
  }
23798
23845
  }
@@ -23956,8 +24003,6 @@ function transformDestructuredProps(ctx, vueImportAliases) {
23956
24003
  } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
23957
24004
  if (stmt.declare || !stmt.id) continue;
23958
24005
  registerLocalBinding(stmt.id);
23959
- } else if ((stmt.type === "ForOfStatement" || stmt.type === "ForInStatement") && stmt.left.type === "VariableDeclaration") {
23960
- walkVariableDeclaration(stmt.left);
23961
24006
  } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration && stmt.declaration.type === "VariableDeclaration") {
23962
24007
  walkVariableDeclaration(stmt.declaration, isRoot);
23963
24008
  } else if (stmt.type === "LabeledStatement" && stmt.body.type === "VariableDeclaration") {
@@ -24036,6 +24081,17 @@ function transformDestructuredProps(ctx, vueImportAliases) {
24036
24081
  walkScope(node.body);
24037
24082
  return;
24038
24083
  }
24084
+ if (node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
24085
+ pushScope();
24086
+ const varDecl = node.type === "ForStatement" ? node.init : node.left;
24087
+ if (varDecl && varDecl.type === "VariableDeclaration") {
24088
+ walkVariableDeclaration(varDecl);
24089
+ }
24090
+ if (node.body.type === "BlockStatement") {
24091
+ walkScope(node.body);
24092
+ }
24093
+ return;
24094
+ }
24039
24095
  if (node.type === "BlockStatement" && !CompilerDOM.isFunctionType(parent)) {
24040
24096
  pushScope();
24041
24097
  walkScope(node);
@@ -24051,7 +24107,7 @@ function transformDestructuredProps(ctx, vueImportAliases) {
24051
24107
  },
24052
24108
  leave(node, parent) {
24053
24109
  parent && parentStack.pop();
24054
- if (node.type === "BlockStatement" && !CompilerDOM.isFunctionType(parent) || CompilerDOM.isFunctionType(node) || node.type === "CatchClause") {
24110
+ if (node.type === "BlockStatement" && !CompilerDOM.isFunctionType(parent) || CompilerDOM.isFunctionType(node) || node.type === "CatchClause" || node.type === "ForOfStatement" || node.type === "ForInStatement" || node.type === "ForStatement") {
24055
24111
  popScope();
24056
24112
  }
24057
24113
  }
@@ -25143,7 +25199,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
25143
25199
  return generator.toJSON();
25144
25200
  }
25145
25201
 
25146
- const version = "3.5.26";
25202
+ const version = "3.5.28";
25147
25203
  const parseCache = parseCache$1;
25148
25204
  const errorMessages = {
25149
25205
  ...CompilerDOM.errorMessages,
@@ -415,11 +415,13 @@ export type SimpleTypeResolveOptions = Partial<Pick<SFCScriptCompileOptions, 'gl
415
415
  * }
416
416
  * ```
417
417
  */
418
- export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'helper' | 'getString' | 'propsTypeDecl' | 'propsRuntimeDefaults' | 'propsDestructuredBindings' | 'emitsTypeDecl' | 'isCE'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
418
+ export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'warn' | 'helper' | 'getString' | 'propsTypeDecl' | 'propsRuntimeDefaults' | 'propsDestructuredBindings' | 'emitsTypeDecl' | 'isCE'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & {
419
419
  ast: Statement[];
420
420
  options: SimpleTypeResolveOptions;
421
421
  };
422
- export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext;
422
+ export type TypeResolveContext = (ScriptCompileContext | SimpleTypeResolveContext) & {
423
+ silentOnExtendsFailure?: boolean;
424
+ };
423
425
  type Import = Pick<ImportBinding, 'source' | 'imported'>;
424
426
  interface WithScope {
425
427
  _ownerScope: TypeScope;