englercj / tsd-jsdoc

Compiles JSDoc annotated JavaScript into a Typescript Definition file (.d.ts)
MIT License
316 stars 42 forks source link

Error message for private subclass of public superclass #105

Open willeastcott opened 5 years ago

willeastcott commented 5 years ago

The following JavaScript:

/**
 * @constructor
 * @name Animal
 * @classdesc An animal.
 * @description Creates a new animal.
 */
function Animal() {
    this.x = 0;
    this.y = 0;
}

/**
 * @function
 * @name Animal#move
 * @description Move the animal to the specified location.
 * @param {Number} x - X-coordinate.
 * @param {Number} y - Y-coordinate.
 */
Animal.prototype.move = function (x, y) {
    this.x = x;
    this.y = y;
}

/**
 * @private
 * @constructor
 * @name Dog
 * @extends Animal
 * @classdesc A dog.
 * @description Creates a new dog.
 */
function Dog() {}

Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;

/**
 * @private
 * @function
 * @name Dog#bark
 * @description The dog barks.
 */
Dog.prototype.bark = function () {
    console.log('Woof!');
}

...generates this message:

[TSD-JSDoc] Failed to find parent of doclet 'Dog#move' using memberof 'Dog', this is likely due to invalid JSDoc.

This bug is currently afflicting the PlayCanvas engine. See forum post.

englercj commented 4 years ago

Look like this is because the move function is not marked private by jsdoc so we try to document it. When we try to lookup where it belongs we fail to find the Dog class because it is private.

The implementation should probably still track private objects so we can tell the difference between an unknown symbol and an existing, but private, symbol. In the later case we can skip the move/bark functions and not output the warning.

aidinabedi commented 4 years ago

This issue is fixed now by merged PR #126 in latest release

thw0rted commented 4 years ago

It looks like #126 did not fix this; at the very least, there should be a test case for this specific problem (@private class, with a @memberof tag on a prototype function) and the tests added for that PR definitely do not include one.