Skip to content

Commit dc12717

Browse files
Bashamegasaschanaz
andauthored
Enhance README.md with KDL patching guidelines and documentation (#2317)
Co-authored-by: saschanaz <saschanaz@users.noreply.github.com>
1 parent f465089 commit dc12717

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

inputfiles/README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@ Some files in this directory are generated. Please do not edit them.
44
This specifically includes:
55

66
* `idl/*`
7-
* `mdn/*`
7+
* `mdn.json`
88

99
Feel free to send a pull request with changes to any other files.
10+
Note It is recommended to add your patch use KDL format, continue reading to find out more.
11+
12+
## Patches
13+
14+
The `patches/` directory contains `.kdl` files that specify modifications ("patches") on top of the Web IDL from web specifications, using the [KDL format](https://kdl.dev/).
15+
These patches are applied by [`patches.ts`](../src/build/patches.ts).
16+
17+
### When to add a patch
18+
19+
- Add extra types to the generated types, e.g. type parameters.
20+
- Make types more strict, e.g. replacing a string type into a string literal type.
21+
- Remove features that are not widely supported by web browsers, in case it's not automatically removed.
22+
23+
### When not to add a patch
24+
25+
- When the type is incorrect, and that's from an upstream spec. It's recommended to file a bug in the corresponding spec, and when the fix happens, it will be applied here automatically.
26+
27+
### How to write a patch
28+
29+
- Try to add a new patch file when the newly desired patch is big, e.g. as long as a whole page. If it's just a few lines then it can usually go into one of the existing files.
30+
- Files are named per their originating web specification. https://respec.org/xref/ helps you search the specifications. If there's no existing patch with that name, you should add one even if the patch will be very small.
31+
- Please add code comment about the intent for the patch, e.g. a feature is removed as it's only implemented in one browser.
32+
- You can largely follow the Web IDL structure but in KDL syntax:
33+
- Most top level types e.g. `enum`, `interface`, or `dictionary` have the same names, but multi-word names like `interface mixin` are hyphened as `interface-mixin`.
34+
- Attributes and operations are called `property` and `method` respectively to follow TypeScript convention.
35+
- If in doubt, feel free to file an issue or request help in [Discord dom-lib-generator channel](https://discord.gg/kRYw84uG).
36+
37+
#### Example (`patches/touch-events.kdl`)
38+
39+
```kdl
40+
interface-mixin GlobalEventHandlers {
41+
// Touch event handlers are intentionally hidden in non-mobile web browsers.
42+
// See w3c.github.io/touch-events#dfn-expose-legacy-touch-event-apis.
43+
property ontouchcancel optional=#true
44+
property ontouchend optional=#true
45+
property ontouchmove optional=#true
46+
property ontouchstart optional=#true
47+
}
48+
```

src/build/patches.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! This file:
2+
//! - Locates all KDL files in the `patches/` directory.
3+
//! - Parses and type-checks them.
4+
//! - Merges their contents and applies structural transformations over the main IDL dataset.
5+
16
import { parse, type Value, type Node, Document } from "kdljs";
27
import type {
38
Enum,

0 commit comments

Comments
 (0)