@runtime-type-inspector/transpiler 3.2.3 → 3.2.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 +29 -9
  2. package/index.mjs +23 -7
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1425,15 +1425,19 @@
1425
1425
  function get() {
1426
1426
  return ' '.repeat(this.numSpaces);
1427
1427
  }
1428
+ }, {
1429
+ key: "path",
1430
+ get: function get() {
1431
+ return this.parents.map(function (_) {
1432
+ return _.type;
1433
+ }).join('/');
1434
+ }
1428
1435
  }, {
1429
1436
  key: "debugSpaces",
1430
1437
  value: function debugSpaces() {
1431
1438
  var spaces = this.spaces,
1432
- parents = this.parents;
1439
+ path = this.path;
1433
1440
  var n = spaces.length;
1434
- var path = parents.map(function (_) {
1435
- return _.type;
1436
- }).join('/');
1437
1441
  return "".concat(spaces, "// got ").concat(n, " spaces for ").concat(path, "\n");
1438
1442
  }
1439
1443
  /**
@@ -3263,7 +3267,11 @@
3263
3267
  if (node.params.length !== 1) {
3264
3268
  this.warn("getJSDoc> setters require exactly one argument");
3265
3269
  }
3266
- return _defineProperty({}, paramName, parseJSDocSetter(lastComment.value, this.expandType));
3270
+ var setterType = parseJSDocSetter(lastComment.value, this.expandType);
3271
+ if (!setterType) {
3272
+ return;
3273
+ }
3274
+ return _defineProperty({}, paramName, setterType);
3267
3275
  }
3268
3276
  if (lastComment.value.includes('@ignoreRTI')) {
3269
3277
  return;
@@ -3576,6 +3584,7 @@
3576
3584
  }, {
3577
3585
  key: "getName",
3578
3586
  value: function getName(node) {
3587
+ var _node4, _node5;
3579
3588
  var toSource = this.toSource.bind(this);
3580
3589
  if (node.type === 'BlockStatement') {
3581
3590
  node = this.parent;
@@ -3611,10 +3620,20 @@
3611
3620
  return 'getName> missing parent for ' + node.type;
3612
3621
  case 'ObjectMethod':
3613
3622
  return toSource(key);
3614
- default:
3615
- this.warn('getName> unhandled type', type, 'for', node);
3616
- return '/*MISSING*/';
3623
+ case 'BinaryExpression':
3624
+ var goodNames = ['FunctionDeclaration', 'ClassMethod', 'ClassPrivateMethod'];
3625
+ var goodParent = this.parents.findLast(function (_) {
3626
+ return goodNames.includes(_.type);
3627
+ });
3628
+ if (goodParent) {
3629
+ return this.getName(goodParent);
3630
+ }
3631
+ // top scope
3632
+ return "".concat(this.filename, ":").concat((_node4 = node) === null || _node4 === void 0 || (_node4 = _node4.loc) === null || _node4 === void 0 || (_node4 = _node4.start) === null || _node4 === void 0 ? void 0 : _node4.line);
3617
3633
  }
3634
+ this.warn('getName> unhandled type', type, 'for', node, this.path);
3635
+ //debugger;
3636
+ return "".concat(this.filename, ":").concat((_node5 = node) === null || _node5 === void 0 || (_node5 = _node5.loc) === null || _node5 === void 0 || (_node5 = _node5.start) === null || _node5 === void 0 ? void 0 : _node5.line);
3618
3637
  }
