@@ -131,7 +131,9 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
131131 ...optionalMember ( "enums.enum" , "object" , enums ) ,
132132 ...optionalMember ( "mixins.mixin" , "object" , mixin ) ,
133133 ...optionalMember ( "interfaces.interface" , "object" , interfaces ) ,
134- ...optionalMember ( "dictionaries.dictionary" , "object" , dictionary ) ,
134+ dictionaries : {
135+ dictionary
136+ }
135137 } ;
136138}
137139
@@ -396,21 +398,26 @@ async function readPatchDocument(fileUrl: URL): Promise<Node[]> {
396398 return output ! ;
397399}
398400/**
399- * Remove all name fields from the object and its children as we don't want
400- * the names to be part of the removal .
401+ * Recursively remove all ' name' fields from the object and its children, and
402+ * replace any empty objects ({} or []) with null .
401403 */
402- function removeNamesDeep ( obj : unknown ) : unknown {
404+ function sanitizeRemovals ( obj : unknown ) : unknown {
403405 if ( Array . isArray ( obj ) ) {
404- return obj . map ( removeNamesDeep ) ;
406+ const result = obj . map ( sanitizeRemovals ) . filter ( ( v ) => v !== undefined ) ;
407+ return result . length === 0 ? null : result ;
405408 }
406409 if ( obj && typeof obj === "object" ) {
407410 const newObj : { [ key : string ] : unknown } = { } ;
408411 for ( const [ key , value ] of Object . entries ( obj as Record < string , unknown > ) ) {
409412 if ( key !== "name" ) {
410- newObj [ key ] = removeNamesDeep ( value ) ;
413+ const cleaned = sanitizeRemovals ( value ) ;
414+ if ( cleaned !== undefined ) {
415+ newObj [ key ] = cleaned ;
416+ }
411417 }
412418 }
413- return newObj ;
419+ // Replace empty objects with null
420+ return Object . keys ( newObj ) . length === 0 ? null : newObj ;
414421 }
415422 return obj ;
416423}
@@ -461,7 +468,7 @@ export default async function readPatches(): Promise<{
461468 const removalObjs = removalsNodeGroups . map ( ( nodes ) => convertKDLNodes ( nodes ) ) ;
462469
463470 const patches = patchObjs . reduce ( ( acc , cur ) => merge ( acc , cur ) , { } ) ;
464- const removalPatches = removeNamesDeep (
471+ const removalPatches = sanitizeRemovals (
465472 removalObjs . reduce ( ( acc , cur ) => merge ( acc , cur ) , { } ) ,
466473 ) ;
467474
0 commit comments