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

Case of FunctionExpression containing its own leadingComments is not handled #56

Closed kungfooman closed 10 months ago

kungfooman commented 10 months ago

Example:

/**
 * @param {number} a - Left hand side value.
 */
function add(a) {
  return (
    /**
     * @param {number} b Value.
     * @returns {number} Sum of a and b.
     */
    function (b) {
      return a + b;
    }
  );
}

Output:

/**
 * @param {number} a - Left hand side value.
 */
function add(a) {
  if (!assertType(a, "number", 'add', 'a')) {
    youCanAddABreakpointHere();
  }
  return (/**
   * @param {number} b Value.
   * @returns {number} Sum of a and b.
   */ function (b) {
    return a + b;
  });
}

The bug here is that the inner function lacks inserted type validations, even though we have the types present.

To fix: