Skip to content

Commit 8a8bb00

Browse files
committed
use generic for existing types
1 parent c157267 commit 8a8bb00

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

inputfiles/addedTypes.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,9 @@
599599
}
600600
}
601601
},
602-
"NodeListOf<TNode extends Node>": {
603-
"name": "NodeListOf<TNode extends Node>",
602+
"NodeListOf": {
603+
"name": "NodeListOf",
604+
"generic": "TNode extends Node",
604605
"exposed": "Window",
605606
"extends": "NodeList",
606607
"properties": {
@@ -634,8 +635,9 @@
634635
]
635636
}
636637
},
637-
"HTMLCollectionOf<T extends Element>": {
638-
"name": "HTMLCollectionOf<T extends Element>",
638+
"HTMLCollectionOf": {
639+
"name": "HTMLCollectionOf",
640+
"generic": "T extends Element",
639641
"exposed": "Window",
640642
"extends": "HTMLCollection",
641643
"methods": {

inputfiles/comments.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
}
178178
}
179179
},
180-
"NodeListOf<TNode extends Node>": {
180+
"NodeListOf": {
181181
"methods": {
182182
"method": {
183183
"forEach": {

src/emitter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
226226
return ehParents;
227227
}
228228

229+
if (!i.name) {
230+
throw new Error("Unexpected nameless object: " + JSON.stringify(i));
231+
}
232+
229233
const iExtends = i.extends && i.extends.replace(/<.*>$/, '');
230234
const parentWithEventHandler = allInterfacesMap[iExtends] && getParentEventHandler(allInterfacesMap[iExtends]) || [];
231235
const mixinsWithEventHandler = flatMap(i.implements || [], i => getParentEventHandler(allInterfacesMap[i]));
@@ -695,7 +699,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
695699
const value = subtype[subtype.length - 1];
696700
const key = subtype.length > 1 ? subtype[0] :
697701
i.iterator.kind === "iterable" ? "number" : value;
698-
const name = i.name.replace(/ extends \w+/, "");
702+
const name = i.name + (i.generic ? `<${i.generic.split(" ")[0]}>` : "");
699703
printer.printLine(`forEach(callbackfn: (value: ${value}, key: ${key}, parent: ${name}) => void, thisArg?: any): void;`);
700704
}
701705

@@ -1229,8 +1233,9 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) {
12291233
if (subtypes) {
12301234
const iteratorExtends = getIteratorExtends(i.iterator, subtypes);
12311235
const name = extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name;
1236+
const generic = i.generic ? `<${i.generic}>` : "";
12321237
printer.printLine("");
1233-
printer.printLine(`interface ${name} ${iteratorExtends}{`);
1238+
printer.printLine(`interface ${name}${generic} ${iteratorExtends}{`);
12341239
printer.increaseIndent();
12351240
if (!iteratorExtends) {
12361241
printer.printLine(`[Symbol.iterator](): IterableIterator<${stringifySingleOrTupleTypes(subtypes)}>;`);

0 commit comments

Comments
 (0)