Skip to content

Commit 9dcfa84

Browse files
committed
Drop @Lends tags during membership inference (fixes #161)
1 parent 268fcce commit 9dcfa84

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

index.js

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,40 @@ var sort = require('./lib/sort'),
1010
polyglot = require('./lib/parsers/polyglot'),
1111
github = require('./lib/github'),
1212
hierarchy = require('./lib/hierarchy'),
13+
inferName = require('./lib/infer/name'),
14+
inferKind = require('./lib/infer/kind'),
15+
inferParams = require('./lib/infer/params'),
16+
inferMembership = require('./lib/infer/membership'),
17+
inferReturn = require('./lib/infer/return'),
1318
lint = require('./lib/lint');
1419

20+
/**
21+
* Build a pipeline of comment handlers.
22+
* @param {...Function} args - Pipeline elements. Each is a function that accepts
23+
* a comment and can return a comment or undefined (to drop that comment).
24+
* @returns {Function} pipeline
25+
* @private
26+
*/
27+
function pipeline() {
28+
var elements = arguments;
29+
return function (comment) {
30+
for (var i = 0; comment && i < elements.length; i++) {
31+
comment = elements[i](comment);
32+
}
33+
return comment;
34+
}
35+
}
36+
37+
/**
38+
* A comment handler that returns the comment unchanged.
39+
* @param {Object} comment parsed comment
40+
* @returns {Object} comment
41+
* @private
42+
*/
43+
function noop(comment) {
44+
return comment;
45+
}
46+
1547
/**
1648
* Generate JavaScript documentation as a list of parsed JSDoc
1749
* comments, given a root file as a path.
@@ -55,26 +87,17 @@ module.exports = function (indexes, options, callback) {
5587
.reduce(function (memo, file) {
5688
return memo.concat(parseFn(file));
5789
}, [])
58-
.map(function (comment) {
59-
var inferName = require('./lib/infer/name')();
60-
var inferKind = require('./lib/infer/kind')();
61-
var inferParams = require('./lib/infer/params')();
62-
var inferMembership = require('./lib/infer/membership')();
63-
var inferReturn = require('./lib/infer/return')();
64-
65-
// compose nesting & membership to avoid intermediate arrays
66-
comment = nestParams(
67-
inferMembership(
68-
inferReturn(
69-
inferParams(
70-
inferKind(
71-
inferName(
72-
lint(comment)))))));
73-
if (options.github) {
74-
comment = github(comment);
75-
}
76-
return comment;
77-
})
90+
.map(pipeline(
91+
lint,
92+
inferName(),
93+
inferKind(),
94+
inferParams(),
95+
inferReturn(),
96+
inferMembership(),
97+
nestParams,
98+
options.github ? github : noop
99+
))
100+
.filter(Boolean)
78101
.sort(sort.bind(undefined, options.order))
79102
.filter(filterAccess.bind(undefined, options.private ? [] : undefined))
80103
callback(null, options.hierarchy !== false ? hierarchy(flat) : flat);

lib/infer/membership.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ module.exports = function () {
113113
currentModule = comment;
114114
}
115115

116-
if (comment.memberof) {
117-
return comment;
116+
if (comment.lends) {
117+
return;
118118
}
119119

120-
if (comment.lends) {
120+
if (comment.memberof) {
121121
return comment;
122122
}
123123

test/lib/infer/membership.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ test('inferMembership - explicit', function (t) {
136136
scope: 'static'
137137
}, 'lends, static');
138138

139-
t.end();
140-
});
141-
142-
143-
144-
test('inferMembership', function (t) {
145139
t.deepEqual(_.pick(evaluate(function () {
146140
lend(/** @lends Foo */{
147141
/**
@@ -182,7 +176,11 @@ test('inferMembership', function (t) {
182176
lend(/** @lends Foo */{});
183177
/** Test */
184178
return 0;
185-
})[0].memberof, undefined, 'inferMembership - lends applies only to following object');
179+
})[1].memberof, undefined, 'inferMembership - lends applies only to following object');
180+
181+
t.equal(evaluate(function () {
182+
lend(/** @lends Foo */{});
183+
})[0], undefined, 'inferMembership - drops lends');
186184

187185
t.end();
188186
});

0 commit comments

Comments
 (0)