Skip to content

Commit b756c0c

Browse files
committed
Support alias tag. Refs #9
1 parent 167079c commit b756c0c

File tree

7 files changed

+231
-0
lines changed

7 files changed

+231
-0
lines changed

lib/flatten.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var flatteners = {
2424
'name': flattenName,
2525
'function': flattenName,
2626
'mixin': flattenName,
27+
'alias': flattenName,
2728
'memberof': flattenDescription,
2829
'classdesc': flattenDescription,
2930
'lends': flattenDescription,

lib/infer/name.js

+6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ var types = require('ast-types'),
1414
*/
1515
module.exports = function () {
1616
return shouldSkipInference(function inferName(comment) {
17+
1718
if (comment.event) {
1819
comment.name = comment.event;
1920
return comment;
2021
}
2122

23+
if (comment.alias) {
24+
comment.name = comment.alias;
25+
return comment;
26+
}
27+
2228
if (comment.callback) {
2329
comment.name = comment.callback;
2430
return comment;

test/fixture/alias.input.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* This is a method that has an alias tag: so it should
3+
* be referred to as nixon, but should still have inference.
4+
* @alias nixon
5+
*/
6+
function dewey(a: number): number {
7+
return a;
8+
}

test/fixture/alias.output.custom.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# nixon
2+
3+
This is a method that has an alias tag: so it should
4+
be referred to as nixon, but should still have inference.
5+
6+
**Parameters**
7+
8+
- `a` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
9+
10+
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**

test/fixture/alias.output.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[
2+
{
3+
"description": "This is a method that has an alias tag: so it should\nbe referred to as nixon, but should still have inference.",
4+
"tags": [
5+
{
6+
"title": "alias",
7+
"description": null,
8+
"lineNumber": 3,
9+
"name": "nixon"
10+
}
11+
],
12+
"loc": {
13+
"start": {
14+
"line": 1,
15+
"column": 0
16+
},
17+
"end": {
18+
"line": 5,
19+
"column": 3
20+
}
21+
},
22+
"context": {
23+
"loc": {
24+
"start": {
25+
"line": 6,
26+
"column": 0
27+
},
28+
"end": {
29+
"line": 8,
30+
"column": 1
31+
}
32+
},
33+
"code": "/**\n * This is a method that has an alias tag: so it should\n * be referred to as nixon, but should still have inference.\n * @alias nixon\n */\nfunction dewey(a: number): number {\n return a;\n}\n"
34+
},
35+
"errors": [],
36+
"alias": "nixon",
37+
"name": "nixon",
38+
"kind": "function",
39+
"params": [
40+
{
41+
"title": "param",
42+
"name": "a",
43+
"lineNumber": 6,
44+
"type": {
45+
"type": "NameExpression",
46+
"name": "number"
47+
}
48+
}
49+
],
50+
"returns": [
51+
{
52+
"type": {
53+
"type": "NameExpression",
54+
"name": "number"
55+
}
56+
}
57+
],
58+
"members": {
59+
"instance": [],
60+
"static": []
61+
},
62+
"path": [
63+
"nixon"
64+
]
65+
}
66+
]

test/fixture/alias.output.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# nixon
2+
3+
This is a method that has an alias tag: so it should
4+
be referred to as nixon, but should still have inference.
5+
6+
**Parameters**
7+
8+
- `a` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
9+
10+
Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**

test/fixture/alias.output.md.json

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"type": "root",
3+
"children": [
4+
{
5+
"depth": 1,
6+
"type": "heading",
7+
"children": [
8+
{
9+
"type": "text",
10+
"value": "nixon"
11+
}
12+
]
13+
},
14+
{
15+
"type": "paragraph",
16+
"children": [
17+
{
18+
"type": "text",
19+
"value": "This is a method that has an alias tag: so it should\nbe referred to as nixon, but should still have inference.",
20+
"position": {
21+
"start": {
22+
"line": 1,
23+
"column": 1
24+
},
25+
"end": {
26+
"line": 2,
27+
"column": 58
28+
},
29+
"indent": [
30+
1
31+
]
32+
}
33+
}
34+
],
35+
"position": {
36+
"start": {
37+
"line": 1,
38+
"column": 1
39+
},
40+
"end": {
41+
"line": 2,
42+
"column": 58
43+
},
44+
"indent": [
45+
1
46+
]
47+
}
48+
},
49+
{
50+
"type": "strong",
51+
"children": [
52+
{
53+
"type": "text",
54+
"value": "Parameters"
55+
}
56+
]
57+
},
58+
{
59+
"ordered": false,
60+
"type": "list",
61+
"children": [
62+
{
63+
"type": "listItem",
64+
"children": [
65+
{
66+
"type": "paragraph",
67+
"children": [
68+
{
69+
"type": "inlineCode",
70+
"value": "a"
71+
},
72+
{
73+
"type": "text",
74+
"value": " "
75+
},
76+
{
77+
"type": "strong",
78+
"children": [
79+
{
80+
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
81+
"type": "link",
82+
"children": [
83+
{
84+
"type": "text",
85+
"value": "number"
86+
}
87+
]
88+
}
89+
]
90+
},
91+
{
92+
"type": "text",
93+
"value": " "
94+
}
95+
]
96+
}
97+
]
98+
}
99+
]
100+
},
101+
{
102+
"type": "paragraph",
103+
"children": [
104+
{
105+
"type": "text",
106+
"value": "Returns "
107+
},
108+
{
109+
"type": "strong",
110+
"children": [
111+
{
112+
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number",
113+
"type": "link",
114+
"children": [
115+
{
116+
"type": "text",
117+
"value": "number"
118+
}
119+
]
120+
}
121+
]
122+
},
123+
{
124+
"type": "text",
125+
"value": " "
126+
}
127+
]
128+
}
129+
]
130+
}

0 commit comments

Comments
 (0)