jsdoc / jsdoc

An API documentation generator for JavaScript.
https://jsdoc.app/
Apache License 2.0
15.05k stars 1.45k forks source link

When the default export is a pre-ES2015 constructor function, its members get the wrong longname #1079

Open isergey opened 9 years ago

isergey commented 9 years ago

Hello! I try to generate documentation for file Leader.js, but in output I found only source description file - Leader.js.html, but Leader.html doesn't exist. What's wrong? Where the Leader.html? Thanks for help!

$ node_modules/jsdoc/jsdoc.js Leader.js -c conf.json

conf.json

{
    "plugins": ["node_modules/jsdoc-babel"]
}

Leader.js


/**
 * Record leader
 * @param {string} data leader data
 * @constructor
 */
export default function Leader(data) {
  this._data = data || '';
}

/**
 * Get leader data
 * @return {String} data
 */
Leader.prototype.getData = function() {
  return this._data;
};

/**
 * Set leader data
 * @param {string} newData
 * @return {String} data
 */
Leader.prototype.setData = function(newData) {
  this._data = newData || '';
  return this;
};
hegemonic commented 8 years ago

You also need a @module tag at the start of the file, like /** @module mymodulename */. But it looks like there's also a bug where we use the wrong name for members of the default export. I'll look into this.

For now, you can work around this in one of two ways:

  1. Use ES2015 classes, which don't have this problem (on GitHub master, that is; they are buggy in JSDoc 3.4.0).
  2. Add an @alias tag to help JSDoc name each symbol correctly. For example, if your module is named leader, you would comment Leader.prototype.getData like so:

    /**
    * Get leader data
    * @alias module:leader#getData
    * @return {String} data
    */
    Leader.prototype.getData = function() {
     return this._data;
    };
kruncher commented 8 years ago

I am finding that methods of my exported class are not being picked up by jsdoc; I think that this may be related to this issue.

/** @module foo/lib/Environment */

/**
 * Represents the environment of a foo project.
 */
export default class Environment {

  /**
   * Builds output of the foo project that is described by this environment.
   *
   * @returns {Promise}
   *   A promise to complete the build.
   */
  build() {
    return this.behaviors.buildOutput(this);
  }

}

Here is the output that I see for the above:

image

It may just be that I am making a silly mistake; but I seem to be following the advice provided in the ES2015 module section of the documentation.

Many thanks

chgibb commented 7 years ago

I don't mean to resurrect an old thread, but I am having an identical issue with identical output to what @kruncher posted. I am however using an anonymous class as my only export. Only my constructor is being documented, no other methods are having their documentation generated.

module.exports = class