1
1
import { parse , type Node } from "kdljs" ;
2
- import type { Enum , Event , Property , Interface , WebIdl } from "./types" ;
2
+ import type { Enum , Event , Property , Interface , WebIdl , Method } from "./types" ;
3
3
import { readdir , readFile } from "fs/promises" ;
4
4
import { merge } from "./helpers.js" ;
5
5
@@ -76,6 +76,7 @@ function handleMixin(node: Node): DeepPartial<Interface> {
76
76
77
77
const event : Event [ ] = [ ] ;
78
78
const property : Record < string , Partial < Property > > = { } ;
79
+ const method : Record < string , Partial < Method > > = { } ;
79
80
80
81
for ( const child of node . children ) {
81
82
switch ( child . name ) {
@@ -87,6 +88,11 @@ function handleMixin(node: Node): DeepPartial<Interface> {
87
88
property [ propName ] = handleProperty ( child ) ;
88
89
break ;
89
90
}
91
+ case "method" : {
92
+ const methodName = child . values [ 0 ] as string ;
93
+ method [ methodName ] = handleMethod ( child ) ;
94
+ break ;
95
+ }
90
96
default :
91
97
throw new Error ( `Unknown node name: ${ child . name } ` ) ;
92
98
}
@@ -96,6 +102,7 @@ function handleMixin(node: Node): DeepPartial<Interface> {
96
102
name,
97
103
events : { event } ,
98
104
properties : { property } ,
105
+ methods : { method } ,
99
106
} as DeepPartial < Interface > ;
100
107
if ( node . properties . extends ) {
101
108
result . extends = node . properties . extends as string ;
@@ -125,6 +132,19 @@ function handleProperty(child: Node): Partial<Property> {
125
132
} ;
126
133
}
127
134
135
+ /**
136
+ * Handles a child node of type "method" and adds it to the method object.
137
+ * @param child The child node to handle.
138
+ */
139
+ function handleMethod ( child : Node ) : Partial < Method > {
140
+ const name = child . values [ 0 ] as string ;
141
+ // Build the overrideSignatures array with the method signature string
142
+ const overrideSignatures = [
143
+ `${ name } (${ child . children . map ( ( c ) => `${ c . values [ 0 ] } : ${ c . properties . type } ` ) . join ( ", " ) } ): ${ child . properties . returns || "void" } ` ,
144
+ ] ;
145
+ return { name, overrideSignatures } ;
146
+ }
147
+
128
148
/**
129
149
* Collect all file URLs in a directory.
130
150
*/
0 commit comments