From 55f79ebf14d08053d344d569068cb1e960b122ce Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 3 Nov 2015 17:40:33 -0500 Subject: [PATCH] Infer rest parameters. Fixes #223 --- lib/html_helpers.js | 2 + lib/infer/params.js | 19 +++ lib/markdown_format_type.js | 2 + test/fixture/es6-import.output.custom.md | 18 ++ test/fixture/es6-import.output.json | 118 +++++++++++-- test/fixture/es6-import.output.md | 18 ++ test/fixture/es6-import.output.md.json | 202 +++++++++++++++++++++++ test/fixture/es6.input.js | 12 ++ test/fixture/es6.output.custom.md | 18 ++ test/fixture/es6.output.json | 118 +++++++++++-- test/fixture/es6.output.md | 18 ++ test/fixture/es6.output.md.json | 202 +++++++++++++++++++++++ 12 files changed, 725 insertions(+), 22 deletions(-) diff --git a/lib/html_helpers.js b/lib/html_helpers.js index 225cb51..7f4ff77 100644 --- a/lib/html_helpers.js +++ b/lib/html_helpers.js @@ -89,6 +89,8 @@ function formatType(type, paths) { return type.elements.map(recurse).join(' or '); case 'AllLiteral': return 'Any'; + case 'RestType': + return '...' + formatType(type.expression); case 'OptionalType': return '[' + formatType(type.expression, paths) + ']'; case 'TypeApplication': diff --git a/lib/infer/params.js b/lib/infer/params.js index cb59a1c..4701727 100644 --- a/lib/infer/params.js +++ b/lib/infer/params.js @@ -58,6 +58,21 @@ module.exports = function () { }].concat(param.properties.map(destructuringPropertyToDoc.bind(null, i))); } + function restParamToDoc(param) { + var newParam = { + title: 'param', + name: param.argument.name, + lineNumber: param.loc.start.name, + type: { + type: 'RestType' + } + }; + if (param.typeAnnotation) { + newParam.type.expression = flowDoctrine(param.typeAnnotation.typeAnnotation); + } + return newParam; + } + function paramToDoc(param, i) { // ES6 default if (param.type === 'AssignmentPattern') { @@ -68,6 +83,10 @@ module.exports = function () { return destructuringParamToDoc(param, i); } + if (param.type === 'RestElement') { + return restParamToDoc(param); + } + var newParam = { title: 'param', name: param.name, diff --git a/lib/markdown_format_type.js b/lib/markdown_format_type.js index 30a08d9..3a90bcd 100644 --- a/lib/markdown_format_type.js +++ b/lib/markdown_format_type.js @@ -13,6 +13,8 @@ function formatType(type) { return 'Any'; case 'OptionalType': return '[' + formatType(type.expression) + ']'; + case 'RestType': + return '...' + formatType(type.expression); case 'TypeApplication': return formatType(type.expression) + '<' + type.applications.map(function (application) { diff --git a/test/fixture/es6-import.output.custom.md b/test/fixture/es6-import.output.custom.md index a1712d6..ea15cbc 100644 --- a/test/fixture/es6-import.output.custom.md +++ b/test/fixture/es6-import.output.custom.md @@ -23,6 +23,24 @@ This method says hello This is an async method +# functionWithRest + +This function takes rest params + +**Parameters** + +- `someParams` **...** + + +# functionWithRestAndType + +So does this one, with types + +**Parameters** + +- `someParams` **...number** + + # multiply This function returns the number one. diff --git a/test/fixture/es6-import.output.json b/test/fixture/es6-import.output.json index 5a42c29..84ca5cd 100644 --- a/test/fixture/es6-import.output.json +++ b/test/fixture/es6-import.output.json @@ -23,7 +23,7 @@ "column": 1 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "Sink", @@ -75,7 +75,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "params": [ @@ -137,7 +137,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "empty", @@ -179,7 +179,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "hello", @@ -204,6 +204,43 @@ { "description": "This is an async method", "tags": [], + "loc": { + "start": { + "line": 52, + "column": 0 + }, + "end": { + "line": 54, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 55, + "column": 0 + }, + "end": { + "line": 55, + "column": 24 + } + }, + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + }, + "errors": [], + "name": "foo", + "kind": "function", + "members": { + "instance": [], + "static": [] + }, + "path": [ + "foo" + ] + }, + { + "description": "This function takes rest params", + "tags": [], "loc": { "start": { "line": 40, @@ -221,21 +258,80 @@ "column": 0 }, "end": { - "line": 43, - "column": 24 + "line": 44, + "column": 1 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], - "name": "foo", + "name": "functionWithRest", "kind": "function", + "params": [ + { + "title": "param", + "name": "someParams", + "type": { + "type": "RestType" + } + } + ], "members": { "instance": [], "static": [] }, "path": [ - "foo" + "functionWithRest" + ] + }, + { + "description": "So does this one, with types", + "tags": [], + "loc": { + "start": { + "line": 46, + "column": 0 + }, + "end": { + "line": 48, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 49, + "column": 0 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + }, + "errors": [], + "name": "functionWithRestAndType", + "kind": "function", + "params": [ + { + "title": "param", + "name": "someParams", + "type": { + "type": "RestType", + "expression": { + "type": "NameExpression", + "name": "number" + } + } + } + ], + "members": { + "instance": [], + "static": [] + }, + "path": [ + "functionWithRestAndType" ] }, { @@ -272,7 +368,7 @@ "column": 31 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "returns": [ @@ -397,7 +493,7 @@ "column": 18 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "staticProp", diff --git a/test/fixture/es6-import.output.md b/test/fixture/es6-import.output.md index a1712d6..ea15cbc 100644 --- a/test/fixture/es6-import.output.md +++ b/test/fixture/es6-import.output.md @@ -23,6 +23,24 @@ This method says hello This is an async method +# functionWithRest + +This function takes rest params + +**Parameters** + +- `someParams` **...** + + +# functionWithRestAndType + +So does this one, with types + +**Parameters** + +- `someParams` **...number** + + # multiply This function returns the number one. diff --git a/test/fixture/es6-import.output.md.json b/test/fixture/es6-import.output.md.json index e60af5d..7b0b4f8 100644 --- a/test/fixture/es6-import.output.md.json +++ b/test/fixture/es6-import.output.md.json @@ -344,6 +344,208 @@ "indent": [] } }, + { + "depth": 1, + "type": "heading", + "children": [ + { + "type": "text", + "value": "functionWithRest" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This function takes rest params", + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 32 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 32 + }, + "indent": [] + } + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "Parameters" + } + ] + }, + { + "ordered": false, + "type": "list", + "children": [ + { + "type": "listItem", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "inlineCode", + "value": "someParams" + }, + { + "type": "text", + "value": " " + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "..." + } + ] + }, + { + "type": "text", + "value": " " + }, + { + "type": "root", + "children": [], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ] + } + ] + } + ] + }, + { + "depth": 1, + "type": "heading", + "children": [ + { + "type": "text", + "value": "functionWithRestAndType" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "So does this one, with types", + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 29 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 29 + }, + "indent": [] + } + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "Parameters" + } + ] + }, + { + "ordered": false, + "type": "list", + "children": [ + { + "type": "listItem", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "inlineCode", + "value": "someParams" + }, + { + "type": "text", + "value": " " + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "...number" + } + ] + }, + { + "type": "text", + "value": " " + }, + { + "type": "root", + "children": [], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ] + } + ] + } + ] + }, { "depth": 1, "type": "heading", diff --git a/test/fixture/es6.input.js b/test/fixture/es6.input.js index 1057619..b3013a8 100644 --- a/test/fixture/es6.input.js +++ b/test/fixture/es6.input.js @@ -37,6 +37,18 @@ class Sink { } } +/** + * This function takes rest params + */ +function functionWithRest(...someParams) { +} + +/** + * So does this one, with types + */ +function functionWithRestAndType(...someParams: number) { +} + /** * This is an async method */ diff --git a/test/fixture/es6.output.custom.md b/test/fixture/es6.output.custom.md index da04967..c3b6b5c 100644 --- a/test/fixture/es6.output.custom.md +++ b/test/fixture/es6.output.custom.md @@ -23,6 +23,24 @@ This method says hello This is an async method +# functionWithRest + +This function takes rest params + +**Parameters** + +- `someParams` **...** + + +# functionWithRestAndType + +So does this one, with types + +**Parameters** + +- `someParams` **...number** + + # multiply This function returns the number one. diff --git a/test/fixture/es6.output.json b/test/fixture/es6.output.json index 0b89072..b94a8ea 100644 --- a/test/fixture/es6.output.json +++ b/test/fixture/es6.output.json @@ -23,7 +23,7 @@ "column": 1 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "Sink", @@ -75,7 +75,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "params": [ @@ -137,7 +137,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "empty", @@ -179,7 +179,7 @@ "column": 3 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "hello", @@ -204,6 +204,43 @@ { "description": "This is an async method", "tags": [], + "loc": { + "start": { + "line": 52, + "column": 0 + }, + "end": { + "line": 54, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 55, + "column": 0 + }, + "end": { + "line": 55, + "column": 24 + } + }, + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + }, + "errors": [], + "name": "foo", + "kind": "function", + "members": { + "instance": [], + "static": [] + }, + "path": [ + "foo" + ] + }, + { + "description": "This function takes rest params", + "tags": [], "loc": { "start": { "line": 40, @@ -221,21 +258,80 @@ "column": 0 }, "end": { - "line": 43, - "column": 24 + "line": 44, + "column": 1 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], - "name": "foo", + "name": "functionWithRest", "kind": "function", + "params": [ + { + "title": "param", + "name": "someParams", + "type": { + "type": "RestType" + } + } + ], "members": { "instance": [], "static": [] }, "path": [ - "foo" + "functionWithRest" + ] + }, + { + "description": "So does this one, with types", + "tags": [], + "loc": { + "start": { + "line": 46, + "column": 0 + }, + "end": { + "line": 48, + "column": 3 + } + }, + "context": { + "loc": { + "start": { + "line": 49, + "column": 0 + }, + "end": { + "line": 50, + "column": 1 + } + }, + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + }, + "errors": [], + "name": "functionWithRestAndType", + "kind": "function", + "params": [ + { + "title": "param", + "name": "someParams", + "type": { + "type": "RestType", + "expression": { + "type": "NameExpression", + "name": "number" + } + } + } + ], + "members": { + "instance": [], + "static": [] + }, + "path": [ + "functionWithRestAndType" ] }, { @@ -272,7 +368,7 @@ "column": 31 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "returns": [ @@ -332,7 +428,7 @@ "column": 18 } }, - "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" + "code": "/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiply = (a, b) => a * b;\n\n/**\n * This is a sink\n */\nclass Sink {\n /**\n * This is a property of the sink.\n */\n staticProp = 42;\n\n /**\n * Is it empty\n */\n empty() {\n return 1;\n }\n\n /**\n * This method says hello\n */\n static hello() {\n return 'hello';\n }\n\n /**\n * @param {number} height the height of the thing\n * @param {number} width the width of the thing\n */\n constructor(height, width) {\n this.height = height;\n this.width = width;\n }\n}\n\n/**\n * This function takes rest params\n */\nfunction functionWithRest(...someParams) {\n}\n\n/**\n * So does this one, with types\n */\nfunction functionWithRestAndType(...someParams: number) {\n}\n\n/**\n * This is an async method\n */\nasync function foo() { }\n\nexport default multiply;\n" }, "errors": [], "name": "staticProp", diff --git a/test/fixture/es6.output.md b/test/fixture/es6.output.md index da04967..c3b6b5c 100644 --- a/test/fixture/es6.output.md +++ b/test/fixture/es6.output.md @@ -23,6 +23,24 @@ This method says hello This is an async method +# functionWithRest + +This function takes rest params + +**Parameters** + +- `someParams` **...** + + +# functionWithRestAndType + +So does this one, with types + +**Parameters** + +- `someParams` **...number** + + # multiply This function returns the number one. diff --git a/test/fixture/es6.output.md.json b/test/fixture/es6.output.md.json index b1d99cf..0cffc83 100644 --- a/test/fixture/es6.output.md.json +++ b/test/fixture/es6.output.md.json @@ -344,6 +344,208 @@ "indent": [] } }, + { + "depth": 1, + "type": "heading", + "children": [ + { + "type": "text", + "value": "functionWithRest" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "This function takes rest params", + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 32 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 32 + }, + "indent": [] + } + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "Parameters" + } + ] + }, + { + "ordered": false, + "type": "list", + "children": [ + { + "type": "listItem", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "inlineCode", + "value": "someParams" + }, + { + "type": "text", + "value": " " + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "..." + } + ] + }, + { + "type": "text", + "value": " " + }, + { + "type": "root", + "children": [], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ] + } + ] + } + ] + }, + { + "depth": 1, + "type": "heading", + "children": [ + { + "type": "text", + "value": "functionWithRestAndType" + } + ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "So does this one, with types", + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 29 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 29 + }, + "indent": [] + } + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "Parameters" + } + ] + }, + { + "ordered": false, + "type": "list", + "children": [ + { + "type": "listItem", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "inlineCode", + "value": "someParams" + }, + { + "type": "text", + "value": " " + }, + { + "type": "strong", + "children": [ + { + "type": "text", + "value": "...number" + } + ] + }, + { + "type": "text", + "value": " " + }, + { + "type": "root", + "children": [], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ] + } + ] + } + ] + }, { "depth": 1, "type": "heading",