925 lines
29 KiB
Plaintext
925 lines
29 KiB
Plaintext
exports[`test CanvasRenderingContext2D.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// fillRect
|
|
function(ctx: CanvasRenderingContext2D) {
|
|
ctx.fillRect(0, 0, 200, 100);
|
|
},
|
|
|
|
// moveTo
|
|
function(ctx: CanvasRenderingContext2D) {
|
|
ctx.moveTo(\'0\', \'1\'); // error: should be numbers
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// fillRect
|
|
// moveTo
|
|
// error: should be numbers
|
|
let tests = [
|
|
function(ctx: CanvasRenderingContext2D) {
|
|
ctx.fillRect(0, 0, 200, 100);
|
|
},
|
|
function(ctx: CanvasRenderingContext2D) {
|
|
ctx.moveTo(\"0\", \"1\");
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test CustomEvent.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// CustomEvent
|
|
function(document: Document) {
|
|
const event = document.createEvent(\'CustomEvent\');
|
|
event.initCustomEvent(\'butts\', true, false, { nice: 42 });
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// CustomEvent
|
|
let tests = [
|
|
function(document: Document) {
|
|
const event = document.createEvent(\"CustomEvent\");
|
|
|
|
event.initCustomEvent(\"butts\", true, false, { nice: 42 });
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test Document.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// createElement
|
|
function(document: Document) {
|
|
(document.createElement(\'canvas\'): HTMLCanvasElement);
|
|
(document.createElement(\'link\'): HTMLLinkElement);
|
|
(document.createElement(\'option\'): HTMLOptionElement);
|
|
(document.createElement(\'select\'): HTMLSelectElement);
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// createElement
|
|
let tests = [
|
|
function(document: Document) {
|
|
(document.createElement(\"canvas\"): HTMLCanvasElement);
|
|
|
|
(document.createElement(\"link\"): HTMLLinkElement);
|
|
|
|
(document.createElement(\"option\"): HTMLOptionElement);
|
|
|
|
(document.createElement(\"select\"): HTMLSelectElement);
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test Element.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// scrollIntoView
|
|
function(element: Element) {
|
|
element.scrollIntoView();
|
|
element.scrollIntoView(false);
|
|
element.scrollIntoView({});
|
|
element.scrollIntoView({ behavior: \'smooth\', block: \'end\' });
|
|
element.scrollIntoView({ block: \'end\' });
|
|
element.scrollIntoView({ behavior: \'smooth\' });
|
|
|
|
// fails
|
|
element.scrollIntoView({ behavior: \'invalid\' });
|
|
element.scrollIntoView({ block: \'invalid\' });
|
|
element.scrollIntoView(1);
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// scrollIntoView
|
|
// fails
|
|
let tests = [
|
|
function(element: Element) {
|
|
element.scrollIntoView();
|
|
|
|
element.scrollIntoView(false);
|
|
|
|
element.scrollIntoView({});
|
|
|
|
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
|
|
|
|
element.scrollIntoView({ block: \"end\" });
|
|
|
|
element.scrollIntoView({ behavior: \"smooth\" });
|
|
|
|
element.scrollIntoView({ behavior: \"invalid\" });
|
|
|
|
element.scrollIntoView({ block: \"invalid\" });
|
|
|
|
element.scrollIntoView(1);
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test HTMLCanvasElement.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// getContext
|
|
function(el: HTMLCanvasElement) {
|
|
(el.getContext(\'2d\'): ?CanvasRenderingContext2D);
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// getContext
|
|
let tests = [
|
|
function(el: HTMLCanvasElement) {
|
|
(el.getContext(\"2d\"): ?CanvasRenderingContext2D);
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test HTMLElement.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// scrollIntoView
|
|
function(element: HTMLElement) {
|
|
element.scrollIntoView();
|
|
element.scrollIntoView(false);
|
|
element.scrollIntoView({});
|
|
element.scrollIntoView({ behavior: \'smooth\', block: \'end\' });
|
|
element.scrollIntoView({ block: \'end\' });
|
|
element.scrollIntoView({ behavior: \'smooth\' });
|
|
|
|
// fails
|
|
element.scrollIntoView({ behavior: \'invalid\' });
|
|
element.scrollIntoView({ block: \'invalid\' });
|
|
element.scrollIntoView(1);
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// scrollIntoView
|
|
// fails
|
|
let tests = [
|
|
function(element: HTMLElement) {
|
|
element.scrollIntoView();
|
|
|
|
element.scrollIntoView(false);
|
|
|
|
element.scrollIntoView({});
|
|
|
|
element.scrollIntoView({ behavior: \"smooth\", block: \"end\" });
|
|
|
|
element.scrollIntoView({ block: \"end\" });
|
|
|
|
element.scrollIntoView({ behavior: \"smooth\" });
|
|
|
|
element.scrollIntoView({ behavior: \"invalid\" });
|
|
|
|
element.scrollIntoView({ block: \"invalid\" });
|
|
|
|
element.scrollIntoView(1);
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test HTMLInputElement.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// setRangeText
|
|
function(el: HTMLInputElement) {
|
|
el.setRangeText(\'foo\');
|
|
el.setRangeText(\'foo\', 123); // end is required
|
|
el.setRangeText(\'foo\', 123, 234);
|
|
el.setRangeText(\'foo\', 123, 234, \'select\');
|
|
el.setRangeText(\'foo\', 123, 234, \'bogus\'); // invalid value
|
|
}
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// setRangeText
|
|
// end is required
|
|
// invalid value
|
|
let tests = [
|
|
function(el: HTMLInputElement) {
|
|
el.setRangeText(\"foo\");
|
|
|
|
el.setRangeText(\"foo\", 123);
|
|
|
|
el.setRangeText(\"foo\", 123, 234);
|
|
|
|
el.setRangeText(\"foo\", 123, 234, \"select\");
|
|
|
|
el.setRangeText(\"foo\", 123, 234, \"bogus\");
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test URL.js 1`] = `
|
|
"/* @flow */
|
|
|
|
const a = new URL(\'http://flowtype.org/\'); // correct
|
|
const b = new URL(\'/docs\', a); // correct
|
|
const c = new URL(\'/docs\', \'http://flowtype.org/\'); // correct
|
|
|
|
const d: URLSearchParams = c.searchParams; // correct
|
|
const e: string = c.path; // not correct
|
|
const f: string = c.pathname; // correct
|
|
const g: string = c.hash; // correct
|
|
const h: string = c.host; // correct
|
|
const i: string = c.hostname; // correct
|
|
const j: string = c.href; // correct
|
|
const l: string = c.origin; // correct
|
|
const m: string = c.password; // correct
|
|
const n: string = c.pathname; // correct
|
|
const o: string = c.port; // correct
|
|
const p: string = c.protocol; // correct
|
|
const q: string = c.search; // correct
|
|
const r: string = c.username; // correct
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// not correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
// correct
|
|
const a = new URL(\"http://flowtype.org/\");
|
|
const b = new URL(\"/docs\", a);
|
|
const c = new URL(\"/docs\", \"http://flowtype.org/\");
|
|
const d: URLSearchParams = c.searchParams;
|
|
const e: string = c.path;
|
|
const f: string = c.pathname;
|
|
const g: string = c.hash;
|
|
const h: string = c.host;
|
|
const i: string = c.hostname;
|
|
const j: string = c.href;
|
|
const l: string = c.origin;
|
|
const m: string = c.password;
|
|
const n: string = c.pathname;
|
|
const o: string = c.port;
|
|
const p: string = c.protocol;
|
|
const q: string = c.search;
|
|
const r: string = c.username;
|
|
"
|
|
`;
|
|
|
|
exports[`test eventtarget.js 1`] = `
|
|
"// @flow
|
|
|
|
let listener: EventListener = function (event: Event) :void {};
|
|
|
|
let tests = [
|
|
// attachEvent
|
|
function() {
|
|
let target = new EventTarget();
|
|
(target.attachEvent(\'foo\', listener): void); // invalid, may be undefined
|
|
(target.attachEvent && target.attachEvent(\'foo\', listener): void); // valid
|
|
},
|
|
|
|
// detachEvent
|
|
function() {
|
|
let target = new EventTarget();
|
|
(target.detachEvent(\'foo\', listener): void); // invalid, may be undefined
|
|
(target.detachEvent && target.detachEvent(\'foo\', listener): void); // valid
|
|
},
|
|
|
|
function() {
|
|
window.onmessage = (event: MessageEvent) => {
|
|
(event.target: window);
|
|
};
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// attachEvent
|
|
// invalid, may be undefined
|
|
// valid
|
|
// detachEvent
|
|
// invalid, may be undefined
|
|
// valid
|
|
let listener: EventListener = function(event: Event): void {};
|
|
let tests = [
|
|
function() {
|
|
let target = new EventTarget();
|
|
|
|
(target.attachEvent(\"foo\", listener): void);
|
|
|
|
(target.attachEvent && target.attachEvent(\"foo\", listener): void);
|
|
},
|
|
function() {
|
|
let target = new EventTarget();
|
|
|
|
(target.detachEvent(\"foo\", listener): void);
|
|
|
|
(target.detachEvent && target.detachEvent(\"foo\", listener): void);
|
|
},
|
|
function() {
|
|
window.onmessage = (event: MessageEvent) => {
|
|
(event.target: window);
|
|
};
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test path2d.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// arcTo
|
|
function() {
|
|
let path = new Path2D();
|
|
(path.arcTo(0, 0, 0, 0, 10): void); // valid
|
|
(path.arcTo(0, 0, 0, 0, 10, 20, 5): void); // valid
|
|
(path.arcTo(0, 0, 0, 0, 10, \'20\', 5): void); // invalid
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// arcTo
|
|
// valid
|
|
// valid
|
|
// invalid
|
|
let tests = [
|
|
function() {
|
|
let path = new Path2D();
|
|
|
|
(path.arcTo(0, 0, 0, 0, 10): void);
|
|
|
|
(path.arcTo(0, 0, 0, 0, 10, 20, 5): void);
|
|
|
|
(path.arcTo(0, 0, 0, 0, 10, \"20\", 5): void);
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test registerElement.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// should work with Object.create()
|
|
function() {
|
|
document.registerElement(\'custom-element\', {
|
|
prototype: Object.create(HTMLElement.prototype, {
|
|
createdCallback: { value: function createdCallback () {
|
|
}},
|
|
attachedCallback: { value: function attachedCallback () {
|
|
}},
|
|
detachedCallback: { value: function detachedCallback () {
|
|
}},
|
|
attributeChangedCallback: {
|
|
value: function attributeChangedCallback (
|
|
attributeLocalName,
|
|
oldAttributeValue,
|
|
newAttributeValue,
|
|
attributeNamespace
|
|
) {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// or with Object.assign()
|
|
function() {
|
|
document.registerElement(\'custom-element\', {
|
|
prototype: Object.assign(Object.create(HTMLElement.prototype), {
|
|
createdCallback () {
|
|
},
|
|
attachedCallback () {
|
|
},
|
|
detachedCallback () {
|
|
},
|
|
attributeChangedCallback (
|
|
attributeLocalName,
|
|
oldAttributeValue,
|
|
newAttributeValue,
|
|
attributeNamespace
|
|
) {
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// should complain about invalid callback parameters
|
|
function() {
|
|
document.registerElement(\'custom-element\', {
|
|
prototype: {
|
|
attributeChangedCallback(
|
|
localName: string,
|
|
oldVal: string, // Error: This might be null
|
|
newVal: string, // Error: This might be null
|
|
namespace: string) {}
|
|
},
|
|
});
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// should work with Object.create()
|
|
// or with Object.assign()
|
|
// should complain about invalid callback parameters
|
|
// Error: This might be null
|
|
// Error: This might be null
|
|
let tests = [
|
|
function() {
|
|
document.registerElement(\"custom-element\", {
|
|
prototype: Object.create(HTMLElement.prototype, {
|
|
createdCallback: { value: function createdCallback() {} },
|
|
attachedCallback: { value: function attachedCallback() {} },
|
|
detachedCallback: { value: function detachedCallback() {} },
|
|
attributeChangedCallback: {
|
|
value: function attributeChangedCallback(
|
|
attributeLocalName,
|
|
oldAttributeValue,
|
|
newAttributeValue,
|
|
attributeNamespace
|
|
) {}
|
|
}
|
|
})
|
|
});
|
|
},
|
|
function() {
|
|
document.registerElement(\"custom-element\", {
|
|
prototype: Object.assign(Object.create(HTMLElement.prototype), {
|
|
createdCallback() {},
|
|
attachedCallback() {},
|
|
detachedCallback() {},
|
|
attributeChangedCallback(attributeLocalName,
|
|
oldAttributeValue,
|
|
newAttributeValue,
|
|
attributeNamespace) {}
|
|
})
|
|
});
|
|
},
|
|
function() {
|
|
document.registerElement(\"custom-element\", {
|
|
prototype: {
|
|
attributeChangedCallback(localName: string,
|
|
oldVal: string,
|
|
newVal: string,
|
|
namespace: string) {}
|
|
}
|
|
});
|
|
}
|
|
];
|
|
"
|
|
`;
|
|
|
|
exports[`test traversal.js 1`] = `
|
|
"// @flow
|
|
|
|
let tests = [
|
|
// basic functionality
|
|
function() {
|
|
const i: NodeIterator<*,*> = document.createNodeIterator(document.body);
|
|
const filter: NodeFilter = i.filter;
|
|
const response:
|
|
typeof NodeFilter.FILTER_ACCEPT |
|
|
typeof NodeFilter.FILTER_REJECT |
|
|
typeof NodeFilter.FILTER_SKIP =
|
|
filter.acceptNode(document.body);
|
|
},
|
|
function() {
|
|
const w: TreeWalker<*,*> = document.createTreeWalker(document.body);
|
|
const filter: NodeFilter = w.filter;
|
|
const response:
|
|
typeof NodeFilter.FILTER_ACCEPT |
|
|
typeof NodeFilter.FILTER_REJECT |
|
|
typeof NodeFilter.FILTER_SKIP =
|
|
filter.acceptNode(document.body);
|
|
},
|
|
// rootNode must be a Node
|
|
function() {
|
|
document.createNodeIterator(document.body); // valid
|
|
document.createNodeIterator({}); // invalid
|
|
},
|
|
function() {
|
|
document.createTreeWalker(document.body);
|
|
document.createTreeWalker({}); // invalid
|
|
},
|
|
// Type Parameters
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ELEMENT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Element = i.referenceNode;
|
|
const previousNode: Element | null = i.previousNode();
|
|
const nextNode: Element | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body.attributes[0];
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ATTRIBUTE);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Attr = i.referenceNode
|
|
const previousNode: Attr | null = i.previousNode();
|
|
const nextNode: Attr | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_TEXT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Text = i.referenceNode;
|
|
const previousNode: Text | null = i.previousNode();
|
|
const nextNode: Text | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_DOCUMENT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Document = i.referenceNode;
|
|
const previousNode: Document | null = i.previousNode();
|
|
const nextNode: Document | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_DOCUMENT_TYPE);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | DocumentType = i.referenceNode;
|
|
const previousNode: DocumentType | null = i.previousNode();
|
|
const nextNode: DocumentType | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.createDocumentFragment();
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_DOCUMENT_FRAGMENT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | DocumentFragment = i.referenceNode;
|
|
const previousNode: DocumentFragment | null = i.previousNode();
|
|
const nextNode: DocumentFragment | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ALL);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Node = i.referenceNode;
|
|
const previousNode: Node | null = i.previousNode();
|
|
const nextNode: Node | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ELEMENT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Element = w.currentNode;
|
|
const parentNode: Element | null = w.parentNode();
|
|
const firstChild: Element | null = w.firstChild();
|
|
const lastChild: Element | null = w.lastChild();
|
|
const previousSibling: Element | null = w.previousSibling();
|
|
const nextSibling: Element | null = w.nextSibling();
|
|
const previousNode: Element | null = w.previousNode();
|
|
const nextNode: Element | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body.attributes[0];
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ATTRIBUTE);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Attr = w.currentNode;
|
|
const parentNode: Attr | null = w.parentNode();
|
|
const firstChild: Attr | null = w.firstChild();
|
|
const lastChild: Attr | null = w.lastChild();
|
|
const previousSibling: Attr | null = w.previousSibling();
|
|
const nextSibling: Attr | null = w.nextSibling();
|
|
const previousNode: Attr | null = w.previousNode();
|
|
const nextNode: Attr | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_TEXT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Text = w.currentNode;
|
|
const parentNode: Text | null = w.parentNode();
|
|
const firstChild: Text | null = w.firstChild();
|
|
const lastChild: Text | null = w.lastChild();
|
|
const previousSibling: Text | null = w.previousSibling();
|
|
const nextSibling: Text | null = w.nextSibling();
|
|
const previousNode: Text | null = w.previousNode();
|
|
const nextNode: Text | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_DOCUMENT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Document = w.currentNode;
|
|
const parentNode: Document | null = w.parentNode();
|
|
const firstChild: Document | null = w.firstChild();
|
|
const lastChild: Document | null = w.lastChild();
|
|
const previousSibling: Document | null = w.previousSibling();
|
|
const nextSibling: Document | null = w.nextSibling();
|
|
const previousNode: Document | null = w.previousNode();
|
|
const nextNode: Document | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_DOCUMENT_TYPE);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | DocumentType = w.currentNode;
|
|
const parentNode: DocumentType | null = w.parentNode();
|
|
const firstChild: DocumentType | null = w.firstChild();
|
|
const lastChild: DocumentType | null = w.lastChild();
|
|
const previousSibling: DocumentType | null = w.previousSibling();
|
|
const nextSibling: DocumentType | null = w.nextSibling();
|
|
const previousNode: DocumentType | null = w.previousNode();
|
|
const nextNode: DocumentType | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.createDocumentFragment();
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_DOCUMENT_FRAGMENT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | DocumentFragment = w.currentNode;
|
|
const parentNode: DocumentFragment | null = w.parentNode();
|
|
const firstChild: DocumentFragment | null = w.firstChild();
|
|
const lastChild: DocumentFragment | null = w.lastChild();
|
|
const previousSibling: DocumentFragment | null = w.previousSibling();
|
|
const nextSibling: DocumentFragment | null = w.nextSibling();
|
|
const previousNode: DocumentFragment | null = w.previousNode();
|
|
const nextNode: DocumentFragment | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ALL);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Node = w.currentNode;
|
|
const parentNode: Node | null = w.parentNode();
|
|
const firstChild: Node | null = w.firstChild();
|
|
const lastChild: Node | null = w.lastChild();
|
|
const previousSibling: Node | null = w.previousSibling();
|
|
const nextSibling: Node | null = w.nextSibling();
|
|
const previousNode: Node | null = w.previousNode();
|
|
const nextNode: Node | null = w.nextNode();
|
|
},
|
|
// NodeFilterInterface
|
|
function() {
|
|
document.createNodeIterator(document.body, -1, node => NodeFilter.FILTER_ACCEPT); // valid
|
|
document.createNodeIterator(document.body, -1, node => \'accept\'); // invalid
|
|
document.createNodeIterator(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); // valid
|
|
document.createNodeIterator(document.body, -1, { accept: node => \'accept\' }); // invalid
|
|
document.createNodeIterator(document.body, -1, {}); // invalid
|
|
},
|
|
function() {
|
|
document.createTreeWalker(document.body, -1, node => NodeFilter.FILTER_ACCEPT); // valid
|
|
document.createTreeWalker(document.body, -1, node => \'accept\'); // invalid
|
|
document.createTreeWalker(document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT }); // valid
|
|
document.createTreeWalker(document.body, -1, { accept: node => \'accept\' }); // invalid
|
|
document.createTreeWalker(document.body, -1, {}); // invalid
|
|
},
|
|
];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// @flow
|
|
// basic functionality
|
|
// rootNode must be a Node
|
|
// valid
|
|
// invalid
|
|
// invalid
|
|
// Type Parameters
|
|
// NodeFilterInterface
|
|
// valid
|
|
// invalid
|
|
// valid
|
|
// invalid
|
|
// invalid
|
|
// valid
|
|
// invalid
|
|
// valid
|
|
// invalid
|
|
// invalid
|
|
let tests = [
|
|
function() {
|
|
const i: NodeIterator<*, *> = document.createNodeIterator(document.body);
|
|
const filter: NodeFilter = i.filter;
|
|
const response: typeof NodeFilter.FILTER_ACCEPT | typeof NodeFilter.FILTER_REJECT | typeof NodeFilter.FILTER_SKIP = filter.acceptNode(
|
|
document.body
|
|
);
|
|
},
|
|
function() {
|
|
const w: TreeWalker<*, *> = document.createTreeWalker(document.body);
|
|
const filter: NodeFilter = w.filter;
|
|
const response: typeof NodeFilter.FILTER_ACCEPT | typeof NodeFilter.FILTER_REJECT | typeof NodeFilter.FILTER_SKIP = filter.acceptNode(
|
|
document.body
|
|
);
|
|
},
|
|
function() {
|
|
document.createNodeIterator(document.body);
|
|
|
|
document.createNodeIterator({});
|
|
},
|
|
function() {
|
|
document.createTreeWalker(document.body);
|
|
|
|
document.createTreeWalker({});
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ELEMENT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Element = i.referenceNode;
|
|
const previousNode: Element | null = i.previousNode();
|
|
const nextNode: Element | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body.attributes[0];
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ATTRIBUTE);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Attr = i.referenceNode;
|
|
const previousNode: Attr | null = i.previousNode();
|
|
const nextNode: Attr | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_TEXT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Text = i.referenceNode;
|
|
const previousNode: Text | null = i.previousNode();
|
|
const nextNode: Text | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_DOCUMENT);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Document = i.referenceNode;
|
|
const previousNode: Document | null = i.previousNode();
|
|
const nextNode: Document | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_DOCUMENT_TYPE);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | DocumentType = i.referenceNode;
|
|
const previousNode: DocumentType | null = i.previousNode();
|
|
const nextNode: DocumentType | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.createDocumentFragment();
|
|
const i = document.createNodeIterator(
|
|
_root,
|
|
NodeFilter.SHOW_DOCUMENT_FRAGMENT
|
|
);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | DocumentFragment = i.referenceNode;
|
|
const previousNode: DocumentFragment | null = i.previousNode();
|
|
const nextNode: DocumentFragment | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const i = document.createNodeIterator(_root, NodeFilter.SHOW_ALL);
|
|
const root: typeof _root = i.root;
|
|
const referenceNode: typeof _root | Node = i.referenceNode;
|
|
const previousNode: Node | null = i.previousNode();
|
|
const nextNode: Node | null = i.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ELEMENT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Element = w.currentNode;
|
|
const parentNode: Element | null = w.parentNode();
|
|
const firstChild: Element | null = w.firstChild();
|
|
const lastChild: Element | null = w.lastChild();
|
|
const previousSibling: Element | null = w.previousSibling();
|
|
const nextSibling: Element | null = w.nextSibling();
|
|
const previousNode: Element | null = w.previousNode();
|
|
const nextNode: Element | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body.attributes[0];
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ATTRIBUTE);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Attr = w.currentNode;
|
|
const parentNode: Attr | null = w.parentNode();
|
|
const firstChild: Attr | null = w.firstChild();
|
|
const lastChild: Attr | null = w.lastChild();
|
|
const previousSibling: Attr | null = w.previousSibling();
|
|
const nextSibling: Attr | null = w.nextSibling();
|
|
const previousNode: Attr | null = w.previousNode();
|
|
const nextNode: Attr | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_TEXT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Text = w.currentNode;
|
|
const parentNode: Text | null = w.parentNode();
|
|
const firstChild: Text | null = w.firstChild();
|
|
const lastChild: Text | null = w.lastChild();
|
|
const previousSibling: Text | null = w.previousSibling();
|
|
const nextSibling: Text | null = w.nextSibling();
|
|
const previousNode: Text | null = w.previousNode();
|
|
const nextNode: Text | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_DOCUMENT);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Document = w.currentNode;
|
|
const parentNode: Document | null = w.parentNode();
|
|
const firstChild: Document | null = w.firstChild();
|
|
const lastChild: Document | null = w.lastChild();
|
|
const previousSibling: Document | null = w.previousSibling();
|
|
const nextSibling: Document | null = w.nextSibling();
|
|
const previousNode: Document | null = w.previousNode();
|
|
const nextNode: Document | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_DOCUMENT_TYPE);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | DocumentType = w.currentNode;
|
|
const parentNode: DocumentType | null = w.parentNode();
|
|
const firstChild: DocumentType | null = w.firstChild();
|
|
const lastChild: DocumentType | null = w.lastChild();
|
|
const previousSibling: DocumentType | null = w.previousSibling();
|
|
const nextSibling: DocumentType | null = w.nextSibling();
|
|
const previousNode: DocumentType | null = w.previousNode();
|
|
const nextNode: DocumentType | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.createDocumentFragment();
|
|
const w = document.createTreeWalker(
|
|
_root,
|
|
NodeFilter.SHOW_DOCUMENT_FRAGMENT
|
|
);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | DocumentFragment = w.currentNode;
|
|
const parentNode: DocumentFragment | null = w.parentNode();
|
|
const firstChild: DocumentFragment | null = w.firstChild();
|
|
const lastChild: DocumentFragment | null = w.lastChild();
|
|
const previousSibling: DocumentFragment | null = w.previousSibling();
|
|
const nextSibling: DocumentFragment | null = w.nextSibling();
|
|
const previousNode: DocumentFragment | null = w.previousNode();
|
|
const nextNode: DocumentFragment | null = w.nextNode();
|
|
},
|
|
function() {
|
|
const _root = document.body;
|
|
const w = document.createTreeWalker(_root, NodeFilter.SHOW_ALL);
|
|
const root: typeof _root = w.root;
|
|
const currentNode: typeof _root | Node = w.currentNode;
|
|
const parentNode: Node | null = w.parentNode();
|
|
const firstChild: Node | null = w.firstChild();
|
|
const lastChild: Node | null = w.lastChild();
|
|
const previousSibling: Node | null = w.previousSibling();
|
|
const nextSibling: Node | null = w.nextSibling();
|
|
const previousNode: Node | null = w.previousNode();
|
|
const nextNode: Node | null = w.nextNode();
|
|
},
|
|
function() {
|
|
document.createNodeIterator(
|
|
document.body,
|
|
-1,
|
|
node => NodeFilter.FILTER_ACCEPT
|
|
);
|
|
|
|
document.createNodeIterator(document.body, -1, node => \"accept\");
|
|
|
|
document.createNodeIterator(document.body, -1, {
|
|
accept: node => NodeFilter.FILTER_ACCEPT
|
|
});
|
|
|
|
document.createNodeIterator(document.body, -1, {
|
|
accept: node => \"accept\"
|
|
});
|
|
|
|
document.createNodeIterator(document.body, -1, {});
|
|
},
|
|
function() {
|
|
document.createTreeWalker(
|
|
document.body,
|
|
-1,
|
|
node => NodeFilter.FILTER_ACCEPT
|
|
);
|
|
|
|
document.createTreeWalker(document.body, -1, node => \"accept\");
|
|
|
|
document.createTreeWalker(document.body, -1, {
|
|
accept: node => NodeFilter.FILTER_ACCEPT
|
|
});
|
|
|
|
document.createTreeWalker(document.body, -1, { accept: node => \"accept\" });
|
|
|
|
document.createTreeWalker(document.body, -1, {});
|
|
}
|
|
];
|
|
"
|
|
`;
|