diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 6d4e376b8..d20b4bd22 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -4562,12 +4562,12 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad * Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order. */ /** @deprecated */ - readonly anchors: HTMLCollectionOf; + readonly anchors: HTMLCollection; /** * Retrieves a collection of all applet objects in the document. */ /** @deprecated */ - readonly applets: HTMLCollectionOf; + readonly applets: HTMLCollection; /** * Deprecated. Sets or retrieves a value that indicates the background color behind the object. */ @@ -4635,7 +4635,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Retrieves a collection of all embed objects in the document. */ - readonly embeds: HTMLCollectionOf; + readonly embeds: HTMLCollection; /** * Sets or gets the foreground (text) color of the document. */ @@ -4644,7 +4644,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Retrieves a collection, in source order, of all form objects in the document. */ - readonly forms: HTMLCollectionOf; + readonly forms: HTMLCollection; /** @deprecated */ readonly fullscreen: boolean; /** @@ -4659,7 +4659,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Retrieves a collection, in source order, of img objects in the document. */ - readonly images: HTMLCollectionOf; + readonly images: HTMLCollection; /** * Gets the implementation object of the current document. */ @@ -4680,7 +4680,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Retrieves a collection of all a objects that specify the href property and all area objects in the document. */ - readonly links: HTMLCollectionOf; + readonly links: HTMLCollection; /** * Contains information about the current URL. */ @@ -4702,7 +4702,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Return an HTMLCollection of the embed elements in the Document. */ - readonly plugins: HTMLCollectionOf; + readonly plugins: HTMLCollection; /** * Retrieves a value that indicates the current state of the object. */ @@ -4714,7 +4714,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Retrieves a collection of all script objects in the document. */ - readonly scripts: HTMLCollectionOf; + readonly scripts: HTMLCollection; readonly scrollingElement: Element | null; readonly timeline: DocumentTimeline; /** @@ -4928,7 +4928,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes. */ - getElementsByClassName(classNames: string): HTMLCollectionOf; + getElementsByClassName(classNames: string): HTMLCollection; /** * Gets a collection of objects based on the value of the NAME or ID attribute. * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. @@ -4938,9 +4938,9 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad * Retrieves a collection of objects based on the specified element name. * @param name Specifies the name of an element. */ - getElementsByTagName(qualifiedName: K): HTMLCollectionOf; - getElementsByTagName(qualifiedName: K): HTMLCollectionOf; - getElementsByTagName(qualifiedName: string): HTMLCollectionOf; + getElementsByTagName(qualifiedName: K): HTMLCollection; + getElementsByTagName(qualifiedName: K): HTMLCollection; + getElementsByTagName(qualifiedName: string): HTMLCollection; /** * If namespace and localName are "*" returns a HTMLCollection of all descendant elements. * @@ -4950,9 +4950,9 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad * * Otherwise, returns a HTMLCollection of all descendant elements whose namespace is namespace and local name is localName. */ - getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf; - getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf; - getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollection; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollection; + getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollection; /** * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. */ @@ -5307,13 +5307,13 @@ interface Element extends Node, Animatable, ChildNode, InnerHTML, NonDocumentTyp /** * Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes. */ - getElementsByClassName(classNames: string): HTMLCollectionOf; - getElementsByTagName(qualifiedName: K): HTMLCollectionOf; - getElementsByTagName(qualifiedName: K): HTMLCollectionOf; - getElementsByTagName(qualifiedName: string): HTMLCollectionOf; - getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf; - getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf; - getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf; + getElementsByClassName(classNames: string): HTMLCollection; + getElementsByTagName(qualifiedName: K): HTMLCollection; + getElementsByTagName(qualifiedName: K): HTMLCollection; + getElementsByTagName(qualifiedName: string): HTMLCollection; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollection; + getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollection; + getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollection; /** * Returns true if element has an attribute whose qualified name is qualifiedName, and false otherwise. */ @@ -6562,7 +6562,7 @@ declare var HTMLCanvasElement: { }; /** A generic collection (array-like object similar to arguments) of elements (in document order) and offers methods and properties for selecting from the list. */ -interface HTMLCollectionBase { +interface HTMLCollection { /** * Sets or retrieves the number of objects in a collection. */ @@ -6570,15 +6570,12 @@ interface HTMLCollectionBase { /** * Retrieves an object from various collections. */ - item(index: number): Element | null; - [index: number]: Element; -} - -interface HTMLCollection extends HTMLCollectionBase { + item(index: number): E | null; /** * Retrieves a select object or an object from an options collection. */ - namedItem(name: string): Element | null; + namedItem(name: string): E | N | null; + [index: number]: E; } declare var HTMLCollection: { @@ -6586,12 +6583,6 @@ declare var HTMLCollection: { new(): HTMLCollection; }; -interface HTMLCollectionOf extends HTMLCollectionBase { - item(index: number): T | null; - namedItem(name: string): T | null; - [index: number]: T; -} - /** Provides special properties (beyond those of the regular HTMLElement interface it also has available to it by inheritance) for manipulating definition list (
) elements. */ interface HTMLDListElement extends HTMLElement { /** @deprecated */ @@ -6623,7 +6614,7 @@ declare var HTMLDataElement: { /** Provides special properties (beyond the HTMLElement object interface it also has available to it by inheritance) to manipulate elements and their content. */ interface HTMLDataListElement extends HTMLElement { - readonly options: HTMLCollectionOf; + readonly options: HTMLCollection; addEventListener(type: K, listener: (this: HTMLDataListElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: HTMLDataListElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -6843,7 +6834,7 @@ declare var HTMLFontElement: { }; /** A collection of HTML form control elements. */ -interface HTMLFormControlsCollection extends HTMLCollectionBase { +interface HTMLFormControlsCollection extends HTMLCollection { /** * Returns the item with ID or name name from the collection. * @@ -7606,7 +7597,7 @@ interface HTMLMapElement extends HTMLElement { /** * Retrieves a collection of the area objects defined for the given map object. */ - readonly areas: HTMLCollection; + readonly areas: HTMLCollection; /** * Sets or retrieves the name of the object. */ @@ -8147,7 +8138,7 @@ declare var HTMLOptionElement: { }; /** HTMLOptionsCollection is an interface representing a collection of HTML option elements (in document order) and offers methods and properties for traversing the list as well as optionally altering its items. This type is returned solely by the "options" property of select. */ -interface HTMLOptionsCollection extends HTMLCollectionOf { +interface HTMLOptionsCollection extends HTMLCollection { /** * Returns the number of elements in the collection. * @@ -8420,7 +8411,7 @@ interface HTMLSelectElement extends HTMLElement { * Sets or retrieves the index of the selected option in a select object. */ selectedIndex: number; - readonly selectedOptions: HTMLCollectionOf; + readonly selectedOptions: HTMLCollection; /** * Sets or retrieves the number of rows in the list box. */ @@ -8736,7 +8727,7 @@ interface HTMLTableElement extends HTMLElement { /** * Sets or retrieves the number of horizontal rows contained in the object. */ - readonly rows: HTMLCollectionOf; + readonly rows: HTMLCollection; /** * Sets or retrieves which dividing lines (inner borders) are displayed. */ @@ -8750,7 +8741,7 @@ interface HTMLTableElement extends HTMLElement { /** * Retrieves a collection of all tBody objects in the table. Objects in this collection are in source order. */ - readonly tBodies: HTMLCollectionOf; + readonly tBodies: HTMLCollection; /** * Retrieves the tFoot object of the table. */ @@ -8838,7 +8829,7 @@ interface HTMLTableRowElement extends HTMLElement { /** * Retrieves a collection of all cells in the table row. */ - readonly cells: HTMLCollectionOf; + readonly cells: HTMLCollection; /** @deprecated */ ch: string; /** @deprecated */ @@ -8888,7 +8879,7 @@ interface HTMLTableSectionElement extends HTMLElement { /** * Sets or retrieves the number of horizontal rows contained in the object. */ - readonly rows: HTMLCollectionOf; + readonly rows: HTMLCollection; /** @deprecated */ vAlign: string; /** @@ -20071,6 +20062,8 @@ type RTCTransport = RTCDtlsTransport | RTCSrtpSdesTransport; /** @deprecated */ type MouseWheelEvent = WheelEvent; type WindowProxy = Window; +/** @deprecated */ +type HTMLCollectionOf = HTMLCollection; type AlignSetting = "center" | "end" | "left" | "right" | "start"; type AnimationPlayState = "finished" | "idle" | "paused" | "running"; type AppendMode = "segments" | "sequence"; diff --git a/baselines/dom.iterable.generated.d.ts b/baselines/dom.iterable.generated.d.ts index 13a22e5aa..5ff10894e 100644 --- a/baselines/dom.iterable.generated.d.ts +++ b/baselines/dom.iterable.generated.d.ts @@ -81,14 +81,10 @@ interface HTMLAllCollection { [Symbol.iterator](): IterableIterator; } -interface HTMLCollectionBase { +interface HTMLCollection { [Symbol.iterator](): IterableIterator; } -interface HTMLCollectionOf { - [Symbol.iterator](): IterableIterator; -} - interface HTMLFormElement { [Symbol.iterator](): IterableIterator; } diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index c612bc495..2198d4caa 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -512,45 +512,6 @@ ] } }, - "HTMLCollectionOf": { - "name": "HTMLCollectionOf", - "type-parameters": [ - { - "name": "T", - "extends": "Element" - } - ], - "exposed": "Window", - "extends": "HTMLCollection", - "methods": { - "method": { - "item": { - "getter": 1, - "signature": [ - { - "nullable": 1, - "override-type": "T", - "param": [ - { - "name": "index", - "type": "unsigned long" - } - ] - } - ], - "specs": "html5", - "name": "item" - }, - "namedItem": { - "name": "namedItem", - "override-signatures": [ - "namedItem(name: string): T | null" - ] - } - } - }, - "no-interface-object": "1" - }, "EventListenerObject": { "name": "EventListenerObject", "methods": { @@ -608,7 +569,7 @@ "getElementsByClassName": { "name": "getElementsByClassName", "override-signatures": [ - "getElementsByClassName(classNames: string): HTMLCollectionOf" + "getElementsByClassName(classNames: string): HTMLCollection" ] }, "closest": { @@ -2377,6 +2338,17 @@ "type": "ModuleImports" } ] + }, + { + "deprecated": 1, + "new-type": "HTMLCollectionOf", + "type-parameters": [ + { + "name": "T", + "extends": "Element" + } + ], + "override-type": "HTMLCollection" } ] } diff --git a/inputfiles/knownTypes.json b/inputfiles/knownTypes.json index b79a1e39b..3f75132b4 100644 --- a/inputfiles/knownTypes.json +++ b/inputfiles/knownTypes.json @@ -35,6 +35,7 @@ "HmacImportParams", "HmacKeyAlgorithm", "HmacKeyGenParams", + "HTMLCollectionOf", "IDBKeyPath", "IDBValidKey", "ImageBitmapRenderingContextSettings", diff --git a/inputfiles/overridingTypes.json b/inputfiles/overridingTypes.json index 5f6279ba9..95d476696 100644 --- a/inputfiles/overridingTypes.json +++ b/inputfiles/overridingTypes.json @@ -540,15 +540,15 @@ "getElementsByTagNameNS": { "name": "getElementsByTagNameNS", "override-signatures": [ - "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/1999/xhtml\", localName: string): HTMLCollectionOf", - "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/2000/svg\", localName: string): HTMLCollectionOf", - "getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf" + "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/1999/xhtml\", localName: string): HTMLCollection", + "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/2000/svg\", localName: string): HTMLCollection", + "getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollection" ] }, "getElementsByClassName": { "name": "getElementsByClassName", "override-signatures": [ - "getElementsByClassName(classNames: string): HTMLCollectionOf" + "getElementsByClassName(classNames: string): HTMLCollection" ] }, "getElementsByName": { @@ -606,38 +606,38 @@ }, "anchors": { "name": "anchors", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "applets": { "name": "applets", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "embeds": { "name": "embeds", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "forms": { "name": "forms", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "fullscreen": { "deprecated": 1 }, "images": { "name": "images", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "links": { "name": "links", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "plugins": { "name": "plugins", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "scripts": { "name": "scripts", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "location": { "read-only": 0, @@ -1112,7 +1112,7 @@ "property": { "selectedOptions": { "name": "selectedOptions", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "labels": { "name": "labels", @@ -1135,7 +1135,7 @@ "property": { "options": { "name": "options", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" } } }, @@ -1183,11 +1183,11 @@ "property": { "rows": { "name": "rows", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" }, "tBodies": { "name": "tBodies", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" } } } @@ -1208,7 +1208,7 @@ "property": { "rows": { "name": "rows", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" } } } @@ -1232,9 +1232,9 @@ "getElementsByTagNameNS": { "name": "getElementsByTagNameNS", "override-signatures": [ - "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/1999/xhtml\", localName: string): HTMLCollectionOf", - "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/2000/svg\", localName: string): HTMLCollectionOf", - "getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf" + "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/1999/xhtml\", localName: string): HTMLCollection", + "getElementsByTagNameNS(namespaceURI: \"http://www.w3.org/2000/svg\", localName: string): HTMLCollection", + "getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollection" ] }, "msGetRegionContent": { @@ -1246,6 +1246,41 @@ } } }, + "HTMLCollection": { + "type-parameters": [ + { + "name": "E", + "extends": "Element", + "default": "Element" + }, + { + "name": "N", + "default": "never" + } + ], + "methods": { + "method": { + "item": { + "name": "item", + "override-signatures": [ + "item(index: number): E | null" + ] + }, + "namedItem": { + "name": "namedItem", + "override-signatures": [ + "namedItem(name: string): E | N | null" + ] + } + } + }, + "override-index-signatures": [ + "[index: number]: E" + ] + }, + "HTMLFormControlsCollection": { + "extends": "HTMLCollection" + }, "HTMLMediaElement": { "name": "HTMLMediaElement", "properties": { @@ -1408,7 +1443,7 @@ }, "HTMLOptionsCollection": { "name": "HTMLOptionsCollection", - "extends": "HTMLCollectionOf" + "extends": "HTMLCollection" }, "SubtleCrypto": { "name": "SubtleCrypto", @@ -1776,7 +1811,7 @@ "property": { "cells": { "name": "cells", - "override-type": "HTMLCollectionOf" + "override-type": "HTMLCollection" } } }, @@ -2272,6 +2307,16 @@ } } }, + "HTMLMapElement": { + "properties": { + "property": { + "areas": { + "name": "areas", + "override-type": "HTMLCollection" + } + } + } + }, "HTMLMarqueeElement": { "name": "HTMLMarqueeElement", "events": { diff --git a/src/emitter.ts b/src/emitter.ts index 72c4bfb67..52876f246 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -22,9 +22,6 @@ enum EmitScope { const defaultEventType = "Event"; const tsKeywords = new Set(["default", "delete", "continue"]); -const extendConflictsBaseTypes: Record }> = { - "HTMLCollection": { extendType: ["HTMLFormControlsCollection"], memberNames: new Set(["namedItem"]) }, -}; const eventTypeMap: Record = { "abort": "UIEvent", "complete": "Event", @@ -57,8 +54,6 @@ function createTextWriter(newLine: string) { let output: string; let indent: number; let lineStart: boolean; - /** print declarations conflicting with base interface to a side list to write them under a diffrent name later */ - let stack: { content: string, indent: number }[] = []; function getIndentString(level: number) { return " ".repeat(level); @@ -76,7 +71,6 @@ function createTextWriter(newLine: string) { output = ""; indent = 0; lineStart = true; - stack = []; } function endLine() { @@ -96,18 +90,6 @@ function createTextWriter(newLine: string) { print: write, printLine(c: string) { write(c); endLine(); }, - clearStack() { stack = []; }, - stackIsEmpty() { return stack.length === 0; }, - printLineToStack(content: string) { stack.push({ content, indent }); }, - printStackContent() { - stack.forEach(e => { - const oldIndent = indent; - indent = e.indent; - this.printLine(e.content); - indent = oldIndent; - }); - }, - getResult() { return output; } }; } @@ -380,7 +362,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitConstant(c: Browser.Constant) { - emitComments(c, printer.printLine); + emitComments(c); printer.printLine(`readonly ${c.name}: ${convertDomTypeToTsType(c)};`); } @@ -430,9 +412,9 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { /// Emit overloads for the getElementsByTagName method function emitGetElementsByTagNameOverloads(m: Browser.Method) { if (matchParamMethodSignature(m, "getElementsByTagName", "HTMLCollection", "string")) { - printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: K): HTMLCollectionOf;`); - printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: K): HTMLCollectionOf;`); - printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: string): HTMLCollectionOf;`); + printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: K): HTMLCollection;`); + printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: K): HTMLCollection;`); + printer.printLine(`getElementsByTagName(${m.signature[0].param![0].name}: string): HTMLCollection;`); } } @@ -548,7 +530,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { function emitCallBackFunction(cb: Browser.CallbackFunction) { printer.printLine(`interface ${getNameWithTypeParameter(cb, cb.name)} {`); printer.increaseIndent(); - emitSignatures(cb, "", "", printer.printLine); + emitSignatures(cb, "", ""); printer.decreaseIndent(); printer.printLine("}"); printer.printLine(""); @@ -593,7 +575,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitProperty(prefix: string, i: Browser.Interface, emitScope: EmitScope, p: Browser.Property) { - emitComments(p, printer.printLine); + emitComments(p); // Treat window.name specially because of https://github.com/Microsoft/TypeScript/issues/9850 if (p.name === "name" && i.name === "Window" && emitScope === EmitScope.All) { @@ -632,12 +614,12 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } } - function emitComments(entity: { comment?: string; deprecated?: 1 }, print: (s: string) => void) { + function emitComments(entity: { comment?: string; deprecated?: 1 }) { if (entity.comment) { - entity.comment.split('\n').forEach(print); + entity.comment.split('\n').forEach(printer.printLine); } if (entity.deprecated) { - print(`/** @deprecated */`); + printer.printLine(`/** @deprecated */`); } } @@ -651,17 +633,8 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } } - function emitMethod(prefix: string, m: Browser.Method, conflictedMembers: Set) { - function printLine(content: string) { - if (m.name && conflictedMembers.has(m.name)) { - printer.printLineToStack(content); - } - else { - printer.printLine(content); - } - } - - emitComments(m, printLine); + function emitMethod(prefix: string, m: Browser.Method) { + emitComments(m); switch (m.name) { case "createElement": return emitCreateElementOverloads(m); @@ -674,42 +647,42 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { // ignore toString() provided from browser.webidl.preprocessed.json // to prevent duplication if (m.name !== "toString") { - emitSignatures(m, prefix, m.name, printLine); + emitSignatures(m, prefix, m.name); if (m.stringifier) { - printLine("toString(): string;") + printer.printLine("toString(): string;") } } } - function emitSignature(s: Browser.Signature, prefix: string | undefined, name: string | undefined, printLine: (s: string) => void) { + function emitSignature(s: Browser.Signature, prefix: string | undefined, name: string | undefined) { const paramsString = s.param ? paramsToString(s.param) : ""; let returnType = convertDomTypeToTsType(s); returnType = s.nullable ? makeNullable(returnType) : returnType; - emitComments(s, printLine); - printLine(`${prefix || ""}${name || ""}(${paramsString}): ${returnType};`); + emitComments(s); + printer.printLine(`${prefix || ""}${name || ""}(${paramsString}): ${returnType};`); } - function emitSignatures(method: { signature?: Browser.Signature[], "override-signatures"?: string[], "additional-signatures"?: string[] }, prefix: string, name: string, printLine: (s: string) => void) { + function emitSignatures(method: { signature?: Browser.Signature[], "override-signatures"?: string[], "additional-signatures"?: string[] }, prefix: string, name: string) { if (method["override-signatures"]) { - method["override-signatures"]!.forEach(s => printLine(`${prefix}${s};`)); + method["override-signatures"]!.forEach(s => printer.printLine(`${prefix}${s};`)); } else if (method.signature) { if (method["additional-signatures"]) { - method["additional-signatures"]!.forEach(s => printLine(`${prefix}${s};`)); + method["additional-signatures"]!.forEach(s => printer.printLine(`${prefix}${s};`)); } - method.signature.forEach(sig => emitSignature(sig, prefix, name, printLine)); + method.signature.forEach(sig => emitSignature(sig, prefix, name)); } } - function emitMethods(prefix: string, emitScope: EmitScope, i: Browser.Interface, conflictedMembers: Set) { + function emitMethods(prefix: string, emitScope: EmitScope, i: Browser.Interface) { // If prefix is not empty, then this is the global declare function addEventListener, we want to override this // Otherwise, this is EventTarget.addEventListener, we want to keep that. if (i.methods) { mapToArray(i.methods.method) .filter(m => matchScope(emitScope, m) && !(prefix !== "" && (m.name === "addEventListener" || m.name === "removeEventListener"))) .sort(compareName) - .forEach(m => emitMethod(prefix, m, conflictedMembers)); + .forEach(m => emitMethod(prefix, m)); } if (i["anonymous-methods"]) { const stringifier = i["anonymous-methods"].method.find(m => m.stringifier); @@ -740,10 +713,9 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { /// Emit the properties and methods of a given interface function emitMembers(prefix: string, emitScope: EmitScope, i: Browser.Interface) { - const conflictedMembers = extendConflictsBaseTypes[i.name] ? extendConflictsBaseTypes[i.name].memberNames : new Set(); emitProperties(prefix, emitScope, i); const methodPrefix = prefix.startsWith("declare var") ? "declare function " : ""; - emitMethods(methodPrefix, emitScope, i, conflictedMembers); + emitMethods(methodPrefix, emitScope, i); if (emitScope === EmitScope.InstanceOnly) { emitIteratorForEach(i); } @@ -800,8 +772,8 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { // Emit constructor signature if (constructor) { - emitComments(constructor, printer.print); - emitSignatures(constructor, "", "new", printer.printLine); + emitComments(constructor); + emitSignatures(constructor, "", "new"); } else { printer.printLine(`new(): ${i.name};`); @@ -854,26 +826,15 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitInterfaceDeclaration(i: Browser.Interface) { - function processIName(iName: string) { - return extendConflictsBaseTypes[iName] ? `${iName}Base` : iName; - } - - const processedIName = processIName(i.name); - - if (processedIName !== i.name) { - printer.printLineToStack(`interface ${getNameWithTypeParameter(i, i.name)} extends ${processedIName} {`); - } - if (i.comment) { printer.printLine(`/** ${i.comment} */`); } - printer.print(`interface ${getNameWithTypeParameter(i, processedIName)}`); + printer.print(`interface ${getNameWithTypeParameter(i, i.name)}`); const finalExtends = [i.extends || "Object"] .concat((i.implements || []).sort()) - .filter(i => i !== "Object") - .map(processIName); + .filter(i => i !== "Object"); if (finalExtends.length) { printer.print(` extends ${finalExtends.join(", ")}`); @@ -960,7 +921,6 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitInterface(i: Browser.Interface) { - printer.clearStack(); emitInterfaceEventMap(i); emitInterfaceDeclaration(i); @@ -974,12 +934,6 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { printer.decreaseIndent(); printer.printLine("}"); printer.printLine(""); - - if (!printer.stackIsEmpty()) { - printer.printStackContent(); - printer.printLine("}"); - printer.printLine(""); - } } function emitStaticInterface(i: Browser.Interface) { @@ -1078,7 +1032,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } emitProperties("var ", EmitScope.InstanceOnly, namespace); - emitMethods("function ", EmitScope.InstanceOnly, namespace, new Set()); + emitMethods("function ", EmitScope.InstanceOnly, namespace); printer.decreaseIndent(); printer.printLine("}"); @@ -1097,7 +1051,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { mapToArray(dict.members.member) .sort(compareName) .forEach(m => { - emitComments(m, printer.printLine); + emitComments(m); printer.printLine(`${m.name}${m.required === 1 ? "" : "?"}: ${convertDomTypeToTsType(m)};`) }); } @@ -1117,7 +1071,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitTypeDef(typeDef: Browser.TypeDef) { - emitComments(typeDef, printer.printLine); + emitComments(typeDef); printer.printLine(`type ${getNameWithTypeParameter(typeDef, typeDef["new-type"])} = ${convertDomTypeToTsType(typeDef)};`); } @@ -1308,12 +1262,12 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor) { if (subtypes || methodsWithSequence.length) { const iteratorExtends = getIteratorExtends(i.iterator, subtypes); - const name = getNameWithTypeParameter(i, extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name); + const name = getNameWithTypeParameter(i, i.name); printer.printLine(""); printer.printLine(`interface ${name} ${iteratorExtends}{`); printer.increaseIndent(); - methodsWithSequence.forEach(m => emitMethod("", m, new Set())); + methodsWithSequence.forEach(m => emitMethod("", m)); if (subtypes && !iteratorExtends) { printer.printLine(`[Symbol.iterator](): IterableIterator<${stringifySingleOrTupleTypes(subtypes)}>;`);