Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,40 @@ var sort = require('./lib/sort'),
polyglot = require('./lib/parsers/polyglot'),
github = require('./lib/github'),
hierarchy = require('./lib/hierarchy'),
inferName = require('./lib/infer/name'),
inferKind = require('./lib/infer/kind'),
inferParams = require('./lib/infer/params'),
inferMembership = require('./lib/infer/membership'),
inferReturn = require('./lib/infer/return'),
lint = require('./lib/lint');

/**
* Build a pipeline of comment handlers.
* @param {...Function} args - Pipeline elements. Each is a function that accepts
* a comment and can return a comment or undefined (to drop that comment).
* @returns {Function} pipeline
* @private
*/
function pipeline() {
var elements = arguments;
return function (comment) {
for (var i = 0; comment && i < elements.length; i++) {
comment = elements[i](comment);
}
return comment;
}
}

/**
* A comment handler that returns the comment unchanged.
* @param {Object} comment parsed comment
* @returns {Object} comment
* @private
*/
function noop(comment) {
return comment;
}

/**
* Generate JavaScript documentation as a list of parsed JSDoc
* comments, given a root file as a path.
Expand Down Expand Up @@ -55,26 +87,17 @@ module.exports = function (indexes, options, callback) {
.reduce(function (memo, file) {
return memo.concat(parseFn(file));
}, [])
.map(function (comment) {
var inferName = require('./lib/infer/name')();
var inferKind = require('./lib/infer/kind')();
var inferParams = require('./lib/infer/params')();
var inferMembership = require('./lib/infer/membership')();
var inferReturn = require('./lib/infer/return')();

// compose nesting & membership to avoid intermediate arrays
comment = nestParams(
inferMembership(
inferReturn(
inferParams(
inferKind(
inferName(
lint(comment)))))));
if (options.github) {
comment = github(comment);
}
return comment;
})
.map(pipeline(
lint,
inferName(),
inferKind(),
inferParams(),
inferReturn(),
inferMembership(),
nestParams,
options.github ? github : noop
))
.filter(Boolean)
.sort(sort.bind(undefined, options.order))
.filter(filterAccess.bind(undefined, options.private ? [] : undefined))
callback(null, options.hierarchy !== false ? hierarchy(flat) : flat);
Expand Down
6 changes: 3 additions & 3 deletions lib/infer/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ module.exports = function () {
currentModule = comment;
}

if (comment.memberof) {
return comment;
if (comment.lends) {
return;
}

if (comment.lends) {
if (comment.memberof) {
return comment;
}

Expand Down
12 changes: 5 additions & 7 deletions test/lib/infer/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ test('inferMembership - explicit', function (t) {
scope: 'static'
}, 'lends, static');

t.end();
});



test('inferMembership', function (t) {
t.deepEqual(_.pick(evaluate(function () {
lend(/** @lends Foo */{
/**
Expand Down Expand Up @@ -182,7 +176,11 @@ test('inferMembership', function (t) {
lend(/** @lends Foo */{});
/** Test */
return 0;
})[0].memberof, undefined, 'inferMembership - lends applies only to following object');
})[1].memberof, undefined, 'inferMembership - lends applies only to following object');

t.equal(evaluate(function () {
lend(/** @lends Foo */{});
})[0], undefined, 'inferMembership - drops lends');

t.end();
});
Expand Down