Skip to content

Commit e0df156

Browse files
committed
Output thrown exceptions. Fixes #86
1 parent de66668 commit e0df156

18 files changed

+192
-0
lines changed

share/html/section.hbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@
5656
{{/returns}}
5757
{{/if}}
5858

59+
{{#if throws}}
60+
<h4>Throws</h4>
61+
<table class='table-light overflow-hidden bg-cloudy-light'>
62+
<thead>
63+
<th class='col-3'>exception</th>
64+
<th class='col-9'>description</th>
65+
</thead>
66+
{{#throws}}
67+
<tr>
68+
<td>{{{format_type type}}}</td>
69+
<td>
70+
{{{md description}}}
71+
</td>
72+
</tr>
73+
{{/throws}}
74+
</table>
75+
{{/if}}
76+
5977
{{#if examples}}
6078
<h4>Examples</h4>
6179
{{#each examples ~}}<pre>{{{.}}}</pre>{{/each}}

share/markdown.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@
3434
Returns {{#type.name}}`{{.}}`{{/type.name}} {{inlines description}}
3535
{{/returns}}
3636

37+
38+
{{#if throws}}
39+
| type | description |
40+
| ---- | ----------- |
41+
{{#throws}}
42+
| {{format_type type}} | {{format_description description}} |
43+
{{/throws}}
44+
{{/if}}

streams/flatten.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var through = require('through'),
2222
* * `@property` (to `properties` property)
2323
* * `@returns` (to `returns` property)
2424
* * `@example` (to `examples` property)
25+
* * `@throws` (to `throws` property)
2526
*
2627
* The `@global`, `@static`, `@instance`, and `@inner` tags are flattened
2728
* to a `scope` property whose value is `"global"`, `"static"`, `"instance"`,
@@ -72,6 +73,12 @@ var flatteners = {
7273
}
7374
result.params.push(tag);
7475
},
76+
'throws': function (result, tag) {
77+
if (!result.throws) {
78+
result.throws = [];
79+
}
80+
result.throws.push(tag);
81+
},
7582
'returns': function (result, tag) {
7683
if (!result.returns) {
7784
result.returns = [];

test/fixture/es6.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ This function returns the number one.
77

88
Returns `Number` numberone
99

10+

test/fixture/event.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Mouse event
1010

1111

1212

13+

test/fixture/factory.output.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ an area chart generator
77

88
Returns `area` chart
99

10+
1011
## `area`
1112

1213

@@ -15,6 +16,7 @@ Returns `area` chart
1516

1617

1718

19+
1820
## `data`
1921

2022
Sets the chart data.
@@ -23,3 +25,4 @@ Sets the chart data.
2325

2426

2527

28+

test/fixture/html/nested.output.files

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ section:target {
15111511

15121512

15131513

1514+
15141515
<div class='section-indent'>
15151516
<section id='klass/magic-number'class='mt2 mb2 py1 px2 keyline-top'>
15161517
<h3 class='regular'>
@@ -1528,6 +1529,7 @@ section:target {
15281529

15291530

15301531

1532+
15311533
</section>
15321534
</div>
15331535
<div class='section-indent'>
@@ -1570,6 +1572,7 @@ section:target {
15701572

15711573

15721574

1575+
15731576
</section>
15741577
</div>
15751578
<div class='section-indent'>
@@ -1614,6 +1617,7 @@ This is a <a href="doesnot"><code>link to something that does not exist</code></
16141617

16151618

16161619

1620+
16171621
</section>
16181622
</div>
16191623

@@ -1638,6 +1642,7 @@ This is a <a href="doesnot"><code>link to something that does not exist</code></
16381642

16391643
</span>
16401644

1645+
16411646
<h4>Examples</h4>
16421647
<pre>foo.getFoo();</pre>
16431648

@@ -1672,6 +1677,7 @@ like a <a href="klass"><code>klass</code></a></p>
16721677

16731678

16741679

1680+
16751681
</section>
16761682

16771683
</div>

test/fixture/inline-link.output.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Adds one to a number
1010

1111
Returns `number` the output
1212

13+
1314
## `exports`
1415

1516
This function returns the number one. Internally, this uses
@@ -23,3 +24,4 @@ This function returns the number one. Internally, this uses
2324

2425
Returns `number` numberone
2526

27+

test/fixture/multisignature.output.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Get the time
77

88
Returns `Date` the current date
99

10+
1011
## `getTheTime`
1112

1213
Set the time
@@ -19,3 +20,4 @@ Set the time
1920

2021
Returns nothing
2122

23+

test/fixture/newline-in-description.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ A function.
99

1010

1111

12+

test/fixture/optional.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ var address = new Address6('2001::/32');
1515
```
1616

1717

18+

test/fixture/simple-hashbang.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ This function returns the number one.
77

88
Returns `Number` numberone
99

10+

test/fixture/simple-two.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ var result = returnTwo(4);
1616

1717
Returns `Number` numbertwo
1818

19+

test/fixture/simple.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ This function returns the number one.
77

88
Returns `Number` numberone
99

10+

test/fixture/throws.input.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This function returns the number plus two.
3+
*
4+
* @param {Number} a the number
5+
* @returns {Number} numbertwo
6+
* @throws {Error} if number is 3
7+
* @example
8+
* var result = returnTwo(4);
9+
* // result is 6
10+
*/
11+
function returnTwo(a) {
12+
if (a === 3) throw new Error('cannot be 3');
13+
// this returns a + 2
14+
return a + 2;
15+
}

test/fixture/throws.output.custom.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## `returnTwo`
2+
3+
This function returns the number plus two.
4+
5+
* `a`: the number
6+
7+
Returns `Number` numbertwo
8+

test/fixture/throws.output.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[
2+
{
3+
"description": "This function returns the number plus two.",
4+
"tags": [
5+
{
6+
"title": "param",
7+
"description": "the number",
8+
"type": {
9+
"type": "NameExpression",
10+
"name": "Number"
11+
},
12+
"name": "a"
13+
},
14+
{
15+
"title": "returns",
16+
"description": "numbertwo",
17+
"type": {
18+
"type": "NameExpression",
19+
"name": "Number"
20+
}
21+
},
22+
{
23+
"title": "throws",
24+
"description": "if number is 3",
25+
"type": {
26+
"type": "NameExpression",
27+
"name": "Error"
28+
}
29+
},
30+
{
31+
"title": "example",
32+
"description": "var result = returnTwo(4);\n// result is 6"
33+
},
34+
{
35+
"title": "name",
36+
"name": "returnTwo"
37+
},
38+
{
39+
"title": "kind",
40+
"kind": "function"
41+
}
42+
],
43+
"context": {
44+
"loc": {
45+
"start": {
46+
"line": 11,
47+
"column": 0
48+
},
49+
"end": {
50+
"line": 15,
51+
"column": 1
52+
}
53+
},
54+
"file": "fixture/throws.input.js",
55+
"code": "function returnTwo(a) {\n if (a === 3) throw new Error('cannot be 3');\n // this returns a + 2\n return a + 2;\n}"
56+
},
57+
"params": [
58+
{
59+
"title": "param",
60+
"description": "the number",
61+
"type": {
62+
"type": "NameExpression",
63+
"name": "Number"
64+
},
65+
"name": "a"
66+
}
67+
],
68+
"returns": [
69+
{
70+
"title": "returns",
71+
"description": "numbertwo",
72+
"type": {
73+
"type": "NameExpression",
74+
"name": "Number"
75+
}
76+
}
77+
],
78+
"throws": [
79+
{
80+
"title": "throws",
81+
"description": "if number is 3",
82+
"type": {
83+
"type": "NameExpression",
84+
"name": "Error"
85+
}
86+
}
87+
],
88+
"examples": [
89+
"var result = returnTwo(4);\n// result is 6"
90+
],
91+
"name": "returnTwo",
92+
"kind": "function"
93+
}
94+
]

test/fixture/throws.output.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## `returnTwo`
2+
3+
This function returns the number plus two.
4+
5+
### Parameters
6+
7+
* `a` **`Number`** the number
8+
9+
10+
### Examples
11+
12+
```js
13+
var result = returnTwo(4);
14+
// result is 6
15+
```
16+
17+
Returns `Number` numbertwo
18+
19+
20+
| type | description |
21+
| ---- | ----------- |
22+
| `Error` | if number is 3 |

0 commit comments

Comments
 (0)