@@ -455,6 +455,26 @@ function getImplementedAdditions(implDoclets, allDoclets, commentedDoclets) {
455455 return additions ;
456456}
457457
458+ // Add a @return tag with the type being the current class
459+ function augumentChainableMethodReturn ( doclets , docs , documented ) {
460+ doclets . forEach ( function ( doclet ) {
461+ var members = getMembers ( doclet . longname , docs , [ 'instance' ] ) ;
462+ if ( ! members ) { return ; }
463+
464+ members . forEach ( function ( member ) {
465+ if ( member . chainable ) {
466+ addDocletProperty (
467+ documented [ member . longname ] ,
468+ 'returns' ,
469+ [ { type : { names : [ member . longname . split ( '#' ) [ 0 ] ] } } ]
470+ ) ;
471+ }
472+ } ) ;
473+ } ) ;
474+
475+ return [ ] ;
476+ }
477+
458478function augment ( doclets , propertyName , docletFinder ) {
459479 var index = doclets . index . longname ;
460480 var dependencies = sort ( mapDependencies ( index , propertyName ) ) ;
@@ -528,6 +548,17 @@ exports.addImplemented = function(doclets) {
528548 augment ( doclets , 'implements' , getImplementedAdditions ) ;
529549} ;
530550
551+ /**
552+ * Update the doclets for all methods with `@chainable` so that the return type is the current class.
553+ *
554+ * @param {!Array.<module:jsdoc/doclet.Doclet> } docs - The doclets generated by JSDoc.
555+ * @param {!Object } doclets.index - The doclet index added by {@link module:jsdoc/borrow.indexAll}.
556+ * @return {void }
557+ */
558+ exports . addChainableMethodReturn = function ( doclets ) {
559+ augment ( doclets , 'chainable' , augumentChainableMethodReturn ) ;
560+ } ;
561+
531562/**
532563 * Add and update doclets to reflect all of the following:
533564 *
@@ -545,4 +576,5 @@ exports.augmentAll = function(doclets) {
545576 exports . addInherited ( doclets ) ;
546577 // look for implemented doclets again, in case we inherited an interface
547578 exports . addImplemented ( doclets ) ;
579+ exports . addChainableMethodReturn ( doclets ) ;
548580} ;
0 commit comments