File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -173,20 +173,40 @@ function handleProperty(child: Node): Partial<Property> {
173
173
*/
174
174
function handleMethod ( child : Node ) : Partial < Method > {
175
175
const name = string ( child . values [ 0 ] ) ;
176
- const type = child . children [ 0 ] ;
177
176
const returnType = child . properties . returns ;
178
177
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
+ }
185
205
186
206
const signature : Method [ "signature" ] = [
187
207
{
188
208
param : params ,
189
- ...handleTyped ( type , returnType ) ,
209
+ ...handleTyped ( typeNode , returnType ) ,
190
210
} ,
191
211
] ;
192
212
return { name, signature } ;
You can’t perform that action at this time.
0 commit comments