Skip to content

Commit 5b2dec6

Browse files
authored
Support migration to async_iterable (#2087)
1 parent 8232699 commit 5b2dec6

File tree

6 files changed

+52
-38
lines changed

6 files changed

+52
-38
lines changed

package-lock.json

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
"@types/webidl2": "^24.4.3",
4747
"@typescript-eslint/eslint-plugin": "^8",
4848
"@typescript-eslint/parser": "^8",
49-
"@webref/css": "^6.12.7",
50-
"@webref/elements": "^2.3.0",
51-
"@webref/events": "^1.11.3",
52-
"@webref/idl": "^3.46.1",
49+
"@webref/css": "^6.23.6",
50+
"@webref/elements": "^2.5.0",
51+
"@webref/events": "^1.18.6",
52+
"@webref/idl": "^3.66.0",
5353
"bcd-idl-mapper": "^3.0.0",
5454
"cpx2": "^8.0.0",
5555
"danger": "^13.0.4",
@@ -64,7 +64,7 @@
6464
"print-diff": "^2.0.0",
6565
"typescript": "^5.6.0-dev.20240806",
6666
"typescript-eslint": "^8",
67-
"webidl2": "^24.4.1"
67+
"webidl2": "^24.5.0"
6868
},
6969
"overrides": {
7070
"typescript@*": "$typescript"

src/build/bcd/mapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ function mapInterfaceLike(
9191
);
9292

9393
if (i.iterator) {
94-
const iteratorKey = i.iterator.async ? "@@asyncIterator" : "@@iterator";
94+
const iteratorKey =
95+
i.iterator.kind === "async_iterable" ? "@@asyncIterator" : "@@iterator";
9596
// BCD often doesn't have an @@iterator entry, but it does usually have an entry
9697
// for iterable methods such as values(). Use that as a fallback.
9798
// See also: https://github.com/mdn/browser-compat-data/issues/6367

src/build/emitter.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ export function emitWebIdl(
10821082

10831083
// Emit forEach for iterators
10841084
function emitIteratorForEach(i: Browser.Interface) {
1085-
if (!i.iterator || i.iterator.async) {
1085+
if (!i.iterator || i.iterator.kind === "async_iterable") {
10861086
return;
10871087
}
10881088
const subtype = i.iterator.type.map(convertDomTypeToTsType);
@@ -1619,7 +1619,7 @@ export function emitWebIdl(
16191619

16201620
function emitSelfIterator(i: Browser.Interface) {
16211621
if (!compilerBehavior.useIteratorObject) return;
1622-
const async = i.iterator?.async;
1622+
const async = i.iterator?.kind === "async_iterable";
16231623
const name = getName(i);
16241624
const iteratorBaseType = `${async ? "Async" : ""}IteratorObject`;
16251625
const iteratorType = `${name}${async ? "Async" : ""}Iterator`;
@@ -1644,7 +1644,7 @@ export function emitWebIdl(
16441644
case "setlike":
16451645
return;
16461646
}
1647-
const async = i.iterator?.async;
1647+
const async = i.iterator?.kind === "async_iterable";
16481648
const iteratorType = async
16491649
? !compilerBehavior.useIteratorObject
16501650
? "AsyncIterableIterator"
@@ -1659,7 +1659,10 @@ export function emitWebIdl(
16591659
name: `[Symbol.${async ? "asyncIterator" : "iterator"}]`,
16601660
type: stringifySingleOrTupleTypes(subtypes),
16611661
});
1662-
if (i.iterator?.kind === "iterable") {
1662+
if (
1663+
i.iterator?.kind === "iterable" ||
1664+
i.iterator?.kind === "async_iterable"
1665+
) {
16631666
if (subtypes.length === 2) {
16641667
const [keyType, valueType] = subtypes;
16651668
methods.push(
@@ -1718,7 +1721,7 @@ export function emitWebIdl(
17181721
}
17191722

17201723
function getIteratorSubtypes() {
1721-
if (i.iterator && !i.iterator.async) {
1724+
if (i.iterator && i.iterator.kind !== "async_iterable") {
17221725
if (i.iterator.type.length === 1) {
17231726
return [convertDomTypeToTsType(i.iterator.type[0])];
17241727
}
@@ -1848,7 +1851,7 @@ export function emitWebIdl(
18481851

18491852
function emitAsyncIterator(i: Browser.Interface) {
18501853
function getAsyncIteratorSubtypes() {
1851-
if (i.iterator && i.iterator.kind === "iterable" && i.iterator.async) {
1854+
if (i.iterator && i.iterator.kind === "async_iterable") {
18521855
if (i.iterator.type.length === 1) {
18531856
return [convertDomTypeToTsType(i.iterator.type[0])];
18541857
}

src/build/types.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ export interface Interface {
204204
}
205205

206206
export interface Iterator {
207-
kind: "iterable" | "setlike" | "maplike";
207+
kind: "async_iterable" | "iterable" | "setlike" | "maplike";
208208
readonly: boolean;
209-
async: boolean;
210209
type: Typed[];
211210
param?: Param[];
212211
comments?: {

src/build/widlprocess.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,26 @@ function convertInterfaceCommon(
203203
addComments(method[member.name], commentMap, i.name, member.name);
204204
}
205205
} else if (
206+
(member.type as string) === "async_iterable" ||
206207
member.type === "iterable" ||
207208
member.type === "maplike" ||
208209
member.type === "setlike"
209210
) {
211+
// TODO(saschanaz): @types/webidl2 doesn't support async_iterable
212+
const iterableLike = member as
213+
| webidl2.IterableDeclarationMemberType
214+
| webidl2.MaplikeDeclarationMemberType
215+
| webidl2.SetlikeDeclarationMemberType;
216+
// Compatibility between `async_iterable` and `async iterable`
217+
const kind =
218+
iterableLike.type === "iterable" && iterableLike.async
219+
? "async_iterable"
220+
: iterableLike.type;
210221
result.iterator = {
211-
kind: member.type,
212-
readonly: member.readonly,
213-
async: member.async,
214-
param: member.arguments.map(convertArgument),
215-
type: member.idlType.map(convertIdlType),
222+
kind,
223+
readonly: iterableLike.readonly,
224+
param: iterableLike.arguments.map(convertArgument),
225+
type: iterableLike.idlType.map(convertIdlType),
216226
};
217227
}
218228
}

0 commit comments

Comments
 (0)