Jsdoc not documenting correct nodejs modules

I am trying to get JSDOC (3) to correctly document my NodeJS modules. While simple modules are working, I cannot find a way to document a slightly more complex module.

My NodeJS module has the following structure:

/** @module MyModule */
(function() {


     function functionToExportOne {...}

     function functionToExportTwo {...}

     /** 
      * @module MyModule.ClassToExportOne
      * @constructor 
      */
     function ClassToExportOne {

           this.classMethodOne=function() { ... }
           this.classMethodTwo=function() { ... }

     }

     /** @constructor */
     function ClassToExportTwo {

           function classMethodOne() { ... }
           function classMethodTwo() { ... }

           return /** @lends {ClassToExportTwo.prototype} */ {

               methodOne:classMethodOne,
               methodTwo:classMethodTwo
           }
     }
     /** @exports MyModule */  <--- late addition, see comments
     module.exports={
         functionOne:functionToExportOne,
         functionTwo:functionToExportTwo,
         classOne:ClassToExportOne,
         classTwo:ClassToExportTwo
     }
})()

Well, as you can see, the module exports both methods and class constructors. Nothing special.

The problem is that JSDOC

  • always does not recognize inner classes,
  • Errors are the first internal methods of the class as methods of the (external) module,
  • always skips the actual methods of the exported module.
  • ClassToExportOne, @module MyModule.<className>, @constructor ( ): , ,

:

  • this.method=function() {...} ( ClassToExportOne) @lends {ClassToExportTwo.prototype} ( ClassToExportTwo)
  • @module MyModule.ClassToExportOne
  • module.exports vs. export.xxxx
  • @private, @private,
  • @module ( , "", !!)
  • @exports <modulename> , ( )

, http://usejsdoc.org/howto-commonjs-modules.html .

, - , .

+4
2

jsdoc 3.3.3:

/**
 * Example model.
 *
 * @module model/example
 */
module.exports = (function () {
    /**
     * Constructor function.
     *
     * @exports model/example.Example
     * @constructor
     * @param {string} id
     */
    var example = function Example(id) {
        this.id = id;
    };

    /**
     * Returns the ID.
     *
     * @memberof model/example.Example
     * @returns {string} the id
     */
    example.prototype.getId = function () {
        return this.id;
    };

    return example;
}());

:

var example = new Example("ID");
console.log(example.getId());
+4

, . , , , , :)

, , @exports <modulename>.<classname> @constructor, "classes" this.method=function() {...}

, , , ClassToExportTwo, , , , "this" ().

Well here is a template that works for me:

/** @module MyModule */
(function() {


     function functionToExportOne {...}

     function functionToExportTwo {...}

     /** works !!
      * @exports MyModule.ClassToExportOne
      * @constructor 
      */
     function ClassToExportOne {

           function innerMethod() { ... }

           // this works: assigning methods to this

           this.classMethodOne=function() { ... }
           this.classMethodTwo=function() { ... }

     }

     /** does not work
      * @exports MyModule.ClassToExportTwo
      * @constructor 
      */         
     function ClassToExportTwo {

           function classMethodOne() { ... }
           function classMethodTwo() { ... }

           // this DOES NOT WORK !! Methods get mixed with parent module
           return  {

               methodOne:classMethodOne,
               methodTwo:classMethodTwo
           }
     }

     // no more @exports here as it duplicates definitions in the docs
     module.exports={
         /** blah blah function description */
         functionOne:functionToExportOne,
         /** blah blah function description */
         functionTwo:functionToExportTwo,
         /** blah blah function description */
         classOne:ClassToExportOne,
         /** blah blah function description */
         classTwo:ClassToExportTwo
     }
})()
+1
source

All Articles