EnterTheNameHere / esdoc-monorepo

Monorepo for custom esdoc and all its packages.
Other
7 stars 1 forks source link

@emits links to method if the event has the same name #30

Open VividVisions opened 9 months ago

VividVisions commented 9 months ago

Is there a way to differentiate an event from a method if they have the same name (other than renaming one or both)? How to document the event itself?

EnterTheNameHere commented 9 months ago

If you have a simple example of code of such situation, it would be appreciated.

VividVisions commented 9 months ago
import { EventEmitter } from 'node:events';

/**
 * Test class
 */
class Test extends EventEmitter {
   /**
    * Foo function.
    * @emits {bar}
    */
   foo(str) {
      this.emit('bar', str);
      return str + '!';
   }

   /**
    * Bar function.
    */
   bar(num) {
      return num + 1;
   }
}

This would link the event bar to the method bar in the rendered HTML.

And there don't seem to be a way to document events as their own symbols. Something like that:

/**
 * Event bar.
 * Gets fired when foo() is called.
 *
 * @event bar
 * @param {String} - The string
 */
EnterTheNameHere commented 8 months ago

Yes, this should be easily detected by ESDoc as two different kinds, The @variation tag should also work, but it's not implemented. This can be hacked in, if needed, otherwise updated JSDoc parsing and detection will fix it in future.