@runtime-type-inspector/transpiler 2.2.5 → 3.0.1

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.
Files changed (3) hide show
  1. package/index.cjs +30 -19
  2. package/index.mjs +30 -19
  3. 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 {assertType, youCanAddABreakpointHere";
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 (!assertType(").concat(element.name, ", ").concat(_t, ", '").concat(_loc, "', '").concat(name, "')) {\n");
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 (!assertType(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(name, "')) {\n");
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, "!assertType(").concat(name, ", ").concat(t, ", '").concat(loc, "', '").concat(name, "')) {\n");
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;
@@ -3460,8 +3460,8 @@
3460
3460
  * or an object representing the type.
3461
3461
  *
3462
3462
  * @param {TypeScriptType} node - The TypeScript AST node to convert.
3463
- * @returns {string | {type: string, [key: string]: any} | undefined} The source string or an object with type information based on the node,
3464
- * 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.
3465
3465
  */
3466
3466
  function toSourceTS(node) {
3467
3467
  var typeArguments = node.typeArguments,
@@ -3666,19 +3666,24 @@
3666
3666
  case NamedTupleMember:
3667
3667
  return toSourceTS(node.type);
3668
3668
  case IntersectionType:
3669
- return {
3670
- type: 'intersection',
3671
- members: node.types.map(toSourceTS)
3672
- };
3669
+ {
3670
+ var _members = node.types.map(toSourceTS);
3671
+ return {
3672
+ type: 'intersection',
3673
+ members: _members
3674
+ };
3675
+ }
3673
3676
  case TupleType:
3677
+ var elements = node.elements.map(toSourceTS);
3674
3678
  return {
3675
3679
  type: 'tuple',
3676
- elements: node.elements.map(toSourceTS)
3680
+ elements: elements
3677
3681
  };
3678
3682
  case UnionType:
3683
+ var members = node.types.map(toSourceTS);
3679
3684
  return {
3680
3685
  type: 'union',
3681
- members: node.types.map(toSourceTS)
3686
+ members: members
3682
3687
  };
3683
3688
  case TypeLiteral:
3684
3689
  var properties = {};
@@ -3697,10 +3702,13 @@
3697
3702
  case Identifier:
3698
3703
  return node.text;
3699
3704
  case ArrayType:
3700
- return {
3701
- type: 'array',
3702
- elementType: toSourceTS(node.elementType)
3703
- };
3705
+ {
3706
+ var _elementType4 = toSourceTS(node.elementType);
3707
+ return {
3708
+ type: 'array',
3709
+ elementType: _elementType4
3710
+ };
3711
+ }
3704
3712
  case LiteralType:
3705
3713
  return toSourceTS(node.literal);
3706
3714
  case AnyKeyword:
@@ -3708,16 +3716,19 @@
3708
3716
  // ts.SyntaxKind[parseType("*").kind] === 'JSDocAllType'
3709
3717
  case JSDocAllType:
3710
3718
  case NullKeyword:
3711
- case NumericLiteral:
3712
3719
  case StringLiteral:
3713
3720
  case ThisType:
3714
3721
  case UndefinedKeyword:
3715
- case TrueKeyword:
3716
- case FalseKeyword:
3717
3722
  case VoidKeyword:
3718
3723
  case UnknownKeyword:
3719
3724
  case NeverKeyword:
3720
3725
  return node.getText();
3726
+ case TrueKeyword:
3727
+ return true;
3728
+ case FalseKeyword:
3729
+ return false;
3730
+ case NumericLiteral:
3731
+ return Number(node.getText());
3721
3732
  case ObjectKeyword:
3722
3733
  return {
3723
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 {assertType, youCanAddABreakpointHere";
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 (!assertType(${element.name}, ${_t}, '${_loc}', '${name}')) {\n`;
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 (!assertType(${keyName}, ${_t2}, '${_loc}', '${name}')) {\n`;
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}!assertType(${name}, ${t}, '${_loc3}', '${name}')) {\n`;
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;
@@ -3078,8 +3078,8 @@ function parseType(str) {
3078
3078
  * or an object representing the type.
3079
3079
  *
3080
3080
  * @param {TypeScriptType} node - The TypeScript AST node to convert.
3081
- * @returns {string | {type: string, [key: string]: any} | undefined} The source string or an object with type information based on the node,
3082
- * 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.
3083
3083
  */
3084
3084
  function toSourceTS(node) {
3085
3085
  const {
@@ -3291,19 +3291,24 @@ function toSourceTS(node) {
3291
3291
  case NamedTupleMember:
3292
3292
  return toSourceTS(node.type);
3293
3293
  case IntersectionType:
3294
- return {
3295
- type: 'intersection',
3296
- members: node.types.map(toSourceTS)
3297
- };
3294
+ {
3295
+ const _members = node.types.map(toSourceTS);
3296
+ return {
3297
+ type: 'intersection',
3298
+ members: _members
3299
+ };
3300
+ }
3298
3301
  case TupleType:
3302
+ const elements = node.elements.map(toSourceTS);
3299
3303
  return {
3300
3304
  type: 'tuple',
3301
- elements: node.elements.map(toSourceTS)
3305
+ elements
3302
3306
  };
3303
3307
  case UnionType:
3308
+ const members = node.types.map(toSourceTS);
3304
3309
  return {
3305
3310
  type: 'union',
3306
- members: node.types.map(toSourceTS)
3311
+ members
3307
3312
  };
3308
3313
  case TypeLiteral:
3309
3314
  const properties = {};
@@ -3322,10 +3327,13 @@ function toSourceTS(node) {
3322
3327
  case Identifier:
3323
3328
  return node.text;
3324
3329
  case ArrayType:
3325
- return {
3326
- type: 'array',
3327
- elementType: toSourceTS(node.elementType)
3328
- };
3330
+ {
3331
+ const elementType = toSourceTS(node.elementType);
3332
+ return {
3333
+ type: 'array',
3334
+ elementType
3335
+ };
3336
+ }
3329
3337
  case LiteralType:
3330
3338
  return toSourceTS(node.literal);
3331
3339
  case AnyKeyword:
@@ -3333,16 +3341,19 @@ function toSourceTS(node) {
3333
3341
  // ts.SyntaxKind[parseType("*").kind] === 'JSDocAllType'
3334
3342
  case JSDocAllType:
3335
3343
  case NullKeyword:
3336
- case NumericLiteral:
3337
3344
  case StringLiteral:
3338
3345
  case ThisType:
3339
3346
  case UndefinedKeyword:
3340
- case TrueKeyword:
3341
- case FalseKeyword:
3342
3347
  case VoidKeyword:
3343
3348
  case UnknownKeyword:
3344
3349
  case NeverKeyword:
3345
3350
  return node.getText();
3351
+ case TrueKeyword:
3352
+ return true;
3353
+ case FalseKeyword:
3354
+ return false;
3355
+ case NumericLiteral:
3356
+ return Number(node.getText());
3346
3357
  case ObjectKeyword:
3347
3358
  return {
3348
3359
  type: 'object',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtime-type-inspector/transpiler",
3
- "version": "2.2.5",
3
+ "version": "3.0.1",
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": "^2.1.0",
21
+ "@runtime-type-inspector/runtime": "^3",
22
22
  "typescript": "^5.1.6"
23
23
  },
24
24
  "files": [