Skip to content

Commit 99e1b99

Browse files
committed
-
1 parent ac0e253 commit 99e1b99

File tree

4 files changed

+115
-97
lines changed

4 files changed

+115
-97
lines changed

inputfiles/AutoFill/addedTypes.kdl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
enum AutoFillBase {
2+
// Off
3+
value "off"
4+
// Automatic
5+
value "on"
6+
value ""
7+
}
8+
enum AutoFillAddressKind {
9+
value "shipping"
10+
value "billing"
11+
}
12+
enum AutoFillNormalField {
13+
value "name"
14+
value "honorific-prefix"
15+
value "given-name"
16+
value "additional-name"
17+
value "family-name"
18+
value "honorific-suffix"
19+
value "username"
20+
value "new-password"
21+
value "current-password"
22+
// Supported in iOS Safari too even though WPT tests
23+
// for Safari currently fail as of 2023-06.
24+
value "one-time-code"
25+
value "organization"
26+
value "street-address"
27+
value "address-line1"
28+
value "address-line2"
29+
value "address-line3"
30+
value "address-level4"
31+
value "address-level3"
32+
value "address-level2"
33+
value "address-level1"
34+
value "country"
35+
value "country-name"
36+
value "postal-code"
37+
value "cc-name"
38+
value "cc-given-name"
39+
value "cc-family-name"
40+
value "cc-number"
41+
value "cc-exp"
42+
value "cc-exp-month"
43+
value "cc-exp-year"
44+
value "cc-csc"
45+
value "cc-type"
46+
value "transaction-currency"
47+
value "transaction-amount"
48+
value "bday-day"
49+
value "bday-month"
50+
value "bday-year"
51+
}
52+
enum AutoFillContactKind {
53+
value "home"
54+
value "work"
55+
value "mobile"
56+
}
57+
enum AutoFillContactField {
58+
value "tel"
59+
value "tel-country-code"
60+
value "tel-national"
61+
value "tel-area-code"
62+
value "tel-local"
63+
value "tel-local-prefix"
64+
value "tel-local-suffix"
65+
value "tel-extension"
66+
value "email"
67+
}
68+
enum AutoFillCredentialField {
69+
value "webauthn"
70+
}

inputfiles/addedTypes.jsonc

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -373,98 +373,6 @@
373373
// Full support: https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API#browser_compatibility
374374
"storage-access"
375375
]
376-
},
377-
"AutoFillBase": {
378-
"name": "AutoFillBase",
379-
"value": [
380-
// Off
381-
"off",
382-
// Automatic
383-
"on",
384-
""
385-
]
386-
},
387-
"AutoFillAddressKind": {
388-
"name": "AutoFillAddressKind",
389-
"value": [
390-
"shipping",
391-
"billing"
392-
]
393-
},
394-
"AutoFillNormalField": {
395-
"name": "AutoFillNormalField",
396-
"value": [
397-
"name",
398-
"honorific-prefix",
399-
"given-name",
400-
"additional-name",
401-
"family-name",
402-
"honorific-suffix",
403-
404-
"username",
405-
"new-password",
406-
"current-password",
407-
// Supported in iOS Safari too even though WPT tests
408-
// for Safari currently fail as of 2023-06.
409-
"one-time-code",
410-
411-
"organization",
412-
"street-address",
413-
"address-line1",
414-
"address-line2",
415-
"address-line3",
416-
"address-level4",
417-
"address-level3",
418-
"address-level2",
419-
"address-level1",
420-
"country",
421-
"country-name",
422-
"postal-code",
423-
424-
"cc-name",
425-
"cc-given-name",
426-
"cc-family-name",
427-
"cc-number",
428-
"cc-exp",
429-
"cc-exp-month",
430-
"cc-exp-year",
431-
"cc-csc",
432-
"cc-type",
433-
"transaction-currency",
434-
"transaction-amount",
435-
436-
"bday-day",
437-
"bday-month",
438-
"bday-year"
439-
]
440-
},
441-
"AutoFillContactKind": {
442-
"name": "AutoFillContactKind",
443-
"value": [
444-
"home",
445-
"work",
446-
"mobile"
447-
]
448-
},
449-
"AutoFillContactField": {
450-
"name": "AutoFillContactField",
451-
"value": [
452-
"tel",
453-
"tel-country-code",
454-
"tel-national",
455-
"tel-area-code",
456-
"tel-local",
457-
"tel-local-prefix",
458-
"tel-local-suffix",
459-
"tel-extension",
460-
"email"
461-
]
462-
},
463-
"AutoFillCredentialField": {
464-
"name": "AutoFillCredentialField",
465-
"value": [
466-
"webauthn"
467-
]
468376
}
469377
}
470378
},

