@runtime-type-inspector/transpiler 3.2.4 → 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 +60 -47
- package/index.mjs +37 -37
- 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) {
|
|
@@ -1425,15 +1422,19 @@
|
|
|
1425
1422
|
function get() {
|
|
1426
1423
|
return ' '.repeat(this.numSpaces);
|
|
1427
1424
|
}
|
|
1425
|
+
}, {
|
|
1426
|
+
key: "path",
|
|
1427
|
+
get: function get() {
|
|
1428
|
+
return this.parents.map(function (_) {
|
|
1429
|
+
return _.type;
|
|
1430
|
+
}).join('/');
|
|
1431
|
+
}
|
|
1428
1432
|
}, {
|
|
1429
1433
|
key: "debugSpaces",
|
|
1430
1434
|
value: function debugSpaces() {
|
|
1431
1435
|
var spaces = this.spaces,
|
|
1432
|
-
|
|
1436
|
+
path = this.path;
|
|
1433
1437
|
var n = spaces.length;
|
|
1434
|
-
var path = parents.map(function (_) {
|
|
1435
|
-
return _.type;
|
|
1436
|
-
}).join('/');
|
|
1437
1438
|
return "".concat(spaces, "// got ").concat(n, " spaces for ").concat(path, "\n");
|
|
1438
1439
|
}
|
|
1439
1440
|
/**
|
|
@@ -3580,6 +3581,7 @@
|
|
|
3580
3581
|
}, {
|
|
3581
3582
|
key: "getName",
|
|
3582
3583
|
value: function getName(node) {
|
|
3584
|
+
var _node4, _node5;
|
|
3583
3585
|
var toSource = this.toSource.bind(this);
|
|
3584
3586
|
if (node.type === 'BlockStatement') {
|
|
3585
3587
|
node = this.parent;
|
|
@@ -3615,10 +3617,20 @@
|
|
|
3615
3617
|
return 'getName> missing parent for ' + node.type;
|
|
3616
3618
|
case 'ObjectMethod':
|
|
3617
3619
|
return toSource(key);
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3620
|
+
case 'BinaryExpression':
|
|
3621
|
+
var goodNames = ['FunctionDeclaration', 'ClassMethod', 'ClassPrivateMethod'];
|
|
3622
|
+
var goodParent = this.parents.findLast(function (_) {
|
|
3623
|
+
return goodNames.includes(_.type);
|
|
3624
|
+
});
|
|
3625
|
+
if (goodParent) {
|
|
3626
|
+
return this.getName(goodParent);
|
|
3627
|
+
}
|
|
3628
|
+
// top scope
|
|
3629
|
+
return "".concat(this.filename, ":").concat((_node4 = node) === null || _node4 === void 0 || (_node4 = _node4.loc) === null || _node4 === void 0 || (_node4 = _node4.start) === null || _node4 === void 0 ? void 0 : _node4.line);
|
|
3621
3630
|
}
|
|
3631
|
+
this.warn('getName> unhandled type', type, 'for', node, this.path);
|
|
3632
|
+
//debugger;
|
|
3633
|
+
return "".concat(this.filename, ":").concat((_node5 = node) === null || _node5 === void 0 || (_node5 = _node5.loc) === null || _node5 === void 0 || (_node5 = _node5.start) === null || _node5 === void 0 ? void 0 : _node5.line);
|
|
3622
3634
|
}
|
|
3623
3635
|
/**
|
|
3624
3636
|
* @override
|
|
@@ -3637,7 +3649,8 @@
|
|
|
3637
3649
|
var left_ = this.toSource(left);
|
|
3638
3650
|
var right_ = this.toSource(right);
|
|
3639
3651
|
if (operator === '/') {
|
|
3640
|
-
|
|
3652
|
+
var loc = this.getName(node);
|
|
3653
|
+
return "validateDivision(".concat(left_, ", ").concat(right_, ", ").concat(JSON.stringify(loc), ")");
|
|
3641
3654
|
}
|
|
3642
3655
|
return "".concat(left_, " ").concat(operator, " ").concat(right_);
|
|
3643
3656
|
}
|
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) {
|
|
@@ -1121,13 +1109,15 @@ class Stringifier {
|
|
|
1121
1109
|
get spaces() {
|
|
1122
1110
|
return ' '.repeat(this.numSpaces);
|
|
1123
1111
|
}
|
|
1112
|
+
get path() {
|
|
1113
|
+
return this.parents.map(_ => _.type).join('/');
|
|
1114
|
+
}
|
|
1124
1115
|
debugSpaces() {
|
|
1125
1116
|
const {
|
|
1126
1117
|
spaces,
|
|
1127
|
-
|
|
1118
|
+
path
|
|
1128
1119
|
} = this;
|
|
1129
1120
|
const n = spaces.length;
|
|
1130
|
-
const path = parents.map(_ => _.type).join('/');
|
|
1131
1121
|
return `${spaces}// got ${n} spaces for ${path}\n`;
|
|
1132
1122
|
}
|
|
1133
1123
|
/**
|
|
@@ -3219,6 +3209,7 @@ class Asserter extends Stringifier {
|
|
|
3219
3209
|
* @returns {string} Stringification of the node.
|
|
3220
3210
|
*/
|
|
3221
3211
|
getName(node) {
|
|
3212
|
+
var _node, _node2;
|
|
3222
3213
|
const toSource = this.toSource.bind(this);
|
|
3223
3214
|
if (node.type === 'BlockStatement') {
|
|
3224
3215
|
node = this.parent;
|
|
@@ -3253,10 +3244,18 @@ class Asserter extends Stringifier {
|
|
|
3253
3244
|
return 'getName> missing parent for ' + node.type;
|
|
3254
3245
|
case 'ObjectMethod':
|
|
3255
3246
|
return toSource(key);
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3247
|
+
case 'BinaryExpression':
|
|
3248
|
+
const goodNames = ['FunctionDeclaration', 'ClassMethod', 'ClassPrivateMethod'];
|
|
3249
|
+
const goodParent = this.parents.findLast(_ => goodNames.includes(_.type));
|
|
3250
|
+
if (goodParent) {
|
|
3251
|
+
return this.getName(goodParent);
|
|
3252
|
+
}
|
|
3253
|
+
// top scope
|
|
3254
|
+
return `${this.filename}:${(_node = node) == null || (_node = _node.loc) == null || (_node = _node.start) == null ? void 0 : _node.line}`;
|
|
3259
3255
|
}
|
|
3256
|
+
this.warn('getName> unhandled type', type, 'for', node, this.path);
|
|
3257
|
+
//debugger;
|
|
3258
|
+
return `${this.filename}:${(_node2 = node) == null || (_node2 = _node2.loc) == null || (_node2 = _node2.start) == null ? void 0 : _node2.line}`;
|
|
3260
3259
|
}
|
|
3261
3260
|
/**
|
|
3262
3261
|
* @override
|
|
@@ -3275,7 +3274,8 @@ class Asserter extends Stringifier {
|
|
|
3275
3274
|
const left_ = this.toSource(left);
|
|
3276
3275
|
const right_ = this.toSource(right);
|
|
3277
3276
|
if (operator === '/') {
|
|
3278
|
-
|
|
3277
|
+
const loc = this.getName(node);
|
|
3278
|
+
return `validateDivision(${left_}, ${right_}, ${JSON.stringify(loc)})`;
|
|
3279
3279
|
}
|
|
3280
3280
|
return `${left_} ${operator} ${right_}`;
|
|
3281
3281
|
}
|
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": [
|