inferred-types 0.54.7 → 0.54.8

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.
@@ -4022,26 +4022,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
4022
4022
 
4023
4023
  // src/literals/infer.ts
4024
4024
  function parseTemplate(template) {
4025
- const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
4025
+ const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
4026
4026
  let lastIndex = 0;
4027
4027
  let match;
4028
4028
  const segments = [];
4029
- do {
4030
- match = pattern.exec(template);
4031
- if (match) {
4032
- const [fullMatch, varName, asType2] = match;
4033
- const staticPart = template.slice(lastIndex, match.index);
4034
- if (staticPart) {
4035
- segments.push({ dynamic: false, text: staticPart });
4036
- }
4037
- segments.push({
4038
- dynamic: true,
4039
- varName,
4040
- type: asType2 ? asType2 : "string"
4041
- });
4042
- lastIndex = match.index + fullMatch.length;
4029
+ while (match = pattern.exec(template)) {
4030
+ const [fullMatch, varName, asType2] = match;
4031
+ const staticPart = template.slice(lastIndex, match.index);
4032
+ if (staticPart) {
4033
+ segments.push({ dynamic: false, text: staticPart });
4043
4034
  }
4044
- } while (match);
4035
+ segments.push({
4036
+ dynamic: true,
4037
+ varName,
4038
+ type: asType2 ? asType2 : "string"
4039
+ });
4040
+ lastIndex = match.index + fullMatch.length;
4041
+ }
4045
4042
  const remainder = template.slice(lastIndex);
4046
4043
  if (remainder) {
4047
4044
  segments.push({ dynamic: false, text: remainder });
@@ -4059,19 +4056,19 @@ function buildRegexPattern(segments) {
4059
4056
  } else {
4060
4057
  switch (seg.type) {
4061
4058
  case "string":
4062
- regexStr += `(?<${seg.varName}>.*?)`;
4059
+ regexStr += "(.*?)";
4063
4060
  break;
4064
4061
  case "number":
4065
- regexStr += `(?<${seg.varName}>\\d+)`;
4062
+ regexStr += "(\\d+)";
4066
4063
  break;
4067
4064
  case "boolean":
4068
- regexStr += `(?<${seg.varName}>(?:true|false))`;
4065
+ regexStr += "(true|false)";
4069
4066
  break;
4070
4067
  }
4071
4068
  }
4072
4069
  }
4073
4070
  regexStr += "$";
4074
- return new RegExp(regexStr, "s");
4071
+ return new RegExp(regexStr);
4075
4072
  }
4076
4073
  function convertValue(type, value) {
4077
4074
  switch (type) {
@@ -4083,19 +4080,20 @@ function convertValue(type, value) {
4083
4080
  return value === "true";
4084
4081
  }
4085
4082
  }
4086
- function matchTemplate(inference, test) {
4087
- const segments = parseTemplate(inference);
4083
+ function matchTemplate(template, test) {
4084
+ const segments = parseTemplate(template);
4088
4085
  const regex = buildRegexPattern(segments);
4089
- const match = test.match(regex);
4086
+ const match = regex.exec(test);
4090
4087
  if (!match)
4091
4088
  return false;
4089
+ let captureIndex = 1;
4092
4090
  const result2 = {};
4093
4091
  for (const seg of segments) {
4094
4092
  if (seg.dynamic) {
4095
- const rawVal = match.groups?.[seg.varName];
4093
+ const rawVal = match[captureIndex++];
4096
4094
  if (rawVal === void 0)
4097
4095
  return false;
4098
- result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
4096
+ result2[seg.varName] = convertValue(seg.type, rawVal);
4099
4097
  }
4100
4098
  }
4101
4099
  return result2;