documentation icon indicating copy to clipboard operation
documentation copied to clipboard

ES6 class constructor doesn't support destructured function parameters

Open brycecoldcocacola opened this issue 5 years ago • 1 comments

Information

  • Node.js version: 12.14.1
  • npm version: 6.11.3
  • Documentation.js version: 12.1.4
  • Method of running:
    • Node.js / npm
    • Installed documentation.js globally using npm install -g documentation
    • Running documentation build test.js -f md > test.md
  • Expected behavior
    • Parameters block for class constructor should use animals instead of $0 and maintain documentation for fishes parameters

Input code (test.js)

/** test class */
export class Test {

    /**
    * This method has hierarchical params
    * @param {Object} animals different kinds of animals
    * @param {String} animals.fishes number of kinds of fish
    */
    constructor({ fishes, foxes }) {
        return fishes + foxes;
    }

    /**
    * This method has hierarchical params
    * @param {Object} animals different kinds of animals
    * @param {String} animals.fishes number of kinds of fish
    */
    method1({ fishes, foxes }) {
        return fishes + foxes;
    }

}

Output documentation (test.md)

Table of Contents

  • Test
    • Parameters
    • method1
      • Parameters

Test

test class

Parameters

  • $0 Object
    • $0.fishes
    • $0.foxes
  • animals Object different kinds of animals

method1

This method has hierarchical params

Parameters

  • animals Object different kinds of animals
    • animals.fishes String number of kinds of fish
    • animals.foxes

brycecoldcocacola avatar Feb 20 '20 01:02 brycecoldcocacola

Not sure whether it is a proper solution or not, but if you move the description of the constructor to the description of the class, it will work:

/** test class
 * @param {Object} animals different kinds of animals
 * @param {String} animals.fishes number of kinds of fish
 */
module.exports = class Test {
  constructor({ fishes, foxes }) {
    this.fishes = fishes;
    this.foxes = foxes;
  }

  /**
   * This method has hierarchical params
   * @param {Object} animals different kinds of animals
   * @param {String} animals.fishes number of kinds of fish
   */
  method1({ fishes, foxes }) {
    return fishes + foxes;
  }
};

Demo:

Test

test class

Parameters

  • animals Object different kinds of animals

    • animals.fishes String number of kinds of fish

method1

This method has hierarchical params

Parameters

  • animals Object different kinds of animals

    • animals.fishes String number of kinds of fish
    • animals.foxes

igoradamenko avatar Dec 29 '21 10:12 igoradamenko