kungfooman / RuntimeTypeInspector.js

Checking JSDoc types at runtime for high-quality types - Trust is good, control is better.
MIT License
8 stars 0 forks source link

Keep param name for pattern processing #174

Closed kungfooman closed 3 weeks ago

kungfooman commented 3 weeks ago

This code:

/**
 * @param {number[]} input
 */
function add([a, b]) {
  return a + b;
}
const ret = add([10, 20]);
console.log('ret', ret);

transpiler to:

/**
 * @param {number[]} input
 */
function add([a, b]) {
  if (!inspectType(arguments[0], {
    "type": "array",
    "elementType": "number",
    "optional": false
  }, 'add', 'arguments[0]')) {
    youCanAddABreakpointHere();
  }
  return a + b;
}
const ret = add([10, 20]);
console.log('ret', ret);

What I don't like is and how it should be instead:

-  }, 'add', 'arguments[0]')) {
+  }, 'add', 'input')) {

This makes the log more informative.