Skip to content

Commit b173cf1

Browse files
committed
Fix parameter sorting, nest properties in Markdown
1 parent cbff1d3 commit b173cf1

20 files changed

+957
-50
lines changed

lib/infer/params.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = function inferParams(comment) {
2121
return memo;
2222
}, {});
2323

24-
var paramOrder = [];
24+
var paramOrder = {};
25+
var i = 0;
2526

2627
path.value.params.forEach(function (param) {
2728
if (existingParams[param.name] === undefined) {
@@ -34,15 +35,15 @@ module.exports = function inferParams(comment) {
3435
lineNumber: param.loc.start.line
3536
});
3637
}
37-
paramOrder.push(param.name);
38+
paramOrder[param.name] = i++;
3839
});
3940

4041
// Ensure that if params are specified partially or in
4142
// the wrong order, they'll be output in the order
4243
// they actually appear in code
4344
if (comment.params) {
4445
comment.params.sort(function (a, b) {
45-
return paramOrder.indexOf(a.name) - paramOrder.indexOf(b.name);
46+
return paramOrder[a.name] - paramOrder[b.name];
4647
});
4748
}
4849

lib/output/markdown_ast.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ function identity(x) {
99

1010
function commentsToAST(comments, opts, callback) {
1111
function generate(depth, comment) {
12+
13+
function paramList(params) {
14+
return u('list', { ordered: false }, params.map(function (param) {
15+
return u('listItem', [
16+
u('paragraph', [
17+
u('inlineCode', param.name),
18+
u('text', ' '),
19+
!!param.type && u('strong', [u('text', formatType(param.type))]),
20+
u('text', ' '),
21+
mdast.parse(formatInlineTags(param.description)),
22+
!!param.default && u('root', [
23+
u('text', ' (optional, default '),
24+
u('text', param.default, 'inlineCode'),
25+
u('text', ')')
26+
]),
27+
param.properties && paramList(param.properties)
28+
].filter(identity))
29+
]);
30+
}));
31+
}
32+
1233
function paramSection(comment) {
1334
return !!comment.params && u('root', [
1435
u('strong', [u('text', 'Parameters')]),
15-
u('list', { ordered: false }, comment.params.map(function (param) {
16-
return u('listItem', [
17-
u('paragraph', [
18-
u('inlineCode', param.name),
19-
u('text', ' '),
20-
!!param.type && u('strong', [u('text', formatType(param.type))]),
21-
u('text', ' '),
22-
mdast.parse(formatInlineTags(param.description)),
23-
!!param.default && u('root', [
24-
u('text', ' (optional, default '),
25-
u('text', param.default, 'inlineCode'),
26-
u('text', ')')
27-
])
28-
].filter(identity))
29-
]);
30-
}))
36+
paramList(comment.params)
3137
]);
3238
}
3339

@@ -38,13 +44,13 @@ function commentsToAST(comments, opts, callback) {
3844
comment.properties.map(function (property) {
3945
return u('listItem', [
4046
u('paragraph', [
41-
u('inlineCode', property.title),
47+
u('inlineCode', property.name),
4248
u('text', ' '),
4349
u('text', [u('text', formatType(property.type))]),
4450
u('text', ' '),
4551
mdast.parse(formatInlineTags(property.description))
4652
])
47-
])
53+
].filter(identity))
4854
}))
4955
]);
5056
}

test/fixture/class.output.custom.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is my class, a demo thing.
55

66
**Properties**
77

8-
- `property` how many things it contains
8+
- `howMany` how many things it contains
99

1010

1111

test/fixture/class.output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is my class, a demo thing.
55

66
**Properties**
77

8-
- `property` how many things it contains
8+
- `howMany` how many things it contains
99

1010

1111

test/fixture/class.output.md.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"children": [
8585
{
8686
"type": "inlineCode",
87-
"value": "property"
87+
"value": "howMany"
8888
},
8989
{
9090
"type": "text",

test/fixture/event.output.custom.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Mouse event
55

66
**Properties**
77

8-
- `property` the pixel location of the event
8+
- `point` the pixel location of the event
99

10-
- `property` the original DOM event
10+
- `originalEvent` the original DOM event
1111

1212

1313

test/fixture/event.output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Mouse event
55

66
**Properties**
77

8-
- `property` the pixel location of the event
8+
- `point` the pixel location of the event
99

10-
- `property` the original DOM event
10+
- `originalEvent` the original DOM event
1111

1212

1313

test/fixture/event.output.md.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"children": [
8585
{
8686
"type": "inlineCode",
87-
"value": "property"
87+
"value": "point"
8888
},
8989
{
9090
"type": "text",
@@ -161,7 +161,7 @@
161161
"children": [
162162
{
163163
"type": "inlineCode",
164-
"value": "property"
164+
"value": "originalEvent"
165165
},
166166
{
167167
"type": "text",

test/fixture/html/nested.output.files

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ the referenced class type</p>
20412041
<div class='collapsible' id='klass/withoptions'>
20422042
<a href='#klass/withoptions'>
20432043
<code>
2044-
#withOptions<span class='gray'>(options.foo, options.bar, options)</span>
2044+
#withOptions<span class='gray'>(options)</span>
20452045
</code>
20462046
<span class='force-inline'>
20472047
<p>A function with an options parameter</p>
@@ -2051,30 +2051,24 @@ the referenced class type</p>
20512051
<div class='collapser border px2'>
20522052
<section class='py2 clearfix'>
20532053
<h2 id='klass/withoptions' class='mt0'>
2054-
withOptions<span class='gray'>(options.foo, options.bar, options)</span>
2054+
withOptions<span class='gray'>(options)</span>
20552055
</h2>
20562056
<p>A function with an options parameter</p>
20572057

20582058
<h4>Parameters</h4>
20592059
<ul class='suppress-p-margin'>
2060-
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code> <strong>options.foo</strong>
2061-
:
2062-
<span class='force-inline'>
2063-
2064-
</span>
2065-
</li>
2066-
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code> <strong>options.bar</strong>
2067-
:
2068-
<span class='force-inline'>
2069-
2070-
</span>
2071-
</li>
20722060
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code> <strong>options</strong>
20732061
:
20742062
<span class='force-inline'>
20752063

20762064
</span>
20772065
</li>
2066+
<ul>
2067+
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code> options.foo
2068+
</li>
2069+
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code> options.bar
2070+
</li>
2071+
</ul>
20782072
</ul>
20792073
</section>
20802074
</div>

test/fixture/nested_properties.output.custom.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
**Parameters**
77

88
- `options` **Object** some options
9+
- `options.much` **number** how much
910

1011
- `bar` **number** something else
1112

0 commit comments

Comments
 (0)