From 73855ea27ae1683a5f5589bf07d749c6e2eca632 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 6 Jul 2025 16:52:14 +0300 Subject: [PATCH 01/32] chore: install deps --- package-lock.json | 77 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 78 insertions(+) diff --git a/package-lock.json b/package-lock.json index 1df705e51..a841533f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "eslint-plugin-prettier": "^5.1.3", "globals": "^16.0.0", "jsonc-parser": "^3.2.1", + "kdljs": "^0.3.0", "node-fetch": "^3.3.2", "prettier": "^3.2.5", "print-diff": "^2.0.0", @@ -46,6 +47,50 @@ "node": ">=0.10.0" } }, + "node_modules/@chevrotain/cst-dts-gen": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@chevrotain/cst-dts-gen/-/cst-dts-gen-11.0.3.tgz", + "integrity": "sha512-BvIKpRLeS/8UbfxXxgC33xOumsacaeCKAjAeLyOn7Pcp95HiRbrpl14S+9vaZLolnbssPIUuiUd8IvgkRyt6NQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/gast": "11.0.3", + "@chevrotain/types": "11.0.3", + "lodash-es": "4.17.21" + } + }, + "node_modules/@chevrotain/gast": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@chevrotain/gast/-/gast-11.0.3.tgz", + "integrity": "sha512-+qNfcoNk70PyS/uxmj3li5NiECO+2YKZZQMbmjTqRI3Qchu8Hig/Q9vgkHpI3alNjr7M+a2St5pw5w5F6NL5/Q==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/types": "11.0.3", + "lodash-es": "4.17.21" + } + }, + "node_modules/@chevrotain/regexp-to-ast": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@chevrotain/regexp-to-ast/-/regexp-to-ast-11.0.3.tgz", + "integrity": "sha512-1fMHaBZxLFvWI067AVbGJav1eRY7N8DDvYCTwGBiE/ytKBgP8azTdgyrKyWZ9Mfh09eHWb5PgTSO8wi7U824RA==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/@chevrotain/types": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@chevrotain/types/-/types-11.0.3.tgz", + "integrity": "sha512-gsiM3G8b58kZC2HaWR50gu6Y1440cHiJ+i3JUvcp/35JchYejb2+5MVeJK0iKThYpAa/P2PYFV4hoi44HD+aHQ==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/@chevrotain/utils": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@chevrotain/utils/-/utils-11.0.3.tgz", + "integrity": "sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.7.0.tgz", @@ -1199,6 +1244,21 @@ "node": ">=4" } }, + "node_modules/chevrotain": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-11.0.3.tgz", + "integrity": "sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@chevrotain/cst-dts-gen": "11.0.3", + "@chevrotain/gast": "11.0.3", + "@chevrotain/regexp-to-ast": "11.0.3", + "@chevrotain/types": "11.0.3", + "@chevrotain/utils": "11.0.3", + "lodash-es": "4.17.21" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -2707,6 +2767,16 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/kdljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/kdljs/-/kdljs-0.3.0.tgz", + "integrity": "sha512-tNb5vWkcouQKp8Q3CJ0BhA4ThcnWdVcY0Z+zertOelM8ywHVOabu3FZdDKldQj9j/CZt17eb5+kq/1Gg9GDtXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "chevrotain": "^11.0.3" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -2750,6 +2820,13 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "node_modules/lodash-es": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz", + "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.find": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz", diff --git a/package.json b/package.json index 80809a5c4..57b831ffc 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "eslint-plugin-prettier": "^5.1.3", "globals": "^16.0.0", "jsonc-parser": "^3.2.1", + "kdljs": "^0.3.0", "node-fetch": "^3.3.2", "prettier": "^3.2.5", "print-diff": "^2.0.0", From 82c47f9cdb1b3dbf6dfd0b293fdac01526106228 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 6 Jul 2025 16:56:02 +0300 Subject: [PATCH 02/32] Parser --- src/build/utils/kdl.ts | 112 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/build/utils/kdl.ts diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts new file mode 100644 index 000000000..12036a778 --- /dev/null +++ b/src/build/utils/kdl.ts @@ -0,0 +1,112 @@ +import { parse } from "kdljs"; +import { Enum, Event, Method, Property } from "../types"; +import { readFile } from "fs/promises"; + +interface MethodDescriptor { + [x: string]: Omit; +} + +interface EnumDescriptor { + [x: string]: Enum; +} +interface PropertyDescriptor { + [x: string]: Omit; +} + +interface InterfaceMixin { + [x: string]: { + events?: { event: Event[] }; + methods?: { method: MethodDescriptor }; + }; +} + +/** + * Converts KDL text describing interface-mixins into JSON format. + * Uses kdljs v3. + */ +export function parseKDL(kdlText: string) { + const { output, errors } = parse(kdlText); + + if (errors.length) { + throw new Error( + `KDL parse errors:\n${errors.map((e) => e.message).join("\n")}`, + ); + } + + const nodes = output!; + const enums: EnumDescriptor = {}; + const interfaces: InterfaceMixin = {}; + + for (const node of nodes) { + if (node.name === "enum") { + // Handle enum + const enumName = node.values?.[0]?.toString() ?? ""; + let name = enumName; + const values: string[] = []; + + for (const child of node.children ?? []) { + if ( + child.name === "value" && + child.values && + child.values[0] !== undefined + ) { + values.push(child.values[0]!.toString()); + } else if (child.name === "name") { + name = child.values?.[0]?.toString() ?? enumName; + } + } + + enums[enumName] = { name, value: values }; + } else { + // Handle interface-mixin + const name = node.values?.[0]?.toString() ?? ""; + const iface: { + events?: { event: Event[] }; + methods?: { method: MethodDescriptor }; + properties?: { property: PropertyDescriptor }; + } = {}; + + const events: Event[] = []; + const methods: MethodDescriptor = {}; + const properties: PropertyDescriptor = {}; + + for (const child of node.children ?? []) { + const name = child.values?.[0]?.toString() ?? ""; + if (child.name === "event") { + events.push({ + name, + type: child.properties?.type?.toString() ?? "", + }); + } else if (child.name === "method") { + methods[name] = { + name, + overrideSignatures: [ + child.properties?.overrideSignatures?.toString() ?? "", + ], + }; + } else if (child.name === "property") { + properties[name] = { + name, + exposed: child.properties?.exposed?.toString(), + }; + } + } + + if (events.length) iface.events = { event: events }; + if (Object.keys(methods).length) iface.methods = { method: methods }; + if (Object.keys(properties).length) + iface.properties = { property: properties }; + + interfaces[name] = iface; + } + } + + return { mixins: { mixin: interfaces }, enums: { enum: enums } }; +} +export default async function readInputKDL( + path: string, + inputFolder: string, +): Promise { + const text = await readFile(new URL(path, inputFolder), "utf8"); + return parseKDL(text); +} From ac0e253bac0a4ac3fc4a261c8a2358d8fa6bb543 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 6 Jul 2025 17:00:44 +0300 Subject: [PATCH 03/32] patch: types --- src/build/utils/kdl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 12036a778..540eabed2 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -105,7 +105,7 @@ export function parseKDL(kdlText: string) { } export default async function readInputKDL( path: string, - inputFolder: string, + inputFolder: URL, ): Promise { const text = await readFile(new URL(path, inputFolder), "utf8"); return parseKDL(text); From 99e1b99ac096bcc5bae6b1e8128abb00d08b761a Mon Sep 17 00:00:00 2001 From: Bashamega Date: Tue, 8 Jul 2025 09:42:56 +0300 Subject: [PATCH 04/32] - --- inputfiles/AutoFill/addedTypes.kdl | 70 +++++++++++++++++++++++ inputfiles/addedTypes.jsonc | 92 ------------------------------ src/build.ts | 3 + src/build/utils/kdl.ts | 47 +++++++++++++-- 4 files changed, 115 insertions(+), 97 deletions(-) create mode 100644 inputfiles/AutoFill/addedTypes.kdl diff --git a/inputfiles/AutoFill/addedTypes.kdl b/inputfiles/AutoFill/addedTypes.kdl new file mode 100644 index 000000000..4ea04c792 --- /dev/null +++ b/inputfiles/AutoFill/addedTypes.kdl @@ -0,0 +1,70 @@ +enum AutoFillBase { + // Off + value "off" + // Automatic + value "on" + value "" +} +enum AutoFillAddressKind { + value "shipping" + value "billing" +} +enum AutoFillNormalField { + value "name" + value "honorific-prefix" + value "given-name" + value "additional-name" + value "family-name" + value "honorific-suffix" + value "username" + value "new-password" + value "current-password" + // Supported in iOS Safari too even though WPT tests + // for Safari currently fail as of 2023-06. + value "one-time-code" + value "organization" + value "street-address" + value "address-line1" + value "address-line2" + value "address-line3" + value "address-level4" + value "address-level3" + value "address-level2" + value "address-level1" + value "country" + value "country-name" + value "postal-code" + value "cc-name" + value "cc-given-name" + value "cc-family-name" + value "cc-number" + value "cc-exp" + value "cc-exp-month" + value "cc-exp-year" + value "cc-csc" + value "cc-type" + value "transaction-currency" + value "transaction-amount" + value "bday-day" + value "bday-month" + value "bday-year" +} +enum AutoFillContactKind { + value "home" + value "work" + value "mobile" +} +enum AutoFillContactField { + value "tel" + value "tel-country-code" + value "tel-national" + value "tel-area-code" + value "tel-local" + value "tel-local-prefix" + value "tel-local-suffix" + value "tel-extension" + value "email" +} +enum AutoFillCredentialField { + value "webauthn" +} \ No newline at end of file diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index fbc48d8dd..62a55b192 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -373,98 +373,6 @@ // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility "storage-access" ] - }, - "AutoFillBase": { - "name": "AutoFillBase", - "value": [ - // Off - "off", - // Automatic - "on", - "" - ] - }, - "AutoFillAddressKind": { - "name": "AutoFillAddressKind", - "value": [ - "shipping", - "billing" - ] - }, - "AutoFillNormalField": { - "name": "AutoFillNormalField", - "value": [ - "name", - "honorific-prefix", - "given-name", - "additional-name", - "family-name", - "honorific-suffix", - - "username", - "new-password", - "current-password", - // Supported in iOS Safari too even though WPT tests - // for Safari currently fail as of 2023-06. - "one-time-code", - - "organization", - "street-address", - "address-line1", - "address-line2", - "address-line3", - "address-level4", - "address-level3", - "address-level2", - "address-level1", - "country", - "country-name", - "postal-code", - - "cc-name", - "cc-given-name", - "cc-family-name", - "cc-number", - "cc-exp", - "cc-exp-month", - "cc-exp-year", - "cc-csc", - "cc-type", - "transaction-currency", - "transaction-amount", - - "bday-day", - "bday-month", - "bday-year" - ] - }, - "AutoFillContactKind": { - "name": "AutoFillContactKind", - "value": [ - "home", - "work", - "mobile" - ] - }, - "AutoFillContactField": { - "name": "AutoFillContactField", - "value": [ - "tel", - "tel-country-code", - "tel-national", - "tel-area-code", - "tel-local", - "tel-local-prefix", - "tel-local-suffix", - "tel-extension", - "email" - ] - }, - "AutoFillCredentialField": { - "name": "AutoFillCredentialField", - "value": [ - "webauthn" - ] } } }, diff --git a/src/build.ts b/src/build.ts index 27a2509f5..7c2b0d869 100644 --- a/src/build.ts +++ b/src/build.ts @@ -14,6 +14,7 @@ import { getInterfaceToEventMap } from "./build/webref/events.js"; import { getWebidls } from "./build/webref/idl.js"; import jsonc from "jsonc-parser"; import { generateDescriptions } from "./build/mdn-comments.js"; +import readKDL from "./build/utils/kdl.js"; function mergeNamesakes(filtered: Browser.WebIdl) { const targets = [ @@ -97,6 +98,7 @@ async function emitDom() { const deprecatedInfo = await readInputJSON("deprecatedMessage.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); + const addedItemsKDL = await readKDL(inputFolder, "addedTypes.kdl"); async function readInputJSON(filename: string) { const content = await fs.readFile(new URL(filename, inputFolder), "utf8"); @@ -229,6 +231,7 @@ async function emitDom() { webidl = prune(webidl, removedItems); webidl = mergeApiDescriptions(webidl, documentationFromMDN); webidl = merge(webidl, addedItems); + webidl = merge(webidl, addedItemsKDL); webidl = merge(webidl, overriddenItems); webidl = merge(webidl, comments); webidl = mergeDeprecatedMessage(webidl, deprecatedInfo); diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 540eabed2..c9e9935d6 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -1,6 +1,7 @@ import { parse } from "kdljs"; import { Enum, Event, Method, Property } from "../types"; -import { readFile } from "fs/promises"; +import { readdir, readFile } from "fs/promises"; +import { merge } from "../helpers.js"; interface MethodDescriptor { [x: string]: Omit; @@ -103,10 +104,46 @@ export function parseKDL(kdlText: string) { return { mixins: { mixin: interfaces }, enums: { enum: enums } }; } -export default async function readInputKDL( - path: string, + +/** + * Recursively collect all KDL file URLs in a directory. + */ +async function getAllKDLFileURLs(folder: URL, file: string): Promise { + const entries = await readdir(folder, { withFileTypes: true }); + + const results: URL[] = []; + + for (const entry of entries) { + const child = new URL(entry.name + "/", folder); + + if (entry.isDirectory()) { + results.push(...(await getAllKDLFileURLs(child, file))); + } else if (entry.isFile() && entry.name == file) { + results.push(new URL(entry.name, folder)); + } + } + + return results; +} + +/** + * Read and parse a single KDL file. + */ +export async function readInputKDL(fileUrl: URL): Promise { + const text = await readFile(fileUrl, "utf8"); + return parseKDL(text); +} + +/** + * Read, parse, and merge all KDL files under the input folder. + */ +export default async function readKDL( inputFolder: URL, + file: string, ): Promise { - const text = await readFile(new URL(path, inputFolder), "utf8"); - return parseKDL(text); + const fileUrls = await getAllKDLFileURLs(inputFolder, file); + + const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); + + return parsedContents.reduce((acc, current) => merge(acc, current), {}); } From 28cdf7d275cb9fd8557ca1468a4686c4a56b6f57 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Tue, 8 Jul 2025 09:45:14 +0300 Subject: [PATCH 05/32] chore: ignore mdn and idl folders --- src/build/utils/kdl.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index c9e9935d6..f40b65c6b 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -116,7 +116,11 @@ async function getAllKDLFileURLs(folder: URL, file: string): Promise { for (const entry of entries) { const child = new URL(entry.name + "/", folder); - if (entry.isDirectory()) { + if ( + entry.isDirectory() && + !child.pathname.includes("mdn") && + !child.pathname.includes("idl") + ) { results.push(...(await getAllKDLFileURLs(child, file))); } else if (entry.isFile() && entry.name == file) { results.push(new URL(entry.name, folder)); From b68c50883fd367fda38abf7f745ab1624f71ebda Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 9 Jul 2025 06:39:28 +0300 Subject: [PATCH 06/32] Update src/build/utils/kdl.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/utils/kdl.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index f40b65c6b..13122c3e9 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -41,7 +41,10 @@ export function parseKDL(kdlText: string) { for (const node of nodes) { if (node.name === "enum") { // Handle enum - const enumName = node.values?.[0]?.toString() ?? ""; + const enumName = node.values[0]; + if (typeof enumName !== "string") { + throw new Error("Missing enum name"); + } let name = enumName; const values: string[] = []; From 761bc35f78836a61b2a9b6013df4ecf1cda75077 Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 9 Jul 2025 06:39:53 +0300 Subject: [PATCH 07/32] Update src/build/utils/kdl.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/utils/kdl.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 13122c3e9..57aa2d735 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -29,9 +29,7 @@ export function parseKDL(kdlText: string) { const { output, errors } = parse(kdlText); if (errors.length) { - throw new Error( - `KDL parse errors:\n${errors.map((e) => e.message).join("\n")}`, - ); + throw new Error("KDL parse errors", { cause: errors }); } const nodes = output!; From 1aaee0dae3e22078156cb67941e1434883feb1bc Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 9 Jul 2025 06:40:11 +0300 Subject: [PATCH 08/32] Update src/build/utils/kdl.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/utils/kdl.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 57aa2d735..d4b846632 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -22,8 +22,7 @@ interface InterfaceMixin { } /** - * Converts KDL text describing interface-mixins into JSON format. - * Uses kdljs v3. + * Converts patch files in KDL to match the [types](types.d.ts). */ export function parseKDL(kdlText: string) { const { output, errors } = parse(kdlText); From fc238c7039533fe556a73f376c5b413a712ded7b Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 9 Jul 2025 06:40:27 +0300 Subject: [PATCH 09/32] Update src/build/utils/kdl.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/utils/kdl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index d4b846632..4c8dd1c32 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -149,5 +149,5 @@ export default async function readKDL( const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); - return parsedContents.reduce((acc, current) => merge(acc, current), {}); + return parsedContents.reduce(merge, {}); } From 56f7ebf9737d296fa87df7d005e3899fcf3ff7cb Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 9 Jul 2025 06:41:09 +0300 Subject: [PATCH 10/32] Update src/build/utils/kdl.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/utils/kdl.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 4c8dd1c32..9de76ee07 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -46,15 +46,10 @@ export function parseKDL(kdlText: string) { const values: string[] = []; for (const child of node.children ?? []) { - if ( - child.name === "value" && - child.values && - child.values[0] !== undefined - ) { - values.push(child.values[0]!.toString()); - } else if (child.name === "name") { - name = child.values?.[0]?.toString() ?? enumName; + if (child.name !== "value" || typeof child.values[0] !== "string") { + throw new Error("enum values should be in the form of `value {name}`"); } + values.push(child.values[0]); } enums[enumName] = { name, value: values }; From 4f15c5de98eca8f9fe035345b18ea39df1715863 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:04:12 +0300 Subject: [PATCH 11/32] - --- src/build/utils/kdl.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/build/utils/kdl.ts b/src/build/utils/kdl.ts index 9de76ee07..e60c13c4a 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/utils/kdl.ts @@ -42,12 +42,14 @@ export function parseKDL(kdlText: string) { if (typeof enumName !== "string") { throw new Error("Missing enum name"); } - let name = enumName; + const name = enumName; const values: string[] = []; for (const child of node.children ?? []) { if (child.name !== "value" || typeof child.values[0] !== "string") { - throw new Error("enum values should be in the form of `value {name}`"); + throw new Error( + "enum values should be in the form of `value {name}`", + ); } values.push(child.values[0]); } @@ -144,5 +146,5 @@ export default async function readKDL( const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); - return parsedContents.reduce(merge, {}); + return parsedContents.reduce((acc, current) => merge(acc, current), {}); } From 4625aa4603d72fafd0926fd4f81da48d9d97db17 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:05:52 +0300 Subject: [PATCH 12/32] chore: rename --- src/build.ts | 2 +- src/build/{utils/kdl.ts => patches.ts} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/build/{utils/kdl.ts => patches.ts} (97%) diff --git a/src/build.ts b/src/build.ts index 7c2b0d869..09258ed6b 100644 --- a/src/build.ts +++ b/src/build.ts @@ -14,7 +14,7 @@ import { getInterfaceToEventMap } from "./build/webref/events.js"; import { getWebidls } from "./build/webref/idl.js"; import jsonc from "jsonc-parser"; import { generateDescriptions } from "./build/mdn-comments.js"; -import readKDL from "./build/utils/kdl.js"; +import readKDL from "./build/patches.js"; function mergeNamesakes(filtered: Browser.WebIdl) { const targets = [ diff --git a/src/build/utils/kdl.ts b/src/build/patches.ts similarity index 97% rename from src/build/utils/kdl.ts rename to src/build/patches.ts index e60c13c4a..4fb3ef251 100644 --- a/src/build/utils/kdl.ts +++ b/src/build/patches.ts @@ -1,7 +1,7 @@ import { parse } from "kdljs"; -import { Enum, Event, Method, Property } from "../types"; +import { Enum, Event, Method, Property } from "./types"; import { readdir, readFile } from "fs/promises"; -import { merge } from "../helpers.js"; +import { merge } from "./helpers.js"; interface MethodDescriptor { [x: string]: Omit; From 3f1bd04a811866662c58cd99ba585bfbe7e948b7 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:09:03 +0300 Subject: [PATCH 13/32] chore: create patches folder --- inputfiles/{ => patches}/AutoFill/addedTypes.kdl | 0 src/build.ts | 2 +- src/build/patches.ts | 12 +++--------- 3 files changed, 4 insertions(+), 10 deletions(-) rename inputfiles/{ => patches}/AutoFill/addedTypes.kdl (100%) diff --git a/inputfiles/AutoFill/addedTypes.kdl b/inputfiles/patches/AutoFill/addedTypes.kdl similarity index 100% rename from inputfiles/AutoFill/addedTypes.kdl rename to inputfiles/patches/AutoFill/addedTypes.kdl diff --git a/src/build.ts b/src/build.ts index 09258ed6b..e86d5c545 100644 --- a/src/build.ts +++ b/src/build.ts @@ -98,7 +98,7 @@ async function emitDom() { const deprecatedInfo = await readInputJSON("deprecatedMessage.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); - const addedItemsKDL = await readKDL(inputFolder, "addedTypes.kdl"); + const addedItemsKDL = await readKDL("addedTypes.kdl"); async function readInputJSON(filename: string) { const content = await fs.readFile(new URL(filename, inputFolder), "utf8"); diff --git a/src/build/patches.ts b/src/build/patches.ts index 4fb3ef251..c07a924c7 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -113,11 +113,7 @@ async function getAllKDLFileURLs(folder: URL, file: string): Promise { for (const entry of entries) { const child = new URL(entry.name + "/", folder); - if ( - entry.isDirectory() && - !child.pathname.includes("mdn") && - !child.pathname.includes("idl") - ) { + if (entry.isDirectory()) { results.push(...(await getAllKDLFileURLs(child, file))); } else if (entry.isFile() && entry.name == file) { results.push(new URL(entry.name, folder)); @@ -138,10 +134,8 @@ export async function readInputKDL(fileUrl: URL): Promise { /** * Read, parse, and merge all KDL files under the input folder. */ -export default async function readKDL( - inputFolder: URL, - file: string, -): Promise { +export default async function readKDL(file: string): Promise { + const inputFolder = new URL("../inputfiles/patches/", import.meta.url); const fileUrls = await getAllKDLFileURLs(inputFolder, file); const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); From 97e5390ad13a1bd13cca459542fb865403bcb548 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:11:28 +0300 Subject: [PATCH 14/32] patch: rename url --- src/build/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index c07a924c7..349e09222 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -135,7 +135,7 @@ export async function readInputKDL(fileUrl: URL): Promise { * Read, parse, and merge all KDL files under the input folder. */ export default async function readKDL(file: string): Promise { - const inputFolder = new URL("../inputfiles/patches/", import.meta.url); + const inputFolder = new URL("../../inputfiles/patches/", import.meta.url); const fileUrls = await getAllKDLFileURLs(inputFolder, file); const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); From 4c85911d4e763957c2fb50044391f9c2e7b6532d Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:13:07 +0300 Subject: [PATCH 15/32] - --- src/build/patches.ts | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 349e09222..e785606ea 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -55,47 +55,6 @@ export function parseKDL(kdlText: string) { } enums[enumName] = { name, value: values }; - } else { - // Handle interface-mixin - const name = node.values?.[0]?.toString() ?? ""; - const iface: { - events?: { event: Event[] }; - methods?: { method: MethodDescriptor }; - properties?: { property: PropertyDescriptor }; - } = {}; - - const events: Event[] = []; - const methods: MethodDescriptor = {}; - const properties: PropertyDescriptor = {}; - - for (const child of node.children ?? []) { - const name = child.values?.[0]?.toString() ?? ""; - if (child.name === "event") { - events.push({ - name, - type: child.properties?.type?.toString() ?? "", - }); - } else if (child.name === "method") { - methods[name] = { - name, - overrideSignatures: [ - child.properties?.overrideSignatures?.toString() ?? "", - ], - }; - } else if (child.name === "property") { - properties[name] = { - name, - exposed: child.properties?.exposed?.toString(), - }; - } - } - - if (events.length) iface.events = { event: events }; - if (Object.keys(methods).length) iface.methods = { method: methods }; - if (Object.keys(properties).length) - iface.properties = { property: properties }; - - interfaces[name] = iface; } } From 16c4f1458a21ca43f08ffa250100ee738b5f593e Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 11:20:02 +0300 Subject: [PATCH 16/32] KDL parser --- src/build/patches.ts | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index e785606ea..821d985f9 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -1,25 +1,11 @@ import { parse } from "kdljs"; -import { Enum, Event, Method, Property } from "./types"; +import { Enum } from "./types"; import { readdir, readFile } from "fs/promises"; import { merge } from "./helpers.js"; -interface MethodDescriptor { - [x: string]: Omit; -} - interface EnumDescriptor { [x: string]: Enum; } -interface PropertyDescriptor { - [x: string]: Omit; -} - -interface InterfaceMixin { - [x: string]: { - events?: { event: Event[] }; - methods?: { method: MethodDescriptor }; - }; -} /** * Converts patch files in KDL to match the [types](types.d.ts). @@ -33,7 +19,6 @@ export function parseKDL(kdlText: string) { const nodes = output!; const enums: EnumDescriptor = {}; - const interfaces: InterfaceMixin = {}; for (const node of nodes) { if (node.name === "enum") { @@ -58,7 +43,7 @@ export function parseKDL(kdlText: string) { } } - return { mixins: { mixin: interfaces }, enums: { enum: enums } }; + return { enums: { enum: enums } }; } /** From 2d3d3e4f61fcc6f7ac57cb932652df65e0c896a4 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Wed, 9 Jul 2025 13:58:38 +0300 Subject: [PATCH 17/32] - --- .../addedTypes.kdl => autoFills.kdl} | 0 src/build.ts | 2 +- src/build/patches.ts | 23 ++++--------------- 3 files changed, 6 insertions(+), 19 deletions(-) rename inputfiles/patches/{AutoFill/addedTypes.kdl => autoFills.kdl} (100%) diff --git a/inputfiles/patches/AutoFill/addedTypes.kdl b/inputfiles/patches/autoFills.kdl similarity index 100% rename from inputfiles/patches/AutoFill/addedTypes.kdl rename to inputfiles/patches/autoFills.kdl diff --git a/src/build.ts b/src/build.ts index e86d5c545..594dba9e4 100644 --- a/src/build.ts +++ b/src/build.ts @@ -98,7 +98,7 @@ async function emitDom() { const deprecatedInfo = await readInputJSON("deprecatedMessage.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); - const addedItemsKDL = await readKDL("addedTypes.kdl"); + const addedItemsKDL = await readKDL("patches"); async function readInputJSON(filename: string) { const content = await fs.readFile(new URL(filename, inputFolder), "utf8"); diff --git a/src/build/patches.ts b/src/build/patches.ts index 821d985f9..35909ba12 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -49,22 +49,9 @@ export function parseKDL(kdlText: string) { /** * Recursively collect all KDL file URLs in a directory. */ -async function getAllKDLFileURLs(folder: URL, file: string): Promise { +async function getAllKDLFileURLs(folder: URL): Promise { const entries = await readdir(folder, { withFileTypes: true }); - - const results: URL[] = []; - - for (const entry of entries) { - const child = new URL(entry.name + "/", folder); - - if (entry.isDirectory()) { - results.push(...(await getAllKDLFileURLs(child, file))); - } else if (entry.isFile() && entry.name == file) { - results.push(new URL(entry.name, folder)); - } - } - - return results; + return entries.map((entry) => new URL(entry.name, folder)); } /** @@ -78,9 +65,9 @@ export async function readInputKDL(fileUrl: URL): Promise { /** * Read, parse, and merge all KDL files under the input folder. */ -export default async function readKDL(file: string): Promise { - const inputFolder = new URL("../../inputfiles/patches/", import.meta.url); - const fileUrls = await getAllKDLFileURLs(inputFolder, file); +export default async function readKDL(folder: string): Promise { + const inputFolder = new URL(`../../inputfiles/${folder}/`, import.meta.url); + const fileUrls = await getAllKDLFileURLs(inputFolder); const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); From da909afa81819b96b009607f6ca98906cc34668f Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 07:51:44 +0300 Subject: [PATCH 18/32] feat: rename --- src/build.ts | 4 ++-- src/build/patches.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/build.ts b/src/build.ts index 594dba9e4..ce7c4daf1 100644 --- a/src/build.ts +++ b/src/build.ts @@ -14,7 +14,7 @@ import { getInterfaceToEventMap } from "./build/webref/events.js"; import { getWebidls } from "./build/webref/idl.js"; import jsonc from "jsonc-parser"; import { generateDescriptions } from "./build/mdn-comments.js"; -import readKDL from "./build/patches.js"; +import readPatches from "./build/patches.js"; function mergeNamesakes(filtered: Browser.WebIdl) { const targets = [ @@ -98,7 +98,7 @@ async function emitDom() { const deprecatedInfo = await readInputJSON("deprecatedMessage.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); - const addedItemsKDL = await readKDL("patches"); + const addedItemsKDL = await readPatches(); async function readInputJSON(filename: string) { const content = await fs.readFile(new URL(filename, inputFolder), "utf8"); diff --git a/src/build/patches.ts b/src/build/patches.ts index 35909ba12..384a6fbda 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -57,7 +57,7 @@ async function getAllKDLFileURLs(folder: URL): Promise { /** * Read and parse a single KDL file. */ -export async function readInputKDL(fileUrl: URL): Promise { +export async function readPatch(fileUrl: URL): Promise { const text = await readFile(fileUrl, "utf8"); return parseKDL(text); } @@ -65,11 +65,11 @@ export async function readInputKDL(fileUrl: URL): Promise { /** * Read, parse, and merge all KDL files under the input folder. */ -export default async function readKDL(folder: string): Promise { - const inputFolder = new URL(`../../inputfiles/${folder}/`, import.meta.url); +export default async function readPatches(): Promise { + const inputFolder = new URL("../../inputfiles/patches/", import.meta.url); const fileUrls = await getAllKDLFileURLs(inputFolder); - const parsedContents = await Promise.all(fileUrls.map(readInputKDL)); + const parsedContents = await Promise.all(fileUrls.map(readPatch)); return parsedContents.reduce((acc, current) => merge(acc, current), {}); } From 3e236c4550d811ec777379069416399b90007b8b Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:06:45 +0300 Subject: [PATCH 19/32] chore: remove EnumDescriptor --- src/build/patches.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 384a6fbda..34ca9b565 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -3,10 +3,6 @@ import { Enum } from "./types"; import { readdir, readFile } from "fs/promises"; import { merge } from "./helpers.js"; -interface EnumDescriptor { - [x: string]: Enum; -} - /** * Converts patch files in KDL to match the [types](types.d.ts). */ @@ -18,7 +14,7 @@ export function parseKDL(kdlText: string) { } const nodes = output!; - const enums: EnumDescriptor = {}; + const enums: Record = {}; for (const node of nodes) { if (node.name === "enum") { From 1f4e523c91f748bb7e635e9e2df183316400d2e0 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:14:58 +0300 Subject: [PATCH 20/32] chore: remove an extra variable --- src/build/patches.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 34ca9b565..6c11dabe8 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -23,7 +23,6 @@ export function parseKDL(kdlText: string) { if (typeof enumName !== "string") { throw new Error("Missing enum name"); } - const name = enumName; const values: string[] = []; for (const child of node.children ?? []) { @@ -35,7 +34,7 @@ export function parseKDL(kdlText: string) { values.push(child.values[0]); } - enums[enumName] = { name, value: values }; + enums[enumName] = { name:enumName, value: values }; } } From c9c4eee181bfe340a02abcd4e9e9363ac2a65e22 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:15:49 +0300 Subject: [PATCH 21/32] rename --- src/build/patches.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 6c11dabe8..0e7efb6a3 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -61,8 +61,8 @@ export async function readPatch(fileUrl: URL): Promise { * Read, parse, and merge all KDL files under the input folder. */ export default async function readPatches(): Promise { - const inputFolder = new URL("../../inputfiles/patches/", import.meta.url); - const fileUrls = await getAllKDLFileURLs(inputFolder); + const patchDirectory = new URL("../../inputfiles/patches/", import.meta.url); + const fileUrls = await getAllKDLFileURLs(patchDirectory); const parsedContents = await Promise.all(fileUrls.map(readPatch)); From f69385edbdb95d29cf022ec758c24dd076e614e5 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:16:52 +0300 Subject: [PATCH 22/32] rename --- src/build/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 0e7efb6a3..1f29f5a39 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -42,7 +42,7 @@ export function parseKDL(kdlText: string) { } /** - * Recursively collect all KDL file URLs in a directory. + * Collect all file URLs in a directory. */ async function getAllKDLFileURLs(folder: URL): Promise { const entries = await readdir(folder, { withFileTypes: true }); From 721318086880d2bae77a794b42f222a4954bb859 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:18:57 +0300 Subject: [PATCH 23/32] lint --- src/build/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 1f29f5a39..8c8a2fd32 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -34,7 +34,7 @@ export function parseKDL(kdlText: string) { values.push(child.values[0]); } - enums[enumName] = { name:enumName, value: values }; + enums[enumName] = { name: enumName, value: values }; } } From a5176a72185a5d3f7c21f265d213fa4805043d34 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:21:49 +0300 Subject: [PATCH 24/32] rename --- src/build/patches.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 8c8a2fd32..90bccfb99 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -19,8 +19,8 @@ export function parseKDL(kdlText: string) { for (const node of nodes) { if (node.name === "enum") { // Handle enum - const enumName = node.values[0]; - if (typeof enumName !== "string") { + const name = node.values[0]; + if (typeof name !== "string") { throw new Error("Missing enum name"); } const values: string[] = []; @@ -34,7 +34,7 @@ export function parseKDL(kdlText: string) { values.push(child.values[0]); } - enums[enumName] = { name: enumName, value: values }; + enums[name] = { name, value: values }; } } From b056cf19cd48c5d8f1afe8ee58ed4672b9490c07 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Thu, 10 Jul 2025 11:29:53 +0300 Subject: [PATCH 25/32] split into smaller functions --- src/build/patches.ts | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 90bccfb99..b2f389d71 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -18,27 +18,34 @@ export function parseKDL(kdlText: string) { for (const node of nodes) { if (node.name === "enum") { - // Handle enum - const name = node.values[0]; - if (typeof name !== "string") { - throw new Error("Missing enum name"); - } - const values: string[] = []; + handleEnum(node, enums); + } + } - for (const child of node.children ?? []) { - if (child.name !== "value" || typeof child.values[0] !== "string") { - throw new Error( - "enum values should be in the form of `value {name}`", - ); - } - values.push(child.values[0]); - } + return { enums: { enum: enums } }; +} - enums[name] = { name, value: values }; +/** + * Handles an enum node by extracting its name and values. + * Throws an error if the enum name is missing or if the values are not in the correct format. + * @param node The enum node to handle. + * @param enums The record of enums to update. + */ +function handleEnum(node: any, enums: Record) { + const name = node.values[0]; + if (typeof name !== "string") { + throw new Error("Missing enum name"); + } + const values: string[] = []; + + for (const child of node.children ?? []) { + if (child.name !== "value" || typeof child.values[0] !== "string") { + throw new Error("enum values should be in the form of `value {name}`"); } + values.push(child.values[0]); } - return { enums: { enum: enums } }; + enums[name] = { name, value: values }; } /** From 609c174dbdaedf750ff4e4652cae6b2d940cfca2 Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:37:18 +0300 Subject: [PATCH 26/32] Update src/build/patches.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index b2f389d71..b84926c51 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -1,5 +1,5 @@ import { parse } from "kdljs"; -import { Enum } from "./types"; +import type { Enum } from "./types"; import { readdir, readFile } from "fs/promises"; import { merge } from "./helpers.js"; From 72303fdfcff2d70f84d7208ca804e0dbdd24ff5a Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:37:45 +0300 Subject: [PATCH 27/32] Update src/build/patches.ts Co-authored-by: Kagami Sascha Rosylight --- src/build/patches.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index b84926c51..de0078c33 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -6,7 +6,7 @@ import { merge } from "./helpers.js"; /** * Converts patch files in KDL to match the [types](types.d.ts). */ -export function parseKDL(kdlText: string) { +function parseKDL(kdlText: string) { const { output, errors } = parse(kdlText); if (errors.length) { From 25520323cab17b972afc508d2ef3131e036d9207 Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:56:02 +0300 Subject: [PATCH 28/32] Integrate more enums * feat: FontDisplay * rename * feat: InsertPosition * feat: RTCStatsIceCandidatePairState * feat: GlobalCompositeOperation * PermissionName * - * Delete inputfiles/patches/imageOrientation.kdl --- inputfiles/addedTypes.jsonc | 82 ------------------- inputfiles/overridingTypes.jsonc | 8 -- inputfiles/patches/ImageOrientation.kdl | 3 + .../patches/RTCStatsIceCandidatePairState.kdl | 3 + inputfiles/patches/fontDisplay.kdl | 8 ++ .../patches/globalCompositeOperation.kdl | 28 +++++++ inputfiles/patches/insertPosition.kdl | 6 ++ inputfiles/patches/permissionName.kdl | 23 ++++++ 8 files changed, 71 insertions(+), 90 deletions(-) create mode 100644 inputfiles/patches/ImageOrientation.kdl create mode 100644 inputfiles/patches/RTCStatsIceCandidatePairState.kdl create mode 100644 inputfiles/patches/fontDisplay.kdl create mode 100644 inputfiles/patches/globalCompositeOperation.kdl create mode 100644 inputfiles/patches/insertPosition.kdl create mode 100644 inputfiles/patches/permissionName.kdl diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 62a55b192..d8484156f 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -289,90 +289,8 @@ }, "enums": { "enum": { - "InsertPosition": { - "name": "InsertPosition", - "value": [ - "beforebegin", - "beforeend", - "afterbegin", - "afterend" - ] - }, - "FontDisplay": { - "name": "FontDisplay", - // https://w3c.github.io/csswg-drafts/css-fonts-4/#font-display-desc - "value": [ - "auto", - "block", - "swap", - "fallback", - "optional" - ] - }, "ClientType": { "name": "ClientTypes" - }, - "RTCStatsIceCandidatePairState": { - "value": [ - "inprogress" - ] - }, - "GlobalCompositeOperation": { - "name": "GlobalCompositeOperation", - "value": [ - "source-over", - "source-in", - "source-out", - "source-atop", - "destination-over", - "destination-in", - "destination-out", - "destination-atop", - "lighter", - "copy", - "xor", - "multiply", - "screen", - "overlay", - "darken", - "lighten", - "color-dodge", - "color-burn", - "hard-light", - "soft-light", - "difference", - "exclusion", - "hue", - "saturation", - "color", - "luminosity" - ] - }, - "PermissionName": { - "name": "PermissionName", - // This is a subset of the permissions defined in the spec: - // https://w3c.github.io/powerful-features-registry/#registry-table-of-powerful-features - // Please add a feature only when it's supported by multiple engines. - "value": [ - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility - "camera", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API#browser_compatibility - "geolocation", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility - "microphone", - // Gecko and Blink: https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API#browser_compatibility - "midi", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API#browser_compatibility - "notifications", - // Gecko and Blink: https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#browser_compatibility - "persistent-storage", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Push_API#browser_compatibility - "push", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API#browser_compatibility - "screen-wake-lock", - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - "storage-access" - ] } } }, diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 1b9559938..2c7f7e820 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -504,14 +504,6 @@ }, "TableKind": { "legacyNamespace": "WebAssembly" - }, - "ImageOrientation": { - "value": [ - // The spec removed this but it's still in browsers and WebKit doesn't support the new one. - // Keep it until it's safer to fully migrate. - // See https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1507#issuecomment-1454792451 - "none" - ] } } }, diff --git a/inputfiles/patches/ImageOrientation.kdl b/inputfiles/patches/ImageOrientation.kdl new file mode 100644 index 000000000..fee446280 --- /dev/null +++ b/inputfiles/patches/ImageOrientation.kdl @@ -0,0 +1,3 @@ +enum ImageOrientation { + value "none" +} \ No newline at end of file diff --git a/inputfiles/patches/RTCStatsIceCandidatePairState.kdl b/inputfiles/patches/RTCStatsIceCandidatePairState.kdl new file mode 100644 index 000000000..6d5fbe4d4 --- /dev/null +++ b/inputfiles/patches/RTCStatsIceCandidatePairState.kdl @@ -0,0 +1,3 @@ +enum RTCStatsIceCandidatePairState { + value "inprogress" +} \ No newline at end of file diff --git a/inputfiles/patches/fontDisplay.kdl b/inputfiles/patches/fontDisplay.kdl new file mode 100644 index 000000000..97ad55e49 --- /dev/null +++ b/inputfiles/patches/fontDisplay.kdl @@ -0,0 +1,8 @@ +enum FontDisplay { + // https://w3c.github.io/csswg-drafts/css-fonts-4/#font-display-desc + value "auto" + value "block" + value "swap" + value "fallback" + value "optional" +} \ No newline at end of file diff --git a/inputfiles/patches/globalCompositeOperation.kdl b/inputfiles/patches/globalCompositeOperation.kdl new file mode 100644 index 000000000..f3528f8bb --- /dev/null +++ b/inputfiles/patches/globalCompositeOperation.kdl @@ -0,0 +1,28 @@ +enum GlobalCompositeOperation { + value "source-over" + value "source-in" + value "source-out" + value "source-atop" + value "destination-over" + value "destination-in" + value "destination-out" + value "destination-atop" + value "lighter" + value "copy" + value "xor" + value "multiply" + value "screen" + value "overlay" + value "darken" + value "lighten" + value "color-dodge" + value "color-burn" + value "hard-light" + value "soft-light" + value "difference" + value "exclusion" + value "hue" + value "saturation" + value "color" + value "luminosity" +} \ No newline at end of file diff --git a/inputfiles/patches/insertPosition.kdl b/inputfiles/patches/insertPosition.kdl new file mode 100644 index 000000000..c08b9af86 --- /dev/null +++ b/inputfiles/patches/insertPosition.kdl @@ -0,0 +1,6 @@ +enum InsertPosition { + value "beforebegin" + value "beforeend" + value "afterbegin" + value "afterend" +} \ No newline at end of file diff --git a/inputfiles/patches/permissionName.kdl b/inputfiles/patches/permissionName.kdl new file mode 100644 index 000000000..b0b62596c --- /dev/null +++ b/inputfiles/patches/permissionName.kdl @@ -0,0 +1,23 @@ +enum PermissionName { + // This is a subset of the permissions defined in the spec: + // https://w3c.github.io/powerful-features-registry/#registry-table-of-powerful-features + // Please add a feature only when it's supported by multiple engines. + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "camera" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "geolocation" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "microphone" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "midi" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "notifications" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "persistent-storage" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "push" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "screen-wake-lock" + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + value "storage-access" +} \ No newline at end of file From 4d1ab0f6b71ce00e3ab9f4220637e57f4b717eb0 Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Fri, 11 Jul 2025 14:52:35 +0300 Subject: [PATCH 29/32] Revert "Integrate more enums" (#3) This reverts commit 25520323cab17b972afc508d2ef3131e036d9207. --- inputfiles/addedTypes.jsonc | 82 +++++++++++++++++++ inputfiles/overridingTypes.jsonc | 8 ++ inputfiles/patches/ImageOrientation.kdl | 3 - .../patches/RTCStatsIceCandidatePairState.kdl | 3 - inputfiles/patches/fontDisplay.kdl | 8 -- .../patches/globalCompositeOperation.kdl | 28 ------- inputfiles/patches/insertPosition.kdl | 6 -- inputfiles/patches/permissionName.kdl | 23 ------ 8 files changed, 90 insertions(+), 71 deletions(-) delete mode 100644 inputfiles/patches/ImageOrientation.kdl delete mode 100644 inputfiles/patches/RTCStatsIceCandidatePairState.kdl delete mode 100644 inputfiles/patches/fontDisplay.kdl delete mode 100644 inputfiles/patches/globalCompositeOperation.kdl delete mode 100644 inputfiles/patches/insertPosition.kdl delete mode 100644 inputfiles/patches/permissionName.kdl diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index d8484156f..62a55b192 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -289,8 +289,90 @@ }, "enums": { "enum": { + "InsertPosition": { + "name": "InsertPosition", + "value": [ + "beforebegin", + "beforeend", + "afterbegin", + "afterend" + ] + }, + "FontDisplay": { + "name": "FontDisplay", + // https://w3c.github.io/csswg-drafts/css-fonts-4/#font-display-desc + "value": [ + "auto", + "block", + "swap", + "fallback", + "optional" + ] + }, "ClientType": { "name": "ClientTypes" + }, + "RTCStatsIceCandidatePairState": { + "value": [ + "inprogress" + ] + }, + "GlobalCompositeOperation": { + "name": "GlobalCompositeOperation", + "value": [ + "source-over", + "source-in", + "source-out", + "source-atop", + "destination-over", + "destination-in", + "destination-out", + "destination-atop", + "lighter", + "copy", + "xor", + "multiply", + "screen", + "overlay", + "darken", + "lighten", + "color-dodge", + "color-burn", + "hard-light", + "soft-light", + "difference", + "exclusion", + "hue", + "saturation", + "color", + "luminosity" + ] + }, + "PermissionName": { + "name": "PermissionName", + // This is a subset of the permissions defined in the spec: + // https://w3c.github.io/powerful-features-registry/#registry-table-of-powerful-features + // Please add a feature only when it's supported by multiple engines. + "value": [ + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility + "camera", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API#browser_compatibility + "geolocation", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility + "microphone", + // Gecko and Blink: https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API#browser_compatibility + "midi", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API#browser_compatibility + "notifications", + // Gecko and Blink: https://developer.mozilla.org/en-US/docs/Web/API/Storage_API#browser_compatibility + "persistent-storage", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Push_API#browser_compatibility + "push", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API#browser_compatibility + "screen-wake-lock", + // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility + "storage-access" + ] } } }, diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 2c7f7e820..1b9559938 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -504,6 +504,14 @@ }, "TableKind": { "legacyNamespace": "WebAssembly" + }, + "ImageOrientation": { + "value": [ + // The spec removed this but it's still in browsers and WebKit doesn't support the new one. + // Keep it until it's safer to fully migrate. + // See https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1507#issuecomment-1454792451 + "none" + ] } } }, diff --git a/inputfiles/patches/ImageOrientation.kdl b/inputfiles/patches/ImageOrientation.kdl deleted file mode 100644 index fee446280..000000000 --- a/inputfiles/patches/ImageOrientation.kdl +++ /dev/null @@ -1,3 +0,0 @@ -enum ImageOrientation { - value "none" -} \ No newline at end of file diff --git a/inputfiles/patches/RTCStatsIceCandidatePairState.kdl b/inputfiles/patches/RTCStatsIceCandidatePairState.kdl deleted file mode 100644 index 6d5fbe4d4..000000000 --- a/inputfiles/patches/RTCStatsIceCandidatePairState.kdl +++ /dev/null @@ -1,3 +0,0 @@ -enum RTCStatsIceCandidatePairState { - value "inprogress" -} \ No newline at end of file diff --git a/inputfiles/patches/fontDisplay.kdl b/inputfiles/patches/fontDisplay.kdl deleted file mode 100644 index 97ad55e49..000000000 --- a/inputfiles/patches/fontDisplay.kdl +++ /dev/null @@ -1,8 +0,0 @@ -enum FontDisplay { - // https://w3c.github.io/csswg-drafts/css-fonts-4/#font-display-desc - value "auto" - value "block" - value "swap" - value "fallback" - value "optional" -} \ No newline at end of file diff --git a/inputfiles/patches/globalCompositeOperation.kdl b/inputfiles/patches/globalCompositeOperation.kdl deleted file mode 100644 index f3528f8bb..000000000 --- a/inputfiles/patches/globalCompositeOperation.kdl +++ /dev/null @@ -1,28 +0,0 @@ -enum GlobalCompositeOperation { - value "source-over" - value "source-in" - value "source-out" - value "source-atop" - value "destination-over" - value "destination-in" - value "destination-out" - value "destination-atop" - value "lighter" - value "copy" - value "xor" - value "multiply" - value "screen" - value "overlay" - value "darken" - value "lighten" - value "color-dodge" - value "color-burn" - value "hard-light" - value "soft-light" - value "difference" - value "exclusion" - value "hue" - value "saturation" - value "color" - value "luminosity" -} \ No newline at end of file diff --git a/inputfiles/patches/insertPosition.kdl b/inputfiles/patches/insertPosition.kdl deleted file mode 100644 index c08b9af86..000000000 --- a/inputfiles/patches/insertPosition.kdl +++ /dev/null @@ -1,6 +0,0 @@ -enum InsertPosition { - value "beforebegin" - value "beforeend" - value "afterbegin" - value "afterend" -} \ No newline at end of file diff --git a/inputfiles/patches/permissionName.kdl b/inputfiles/patches/permissionName.kdl deleted file mode 100644 index b0b62596c..000000000 --- a/inputfiles/patches/permissionName.kdl +++ /dev/null @@ -1,23 +0,0 @@ -enum PermissionName { - // This is a subset of the permissions defined in the spec: - // https://w3c.github.io/powerful-features-registry/#registry-table-of-powerful-features - // Please add a feature only when it's supported by multiple engines. - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "camera" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "geolocation" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "microphone" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "midi" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "notifications" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "persistent-storage" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "push" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "screen-wake-lock" - // Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility - value "storage-access" -} \ No newline at end of file From 811a21761eb8c5a9edbecdd81eeb2fe7e65800c1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 12 Jul 2025 11:49:55 +0200 Subject: [PATCH 30/32] Update patches.ts --- src/build/patches.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index de0078c33..b2875f6b2 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -39,10 +39,7 @@ function handleEnum(node: any, enums: Record) { const values: string[] = []; for (const child of node.children ?? []) { - if (child.name !== "value" || typeof child.values[0] !== "string") { - throw new Error("enum values should be in the form of `value {name}`"); - } - values.push(child.values[0]); + values.push(child.name); } enums[name] = { name, value: values }; @@ -51,7 +48,7 @@ function handleEnum(node: any, enums: Record) { /** * Collect all file URLs in a directory. */ -async function getAllKDLFileURLs(folder: URL): Promise { +async function getAllFileURLs(folder: URL): Promise { const entries = await readdir(folder, { withFileTypes: true }); return entries.map((entry) => new URL(entry.name, folder)); } @@ -69,7 +66,7 @@ export async function readPatch(fileUrl: URL): Promise { */ export default async function readPatches(): Promise { const patchDirectory = new URL("../../inputfiles/patches/", import.meta.url); - const fileUrls = await getAllKDLFileURLs(patchDirectory); + const fileUrls = await getAllFileURLs(patchDirectory); const parsedContents = await Promise.all(fileUrls.map(readPatch)); From e7e259791b31ef4df1842c7e195fd1434da8988a Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 12 Jul 2025 11:50:22 +0200 Subject: [PATCH 31/32] Update and rename autoFills.kdl to autocomplete.kdl --- inputfiles/patches/autoFills.kdl | 70 --------------------------- inputfiles/patches/autocomplete.kdl | 74 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 70 deletions(-) delete mode 100644 inputfiles/patches/autoFills.kdl create mode 100644 inputfiles/patches/autocomplete.kdl diff --git a/inputfiles/patches/autoFills.kdl b/inputfiles/patches/autoFills.kdl deleted file mode 100644 index 4ea04c792..000000000 --- a/inputfiles/patches/autoFills.kdl +++ /dev/null @@ -1,70 +0,0 @@ -enum AutoFillBase { - // Off - value "off" - // Automatic - value "on" - value "" -} -enum AutoFillAddressKind { - value "shipping" - value "billing" -} -enum AutoFillNormalField { - value "name" - value "honorific-prefix" - value "given-name" - value "additional-name" - value "family-name" - value "honorific-suffix" - value "username" - value "new-password" - value "current-password" - // Supported in iOS Safari too even though WPT tests - // for Safari currently fail as of 2023-06. - value "one-time-code" - value "organization" - value "street-address" - value "address-line1" - value "address-line2" - value "address-line3" - value "address-level4" - value "address-level3" - value "address-level2" - value "address-level1" - value "country" - value "country-name" - value "postal-code" - value "cc-name" - value "cc-given-name" - value "cc-family-name" - value "cc-number" - value "cc-exp" - value "cc-exp-month" - value "cc-exp-year" - value "cc-csc" - value "cc-type" - value "transaction-currency" - value "transaction-amount" - value "bday-day" - value "bday-month" - value "bday-year" -} -enum AutoFillContactKind { - value "home" - value "work" - value "mobile" -} -enum AutoFillContactField { - value "tel" - value "tel-country-code" - value "tel-national" - value "tel-area-code" - value "tel-local" - value "tel-local-prefix" - value "tel-local-suffix" - value "tel-extension" - value "email" -} -enum AutoFillCredentialField { - value "webauthn" -} \ No newline at end of file diff --git a/inputfiles/patches/autocomplete.kdl b/inputfiles/patches/autocomplete.kdl new file mode 100644 index 000000000..a73f49aac --- /dev/null +++ b/inputfiles/patches/autocomplete.kdl @@ -0,0 +1,74 @@ +enum AutoFillBase { + // Off + off + // Automatic + on + "" +} +enum AutoFillAddressKind { + shipping + billing +} +enum AutoFillNormalField { + name + honorific-prefix + given-name + additional-name + family-name + honorific-suffix + + username + new-password + current-password + // Supported in iOS Safari too even though WPT tests + // for Safari currently fail as of 2023-06. + one-time-code + + organization + street-address + address-line1 + address-line2 + address-line3 + address-level4 + address-level3 + address-level2 + address-level1 + country + country-name + postal-code + + cc-name + cc-given-name + cc-family-name + cc-number + cc-exp + cc-exp-month + cc-exp-year + cc-csc + cc-type + transaction-currency + transaction-amount + + bday-day + bday-month + bday-year +} +enum AutoFillContactKind { + home + work + mobile +} +enum AutoFillContactField { + tel + tel-country-code + tel-national + tel-area-code + tel-local + tel-local-prefix + tel-local-suffix + tel-extension + email +} +enum AutoFillCredentialField { + webauthn +} From 7ff687c85c699da3261c265a08313b2ce2d9f1f1 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 12 Jul 2025 11:55:01 +0200 Subject: [PATCH 32/32] Update build.ts --- src/build.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build.ts b/src/build.ts index ce7c4daf1..533d4cc26 100644 --- a/src/build.ts +++ b/src/build.ts @@ -94,11 +94,11 @@ async function emitDom() { const overriddenItems = await readInputJSON("overridingTypes.jsonc"); const addedItems = await readInputJSON("addedTypes.jsonc"); + const patches = await readPatches(); const comments = await readInputJSON("comments.json"); const deprecatedInfo = await readInputJSON("deprecatedMessage.json"); const documentationFromMDN = await generateDescriptions(); const removedItems = await readInputJSON("removedTypes.jsonc"); - const addedItemsKDL = await readPatches(); async function readInputJSON(filename: string) { const content = await fs.readFile(new URL(filename, inputFolder), "utf8"); @@ -231,8 +231,8 @@ async function emitDom() { webidl = prune(webidl, removedItems); webidl = mergeApiDescriptions(webidl, documentationFromMDN); webidl = merge(webidl, addedItems); - webidl = merge(webidl, addedItemsKDL); webidl = merge(webidl, overriddenItems); + webidl = merge(webidl, patches); webidl = merge(webidl, comments); webidl = mergeDeprecatedMessage(webidl, deprecatedInfo); for (const name in webidl.interfaces!.interface) {