Skip to content

Allow param tag type to be inferred and merged with description #232

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
Nov 5, 2015
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
9 changes: 9 additions & 0 deletions lib/infer/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,20 @@ module.exports = function () {

path.value.params.forEach(function (param, j) {
if (existingParams[param.name] === undefined) {
// This type is not explicitly documented
if (!comment.params) {
comment.params = [];
}

comment.params = comment.params.concat(paramToDoc(param, j));
} else if (!existingParams[param.name].type) {
// This param has a description, but potentially it can
// be have an inferred type. Infer its type without
// dropping the description.
var doc = paramToDoc(param, j);
if (doc.type) {
existingParams[param.name].type = doc.type;
}
}
paramOrder[param.name] = i++;
});
Expand Down
9 changes: 9 additions & 0 deletions test/fixture/merge-infered-type.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Add five to `x`.
*
* @param x The number to add five to.
* @returns {number} x plus five.
*/
function addFive(x: number): number {
return x + 5;
}
9 changes: 9 additions & 0 deletions test/fixture/merge-infered-type.output.custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# addFive

Add five to `x`.

**Parameters**

- `x` **number** The number to add five to.

Returns **number** x plus five.
82 changes: 82 additions & 0 deletions test/fixture/merge-infered-type.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"description": "Add five to `x`.",
"tags": [
{
"title": "param",
"description": "The number to add five to.",
"lineNumber": 3,
"type": {
"type": "NameExpression",
"name": "number"
},
"name": "x"
},
{
"title": "returns",
"description": "x plus five.",
"lineNumber": 4,
"type": {
"type": "NameExpression",
"name": "number"
}
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 9,
"column": 1
}
},
"code": "/**\n * Add five to `x`.\n *\n * @param x The number to add five to.\n * @returns {number} x plus five.\n */\nfunction addFive(x: number): number {\n return x + 5;\n}\n"
},
"errors": [],
"params": [
{
"title": "param",
"description": "The number to add five to.",
"lineNumber": 3,
"type": {
"type": "NameExpression",
"name": "number"
},
"name": "x"
}
],
"returns": [
{
"title": "returns",
"description": "x plus five.",
"lineNumber": 4,
"type": {
"type": "NameExpression",
"name": "number"
}
}
],
"name": "addFive",
"kind": "function",
"members": {
"instance": [],
"static": []
},
"path": [
"addFive"
]
}
]
9 changes: 9 additions & 0 deletions test/fixture/merge-infered-type.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# addFive

Add five to `x`.

**Parameters**

- `x` **number** The number to add five to.

Returns **number** x plus five.
206 changes: 206 additions & 0 deletions test/fixture/merge-infered-type.output.md.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
{
"type": "root",
"children": [
{
"depth": 1,
"type": "heading",
"children": [
{
"type": "text",
"value": "addFive"
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Add five to ",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 13
},
"indent": []
}
},
{
"type": "inlineCode",
"value": "x",
"position": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 16
},
"indent": []
}
},
{
"type": "text",
"value": ".",
"position": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 17
},
"indent": []
}
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "Parameters"
}
]
},
{
"ordered": false,
"type": "list",
"children": [
{
"type": "listItem",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "inlineCode",
"value": "x"
},
{
"type": "text",
"value": " "
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "number"
}
]
},
{
"type": "text",
"value": " "
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "The number to add five to.",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 27
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 27
},
"indent": []
}
}
]
}
]
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Returns "
},
{
"type": "strong",
"children": [
{
"type": "text",
"value": "number"
}
]
},
{
"type": "text",
"value": " "
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "x plus five.",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 13
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 13
},
"indent": []
}
}
]
}
]
}