Skip to content

Commit 432151b

Browse files
committed
Fix nullable type support. Fixes #245
1 parent a8581b4 commit 432151b

9 files changed

+108
-6
lines changed

lib/html_helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function formatType(type, paths) {
9292
case 'RestType':
9393
return '...' + formatType(type.expression, paths);
9494
case 'OptionalType':
95+
case 'NullableType':
9596
return '<code>[' + formatType(type.expression, paths) + ']</code>';
9697
case 'TypeApplication':
9798
return formatType(type.expression, paths) + '<' +

lib/markdown_format_type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function formatType(type) {
1212
case 'AllLiteral':
1313
return 'Any';
1414
case 'OptionalType':
15+
case 'NullableType':
1516
return '[' + formatType(type.expression) + ']';
1617
case 'RestType':
1718
return '...' + formatType(type.expression);

test/fixture/html/nested.input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ Klass.prototype.getFoo = function () {
2323
* @param {Object} options
2424
* @param {string} options.foo
2525
* @param {number} options.bar
26+
* @param {?number} otherOptions
2627
*/
27-
Klass.prototype.withOptions = function (options) {
28+
Klass.prototype.withOptions = function (options, otherOptions) {
2829
};
2930

3031
/**

test/fixture/html/nested.output.files

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ the referenced class type</p>
16511651
<div class='collapsible' id='Klass.withOptions'>
16521652
<a href='#Klass.withOptions'>
16531653
<code>
1654-
#withOptions<span class='gray'>(options)</span>
1654+
#withOptions<span class='gray'>(options, otherOptions)</span>
16551655
</code>
16561656
<span class='force-inline'>
16571657
<p>A function with an options parameter</p>
@@ -1661,7 +1661,7 @@ the referenced class type</p>
16611661
<div class='collapser border px2'>
16621662
<section class='py2 clearfix'>
16631663
<h2 id='Klass.withOptions' class='mt0'>
1664-
withOptions<span class='gray'>(options)</span>
1664+
withOptions<span class='gray'>(options, otherOptions)</span>
16651665
</h2>
16661666
<p>A function with an options parameter</p>
16671667

@@ -1679,6 +1679,12 @@ the referenced class type</p>
16791679
<li><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code> options.bar
16801680
</li>
16811681
</ul>
1682+
<li><code>[<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>]</code> <strong>otherOptions</strong>
1683+
:
1684+
<span class='force-inline'>
1685+
1686+
</span>
1687+
</li>
16821688
</ul>
16831689
</section>
16841690
</div>

test/fixture/optional.input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @class Address6
44
* @param {string} address - An IPv6 address string
55
* @param {number} [groups=8] - How many octets to parse
6+
* @param {?number} third - A third argument
67
* @example
78
* var address = new Address6('2001::/32');
89
*/

test/fixture/optional.output.custom.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Represents an IPv6 address
66

77
- `address` **string** An IPv6 address string
88
- `groups` **[number]** How many octets to parse (optional, default `8`)
9+
- `third` **[number]** A third argument
910

1011
**Examples**
1112

test/fixture/optional.output.json

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,24 @@
3333
"name": "groups",
3434
"default": "8"
3535
},
36+
{
37+
"title": "param",
38+
"description": "A third argument",
39+
"lineNumber": 5,
40+
"type": {
41+
"type": "NullableType",
42+
"expression": {
43+
"type": "NameExpression",
44+
"name": "number"
45+
},
46+
"prefix": true
47+
},
48+
"name": "third"
49+
},
3650
{
3751
"title": "example",
3852
"description": "var address = new Address6('2001::/32');",
39-
"lineNumber": 5
53+
"lineNumber": 6
4054
}
4155
],
4256
"loc": {
@@ -45,7 +59,7 @@
4559
"column": 0
4660
},
4761
"end": {
48-
"line": 8,
62+
"line": 9,
4963
"column": 3
5064
}
5165
},
@@ -56,7 +70,7 @@
5670
"column": 0
5771
},
5872
"end": {
59-
"line": 9,
73+
"line": 10,
6074
"column": 0
6175
}
6276
}
@@ -89,6 +103,20 @@
89103
},
90104
"name": "groups",
91105
"default": "8"
106+
},
107+
{
108+
"title": "param",
109+
"description": "A third argument",
110+
"lineNumber": 5,
111+
"type": {
112+
"type": "NullableType",
113+
"expression": {
114+
"type": "NameExpression",
115+
"name": "number"
116+
},
117+
"prefix": true
118+
},
119+
"name": "third"
92120
}
93121
],
94122
"examples": [

test/fixture/optional.output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Represents an IPv6 address
66

77
- `address` **string** An IPv6 address string
88
- `groups` **[number]** How many octets to parse (optional, default `8`)
9+
- `third` **[number]** A third argument
910

1011
**Examples**
1112

test/fixture/optional.output.md.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,68 @@
195195
]
196196
}
197197
]
198+
},
199+
{
200+
"type": "listItem",
201+
"children": [
202+
{
203+
"type": "paragraph",
204+
"children": [
205+
{
206+
"type": "inlineCode",
207+
"value": "third"
208+
},
209+
{
210+
"type": "text",
211+
"value": " "
212+
},
213+
{
214+
"type": "strong",
215+
"children": [
216+
{
217+
"type": "text",
218+
"value": "[number]"
219+
}
220+
]
221+
},
222+
{
223+
"type": "text",
224+
"value": " "
225+
},
226+
{
227+
"type": "paragraph",
228+
"children": [
229+
{
230+
"type": "text",
231+
"value": "A third argument",
232+
"position": {
233+
"start": {
234+
"line": 1,
235+
"column": 1
236+
},
237+
"end": {
238+
"line": 1,
239+
"column": 17
240+
},
241+
"indent": []
242+
}
243+
}
244+
],
245+
"position": {
246+
"start": {
247+
"line": 1,
248+
"column": 1
249+
},
250+
"end": {
251+
"line": 1,
252+
"column": 17
253+
},
254+
"indent": []
255+
}
256+
}
257+
]
258+
}
259+
]
198260
}
199261
]
200262
},

0 commit comments

Comments
 (0)