From f73b23b211d4934be178f37b02202aa8af9daeca Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 28 Dec 2025 14:19:54 +0200 Subject: [PATCH 1/5] Support types in KDL --- inputfiles/addedTypes.jsonc | 9 --------- inputfiles/patches/indexeddb.kdl | 10 ++++++++++ inputfiles/patches/webassembly.kdl | 5 +++++ src/build/patches.ts | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index e377c9546..7c7dd0b34 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -476,10 +476,6 @@ "additionalTypes": ["Headers"], "name": "HeadersInit" }, - { - "overrideType": "number | string | Date | BufferSource | IDBValidKey[]", - "name": "IDBValidKey" - }, { "type": { "0": { @@ -519,11 +515,6 @@ } ] }, - { - "name": "ImportValue", - "legacyNamespace": "WebAssembly", - "overrideType": "ExportValue | number" - }, { "name": "ModuleImports", "legacyNamespace": "WebAssembly", diff --git a/inputfiles/patches/indexeddb.kdl b/inputfiles/patches/indexeddb.kdl index b11fc6ab4..d5a4ff503 100644 --- a/inputfiles/patches/indexeddb.kdl +++ b/inputfiles/patches/indexeddb.kdl @@ -5,3 +5,13 @@ interface IDBRequest { } property result overrideType=T } + +type-def IDBValidKey { + type long + type DOMString + type Date + type BufferSource + type sequence { + type IDBValidKey + } +} \ No newline at end of file diff --git a/inputfiles/patches/webassembly.kdl b/inputfiles/patches/webassembly.kdl index 426530070..db0bfd089 100644 --- a/inputfiles/patches/webassembly.kdl +++ b/inputfiles/patches/webassembly.kdl @@ -16,6 +16,11 @@ dictionary MemoryDescriptor { member shared type=boolean } +type-def ImportValue legacyNamespace=WebAssembly { + type ExportValue + type long +} + removals { // Overridden with `keyof ValueTypeMap` enum ValueType diff --git a/src/build/patches.ts b/src/build/patches.ts index a2515c73f..3aa8c4185 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -16,6 +16,7 @@ import type { Dictionary, Member, Signature, + TypeDef, } from "./types.js"; import { readdir, readFile } from "fs/promises"; import { merge } from "./helpers.js"; @@ -120,6 +121,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial { const mixin: Record> = {}; const interfaces: Record> = {}; const dictionary: Record> = {}; + const typedefs: DeepPartial[] = []; for (const node of nodes) { // Note: no "removals" handling here; caller is responsible for splitting @@ -143,6 +145,9 @@ function convertKDLNodes(nodes: Node[]): DeepPartial { case "dictionary": dictionary[name] = merge(dictionary[name], handleDictionary(node)); break; + case "type-def": + typedefs.push(handleTypeDef(node)); + break; default: throw new Error(`Unknown node name: ${node.name}`); } @@ -155,6 +160,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial { interface: interfaces, }), ...optionalNestedMember("dictionaries", dictionary, { dictionary }), + ...optionalNestedMember("typedefs", typedefs, { typedef: typedefs }), }; } @@ -432,6 +438,19 @@ function handleMember(c: Node): DeepPartial { }; } +/** + * Handles type definition nodes + * @param node The type definition node to handle. + */ +function handleTypeDef(node: Node): DeepPartial { + const typeNodes = node.children.filter((c) => c.name === "type"); + return { + name: string(node.values[0]), + ...handleTyped(typeNodes), + ...optionalMember("legacyNamespace", "string", node.properties?.legacyNamespace), + }; +} + /** * Collect all file URLs in a directory. */ From d0171e8026393b506b11762f980120c272105478 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 28 Dec 2025 14:22:39 +0200 Subject: [PATCH 2/5] format --- src/build/patches.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index 3aa8c4185..fa22c5cd0 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -447,7 +447,11 @@ function handleTypeDef(node: Node): DeepPartial { return { name: string(node.values[0]), ...handleTyped(typeNodes), - ...optionalMember("legacyNamespace", "string", node.properties?.legacyNamespace), + ...optionalMember( + "legacyNamespace", + "string", + node.properties?.legacyNamespace, + ), }; } From b624d2b0771ac859ef7d785f57128b7b53746ca2 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Mon, 29 Dec 2025 06:35:18 +0200 Subject: [PATCH 3/5] - --- inputfiles/patches/indexeddb.kdl | 2 +- inputfiles/patches/webassembly.kdl | 2 +- src/build/patches.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inputfiles/patches/indexeddb.kdl b/inputfiles/patches/indexeddb.kdl index 0083caae0..02a0fba2d 100644 --- a/inputfiles/patches/indexeddb.kdl +++ b/inputfiles/patches/indexeddb.kdl @@ -8,7 +8,7 @@ interface IDBRequest { interface IDBOpenDBRequest extends=IDBRequest -type-def IDBValidKey { +typedef IDBValidKey { type long type DOMString type Date diff --git a/inputfiles/patches/webassembly.kdl b/inputfiles/patches/webassembly.kdl index db0bfd089..c3adceb31 100644 --- a/inputfiles/patches/webassembly.kdl +++ b/inputfiles/patches/webassembly.kdl @@ -16,7 +16,7 @@ dictionary MemoryDescriptor { member shared type=boolean } -type-def ImportValue legacyNamespace=WebAssembly { +typedef ImportValue legacyNamespace=WebAssembly { type ExportValue type long } diff --git a/src/build/patches.ts b/src/build/patches.ts index fa22c5cd0..54ab46911 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -145,7 +145,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial { case "dictionary": dictionary[name] = merge(dictionary[name], handleDictionary(node)); break; - case "type-def": + case "typedef": typedefs.push(handleTypeDef(node)); break; default: From 3eb87fd86e7dd221f25ff5b24be85fccca443007 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 29 Dec 2025 17:19:22 +0100 Subject: [PATCH 4/5] Rename handleTypeDef to handleTypedef for consistency --- 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 54ab46911..6c5d90f2e 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -146,7 +146,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial { dictionary[name] = merge(dictionary[name], handleDictionary(node)); break; case "typedef": - typedefs.push(handleTypeDef(node)); + typedefs.push(handleTypedef(node)); break; default: throw new Error(`Unknown node name: ${node.name}`); @@ -442,7 +442,7 @@ function handleMember(c: Node): DeepPartial { * Handles type definition nodes * @param node The type definition node to handle. */ -function handleTypeDef(node: Node): DeepPartial { +function handleTypedef(node: Node): DeepPartial { const typeNodes = node.children.filter((c) => c.name === "type"); return { name: string(node.values[0]), From d0bfe869ea3cf4e15dc8577c288cbe6ddc0a5975 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Mon, 29 Dec 2025 17:21:37 +0100 Subject: [PATCH 5/5] Update documentation for handleTypedef function --- 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 6c5d90f2e..292cbb3da 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -439,8 +439,8 @@ function handleMember(c: Node): DeepPartial { } /** - * Handles type definition nodes - * @param node The type definition node to handle. + * Handles typedef nodes + * @param node The typedef node to handle. */ function handleTypedef(node: Node): DeepPartial { const typeNodes = node.children.filter((c) => c.name === "type");