@vue/compiler-sfc 3.6.0-rc.2 → 3.6.0-rc.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.6.0-rc.2
2
+ * @vue/compiler-sfc v3.6.0-rc.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -1305,6 +1305,18 @@ function createCache(max = 500) {
1305
1305
  return new LRUCache({ max });
1306
1306
  }
1307
1307
  //#endregion
1308
+ //#region packages/compiler-sfc/src/template/resolveTemplateAST.ts
1309
+ function resolveTemplateAST(inAST, options) {
1310
+ if (!(inAST === null || inAST === void 0 ? void 0 : inAST.transformed)) return inAST;
1311
+ const { compiler = _vue_compiler_dom, compilerOptions, ssr, onError } = options;
1312
+ return (0, _vue_compiler_core.createRoot)((ssr ? _vue_compiler_dom : compiler).parse(inAST.source, {
1313
+ prefixIdentifiers: true,
1314
+ ...compilerOptions,
1315
+ parseMode: "sfc",
1316
+ onError
1317
+ }).children.find((node) => node.type === 1 && node.tag === "template").children, inAST.source);
1318
+ }
1319
+ //#endregion
1308
1320
  //#region packages/compiler-sfc/src/script/importUsageCheck.ts
1309
1321
  /**
1310
1322
  * Check if an identifier is used in the SFC's template.
@@ -1312,23 +1324,28 @@ function createCache(max = 500) {
1312
1324
  * when not using inline mode.
1313
1325
  * - 2.check whether the built-in properties such as $attrs, $slots, $emit are used in the template
1314
1326
  */
