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.
@@ -6077,26 +6077,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
6077
6077
  return LOWER_ALPHA_CHARS2.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
6078
6078
  }
6079
6079
  function parseTemplate(template) {
6080
- const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
6080
+ const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
6081
6081
  let lastIndex = 0;
6082
6082
  let match;
6083
6083
  const segments = [];
6084
- do {
6085
- match = pattern.exec(template);
6086
- if (match) {
6087
- const [fullMatch, varName, asType2] = match;
6088
- const staticPart = template.slice(lastIndex, match.index);
6089
- if (staticPart) {
6090
- segments.push({ dynamic: false, text: staticPart });
6091
- }
6092
- segments.push({
6093
- dynamic: true,
6094
- varName,
6095
- type: asType2 ? asType2 : "string"
6096
- });
6097
- lastIndex = match.index + fullMatch.length;
6084
+ while (match = pattern.exec(template)) {
6085
+ const [fullMatch, varName, asType2] = match;
6086
+ const staticPart = template.slice(lastIndex, match.index);
6087
+ if (staticPart) {
6088
+ segments.push({ dynamic: false, text: staticPart });
6098
6089
  }
6099
- } while (match);
6090
+ segments.push({
6091
+ dynamic: true,
6092
+ varName,
6093
+ type: asType2 ? asType2 : "string"
6094
+ });
6095
+ lastIndex = match.index + fullMatch.length;
6096
+ }
6100
6097
  const remainder = template.slice(lastIndex);
6101
6098
  if (remainder) {
6102
6099
  segments.push({ dynamic: false, text: remainder });
@@ -6114,19 +6111,19 @@ function buildRegexPattern(segments) {
6114
6111
  } else {
6115
6112
  switch (seg.type) {
6116
6113
  case "string":
6117
- regexStr += `(?<${seg.varName}>.*?)`;
6114
+ regexStr += "(.*?)";
6118
6115
  break;
6119
6116
  case "number":
6120
- regexStr += `(?<${seg.varName}>\\d+)`;
6117
+ regexStr += "(\\d+)";
6121
6118
  break;
6122
6119
  case "boolean":
6123
- regexStr += `(?<${seg.varName}>(?:true|false))`;
6120
+ regexStr += "(true|false)";
6124
6121
  break;
6125
6122
  }
6126
6123
  }
6127
6124
  }
6128
6125
  regexStr += "$";
6129
- return new RegExp(regexStr, "s");
6126
+ return new RegExp(regexStr);
6130
6127
  }
6131
6128
  function convertValue(type, value) {
6132
6129
  switch (type) {
@@ -6138,19 +6135,20 @@ function convertValue(type, value) {
6138
6135
  return value === "true";
6139
6136
  }
6140
6137
  }
6141
- function matchTemplate(inference, test) {
6142
- const segments = parseTemplate(inference);
6138
+ function matchTemplate(template, test) {
6139
+ const segments = parseTemplate(template);
6143
6140
  const regex = buildRegexPattern(segments);
6144
- const match = test.match(regex);
6141
+ const match = regex.exec(test);
6145
6142
  if (!match)
6146
6143
  return false;
6144
+ let captureIndex = 1;
6147
6145
  const result2 = {};
6148
6146
  for (const seg of segments) {
6149
6147
  if (seg.dynamic) {
6150
- const rawVal = match.groups?.[seg.varName];
6148
+ const rawVal = match[captureIndex++];
6151
6149
  if (rawVal === void 0)
6152
6150
  return false;
6153
- result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
6151
+ result2[seg.varName] = convertValue(seg.type, rawVal);
6154
6152
  }
6155
6153
  }
6156
6154
  return result2;