Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 1, 2022
2 parents c1e5cdb + d982de4 commit bde74d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,23 @@ function table(parameters: any) {
const rows = parameters.map((parameter) => {
const row: string[] = [];

row.push(
`\`${parameter.flags.isRest ? '...' : ''}${parameter.name}${
parameter.flags.isOptional ? '?' : ''
}\``,
const nbsp = ' '; // ? <== Unicode no-break space character
const rest = parameter.flags.isRest ? '...' : '';
const optional = parameter.flags.isOptional ? '?' : '';

const isDestructuredParam = parameter.name == '__namedParameters';
const isDestructuredParamProp = parameter.name.startsWith(
'__namedParameters.',
);

if (isDestructuredParam) {
row.push(`\`${rest}«destructured»\``);
} else if (isDestructuredParamProp) {
row.push(`›${nbsp}\`${rest}${parameter.name.slice(18)}${optional}\``);
} else {
row.push(`\`${rest}${parameter.name}${optional}\``);
}

row.push(
parameter.type
? Handlebars.helpers.type.call(parameter.type, 'object')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ const getParameters = (
) => {
return parameters
.map((param) => {
const paramsmd: string[] = [];
if (param.flags.isRest) {
paramsmd.push('...');
}
const paramItem = `${param.name}${
param.flags.isOptional || param.defaultValue ? '?' : ''
}`;
paramsmd.push(backticks ? `\`${paramItem}\`` : paramItem);
return paramsmd.join('');
const isDestructuredParam = param.name == '__namedParameters';
const paramItem = `${param.flags.isRest ? '...' : ''}${
isDestructuredParam ? '«destructured»' : param.name
}${param.flags.isOptional || param.defaultValue ? '?' : ''}`;
return backticks ? `\`${paramItem}\`` : paramItem;
})
.join(', ');
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`Declarations: should compile any function type 1`] = `
#### Type declaration
▸ (...\`input\`): \`A\`
▸ (\`...input\`): \`A\`
##### Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ exports[`Signatures: should compile function with reference type' 1`] = `
`;
exports[`Signatures: should compile named parameters with comments' 1`] = `
"▸ **functionWithNamedParamsAndComments**(\`__namedParameters?\`, \`anotherParam\`): \`void\`
"▸ **functionWithNamedParamsAndComments**(\`«destructured»?\`, \`anotherParam\`): \`void\`
FOO
##### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| \`__namedParameters\` | \`Object\` | various options |
| \`__namedParameters.bar?\` | \`number\` | - |
| \`__namedParameters.foo?\` | \`number\` | - |
| \`«destructured»\` | \`Object\` | various options |
|  › \`bar?\` | \`number\` | - |
|  › \`foo?\` | \`number\` | - |
| \`anotherParam\` | \`string\` | Another param comment |
##### Returns
Expand All @@ -149,13 +149,13 @@ FOO
`;
exports[`Signatures: should compile named parameters' 1`] = `
"▸ **functionWithNamedParams**(\`__namedParameters\`): \`string\`
"▸ **functionWithNamedParams**(\`«destructured»\`): \`string\`
##### Parameters
| Name | Type |
| :------ | :------ |
| \`__namedParameters\` | \`Object\` |
| \`«destructured»\` | \`Object\` |
##### Returns
Expand Down Expand Up @@ -260,7 +260,7 @@ This is a function with multiple arguments and a return value.
`;
exports[`Signatures: should compile signature with rest params' 1`] = `
"▸ **functionWithRest**(...\`rest\`): \`string\`
"▸ **functionWithRest**(\`...rest\`): \`string\`
This is a function with rest parameter.
Expand All @@ -277,7 +277,7 @@ This is a function with rest parameter.
`;
exports[`Signatures: should compile signature with union types' 1`] = `
"▸ **functionWithUnionTypes**(\`arg\`, ...\`args\`): \`any\`
"▸ **functionWithUnionTypes**(\`arg\`, \`...args\`): \`any\`
##### Parameters
Expand Down

0 comments on commit bde74d1

Please sign in to comment.