Skip to content

Commit

Permalink
Make a few DOM properties nullable and IDL classes iterable
Browse files Browse the repository at this point in the history
Summary:
These DOM properties are definitely nullable, though in the average case they probably exist. I assume it's best for the type definitions to cover all the possibilities.

For the iterability, Chome added these in a few releases ago and the next release of core-js should include polyfill logic for them. More info in zloirock/core-js#249
Closes #3127

Differential Revision: D4388268

Pulled By: gabelevi

fbshipit-source-id: 282238b38f82fb71db87f88eb7f9583c20286724
  • Loading branch information
loganfsmyth authored and facebook-github-bot committed Jan 6, 2017
1 parent 9c5de9a commit 9c2c536
Show file tree
Hide file tree
Showing 3 changed files with 8,400 additions and 1,285 deletions.
6 changes: 6 additions & 0 deletions lib/cssom.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ declare class StyleSheet {
}

declare class StyleSheetList {
@@iterator(): Iterator<StyleSheet>;
length: number;
[index: number]: StyleSheet;
}

declare class MediaList {
@@iterator(): Iterator<string>;
mediaText: string;
length: number;
item(index: number): ?string;
Expand Down Expand Up @@ -63,11 +65,14 @@ declare class CSSRule {
}

declare class CSSRuleList {
@@iterator(): Iterator<CSSRule>;
length: number;
item(index: number): ?CSSRule;
[index: number]: CSSRule;
}

declare class CSSStyleDeclaration {
@@iterator(): Iterator<string>;
/* DOM CSS Properties */
alignContent: string;
alignItems: string;
Expand Down Expand Up @@ -368,6 +373,7 @@ declare class CSSStyleDeclaration {
getPropertyPriority(property: string): string;
getPropertyValue(property:string): string;
item(index: number): string;
[index: number]: string;
length: number;
parentRule: CSSRule;
removeProperty(property: string): string;
Expand Down
44 changes: 31 additions & 13 deletions lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare class DataTransfer {
}

declare class DataTransferItemList {
@@iterator(): Iterator<DataTransferItem>;
length: number; // readonly
[index: number]: DataTransferItem;
add(data: string, type: string): ?DataTransferItem;
Expand Down Expand Up @@ -347,6 +348,7 @@ declare class Touch {
// TouchList#item(index) will return null if n > #length. Should #item's
// return type just been Touch?
declare class TouchList {
@@iterator(): Iterator<Touch>;
length: number,
item(index: number): null | Touch,
[index: number]: Touch,
Expand Down Expand Up @@ -423,9 +425,15 @@ declare class NodeList<T> {
length: number;
item(index: number): T;
[index: number]: T;

forEach(callbackfn: (value: T, index: number, list: NodeList<T>) => any, thisArg?: any): void;
entries(): Iterator<[number, T]>;
keys(): Iterator<number>;
values(): Iterator<T>;
}

declare class NamedNodeMap {
@@iterator(): Iterator<Attr>;
length: number;
removeNamedItemNS(namespaceURI: string, localName: string): Attr;
item(index: number): Attr;
Expand All @@ -440,7 +448,7 @@ declare class NamedNodeMap {
declare class Attr extends Node {
isId: boolean;
specified: boolean;
ownerElement: Element;
ownerElement: Element | null;
value: string;
name: string;
namespaceURI: string | null;
Expand Down Expand Up @@ -494,7 +502,7 @@ declare class Document extends Node {
adoptNode<T: Node>(source: T): T;
anchors: HTMLCollection<HTMLAnchorElement>;
applets: HTMLCollection<HTMLAppletElement>;
body: HTMLElement;
body: HTMLElement | null;
characterSet: string;
close(): void;
cookie: string;
Expand Down Expand Up @@ -534,14 +542,14 @@ declare class Document extends Node {
createElementNS(namespaceURI: string | null, qualifiedName: string): Element;
createTextNode(data: string): Text;
currentScript: HTMLScriptElement | null;
doctype: DocumentType;
documentElement: HTMLElement;
doctype: DocumentType | null;
documentElement: HTMLElement | null;
documentMode: number;
domain: string | null;
embeds: HTMLCollection<HTMLEmbedElement>;
execCommand(cmdID: string, showUI?: boolean, value?: any): boolean;
forms: HTMLCollection<HTMLFormElement>;
getElementById(elementId: string): HTMLElement;
getElementById(elementId: string): HTMLElement | null;
getElementsByClassName(classNames: string): HTMLCollection<HTMLElement>;
getElementsByName(elementName: string): HTMLCollection<HTMLElement>;
getElementsByTagName(name: 'a'): HTMLCollection<HTMLAnchorElement>;
Expand Down Expand Up @@ -600,7 +608,7 @@ declare class Document extends Node {
getElementsByTagNameNS(namespaceURI: string | null, localName: 'tr'): HTMLCollection<HTMLTableRowElement>;
getElementsByTagNameNS(namespaceURI: string | null, localName: 'td' | 'th'): HTMLCollection<HTMLTableCellElement>;
getElementsByTagNameNS(namespaceURI: string | null, localName: string): HTMLCollection<HTMLElement>;
head: HTMLElement;
head: HTMLElement | null;
images: HTMLCollection<HTMLImageElement>;
implementation: DOMImplementation;
importNode<T: Node>(importedNode: T, deep: boolean): T;
Expand All @@ -625,7 +633,7 @@ declare class Document extends Node {
getSelection(): Selection | null;

// 6.4.6 Focus management APIs
activeElement: HTMLElement;
activeElement: HTMLElement | null;
hasFocus(): boolean;

// extension
Expand Down Expand Up @@ -840,12 +848,18 @@ declare var document: Document;
// TODO: HTMLDocument

declare class DOMTokenList {
@@iterator(): Iterator<string>;
length: number;
item(index: number): string;
contains(token: string): boolean;
add(token: string): void;
remove(token: string): void;
toggle(token: string): boolean;

forEach(callbackfn: (value: string, index: number, list: DOMTokenList) => any, thisArg?: any): void;
entries(): Iterator<[number, string]>;
keys(): Iterator<number>;
values(): Iterator<string>;
}


Expand All @@ -869,7 +883,7 @@ declare class Element extends Node {
namespaceURI: ?string;
nextElementSibling: ?Element;
outerHTML: string;
prefix: string;
prefix: string | null;
previousElementSibling: ?Element;
scrollHeight: number;
scrollLeft: number;
Expand All @@ -881,9 +895,9 @@ declare class Element extends Node {
dispatchEvent(event: Event): bool;

getAttribute(name?: string): ?string;
getAttributeNS(namespaceURI: string | null, localName: string): string;
getAttributeNode(name: string): Attr;
getAttributeNodeNS(namespaceURI: string | null, localName: string): Attr;
getAttributeNS(namespaceURI: string | null, localName: string): string | null;
getAttributeNode(name: string): Attr | null;
getAttributeNodeNS(namespaceURI: string | null, localName: string): Attr | null;
getBoundingClientRect(): ClientRect;
getClientRects(): ClientRect[];
getElementsByClassName(names: string): HTMLCollection<HTMLElement>;
Expand Down Expand Up @@ -961,8 +975,8 @@ declare class Element extends Node {
scrollIntoView(arg?: (boolean | { behavior?: ('auto' | 'instant' | 'smooth'), block?: ('start' | 'end') })): void;
setAttribute(name?: string, value?: string): void;
setAttributeNS(namespaceURI: string | null, qualifiedName: string, value: string): void;
setAttributeNode(newAttr: Attr): Attr;
setAttributeNodeNS(newAttr: Attr): Attr;
setAttributeNode(newAttr: Attr): Attr | null;
setAttributeNodeNS(newAttr: Attr): Attr | null;
setPointerCapture(pointerId: string): void;
shadowRoot?: ShadowRoot;
slot?: string;
Expand Down Expand Up @@ -2231,6 +2245,7 @@ declare class HTMLCanvasElement extends HTMLElement {
}

declare class HTMLFormElement extends HTMLElement {
@@iterator(): Iterator<HTMLElement>;
[name: string]: any;
acceptCharset: string;
action: string;
Expand Down Expand Up @@ -2359,6 +2374,7 @@ declare class TextTrackCue extends EventTarget {
}

declare class TextTrackCueList {
@@iterator(): Iterator<TextTrackCue>;
length: number;
[index: number]: TextTrackCue;
getCueById(id: string): ?TextTrackCue;
Expand Down Expand Up @@ -2618,6 +2634,7 @@ declare class HTMLSelectElement extends HTMLElement {
}

declare class HTMLOptionsCollection {
@@iterator(): Iterator<Node>;
length: number;
item(index: number): Node;
namedItem(name: string): Node;
Expand Down Expand Up @@ -2862,6 +2879,7 @@ declare class SourceBuffer extends EventTarget {
}

declare class SourceBufferList extends EventTarget {
@@iterator(): Iterator<SourceBuffer>;
[index: number]: SourceBuffer;
length: number;
}
Expand Down
Loading

0 comments on commit 9c2c536

Please sign in to comment.