Skip to content

Commit 2f99af8

Browse files
committed
support the modifies tag (JSDoc and Closure Compiler) (jsdoc#605)
1 parent b561624 commit 2f99af8

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

lib/jsdoc/schema.js

+6
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ var DOCLET_SCHEMA = exports.DOCLET_SCHEMA = {
436436
type: STRING
437437
}
438438
},
439+
modifies: {
440+
type: ARRAY,
441+
optional: true,
442+
uniqueItems: true,
443+
items: PARAM_SCHEMA
444+
},
439445
// probably a trailing substring of the path
440446
name: {
441447
type: STRING

lib/jsdoc/tag/dictionary/definitions.js

+8
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ var baseTags = exports.baseTags = {
605605
setDocletNameToValue(doclet, tag);
606606
}
607607
},
608+
modifies: {
609+
canHaveType: true,
610+
onTagged: function(doclet, tag) {
611+
doclet.modifies = doclet.modifies || [];
612+
doclet.modifies.push(tag.value);
613+
}
614+
},
608615
module: {
609616
canHaveType: true,
610617
isNamespace: true,
@@ -910,6 +917,7 @@ exports.closureTags = {
910917
}),
911918
lends: cloneTagDef(baseTags.lends),
912919
license: cloneTagDef(baseTags.license),
920+
modifies: cloneTagDef(baseTags.modifies),
913921
// Closure Compiler only
914922
noalias: {
915923
onTagged: ignore

templates/default/tmpl/method.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ var self = this;
7777
<?js }); ?></ul>
7878
<?js } ?>
7979

80+
<?js if (data.modifies && modifies.length) {?>
81+
<h5>Modifies:</h5>
82+
<?js if (modifies.length > 1) { ?><ul><?js
83+
modifies.forEach(function(m) { ?>
84+
<li><?js= self.partial('modifies.tmpl', m) ?></li>
85+
<?js });
86+
?></ul><?js } else {
87+
modifies.forEach(function(m) { ?>
88+
<?js= self.partial('modifies.tmpl', m) ?>
89+
<?js });
90+
} } ?>
91+
8092
<?js if (data.exceptions && exceptions.length) { ?>
8193
<h5>Throws:</h5>
8294
<?js if (exceptions.length > 1) { ?><ul><?js

templates/default/tmpl/modifies.tmpl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?js
2+
var data = obj || {};
3+
?>
4+
5+
<?js if (data.type && data.type.names) {?>
6+
<dl>
7+
<dt>
8+
Type
9+
</dt>
10+
<dd>
11+
<?js= this.partial('type.tmpl', data.type.names) ?>
12+
</dd>
13+
</dl>
14+
<?js } ?>

test/fixtures/modifiestag.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* My mutator function.
3+
* @modifies {(foo|bar)}
4+
*/
5+
function mutator(foo, bar) {}

test/specs/tags/modifiestag.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
describe('@modifies tag', function() {
4+
var docSet = jasmine.getDocSetFromFile('test/fixtures/modifiestag.js');
5+
var mutator = docSet.getByLongname('mutator')[0];
6+
7+
it('should add the specified types to the doclet\'s `modifies` property', function() {
8+
expect(mutator.modifies.length).toBe(1);
9+
expect(mutator.modifies[0].type).toBeDefined();
10+
expect(mutator.modifies[0].type.names).toBeDefined();
11+
expect(mutator.modifies[0].type.names.length).toBe(2);
12+
expect(mutator.modifies[0].type.names[0]).toBe('foo');
13+
expect(mutator.modifies[0].type.names[1]).toBe('bar');
14+
});
15+
});

0 commit comments

Comments
 (0)