@vue/compiler-sfc 3.5.13 → 3.5.15

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.13
2
+ * @vue/compiler-sfc v3.5.15
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -4882,29 +4882,39 @@ function requireContainer$1 () {
4882
4882
  return this.removeAll();
4883
4883
  };
4884
4884
  _proto.insertAfter = function insertAfter(oldNode, newNode) {
4885
+ var _this$nodes;
4885
4886
  newNode.parent = this;
4886
4887
  var oldIndex = this.index(oldNode);
4887
- this.nodes.splice(oldIndex + 1, 0, newNode);
4888
+ var resetNode = [];
4889
+ for (var i = 2; i < arguments.length; i++) {
4890
+ resetNode.push(arguments[i]);
4891
+ }
4892
+ (_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
4888
4893
  newNode.parent = this;
4889
4894
  var index;
4890
4895
  for (var id in this.indexes) {
4891
4896
  index = this.indexes[id];
4892
4897
  if (oldIndex < index) {
4893
- this.indexes[id] = index + 1;
4898
+ this.indexes[id] = index + arguments.length - 1;
4894
4899
  }
4895
4900
  }
4896
4901
  return this;
4897
4902
  };
4898
4903
  _proto.insertBefore = function insertBefore(oldNode, newNode) {
4904
+ var _this$nodes2;
4899
4905
  newNode.parent = this;
4900
4906
  var oldIndex = this.index(oldNode);
4901
- this.nodes.splice(oldIndex, 0, newNode);
4907
+ var resetNode = [];
4908
+ for (var i = 2; i < arguments.length; i++) {
4909
+ resetNode.push(arguments[i]);
4910
+ }
4911
+ (_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
4902
4912
  newNode.parent = this;
4903
4913
  var index;
4904
4914
  for (var id in this.indexes) {
4905
4915
  index = this.indexes[id];
4906
4916
  if (index >= oldIndex) {
4907
- this.indexes[id] = index + 1;
4917
+ this.indexes[id] = index + arguments.length - 1;
4908
4918
  }
4909
4919
  }
4910
4920
  return this;
@@ -4930,7 +4940,7 @@ function requireContainer$1 () {
4930
4940
  * Return the most specific node at the line and column number given.
4931
4941
  * The source location is based on the original parsed location, locations aren't
4932
4942
  * updated as selector nodes are mutated.
4933
- *
4943
+ *
4934
4944
  * Note that this location is relative to the location of the first character
4935
4945
  * of the selector, and not the location of the selector in the overall document
4936
4946
  * when used in conjunction with postcss.
@@ -8029,6 +8039,7 @@ function processRule(id, rule) {
8029
8039
  }
8030
8040
  function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false) {
8031
8041
  let node = null;
8042
+ let starNode = null;
8032
8043
  let shouldInject = !deep;
8033
8044
  selector.each((n) => {
8034
8045
  if (n.type === "combinator" && (n.value === ">>>" || n.value === "/deep/")) {
@@ -8113,10 +8124,11 @@ function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false
8113
8124
  return false;
8114
8125
  }
8115
8126
  }
8116
- if (node) return;
8127
+ starNode = n;
8117
8128
  }
8118
- if (n.type !== "pseudo" && n.type !== "combinator" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
8129
+ if (n.type !== "pseudo" && n.type !== "combinator" && n.type !== "universal" || n.type === "pseudo" && (n.value === ":is" || n.value === ":where") && !node) {
8119
8130
  node = n;
8131
+ starNode = null;
8120
8132
  }
8121
8133
  });
8122
8134
  if (rule.nodes.some((node2) => node2.type === "rule")) {
@@ -8157,6 +8169,18 @@ function rewriteSelector(id, rule, selector, selectorRoot, deep, slotted = false
8157
8169
  quoteMark: `"`
8158
8170
  })
8159
8171
  );
8172
+ if (starNode) {
8173
+ selector.insertBefore(
8174
+ starNode,
8175
+ selectorParser.attribute({
8176
+ attribute: idToAdd,
8177
+ value: idToAdd,
8178
+ raws: {},
8179
+ quoteMark: `"`
8180
+ })
8181
+ );
8182
+ selector.removeChild(starNode);
8183
+ }
8160
8184
  }
8161
8185
  }
