Skip to content

Commit 0718b29

Browse files
committed
Include default values in output
1 parent e1ffa17 commit 0718b29

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ function formatType(node, getNamedLink) {
120120
// lets the expression be omitted.
121121
return decorate(formatType(node.expression, getNamedLink), '...', true);
122122
case Syntax.OptionalType:
123-
return decorate(formatType(node.expression, getNamedLink), '=');
123+
return decorate(formatType(node.expression, getNamedLink), '=').concat(
124+
node.default ? t('(default ' + node.default + ')') : []);
124125
case Syntax.NonNullableType:
125126
return decorate(formatType(node.expression, getNamedLink), '!', node.prefix);
126127
case Syntax.NullableType:

test/format_type.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
var formatType = require('../index').formatType,
55
mdast = require('mdast'),
6-
parseParamType = require('doctrine/lib/typed').parseParamType,
6+
parse = require('doctrine').parse,
77
test = require('tap').test;
88

99
test('formatType', function (t) {
@@ -34,10 +34,17 @@ test('formatType', function (t) {
3434
].forEach(function (example) {
3535
t.deepEqual(mdast().stringify({
3636
type: 'paragraph',
37-
children: formatType(parseParamType(example[0]))
37+
children: formatType(
38+
parse('@param {' + example[0] + '} a', { sloppy: true }).tags[0].type)
3839
}), example[1], example[0]);
3940
});
4041

42+
t.deepEqual(mdast().stringify({
43+
type: 'paragraph',
44+
children: formatType(
45+
parse('@param {number} [a=1]', { sloppy: true }).tags[0].type)
46+
}), '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)=', 'default');
47+
4148
t.deepEqual(formatType(), [], 'empty case');
4249

4350
t.throws(function () {

0 commit comments

Comments
 (0)