Skip to content

Mixin fields are documented twice on class declarations with a constructor #2092

Open
@deiwin

Description

@deiwin

Input code

/**
 * @mixes Mixin
 */
class MyClass {
  constructor() {
  }
}

/**
 * @mixin
 */
const Mixin = {
  /**
   * A field
   */
  field: 'value'
};

Additional observations:

  1. From some debugging, I've traced the issue down to the fact that there are duplicate "doclets" for MyClass. One for the class itself, and one for the undocumented constructor. The logic that adds the mixin fields adds the fields once for each instance.
  2. Based on the above, one workaround for this is to use a simple function constructor (e.g. function MyClass() {} instead of the class declaration.
  3. I played around with the code a bit, and changing if (mixes) with if (mixes && !doclet.undocumented) here also fixes the issue, because the doclet instance for the constructor has undocumented: true in my case. I'm not sure if that would be a reasonable fix for this, though, because the duplication may still cause issues elsewhere and in other similar cases.
  4. I actually also use @hideconstructor for the MyClass equivalent, but that doesn't change the behavior and isn't necessary for reproducing this issue.

JSDoc configuration

Reproduces without any configuration.

JSDoc debug output

DEBUG: JSDoc 4.0.2 (Sun, 19 Feb 2023 23:01:18 GMT)
DEBUG: Environment info: {"env":{"conf":{"plugins":[],"recurseDepth":10,"source":{"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}}},"opts":{"_":["[redacted]test.js"],"debug":true,"destination":"docs","encoding":"utf8"}}}
DEBUG: Parsing source files: ["[redacted]/test.js"]
Parsing [redacted]/test.js ...
DEBUG: Finished parsing source files.
DEBUG: Adding inherited symbols, mixins, and interface implementations...
DEBUG: Adding borrowed doclets...
DEBUG: Post-processing complete.
Generating output files...
Finished running in 0.14 seconds.

Expected behavior

MyClass#field should only be documented once.

Current behavior

MyClass#field is documented twice.

Screenshot 2023-10-31 at 00 03 52

Your environment

Software Version
JSDoc 4.0.2
Node.js v14.21.3
npm 6.14.18
Operating system macOS 14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions