@vue/compiler-sfc 3.5.0-beta.1 → 3.5.0-beta.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.5.0-beta.1
2
+ * @vue/compiler-sfc v3.5.0-beta.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -1831,8 +1831,7 @@ function parse$2(source, options = {}) {
1831
1831
  pad = false,
1832
1832
  ignoreEmpty = true,
1833
1833
  compiler = CompilerDOM__namespace,
1834
- templateParseOptions = {},
1835
- parseExpressions = true
1834
+ templateParseOptions = {}
1836
1835
  } = options;
1837
1836
  const descriptor = {
1838
1837
  filename,
@@ -1849,7 +1848,7 @@ function parse$2(source, options = {}) {
1849
1848
  const errors = [];
1850
1849
  const ast = compiler.parse(source, {
1851
1850
  parseMode: "sfc",
1852
- prefixIdentifiers: parseExpressions,
1851
+ prefixIdentifiers: true,
1853
1852
  ...templateParseOptions,
1854
1853
  onError: (e) => {
1855
1854
  errors.push(e);
@@ -6941,7 +6940,7 @@ tokenTypes.combinator = combinator$1;
6941
6940
  }
6942
6941
  // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
6943
6942
  var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
6944
- if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma) {
6943
+ if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
6945
6944
  var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
6946
6945
  if (nodes.length > 0) {
6947
6946
  var last = this.current.last;
@@ -17974,6 +17973,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
17974
17973
  );
17975
17974
  }
17976
17975
  case "TSExpressionWithTypeArguments":
17976
+ // referenced by interface extends
17977
17977
  case "TSTypeReference": {
17978
17978
  const typeName = getReferenceName(node);
17979
17979
  if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
@@ -19022,6 +19022,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19022
19022
  case "ConstructorParameters":
19023
19023
  case "ReadonlyArray":
19024
19024
  return ["String", "Number"];
19025
+ // TS built-in utility types
19025
19026
  case "Record":
19026
19027
  case "Partial":
19027
19028
  case "Required":
@@ -19075,6 +19076,8 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19075
19076
  case "Promise":
19076
19077
  case "Error":
19077
19078
  return [node.typeName.name];
19079
+ // TS built-in utility types
19080
+ // https://www.typescriptlang.org/docs/handbook/utility-types.html
19078
19081
  case "Partial":
19079
19082
  case "Required":
19080
19083
  case "Readonly":
@@ -19144,7 +19147,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19144
19147
  return ["Symbol"];
19145
19148
  case "TSIndexedAccessType": {
19146
19149
  const types = resolveIndexType(ctx, node, scope);
19147
- return flattenTypes(ctx, types, scope);
19150
+ return flattenTypes(ctx, types, scope, isKeyOf);
19148
19151
  }
19149
19152
  case "ClassDeclaration":
19150
19153
  return ["Object"];
@@ -19171,6 +19174,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
19171
19174
  }
19172
19175
  break;
19173
19176
  }
19177
+ // e.g. readonly
19174
19178
  case "TSTypeOperator": {
19175
19179
  return inferRuntimeType(
19176
19180
  ctx,
@@ -20836,12 +20840,14 @@ function isStaticNode(node) {
20836
20840
  case "UnaryExpression":
20837
20841
  return isStaticNode(node.argument);
20838
20842
  case "LogicalExpression":
20843
+ // 1 > 2
20839
20844
  case "BinaryExpression":
20840
20845
  return isStaticNode(node.left) && isStaticNode(node.right);
20841
20846
  case "ConditionalExpression": {
20842
20847
  return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
20843
20848
  }
20844
20849
  case "SequenceExpression":
20850
+ // (1, 2)
20845
20851
  case "TemplateLiteral":
20846
20852
  return node.expressions.every((expr) => isStaticNode(expr));
20847
20853
  case "ParenthesizedExpression":
@@ -20856,7 +20862,7 @@ function isStaticNode(node) {
20856
20862
  return false;
20857
20863
  }
20858
20864
 
20859
- const version = "3.5.0-beta.1";
20865
+ const version = "3.5.0-beta.3";
20860
20866
  const parseCache = parseCache$1;
20861
20867
  const errorMessages = {
20862
20868
  ...CompilerDOM.errorMessages,
@@ -160,11 +160,6 @@ export interface SFCParseOptions {
160
160
  ignoreEmpty?: boolean;
161
161
  compiler?: TemplateCompiler;
162
162
  templateParseOptions?: ParserOptions;
163
- /**
164
- * TODO remove in 3.5
165
- * @deprecated use `templateParseOptions: { prefixIdentifiers: false }` instead
166
- */
167
- parseExpressions?: boolean;
168
163
  }
169
164
  export interface SFCBlock {
170
165
  type: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-sfc v3.5.0-beta.1
2
+ * @vue/compiler-sfc v3.5.0-beta.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -764,13 +764,13 @@ const decodeMap = new Map([
764
764
  * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point.
765
765
  */
766
766
  const fromCodePoint =
767
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, n/no-unsupported-features/es-builtins
767
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
768
768
  (_a$1 = String.fromCodePoint) !== null && _a$1 !== void 0 ? _a$1 : function (codePoint) {
769
769
  let output = "";
770
- if (codePoint > 65535) {
771
- codePoint -= 65536;
772
- output += String.fromCharCode(((codePoint >>> 10) & 1023) | 55296);
773
- codePoint = 56320 | (codePoint & 1023);
770
+ if (codePoint > 0xffff) {
771
+ codePoint -= 0x10000;
772
+ output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
773
+ codePoint = 0xdc00 | (codePoint & 0x3ff);
774
774
  }
775
775
  output += String.fromCharCode(codePoint);
776
776
  return output;
@@ -782,9 +782,8 @@ const fromCodePoint =
782
782
  */
783
783
  function replaceCodePoint(codePoint) {
784
784
  var _a;
785
- if ((codePoint >= 55296 && codePoint <= 57343) ||
786
- codePoint > 1114111) {
787
- return 65533;
785
+ if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
786
+ return 0xfffd;
788
787
  }
789
788
  return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
790
789
  }
@@ -805,7 +804,7 @@ var CharCodes;
805
804
  CharCodes[CharCodes["UPPER_Z"] = 90] = "UPPER_Z";
806
805
  })(CharCodes || (CharCodes = {}));
807
806
  /** Bit that needs to be set to convert an upper case ASCII character to lower case */
808
- const TO_LOWER_BIT = 32;
807
+ const TO_LOWER_BIT = 0b100000;
809
808
  var BinTrieFlags;
810
809
  (function (BinTrieFlags) {
811
810
  BinTrieFlags[BinTrieFlags["VALUE_LENGTH"] = 49152] = "VALUE_LENGTH";
@@ -906,32 +905,32 @@ class EntityDecoder {
906
905
  * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the
907
906
  * entity is incomplete, and resume when the next string is written.
908
907
  *
909
- * @param input The string containing the entity (or a continuation of the entity).
908
+ * @param string The string containing the entity (or a continuation of the entity).
910
909
  * @param offset The offset at which the entity begins. Should be 0 if this is not the first call.
911
910
  * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
912
911
  */
913
- write(input, offset) {
912
+ write(str, offset) {
914
913
  switch (this.state) {
915
914
  case EntityDecoderState.EntityStart: {
916
- if (input.charCodeAt(offset) === CharCodes.NUM) {
915
+ if (str.charCodeAt(offset) === CharCodes.NUM) {
917
916
  this.state = EntityDecoderState.NumericStart;
918
917
  this.consumed += 1;
919
- return this.stateNumericStart(input, offset + 1);
918
+ return this.stateNumericStart(str, offset + 1);
920
919
  }
921
920
  this.state = EntityDecoderState.NamedEntity;
922
- return this.stateNamedEntity(input, offset);
921
+ return this.stateNamedEntity(str, offset);
923
922
  }
924
923
  case EntityDecoderState.NumericStart: {
925
- return this.stateNumericStart(input, offset);
924
+ return this.stateNumericStart(str, offset);
926
925
  }
927
926
  case EntityDecoderState.NumericDecimal: {
928
- return this.stateNumericDecimal(input, offset);
927
+ return this.stateNumericDecimal(str, offset);
929
928
  }
930
929
  case EntityDecoderState.NumericHex: {
931
- return this.stateNumericHex(input, offset);
930
+ return this.stateNumericHex(str, offset);
932
931
  }
933
932
  case EntityDecoderState.NamedEntity: {
934
- return this.stateNamedEntity(input, offset);
933
+ return this.stateNamedEntity(str, offset);
935
934
  }
936
935
  }
937
936
  }
@@ -940,28 +939,28 @@ class EntityDecoder {
940
939
  *
941
940
  * Equivalent to the `Numeric character reference state` in the HTML spec.
942
941
  *
943
- * @param input The string containing the entity (or a continuation of the entity).
942
+ * @param str The string containing the entity (or a continuation of the entity).
944
943
  * @param offset The current offset.
945
944
  * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
946
945
  */
947
- stateNumericStart(input, offset) {
948
- if (offset >= input.length) {
946
+ stateNumericStart(str, offset) {
947
+ if (offset >= str.length) {
949
948
  return -1;
950
949
  }
951
- if ((input.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
950
+ if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) {
952
951
  this.state = EntityDecoderState.NumericHex;
953
952
  this.consumed += 1;
954
- return this.stateNumericHex(input, offset + 1);
953
+ return this.stateNumericHex(str, offset + 1);
955
954
  }
956
955
  this.state = EntityDecoderState.NumericDecimal;
957
- return this.stateNumericDecimal(input, offset);
956
+ return this.stateNumericDecimal(str, offset);
958
957
  }
959
- addToNumericResult(input, start, end, base) {
958
+ addToNumericResult(str, start, end, base) {
960
959
  if (start !== end) {
961
960
  const digitCount = end - start;
962
961
  this.result =
963
962
  this.result * Math.pow(base, digitCount) +
964
- Number.parseInt(input.substr(start, digitCount), base);
963
+ parseInt(str.substr(start, digitCount), base);
965
964
  this.consumed += digitCount;
966
965
  }
967
966
  }
@@ -970,23 +969,23 @@ class EntityDecoder {
970
969
  *
971
970
  * Equivalent to the `Hexademical character reference state` in the HTML spec.
972
971
  *
973
- * @param input The string containing the entity (or a continuation of the entity).
972
+ * @param str The string containing the entity (or a continuation of the entity).
974
973
  * @param offset The current offset.
975
974
  * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
976
975
  */
977
- stateNumericHex(input, offset) {
978
- const startIndex = offset;
979
- while (offset < input.length) {
980
- const char = input.charCodeAt(offset);
976
+ stateNumericHex(str, offset) {
977
+ const startIdx = offset;
978
+ while (offset < str.length) {
979
+ const char = str.charCodeAt(offset);
981
980
  if (isNumber$2(char) || isHexadecimalCharacter(char)) {
982
981
  offset += 1;
983
982
  }
984
983
  else {
985
- this.addToNumericResult(input, startIndex, offset, 16);
984
+ this.addToNumericResult(str, startIdx, offset, 16);
986
985
  return this.emitNumericEntity(char, 3);
987
986
  }
988
987
  }
989
- this.addToNumericResult(input, startIndex, offset, 16);
988
+ this.addToNumericResult(str, startIdx, offset, 16);
990
989
  return -1;
991
990
  }
992
991
  /**
@@ -994,23 +993,23 @@ class EntityDecoder {
994
993
  *
995
994
  * Equivalent to the `Decimal character reference state` in the HTML spec.
996
995
  *
997
- * @param input The string containing the entity (or a continuation of the entity).
996
+ * @param str The string containing the entity (or a continuation of the entity).
998
997
  * @param offset The current offset.
999
998
  * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
1000
999
  */
1001
- stateNumericDecimal(input, offset) {
1002
- const startIndex = offset;
1003
- while (offset < input.length) {
1004
- const char = input.charCodeAt(offset);
1000
+ stateNumericDecimal(str, offset) {
1001
+ const startIdx = offset;
1002
+ while (offset < str.length) {
1003
+ const char = str.charCodeAt(offset);
1005
1004
  if (isNumber$2(char)) {
1006
1005
  offset += 1;
1007
1006
  }
1008
1007
  else {
1009
- this.addToNumericResult(input, startIndex, offset, 10);
1008
+ this.addToNumericResult(str, startIdx, offset, 10);
1010
1009
  return this.emitNumericEntity(char, 2);
1011
1010
  }
1012
1011
  }
1013
- this.addToNumericResult(input, startIndex, offset, 10);
1012
+ this.addToNumericResult(str, startIdx, offset, 10);
1014
1013
  return -1;
1015
1014
  }
1016
1015
  /**
@@ -1054,17 +1053,17 @@ class EntityDecoder {
1054
1053
  *
1055
1054
  * Equivalent to the `Named character reference state` in the HTML spec.
1056
1055
  *
1057
- * @param input The string containing the entity (or a continuation of the entity).
1056
+ * @param str The string containing the entity (or a continuation of the entity).
1058
1057
  * @param offset The current offset.
1059
1058
  * @returns The number of characters that were consumed, or -1 if the entity is incomplete.
1060
1059
  */
1061
- stateNamedEntity(input, offset) {
1060
+ stateNamedEntity(str, offset) {
1062
1061
  const { decodeTree } = this;
1063
1062
  let current = decodeTree[this.treeIndex];
1064
1063
  // The mask is the number of bytes of the value, including the current byte.
1065
1064
  let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14;
1066
- for (; offset < input.length; offset++, this.excess++) {
1067
- const char = input.charCodeAt(offset);
1065
+ for (; offset < str.length; offset++, this.excess++) {
1066
+ const char = str.charCodeAt(offset);
1068
1067
  this.treeIndex = determineBranch(decodeTree, current, this.treeIndex + Math.max(1, valueLength), char);
1069
1068
  if (this.treeIndex < 0) {
1070
1069
  return this.result === 0 ||
@@ -1171,28 +1170,28 @@ class EntityDecoder {
1171
1170
  * @returns A function that decodes entities in a string.
1172
1171
  */
1173
1172
  function getDecoder(decodeTree) {
1174
- let returnValue = "";
1175
- const decoder = new EntityDecoder(decodeTree, (data) => (returnValue += fromCodePoint(data)));
1176
- return function decodeWithTrie(input, decodeMode) {
1173
+ let ret = "";
1174
+ const decoder = new EntityDecoder(decodeTree, (str) => (ret += fromCodePoint(str)));
1175
+ return function decodeWithTrie(str, decodeMode) {
1177
1176
  let lastIndex = 0;
1178
1177
  let offset = 0;
1179
- while ((offset = input.indexOf("&", offset)) >= 0) {
1180
- returnValue += input.slice(lastIndex, offset);
1178
+ while ((offset = str.indexOf("&", offset)) >= 0) {
1179
+ ret += str.slice(lastIndex, offset);
1181
1180
  decoder.startEntity(decodeMode);
1182
- const length = decoder.write(input,
1181
+ const len = decoder.write(str,
1183
1182
  // Skip the "&"
1184
1183
  offset + 1);
1185
- if (length < 0) {
1184
+ if (len < 0) {
1186
1185
  lastIndex = offset + decoder.end();
1187
1186
  break;
1188
1187
  }
1189
- lastIndex = offset + length;
1190
- // If `length` is 0, skip the current `&` and continue.
1191
- offset = length === 0 ? lastIndex + 1 : lastIndex;
1188
+ lastIndex = offset + len;
1189
+ // If `len` is 0, skip the current `&` and continue.
1190
+ offset = len === 0 ? lastIndex + 1 : lastIndex;
1192
1191
  }
1193
- const result = returnValue + input.slice(lastIndex);
1192
+ const result = ret + str.slice(lastIndex);
1194
1193
  // Make sure we don't keep a reference to the final string.
1195
- returnValue = "";
1194
+ ret = "";
1196
1195
  return result;
1197
1196
  };
1198
1197
  }
@@ -1206,31 +1205,31 @@ function getDecoder(decodeTree) {
1206
1205
  * @param char The current character.
1207
1206
  * @returns The index of the next node, or -1 if no branch is taken.
1208
1207
  */
1209
- function determineBranch(decodeTree, current, nodeIndex, char) {
1208
+ function determineBranch(decodeTree, current, nodeIdx, char) {
1210
1209
  const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7;
1211
1210
  const jumpOffset = current & BinTrieFlags.JUMP_TABLE;
1212
1211
  // Case 1: Single branch encoded in jump offset
1213
1212
  if (branchCount === 0) {
1214
- return jumpOffset !== 0 && char === jumpOffset ? nodeIndex : -1;
1213
+ return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1;
1215
1214
  }
1216
1215
  // Case 2: Multiple branches encoded in jump table
1217
1216
  if (jumpOffset) {
1218
1217
  const value = char - jumpOffset;
1219
1218
  return value < 0 || value >= branchCount
1220
1219
  ? -1
1221
- : decodeTree[nodeIndex + value] - 1;
1220
+ : decodeTree[nodeIdx + value] - 1;
1222
1221
  }
1223
1222
  // Case 3: Multiple branches encoded in dictionary
1224
1223
  // Binary search for the character.
1225
- let lo = nodeIndex;
1224
+ let lo = nodeIdx;
1226
1225
  let hi = lo + branchCount - 1;
1227
1226
  while (lo <= hi) {
1228
1227
  const mid = (lo + hi) >>> 1;
1229
- const midValue = decodeTree[mid];
1230
- if (midValue < char) {
1228
+ const midVal = decodeTree[mid];
1229
+ if (midVal < char) {
1231
1230
  lo = mid + 1;
1232
1231
  }
1233
- else if (midValue > char) {
1232
+ else if (midVal > char) {
1234
1233
  hi = mid - 1;
1235
1234
  }
1236
1235
  else {
@@ -1244,12 +1243,12 @@ getDecoder(xmlDecodeTree);
1244
1243
  /**
1245
1244
  * Decodes an HTML string.
1246
1245
  *
1247
- * @param htmlString The string to decode.
1246
+ * @param str The string to decode.
1248
1247
  * @param mode The decoding mode.
1249
1248
  * @returns The decoded string.
1250
1249
  */
1251
- function decodeHTML(htmlString, mode = DecodingMode.Legacy) {
1252
- return htmlDecoder(htmlString, mode);
1250
+ function decodeHTML(str, mode = DecodingMode.Legacy) {
1251
+ return htmlDecoder(str, mode);
1253
1252
  }
1254
1253
 
1255
1254
  const defaultDelimitersOpen = new Uint8Array([123, 123]);
@@ -16797,6 +16796,9 @@ const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || no
16797
16796
  const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
16798
16797
  function isReferenced(node, parent, grandparent) {
16799
16798
  switch (parent.type) {
16799
+ // yes: PARENT[NODE]
16800
+ // yes: NODE.child
16801
+ // no: parent.NODE
16800
16802
  case "MemberExpression":
16801
16803
  case "OptionalMemberExpression":
16802
16804
  if (parent.property === node) {
@@ -16805,12 +16807,23 @@ function isReferenced(node, parent, grandparent) {
16805
16807
  return parent.object === node;
16806
16808
  case "JSXMemberExpression":
16807
16809
  return parent.object === node;
16810
+ // no: let NODE = init;
16811
+ // yes: let id = NODE;
16808
16812
  case "VariableDeclarator":
16809
16813
  return parent.init === node;
16814
+ // yes: () => NODE
16815
+ // no: (NODE) => {}
16810
16816
  case "ArrowFunctionExpression":
16811
16817
  return parent.body === node;
16818
+ // no: class { #NODE; }
16819
+ // no: class { get #NODE() {} }
16820
+ // no: class { #NODE() {} }
16821
+ // no: class { fn() { return this.#NODE; } }
16812
16822
  case "PrivateName":
16813
16823
  return false;
16824
+ // no: class { NODE() {} }
16825
+ // yes: class { [NODE]() {} }
16826
+ // no: class { foo(NODE) {} }
16814
16827
  case "ClassMethod":
16815
16828
  case "ClassPrivateMethod":
16816
16829
  case "ObjectMethod":
@@ -16818,11 +16831,18 @@ function isReferenced(node, parent, grandparent) {
16818
16831
  return !!parent.computed;
16819
16832
  }
16820
16833
  return false;
16834
+ // yes: { [NODE]: "" }
16835
+ // no: { NODE: "" }
16836
+ // depends: { NODE }
16837
+ // depends: { key: NODE }
16821
16838
  case "ObjectProperty":
16822
16839
  if (parent.key === node) {
16823
16840
  return !!parent.computed;
16824
16841
  }
16825
16842
  return !grandparent;
16843
+ // no: class { NODE = value; }
16844
+ // yes: class { [NODE] = value; }
16845
+ // yes: class { key = NODE; }
16826
16846
  case "ClassProperty":
16827
16847
  if (parent.key === node) {
16828
16848
  return !!parent.computed;
@@ -16830,47 +16850,80 @@ function isReferenced(node, parent, grandparent) {
16830
16850
  return true;
16831
16851
  case "ClassPrivateProperty":
16832
16852
  return parent.key !== node;
16853
+ // no: class NODE {}
16854
+ // yes: class Foo extends NODE {}
16833
16855
  case "ClassDeclaration":
16834
16856
  case "ClassExpression":
16835
16857
  return parent.superClass === node;
16858
+ // yes: left = NODE;
16859
+ // no: NODE = right;
16836
16860
  case "AssignmentExpression":
16837
16861
  return parent.right === node;
16862
+ // no: [NODE = foo] = [];
16863
+ // yes: [foo = NODE] = [];
16838
16864
  case "AssignmentPattern":
16839
16865
  return parent.right === node;
16866
+ // no: NODE: for (;;) {}
16840
16867
  case "LabeledStatement":
16841
16868
  return false;
16869
+ // no: try {} catch (NODE) {}
16842
16870
  case "CatchClause":
16843
16871
  return false;
16872
+ // no: function foo(...NODE) {}
16844
16873
  case "RestElement":
16845
16874
  return false;
16846
16875
  case "BreakStatement":
16847
16876
  case "ContinueStatement":
16848
16877
  return false;
16878
+ // no: function NODE() {}
16879
+ // no: function foo(NODE) {}
16849
16880
  case "FunctionDeclaration":
16850
16881
  case "FunctionExpression":
16851
16882
  return false;
16883
+ // no: export NODE from "foo";
16884
+ // no: export * as NODE from "foo";
16852
16885
  case "ExportNamespaceSpecifier":
16853
16886
  case "ExportDefaultSpecifier":
16854
16887
  return false;
16888
+ // no: export { foo as NODE };
16889
+ // yes: export { NODE as foo };
16890
+ // no: export { NODE as foo } from "foo";
16855
16891
  case "ExportSpecifier":
16856
16892
  return parent.local === node;
16893
+ // no: import NODE from "foo";
16894
+ // no: import * as NODE from "foo";
16895
+ // no: import { NODE as foo } from "foo";
16896
+ // no: import { foo as NODE } from "foo";
16897
+ // no: import NODE from "bar";
16857
16898
  case "ImportDefaultSpecifier":
16858
16899
  case "ImportNamespaceSpecifier":
16859
16900
  case "ImportSpecifier":
16860
16901
  return false;
16902
+ // no: import "foo" assert { NODE: "json" }
16861
16903
  case "ImportAttribute":
16862
16904
  return false;
16905
+ // no: <div NODE="foo" />
16863
16906
  case "JSXAttribute":
16864
16907
  return false;
16908
+ // no: [NODE] = [];
16909
+ // no: ({ NODE }) = [];
16865
16910
  case "ObjectPattern":
16866
16911
  case "ArrayPattern":
16867
16912
  return false;
16913
+ // no: new.NODE
16914
+ // no: NODE.target
16868
16915
  case "MetaProperty":
16869
16916
  return false;
16917
+ // yes: type X = { someProperty: NODE }
16918
+ // no: type X = { NODE: OtherType }
16870
16919
  case "ObjectTypeProperty":
16871
16920
  return parent.key !== node;
16921
+ // yes: enum X { Foo = NODE }
16922
+ // no: enum X { NODE }
16872
16923
  case "TSEnumMember":
16873
16924
  return parent.id !== node;
16925
+ // yes: { [NODE]: value }
16926
+ // no: { NODE: value }
16874
16927
  case "TSPropertySignature":
16875
16928
  if (parent.key === node) {
16876
16929
  return !!parent.computed;
@@ -16921,8 +16974,9 @@ const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
16921
16974
  const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
16922
16975
  const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
16923
16976
  const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
16924
- const isMemberExpressionBrowser = (path) => {
16925
- path = path.trim().replace(whitespaceRE, (s) => s.trim());
16977
+ const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
16978
+ const isMemberExpressionBrowser = (exp) => {
16979
+ const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
16926
16980
  let state = 0 /* inMemberExp */;
16927
16981
  let stateStack = [];
16928
16982
  let currentOpenBracketCount = 0;
@@ -16983,10 +17037,10 @@ const isMemberExpressionBrowser = (path) => {
16983
17037
  }
16984
17038
  return !currentOpenBracketCount && !currentOpenParensCount;
16985
17039
  };
16986
- const isMemberExpressionNode = (path, context) => {
17040
+ const isMemberExpressionNode = (exp, context) => {
16987
17041
  try {
16988
- let ret = parseExpression_1(path, {
16989
- plugins: context.expressionPlugins
17042
+ let ret = exp.ast || parseExpression_1(getExpSource(exp), {
17043
+ plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
16990
17044
  });
16991
17045
  ret = unwrapTSNode(ret);
16992
17046
  return ret.type === "MemberExpression" || ret.type === "OptionalMemberExpression" || ret.type === "Identifier" && ret.name !== "undefined";
@@ -16995,6 +17049,26 @@ const isMemberExpressionNode = (path, context) => {
16995
17049
  }
16996
17050
  };
16997
17051
  const isMemberExpression = isMemberExpressionNode;
17052
+ const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
17053
+ const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
17054
+ const isFnExpressionNode = (exp, context) => {
17055
+ try {
17056
+ let ret = exp.ast || parseExpression_1(getExpSource(exp), {
17057
+ plugins: context.expressionPlugins ? [...context.expressionPlugins, "typescript"] : ["typescript"]
17058
+ });
17059
+ if (ret.type === "Program") {
17060
+ ret = ret.body[0];
17061
+ if (ret.type === "ExpressionStatement") {
17062
+ ret = ret.expression;
17063
+ }
17064
+ }
17065
+ ret = unwrapTSNode(ret);
17066
+ return ret.type === "FunctionExpression" || ret.type === "ArrowFunctionExpression";
17067
+ } catch (e) {
17068
+ return false;
17069
+ }
17070
+ };
17071
+ const isFnExpression = isFnExpressionNode;
16998
17072
  function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
16999
17073
  return advancePositionWithMutation(
17000
17074
  {
@@ -17499,7 +17573,9 @@ const tokenizer$2 = new Tokenizer$1(stack, {
17499
17573
  case 17:
17500
17574
  case 18:
17501
17575
  case 19:
17576
+ // "
17502
17577
  case 20:
17578
+ // '
17503
17579
  case 21:
17504
17580
  emitError(9, end);
17505
17581
  break;
@@ -18448,6 +18524,7 @@ function traverseNode(node, context) {
18448
18524
  context.helper(TO_DISPLAY_STRING);
18449
18525
  }
18450
18526
  break;
18527
+ // for container types, further traverse downwards
18451
18528
  case 9:
18452
18529
  for (let i2 = 0; i2 < node.branches.length; i2++) {
18453
18530
  traverseNode(node.branches[i2], context);
@@ -22263,6 +22340,7 @@ function genNode(node, context) {
22263
22340
  case 21:
22264
22341
  genNodeList(node.body, context, true, false);
22265
22342
  break;
22343
+ // SSR only types
22266
22344
  case 22:
22267
22345
  genTemplateLiteral(node, context);
22268
22346
  break;
@@ -22278,6 +22356,7 @@ function genNode(node, context) {
22278
22356
  case 26:
22279
22357
  genReturnStatement(node, context);
22280
22358
  break;
22359
+ /* istanbul ignore next */
22281
22360
  case 10:
22282
22361
  break;
22283
22362
  default:
@@ -24296,7 +24375,6 @@ function processSlotOutlet(node, context) {
24296
24375
  };
24297
24376
  }
24298
24377
 
24299
- const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
24300
24378
  const transformOn$1 = (dir, node, context, augmentor) => {
24301
24379
  const { loc, modifiers, arg } = dir;
24302
24380
  if (!dir.exp && !modifiers.length) {
@@ -24340,8 +24418,8 @@ const transformOn$1 = (dir, node, context, augmentor) => {
24340
24418
  }
24341
24419
  let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
24342
24420
  if (exp) {
24343
- const isMemberExp = isMemberExpression(exp.content, context);
24344
- const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
24421
+ const isMemberExp = isMemberExpression(exp, context);
24422
+ const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
24345
24423
  const hasMultipleStatements = exp.content.includes(`;`);
24346
24424
  if (context.prefixIdentifiers) {
24347
24425
  isInlineStatement && context.addIdentifiers(`$event`);
@@ -24511,7 +24589,7 @@ const transformModel$1 = (dir, node, context) => {
24511
24589
  return createTransformProps();
24512
24590
  }
24513
24591
  const maybeRef = context.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
24514
- if (!expString.trim() || !isMemberExpression(expString, context) && !maybeRef) {
24592
+ if (!expString.trim() || !isMemberExpression(exp, context) && !maybeRef) {
24515
24593
  context.onError(
24516
24594
  createCompilerError(42, exp.loc)
24517
24595
  );
@@ -25684,6 +25762,9 @@ var CompilerDOM = /*#__PURE__*/Object.freeze({
25684
25762
  helperNameMap: helperNameMap,
25685
25763
  injectProp: injectProp,
25686
25764
  isCoreComponent: isCoreComponent,
25765
+ isFnExpression: isFnExpression,
25766
+ isFnExpressionBrowser: isFnExpressionBrowser,
25767
+ isFnExpressionNode: isFnExpressionNode,
25687
25768
  isFunctionType: isFunctionType,
25688
25769
  isInDestructureAssignment: isInDestructureAssignment,
25689
25770
  isInNewExpression: isInNewExpression,
@@ -26566,8 +26647,7 @@ function parse$7(source, options = {}) {
26566
26647
  pad = false,
26567
26648
  ignoreEmpty = true,
26568
26649
  compiler = CompilerDOM,
26569
- templateParseOptions = {},
26570
- parseExpressions = true
26650
+ templateParseOptions = {}
26571
26651
  } = options;
26572
26652
  const descriptor = {
26573
26653
  filename,
@@ -26584,7 +26664,7 @@ function parse$7(source, options = {}) {
26584
26664
  const errors = [];
26585
26665
  const ast = compiler.parse(source, __spreadProps$9(__spreadValues$a({
26586
26666
  parseMode: "sfc",
26587
- prefixIdentifiers: parseExpressions
26667
+ prefixIdentifiers: true
26588
26668
  }, templateParseOptions), {
26589
26669
  onError: (e) => {
26590
26670
  errors.push(e);
@@ -39645,7 +39725,7 @@ tokenTypes.combinator = combinator$1;
39645
39725
  }
39646
39726
  // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
39647
39727
  var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
39648
- if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma) {
39728
+ if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
39649
39729
  var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
39650
39730
  if (nodes.length > 0) {
39651
39731
  var last = this.current.last;
@@ -45942,6 +46022,7 @@ function innerResolveTypeElements(ctx, node, scope, typeParameters) {
45942
46022
  );
45943
46023
  }
45944
46024
  case "TSExpressionWithTypeArguments":
46025
+ // referenced by interface extends
45945
46026
  case "TSTypeReference": {
45946
46027
  const typeName = getReferenceName(node);
45947
46028
  if ((typeName === "ExtractPropTypes" || typeName === "ExtractPublicPropTypes") && node.typeParameters && ((_a = scope.imports[typeName]) == null ? void 0 : _a.source) === "vue") {
@@ -46902,6 +46983,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
46902
46983
  case "ConstructorParameters":
46903
46984
  case "ReadonlyArray":
46904
46985
  return ["String", "Number"];
46986
+ // TS built-in utility types
46905
46987
  case "Record":
46906
46988
  case "Partial":
46907
46989
  case "Required":
@@ -46955,6 +47037,8 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
46955
47037
  case "Promise":
46956
47038
  case "Error":
46957
47039
  return [node.typeName.name];
47040
+ // TS built-in utility types
47041
+ // https://www.typescriptlang.org/docs/handbook/utility-types.html
46958
47042
  case "Partial":
46959
47043
  case "Required":
46960
47044
  case "Readonly":
@@ -47024,7 +47108,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
47024
47108
  return ["Symbol"];
47025
47109
  case "TSIndexedAccessType": {
47026
47110
  const types = resolveIndexType(ctx, node, scope);
47027
- return flattenTypes(ctx, types, scope);
47111
+ return flattenTypes(ctx, types, scope, isKeyOf);
47028
47112
  }
47029
47113
  case "ClassDeclaration":
47030
47114
  return ["Object"];
@@ -47051,6 +47135,7 @@ function inferRuntimeType(ctx, node, scope = node._ownerScope || ctxToScope(ctx)
47051
47135
  }
47052
47136
  break;
47053
47137
  }
47138
+ // e.g. readonly
47054
47139
  case "TSTypeOperator": {
47055
47140
  return inferRuntimeType(
47056
47141
  ctx,
@@ -48730,12 +48815,14 @@ function isStaticNode(node) {
48730
48815
  case "UnaryExpression":
48731
48816
  return isStaticNode(node.argument);
48732
48817
  case "LogicalExpression":
48818
+ // 1 > 2
48733
48819
  case "BinaryExpression":
48734
48820
  return isStaticNode(node.left) && isStaticNode(node.right);
48735
48821
  case "ConditionalExpression": {
48736
48822
  return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
48737
48823
  }
48738
48824
  case "SequenceExpression":
48825
+ // (1, 2)
48739
48826
  case "TemplateLiteral":
48740
48827
  return node.expressions.every((expr) => isStaticNode(expr));
48741
48828
  case "ParenthesizedExpression":
@@ -48766,7 +48853,7 @@ var __spreadValues = (a, b) => {
48766
48853
  }
48767
48854
  return a;
48768
48855
  };
48769
- const version = "3.5.0-beta.1";
48856
+ const version = "3.5.0-beta.3";
48770
48857
  const parseCache = parseCache$1;
48771
48858
  const errorMessages = __spreadValues(__spreadValues({}, errorMessages$1), DOMErrorMessages);
48772
48859
  const walk = walk$2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/compiler-sfc",
3
- "version": "3.5.0-beta.1",
3
+ "version": "3.5.0-beta.3",
4
4
  "description": "@vue/compiler-sfc",
5
5
  "main": "dist/compiler-sfc.cjs.js",
6
6
  "module": "dist/compiler-sfc.esm-browser.js",
@@ -45,12 +45,12 @@
45
45
  "@babel/parser": "^7.25.3",
46
46
  "estree-walker": "^2.0.2",
47
47
  "magic-string": "^0.30.11",
48
- "postcss": "^8.4.40",
48
+ "postcss": "^8.4.41",
49
49
  "source-map-js": "^1.2.0",
50
- "@vue/compiler-core": "3.5.0-beta.1",
51
- "@vue/compiler-dom": "3.5.0-beta.1",
52
- "@vue/compiler-ssr": "3.5.0-beta.1",
53
- "@vue/shared": "3.5.0-beta.1"
50
+ "@vue/compiler-core": "3.5.0-beta.3",
51
+ "@vue/compiler-ssr": "3.5.0-beta.3",
52
+ "@vue/shared": "3.5.0-beta.3",
53
+ "@vue/compiler-dom": "3.5.0-beta.3"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@babel/types": "^7.25.2",
@@ -60,7 +60,7 @@
60
60
  "merge-source-map": "^1.1.0",
61
61
  "minimatch": "~9.0.5",
62
62
  "postcss-modules": "^6.0.0",
63
- "postcss-selector-parser": "^6.1.1",
63
+ "postcss-selector-parser": "^6.1.2",
64
64
  "pug": "^3.0.3",
65
65
  "sass": "^1.77.8"
66
66
  }