Skip to content
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

feat: spread param #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
]
}
]
}
Expand Down Expand Up @@ -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",
Expand Down
102 changes: 102 additions & 0 deletions packages/analyzer/fixtures/03-module/functionLike/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
]
}
]
}
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(),
}
Expand All @@ -62,6 +62,10 @@ export function handleParametersAndReturnType(functionLike, node) {
parameter.type = {text: param.type.getText() }
}

if(param?.dotDotDotToken) {
parameter.rest = true;
}

parameters.push(parameter);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}

Expand Down