Skip to content

Infer getters as properties, not functions #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/infer/kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module.exports = function () {
} else if (t.isClassDeclaration(path)) {
comment.kind = 'class';
} else if (t.isFunction(path)) {
if (path.node && path.node.id && path.node.id.name && !!/^[A-Z]/.exec(path.node.id.name)) {
if (path.node && (path.node.kind === 'get' || path.node.kind === 'set')) {
comment.kind = 'member';
} else if (path.node && path.node.id && path.node.id.name && !!/^[A-Z]/.exec(path.node.id.name)) {
comment.kind = 'class';
} else {
comment.kind = 'function';
Expand Down
120 changes: 80 additions & 40 deletions test/fixture/es6-import.output.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/fixture/es6-import.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This is a sink

## aGetter

This is a getter method: it should be documented
as a property.

## constructor

**Parameters**
Expand Down
45 changes: 45 additions & 0 deletions test/fixture/es6-import.output.md.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,51 @@
"indent": []
}
},
{
"depth": 2,
"type": "heading",
"children": [
{
"type": "text",
"value": "aGetter"
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is a getter method: it should be documented\nas a property.",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 15
},
"indent": [
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 15
},
"indent": [
1
]
}
},
{
"depth": 2,
"type": "heading",
Expand Down
8 changes: 8 additions & 0 deletions test/fixture/es6.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class Sink {
return 'hello';
}

/**
* This is a getter method: it should be documented
* as a property.
*/
get aGetter() {
return 42;
}

/**
* @param {number} height the height of the thing
* @param {number} width the width of the thing
Expand Down
120 changes: 80 additions & 40 deletions test/fixture/es6.output.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/fixture/es6.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This is a sink

## aGetter

This is a getter method: it should be documented
as a property.

## constructor

**Parameters**
Expand Down
45 changes: 45 additions & 0 deletions test/fixture/es6.output.md.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,51 @@
"indent": []
}
},
{
"depth": 2,
"type": "heading",
"children": [
{
"type": "text",
"value": "aGetter"
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is a getter method: it should be documented\nas a property.",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 15
},
"indent": [
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 15
},
"indent": [
1
]
}
},
{
"depth": 2,
"type": "heading",
Expand Down
10 changes: 10 additions & 0 deletions test/fixture/html/nested.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ function bar() {
*/

bar();

/**
* This is Foo
*/
class Foo {
/**
* This is bar
*/
get bar() { }
}
48 changes: 48 additions & 0 deletions test/fixture/html/nested.output.files
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,16 @@ h4:hover .anchorjs-link {
class='col12 block field'
type='text' />
<div id='toc'>
<a
href='#Foo'
class='block bold'>
Foo
</a>
<a
href='#Foo.bar'
class='regular block'>
#bar
</a>
<a
href='#bar'
class='block bold'>
Expand Down Expand Up @@ -1686,6 +1696,44 @@ h4:hover .anchorjs-link {
<div class='fix-margin-3'>
<div class='px2'>
<div class='py1'><section class='py2 clearfix'>
<h2 id='Foo' class='mt0'>
Foo<span class='gray'></span>
</h2>





<p>This is Foo</p>

<h4>Instance members</h4>
<div class='collapsible' id='Foo.bar'>
<a href='#Foo.bar'>
<code>
#bar<span class='gray'></span>
</code>
<div class='force-inline'>
<p>This is bar</p>

</div>
</a>
<div class='collapser border px2'>
<section class='py2 clearfix'>
<h2 id='Foo.bar' class='mt0'>
bar<span class='gray'></span>
</h2>





<p>This is bar</p>

</section>
</div>
</div>
</section>
</div><div class='py1'><section class='py2 clearfix'>
<h2 id='bar' class='mt0'>
bar<span class='gray'></span>
</h2>
Expand Down
12 changes: 12 additions & 0 deletions test/lib/infer/kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ test('inferKind', function (t) {
foo();
})).kind, 'function', 'inferred var function');

t.equal(inferKind(toComment(
'class Foo { /** set b */ set b(v) { } }'
)).kind, 'member', 'member via set');

t.equal(inferKind(toComment(
'class Foo { /** get b */ get b() { } }'
)).kind, 'member', 'member via get');

t.equal(inferKind(toComment(
'class Foo { /** b */ b(v) { } }'
)).kind, 'function', 'normal function as part of class');

t.equal(inferKind(toComment(function () {
/** class */
function Foo() { }
Expand Down