@runtime-type-inspector/transpiler 3.2.4 → 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 +24 -8
  2. package/index.mjs +18 -6
  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
  /**
@@ -3580,6 +3584,7 @@
3580
3584
  }, {
3581
3585
  key: "getName",
3582
3586
  value: function getName(node) {
3587
+ var _node4, _node5;
3583
3588
  var toSource = this.toSource.bind(this);
3584
3589
  if (node.type === 'BlockStatement') {
3585
3590
  node = this.parent;
@@ -3615,10 +3620,20 @@
3615
3620
  return 'getName> missing parent for ' + node.type;
3616
3621
  case 'ObjectMethod':
3617
3622
  return toSource(key);
3618
- default:
3619
- this.warn('getName> unhandled type', type, 'for', node);
3620
- 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);
3621
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);
3622
3637
  }
3623
3638
  /**
3624
3639
  * @override
@@ -3637,7 +3652,8 @@
3637
3652
  var left_ = this.toSource(left);
3638
3653
  var right_ = this.toSource(right);
3639
3654
  if (operator === '/') {
3640
- return "validateDivision(".concat(left_, ", ").concat(right_, ")");
3655
+ var loc = this.getName(node);
3656
+ return "validateDivision(".concat(left_, ", ").concat(right_, ", ").concat(JSON.stringify(loc), ")");
3641
3657
  }
3642
3658
  return "".concat(left_, " ").concat(operator, " ").concat(right_);
3643
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
  /**
@@ -3219,6 +3221,7 @@ class Asserter extends Stringifier {
3219
3221
  * @returns {string} Stringification of the node.
3220
3222
  */
3221
3223
  getName(node) {
3224
+ var _node, _node2;
3222
3225
  const toSource = this.toSource.bind(this);
3223
3226
  if (node.type === 'BlockStatement') {
3224
3227
  node = this.parent;
@@ -3253,10 +3256,18 @@ class Asserter extends Stringifier {
3253
3256
  return 'getName> missing parent for ' + node.type;
3254
3257
  case 'ObjectMethod':
3255
3258
  return toSource(key);
3256
- default:
3257
- this.warn('getName> unhandled type', type, 'for', node);
3258
- 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}`;
3259
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}`;
3260
3271
  }
3261
3272
  /**
3262
3273
  * @override
@@ -3275,7 +3286,8 @@ class Asserter extends Stringifier {
3275
3286
  const left_ = this.toSource(left);
3276
3287
  const right_ = this.toSource(right);
3277
3288
  if (operator === '/') {
3278
- return `validateDivision(${left_}, ${right_})`;
3289
+ const loc = this.getName(node);
3290
+ return `validateDivision(${left_}, ${right_}, ${JSON.stringify(loc)})`;
3279
3291
  }
3280
3292
  return `${left_} ${operator} ${right_}`;
3281
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.4",
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.4",
22
+ "@runtime-type-inspector/runtime": "^3.2.5",
23
23
  "typescript": "^5.1.6"
24
24
  },
25
25
  "files": [