@runtime-type-inspector/transpiler 2.2.4 → 3.0.0
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 +30 -20
- package/index.mjs +30 -20
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -2738,7 +2738,7 @@
|
|
|
2738
2738
|
if (!this.addHeader) {
|
|
2739
2739
|
return '';
|
|
2740
2740
|
}
|
|
2741
|
-
var header = "import {
|
|
2741
|
+
var header = "import {inspectType, youCanAddABreakpointHere";
|
|
2742
2742
|
if (this.validateDivision) {
|
|
2743
2743
|
header += ", validateDivision";
|
|
2744
2744
|
}
|
|
@@ -3083,7 +3083,7 @@
|
|
|
3083
3083
|
continue;
|
|
3084
3084
|
}
|
|
3085
3085
|
var _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3086
|
-
out += "".concat(spaces, "if (!
|
|
3086
|
+
out += "".concat(spaces, "if (!inspectType(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(name, "')) {\n");
|
|
3087
3087
|
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3088
3088
|
}
|
|
3089
3089
|
} catch (err) {
|
|
@@ -3114,7 +3114,7 @@
|
|
|
3114
3114
|
continue;
|
|
3115
3115
|
}
|
|
3116
3116
|
var _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
3117
|
-
out += "".concat(spaces, "if (!
|
|
3117
|
+
out += "".concat(spaces, "if (!inspectType(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(name, "')) {\n");
|
|
3118
3118
|
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3119
3119
|
}
|
|
3120
3120
|
} catch (err) {
|
|
@@ -3152,7 +3152,7 @@
|
|
|
3152
3152
|
out += '\n';
|
|
3153
3153
|
first = false;
|
|
3154
3154
|
}
|
|
3155
|
-
out += "".concat(spaces, "if (").concat(prevCheck, "!
|
|
3155
|
+
out += "".concat(spaces, "if (").concat(prevCheck, "!inspectType(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(name, "')) {\n");
|
|
3156
3156
|
out += "".concat(spaces, " youCanAddABreakpointHere();\n").concat(spaces, "}\n");
|
|
3157
3157
|
},
|
|
3158
3158
|
_ret;
|
|
@@ -3316,7 +3316,6 @@
|
|
|
3316
3316
|
* original source code commented with an error if processing fails.
|
|
3317
3317
|
*/
|
|
3318
3318
|
function addTypeChecks(src, options) {
|
|
3319
|
-
console.log("GOT OPTIONS", options);
|
|
3320
3319
|
try {
|
|
3321
3320
|
var asserter = new Asserter(options);
|
|
3322
3321
|
var ast = parser.parse(src, {
|
|
@@ -3461,8 +3460,8 @@
|
|
|
3461
3460
|
* or an object representing the type.
|
|
3462
3461
|
*
|
|
3463
3462
|
* @param {TypeScriptType} node - The TypeScript AST node to convert.
|
|
3464
|
-
* @returns {string | {type: string, [key: string]: any} | undefined} The source string
|
|
3465
|
-
* or `undefined` if the node kind is not handled.
|
|
3463
|
+
* @returns {string | number | boolean | {type: string, [key: string]: any} | undefined} The source string/number,
|
|
3464
|
+
* or an object with type information based on the node, or `undefined` if the node kind is not handled.
|
|
3466
3465
|
*/
|
|
3467
3466
|
function toSourceTS(node) {
|
|
3468
3467
|
var typeArguments = node.typeArguments,
|
|
@@ -3667,19 +3666,24 @@
|
|
|
3667
3666
|
case NamedTupleMember:
|
|
3668
3667
|
return toSourceTS(node.type);
|
|
3669
3668
|
case IntersectionType:
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3669
|
+
{
|
|
3670
|
+
var _members = node.types.map(toSourceTS);
|
|
3671
|
+
return {
|
|
3672
|
+
type: 'intersection',
|
|
3673
|
+
members: _members
|
|
3674
|
+
};
|
|
3675
|
+
}
|
|
3674
3676
|
case TupleType:
|
|
3677
|
+
var elements = node.elements.map(toSourceTS);
|
|
3675
3678
|
return {
|
|
3676
3679
|
type: 'tuple',
|
|
3677
|
-
elements:
|
|
3680
|
+
elements: elements
|
|
3678
3681
|
};
|
|
3679
3682
|
case UnionType:
|
|
3683
|
+
var members = node.types.map(toSourceTS);
|
|
3680
3684
|
return {
|
|
3681
3685
|
type: 'union',
|
|
3682
|
-
members:
|
|
3686
|
+
members: members
|
|
3683
3687
|
};
|
|
3684
3688
|
case TypeLiteral:
|
|
3685
3689
|
var properties = {};
|
|
@@ -3698,10 +3702,13 @@
|
|
|
3698
3702
|
case Identifier:
|
|
3699
3703
|
return node.text;
|
|
3700
3704
|
case ArrayType:
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
+
{
|
|
3706
|
+
var _elementType4 = toSourceTS(node.elementType);
|
|
3707
|
+
return {
|
|
3708
|
+
type: 'array',
|
|
3709
|
+
elementType: _elementType4
|
|
3710
|
+
};
|
|
3711
|
+
}
|
|
3705
3712
|
case LiteralType:
|
|
3706
3713
|
return toSourceTS(node.literal);
|
|
3707
3714
|
case AnyKeyword:
|
|
@@ -3709,16 +3716,19 @@
|
|
|
3709
3716
|
// ts.SyntaxKind[parseType("*").kind] === 'JSDocAllType'
|
|
3710
3717
|
case JSDocAllType:
|
|
3711
3718
|
case NullKeyword:
|
|
3712
|
-
case NumericLiteral:
|
|
3713
3719
|
case StringLiteral:
|
|
3714
3720
|
case ThisType:
|
|
3715
3721
|
case UndefinedKeyword:
|
|
3716
|
-
case TrueKeyword:
|
|
3717
|
-
case FalseKeyword:
|
|
3718
3722
|
case VoidKeyword:
|
|
3719
3723
|
case UnknownKeyword:
|
|
3720
3724
|
case NeverKeyword:
|
|
3721
3725
|
return node.getText();
|
|
3726
|
+
case TrueKeyword:
|
|
3727
|
+
return true;
|
|
3728
|
+
case FalseKeyword:
|
|
3729
|
+
return false;
|
|
3730
|
+
case NumericLiteral:
|
|
3731
|
+
return Number(node.getText());
|
|
3722
3732
|
case ObjectKeyword:
|
|
3723
3733
|
return {
|
|
3724
3734
|
type: 'object',
|
package/index.mjs
CHANGED
|
@@ -2400,7 +2400,7 @@ class Asserter extends Stringifier {
|
|
|
2400
2400
|
if (!this.addHeader) {
|
|
2401
2401
|
return '';
|
|
2402
2402
|
}
|
|
2403
|
-
let header = "import {
|
|
2403
|
+
let header = "import {inspectType, youCanAddABreakpointHere";
|
|
2404
2404
|
if (this.validateDivision) {
|
|
2405
2405
|
header += ", validateDivision";
|
|
2406
2406
|
}
|
|
@@ -2735,7 +2735,7 @@ class Asserter extends Stringifier {
|
|
|
2735
2735
|
continue;
|
|
2736
2736
|
}
|
|
2737
2737
|
const _t = JSON.stringify(type.elementType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
2738
|
-
out += `${spaces}if (!
|
|
2738
|
+
out += `${spaces}if (!inspectType(${element.name}, ${_t}, '${_loc}', '${name}')) {\n`;
|
|
2739
2739
|
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
2740
2740
|
}
|
|
2741
2741
|
continue;
|
|
@@ -2757,7 +2757,7 @@ class Asserter extends Stringifier {
|
|
|
2757
2757
|
continue;
|
|
2758
2758
|
}
|
|
2759
2759
|
const _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
|
|
2760
|
-
out += `${spaces}if (!
|
|
2760
|
+
out += `${spaces}if (!inspectType(${keyName}, ${_t2}, '${_loc}', '${name}')) {\n`;
|
|
2761
2761
|
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
2762
2762
|
}
|
|
2763
2763
|
continue;
|
|
@@ -2790,7 +2790,7 @@ class Asserter extends Stringifier {
|
|
|
2790
2790
|
out += '\n';
|
|
2791
2791
|
first = false;
|
|
2792
2792
|
}
|
|
2793
|
-
out += `${spaces}if (${prevCheck}!
|
|
2793
|
+
out += `${spaces}if (${prevCheck}!inspectType(${name}, ${t}, '${_loc3}', '${name}')) {\n`;
|
|
2794
2794
|
out += `${spaces} youCanAddABreakpointHere();\n${spaces}}\n`;
|
|
2795
2795
|
}
|
|
2796
2796
|
return out;
|
|
@@ -2934,7 +2934,6 @@ class Asserter extends Stringifier {
|
|
|
2934
2934
|
* original source code commented with an error if processing fails.
|
|
2935
2935
|
*/
|
|
2936
2936
|
function addTypeChecks(src, options) {
|
|
2937
|
-
console.log("GOT OPTIONS", options);
|
|
2938
2937
|
try {
|
|
2939
2938
|
const asserter = new Asserter(options);
|
|
2940
2939
|
const ast = parse(src, {
|
|
@@ -3079,8 +3078,8 @@ function parseType(str) {
|
|
|
3079
3078
|
* or an object representing the type.
|
|
3080
3079
|
*
|
|
3081
3080
|
* @param {TypeScriptType} node - The TypeScript AST node to convert.
|
|
3082
|
-
* @returns {string | {type: string, [key: string]: any} | undefined} The source string
|
|
3083
|
-
* or `undefined` if the node kind is not handled.
|
|
3081
|
+
* @returns {string | number | boolean | {type: string, [key: string]: any} | undefined} The source string/number,
|
|
3082
|
+
* or an object with type information based on the node, or `undefined` if the node kind is not handled.
|
|
3084
3083
|
*/
|
|
3085
3084
|
function toSourceTS(node) {
|
|
3086
3085
|
const {
|
|
@@ -3292,19 +3291,24 @@ function toSourceTS(node) {
|
|
|
3292
3291
|
case NamedTupleMember:
|
|
3293
3292
|
return toSourceTS(node.type);
|
|
3294
3293
|
case IntersectionType:
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3294
|
+
{
|
|
3295
|
+
const _members = node.types.map(toSourceTS);
|
|
3296
|
+
return {
|
|
3297
|
+
type: 'intersection',
|
|
3298
|
+
members: _members
|
|
3299
|
+
};
|
|
3300
|
+
}
|
|
3299
3301
|
case TupleType:
|
|
3302
|
+
const elements = node.elements.map(toSourceTS);
|
|
3300
3303
|
return {
|
|
3301
3304
|
type: 'tuple',
|
|
3302
|
-
elements
|
|
3305
|
+
elements
|
|
3303
3306
|
};
|
|
3304
3307
|
case UnionType:
|
|
3308
|
+
const members = node.types.map(toSourceTS);
|
|
3305
3309
|
return {
|
|
3306
3310
|
type: 'union',
|
|
3307
|
-
members
|
|
3311
|
+
members
|
|
3308
3312
|
};
|
|
3309
3313
|
case TypeLiteral:
|
|
3310
3314
|
const properties = {};
|
|
@@ -3323,10 +3327,13 @@ function toSourceTS(node) {
|
|
|
3323
3327
|
case Identifier:
|
|
3324
3328
|
return node.text;
|
|
3325
3329
|
case ArrayType:
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
+
{
|
|
3331
|
+
const elementType = toSourceTS(node.elementType);
|
|
3332
|
+
return {
|
|
3333
|
+
type: 'array',
|
|
3334
|
+
elementType
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3330
3337
|
case LiteralType:
|
|
3331
3338
|
return toSourceTS(node.literal);
|
|
3332
3339
|
case AnyKeyword:
|
|
@@ -3334,16 +3341,19 @@ function toSourceTS(node) {
|
|
|
3334
3341
|
// ts.SyntaxKind[parseType("*").kind] === 'JSDocAllType'
|
|
3335
3342
|
case JSDocAllType:
|
|
3336
3343
|
case NullKeyword:
|
|
3337
|
-
case NumericLiteral:
|
|
3338
3344
|
case StringLiteral:
|
|
3339
3345
|
case ThisType:
|
|
3340
3346
|
case UndefinedKeyword:
|
|
3341
|
-
case TrueKeyword:
|
|
3342
|
-
case FalseKeyword:
|
|
3343
3347
|
case VoidKeyword:
|
|
3344
3348
|
case UnknownKeyword:
|
|
3345
3349
|
case NeverKeyword:
|
|
3346
3350
|
return node.getText();
|
|
3351
|
+
case TrueKeyword:
|
|
3352
|
+
return true;
|
|
3353
|
+
case FalseKeyword:
|
|
3354
|
+
return false;
|
|
3355
|
+
case NumericLiteral:
|
|
3356
|
+
return Number(node.getText());
|
|
3347
3357
|
case ObjectKeyword:
|
|
3348
3358
|
return {
|
|
3349
3359
|
type: 'object',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtime-type-inspector/transpiler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/parser": "^7.23.0",
|
|
21
|
-
"@runtime-type-inspector/runtime": "^
|
|
21
|
+
"@runtime-type-inspector/runtime": "^3.0.0",
|
|
22
22
|
"typescript": "^5.1.6"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|