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.
- package/modules/inferred-types/dist/index.cjs +23 -25
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +22447 -22373
- package/modules/inferred-types/dist/index.js +23 -25
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +23 -25
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +6894 -6838
- package/modules/runtime/dist/index.js +23 -25
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +10074 -10056
- package/package.json +1 -1
|
@@ -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
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
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
|
-
|
|
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 +=
|
|
4059
|
+
regexStr += "(.*?)";
|
|
4063
4060
|
break;
|
|
4064
4061
|
case "number":
|
|
4065
|
-
regexStr +=
|
|
4062
|
+
regexStr += "(\\d+)";
|
|
4066
4063
|
break;
|
|
4067
4064
|
case "boolean":
|
|
4068
|
-
regexStr +=
|
|
4065
|
+
regexStr += "(true|false)";
|
|
4069
4066
|
break;
|
|
4070
4067
|
}
|
|
4071
4068
|
}
|
|
4072
4069
|
}
|
|
4073
4070
|
regexStr += "$";
|
|
4074
|
-
return new RegExp(regexStr
|
|
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(
|
|
4087
|
-
const segments = parseTemplate(
|
|
4083
|
+
function matchTemplate(template, test) {
|
|
4084
|
+
const segments = parseTemplate(template);
|
|
4088
4085
|
const regex = buildRegexPattern(segments);
|
|
4089
|
-
const match =
|
|
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
|
|
4093
|
+
const rawVal = match[captureIndex++];
|
|
4096
4094
|
if (rawVal === void 0)
|
|
4097
4095
|
return false;
|
|
4098
|
-
result2[seg.varName
|
|
4096
|
+
result2[seg.varName] = convertValue(seg.type, rawVal);
|
|
4099
4097
|
}
|
|
4100
4098
|
}
|
|
4101
4099
|
return result2;
|