Skip to content

Commit 1a1b80a

Browse files
committed
Add support for throws tag to markdown.
Fixes #360
1 parent 67f8d9e commit 1a1b80a

13 files changed

+663
-52
lines changed

lib/output/markdown_ast.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ function commentsToAST(comments, opts, callback) {
102102
});
103103
}
104104

105+
function throwsSection(comment) {
106+
return !!comment.throws &&
107+
u('list', { ordered: false },
108+
comment.throws.map(function (returns) {
109+
return u('listItem', [
110+
u('paragraph', [
111+
u('text', 'Throws '),
112+
u('strong', formatType(returns.type)),
113+
u('text', ' ')
114+
].concat(remark.parse(formatInlineTags(returns.description)).children))
115+
]);
116+
}));
117+
}
118+
105119
function augmentsLink(comment) {
106120
return comment.augments && u('paragraph', [
107121
u('strong', [
@@ -151,6 +165,7 @@ function commentsToAST(comments, opts, callback) {
151165
.concat(paramSection(comment))
152166
.concat(propertySection(comment))
153167
.concat(examplesSection(comment))
168+
.concat(throwsSection(comment))
154169
.concat(returnsSection(comment))
155170
.concat(metaSection(comment))
156171
.concat(!!comment.members.instance.length &&

test/fixture/auto_lang_hljs/multilanguage.output.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ myFoo.foo(42);
2121
}
2222
```
2323

24+
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if you give it something
25+
- Throws **[TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** if you give it something else
26+
2427
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone

test/fixture/es6-import.output.json

Lines changed: 114 additions & 26 deletions
Large diffs are not rendered by default.

test/fixture/es6-import.output.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ So does this one, with types
7070

7171
- `someParams` **...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
7272

73+
# iAmProtected
74+
75+
A protected function
76+
77+
# iAmPublic
78+
79+
A public function
80+
7381
# multiply
7482

7583
This function returns the number one.

test/fixture/es6-import.output.md.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,88 @@
10451045
}
10461046
]
10471047
},
1048+
{
1049+
"depth": 1,
1050+
"type": "heading",
1051+
"children": [
1052+
{
1053+
"type": "text",
1054+
"value": "iAmProtected"
1055+
}
1056+
]
1057+
},
1058+
{
1059+
"type": "paragraph",
1060+
"children": [
1061+
{
1062+
"type": "text",
1063+
"value": "A protected function",
1064+
"position": {
1065+
"start": {
1066+
"line": 1,
1067+
"column": 1
1068+
},
1069+
"end": {
1070+
"line": 1,
1071+
"column": 21
1072+
},
1073+
"indent": []
1074+
}
1075+
}
1076+
],
1077+
"position": {
1078+
"start": {
1079+
"line": 1,
1080+
"column": 1
1081+
},
1082+
"end": {
1083+
"line": 1,
1084+
"column": 21
1085+
},
1086+
"indent": []
1087+
}
1088+
},
1089+
{
1090+
"depth": 1,
1091+
"type": "heading",
1092+
"children": [
1093+
{
1094+
"type": "text",
1095+
"value": "iAmPublic"
1096+
}
1097+
]
1098+
},
1099+
{
1100+
"type": "paragraph",
1101+
"children": [
1102+
{
1103+
"type": "text",
1104+
"value": "A public function",
1105+
"position": {
1106+
"start": {
1107+
"line": 1,
1108+
"column": 1
1109+
},
1110+
"end": {
1111+
"line": 1,
1112+
"column": 18
1113+
},
1114+
"indent": []
1115+
}
1116+
}
1117+
],
1118+
"position": {
1119+
"start": {
1120+
"line": 1,
1121+
"column": 1
1122+
},
1123+
"end": {
1124+
"line": 1,
1125+
"column": 18
1126+
},
1127+
"indent": []
1128+
}
1129+
},
10481130
{
10491131
"depth": 1,
10501132
"type": "heading",

test/fixture/es6.input.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function functionWithRest(...someParams) {
7070
function functionWithRestAndType(...someParams: number) {
7171
}
7272

73+
// FUNCTION TYPES
74+
7375
/**
7476
* This is an async method
7577
*/
@@ -89,3 +91,29 @@ module.exports = () => (<p>hello</p>);
8991
function veryImportantTransform(foo = 'bar') {
9092
return "42";
9193
}
94+
95+
// ACCESS LEVELS
96+
97+
/**
98+
* A private function
99+
* @private
100+
*/
101+
function iAmPrivate() { }
102+
103+
/**
104+
* A protected function
105+
* @protected
106+
*/
107+
function iAmProtected() { }
108+
109+
/**
110+
* A public function
111+
* @public
112+
*/
113+
function iAmPublic() { }
114+
115+
/**
116+
* A private function using the access tag
117+
* @access private
118+
*/
119+
function iAmAccessPrivate() { }

test/fixture/es6.output.json

Lines changed: 114 additions & 26 deletions
Large diffs are not rendered by default.

test/fixture/es6.output.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ So does this one, with types
7070

7171
- `someParams` **...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
7272

73+
# iAmProtected
74+
75+
A protected function
76+
77+
# iAmPublic
78+
79+
A public function
80+
7381
# multiply
7482

7583
This function returns the number one.

test/fixture/es6.output.md.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,88 @@
10451045
}
10461046
]
10471047
},
1048+
{
1049+
"depth": 1,
1050+
"type": "heading",
1051+
"children": [
1052+
{
1053+
"type": "text",
1054+
"value": "iAmProtected"
1055+
}
1056+
]
1057+
},
1058+
{
1059+
"type": "paragraph",
1060+
"children": [
1061+
{
1062+
"type": "text",
1063+
"value": "A protected function",
1064+
"position": {
1065+
"start": {
1066+
"line": 1,
1067+
"column": 1
1068+
},
1069+
"end": {
1070+
"line": 1,
1071+
"column": 21
1072+
},
1073+
"indent": []
1074+
}
1075+
}
1076+
],
1077+
"position": {
1078+
"start": {
1079+
"line": 1,
1080+
"column": 1
1081+
},
1082+
"end": {
1083+
"line": 1,
1084+
"column": 21
1085+
},
1086+
"indent": []
1087+
}
1088+
},
1089+
{
1090+
"depth": 1,
1091+
"type": "heading",
1092+
"children": [
1093+
{
1094+
"type": "text",
1095+
"value": "iAmPublic"
1096+
}
1097+
]
1098+
},
1099+
{
1100+
"type": "paragraph",
1101+
"children": [
1102+
{
1103+
"type": "text",
1104+
"value": "A public function",
1105+
"position": {
1106+
"start": {
1107+
"line": 1,
1108+
"column": 1
1109+
},
1110+
"end": {
1111+
"line": 1,
1112+
"column": 18
1113+
},
1114+
"indent": []
1115+
}
1116+
}
1117+
],
1118+
"position": {
1119+
"start": {
1120+
"line": 1,
1121+
"column": 1
1122+
},
1123+
"end": {
1124+
"line": 1,
1125+
"column": 18
1126+
},
1127+
"indent": []
1128+
}
1129+
},
10481130
{
10491131
"depth": 1,
10501132
"type": "heading",

test/fixture/multiexample.output.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ foo(1);
1414
foo(2);
1515
```
1616

17+
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if you give it something
18+
- Throws **[TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** if you give it something else
19+
1720
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone

0 commit comments

Comments
 (0)