src/build.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getInterfaceToEventMap } from "./build/webref/events.js";
1414
import { getWebidls } from "./build/webref/idl.js";
1515
import jsonc from "jsonc-parser";
1616
import { generateDescriptions } from "./build/mdn-comments.js";
17+
import readKDL from "./build/utils/kdl.js";
1718

1819
function mergeNamesakes(filtered: Browser.WebIdl) {
1920
const targets = [
@@ -97,6 +98,7 @@ async function emitDom() {
9798
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
9899
const documentationFromMDN = await generateDescriptions();
99100
const removedItems = await readInputJSON("removedTypes.jsonc");
101+
const addedItemsKDL = await readKDL(inputFolder, "addedTypes.kdl");
100102

101103
async function readInputJSON(filename: string) {
102104
const content = await fs.readFile(new URL(filename, inputFolder), "utf8");
@@ -229,6 +231,7 @@ async function emitDom() {
229231
webidl = prune(webidl, removedItems);
230232
webidl = mergeApiDescriptions(webidl, documentationFromMDN);
231233
webidl = merge(webidl, addedItems);
234+
webidl = merge(webidl, addedItemsKDL);
232235
webidl = merge(webidl, overriddenItems);
233236
webidl = merge(webidl, comments);
234237
webidl = mergeDeprecatedMessage(webidl, deprecatedInfo);

src/build/utils/kdl.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { parse } from "kdljs";
22
import { Enum, Event, Method, Property } from "../types";
3-
import { readFile } from "fs/promises";
3+
import { readdir, readFile } from "fs/promises";
4+
import { merge } from "../helpers.js";
45

56
interface MethodDescriptor {
67
[x: string]: Omit<Method, "signature">;
@@ -103,10 +104,46 @@ export function parseKDL(kdlText: string) {
103104

104105
return { mixins: { mixin: interfaces }, enums: { enum: enums } };
105106
}
106-
export default async function readInputKDL(
107-
path: string,
107+
108+
/**
109+
* Recursively collect all KDL file URLs in a directory.
110+
*/
111+
async function getAllKDLFileURLs(folder: URL, file: string): Promise<URL[]> {
112+
const entries = await readdir(folder, { withFileTypes: true });
113+
114+
const results: URL[] = [];
115+
116+
for (const entry of entries) {
117+
const child = new URL(entry.name + "/", folder);
118+
119+
if (entry.isDirectory()) {
120+
results.push(...(await getAllKDLFileURLs(child, file)));
121+
} else if (entry.isFile() && entry.name == file) {
122+
results.push(new URL(entry.name, folder));
123+
}
124+
}
125+
126+
return results;
127+
}
128+
129+
/**
130+
* Read and parse a single KDL file.
131+
*/
132+
export async function readInputKDL(fileUrl: URL): Promise<any> {
133+
const text = await readFile(fileUrl, "utf8");
134+
return parseKDL(text);
135+
}
136+
137+
/**
138+
* Read, parse, and merge all KDL files under the input folder.
139+
*/
140+
export default async function readKDL(
108141
inputFolder: URL,
142+
file: string,
109143
): Promise<any> {
110-
const text = await readFile(new URL(path, inputFolder), "utf8");
111-
return parseKDL(text);
144+
const fileUrls = await getAllKDLFileURLs(inputFolder, file);
145+
146+
const parsedContents = await Promise.all(fileUrls.map(readInputKDL));
147+
148+
return parsedContents.reduce((acc, current) => merge(acc, current), {});
112149
}

0 commit comments

Comments
 (0)