From 743c7a317353f9103b3848543c4bdabf0976de22 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Fri, 7 Nov 2025 09:33:52 +0200 Subject: [PATCH] KDL support for removals --- inputfiles/removals/Authenticator.kdl | 3 +++ inputfiles/removedTypes.jsonc | 3 --- src/build.ts | 4 +++- src/build/patches.ts | 31 +++++++++++++++++++++++---- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 inputfiles/removals/Authenticator.kdl diff --git a/inputfiles/removals/Authenticator.kdl b/inputfiles/removals/Authenticator.kdl new file mode 100644 index 000000000..2482fcbd5 --- /dev/null +++ b/inputfiles/removals/Authenticator.kdl @@ -0,0 +1,3 @@ +enum AuthenticatorTransport { + smart-card // WebKit only as of 2023-05 +} diff --git a/inputfiles/removedTypes.jsonc b/inputfiles/removedTypes.jsonc index f0a655543..d76c1d989 100644 --- a/inputfiles/removedTypes.jsonc +++ b/inputfiles/removedTypes.jsonc @@ -13,9 +13,6 @@ }, "enums": { "enum": { - "AuthenticatorTransport": { - "value": ["smart-card"] // WebKit only as of 2023-05 - }, "ConnectionType": { "value": ["wimax"] }, diff --git a/src/build.ts b/src/build.ts index 489fcbc85..fa38bfa37 100644 --- a/src/build.ts +++ b/src/build.ts @@ -89,7 +89,8 @@ async function emitDom() { const overriddenItems = await readInputJSON("overridingTypes.jsonc"); const addedItems = await readInputJSON("addedTypes.jsonc"); - const patches = await readPatches(); + const patches = await readPatches("patches"); + const removals = await readPatches("removals"); const comments = await readInputJSON("comments.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); @@ -204,6 +205,7 @@ async function emitDom() { webidl = merge(webidl, getRemovalData(webidl)); webidl = merge(webidl, getDocsData(webidl)); webidl = prune(webidl, removedItems); + webidl = prune(webidl, removals); webidl = merge(webidl, addedItems); webidl = merge(webidl, overriddenItems); webidl = merge(webidl, patches); diff --git a/src/build/patches.ts b/src/build/patches.ts index 7c949ebce..0032048f5 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -375,14 +375,37 @@ export async function readPatch(fileUrl: URL): Promise { return parseKDL(text); } +function removeNamesDeep(obj: unknown): unknown { + if (Array.isArray(obj)) { + return obj.map(removeNamesDeep); + } else if (obj && typeof obj === "object") { + const newObj: { [key: string]: unknown } = {}; + for (const [key, value] of Object.entries(obj as Record)) { + if (key !== "name") { + newObj[key] = removeNamesDeep(value); + } + } + return newObj; + } + return obj; +} + /** * Read, parse, and merge all KDL files under the input folder. */ -export default async function readPatches(): Promise { - const patchDirectory = new URL("../../inputfiles/patches/", import.meta.url); +export default async function readPatches( + folder: "patches" | "removals", +): Promise { + const patchDirectory = new URL( + `../../inputfiles/${folder}/`, + import.meta.url, + ); const fileUrls = await getAllFileURLs(patchDirectory); const parsedContents = await Promise.all(fileUrls.map(readPatch)); - - return parsedContents.reduce((acc, current) => merge(acc, current), {}); + const res = parsedContents.reduce((acc, current) => merge(acc, current), {}); + if (folder == "removals") { + return removeNamesDeep(res); + } + return res; }