Skip to content

Commit 37efe71

Browse files
committed
-
1 parent 0377309 commit 37efe71

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

inputfiles/patches/eventhandlers.kdl

Lines changed: 0 additions & 7 deletions
This file was deleted.

inputfiles/patches/events.kdl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ interface-mixin GlobalEventHandlers {
7373
event transitionstart type=TransitionEvent
7474
event transitionend type=TransitionEvent
7575
event transitioncancel type=TransitionEvent
76+
// Touch event handlers are intentionally hidden in non-mobile web browsers.
77+
// See w3c.github.io/touch-events#dfn-expose-legacy-touch-event-apis.
78+
property ontouchcancel optional=#true
79+
property ontouchend optional=#true
80+
property ontouchmove optional=#true
81+
property ontouchstart optional=#true
82+
property onerror overrideType=OnErrorEventHandler
7683
}
7784

7885
interface-mixin MessageEventTarget {

src/build/patches.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parse, type Node } from "kdljs";
1+
import { parse, type Value, type Node } from "kdljs";
22
import type { Enum, Event, Property, Interface, WebIdl } from "./types";
33
import { readdir, readFile } from "fs/promises";
44
import { merge } from "./helpers.js";
@@ -7,6 +7,16 @@ type DeepPartial<T> = T extends object
77
? { [K in keyof T]?: DeepPartial<T[K]> }
88
: T;
99

10+
function optionalMember<const T>(prop: string, type: T, value?: Value) {
11+
if (value === undefined) {
12+
return {};
13+
}
14+
if (typeof value !== type) {
15+
throw new Error(`Expected type ${value} for ${prop}`);
16+
}
17+
return { [prop]: value as T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : never };
18+
}
19+
1020
/**
1121
* Converts patch files in KDL to match the [types](types.d.ts).
1222
*/
@@ -92,15 +102,12 @@ function handleMixin(node: Node): DeepPartial<Interface> {
92102
}
93103
}
94104

95-
const result = {
105+
return {
96106
name,
97107
events: { event },
98108
properties: { property },
109+
...optionalMember("extends", "string", node.properties?.extends),
99110
} as DeepPartial<Interface>;
100-
if (node.properties.extends) {
101-
result.extends = node.properties.extends as string;
102-
}
103-
return result;
104111
}
105112

106113
/**
@@ -119,19 +126,12 @@ function handleEvent(child: Node): Event {
119126
* @param child The child node to handle.
120127
*/
121128
function handleProperty(child: Node): Partial<Property> {
122-
const result: Partial<Property> = {
129+
return {
123130
name: child.values[0] as string,
131+
...optionalMember("exposed", "string", child.properties?.exposed),
132+
...optionalMember("optional", "boolean", child.properties?.optional),
133+
...optionalMember("overrideType", "string", child.properties?.overrideType),
124134
};
125-
126-
const props: (keyof Property)[] = ["exposed", "optional", "overrideType"];
127-
128-
props.forEach((prop) => {
129-
const value = child.properties[prop];
130-
if (value !== undefined) {
131-
result[prop] = value as any;
132-
}
133-
});
134-
return result;
135135
}
136136

137137
/**

0 commit comments

Comments
 (0)