Skip to content

Commit 67b6fbd

Browse files
committed
Infer getters as properties, not functions
1 parent df96427 commit 67b6fbd

File tree

10 files changed

+329
-81
lines changed

10 files changed

+329
-81
lines changed

lib/infer/kind.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ module.exports = function () {
3434
} else if (t.isClassDeclaration(path)) {
3535
comment.kind = 'class';
3636
} else if (t.isFunction(path)) {
37-
if (path.node && path.node.id && path.node.id.name && !!/^[A-Z]/.exec(path.node.id.name)) {
37+
if (path.node && path.node.kind === 'get') {
38+
comment.kind = 'member';
39+
} else if (path.node && path.node.id && path.node.id.name && !!/^[A-Z]/.exec(path.node.id.name)) {
3840
comment.kind = 'class';
3941
} else {
4042
comment.kind = 'function';

test/fixture/es6-import.output.json

Lines changed: 80 additions & 40 deletions
Large diffs are not rendered by default.

test/fixture/es6-import.output.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This is a sink
44

5+
## aGetter
6+
7+
This is a getter method: it should be documented
8+
as a property.
9+
510
## constructor
611

712
**Parameters**

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,51 @@
4242
"indent": []
4343
}
4444
},
45+
{
46+
"depth": 2,
47+
"type": "heading",
48+
"children": [
49+
{
50+
"type": "text",
51+
"value": "aGetter"
52+
}
53+
]
54+
},
55+
{
56+
"type": "paragraph",
57+
"children": [
58+
{
59+
"type": "text",
60+
"value": "This is a getter method: it should be documented\nas a property.",
61+
"position": {
62+
"start": {
63+
"line": 1,
64+
"column": 1
65+
},
66+
"end": {
67+
"line": 2,
68+
"column": 15
69+
},
70+
"indent": [
71+
1
72+
]
73+
}
74+
}
75+
],
76+
"position": {
77+
"start": {
78+
"line": 1,
79+
"column": 1
80+
},
81+
"end": {
82+
"line": 2,
83+
"column": 15
84+
},
85+
"indent": [
86+
1
87+
]
88+
}
89+
},
4590
{
4691
"depth": 2,
4792
"type": "heading",

test/fixture/es6.input.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Sink {
4040
return 'hello';
4141
}
4242

43+
/**
44+
* This is a getter method: it should be documented
45+
* as a property.
46+
*/
47+
get aGetter() {
48+
return 42;
49+
}
50+
4351
/**
4452
* @param {number} height the height of the thing
4553
* @param {number} width the width of the thing

test/fixture/es6.output.json

Lines changed: 80 additions & 40 deletions
Large diffs are not rendered by default.

test/fixture/es6.output.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This is a sink
44

5+
## aGetter
6+
7+
This is a getter method: it should be documented
8+
as a property.
9+
510
## constructor
611

712
**Parameters**

test/fixture/es6.output.md.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,51 @@
4242
"indent": []
4343
}
4444
},
45+
{
46+
"depth": 2,
47+
"type": "heading",
48+
"children": [
49+
{
50+
"type": "text",
51+
"value": "aGetter"
52+
}
53+
]
54+
},
55+
{
56+
"type": "paragraph",
57+
"children": [
58+
{
59+
"type": "text",
60+
"value": "This is a getter method: it should be documented\nas a property.",
61+
"position": {
62+
"start": {
63+
"line": 1,
64+
"column": 1
65+
},
66+
"end": {
67+
"line": 2,
68+
"column": 15
69+
},
70+
"indent": [
71+
1
72+
]
73+
}
74+
}
75+
],
76+
"position": {
77+
"start": {
78+
"line": 1,
79+
"column": 1
80+
},
81+
"end": {
82+
"line": 2,
83+
"column": 15
84+
},
85+
"indent": [
86+
1
87+
]
88+
}
89+
},
4590
{
4691
"depth": 2,
4792
"type": "heading",

test/fixture/html/nested.input.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,13 @@ function bar() {
118118
*/
119119

120120
bar();
121+
122+
/**
123+
* This is Foo
124+
*/
125+
class Foo {
126+
/**
127+
* This is bar
128+
*/
129+
get bar() { }
130+
}

test/fixture/html/nested.output.files

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,16 @@ h4:hover .anchorjs-link {
16201620
class='col12 block field'
16211621
type='text' />
16221622
<div id='toc'>
1623+
<a
1624+
href='#Foo'
1625+
class='block bold'>
1626+
Foo
1627+
</a>
1628+
<a
1629+
href='#Foo.bar'
1630+
class='regular block'>
1631+
#bar
1632+
</a>
16231633
<a
16241634
href='#bar'
16251635
class='block bold'>
@@ -1686,6 +1696,44 @@ h4:hover .anchorjs-link {
16861696
<div class='fix-margin-3'>
16871697
<div class='px2'>
16881698
<div class='py1'><section class='py2 clearfix'>
1699+
<h2 id='Foo' class='mt0'>
1700+
Foo<span class='gray'></span>
1701+
</h2>
1702+
1703+
1704+
1705+
1706+
1707+
<p>This is Foo</p>
1708+
1709+
<h4>Instance members</h4>
1710+
<div class='collapsible' id='Foo.bar'>
1711+
<a href='#Foo.bar'>
1712+
<code>
1713+
#bar<span class='gray'></span>
1714+
</code>
1715+
<div class='force-inline'>
1716+
<p>This is bar</p>
1717+
1718+
</div>
1719+
</a>
1720+
<div class='collapser border px2'>
1721+
<section class='py2 clearfix'>
1722+
<h2 id='Foo.bar' class='mt0'>
1723+
bar<span class='gray'></span>
1724+
</h2>
1725+
1726+
1727+
1728+
1729+
1730+
<p>This is bar</p>
1731+
1732+
</section>
1733+
</div>
1734+
</div>
1735+
</section>
1736+
</div><div class='py1'><section class='py2 clearfix'>
16891737
<h2 id='bar' class='mt0'>
16901738
bar<span class='gray'></span>
16911739
</h2>

0 commit comments

Comments
 (0)