1
- import { parse , type Value , type Node } from "kdljs" ;
1
+ import { parse , type Node } from "kdljs" ;
2
2
import type { Enum , Event , Property , Interface , WebIdl } from "./types" ;
3
3
import { readdir , readFile } from "fs/promises" ;
4
4
import { merge } from "./helpers.js" ;
@@ -7,24 +7,6 @@ type DeepPartial<T> = T extends object
7
7
? { [ K in keyof T ] ?: DeepPartial < T [ K ] > }
8
8
: T ;
9
9
10
- function optionalMember < const T > ( prop : string , type : T , value ?: Value ) {
11
- if ( value === undefined ) {
12
- return { } ;
13
- }
14
- if ( typeof value !== type ) {
15
- throw new Error ( `Expected type ${ value } for ${ prop } ` ) ;
16
- }
17
- return {
18
- [ prop ] : value as T extends "string"
19
- ? string
20
- : T extends "number"
21
- ? number
22
- : T extends "boolean"
23
- ? boolean
24
- : never ,
25
- } ;
26
- }
27
-
28
10
/**
29
11
* Converts patch files in KDL to match the [types](types.d.ts).
30
12
*/
@@ -110,12 +92,15 @@ function handleMixin(node: Node): DeepPartial<Interface> {
110
92
}
111
93
}
112
94
113
- return {
95
+ const result = {
114
96
name,
115
97
events : { event } ,
116
98
properties : { property } ,
117
- ...optionalMember ( "extends" , "string" , node . properties ?. extends ) ,
118
99
} as DeepPartial < Interface > ;
100
+ if ( node . properties . extends ) {
101
+ result . extends = node . properties . extends as string ;
102
+ }
103
+ return result ;
119
104
}
120
105
121
106
/**
@@ -136,9 +121,7 @@ function handleEvent(child: Node): Event {
136
121
function handleProperty ( child : Node ) : Partial < Property > {
137
122
return {
138
123
name : child . values [ 0 ] as string ,
139
- ...optionalMember ( "exposed" , "string" , child . properties ?. exposed ) ,
140
- ...optionalMember ( "optional" , "boolean" , child . properties ?. optional ) ,
141
- ...optionalMember ( "overrideType" , "string" , child . properties ?. overrideType ) ,
124
+ exposed : child . properties ?. exposed as string ,
142
125
} ;
143
126
}
144
127
0 commit comments