Skip to content

Commit d1e3d19

Browse files
author
Duc Tri Le
committed
Added support for @chainable
Squashed commit of the following: commit ab7299b Author: Duc Tri Le <[email protected]> Date: Mon Feb 22 14:29:55 2016 -0500 Adding new @chainable tag for methods to use to specify that it is returning itself
1 parent b1ff7c1 commit d1e3d19

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/jsdoc/augment.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
458478
function 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
};

lib/jsdoc/tag/dictionary/definitions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ var baseTags = exports.baseTags = {
258258
doclet.borrow(borrows.target, borrows.source);
259259
}
260260
},
261+
chainable: {
262+
mustNotHaveValue: true,
263+
mustNotHaveDescription: true,
264+
onTagged: function(doclet, tag) {
265+
doclet.chainable = true;
266+
}
267+
},
261268
class: {
262269
onTagged: function(doclet, tag) {
263270
doclet.addTag('kind', 'class');

0 commit comments

Comments
 (0)