88 EventDescriptor ,
99 ParamTag ,
1010 ParamType ,
11+ Tag ,
1112} from '../Documentation'
1213import getDocblock from '../utils/getDocblock'
1314import getDoclets from '../utils/getDoclets'
@@ -34,24 +35,31 @@ export default function eventHandler(
3435 if ( ! args . length ) {
3536 return false
3637 }
38+ // fetch the leading comments on the wrapping expression
39+ const docblock = getDocblock ( pathExpression . parentPath )
40+ const doclets = getDoclets ( docblock || '' )
41+ let eventName : string
42+ const eventTags = doclets . tags ? doclets . tags . filter ( d => d . title === 'event' ) : [ ]
43+
44+ // if someone wants to document it with anything else, they can force it
45+ if ( eventTags . length ) {
46+ eventName = ( eventTags [ 0 ] as Tag ) . content as string
47+ } else {
48+ let firstArg = pathExpression . get ( 'arguments' , 0 )
49+ if ( bt . isIdentifier ( firstArg . node ) ) {
50+ firstArg = resolveIdentifier ( astPath , firstArg )
51+ }
3752
38- let firstArg = pathExpression . get ( 'arguments' , 0 )
39- if ( bt . isIdentifier ( firstArg . node ) ) {
40- firstArg = resolveIdentifier ( astPath , firstArg )
41- }
42-
43- if ( ! bt . isStringLiteral ( firstArg . node ) ) {
44- return false
53+ if ( ! bt . isStringLiteral ( firstArg . node ) ) {
54+ return false
55+ }
56+ eventName = firstArg . node . value
4557 }
4658
47- const eventName = firstArg . node . value
48-
4959 // if this event is documented somewhere else leave it alone
5060 const evtDescriptor = documentation . getEventDescriptor ( eventName )
5161
52- // fetch the leading comments on the wrapping expression
53- const docblock = getDocblock ( pathExpression . parentPath )
54- setEventDescriptor ( evtDescriptor , getDoclets ( docblock || '' ) )
62+ setEventDescriptor ( evtDescriptor , doclets )
5563
5664 if ( args . length > 1 && ! evtDescriptor . type ) {
5765 evtDescriptor . type = {
0 commit comments