Skip to content

Commit 03d4afe

Browse files
committed
-
1 parent 8c2aa44 commit 03d4afe

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/build/patches.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,40 @@ function handleProperty(child: Node): Partial<Property> {
173173
*/
174174
function handleMethod(child: Node): Partial<Method> {
175175
const name = string(child.values[0]);
176-
const type = child.children[0];
177176
const returnType = child.properties.returns;
178177

179-
const params = child.children
180-
.filter((c) => c.properties.type)
181-
.map((c) => ({
182-
name: string(c.values[0]),
183-
type: string(c.properties.type),
184-
}));
178+
let typeNode: Node | undefined;
179+
const params: { name: string; type: string }[] = [];
180+
181+
for (const c of child.children) {
182+
switch (c.name) {
183+
case "type":
184+
if (typeNode) {
185+
throw new Error(`Method "${name}" has multiple type nodes (invalid)`);
186+
}
187+
typeNode = c;
188+
break;
189+
190+
case "param":
191+
params.push({
192+
name: string(c.values[0]),
193+
type: string(c.properties.type),
194+
});
195+
break;
196+
197+
default:
198+
throw new Error(`Unexpected child "${c.name}" in method "${name}"`);
199+
}
200+
}
201+
202+
if (!typeNode) {
203+
throw new Error(`Method "${name}" is missing a return type`);
204+
}
185205

186206
const signature: Method["signature"] = [
187207
{
188208
param: params,
189-
...handleTyped(type, returnType),
209+
...handleTyped(typeNode, returnType),
190210
},
191211
];
192212
return { name, signature };

0 commit comments

Comments
 (0)