@@ -81,8 +81,8 @@ function handleTypeParameters(value: Value | Node) {
8181 } ;
8282}
8383
84- function undefinedIfEmpty ( object : object , output : object ) {
85- return Object . entries ( object ) . length ? output : undefined ;
84+ function optionalNestedMember < T > ( prop : string , object : object , output : T ) {
85+ return Object . entries ( object ) . length ? { [ prop ] : output } : { } ;
8686}
8787
8888/**
@@ -119,10 +119,12 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
119119 }
120120
121121 return {
122- enums : undefinedIfEmpty ( enums , { enum : enums } ) ,
123- mixins : undefinedIfEmpty ( mixin , { mixin } ) ,
124- interfaces : undefinedIfEmpty ( interfaces , { interface : interfaces } ) ,
125- dictionaries : undefinedIfEmpty ( dictionary , { dictionary } ) ,
122+ ...optionalNestedMember ( "enums" , enums , { enum : enums } ) ,
123+ ...optionalNestedMember ( "mixins" , mixin , { mixin } ) ,
124+ ...optionalNestedMember ( "interfaces" , interfaces , {
125+ interface : interfaces ,
126+ } ) ,
127+ ...optionalNestedMember ( "dictionaries" , dictionary , { dictionary } ) ,
126128 } ;
127129}
128130
@@ -202,7 +204,7 @@ function handleMixinAndInterfaces(
202204 } ;
203205 return {
204206 name,
205- events : { event } ,
207+ ... optionalNestedMember ( " events" , event , { event } ) ,
206208 properties : { property } ,
207209 methods : { method } ,
208210 ...optionalMember ( "extends" , "string" , node . properties ?. extends ) ,
@@ -398,8 +400,7 @@ async function readPatchDocument(fileUrl: URL): Promise<Document> {
398400 */
399401function convertForRemovals ( obj : unknown ) : unknown {
400402 if ( Array . isArray ( obj ) ) {
401- const result = obj . map ( convertForRemovals ) . filter ( ( v ) => v !== undefined ) ;
402- return result . length === 0 ? null : result ;
403+ return obj . map ( convertForRemovals ) . filter ( ( v ) => v !== undefined ) ;
403404 }
404405 if ( obj && typeof obj === "object" ) {
405406 const newObj : Record < string , unknown > = { } ;
0 commit comments