diff --git a/packages/analyzer/fixtures/03-module/functionLike/fixture/custom-elements.json b/packages/analyzer/fixtures/03-module/functionLike/fixture/custom-elements.json index 54b6f2ba..271f8b84 100644 --- a/packages/analyzer/fixtures/03-module/functionLike/fixture/custom-elements.json +++ b/packages/analyzer/fixtures/03-module/functionLike/fixture/custom-elements.json @@ -164,6 +164,45 @@ "name": "emptyReturn", "kind": "function" }, + { + "kind": "function", + "name": "functionWithRestParam1", + "parameters": [ + { + "name": "args", + "type": { + "text": "string" + }, + "rest": true + } + ] + }, + { + "kind": "function", + "name": "functionWithRestParam2", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, + { + "kind": "function", + "name": "functionWithRestParam3", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, { "kind": "class", "description": "METHODS", @@ -244,6 +283,45 @@ } } ] + }, + { + "kind": "method", + "name": "functionWithRestParam1", + "parameters": [ + { + "name": "args", + "type": { + "text": "string" + }, + "rest": true + } + ] + }, + { + "kind": "method", + "name": "functionWithRestParam2", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, + { + "kind": "method", + "name": "functionWithRestParam3", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] } ] } @@ -353,6 +431,30 @@ }, "kind": "js" }, + { + "kind": "js", + "name": "functionWithRestParam1", + "declaration": { + "name": "functionWithRestParam1", + "module": "my-element.js" + } + }, + { + "kind": "js", + "name": "functionWithRestParam2", + "declaration": { + "name": "functionWithRestParam2", + "module": "my-element.js" + } + }, + { + "kind": "js", + "name": "functionWithRestParam3", + "declaration": { + "name": "functionWithRestParam3", + "module": "my-element.js" + } + }, { "kind": "js", "name": "MyEl", diff --git a/packages/analyzer/fixtures/03-module/functionLike/output.json b/packages/analyzer/fixtures/03-module/functionLike/output.json index 609919d8..bdc03177 100644 --- a/packages/analyzer/fixtures/03-module/functionLike/output.json +++ b/packages/analyzer/fixtures/03-module/functionLike/output.json @@ -164,6 +164,45 @@ "kind": "function", "name": "emptyReturn" }, + { + "kind": "function", + "name": "functionWithRestParam1", + "parameters": [ + { + "name": "args", + "type": { + "text": "string" + }, + "rest": true + } + ] + }, + { + "kind": "function", + "name": "functionWithRestParam2", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, + { + "kind": "function", + "name": "functionWithRestParam3", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, { "kind": "class", "description": "METHODS", @@ -244,6 +283,45 @@ } } ] + }, + { + "kind": "method", + "name": "functionWithRestParam1", + "parameters": [ + { + "name": "args", + "type": { + "text": "string" + }, + "rest": true + } + ] + }, + { + "kind": "method", + "name": "functionWithRestParam2", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] + }, + { + "kind": "method", + "name": "functionWithRestParam3", + "parameters": [ + { + "name": "args", + "type": { + "text": "number" + }, + "rest": true + } + ] } ] } @@ -353,6 +431,30 @@ "module": "my-element.js" } }, + { + "kind": "js", + "name": "functionWithRestParam1", + "declaration": { + "name": "functionWithRestParam1", + "module": "my-element.js" + } + }, + { + "kind": "js", + "name": "functionWithRestParam2", + "declaration": { + "name": "functionWithRestParam2", + "module": "my-element.js" + } + }, + { + "kind": "js", + "name": "functionWithRestParam3", + "declaration": { + "name": "functionWithRestParam3", + "module": "my-element.js" + } + }, { "kind": "js", "name": "MyEl", diff --git a/packages/analyzer/fixtures/03-module/functionLike/package/my-element.js b/packages/analyzer/fixtures/03-module/functionLike/package/my-element.js index 3d8f014f..7f06576c 100644 --- a/packages/analyzer/fixtures/03-module/functionLike/package/my-element.js +++ b/packages/analyzer/fixtures/03-module/functionLike/package/my-element.js @@ -39,6 +39,16 @@ export function emptyReturn() { return; } +export function functionWithRestParam1(...args: string){} +/** + * @param {...number} args + */ +export function functionWithRestParam2(args: string){} +/** + * @param {...number} args + */ +export function functionWithRestParam3(args){} + /** * METHODS */ @@ -57,4 +67,14 @@ export class MyEl { * @return {string} */ functionDeclaration6(bar:string):boolean{} + + functionWithRestParam1(...args: string){} + /** + * @param {...number} args + */ + functionWithRestParam2(args: string){} + /** + * @param {...number} args + */ + functionWithRestParam3(args){} } \ No newline at end of file diff --git a/packages/analyzer/src/features/analyse-phase/creators/createFunctionLike.js b/packages/analyzer/src/features/analyse-phase/creators/createFunctionLike.js index 32f121e4..27c4a7f5 100644 --- a/packages/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +++ b/packages/analyzer/src/features/analyse-phase/creators/createFunctionLike.js @@ -10,17 +10,17 @@ export function createFunctionLike(node) { kind: '', name: node?.name?.getText() || '' }; - + functionLikeTemplate = handleKind(functionLikeTemplate, node); functionLikeTemplate = handleModifiers(functionLikeTemplate, node); functionLikeTemplate = handleParametersAndReturnType(functionLikeTemplate, node); functionLikeTemplate = handleJsDoc(functionLikeTemplate, node); - + return functionLikeTemplate; } /** - * Determine the kind of the functionLike, either `'function'` or `'method'` + * Determine the kind of the functionLike, either `'function'` or `'method'` */ export function handleKind(functionLike, node) { switch(node.kind) { @@ -45,7 +45,7 @@ export function handleParametersAndReturnType(functionLike, node) { } const parameters = []; - node?.parameters?.forEach((param) => { + node?.parameters?.forEach((param) => { const parameter = { name: param.name.getText(), } @@ -62,6 +62,10 @@ export function handleParametersAndReturnType(functionLike, node) { parameter.type = {text: param.type.getText() } } + if(param?.dotDotDotToken) { + parameter.rest = true; + } + parameters.push(parameter); }); diff --git a/packages/analyzer/src/features/analyse-phase/creators/handlers.js b/packages/analyzer/src/features/analyse-phase/creators/handlers.js index a684c610..ebf2e032 100644 --- a/packages/analyzer/src/features/analyse-phase/creators/handlers.js +++ b/packages/analyzer/src/features/analyse-phase/creators/handlers.js @@ -83,8 +83,12 @@ export function handleJsDoc(doc, node) { } if(tag?.typeExpression) { - parameterTemplate.type = { - text: handleJsDocType(tag.typeExpression.type.getText()) + const typeExpression = handleJsDoc(tag.typeExpression.type.getText()); + if(typeExpression.startsWith('...')) { + parameterTemplate.type = { text: typeExpression.replace('...', '') }; + parameterTemplate.rest = true; + } else { + parameterTemplate.type = { text: typeExpression }; } }