Skip to content

Commit 302ec59

Browse files
authored
Track typedefs and generics when resolving promises (#1102)
* Track typedefs and generics when resolving promises * dedupe typedefs map
1 parent 6d459ad commit 302ec59

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

baselines/dom.generated.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3456,7 +3456,7 @@ interface ClipboardItem {
34563456

34573457
declare var ClipboardItem: {
34583458
prototype: ClipboardItem;
3459-
new(items: Record<string, ClipboardItemData>, options?: ClipboardItemOptions): ClipboardItem;
3459+
new(items: Record<string, ClipboardItemDataType | PromiseLike<ClipboardItemDataType>>, options?: ClipboardItemOptions): ClipboardItem;
34603460
};
34613461

34623462
/** A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. */

src/build/emitter.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export function emitWebIdl(
160160
const allEnumsMap = webidl.enums ? webidl.enums.enum : {};
161161
const allCallbackFunctionsMap =
162162
webidl.callbackFunctions?.callbackFunction ?? {};
163-
const allTypeDefsMap = new Set(webidl.typedefs?.typedef.map((td) => td.name));
163+
const allTypedefsMap = toNameMap(webidl.typedefs?.typedef ?? []);
164164

165165
/// Tag name to element name map
166166
const tagNameToEleName = getTagNameToElementNameMap();
@@ -415,7 +415,7 @@ export function emitWebIdl(
415415
)
416416
return objDomType;
417417
// Name of a type alias. Just return itself
418-
if (allTypeDefsMap.has(objDomType)) return objDomType;
418+
if (allTypedefsMap[objDomType]) return objDomType;
419419

420420
throw new Error("Unknown DOM type: " + objDomType);
421421
}
@@ -648,11 +648,22 @@ export function emitWebIdl(
648648
}
649649

650650
function resolvePromise<T extends Browser.Typed>(t: T): T {
651-
if (t.type !== "Promise") {
651+
const typedef =
652+
typeof t.type === "string" ? allTypedefsMap[t.type] : undefined;
653+
const typeOwner = typedef ?? t;
654+
if (typeOwner.type !== "Promise") {
655+
if (t.subtype) {
656+
return {
657+
...t,
658+
subtype: Array.isArray(t.subtype)
659+
? t.subtype.map(resolvePromise)
660+
: resolvePromise(t.subtype),
661+
};
662+
}
652663
return t;
653664
}
654-
const type = [t.subtype!].flat();
655-
type.push({ ...t, type: "PromiseLike" });
665+
const type = [typeOwner.subtype!].flat();
666+
type.push({ ...typeOwner, type: "PromiseLike" });
656667
return { ...t, subtype: undefined, type };
657668
}
658669

0 commit comments

Comments
 (0)