@vue/compiler-sfc 3.5.21 → 3.5.23

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.21
2
+ * @vue/compiler-sfc v3.5.23
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -140,7 +140,7 @@ function genCssVarsFromList(vars, id, isProd, isSSR = false) {
140
140
  }
141
141
  function genVarName(id, raw, isProd, isSSR = false) {
142
142
  if (isProd) {
143
- return hash(id + raw);
143
+ return hash(id + raw).replace(/^\d/, (r) => `v${r}`);
144
144
  } else {
145
145
  return `${id}-${shared.getEscapedCssVarName(raw, isSSR)}`;
146
146
  }
@@ -19591,6 +19591,9 @@ function getImportedName(specifier) {
19591
19591
  function getId(node) {
19592
19592
  return node.type === "Identifier" ? node.name : node.type === "StringLiteral" ? node.value : null;
19593
19593
  }
19594
+ function getStringLiteralKey(node) {
19595
+ return node.computed ? node.key.type === "TemplateLiteral" && !node.key.expressions.length ? node.key.quasis.map((q) => q.value.cooked).join("") : null : node.key.type === "Identifier" ? node.key.name : node.key.type === "StringLiteral" ? node.key.value : node.key.type === "NumericLiteral" ? String(node.key.value) : null;
19596
+ }
19594
19597
  const identity = (str) => str;
19595
19598
  const fileNameLowerCaseRegExp = /[^\u0130\u0131\u00DFa-z0-9\\/:\-_\. ]+/g;
19596
19599
  const toLowerCase = (str) => str.toLowerCase();
@@ -20336,21 +20339,35 @@ const parseClass = (glob, position) => {
20336
20339
  /**
20337
20340
  * Un-escape a string that has been escaped with {@link escape}.
20338
20341
  *
20339
- * If the {@link windowsPathsNoEscape} option is used, then square-brace
20340
- * escapes are removed, but not backslash escapes. For example, it will turn
20341
- * the string `'[*]'` into `*`, but it will not turn `'\\*'` into `'*'`,
20342
- * becuase `\` is a path separator in `windowsPathsNoEscape` mode.
20342
+ * If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
20343
+ * square-bracket escapes are removed, but not backslash escapes.
20344
+ *
20345
+ * For example, it will turn the string `'[*]'` into `*`, but it will not
20346
+ * turn `'\\*'` into `'*'`, because `\` is a path separator in
20347
+ * `windowsPathsNoEscape` mode.
20343
20348
  *
20344
- * When `windowsPathsNoEscape` is not set, then both brace escapes and
20349
+ * When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
20345
20350
  * backslash escapes are removed.
20346
20351
  *
20347
20352
  * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
20348
20353
  * or unescaped.
20354
+ *
20355
+ * When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
20356
+ * unescaped.
20349
20357
  */
20350
- const unescape = (s, { windowsPathsNoEscape = false, } = {}) => {
20358
+ const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true, } = {}) => {
20359
+ if (magicalBraces) {
20360
+ return windowsPathsNoEscape
20361
+ ? s.replace(/\[([^\/\\])\]/g, '$1')
20362
+ : s
20363
+ .replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2')
20364
+ .replace(/\\([^\/])/g, '$1');
20365
+ }
20351
20366
  return windowsPathsNoEscape
20352
- ? s.replace(/\[([^\/\\])\]/g, '$1')
20353
- : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
20367
+ ? s.replace(/\[([^\/\\{}])\]/g, '$1')
20368
+ : s
20369
+ .replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2')
20370
+ .replace(/\\([^\/{}])/g, '$1');
20354
20371
  };
20355
20372
 
20356
20373
  // parse a single path portion
@@ -20765,7 +20782,9 @@ class AST {
20765
20782
  if (this.#root === this)
20766
20783
  this.#fillNegs();
20767
20784
  if (!this.type) {
20768
- const noEmpty = this.isStart() && this.isEnd();
20785
+ const noEmpty = this.isStart() &&
20786
+ this.isEnd() &&
20787
+ !this.#parts.some(s => typeof s !== 'string');
20769
20788
  const src = this.#parts
20770
20789
  .map(p => {
20771
20790
  const [re, _, hasMagic, uflag] = typeof p === 'string'
@@ -20921,10 +20940,7 @@ class AST {
20921
20940
  }
20922
20941
  }
20923
20942
  if (c === '*') {
20924
- if (noEmpty && glob === '*')
20925
- re += starNoEmpty;
20926
- else
20927
- re += star$1;
20943
+ re += noEmpty && glob === '*' ? starNoEmpty : star$1;
20928
20944
  hasMagic = true;
20929
20945
  continue;
20930
20946
  }
@@ -20942,16 +20958,24 @@ class AST {
20942
20958
  /**
20943
20959
  * Escape all magic characters in a glob pattern.
20944
20960
  *
20945
- * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
20961
+ * If the {@link MinimatchOptions.windowsPathsNoEscape}
20946
20962
  * option is used, then characters are escaped by wrapping in `[]`, because
20947
20963
  * a magic character wrapped in a character class can only be satisfied by
20948
20964
  * that exact character. In this mode, `\` is _not_ escaped, because it is
20949
20965
  * not interpreted as a magic character, but instead as a path separator.
20966
+ *
20967
+ * If the {@link MinimatchOptions.magicalBraces} option is used,
20968
+ * then braces (`{` and `}`) will be escaped.
20950
20969
  */
20951
- const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
20970
+ const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false, } = {}) => {
20952
20971
  // don't need to escape +@! because we escape the parens
20953
20972
  // that make those magic, and escaping ! as [!] isn't valid,
20954
20973
  // because [!]] is a valid glob class meaning not ']'.
20974
+ if (magicalBraces) {
20975
+ return windowsPathsNoEscape
20976
+ ? s.replace(/[?*()[\]{}]/g, '[$&]')
20977
+ : s.replace(/[?*()[\]\\{}]/g, '\\$&');
20978
+ }
20955
20979
  return windowsPathsNoEscape
20956
20980
  ? s.replace(/[?*()[\]]/g, '[$&]')
20957
20981
  : s.replace(/[?*()[\]\\]/g, '\\$&');
@@ -21585,7 +21609,7 @@ class Minimatch {
21585
21609
  }
21586
21610
  }
21587
21611
  // resolve and reduce . and .. portions in the file as well.
21588
- // dont' need to do the second phase, because it's only one string[]
21612
+ // don't need to do the second phase, because it's only one string[]
21589
21613
  const { optimizationLevel = 1 } = this.options;
21590
21614
  if (optimizationLevel >= 2) {
21591
21615
  file = this.levelTwoFileOptimize(file);
@@ -21838,14 +21862,25 @@ class Minimatch {
21838
21862
  }
21839
21863
  }
21840
21864
  else if (next === undefined) {
21841
- pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?';
21865
+ pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?';
21842
21866
  }
21843
21867
  else if (next !== GLOBSTAR) {
21844
21868
  pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
21845
21869
  pp[i + 1] = GLOBSTAR;
21846
21870
  }
21847
21871
  });
21848
- return pp.filter(p => p !== GLOBSTAR).join('/');
21872
+ const filtered = pp.filter(p => p !== GLOBSTAR);
21873
+ // For partial matches, we need to make the pattern match
21874
+ // any prefix of the full path. We do this by generating
21875
+ // alternative patterns that match progressively longer prefixes.
21876
+ if (this.partial && filtered.length >= 1) {
21877
+ const prefixes = [];
21878
+ for (let i = 1; i <= filtered.length; i++) {
21879
+ prefixes.push(filtered.slice(0, i).join('/'));
21880
+ }
21881
+ return '(?:' + prefixes.join('|') + ')';
21882
+ }
21883
+ return filtered.join('/');
21849
21884
  })
21850
21885
  .join('|');
21851
21886
  // need to wrap in parens if we had more than one thing with |,
@@ -21854,6 +21889,10 @@ class Minimatch {
21854
21889
  // must match entire pattern
21855
21890
  // ending in a * or ** will make it less strict.
21856
21891
  re = '^' + open + re + close + '$';
21892
+ // In partial mode, '/' should always match as it's a valid prefix for any pattern
21893
+ if (this.partial) {
21894
+ re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$';
21895
+ }
21857
21896
  // can match anything, as long as it's not this.
21858
21897
  if (this.negate)
21859
21898
  re = '^(?!' + re + ').+$';
@@ -22124,13 +22163,9 @@ function typeElementsToMap(ctx, elements, scope = ctxToScope(ctx), typeParameter
22124
22163
  Object.assign(scope.types, typeParameters);
22125
22164
  }
22126
22165
  e._ownerScope = scope;
22127
- const name = getId(e.key);
22128
- if (name && !e.computed) {
22166
+ const name = getStringLiteralKey(e);
22167
+ if (name !== null) {
22129
22168
  res.props[name] = e;
22130
- } else if (e.key.type === "TemplateLiteral") {
22131
- for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
22132
- res.props[key] = e;
22133
- }
22134
22169
  } else {
22135
22170
  ctx.error(
22136
22171
  `Unsupported computed key in type referenced by a macro`,
@@ -22529,7 +22564,7 @@ function registerTS(_loadTS) {
22529
22564
  } catch (err) {
22530
22565
  if (typeof err.message === "string" && err.message.includes("Cannot find module")) {
22531
22566
  throw new Error(
22532
- 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "typescript" is installed as a project dependency.'
22567
+ 'Failed to load TypeScript, which is required for resolving imported types. Please make sure "TypeScript" is installed as a project dependency.'
22533
22568
  );
22534
22569
  } else {
22535
22570
  throw new Error(
@@ -22599,7 +22634,7 @@ function importSourceToScope(ctx, node, scope, source) {
22599
22634
  if (loadTS) ts = loadTS();
22600
22635
  if (!ts) {
22601
22636
  return ctx.error(
22602
- `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.`,
22637
+ `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.`,
22603
22638
  node,
22604
22639
  scope
22605
22640
  );
@@ -23015,6 +23050,9 @@ function recordImport(node, imports) {
23015
23050
  }
23016
23051
  }
23017
23052
  function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx), isKeyOf = false, typeParameters) {
23053
+ if (node.leadingComments && node.leadingComments.some((c) => c.value.includes("@vue-ignore"))) {
23054
+ return [UNKNOWN_TYPE];
23055
+ }
23018
23056
  try {
23019
23057
  switch (node.type) {
23020
23058
  case "TSStringKeyword":
@@ -23251,6 +23289,24 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
23251
23289
  typeParameters
23252
23290
  ).filter((t) => t !== UNKNOWN_TYPE);
23253
23291
  }
23292
+ case "TSMappedType": {
23293
+ const { typeAnnotation, typeParameter } = node;
23294
+ if (typeAnnotation && typeAnnotation.type === "TSIndexedAccessType" && typeParameter && typeParameter.constraint && typeParameters) {
23295
+ const constraint = typeParameter.constraint;
23296
+ if (constraint.type === "TSTypeOperator" && constraint.operator === "keyof" && constraint.typeAnnotation && constraint.typeAnnotation.type === "TSTypeReference" && constraint.typeAnnotation.typeName.type === "Identifier") {
23297
+ const typeName = constraint.typeAnnotation.typeName.name;
23298
+ const index = typeAnnotation.indexType;
23299
+ const obj = typeAnnotation.objectType;
23300
+ if (obj && obj.type === "TSTypeReference" && obj.typeName.type === "Identifier" && obj.typeName.name === typeName && index && index.type === "TSTypeReference" && index.typeName.type === "Identifier" && index.typeName.name === typeParameter.name) {
23301
+ const targetType = typeParameters[typeName];
23302
+ if (targetType) {
23303
+ return inferRuntimeType(ctx, targetType, scope);
23304
+ }
23305
+ }
23306
+ }
23307
+ }
23308
+ return [UNKNOWN_TYPE];
23309
+ }
23254
23310
  case "TSEnumDeclaration":
23255
23311
  return inferEnumType(node);
23256
23312
  case "TSSymbolKeyword":
@@ -23399,7 +23455,7 @@ function ctorToType(ctorType) {
23399
23455
  }
23400
23456
  function findStaticPropertyType(node, key) {
23401
23457
  const prop = node.members.find(
23402
- (m) => m.type === "TSPropertySignature" && !m.computed && getId(m.key) === key && m.typeAnnotation
23458
+ (m) => m.type === "TSPropertySignature" && getStringLiteralKey(m) === key && m.typeAnnotation
23403
23459
  );
23404
23460
  return prop && prop.typeAnnotation.typeAnnotation;
23405
23461
  }
@@ -24653,6 +24709,7 @@ let __temp${any}, __restore${any}
24653
24709
  }
24654
24710
  let templateMap;
24655
24711
  let returned;
24712
+ const propsDecl = genRuntimeProps(ctx);
24656
24713
  if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
24657
24714
  const allBindings = {
24658
24715
  ...scriptBindings,
@@ -24759,7 +24816,6 @@ return ${returned}
24759
24816
  runtimeOptions += `
24760
24817
  __ssrInlineRender: true,`;
24761
24818
  }
24762
- const propsDecl = genRuntimeProps(ctx);
24763
24819
  if (propsDecl) runtimeOptions += `
24764
24820
  props: ${propsDecl},`;
24765
24821
  const emitsDecl = genRuntimeEmits(ctx);
@@ -25027,7 +25083,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
25027
25083
  return generator.toJSON();
25028
25084
  }
25029
25085
 
25030
- const version = "3.5.21";
25086
+ const version = "3.5.23";
25031
25087
  const parseCache = parseCache$1;
25032
25088
  const errorMessages = {
25033
25089
  ...CompilerDOM.errorMessages,