3619
3638
  /**
3620
3639
  * @override
@@ -3633,7 +3652,8 @@
3633
3652
  var left_ = this.toSource(left);
3634
3653
  var right_ = this.toSource(right);
3635
3654
  if (operator === '/') {
3636
- return "validateDivision(".concat(left_, ", ").concat(right_, ")");
3655
+ var loc = this.getName(node);
3656
+ return "validateDivision(".concat(left_, ", ").concat(right_, ", ").concat(JSON.stringify(loc), ")");
3637
3657
  }
3638
3658
  return "".concat(left_, " ").concat(operator, " ").concat(right_);
3639
3659
  }
package/index.mjs CHANGED
@@ -1121,13 +1121,15 @@ class Stringifier {
1121
1121
  get spaces() {
1122
1122
  return ' '.repeat(this.numSpaces);
1123
1123
  }
1124
+ get path() {
1125
+ return this.parents.map(_ => _.type).join('/');
1126
+ }
1124
1127
  debugSpaces() {
1125
1128
  const {
1126
1129
  spaces,
1127
- parents
1130
+ path
1128
1131
  } = this;
1129
1132
  const n = spaces.length;
1130
- const path = parents.map(_ => _.type).join('/');
1131
1133
  return `${spaces}// got ${n} spaces for ${path}\n`;
1132
1134
  }
1133
1135
  /**
@@ -2925,8 +2927,12 @@ class Asserter extends Stringifier {
2925
2927
  if (node.params.length !== 1) {
2926
2928
  this.warn("getJSDoc> setters require exactly one argument");
2927
2929
  }
2930
+ const setterType = parseJSDocSetter(lastComment.value, this.expandType);
2931
+ if (!setterType) {
2932
+ return;
2933
+ }
2928
2934
  return {
2929
- [paramName]: parseJSDocSetter(lastComment.value, this.expandType)
2935
+ [paramName]: setterType
2930
2936
  };
2931
2937
  }
2932
2938
  if (lastComment.value.includes('@ignoreRTI')) {
@@ -3215,6 +3221,7 @@ class Asserter extends Stringifier {
3215
3221
  * @returns {string} Stringification of the node.
3216
3222
  */
3217
3223
  getName(node) {
3224
+ var _node, _node2;
3218
3225
  const toSource = this.toSource.bind(this);
3219
3226
  if (node.type === 'BlockStatement') {
3220
3227
  node = this.parent;
@@ -3249,10 +3256,18 @@ class Asserter extends Stringifier {
3249
3256
  return 'getName> missing parent for ' + node.type;
3250
3257
  case 'ObjectMethod':
3251
3258
  return toSource(key);
3252
- default:
3253
- this.warn('getName> unhandled type', type, 'for', node);
3254
- return '/*MISSING*/';
3259
+ case 'BinaryExpression':
3260
+ const goodNames = ['FunctionDeclaration', 'ClassMethod', 'ClassPrivateMethod'];
3261
+ const goodParent = this.parents.findLast(_ => goodNames.includes(_.type));
3262
+ if (goodParent) {
3263
+ return this.getName(goodParent);
3264
+ }
3265
+ // top scope
3266
+ return `${this.filename}:${(_node = node) == null || (_node = _node.loc) == null || (_node = _node.start) == null ? void 0 : _node.line}`;
3255
3267
  }
3268
+ this.warn('getName> unhandled type', type, 'for', node, this.path);
3269
+ //debugger;
3270
+ return `${this.filename}:${(_node2 = node) == null || (_node2 = _node2.loc) == null || (_node2 = _node2.start) == null ? void 0 : _node2.line}`;
3256
3271
  }
3257
3272
  /**
3258
3273
  * @override
@@ -3271,7 +3286,8 @@ class Asserter extends Stringifier {
3271
3286
  const left_ = this.toSource(left);
3272
3287
  const right_ = this.toSource(right);
3273
3288
  if (operator === '/') {
3274
- return `validateDivision(${left_}, ${right_})`;
3289
+ const loc = this.getName(node);
3290
+ return `validateDivision(${left_}, ${right_}, ${JSON.stringify(loc)})`;
3275
3291
  }
3276
3292
  return `${left_} ${operator} ${right_}`;
3277
3293
  }
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.2.3",
4
+ "version": "3.2.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.2.3",
22
+ "@runtime-type-inspector/runtime": "^3.2.5",
23
23
  "typescript": "^5.1.6"
24
24
  },
25
25
  "files": [