1315
- function isUsedInTemplate(identifier, sfc) {
1316
- return resolveTemplateUsedIdentifiers(sfc).has(identifier);
1327
+ function isUsedInTemplate(identifier, sfc, options) {
1328
+ return resolveTemplateUsedIdentifiers(sfc, options).has(identifier);
1317
1329
  }
1318
1330
  const templateAnalysisCache = createCache();
1319
- function resolveTemplateVModelIdentifiers(sfc) {
1320
- return resolveTemplateAnalysisResult(sfc, false).vModelIds;
1331
+ function resolveTemplateVModelIdentifiers(sfc, options) {
1332
+ return resolveTemplateAnalysisResult(sfc, false, options).vModelIds;
1321
1333
  }
1322
- function resolveTemplateUsedIdentifiers(sfc) {
1323
- return resolveTemplateAnalysisResult(sfc).usedIds;
1334
+ function resolveTemplateUsedIdentifiers(sfc, options) {
1335
+ return resolveTemplateAnalysisResult(sfc, true, options).usedIds;
1324
1336
  }
1325
- function resolveTemplateAnalysisResult(sfc, collectUsedIds = true) {
1337
+ function resolveTemplateAnalysisResult(sfc, collectUsedIds = true, options) {
1326
1338
  const { content, ast } = sfc.template;
1327
1339
  const cached = templateAnalysisCache.get(content);
1328
1340
  if (cached && (!collectUsedIds || cached.usedIds)) return cached;
1329
1341
  const ids = collectUsedIds ? /* @__PURE__ */ new Set() : void 0;
1330
1342
  const vModelIds = /* @__PURE__ */ new Set();
1331
- ast.children.forEach(walk);
1343
+ resolveTemplateAST(ast, {
1344
+ compiler: options === null || options === void 0 ? void 0 : options.compiler,
1345
+ compilerOptions: options === null || options === void 0 ? void 0 : options.compilerOptions,
1346
+ ssr: options === null || options === void 0 ? void 0 : options.ssr,
1347
+ onError: () => {}
1348
+ }).children.forEach(walk);
1332
1349
  function walk(node) {
1333
1350
  switch (node.type) {
1334
1351
  case 1:
@@ -3296,12 +3313,12 @@ function doCompileTemplate({ filename, id, scoped, slotted, inMap, source, ast:
3296
3313
  const defaultCompiler = ssr ? _vue_compiler_ssr : vapor ? _vue_compiler_vapor : _vue_compiler_dom;
3297
3314
  compiler = compiler || defaultCompiler;
3298
3315
  if (compiler !== defaultCompiler) inAST = void 0;
3299
- if (inAST === null || inAST === void 0 ? void 0 : inAST.transformed) inAST = (0, _vue_compiler_core.createRoot)((ssr ? _vue_compiler_dom : compiler).parse(inAST.source, {
3300
- prefixIdentifiers: true,
3301
- ...compilerOptions,
3302
- parseMode: "sfc",
3316
+ inAST = resolveTemplateAST(inAST, {
3317
+ compiler,
3318
+ compilerOptions,
3319
+ ssr,
3303
3320
  onError: (e) => errors.push(e)
3304
- }).children.find((node) => node.type === 1 && node.tag === "template").children, inAST.source);
3321
+ });
3305
3322
  let { code, ast, preamble, map, helpers } = compiler.compile(inAST || source, {
3306
3323
  mode: "module",
3307
3324
  prefixIdentifiers: true,
@@ -12297,7 +12314,7 @@ const range = (a, b, str) => {
12297
12314
  return result;
12298
12315
  };
12299
12316
  //#endregion
12300
- //#region node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js
12317
+ //#region node_modules/.pnpm/brace-expansion@5.0.9/node_modules/brace-expansion/dist/esm/index.js
12301
12318
  const escSlash = "\0SLASH" + Math.random() + "\0";
12302
12319
  const escOpen = "\0OPEN" + Math.random() + "\0";
12303
12320
  const escClose = "\0CLOSE" + Math.random() + "\0";
@@ -12314,6 +12331,7 @@ const closePattern = /\\}/g;
12314
12331
  const commaPattern = /\\,/g;
12315
12332
  const periodPattern = /\\\./g;
12316
12333
  const EXPANSION_MAX = 1e5;
12334
+ const EXPANSION_MAX_LENGTH = 4e6;
12317
12335
  function numeric(str) {
12318
12336
  return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
12319
12337
  }
@@ -12346,9 +12364,9 @@ function parseCommaParts(str) {
12346
12364
  }
12347
12365
  function expand(str, options = {}) {
12348
12366
  if (!str) return [];
12349
- const { max = EXPANSION_MAX } = options;
12367
+ const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options;
12350
12368
  if (str.slice(0, 2) === "{}") str = "\\{\\}" + str.slice(2);
12351
- return expand_(escapeBraces(str), max, true).map(unescapeBraces);
12369
+ return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
12352
12370
  }
12353
12371
  function embrace(str) {
12354
12372
  return "{" + str + "}";
@@ -12362,18 +12380,73 @@ function lte(i, y) {
12362
12380
  function gte(i, y) {
12363
12381
  return i >= y;
12364
12382
  }
12365
- function expand_(str, max, isTop) {
12366
- /** @type {string[]} */
12367
- const expansions = [];
12368
- const m = balanced("{", "}", str);
12369
- if (!m) return [str];
12370
- const pre = m.pre;
12371
- const post = m.post.length ? expand_(m.post, max, false) : [""];
12372
- if (/\$$/.test(m.pre)) for (let k = 0; k < post.length && k < max; k++) {
12373
- const expansion = pre + "{" + m.body + "}" + post[k];
12374
- expansions.push(expansion);
12375
- }
12376
- else {
12383
+ function combine(acc, pre, values, max, maxLength, dropEmpties) {
12384
+ const out = [];
12385
+ let length = 0;
12386
+ for (let a = 0; a < acc.length; a++) for (let v = 0; v < values.length; v++) {
12387
+ if (out.length >= max) return out;
12388
+ const expansion = acc[a] + pre + values[v];
12389
+ if (dropEmpties && !expansion) continue;
12390
+ if (length + expansion.length > maxLength) return out;
12391
+ out.push(expansion);
12392
+ length += expansion.length;
12393
+ }
12394
+ return out;
12395
+ }
12396
+ function expandSequence(body, isAlphaSequence, max, maxLength) {
12397
+ const n = body.split(/\.\./);
12398
+ const N = [];
12399
+ /* c8 ignore start */
12400
+ if (n[0] === void 0 || n[1] === void 0) return N;
12401
+ /* c8 ignore stop */
12402
+ const x = numeric(n[0]);
12403
+ const y = numeric(n[1]);
12404
+ const width = Math.max(n[0].length, n[1].length);
12405
+ let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
12406
+ let test = lte;
12407
+ if (y < x) {
12408
+ incr *= -1;
12409
+ test = gte;
12410
+ }
12411
+ const pad = n.some(isPadded);
12412
+ let length = 0;
12413
+ for (let i = x; test(i, y) && N.length < max; i += incr) {
12414
+ let c;
12415
+ if (isAlphaSequence) {
12416
+ c = String.fromCharCode(i);
12417
+ if (c === "\\") c = "";
12418
+ } else {
12419
+ c = String(i);
12420
+ if (pad) {
12421
+ const need = width - c.length;
12422
+ if (need > 0) {
12423
+ const z = new Array(need + 1).join("0");
12424
+ if (i < 0) c = "-" + z + c.slice(1);
12425
+ else c = z + c;
12426
+ }
12427
+ }
12428
+ }
12429
+ if (length + c.length > maxLength) break;
12430
+ N.push(c);
12431
+ length += c.length;
12432
+ }
12433
+ return N;
12434
+ }
12435
+ function expand_(str, max, maxLength, isTop) {
12436
+ let acc = [""];
12437
+ let dropEmpties = false;
12438
+ let firstGroup = true;
12439
+ for (;;) {
12440
+ const m = balanced("{", "}", str);
12441
+ if (!m) return combine(acc, str, [""], max, maxLength, dropEmpties);
12442
+ const pre = m.pre;
12443
+ if (/\$$/.test(pre)) {
12444
+ acc = combine(acc, pre + "{" + m.body + "}", [""], max, maxLength, dropEmpties && !m.post.length);
12445
+ firstGroup = false;
12446
+ if (!m.post.length) break;
12447
+ str = m.post;
12448
+ continue;
12449
+ }
12377
12450
  const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
12378
12451
  const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
12379
12452
  const isSequence = isNumericSequence || isAlphaSequence;
@@ -12381,71 +12454,59 @@ function expand_(str, max, isTop) {
12381
12454
  if (!isSequence && !isOptions) {
12382
12455
  if (m.post.match(/,(?!,).*\}/)) {
12383
12456
  str = m.pre + "{" + m.body + escClose + m.post;
12384
- return expand_(str, max, true);
12457
+ isTop = true;
12458
+ continue;
12385
12459
  }
12386
- return [str];
12460
+ return combine(acc, pre + "{" + m.body + "}" + m.post, [""], max, maxLength, dropEmpties);
12461
+ }
12462
+ if (firstGroup) {
12463
+ dropEmpties = isTop && !isSequence;
12464
+ firstGroup = false;
12387
12465
  }
12388
- let n;
12389
- if (isSequence) n = m.body.split(/\.\./);
12466
+ let values;
12467
+ if (isSequence) values = expandSequence(m.body, isAlphaSequence, max, maxLength);
12390
12468
  else {
12391
- n = parseCommaParts(m.body);
12469
+ let n = parseCommaParts(m.body);
12392
12470
  if (n.length === 1 && n[0] !== void 0) {
12393
- n = expand_(n[0], max, false).map(embrace);
12471
+ n = expand_(n[0], max, maxLength, false).map(embrace);
12394
12472
  /* c8 ignore start */
12395
- if (n.length === 1) return post.map((p) => m.pre + n[0] + p);
12396
- }
12397
- }
12398
- let N;
12399
- if (isSequence && n[0] !== void 0 && n[1] !== void 0) {
12400
- const x = numeric(n[0]);
12401
- const y = numeric(n[1]);
12402
- const width = Math.max(n[0].length, n[1].length);
12403
- let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
12404
- let test = lte;
12405
- if (y < x) {
12406
- incr *= -1;
12407
- test = gte;
12408
- }
12409
- const pad = n.some(isPadded);
12410
- N = [];
12411
- for (let i = x; test(i, y); i += incr) {
12412
- let c;
12413
- if (isAlphaSequence) {
12414
- c = String.fromCharCode(i);
12415
- if (c === "\\") c = "";
12416
- } else {
12417
- c = String(i);
12418
- if (pad) {
12419
- const need = width - c.length;
12420
- if (need > 0) {
12421
- const z = new Array(need + 1).join("0");
12422
- if (i < 0) c = "-" + z + c.slice(1);
12423
- else c = z + c;
12424
- }
12425
- }
12473
+ if (n.length === 1) {
12474
+ acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
12475
+ if (!m.post.length) break;
12476
+ str = m.post;
12477
+ continue;
12478
+ }
12479
+ }
12480
+ let dropsEmpties = dropEmpties && !m.post.length && !pre;
12481
+ for (let d = 0; dropsEmpties && d < acc.length; d++) if (acc[d]) dropsEmpties = false;
12482
+ values = [];
12483
+ let valuesLength = 0;
12484
+ outer: for (let j = 0; j < n.length; j++) {
12485
+ const expanded = expand_(n[j], max, maxLength, false);
12486
+ for (let k = 0; k < expanded.length; k++) {
12487
+ const v = expanded[k];
12488
+ if (dropsEmpties && !v) continue;
12489
+ if (values.length >= max || valuesLength + v.length > maxLength) break outer;
12490
+ values.push(v);
12491
+ valuesLength += v.length;
12426
12492
  }
12427
- N.push(c);
12428
12493
  }
12429
- } else {
12430
- N = [];
12431
- for (let j = 0; j < n.length; j++) N.push.apply(N, expand_(n[j], max, false));
12432
- }
12433
- for (let j = 0; j < N.length; j++) for (let k = 0; k < post.length && expansions.length < max; k++) {
12434
- const expansion = pre + N[j] + post[k];
12435
- if (!isTop || isSequence || expansion) expansions.push(expansion);
12436
12494
  }
12495
+ acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
12496
+ if (!m.post.length) break;
12497
+ str = m.post;
12437
12498
  }
12438
- return expansions;
12499
+ return acc;
12439
12500
  }
12440
12501
  //#endregion
12441
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/assert-valid-pattern.js
12502
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/assert-valid-pattern.js
12442
12503
  const MAX_PATTERN_LENGTH = 1024 * 64;
12443
12504
  const assertValidPattern = (pattern) => {
12444
12505
  if (typeof pattern !== "string") throw new TypeError("invalid pattern");
12445
12506
  if (pattern.length > MAX_PATTERN_LENGTH) throw new TypeError("pattern is too long");
12446
12507
  };
12447
12508
  //#endregion
12448
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/brace-expressions.js
12509
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/brace-expressions.js
12449
12510
  const posixClasses = {
12450
12511
  "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
12451
12512
  "[:alpha:]": ["\\p{L}\\p{Nl}", true],
@@ -12566,7 +12627,7 @@ const parseClass = (glob, position) => {
12566
12627
  ];
12567
12628
  };
12568
12629
  //#endregion
12569
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/unescape.js
12630
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/unescape.js
12570
12631
  /**
12571
12632
  * Un-escape a string that has been escaped with {@link escape}.
12572
12633
  *
@@ -12591,7 +12652,7 @@ const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}
12591
12652
  return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
12592
12653
  };
12593
12654
  //#endregion
12594
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/ast.js
12655
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/ast.js
12595
12656
  var _AST;
12596
12657
  let _Symbol$for;
12597
12658
  var _a;
@@ -13125,7 +13186,7 @@ function _parseGlob(glob, hasMagic, noEmpty = false) {
13125
13186
  }
13126
13187
  _a = AST;
13127
13188
  //#endregion
13128
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/escape.js
13189
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/escape.js
13129
13190
  /**
13130
13191
  * Escape all magic characters in a glob pattern.
13131
13192
  *
@@ -13143,7 +13204,7 @@ const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {})
13143
13204
  return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
13144
13205
  };
13145
13206
  //#endregion
13146
- //#region node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js
13207
+ //#region node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/index.js
13147
13208
  const minimatch = (p, pattern, options = {}) => {
13148
13209
  assertValidPattern(pattern);
13149
13210
  if (!options.nocomment && pattern.charAt(0) === "#") return false;
@@ -14060,7 +14121,13 @@ function resolveTypeReference(ctx, node, scope, name, onlyExported = false) {
14060
14121
  return node._resolvedReference;
14061
14122
  }
14062
14123
  const resolved = innerResolveTypeReference(ctx, scope || ctxToScope(ctx), name || getReferenceName(node), node, onlyExported);
14063
- return canCache ? node._resolvedReference = resolved : resolved;
14124
+ if (canCache) Object.defineProperty(node, "_resolvedReference", {
14125
+ value: resolved,
14126
+ writable: true,
14127
+ configurable: true,
14128
+ enumerable: false
14129
+ });
14130
+ return resolved;
14064
14131
  }
14065
14132
  function innerResolveTypeReference(ctx, scope, name, node, onlyExported) {
14066
14133
  if (typeof name === "string") if (scope.imports[name]) return resolveTypeFromImport(ctx, node, name, scope);
@@ -15348,7 +15415,7 @@ function compileScript(sfc, options) {
15348
15415
  }
15349
15416
  function registerUserImport(source, local, imported, isType, isFromSetup, needTemplateUsageCheck) {
15350
15417
  let isImportUsed = needTemplateUsageCheck;
15351
- if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) isImportUsed = isUsedInTemplate(local, sfc);
15418
+ if (needTemplateUsageCheck && ctx.isTS && sfc.template && !sfc.template.src && !sfc.template.lang) isImportUsed = isUsedInTemplate(local, sfc, options.templateOptions);
15352
15419
  ctx.userImports[local] = {
15353
15420
  isType,
15354
15421
  imported,
@@ -15551,7 +15618,7 @@ function compileScript(sfc, options) {
15551
15618
  for (const key in scriptBindings) ctx.bindingMetadata[key] = scriptBindings[key];
15552
15619
  for (const key in setupBindings) ctx.bindingMetadata[key] = setupBindings[key];
15553
15620
  if (sfc.template && !sfc.template.src && sfc.template.ast) {
15554
- const vModelIds = resolveTemplateVModelIdentifiers(sfc);
15621
+ const vModelIds = resolveTemplateVModelIdentifiers(sfc, options.templateOptions);
15555
15622
  if (vModelIds.size) {
15556
15623
  const toDemote = /* @__PURE__ */ new Set();
15557
15624
  for (const id of vModelIds) if (setupBindings[id] === "setup-reactive-const") toDemote.add(id);
@@ -15812,7 +15879,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
15812
15879
  }
15813
15880
  //#endregion
15814
15881
  //#region packages/compiler-sfc/src/index.ts
15815
- const version = "3.6.0-rc.2";
15882
+ const version = "3.6.0-rc.3";
15816
15883
  const parseCache = parseCache$1;
15817
15884
  const errorMessages = {
15818
15885
  ..._vue_compiler_dom.errorMessages,