Skip to content

Commit d0869e0

Browse files
committed
Keep the order of parameters from the yaml
1 parent 529c4a8 commit d0869e0

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

web/src/utils/functions.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,30 @@ function buildSyntaxString(
3232
? `${returns.values.map(v => v.type).join(`,${ZERO_WIDTH_SPACE} `)}`
3333
: '';
3434

35-
const requiredParams = parameters.filter(p => p.default === undefined);
36-
const optionalParams = parameters.filter(p => p.default !== undefined);
37-
38-
const requiredStr = requiredParams
39-
.map(p => `${p.type} ${p.name}`)
40-
.join(', ');
41-
42-
const optionalStr = optionalParams
43-
.map(p => `${p.type} ${p.name} = ${p.default}`)
44-
.join(', ');
45-
46-
let paramStr = '';
47-
if (requiredParams.length && optionalParams.length) {
48-
paramStr = `${requiredStr}, [ ${optionalStr} ]`;
49-
} else if (!requiredParams.length && optionalParams.length) {
50-
paramStr = `[ ${optionalStr} ]`;
51-
} else {
52-
paramStr = requiredStr;
35+
const paramParts: string[] = [];
36+
let optionalGroup: string[] = [];
37+
38+
const flushOptional = () => {
39+
if (optionalGroup.length) {
40+
paramParts.push(`[ ${optionalGroup.join(', ')} ]`);
41+
optionalGroup = [];
42+
}
43+
};
44+
45+
for (const p of parameters) {
46+
const str = `${p.type} ${p.name}${p.default !== undefined ? ` = ${p.default}` : ''}`;
47+
48+
if (p.default !== undefined) {
49+
optionalGroup.push(str);
50+
} else {
51+
flushOptional();
52+
paramParts.push(str);
53+
}
5354
}
5455

56+
flushOptional();
57+
58+
const paramStr = paramParts.join(', ');
5559
const spacedParams = paramStr.trim() === '' ? ' ' : ` ${paramStr} `;
5660

5761
return `${returnString} ${funcName} (${spacedParams})`;

0 commit comments

Comments
 (0)