Skip to content

Commit bb41619

Browse files
committed
Restore default values. Fix sort test
1 parent 888f5ec commit bb41619

11 files changed

+316
-78
lines changed

lib/parse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ var flatteners = {
154154
param.type = tag.type;
155155
}
156156

157+
if (tag.default) {
158+
param.default = tag.default;
159+
}
160+
157161
result.params.push(param);
158162
},
159163
'private': function (result) {

lib/sort.js

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,49 @@ function parseMarkdown(string) {
1111
* Sort two documentation objects, given an optional order object. Returns
1212
* a numeric sorting value that is compatible with stream-sort.
1313
*
14-
* @param {Object} a documentation object
15-
* @param {Object} b documentation object
14+
* @param {Array<Object>} comments all comments
15+
* @param {Object} options options from documentation.yml
1616
* @return {number} sorting value
1717
* @private
1818
*/
1919
module.exports = function sortDocs(comments, options) {
20-
if (!options.toc) {
20+
if (!options || !options.toc) {
2121
return comments.sort(function (a, b) {
2222
return a.context.sortKey.localeCompare(b.context.sortKey);
2323
});
24-
} else {
25-
var indexes = options.toc.reduce(function (memo, val, i) {
26-
if (typeof val === 'object' && val.name) {
27-
val.kind = 'note';
28-
memo[val.name] = i;
29-
} else {
30-
memo[val] = i;
31-
}
32-
return memo;
33-
}, {});
34-
var fixed = options.toc.filter(function (val) {
35-
return typeof val === 'object' && val.name;
36-
}).map(function (val) {
37-
if (val.description) {
38-
val.description = parseMarkdown(val.description);
39-
}
40-
return val;
41-
});
42-
var unfixed = [];
43-
comments.forEach(function (comment) {
44-
if (!comment.memberof && indexes[comment.name] !== undefined) {
45-
fixed.push(comment);
46-
} else {
47-
unfixed.push(comment);
48-
}
49-
});
50-
fixed.sort(function (a, b) {
51-
if (indexes[a.name] !== undefined && indexes[b.name] !== undefined) {
52-
return indexes[a.name] - indexes[b.name];
53-
}
54-
});
55-
unfixed.sort(function (a, b) {
56-
return a.context.sortKey.localeCompare(b.context.sortKey);
57-
});
58-
return fixed.concat(unfixed);
5924
}
25+
var indexes = options.toc.reduce(function (memo, val, i) {
26+
if (typeof val === 'object' && val.name) {
27+
val.kind = 'note';
28+
memo[val.name] = i;
29+
} else {
30+
memo[val] = i;
31+
}
32+
return memo;
33+
}, {});
34+
var fixed = options.toc.filter(function (val) {
35+
return typeof val === 'object' && val.name;
36+
}).map(function (val) {
37+
if (val.description) {
38+
val.description = parseMarkdown(val.description);
39+
}
40+
return val;
41+
});
42+
var unfixed = [];
43+
comments.forEach(function (comment) {
44+
if (!comment.memberof && indexes[comment.name] !== undefined) {
45+
fixed.push(comment);
46+
} else {
47+
unfixed.push(comment);
48+
}
49+
});
50+
fixed.sort(function (a, b) {
51+
if (indexes[a.name] !== undefined && indexes[b.name] !== undefined) {
52+
return indexes[a.name] - indexes[b.name];
53+
}
54+
});
55+
unfixed.sort(function (a, b) {
56+
return a.context.sortKey.localeCompare(b.context.sortKey);
57+
});
58+
return fixed.concat(unfixed);
6059
};

test/fixture/html/nested.output.files

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626

2727
<li><a
2828
href='#Klass'
29-
30-
class='toggle-sibling'
31-
32-
>
29+
class=" toggle-sibling">
3330
Klass
3431
<span class='icon'>▸</span>
3532
</a>
@@ -103,8 +100,7 @@
103100

104101
<li><a
105102
href='#bar'
106-
107-
>
103+
class="">
108104
bar
109105

110106
</a>
@@ -114,8 +110,7 @@
114110

115111
<li><a
116112
href='#bar'
117-
118-
>
113+
class="">
119114
bar
120115

121116
</a>
@@ -125,8 +120,7 @@
125120

126121
<li><a
127122
href='#bar'
128-
129-
>
123+
class="">
130124
bar
131125

132126
</a>
@@ -136,10 +130,7 @@
136130

137131
<li><a
138132
href='#Foo'
139-
140-
class='toggle-sibling'
141-
142-
>
133+
class=" toggle-sibling">
143134
Foo
144135
<span class='icon'>▸</span>
145136
</a>
@@ -170,7 +161,8 @@
170161
<div class='fix-margin-3'>
171162
<div class='px2'>
172163

173-
<div class='keyline-top-not py2'><section class='py2 clearfix'>
164+
165+
<div class='keyline-top-not py2'><section class='py2 clearfix'>
174166

175167
<h3 id='Klass' class='mt0'>
176168
Klass
@@ -401,7 +393,9 @@ the referenced class type</p>
401393

402394
</li>
403395

404-
<li><code>size</code> <em>([<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>])</em>: size
396+
<li><code>size</code> <em>([<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>]
397+
(default <code>0</code>)
398+
)</em>: size
405399

406400

407401
</li>
@@ -758,8 +752,10 @@ k.isArrayOfBuffers();</pre>
758752

759753

760754
</div>
755+
761756

762-
<div class='keyline-top-not py2'><section class='py2 clearfix'>
757+
758+
<div class='keyline-top-not py2'><section class='py2 clearfix'>
763759

764760
<h3 id='bar' class='mt0'>
765761
bar
@@ -806,8 +802,10 @@ like a <a href="#Klass">klass</a></p>
806802

807803

808804
</div>
805+
809806

810-
<div class='keyline-top-not py2'><section class='py2 clearfix'>
807+
808+
<div class='keyline-top-not py2'><section class='py2 clearfix'>
811809

812810
<h3 id='bar' class='mt0'>
813811
bar
@@ -861,8 +859,10 @@ like a <a href="#Klass">klass</a></p>
861859

862860

863861
</div>
862+
864863

865-
<div class='keyline-top-not py2'><section class='py2 clearfix'>
864+
865+
<div class='keyline-top-not py2'><section class='py2 clearfix'>
866866

867867
<h3 id='bar' class='mt0'>
868868
bar
@@ -909,8 +909,10 @@ like a <a href="#Klass">klass</a>. This needs a <a href="#number">number</a> inp
909909

910910

911911
</div>
912+
912913

913-
<div class='keyline-top-not py2'><section class='py2 clearfix'>
914+
915+
<div class='keyline-top-not py2'><section class='py2 clearfix'>
914916

915917
<h3 id='Foo' class='mt0'>
916918
Foo
@@ -1003,6 +1005,7 @@ like a <a href="#Klass">klass</a>. This needs a <a href="#number">number</a> inp
10031005

10041006

10051007
</div>
1008+
10061009

10071010
</div>
10081011
</div>

test/fixture/nest_params.input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @param {Object[]} employees - The employees who are responsible for the project.
33
* @param {string} employees[].name - The name of an employee.
44
* @param {string} employees[].department - The employee's department.
5+
* @param {string} [type=minion] - The employee's type.
56
*/
6-
function foo(employee) {
7+
function foo(employee, type) {
78
}
89

910
/**

test/fixture/nest_params.output.json

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@
4040
"name": "string"
4141
},
4242
"name": "employees[].department"
43+
},
44+
{
45+
"title": "param",
46+
"description": "The employee's type.",
47+
"lineNumber": 4,
48+
"type": {
49+
"type": "OptionalType",
50+
"expression": {
51+
"type": "NameExpression",
52+
"name": "string"
53+
}
54+
},
55+
"name": "type",
56+
"default": "minion"
4357
}
4458
],
4559
"loc": {
@@ -48,22 +62,22 @@
4862
"column": 0
4963
},
5064
"end": {
51-
"line": 5,
65+
"line": 6,
5266
"column": 3
5367
}
5468
},
5569
"context": {
5670
"loc": {
5771
"start": {
58-
"line": 6,
72+
"line": 7,
5973
"column": 0
6074
},
6175
"end": {
62-
"line": 7,
76+
"line": 8,
6377
"column": 1
6478
}
6579
},
66-
"code": "/**\n * @param {Object[]} employees - The employees who are responsible for the project.\n * @param {string} employees[].name - The name of an employee.\n * @param {string} employees[].department - The employee's department.\n */\nfunction foo(employee) {\n}\n\n/**\n * @name foo\n * @param {Object} options some options\n * @param {number} options.much how much\n * @param {number} bar something else\n * @property {Object} theTime the current time\n * @property {number} theTime.hours\n * @property {number} theTime.minutes\n * @property {number} theTime.seconds\n * @returns {Object} foo something else\n */\n"
80+
"code": "/**\n * @param {Object[]} employees - The employees who are responsible for the project.\n * @param {string} employees[].name - The name of an employee.\n * @param {string} employees[].department - The employee's department.\n * @param {string} [type=minion] - The employee's type.\n */\nfunction foo(employee, type) {\n}\n\n/**\n * @name foo\n * @param {Object} options some options\n * @param {number} options.much how much\n * @param {number} bar something else\n * @property {Object} theTime the current time\n * @property {number} theTime.hours\n * @property {number} theTime.minutes\n * @property {number} theTime.seconds\n * @returns {Object} foo something else\n */\n"
6781
},
6882
"errors": [],
6983
"params": [
@@ -261,7 +275,71 @@
261275
{
262276
"title": "param",
263277
"name": "employee",
264-
"lineNumber": 6
278+
"lineNumber": 7
279+
},
280+
{
281+
"name": "type",
282+
"lineNumber": 4,
283+
"description": {
284+
"type": "root",
285+
"children": [
286+
{
287+
"type": "paragraph",
288+
"children": [
289+
{
290+
"type": "text",
291+
"value": "The employee's type.",
292+
"position": {
293+
"start": {
294+
"line": 1,
295+
"column": 1,
296+
"offset": 0
297+
},
298+
"end": {
299+
"line": 1,
300+
"column": 21,
301+
"offset": 20
302+
},
303+
"indent": []
304+
}
305+
}
306+
],
307+
"position": {
308+
"start": {
309+
"line": 1,
310+
"column": 1,
311+
"offset": 0
312+
},
313+
"end": {
314+
"line": 1,
315+
"column": 21,
316+
"offset": 20
317+
},
318+
"indent": []
319+
}
320+
}
321+
],
322+
"position": {
323+
"start": {
324+
"line": 1,
325+
"column": 1,
326+
"offset": 0
327+
},
328+
"end": {
329+
"line": 1,
330+
"column": 21,
331+
"offset": 20
332+
}
333+
}
334+
},
335+
"type": {
336+
"type": "OptionalType",
337+
"expression": {
338+
"type": "NameExpression",
339+
"name": "string"
340+
}
341+
},
342+
"default": "minion"
265343
}
266344
],
267345
"name": "foo",
@@ -369,22 +447,22 @@
369447
],
370448
"loc": {
371449
"start": {
372-
"line": 9,
450+
"line": 10,
373451
"column": 0
374452
},
375453
"end": {
376-
"line": 19,
454+
"line": 20,
377455
"column": 3
378456
}
379457
},
380458
"context": {
381459
"loc": {
382460
"start": {
383-
"line": 6,
461+
"line": 7,
384462
"column": 0
385463
},
386464
"end": {
387-
"line": 7,
465+
"line": 8,
388466
"column": 1
389467
}
390468
}

test/fixture/nest_params.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- `employees[].name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of an employee.
77
- `employees[].department` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The employee's department.
88
- `employee`
9+
- `type` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The employee's type. (optional, default `minion`)
910

1011
# foo
1112

0 commit comments

Comments
 (0)