diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index da2e10e3a..bfdf350ce 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -446,10 +446,6 @@ "additionalTypes": ["Headers"], "name": "HeadersInit" }, - { - "overrideType": "number | string | Date | BufferSource | IDBValidKey[]", - "name": "IDBValidKey" - }, { "type": { "0": { @@ -489,11 +485,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 ee4b5e222..02a0fba2d 100644 --- a/inputfiles/patches/indexeddb.kdl +++ b/inputfiles/patches/indexeddb.kdl @@ -7,3 +7,13 @@ interface IDBRequest { } interface IDBOpenDBRequest extends=IDBRequest + +typedef IDBValidKey { + type long + type DOMString + type Date + type BufferSource + type sequence { + type IDBValidKey + } +} diff --git a/inputfiles/patches/webassembly.kdl b/inputfiles/patches/webassembly.kdl index 426530070..c3adceb31 100644 --- a/inputfiles/patches/webassembly.kdl +++ b/inputfiles/patches/webassembly.kdl @@ -16,6 +16,11 @@ dictionary MemoryDescriptor { member shared type=boolean } +typedef 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..54ab46911 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 "typedef": + 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,23 @@ 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. */