@runtime-type-inspector/transpiler 3.2.5 → 3.2.6
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/index.cjs +36 -39
- package/index.mjs +19 -31
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -876,46 +876,43 @@
|
|
|
876
876
|
// Strip the rest (either leftover of optional value or description)
|
|
877
877
|
name = name.split(' ')[0].split('=')[0].trim();
|
|
878
878
|
var simplifiedType = simplifyType(type, optional);
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
})
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
toptype: _toptype,
|
|
912
|
-
parts0: _parts,
|
|
913
|
-
parts1: _parts2,
|
|
914
|
-
simplifiedType: simplifiedType
|
|
915
|
-
});
|
|
879
|
+
// Turn "options.stats[].unitsName" into ['options', 'stats', 'unitsName'].
|
|
880
|
+
var parts = name.split(/[\[\]]*\./);
|
|
881
|
+
var properties = params;
|
|
882
|
+
var _iterator = _createForOfIteratorHelper(parts),
|
|
883
|
+
_step;
|
|
884
|
+
try {
|
|
885
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
886
|
+
var part = _step.value;
|
|
887
|
+
/** @type {object} */
|
|
888
|
+
var toptype = properties[part];
|
|
889
|
+
if (!toptype) {
|
|
890
|
+
// No toptype means we resolved as far as possible, now we can add `simplifiedType`.
|
|
891
|
+
console.assert(part === parts.at(-1), 'Current part and last part should be the same.');
|
|
892
|
+
properties[part] = simplifiedType;
|
|
893
|
+
} else if (toptype.type === "union") {
|
|
894
|
+
var typeObject = toptype.members.find(function (_) {
|
|
895
|
+
return (_ === null || _ === void 0 ? void 0 : _.type) === 'object';
|
|
896
|
+
});
|
|
897
|
+
properties = typeObject.properties;
|
|
898
|
+
} else if (toptype.type === "array") {
|
|
899
|
+
properties = toptype.elementType.properties;
|
|
900
|
+
} else if (toptype.type === "object") {
|
|
901
|
+
toptype.properties = toptype.properties || Object.create(null);
|
|
902
|
+
properties = toptype.properties;
|
|
903
|
+
} else {
|
|
904
|
+
console.warn("parseJSDoc> Skipping @param, unseen syntax detected. Please check if your JSDoc is valid or open an issue about this!", {
|
|
905
|
+
src: src,
|
|
906
|
+
toptype: toptype,
|
|
907
|
+
parts: parts,
|
|
908
|
+
simplifiedType: simplifiedType
|
|
909
|
+
});
|
|
910
|
+
}
|
|
916
911
|
}
|
|
917
|
-
}
|
|
918
|
-
|
|
912
|
+
} catch (err) {
|
|
913
|
+
_iterator.e(err);
|
|
914
|
+
} finally {
|
|
915
|
+
_iterator.f();
|
|
919
916
|
}
|
|
920
917
|
});
|
|
921
918
|
if (Object.keys(params).length === 0) {
|
package/index.mjs
CHANGED
|
@@ -619,44 +619,32 @@ function parseJSDoc(src, expandType = expandTypeDepFree) {
|
|
|
619
619
|
// Strip the rest (either leftover of optional value or description)
|
|
620
620
|
name = name.split(' ')[0].split('=')[0].trim();
|
|
621
621
|
const simplifiedType = simplifyType(type, optional);
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
let parts0 = parts[0]; // description[]
|
|
634
|
-
const parts1 = parts[1]; // components
|
|
635
|
-
if (parts0.endsWith('[]')) {
|
|
636
|
-
parts0 = parts0.slice(0, -2); // description[] -> description
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const toptype = params[parts0];
|
|
640
|
-
if ((toptype == null ? void 0 : toptype.type) === "union") {
|
|
622
|
+
// Turn "options.stats[].unitsName" into ['options', 'stats', 'unitsName'].
|
|
623
|
+
const parts = name.split(/[\[\]]*\./);
|
|
624
|
+
let properties = params;
|
|
625
|
+
for (const part of parts) {
|
|
626
|
+
/** @type {object} */
|
|
627
|
+
const toptype = properties[part];
|
|
628
|
+
if (!toptype) {
|
|
629
|
+
// No toptype means we resolved as far as possible, now we can add `simplifiedType`.
|
|
630
|
+
console.assert(part === parts.at(-1), 'Current part and last part should be the same.');
|
|
631
|
+
properties[part] = simplifiedType;
|
|
632
|
+
} else if (toptype.type === "union") {
|
|
641
633
|
const typeObject = toptype.members.find(_ => (_ == null ? void 0 : _.type) === 'object');
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
toptype.properties[parts1] = simplifiedType;
|
|
634
|
+
properties = typeObject.properties;
|
|
635
|
+
} else if (toptype.type === "array") {
|
|
636
|
+
properties = toptype.elementType.properties;
|
|
637
|
+
} else if (toptype.type === "object") {
|
|
638
|
+
toptype.properties = toptype.properties || Object.create(null);
|
|
639
|
+
properties = toptype.properties;
|
|
649
640
|
} else {
|
|
650
|
-
console.warn("parseJSDoc>
|
|
641
|
+
console.warn("parseJSDoc> Skipping @param, unseen syntax detected. Please check if your JSDoc is valid or open an issue about this!", {
|
|
651
642
|
src,
|
|
652
643
|
toptype,
|
|
653
|
-
|
|
654
|
-
parts1,
|
|
644
|
+
parts,
|
|
655
645
|
simplifiedType
|
|
656
646
|
});
|
|
657
647
|
}
|
|
658
|
-
} else {
|
|
659
|
-
params[name] = simplifiedType;
|
|
660
648
|
}
|
|
661
649
|
});
|
|
662
650
|
if (Object.keys(params).length === 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bin": "bin.js",
|
|
3
3
|
"name": "@runtime-type-inspector/transpiler",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.6",
|
|
5
5
|
"description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
|
|
6
6
|
"main": "index.cjs",
|
|
7
7
|
"module": "index.mjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/parser": "^7.23.0",
|
|
22
|
-
"@runtime-type-inspector/runtime": "^3.2.
|
|
22
|
+
"@runtime-type-inspector/runtime": "^3.2.6",
|
|
23
23
|
"typescript": "^5.1.6"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|