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
|
@@ -4490,26 +4490,23 @@ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
|
4490
4490
|
|
|
4491
4491
|
// src/literals/infer.ts
|
|
4492
4492
|
function parseTemplate(template) {
|
|
4493
|
-
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
4493
|
+
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:(?:extends|as)\s+(string|number|boolean)\s*)?\}\}/g;
|
|
4494
4494
|
let lastIndex = 0;
|
|
4495
4495
|
let match;
|
|
4496
4496
|
const segments = [];
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
if (staticPart) {
|
|
4503
|
-
segments.push({ dynamic: false, text: staticPart });
|
|
4504
|
-
}
|
|
4505
|
-
segments.push({
|
|
4506
|
-
dynamic: true,
|
|
4507
|
-
varName,
|
|
4508
|
-
type: asType2 ? asType2 : "string"
|
|
4509
|
-
});
|
|
4510
|
-
lastIndex = match.index + fullMatch.length;
|
|
4497
|
+
while (match = pattern.exec(template)) {
|
|
4498
|
+
const [fullMatch, varName, asType2] = match;
|
|
4499
|
+
const staticPart = template.slice(lastIndex, match.index);
|
|
4500
|
+
if (staticPart) {
|
|
4501
|
+
segments.push({ dynamic: false, text: staticPart });
|
|
4511
4502
|
}
|
|
4512
|
-
|
|
4503
|
+
segments.push({
|
|
4504
|
+
dynamic: true,
|
|
4505
|
+
varName,
|
|
4506
|
+
type: asType2 ? asType2 : "string"
|
|
4507
|
+
});
|
|
4508
|
+
lastIndex = match.index + fullMatch.length;
|
|
4509
|
+
}
|
|
4513
4510
|
const remainder = template.slice(lastIndex);
|
|
4514
4511
|
if (remainder) {
|
|
4515
4512
|
segments.push({ dynamic: false, text: remainder });
|
|
@@ -4527,19 +4524,19 @@ function buildRegexPattern(segments) {
|
|
|
4527
4524
|
} else {
|
|
4528
4525
|
switch (seg.type) {
|
|
4529
4526
|
case "string":
|
|
4530
|
-
regexStr +=
|
|
4527
|
+
regexStr += "(.*?)";
|
|
4531
4528
|
break;
|
|
4532
4529
|
case "number":
|
|
4533
|
-
regexStr +=
|
|
4530
|
+
regexStr += "(\\d+)";
|
|
4534
4531
|
break;
|
|
4535
4532
|
case "boolean":
|
|
4536
|
-
regexStr +=
|
|
4533
|
+
regexStr += "(true|false)";
|
|
4537
4534
|
break;
|
|
4538
4535
|
}
|
|
4539
4536
|
}
|
|
4540
4537
|
}
|
|
4541
4538
|
regexStr += "$";
|
|
4542
|
-
return new RegExp(regexStr
|
|
4539
|
+
return new RegExp(regexStr);
|
|
4543
4540
|
}
|
|
4544
4541
|
function convertValue(type, value) {
|
|
4545
4542
|
switch (type) {
|
|
@@ -4551,19 +4548,20 @@ function convertValue(type, value) {
|
|
|
4551
4548
|
return value === "true";
|
|
4552
4549
|
}
|
|
4553
4550
|
}
|
|
4554
|
-
function matchTemplate(
|
|
4555
|
-
const segments = parseTemplate(
|
|
4551
|
+
function matchTemplate(template, test) {
|
|
4552
|
+
const segments = parseTemplate(template);
|
|
4556
4553
|
const regex = buildRegexPattern(segments);
|
|
4557
|
-
const match =
|
|
4554
|
+
const match = regex.exec(test);
|
|
4558
4555
|
if (!match)
|
|
4559
4556
|
return false;
|
|
4557
|
+
let captureIndex = 1;
|
|
4560
4558
|
const result2 = {};
|
|
4561
4559
|
for (const seg of segments) {
|
|
4562
4560
|
if (seg.dynamic) {
|
|
4563
|
-
const rawVal = match
|
|
4561
|
+
const rawVal = match[captureIndex++];
|
|
4564
4562
|
if (rawVal === void 0)
|
|
4565
4563
|
return false;
|
|
4566
|
-
result2[seg.varName
|
|
4564
|
+
result2[seg.varName] = convertValue(seg.type, rawVal);
|
|
4567
4565
|
}
|
|
4568
4566
|
}
|
|
4569
4567
|
return result2;
|