Jsdoc: ES6 module exporting ES6 class omits members

Created on 13 Nov 2016  Â·  13Comments  Â·  Source: jsdoc/jsdoc

The following class:

/**
 * Test module.
 * @module foo
 */

/**
 * Test class.
 */
export class Foo {

  /**
   * Test method.
   */
  testMethod() {
  }
}

fails to emit documentation for testMethod. You can run jsdoc foo.js and see the result immediately.

Based on my investigations of why our docs broke, the salient problem is here in the --explain output:

    {
        "comment": "/**\n * Test class.\n */",
        "meta": {
            "range": [
                63,
                135
            ],
            "filename": "foo.js",
            "lineno": 9,
            "path": "/Users/mdb/research/jsdoc-es6-bug",
            "code": {
                "id": "astnode100000001",
                "name": "exports.Foo",
                "type": "ClassDeclaration"
            }
        },
        "classdesc": "Test class.",
        "name": "Foo",
        "longname": "module:foo.Foo",
        "kind": "class",
        "memberof": "module:foo",
        "scope": "static"
    },

Where exports.Foo appears, this seems to break things. When I make changes that cause that to be just Foo, things work.

explain.txt
foo.js.txt

bugfix

Most helpful comment

Oh, maybe you're having a different issue after all?

For, me

export class Foo {}

didn't work right, but

class Foo {}

export {Foo}

does.

All 13 comments

When the export is on the class declaration, an additional node is inserted into the explain output. With export we get:

    {
        "comment": "/**\n * Test class.\n */",
        "meta": {
            "range": [
                63,
                135
            ],
            "filename": "foo.js",
            "lineno": 9,
            "path": "/Users/mdb/research/jsdoc-es6-bug",
            "code": {
                "id": "astnode100000001",
                "name": "exports.Foo",
                "type": "ClassDeclaration"
            }
        },
        "classdesc": "Test class.",
        "name": "Foo",
        "longname": "module:foo.Foo",
        "kind": "class",
        "memberof": "module:foo",
        "scope": "static"
    },
    {
        "comment": "",
        "meta": {
            "range": [
                70,
                135
            ],
            "filename": "foo.js",
            "lineno": 9,
            "path": "/Users/mdb/research/jsdoc-es6-bug",
            "code": {
                "id": "astnode100000002",
                "name": "Foo",
                "type": "ClassDeclaration",
                "paramnames": []
            }
        },
        "undocumented": true,
        "name": "Foo",
        "longname": "module:foo~Foo",
        "kind": "class",
        "scope": "inner",
        "memberof": "module:foo"
    },

and without the export (where testMethod documentation is generated properly) we get only:

    {
        "comment": "/**\n * Test class.\n */",
        "meta": {
            "range": [
                63,
                128
            ],
            "filename": "foo.js",
            "lineno": 9,
            "path": "/Users/mdb/research/jsdoc-es6-bug",
            "code": {
                "id": "astnode100000001",
                "name": "Foo",
                "type": "ClassDeclaration",
                "paramnames": []
            }
        },
        "classdesc": "Test class.",
        "name": "Foo",
        "longname": "module:foo~Foo",
        "kind": "class",
        "scope": "inner",
        "memberof": "module:foo"
    },

Hi, is there any workaround for this?

I'm having the same issue. Has anyone found a fix?

Not exactly a fix, but I worked around it by not marking classes as exported, instead exporting them "manually" at the end of the file.

What do you mean manually? I use Classs Foo{} module.exports = Foo;

Oh, maybe you're having a different issue after all?

For, me

export class Foo {}

didn't work right, but

class Foo {}

export {Foo}

does.

Very similar to what I do. I do

class Foo{
//Members etc
}

module.exports = Foo;

I actually found out how to get this working. Instead of starting my module with

/**
 * @module Foo
 * @exports Foo.Bar <-- ModuleName.ClassName
*/

I do

/** @module Foo */ <-- No exports tag

/**
 * @class
 * @memberof module:Foo  <-- instead, explicitly tell JSDOC what module the class is a part of
 */
class Bar{
    constructor(){
       /**
        * This is the text description of the method.
        * @member {String} module:Foo.Bar#StringMember <-- This generates the documentation correctly
        */
        this.StringMember = 'blah';
    }
}

module.exports = Foo;

By using @member {Type} module:ModuleName.ClassName#MemberName we tell JSDOC explicitly what to do. It's a bit more time consuming. But at least it works..

¯_(ツ)_/¯

Fixed on master. The fix will be included in JSDoc 3.5.0.

I'm still having this issue ([email protected]); the following file shows the constructor and the class, but all the virtual members are not appearing:

import { Record } from "immutable";

const schema = {
    userID: null,
    isAnonymous: true,
    isPresent: true,
    order: null,
    color: "",
    user: null
};

/**
 * Record representing a player in a particular game.
 *
 * @memberof client.records
 * @extends Immutable.Record
 */
class PlayerRecord extends Record(schema, "Player") {
    /**
     * @param {object} args - the constructor arguments
     * @param {string} args.userID - the ID of the user represented by this player
     * @param {object} args.user - the user represented by this player. If specified,
     *  this should contain an `id` key with the user ID. This parameter should be avoided;
     *  use the `userID` parameter instead (the user data will not be stored in this record
     *  anyway)
     */
    constructor(args) {
        if (args.user && !args.userID) {
            args.userID = args.user.id;
            delete args.user;
        }

        super(args);
    }

    /**
     * The ID of the user represented by this player
     *
     * @member {string} userID
     */

    /**
     * @member {boolean} isAnonymous - whether or not the user has a site account
     */

    /**
     * @member {boolean} isPresent - whether or not the player is present in the game
     */

    /**
     * @member {Number} order - the index (0-based) of where this player falls in the
     *  turn order for the game
     */

    /**
     * @member {string} color - the color representing this player in the game
     */
}

export default PlayerRecord;

I am also still having the issue with jsdoc3.5.5.

Documentation is not generating for class members. It is generating only for constructor

export class Foo {
  /**
   * @description Test description
   */
  constructor() {
  }

 /**
  * @summary
  * Creates an Test Method
  * @desc 
  * Test Methd
  * @memberof Foo
  */
  test() {
 }
}

You don't need @memberof and that might be messing things up. Does it work if you remove that?

@samskivert Thanks!
After adding the header string It's working fine.

/** Class representing Foo. */
export class Foo {
  /**
   * @description Test description
   */
  constructor() {
  }

 /**
  * @summary
  * Creates an Test Method
  * @desc 
  * Test Method
  */
  test() {
 }
}

I'm still having this problem in 3.6.3:

/**
 * @memberof PIXI.brend
 */
export class BatchRenderer {}

I am forced to change it to:

/**
 * @memberof PIXI.brend
 */
class BatchRenderer {}

export { BatchRenderer };
Was this page helpful?
0 / 5 - 0 ratings

Related issues

anselmbradford picture anselmbradford  Â·  14Comments

adrian-moisa picture adrian-moisa  Â·  19Comments

opvasger picture opvasger  Â·  31Comments

coryroloff picture coryroloff  Â·  18Comments

cowwoc picture cowwoc  Â·  29Comments