|
1 | | -import { parse, type Value, type Node } from "kdljs"; |
| 1 | +import { parse, type Value, type Node, Document } from "kdljs"; |
2 | 2 | import type { |
3 | 3 | Enum, |
4 | 4 | Event, |
@@ -377,16 +377,16 @@ async function readPatchDocument(fileUrl: URL): Promise<Document> { |
377 | 377 | * Recursively remove all 'name' fields from the object and its children, and |
378 | 378 | * replace any empty objects ({} or []) with null. |
379 | 379 | */ |
380 | | -function sanitizeRemovals(obj: unknown): unknown { |
| 380 | +function convertForRemovals(obj: unknown): unknown { |
381 | 381 | if (Array.isArray(obj)) { |
382 | | - const result = obj.map(sanitizeRemovals).filter((v) => v !== undefined); |
| 382 | + const result = obj.map(convertForRemovals).filter((v) => v !== undefined); |
383 | 383 | return result.length === 0 ? null : result; |
384 | 384 | } |
385 | 385 | if (obj && typeof obj === "object") { |
386 | 386 | const newObj: Record<string, unknown> = {}; |
387 | 387 | for (const [key, value] of Object.entries(obj)) { |
388 | 388 | if (key !== "name") { |
389 | | - const cleaned = sanitizeRemovals(value); |
| 389 | + const cleaned = convertForRemovals(value); |
390 | 390 | if (cleaned !== undefined) { |
391 | 391 | newObj[key] = cleaned; |
392 | 392 | } |
@@ -421,11 +421,16 @@ export default async function readPatches(): Promise<{ |
421 | 421 | // Stage 2: Group by patches or removals |
422 | 422 | const merged = documents.flat(); |
423 | 423 | const patchNodes = merged.filter((node) => node.name !== "removals"); |
424 | | - const removalNodes = merged.filter((node) => node.name === "removals").map((node) => node.children)).flat(); |
| 424 | + const removalNodes = merged |
| 425 | + .filter((node) => node.name === "removals") |
| 426 | + .map((node) => node.children) |
| 427 | + .flat(); |
425 | 428 |
|
426 | 429 | // Stage 3: Convert the nodes for patches and removals respectively |
427 | 430 | const patches = convertKDLNodes(patchNodes); |
428 | | - const removalPatches = sanitizeRemovals(convertKDLNodes(removalNodes)); |
| 431 | + const removalPatches = convertForRemovals( |
| 432 | + convertKDLNodes(removalNodes), |
| 433 | + ) as DeepPartial<WebIdl>; |
429 | 434 |
|
430 | 435 | // Only because we don't use them |
431 | 436 | removalPatches.mixins = undefined; |
|
0 commit comments