@runtime-type-inspector/transpiler 3.3.4 → 3.3.5
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 +45 -37
- package/index.mjs +37 -29
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -3614,6 +3614,8 @@
|
|
|
3614
3614
|
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
|
|
3615
3615
|
var _loop = function _loop(name) {
|
|
3616
3616
|
var type = params[name];
|
|
3617
|
+
// Copy name for warnings, `name` may become `arguments[${paramIndex}]`.
|
|
3618
|
+
var nameFancy = name;
|
|
3617
3619
|
var hasParam = _this2.nodeHasParamName(node, name);
|
|
3618
3620
|
if (!hasParam) {
|
|
3619
3621
|
var testNode = node;
|
|
@@ -3657,9 +3659,9 @@
|
|
|
3657
3659
|
}
|
|
3658
3660
|
var _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3659
3661
|
if (templates) {
|
|
3660
|
-
out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(
|
|
3662
|
+
out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3661
3663
|
} else {
|
|
3662
|
-
out += "".concat(spaces, "if (!inspectType(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(
|
|
3664
|
+
out += "".concat(spaces, "if (!inspectType(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(nameFancy, "')) {\n");
|
|
3663
3665
|
}
|
|
3664
3666
|
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3665
3667
|
}
|
|
@@ -3669,44 +3671,50 @@
|
|
|
3669
3671
|
_iterator.f();
|
|
3670
3672
|
}
|
|
3671
3673
|
return 0; // continue
|
|
3672
|
-
} else if (param.left.type === 'ObjectPattern'
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3674
|
+
} else if (param.left.type === 'ObjectPattern') {
|
|
3675
|
+
if (type.type === 'object') {
|
|
3676
|
+
// Add a type assertion for each property of the ObjectPattern
|
|
3677
|
+
var _iterator2 = _createForOfIteratorHelper(param.left.properties),
|
|
3678
|
+
_step2;
|
|
3679
|
+
try {
|
|
3680
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
3681
|
+
var property = _step2.value;
|
|
3682
|
+
if (property.key.type !== 'Identifier') {
|
|
3683
|
+
_this2.warn('ObjectPattern> Only Identifier case handled right now');
|
|
3684
|
+
continue;
|
|
3685
|
+
}
|
|
3686
|
+
var keyName = property.key.name;
|
|
3687
|
+
if (type.type !== 'object' || !type.properties) {
|
|
3688
|
+
_this2.warn("missing subtype information in JSDoc> in type", JSON.stringify(type, null, 2), "for ObjectPattern:", _this2.toSource(property).trim());
|
|
3689
|
+
continue;
|
|
3690
|
+
}
|
|
3691
|
+
var subType = type.properties[keyName];
|
|
3692
|
+
if (!subType) {
|
|
3693
|
+
_this2.warn("missing subtype information in JSDoc");
|
|
3694
|
+
continue;
|
|
3695
|
+
}
|
|
3696
|
+
var _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3697
|
+
if (templates) {
|
|
3698
|
+
out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3699
|
+
} else {
|
|
3700
|
+
out += "".concat(spaces, "if (!inspectType(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(nameFancy, "')) {\n");
|
|
3701
|
+
}
|
|
3702
|
+
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3692
3703
|
}
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
out += "".concat(spaces, "if (!inspectType(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(name, "')) {\n");
|
|
3698
|
-
}
|
|
3699
|
-
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3704
|
+
} catch (err) {
|
|
3705
|
+
_iterator2.e(err);
|
|
3706
|
+
} finally {
|
|
3707
|
+
_iterator2.f();
|
|
3700
3708
|
}
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3709
|
+
return 0; // continue
|
|
3710
|
+
} else if (typeof type === 'string') {
|
|
3711
|
+
// The case when we have an ObjectPattern with a @typedef
|
|
3712
|
+
name = "arguments[".concat(paramIndex, "]");
|
|
3705
3713
|
}
|
|
3714
|
+
} else {
|
|
3715
|
+
_this2.warn("generateTypeChecks> ".concat(_loc, "> todo implement"), "AssignmentPattern for parameter ".concat(name));
|
|
3706
3716
|
return 0; // continue
|
|
3707
3717
|
}
|
|
3708
|
-
_this2.warn("generateTypeChecks> ".concat(_loc, "> todo implement"), "AssignmentPattern for parameter ".concat(name));
|
|
3709
|
-
return 0; // continue
|
|
3710
3718
|
}
|
|
3711
3719
|
} else {
|
|
3712
3720
|
var _loc2 = _this2.getName(node);
|
|
@@ -3734,9 +3742,9 @@
|
|
|
3734
3742
|
first = false;
|
|
3735
3743
|
}
|
|
3736
3744
|
if (templates) {
|
|
3737
|
-
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectTypeWithTemplates(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(
|
|
3745
|
+
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectTypeWithTemplates(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(nameFancy, "', rtiTemplates)) {\n");
|
|
3738
3746
|
} else {
|
|
3739
|
-
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectType(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(
|
|
3747
|
+
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectType(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(nameFancy, "')) {\n");
|
|
3740
3748
|
}
|
|
3741
3749
|
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3742
3750
|
},
|
package/index.mjs
CHANGED
|
@@ -3305,6 +3305,8 @@ class Asserter extends Stringifier {
|
|
|
3305
3305
|
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
|
|
3306
3306
|
for (let name in params) {
|
|
3307
3307
|
const type = params[name];
|
|
3308
|
+
// Copy name for warnings, `name` may become `arguments[${paramIndex}]`.
|
|
3309
|
+
const nameFancy = name;
|
|
3308
3310
|
const hasParam = this.nodeHasParamName(node, name);
|
|
3309
3311
|
if (!hasParam) {
|
|
3310
3312
|
let testNode = node;
|
|
@@ -3342,42 +3344,48 @@ class Asserter extends Stringifier {
|
|
|
3342
3344
|
}
|
|
3343
3345
|
const _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3344
3346
|
if (templates) {
|
|
3345
|
-
out += `${spaces}if (!inspectTypeWithTemplates(${element.name}, ${_t}, '${_loc}', '${
|
|
3347
|
+
out += `${spaces}if (!inspectTypeWithTemplates(${element.name}, ${_t}, '${_loc}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3346
3348
|
} else {
|
|
3347
|
-
out += `${spaces}if (!inspectType(${element.name}, ${_t}, '${_loc}', '${
|
|
3349
|
+
out += `${spaces}if (!inspectType(${element.name}, ${_t}, '${_loc}', '${nameFancy}')) {\n`;
|
|
3348
3350
|
}
|
|
3349
3351
|
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
3350
3352
|
}
|
|
3351
3353
|
continue;
|
|
3352
|
-
} else if (param.left.type === 'ObjectPattern'
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3354
|
+
} else if (param.left.type === 'ObjectPattern') {
|
|
3355
|
+
if (type.type === 'object') {
|
|
3356
|
+
// Add a type assertion for each property of the ObjectPattern
|
|
3357
|
+
for (const property of param.left.properties) {
|
|
3358
|
+
if (property.key.type !== 'Identifier') {
|
|
3359
|
+
this.warn('ObjectPattern> Only Identifier case handled right now');
|
|
3360
|
+
continue;
|
|
3361
|
+
}
|
|
3362
|
+
const keyName = property.key.name;
|
|
3363
|
+
if (type.type !== 'object' || !type.properties) {
|
|
3364
|
+
this.warn("missing subtype information in JSDoc> in type", JSON.stringify(type, null, 2), "for ObjectPattern:", this.toSource(property).trim());
|
|
3365
|
+
continue;
|
|
3366
|
+
}
|
|
3367
|
+
const subType = type.properties[keyName];
|
|
3368
|
+
if (!subType) {
|
|
3369
|
+
this.warn("missing subtype information in JSDoc");
|
|
3370
|
+
continue;
|
|
3371
|
+
}
|
|
3372
|
+
const _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3373
|
+
if (templates) {
|
|
3374
|
+
out += `${spaces}if (!inspectTypeWithTemplates(${keyName}, ${_t2}, '${_loc}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3375
|
+
} else {
|
|
3376
|
+
out += `${spaces}if (!inspectType(${keyName}, ${_t2}, '${_loc}', '${nameFancy}')) {\n`;
|
|
3377
|
+
}
|
|
3378
|
+
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
3368
3379
|
}
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
out += `${spaces}if (!inspectType(${keyName}, ${_t2}, '${_loc}', '${name}')) {\n`;
|
|
3374
|
-
}
|
|
3375
|
-
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
3380
|
+
continue;
|
|
3381
|
+
} else if (typeof type === 'string') {
|
|
3382
|
+
// The case when we have an ObjectPattern with a @typedef
|
|
3383
|
+
name = `arguments[${paramIndex}]`;
|
|
3376
3384
|
}
|
|
3385
|
+
} else {
|
|
3386
|
+
this.warn(`generateTypeChecks> ${_loc}> todo implement`, `AssignmentPattern for parameter ${name}`);
|
|
3377
3387
|
continue;
|
|
3378
3388
|
}
|
|
3379
|
-
this.warn(`generateTypeChecks> ${_loc}> todo implement`, `AssignmentPattern for parameter ${name}`);
|
|
3380
|
-
continue;
|
|
3381
3389
|
}
|
|
3382
3390
|
} else {
|
|
3383
3391
|
const _loc2 = this.getName(node);
|
|
@@ -3405,9 +3413,9 @@ class Asserter extends Stringifier {
|
|
|
3405
3413
|
first = false;
|
|
3406
3414
|
}
|
|
3407
3415
|
if (templates) {
|
|
3408
|
-
out += `${spaces}if (${prevCheck}!inspectTypeWithTemplates(${name}, ${t}, '${_loc3}', '${
|
|
3416
|
+
out += `${spaces}if (${prevCheck}!inspectTypeWithTemplates(${name}, ${t}, '${_loc3}', '${nameFancy}', rtiTemplates)) {\n`;
|
|
3409
3417
|
} else {
|
|
3410
|
-
out += `${spaces}if (${prevCheck}!inspectType(${name}, ${t}, '${_loc3}', '${
|
|
3418
|
+
out += `${spaces}if (${prevCheck}!inspectType(${name}, ${t}, '${_loc3}', '${nameFancy}')) {\n`;
|
|
3411
3419
|
}
|
|
3412
3420
|
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
3413
3421
|
}
|
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.5",
|
|
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.5",
|
|
23
23
|
"typescript": "^5.1.6"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|