@@ -10,8 +10,40 @@ var sort = require('./lib/sort'),
10
10
polyglot = require ( './lib/parsers/polyglot' ) ,
11
11
github = require ( './lib/github' ) ,
12
12
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' ) ,
13
18
lint = require ( './lib/lint' ) ;
14
19
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
+
15
47
/**
16
48
* Generate JavaScript documentation as a list of parsed JSDoc
17
49
* comments, given a root file as a path.
@@ -55,26 +87,17 @@ module.exports = function (indexes, options, callback) {
55
87
. reduce ( function ( memo , file ) {
56
88
return memo . concat ( parseFn ( file ) ) ;
57
89
} , [ ] )
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 )
78
101
. sort ( sort . bind ( undefined , options . order ) )
79
102
. filter ( filterAccess . bind ( undefined , options . private ? [ ] : undefined ) )
80
103
callback ( null , options . hierarchy !== false ? hierarchy ( flat ) : flat ) ;
0 commit comments