@runtime-type-inspector/transpiler 3.3.5 → 3.3.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 +22 -5
- package/index.mjs +22 -5
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -964,7 +964,7 @@
|
|
|
964
964
|
function parseJSDoc(src) {
|
|
965
965
|
var expandType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : expandTypeDepFree;
|
|
966
966
|
// Parse something like: @param {Object} [kwargs={}] Optional arguments.
|
|
967
|
-
var regex = /@param \{(.*?)\} ([\[\]a-zA-Z0-9_
|
|
967
|
+
var regex = /@param \{(.*?)\} ([\[\]a-zA-Z0-9_$=\-\{\}\.'" ]+)/g;
|
|
968
968
|
var matches = _toConsumableArray(src.matchAll(regex));
|
|
969
969
|
/** @type {Record<string, ExpandTypeReturnType>} */
|
|
970
970
|
var params = Object.create(null);
|
|
@@ -3610,6 +3610,12 @@
|
|
|
3610
3610
|
var tmp = JSON.stringify(templates, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3611
3611
|
out += "\n".concat(spaces, "const rtiTemplates = ").concat(tmp, ";");
|
|
3612
3612
|
}
|
|
3613
|
+
function newlineBeforeFirst() {
|
|
3614
|
+
if (first) {
|
|
3615
|
+
out += '\n';
|
|
3616
|
+
first = false;
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3613
3619
|
//out += `${spaces}/*${spaces} node.type=${node.type}\n${spaces}
|
|
3614
3620
|
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
|
|
3615
3621
|
var _loop = function _loop(name) {
|
|
@@ -3653,11 +3659,19 @@
|
|
|
3653
3659
|
try {
|
|
3654
3660
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3655
3661
|
var element = _step.value;
|
|
3662
|
+
if (element.type === 'RestElement') {
|
|
3663
|
+
// Case for:
|
|
3664
|
+
// function test([a, b, ...rest] = [1, 2, 3]) {return rest;}
|
|
3665
|
+
/** @todo We could typecheck the rest element too */
|
|
3666
|
+
// console.log("Ignore RestElement", element);
|
|
3667
|
+
continue;
|
|
3668
|
+
}
|
|
3656
3669
|
if (element.type !== 'Identifier') {
|
|
3657
3670
|
_this2.warn('Only Identifier case handled right now');
|
|
3658
3671
|
continue;
|
|
3659
3672
|
}
|
|
3660
3673
|
var _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3674
|
+
newlineBeforeFirst();
|
|
3661
3675
|
if (templates) {
|
|
3662
3676
|
out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3663
3677
|
} else {
|
|
@@ -3679,6 +3693,11 @@
|
|
|
3679
3693
|
try {
|
|
3680
3694
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
3681
3695
|
var property = _step2.value;
|
|
3696
|
+
if (property.type !== 'ObjectProperty') {
|
|
3697
|
+
// E.g. case of RestElement, {a, b, c, ...kwargs}
|
|
3698
|
+
// console.log("Ignore property", property);
|
|
3699
|
+
continue;
|
|
3700
|
+
}
|
|
3682
3701
|
if (property.key.type !== 'Identifier') {
|
|
3683
3702
|
_this2.warn('ObjectPattern> Only Identifier case handled right now');
|
|
3684
3703
|
continue;
|
|
@@ -3694,6 +3713,7 @@
|
|
|
3694
3713
|
continue;
|
|
3695
3714
|
}
|
|
3696
3715
|
var _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3716
|
+
newlineBeforeFirst();
|
|
3697
3717
|
if (templates) {
|
|
3698
3718
|
out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3699
3719
|
} else {
|
|
@@ -3737,10 +3757,7 @@
|
|
|
3737
3757
|
if (loc === 'ContactPoint#constructor' || loc === 'ContactResult#constructor' || loc === 'SingleContactResult#constructor') {
|
|
3738
3758
|
prevCheck = 'arguments.length !== 0 && ';
|
|
3739
3759
|
}
|
|
3740
|
-
|
|
3741
|
-
out += '\n';
|
|
3742
|
-
first = false;
|
|
3743
|
-
}
|
|
3760
|
+
newlineBeforeFirst();
|
|
3744
3761
|
if (templates) {
|
|
3745
3762
|
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectTypeWithTemplates(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3746
3763
|
} else {
|
package/index.mjs
CHANGED
|
@@ -744,7 +744,7 @@ function simplifyType(type, optional) {
|
|
|
744
744
|
*/
|
|
745
745
|
function parseJSDoc(src, expandType = expandTypeDepFree) {
|
|
746
746
|
// Parse something like: @param {Object} [kwargs={}] Optional arguments.
|
|
747
|
-
const regex = /@param \{(.*?)\} ([\[\]a-zA-Z0-9_
|
|
747
|
+
const regex = /@param \{(.*?)\} ([\[\]a-zA-Z0-9_$=\-\{\}\.'" ]+)/g;
|
|
748
748
|
const matches = [...src.matchAll(regex)];
|
|
749
749
|
/** @type {Record<string, ExpandTypeReturnType>} */
|
|
750
750
|
const params = Object.create(null);
|
|
@@ -3301,6 +3301,12 @@ class Asserter extends Stringifier {
|
|
|
3301
3301
|
const tmp = JSON.stringify(templates, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3302
3302
|
out += `\n${spaces}const rtiTemplates = ${tmp};`;
|
|
3303
3303
|
}
|
|
3304
|
+
function newlineBeforeFirst() {
|
|
3305
|
+
if (first) {
|
|
3306
|
+
out += '\n';
|
|
3307
|
+
first = false;
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3304
3310
|
//out += `${spaces}/*${spaces} node.type=${node.type}\n${spaces}
|
|
3305
3311
|
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
|
|
3306
3312
|
for (let name in params) {
|
|
@@ -3338,11 +3344,19 @@ class Asserter extends Stringifier {
|
|
|
3338
3344
|
if (param.left.type === 'ArrayPattern' && type.type === 'array') {
|
|
3339
3345
|
// Add a type assertion for each element of the ArrayPattern
|
|
3340
3346
|
for (const element of param.left.elements) {
|
|
3347
|
+
if (element.type === 'RestElement') {
|
|
3348
|
+
// Case for:
|
|
3349
|
+
// function test([a, b, ...rest] = [1, 2, 3]) {return rest;}
|
|
3350
|
+
/** @todo We could typecheck the rest element too */
|
|
3351
|
+
// console.log("Ignore RestElement", element);
|
|
3352
|
+
continue;
|
|
3353
|
+
}
|
|
3341
3354
|
if (element.type !== 'Identifier') {
|
|
3342
3355
|
this.warn('Only Identifier case handled right now');
|
|
3343
3356
|
continue;
|
|
3344
3357
|
}
|
|
3345
3358
|
const _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3359
|
+
newlineBeforeFirst();
|
|
3346
3360
|
if (templates) {
|
|
3347
3361
|
out += `${spaces}if (!inspectTypeWithTemplates(${element.name}, ${_t}, '${_loc}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3348
3362
|
} else {
|
|
@@ -3355,6 +3369,11 @@ class Asserter extends Stringifier {
|
|
|
3355
3369
|
if (type.type === 'object') {
|
|
3356
3370
|
// Add a type assertion for each property of the ObjectPattern
|
|
3357
3371
|
for (const property of param.left.properties) {
|
|
3372
|
+
if (property.type !== 'ObjectProperty') {
|
|
3373
|
+
// E.g. case of RestElement, {a, b, c, ...kwargs}
|
|
3374
|
+
// console.log("Ignore property", property);
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3358
3377
|
if (property.key.type !== 'Identifier') {
|
|
3359
3378
|
this.warn('ObjectPattern> Only Identifier case handled right now');
|
|
3360
3379
|
continue;
|
|
@@ -3370,6 +3389,7 @@ class Asserter extends Stringifier {
|
|
|
3370
3389
|
continue;
|
|
3371
3390
|
}
|
|
3372
3391
|
const _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3392
|
+
newlineBeforeFirst();
|
|
3373
3393
|
if (templates) {
|
|
3374
3394
|
out += `${spaces}if (!inspectTypeWithTemplates(${keyName}, ${_t2}, '${_loc}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3375
3395
|
} else {
|
|
@@ -3408,10 +3428,7 @@ class Asserter extends Stringifier {
|
|
|
3408
3428
|
if (_loc3 === 'ContactPoint#constructor' || _loc3 === 'ContactResult#constructor' || _loc3 === 'SingleContactResult#constructor') {
|
|
3409
3429
|
prevCheck = 'arguments.length !== 0 && ';
|
|
3410
3430
|
}
|
|
3411
|
-
|
|
3412
|
-
out += '\n';
|
|
3413
|
-
first = false;
|
|
3414
|
-
}
|
|
3431
|
+
newlineBeforeFirst();
|
|
3415
3432
|
if (templates) {
|
|
3416
3433
|
out += `${spaces}if (${prevCheck}!inspectTypeWithTemplates(${name}, ${t}, '${_loc3}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3417
3434
|
} else {
|
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.3.
|
|
4
|
+
"version": "3.3.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.3.
|
|
22
|
+
"@runtime-type-inspector/runtime": "^3.3.6",
|
|
23
23
|
"typescript": "^5.1.6"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|