Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deiwin opened this issue Oct 30, 2023 · 1 comment
Open

Comments

@deiwin
Copy link

deiwin commented Oct 30, 2023

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
@johnnymast
Copy link

I am having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants