Skip to content

Add HTML grouping content types #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4603,6 +4603,8 @@ interface Document extends Node, GlobalEventHandlers, ParentNode, DocumentEvent
* @param tagName The name of an element.
*/
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];
/** @deprecated */
createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K];
createElement(tagName: string, options?: ElementCreationOptions): HTMLElement;
createElementNS(namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string): HTMLElement;
createElementNS(namespaceURI: "http://www.w3.org/2000/svg", qualifiedName: "a"): SVGAElement;
Expand Down Expand Up @@ -6022,10 +6024,6 @@ interface HTMLDivElement extends HTMLElement {
*/
/** @deprecated */
align: string;
/**
* Sets or retrieves whether the browser automatically performs wordwrap.
*/
noWrap: boolean;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLDivElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLDivElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -7384,7 +7382,6 @@ declare var HTMLMediaElement: {
interface HTMLMenuElement extends HTMLElement {
/** @deprecated */
compact: boolean;
type: string;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLMenuElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLMenuElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -7477,6 +7474,7 @@ declare var HTMLModElement: {
interface HTMLOListElement extends HTMLElement {
/** @deprecated */
compact: boolean;
reversed: boolean;
/**
* The starting number.
*/
Expand Down Expand Up @@ -7741,7 +7739,6 @@ interface HTMLParagraphElement extends HTMLElement {
*/
/** @deprecated */
align: string;
clear: string;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLParagraphElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLParagraphElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -16778,7 +16775,6 @@ interface HTMLElementTagNameMap {
"legend": HTMLLegendElement;
"li": HTMLLIElement;
"link": HTMLLinkElement;
"listing": HTMLPreElement;
"map": HTMLMapElement;
"mark": HTMLElement;
"marquee": HTMLMarqueeElement;
Expand Down Expand Up @@ -16836,6 +16832,10 @@ interface HTMLElementTagNameMap {
"var": HTMLElement;
"video": HTMLVideoElement;
"wbr": HTMLElement;
}

interface HTMLElementDeprecatedTagNameMap {
"listing": HTMLPreElement;
"xmp": HTMLPreElement;
}

Expand Down
81 changes: 81 additions & 0 deletions inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,80 @@
},
"no-interface-object": "1"
},
"HTMLDivElement": {
"element": [
{
"name": "div"
}
]
},
"HTMLDListElement": {
"element": [
{
"name": "dl"
}
]
},
"HTMLHRElement": {
"element": [
{
"name": "hr"
}
]
},
"HTMLLIElement": {
"element": [
{
"name": "li"
}
]
},
"HTMLMenuElement": {
"element": [
{
"name": "menu"
}
]
},
"HTMLOListElement": {
"element": [
{
"name": "ol"
}
]
},
"HTMLParagraphElement": {
"element": [
{
"name": "p"
}
]
},
"HTMLPreElement": {
"element": [
{
"name": "pre"
},
{
"name": "listing",
"deprecated": true
},
{
"name": "xmp",
"deprecated": true
}
]
},
"HTMLQuoteElement": {
"element": [
{
"name": "blockquote"
},
{
"name": "q"
}
]
},
"HTMLTableDataCellElement": {
"name": "HTMLTableDataCellElement",
"extends": "HTMLTableCellElement",
Expand Down Expand Up @@ -2153,6 +2227,13 @@
}
]
},
"HTMLUListElement": {
"element": [
{
"name": "ul"
}
]
},
"NodeSelector": {
"name": "NodeSelector",
"extends": "Object",
Expand Down
3 changes: 0 additions & 3 deletions inputfiles/comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -1517,9 +1517,6 @@
"property": {
"align": {
"comment": "/**\r\n * Sets or retrieves how the object is aligned with adjacent text.\r\n */"
},
"noWrap": {
"comment": "/**\r\n * Sets or retrieves whether the browser automatically performs wordwrap.\r\n */"
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions inputfiles/idl/HTML - Grouping content.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[Exposed=Window,
HTMLConstructor]
interface HTMLParagraphElement : HTMLElement {};

[Exposed=Window,
HTMLConstructor]
interface HTMLHRElement : HTMLElement {};

[Exposed=Window,
HTMLConstructor]
interface HTMLPreElement : HTMLElement {};

[Exposed=Window,
HTMLConstructor]
interface HTMLQuoteElement : HTMLElement {
[CEReactions] attribute USVString cite;
};

[Exposed=Window,
HTMLConstructor]
interface HTMLOListElement : HTMLElement {
[CEReactions] attribute boolean reversed;
[CEReactions] attribute long start;
[CEReactions] attribute DOMString type;
};

[Exposed=Window,
HTMLConstructor]
interface HTMLUListElement : HTMLElement {};

[Exposed=Window,
HTMLConstructor]
interface HTMLMenuElement : HTMLElement {
};

[Exposed=Window,
HTMLConstructor]
interface HTMLLIElement : HTMLElement {
[CEReactions] attribute long value;
};

[Exposed=Window,
HTMLConstructor]
interface HTMLDListElement : HTMLElement {};

[Exposed=Window,
HTMLConstructor]
interface HTMLDivElement : HTMLElement {};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"url": "https://html.spec.whatwg.org/multipage/form-elements.html",
"title": "HTML - Form elements"
},
{
"url": "https://html.spec.whatwg.org/multipage/grouping-content.html",
"title": "HTML - Grouping content"
},
{
"url": "https://html.spec.whatwg.org/multipage/obsolete.html",
"title": "HTML - Obsolete features",
Expand Down
26 changes: 21 additions & 5 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,24 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {

function getTagNameToElementNameMap() {
const htmlResult: Record<string, string> = {};
const htmlDeprecatedResult: Record<string, string> = {};
const svgResult: Record<string, string> = {};
for (const i of allNonCallbackInterfaces) {
if (i.element) {
for (const e of i.element) {
if (e.namespace === "SVG") {
svgResult[e.name] = i.name;
}
else if (e.deprecated) {
htmlDeprecatedResult[e.name] = i.name;
}
else {
htmlResult[e.name] = i.name;
}
}
}
}
return { htmlResult, svgResult };
return { htmlResult, htmlDeprecatedResult, svgResult };
}

function getExtendList(iName: string): string[] {
Expand Down Expand Up @@ -355,6 +359,8 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
function emitCreateElementOverloads(m: Browser.Method) {
if (matchSingleParamMethodSignature(m, "createElement", "Element", "string")) {
printer.printLine("createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];");
printer.printLine("/** @deprecated */");
printer.printLine("createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K];");
printer.printLine("createElement(tagName: string, options?: ElementCreationOptions): HTMLElement;");
}
}
Expand Down Expand Up @@ -389,8 +395,18 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
function emitHTMLElementTagNameMap() {
printer.printLine("interface HTMLElementTagNameMap {");
printer.increaseIndent();
for (const e of Object.keys(tagNameToEleName.htmlResult).sort()) {
const value = tagNameToEleName.htmlResult[e];
for (const [e, value] of Object.entries(tagNameToEleName.htmlResult).sort()) {
printer.printLine(`"${e.toLowerCase()}": ${value};`);
}
printer.decreaseIndent();
printer.printLine("}");
printer.printLine("");
}

function emitHTMLElementDeprecatedTagNameMap() {
printer.printLine("interface HTMLElementDeprecatedTagNameMap {");
printer.increaseIndent();
for (const [e, value] of Object.entries(tagNameToEleName.htmlDeprecatedResult).sort()) {
printer.printLine(`"${e.toLowerCase()}": ${value};`);
}
printer.decreaseIndent();
Expand All @@ -401,13 +417,12 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
function emitSVGElementTagNameMap() {
printer.printLine("interface SVGElementTagNameMap {");
printer.increaseIndent();
for (const e of Object.keys(tagNameToEleName.svgResult).sort()) {
for (const [e, value] of Object.entries(tagNameToEleName.svgResult).sort()) {
if (e in tagNameToEleName.htmlResult) {
// Skip conflicting fields with HTMLElementTagNameMap
// to be compatible with deprecated ElementTagNameMap
continue;
}
const value = tagNameToEleName.svgResult[e];
printer.printLine(`"${e}": ${value};`);
}
printer.decreaseIndent();
Expand Down Expand Up @@ -1012,6 +1027,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {

if (flavor !== Flavor.Worker) {
emitHTMLElementTagNameMap();
emitHTMLElementDeprecatedTagNameMap();
emitSVGElementTagNameMap();
emitElementTagNameMap();
emitNamedConstructors();
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export interface ParsedAttribute{
export interface Element {
name: string;
namespace?: string;
deprecated?: boolean;
"html-self-closing"?: string;
specs?: string;
}
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"target": "es2017",
"module": "commonjs",
"lib": ["es2016", "dom", "dom.iterable"],
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
Expand Down