@runtime-type-inspector/transpiler 3.3.3 → 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.
Files changed (3) hide show
  1. package/index.cjs +46 -38
  2. package/index.mjs +38 -30
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -3257,7 +3257,7 @@
3257
3257
  if (!this.addHeader) {
3258
3258
  return '';
3259
3259
  }
3260
- var header = "import {inspectType, youCanAddABreakpointHere, registerVariable";
3260
+ var header = "import {inspectType, inspectTypeWithTemplates, youCanAddABreakpointHere, registerVariable";
3261
3261
  if (this.validateDivision) {
3262
3262
  header += ", validateDivision";
3263
3263
  }
@@ -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(name, "', rtiTemplates)) {\n");
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(name, "')) {\n");
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' && type.type === 'object') {
3673
- // Add a type assertion for each property of the ObjectPattern
3674
- var _iterator2 = _createForOfIteratorHelper(param.left.properties),
3675
- _step2;
3676
- try {
3677
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3678
- var property = _step2.value;
3679
- if (property.key.type !== 'Identifier') {
3680
- _this2.warn('ObjectPattern> Only Identifier case handled right now');
3681
- continue;
3682
- }
3683
- var keyName = property.key.name;
3684
- if (type.type !== 'object' || !type.properties) {
3685
- _this2.warn("missing subtype information in JSDoc> in type", JSON.stringify(type, null, 2), "for ObjectPattern:", _this2.toSource(property).trim());
3686
- continue;
3687
- }
3688
- var subType = type.properties[keyName];
3689
- if (!subType) {
3690
- _this2.warn("missing subtype information in JSDoc");
3691
- continue;
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
- var _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
3694
- if (templates) {
3695
- out += "".concat(spaces, "if (!inspectTypeWithTemplates(").concat(keyName, ", ").concat(_t2, ", '").concat(_loc, "', '").concat(name, "', rtiTemplates)) {\n");
3696
- } else {
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
- } catch (err) {
3702
- _iterator2.e(err);
3703
- } finally {
3704
- _iterator2.f();
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(name, "', rtiTemplates)) {\n");
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(name, "')) {\n");
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
@@ -2952,7 +2952,7 @@ class Asserter extends Stringifier {
2952
2952
  if (!this.addHeader) {
2953
2953
  return '';
2954
2954
  }
2955
- let header = "import {inspectType, youCanAddABreakpointHere, registerVariable";
2955
+ let header = "import {inspectType, inspectTypeWithTemplates, youCanAddABreakpointHere, registerVariable";
2956
2956
  if (this.validateDivision) {
2957
2957
  header += ", validateDivision";
2958
2958
  }
@@ -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}', '${name}', rtiTemplates)) {\n`;
3347
+ out += `${spaces}if (!inspectTypeWithTemplates(${element.name}, ${_t}, '${_loc}', '${nameFancy}', rtiTemplates)) {\n`;
3346
3348
  } else {
3347
- out += `${spaces}if (!inspectType(${element.name}, ${_t}, '${_loc}', '${name}')) {\n`;
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' && type.type === 'object') {
3353
- // Add a type assertion for each property of the ObjectPattern
3354
- for (const property of param.left.properties) {
3355
- if (property.key.type !== 'Identifier') {
3356
- this.warn('ObjectPattern> Only Identifier case handled right now');
3357
- continue;
3358
- }
3359
- const keyName = property.key.name;
3360
- if (type.type !== 'object' || !type.properties) {
3361
- this.warn("missing subtype information in JSDoc> in type", JSON.stringify(type, null, 2), "for ObjectPattern:", this.toSource(property).trim());
3362
- continue;
3363
- }
3364
- const subType = type.properties[keyName];
3365
- if (!subType) {
3366
- this.warn("missing subtype information in JSDoc");
3367
- continue;
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
- const _t2 = JSON.stringify(subType, null, 2).replaceAll('\n', '\n' + spaces);
3370
- if (templates) {
3371
- out += `${spaces}if (!inspectTypeWithTemplates(${keyName}, ${_t2}, '${_loc}', '${name}', rtiTemplates)) {\n`;
3372
- } else {
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}', '${name}', rtiTemplates)) {\n`;
3416
+ out += `${spaces}if (${prevCheck}!inspectTypeWithTemplates(${name}, ${t}, '${_loc3}', '${nameFancy}', rtiTemplates)) {\n`;
3409
3417
  } else {
3410
- out += `${spaces}if (${prevCheck}!inspectType(${name}, ${t}, '${_loc3}', '${name}')) {\n`;
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.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.3",
22
+ "@runtime-type-inspector/runtime": "^3.3.5",
23
23
  "typescript": "^5.1.6"
24
24
  },
25
25
  "files": [