8162
8186
  function isSpaceCombinator(node) {
@@ -12056,8 +12080,6 @@ var hasRequiredLodash_camelcase;
12056
12080
  function requireLodash_camelcase () {
12057
12081
  if (hasRequiredLodash_camelcase) return lodash_camelcase;
12058
12082
  hasRequiredLodash_camelcase = 1;
12059
- /** Used as references for various `Number` constants. */
12060
- var INFINITY = 1 / 0;
12061
12083
 
12062
12084
  /** `Object#toString` result references. */
12063
12085
  var symbolTag = '[object Symbol]';
@@ -12393,7 +12415,7 @@ function requireLodash_camelcase () {
12393
12415
  return symbolToString ? symbolToString.call(value) : '';
12394
12416
  }
12395
12417
  var result = (value + '');
12396
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
12418
+ return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
12397
12419
  }
12398
12420
 
12399
12421
  /**
@@ -12408,7 +12430,7 @@ function requireLodash_camelcase () {
12408
12430
  function castSlice(array, start, end) {
12409
12431
  var length = array.length;
12410
12432
  end = end === undefined ? length : end;
12411
- return (!start && end >= length) ? array : baseSlice(array, start, end);
12433
+ return (false && end >= length) ? array : baseSlice(array, start, end);
12412
12434
  }
12413
12435
 
12414
12436
  /**
@@ -13161,7 +13183,7 @@ function requireWasmHash () {
13161
13183
  // 64 is the maximum chunk size for every possible wasm hash implementation
13162
13184
  // 4 is the maximum number of bytes per char for string encoding (max is utf-8)
13163
13185
  // ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
13164
- const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
13186
+ const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & -4;
13165
13187
 
13166
13188
  class WasmHash {
13167
13189
  /**
@@ -19796,7 +19818,7 @@ const ${as} = {}`);
19796
19818
  ast.forEach((node) => {
19797
19819
  if (node.type === "ExportDefaultDeclaration") {
19798
19820
  if (node.declaration.type === "ClassDeclaration" && node.declaration.id) {
19799
- let start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
19821
+ const start = node.declaration.decorators && node.declaration.decorators.length > 0 ? node.declaration.decorators[node.declaration.decorators.length - 1].end : node.start;
19800
19822
  s.overwrite(start, node.declaration.id.start, ` class `);
19801
19823
  s.append(`
19802
19824
  const ${as} = ${node.declaration.id.name}`);
@@ -20858,7 +20880,7 @@ class AST {
20858
20880
  return [s, unescape(this.toString()), false, false];
20859
20881
  }
20860
20882
  // XXX abstract out this map method
20861
- let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot
20883
+ let bodyDotAllowed = !repeated || allowDot || dot || false
20862
20884
  ? ''
20863
20885
  : this.#partsToRegExp(true);
20864
20886
  if (bodyDotAllowed === body) {
@@ -22560,13 +22582,13 @@ function resolveFS(ctx) {
22560
22582
  }
22561
22583
  return ctx.fs = {
22562
22584
  fileExists(file) {
22563
- if (file.endsWith(".vue.ts")) {
22585
+ if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
22564
22586
  file = file.replace(/\.ts$/, "");
22565
22587
  }
22566
22588
  return fs.fileExists(file);
22567
22589
  },
22568
22590
  readFile(file) {
22569
- if (file.endsWith(".vue.ts")) {
22591
+ if (file.endsWith(".vue.ts") && !file.endsWith(".d.vue.ts")) {
22570
22592
  file = file.replace(/\.ts$/, "");
22571
22593
  }
22572
22594
  return fs.readFile(file);
@@ -22694,7 +22716,7 @@ function resolveWithTS(containingFile, source, ts2, fs) {
22694
22716
  );
22695
22717
  if (res.resolvedModule) {
22696
22718
  let filename = res.resolvedModule.resolvedFileName;
22697
- if (filename.endsWith(".vue.ts")) {
22719
+ if (filename.endsWith(".vue.ts") && !filename.endsWith(".d.vue.ts")) {
22698
22720
  filename = filename.replace(/\.ts$/, "");
22699
22721
  }
22700
22722
  return fs.realpath ? fs.realpath(filename) : filename;
@@ -22738,13 +22760,13 @@ function fileToScope(ctx, filename, asGlobal = false) {
22738
22760
  }
22739
22761
  const fs = resolveFS(ctx);
22740
22762
  const source = fs.readFile(filename) || "";
22741
- const body = parseFile(filename, source, ctx.options.babelParserPlugins);
22763
+ const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
22742
22764
  const scope = new TypeScope(filename, source, 0, recordImports(body));
22743
22765
  recordTypes(ctx, body, scope, asGlobal);
22744
22766
  fileToScopeCache.set(filename, scope);
22745
22767
  return scope;
22746
22768
  }
22747
- function parseFile(filename, content, parserPlugins) {
22769
+ function parseFile(filename, content, fs, parserPlugins) {
22748
22770
  const ext = path$1.extname(filename);
22749
22771
  if (ext === ".ts" || ext === ".mts" || ext === ".tsx" || ext === ".mtsx") {
22750
22772
  return parser$2.parse(content, {
@@ -22755,7 +22777,17 @@ function parseFile(filename, content, parserPlugins) {
22755
22777
  ),
22756
22778
  sourceType: "module"
22757
22779
  }).program.body;
22758
- } else if (ext === ".vue") {
22780
+ }
22781
+ const isUnknownTypeSource = !/\.[cm]?[tj]sx?$/.test(filename);
22782
+ const arbitraryTypeSource = `${filename.slice(0, -ext.length)}.d${ext}.ts`;
22783
+ const hasArbitraryTypeDeclaration = isUnknownTypeSource && fs.fileExists(arbitraryTypeSource);
22784
+ if (hasArbitraryTypeDeclaration) {
22785
+ return parser$2.parse(fs.readFile(arbitraryTypeSource), {
22786
+ plugins: resolveParserPlugins("ts", parserPlugins, true),
22787
+ sourceType: "module"
22788
+ }).program.body;
22789
+ }
22790
+ if (ext === ".vue") {
22759
22791
  const {
22760
22792
  descriptor: { script, scriptSetup }
22761
22793
  } = parse$1(content);
@@ -23076,6 +23108,14 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
23076
23108
  case "TSTypeReference": {
23077
23109
  const resolved = resolveTypeReference(ctx, node, scope);
23078
23110
  if (resolved) {
23111
+ if (resolved.type === "TSTypeAliasDeclaration") {
23112
+ return inferRuntimeType(
23113
+ ctx,
23114
+ resolved.typeAnnotation,
23115
+ resolved._ownerScope,
23116
+ isKeyOf
23117
+ );
23118
+ }
23079
23119
  return inferRuntimeType(ctx, resolved, resolved._ownerScope, isKeyOf);
23080
23120
  }
23081
23121
  if (node.typeName.type === "Identifier") {
@@ -23390,6 +23430,12 @@ function processDefineModel(ctx, node, declId) {
23390
23430
  if (!isCallOf(node, DEFINE_MODEL)) {
23391
23431
  return false;
23392
23432
  }
23433
+ if (!declId) {
23434
+ ctx.error(
23435
+ "defineModel() must be assigned to a variable. For example: const model = defineModel()",
23436
+ node
23437
+ );
23438
+ }
23393
23439
  ctx.hasDefineModelCall = true;
23394
23440
  const type = node.typeParameters && node.typeParameters.params[0] || void 0;
23395
23441
  let modelName;
@@ -23926,7 +23972,7 @@ function transformDestructuredProps(ctx, vueImportAliases) {
23926
23972
  },
23927
23973
  leave(node, parent) {
23928
23974
  parent && parentStack.pop();
23929
- if (node.type === "BlockStatement" && !CompilerDOM.isFunctionType(parent) || CompilerDOM.isFunctionType(node)) {
23975
+ if (node.type === "BlockStatement" && !CompilerDOM.isFunctionType(parent) || CompilerDOM.isFunctionType(node) || node.type === "CatchClause") {
23930
23976
  popScope();
23931
23977
  }
23932
23978
  }
@@ -24600,6 +24646,7 @@ let __temp${any}, __restore${any}
24600
24646
  if (destructureElements.length) {
24601
24647
  args += `, { ${destructureElements.join(", ")} }`;
24602
24648
  }
24649
+ let templateMap;
24603
24650
  let returned;
24604
24651
  if (!options.inlineTemplate || !sfc.template && ctx.hasDefaultExportRender) {
24605
24652
  const allBindings = {
@@ -24628,7 +24675,7 @@ let __temp${any}, __restore${any}
24628
24675
  if (options.templateOptions && options.templateOptions.ssr) {
24629
24676
  hasInlinedSsrRenderFn = true;
24630
24677
  }
24631
- const { code, ast, preamble, tips, errors } = compileTemplate({
24678
+ const { code, ast, preamble, tips, errors, map: map2 } = compileTemplate({
24632
24679
  filename,
24633
24680
  ast: sfc.template.ast,
24634
24681
  source: sfc.template.content,
@@ -24645,6 +24692,7 @@ let __temp${any}, __restore${any}
24645
24692
  bindingMetadata: ctx.bindingMetadata
24646
24693
  }
24647
24694
  });
24695
+ templateMap = map2;
24648
24696
  if (tips.length) {
24649
24697
  tips.forEach(warnOnce);
24650
24698
  }
@@ -24761,16 +24809,23 @@ ${exposeCall}`
24761
24809
  `
24762
24810
  );
24763
24811
  }
24812
+ const content = ctx.s.toString();
24813
+ let map = options.sourceMap !== false ? ctx.s.generateMap({
24814
+ source: filename,
24815
+ hires: true,
24816
+ includeContent: true
24817
+ }) : void 0;
24818
+ if (templateMap && map) {
24819
+ const offset = content.indexOf(returned);
24820
+ const templateLineOffset = content.slice(0, offset).split(/\r?\n/).length - 1;
24821
+ map = mergeSourceMaps(map, templateMap, templateLineOffset);
24822
+ }
24764
24823
  return {
24765
24824
  ...scriptSetup,
24766
24825
  bindings: ctx.bindingMetadata,
24767
24826
  imports: ctx.userImports,
24768
- content: ctx.s.toString(),
24769
- map: options.sourceMap !== false ? ctx.s.generateMap({
24770
- source: filename,
24771
- hires: true,
24772
- includeContent: true
24773
- }) : void 0,
24827
+ content,
24828
+ map,
24774
24829
  scriptAst: scriptAst == null ? void 0 : scriptAst.body,
24775
24830
  scriptSetupAst: scriptSetupAst == null ? void 0 : scriptSetupAst.body,
24776
24831
  deps: ctx.deps ? [...ctx.deps] : void 0
@@ -24808,7 +24863,7 @@ function walkDeclaration(from, node, bindings, userImportAliases, hoistStatic, i
24808
24863
  } else if (isConst) {
24809
24864
  if (isCallOf(
24810
24865
  init,
24811
- (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === DEFINE_MODEL
24866
+ (m) => m === userImportAliases["ref"] || m === userImportAliases["computed"] || m === userImportAliases["shallowRef"] || m === userImportAliases["customRef"] || m === userImportAliases["toRef"] || m === userImportAliases["useTemplateRef"] || m === DEFINE_MODEL
24812
24867
  )) {
24813
24868
  bindingType = "setup-ref";
24814
24869
  } else {
@@ -24933,8 +24988,41 @@ function isStaticNode(node) {
24933
24988
  }
24934
24989
  return false;
24935
24990
  }
24991
+ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
24992
+ const generator = new sourceMapJs.SourceMapGenerator();
24993
+ const addMapping = (map, lineOffset = 0) => {
24994
+ const consumer = new sourceMapJs.SourceMapConsumer(map);
24995
+ consumer.sources.forEach((sourceFile) => {
24996
+ generator._sources.add(sourceFile);
24997
+ const sourceContent = consumer.sourceContentFor(sourceFile);
24998
+ if (sourceContent != null) {
24999
+ generator.setSourceContent(sourceFile, sourceContent);
25000
+ }
25001
+ });
25002
+ consumer.eachMapping((m) => {
25003
+ if (m.originalLine == null) return;
25004
+ generator.addMapping({
25005
+ generated: {
25006
+ line: m.generatedLine + lineOffset,
25007
+ column: m.generatedColumn
25008
+ },
25009
+ original: {
25010
+ line: m.originalLine,
25011
+ column: m.originalColumn
25012
+ },
25013
+ source: m.source,
25014
+ name: m.name
25015
+ });
25016
+ });
25017
+ };
25018
+ addMapping(scriptMap);
25019
+ addMapping(templateMap, templateLineOffset);
25020
+ generator._sourceRoot = scriptMap.sourceRoot;
25021
+ generator._file = scriptMap.file;
25022
+ return generator.toJSON();
25023
+ }
24936
25024
 
24937
- const version = "3.5.13";
25025
+ const version = "3.5.15";
24938
25026
  const parseCache = parseCache$1;
24939
25027
  const errorMessages = {
24940
25028
  ...CompilerDOM.errorMessages,
@@ -1,6 +1,6 @@
1
1
  import * as _babel_types from '@babel/types';
2
2
  import { Statement, Expression, TSType, Node, Program, CallExpression, ObjectPattern, TSModuleDeclaration, TSPropertySignature, TSMethodSignature, TSCallSignatureDeclaration, TSFunctionType } from '@babel/types';
3
- import { RootNode, CompilerOptions, CodegenResult, ParserOptions, CompilerError, RawSourceMap, SourceLocation, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core';
3
+ import { RootNode, CompilerOptions, CodegenResult, ParserOptions, RawSourceMap, CompilerError, SourceLocation, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core';
4
4
  export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core';
5
5
  import { ParserPlugin } from '@babel/parser';
6
6
  export { parse as babelParse } from '@babel/parser';
@@ -482,3 +482,4 @@ export declare const walk: any;
482
482
  */
483
483
  export declare const shouldTransformRef: () => boolean;
484
484
 
485
+