Skip to content

Commit 729d58a

Browse files
committed
undefinedifempty
1 parent fdd8294 commit 729d58a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/build/patches.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ function handleTypeParameters(value: Value) {
7676
};
7777
}
7878

79+
function undefinedIfEmpty(object: object, output: object) {
80+
return Object.entries(object).length ? output : undefined;
81+
}
82+
7983
/**
8084
* Converts parsed KDL Document nodes to match the [types](types.d.ts).
8185
*/
@@ -110,10 +114,10 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
110114
}
111115

112116
return {
113-
enums: { enum: enums },
114-
mixins: { mixin },
115-
interfaces: { interface: interfaces },
116-
dictionaries: { dictionary },
117+
enums: undefinedIfEmpty(enums, { enum: enums }),
118+
mixins: undefinedIfEmpty(mixin, { mixin }),
119+
interfaces: undefinedIfEmpty(interfaces, { interface: interfaces }),
120+
dictionaries: undefinedIfEmpty(dictionary, { dictionary }),
117121
};
118122
}
119123

@@ -436,9 +440,5 @@ export default async function readPatches(): Promise<{
436440
convertKDLNodes(removalNodes),
437441
) as DeepPartial<WebIdl>;
438442

439-
// Only because we don't use them
440-
removalPatches.mixins = undefined;
441-
removalPatches.interfaces = undefined;
442-
443443
return { patches, removalPatches };
444444
}

0 commit comments

Comments
 (0)