Skip to content

Commit f73b23b

Browse files
committed
Support types in KDL
1 parent 3b5b514 commit f73b23b

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

inputfiles/addedTypes.jsonc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@
476476
"additionalTypes": ["Headers"],
477477
"name": "HeadersInit"
478478
},
479-
{
480-
"overrideType": "number | string | Date | BufferSource | IDBValidKey[]",
481-
"name": "IDBValidKey"
482-
},
483479
{
484480
"type": {
485481
"0": {
@@ -519,11 +515,6 @@
519515
}
520516
]
521517
},
522-
{
523-
"name": "ImportValue",
524-
"legacyNamespace": "WebAssembly",
525-
"overrideType": "ExportValue | number"
526-
},
527518
{
528519
"name": "ModuleImports",
529520
"legacyNamespace": "WebAssembly",

inputfiles/patches/indexeddb.kdl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ interface IDBRequest {
55
}
66
property result overrideType=T
77
}
8+
9+
type-def IDBValidKey {
10+
type long
11+
type DOMString
12+
type Date
13+
type BufferSource
14+
type sequence {
15+
type IDBValidKey
16+
}
17+
}

inputfiles/patches/webassembly.kdl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ dictionary MemoryDescriptor {
1616
member shared type=boolean
1717
}
1818

19+
type-def ImportValue legacyNamespace=WebAssembly {
20+
type ExportValue
21+
type long
22+
}
23+
1924
removals {
2025
// Overridden with `keyof ValueTypeMap`
2126
enum ValueType

src/build/patches.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
Dictionary,
1717
Member,
1818
Signature,
19+
TypeDef,
1920
} from "./types.js";
2021
import { readdir, readFile } from "fs/promises";
2122
import { merge } from "./helpers.js";
@@ -120,6 +121,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
120121
const mixin: Record<string, DeepPartial<Interface>> = {};
121122
const interfaces: Record<string, DeepPartial<Interface>> = {};
122123
const dictionary: Record<string, DeepPartial<Dictionary>> = {};
124+
const typedefs: DeepPartial<TypeDef>[] = [];
123125

124126
for (const node of nodes) {
125127
// Note: no "removals" handling here; caller is responsible for splitting
@@ -143,6 +145,9 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
143145
case "dictionary":
144146
dictionary[name] = merge(dictionary[name], handleDictionary(node));
145147
break;
148+
case "type-def":
149+
typedefs.push(handleTypeDef(node));
150+
break;
146151
default:
147152
throw new Error(`Unknown node name: ${node.name}`);
148153
}
@@ -155,6 +160,7 @@ function convertKDLNodes(nodes: Node[]): DeepPartial<WebIdl> {
155160
interface: interfaces,
156161
}),
157162
...optionalNestedMember("dictionaries", dictionary, { dictionary }),
163+
...optionalNestedMember("typedefs", typedefs, { typedef: typedefs }),
158164
};
159165
}
160166

@@ -432,6 +438,19 @@ function handleMember(c: Node): DeepPartial<Member> {
432438
};
433439
}
434440

441+
/**
442+
* Handles type definition nodes
443+
* @param node The type definition node to handle.
444+
*/
445+
function handleTypeDef(node: Node): DeepPartial<TypeDef> {
446+
const typeNodes = node.children.filter((c) => c.name === "type");
447+
return {
448+
name: string(node.values[0]),
449+
...handleTyped(typeNodes),
450+
...optionalMember("legacyNamespace", "string", node.properties?.legacyNamespace),
451+
};
452+
}
453+
435454
/**
436455
* Collect all file URLs in a directory.
437456
*/

0 commit comments

Comments
 (0)