Skip to content

Commit 688ea75

Browse files
committed
cats generator uses ... name for variadic arguments;
1 parent 4fcbe70 commit 688ea75

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

api/generators/cats.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ function argumentType(arg)
127127
end
128128
end
129129

130+
--- Returns the name of a function argument.
131+
function argumentName(arg)
132+
if arg.name:sub(1, 3) == '...' then
133+
return '...'
134+
else
135+
return arg.name
136+
end
137+
end
138+
130139
--- Renders the header (description, notes, examples, etc.) for anything that's like a function.
131140
local function renderFunctionHeader(out, func)
132141
add(out, "")
@@ -172,7 +181,7 @@ local function renderType(out, tag, variant)
172181
end
173182

174183
local params = join(map(variant.arguments, function(arg)
175-
return ("%s%s: %s"):format(arg.name, optionalSuffix(arg), argumentType(arg))
184+
return ("%s%s: %s"):format(argumentName(arg), optionalSuffix(arg), argumentType(arg))
176185
end), ", ")
177186

178187
add(out, doc(("%s fun(%s): %s"):format(tag, params, returns)))
@@ -184,7 +193,7 @@ local function renderFunctionVariant(out, func, variant)
184193
-- Document parameters
185194
if variant.arguments then
186195
for _, arg in ipairs(variant.arguments) do
187-
add(out, doc(("@param %s%s %s %s"):format(arg.name, optionalSuffix(arg), argumentType(arg), arg.description)))
196+
add(out, doc(("@param %s%s %s %s"):format(argumentName(arg), optionalSuffix(arg), argumentType(arg), arg.description)))
188197
end
189198
end
190199

@@ -197,7 +206,7 @@ local function renderFunctionVariant(out, func, variant)
197206

198207
-- Build function signature
199208
local signature = join(map(variant.arguments, function(arg)
200-
return arg.name
209+
return argumentName(arg)
201210
end), ", ")
202211

203212
add(out, ("function %s(%s) end"):format(func.key, signature))

0 commit comments

Comments
 (0)