Skip to content

Commit 45ff0e4

Browse files
authored
Support KDL Interfaces (#2153)
1 parent 4fb1587 commit 45ff0e4

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

inputfiles/addedTypes.jsonc

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,6 @@
9696
}
9797
}
9898
},
99-
"HTMLTableDataCellElement": {
100-
"name": "HTMLTableDataCellElement",
101-
"extends": "HTMLTableCellElement",
102-
"noInterfaceObject": true,
103-
"deprecated": "prefer HTMLTableCellElement",
104-
"exposed": "Window"
105-
},
106-
"HTMLTableHeaderCellElement": {
107-
"name": "HTMLTableHeaderCellElement",
108-
"extends": "HTMLTableCellElement",
109-
"noInterfaceObject": true,
110-
"deprecated": "prefer HTMLTableCellElement",
111-
"exposed": "Window"
112-
},
113-
"HTMLDocument": {
114-
"name": "HTMLDocument",
115-
"extends": "Document",
116-
"exposed": "Window"
117-
},
11899
"HTMLMediaElement": {
119100
"events": {
120101
"event": [

inputfiles/patches/html.kdl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ enum ImageOrientation {
44
// See https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1507#issuecomment-1454792451
55
none
66
}
7+
8+
interface HTMLTableDataCellElement extends=HTMLTableCellElement exposed=Window deprecated="prefer HTMLTableCellElement" noInterfaceObject=#true
9+
interface HTMLTableHeaderCellElement extends=HTMLTableCellElement exposed=Window deprecated="prefer HTMLTableCellElement" noInterfaceObject=#true
10+
interface HTMLDocument extends=Document exposed=Window

src/build/patches.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function parseKDL(kdlText: string): DeepPartial<WebIdl> {
6868
const nodes = output!;
6969
const enums: Record<string, Enum> = {};
7070
const mixin: Record<string, DeepPartial<Interface>> = {};
71+
const interfaces: Record<string, DeepPartial<Interface>> = {};
7172

7273
for (const node of nodes) {
7374
const name = string(node.values[0]);
@@ -76,14 +77,21 @@ function parseKDL(kdlText: string): DeepPartial<WebIdl> {
7677
enums[name] = handleEnum(node);
7778
break;
7879
case "interface-mixin":
79-
mixin[name] = handleMixin(node);
80+
mixin[name] = handleMixinandInterfaces(node, "mixin");
81+
break;
82+
case "interface":
83+
interfaces[name] = handleMixinandInterfaces(node, "interface");
8084
break;
8185
default:
8286
throw new Error(`Unknown node name: ${node.name}`);
8387
}
8488
}
8589

86-
return { enums: { enum: enums }, mixins: { mixin } };
90+
return {
91+
enums: { enum: enums },
92+
mixins: { mixin },
93+
interfaces: { interface: interfaces },
94+
};
8795
}
8896

8997
/**
@@ -118,7 +126,10 @@ function handleEnum(node: Node): Enum {
118126
* @param node The mixin node to handle.
119127
* @param mixins The record of mixins to update.
120128
*/
121-
function handleMixin(node: Node): DeepPartial<Interface> {
129+
function handleMixinandInterfaces(
130+
node: Node,
131+
type: "mixin" | "interface",
132+
): DeepPartial<Interface> {
122133
const name = node.values[0];
123134

124135
const event: Event[] = [];
@@ -145,12 +156,22 @@ function handleMixin(node: Node): DeepPartial<Interface> {
145156
}
146157
}
147158

159+
const interfaceObject = type === "interface" && {
160+
...optionalMember("exposed", "string", node.properties?.exposed),
161+
...optionalMember("deprecated", "string", node.properties?.deprecated),
162+
...optionalMember(
163+
"noInterfaceObject",
164+
"boolean",
165+
node.properties?.noInterfaceObject,
166+
),
167+
};
148168
return {
149169
name,
150170
events: { event },
151171
properties: { property },
152172
methods: { method },
153173
...optionalMember("extends", "string", node.properties?.extends),
174+
...interfaceObject,
154175
} as DeepPartial<Interface>;
155176
}
156177

0 commit comments

Comments
 (0)