Skip to content

Commit 82db6e8

Browse files
authored
Merge pull request #556 from saschanaz/dom-parsing
Add DOM Parsing and Serialization types
2 parents 5cd35f3 + 7a50cb6 commit 82db6e8

File tree

7 files changed

+54
-10
lines changed

7 files changed

+54
-10
lines changed

baselines/dom.generated.d.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -3480,7 +3480,7 @@ declare var DOMMatrixReadOnly: {
34803480
};
34813481

34823482
interface DOMParser {
3483-
parseFromString(source: string, mimeType: string): Document;
3483+
parseFromString(str: string, type: SupportedType): Document;
34843484
}
34853485

34863486
declare var DOMParser: {
@@ -4648,6 +4648,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode,
46484648
* change it.
46494649
*/
46504650
id: string;
4651+
innerHTML: string;
46514652
/**
46524653
* Returns the local name.
46534654
*/
@@ -4656,6 +4657,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode,
46564657
* Returns the namespace.
46574658
*/
46584659
readonly namespaceURI: string | null;
4660+
outerHTML: string;
46594661
/**
46604662
* Returns the namespace prefix.
46614663
*/
@@ -4775,6 +4777,10 @@ declare var Element: {
47754777
new(): Element;
47764778
};
47774779

4780+
interface ElementCSSInlineStyle {
4781+
readonly style: CSSStyleDeclaration;
4782+
}
4783+
47784784
interface ElementContentEditable {
47794785
contentEditable: string;
47804786
inputMode: string;
@@ -6016,7 +6022,7 @@ declare var HTMLDocument: {
60166022
interface HTMLElementEventMap extends GlobalEventHandlersEventMap, DocumentAndElementEventHandlersEventMap {
60176023
}
60186024

6019-
interface HTMLElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, ElementContentEditable, HTMLOrSVGElement {
6025+
interface HTMLElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, ElementContentEditable, HTMLOrSVGElement, ElementCSSInlineStyle {
60206026
accessKey: string;
60216027
readonly accessKeyLabel: string;
60226028
autocapitalize: string;
@@ -11707,6 +11713,7 @@ interface Range extends AbstractRange {
1170711713
* in the range, and 1 if the point is after the range.
1170811714
*/
1170911715
comparePoint(node: Node, offset: number): number;
11716+
createContextualFragment(fragment: string): DocumentFragment;
1171011717
deleteContents(): void;
1171111718
detach(): void;
1171211719
extractContents(): DocumentFragment;
@@ -12116,7 +12123,7 @@ declare var SVGDescElement: {
1211612123
interface SVGElementEventMap extends GlobalEventHandlersEventMap, DocumentAndElementEventHandlersEventMap {
1211712124
}
1211812125

12119-
interface SVGElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, SVGElementInstance, HTMLOrSVGElement {
12126+
interface SVGElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, SVGElementInstance, HTMLOrSVGElement, ElementCSSInlineStyle {
1212012127
/** @deprecated */
1212112128
readonly className: any;
1212212129
readonly ownerSVGElement: SVGSVGElement | null;
@@ -16708,7 +16715,7 @@ declare var XMLHttpRequestUpload: {
1670816715
};
1670916716

1671016717
interface XMLSerializer {
16711-
serializeToString(target: Node): string;
16718+
serializeToString(root: Node): string;
1671216719
}
1671316720

1671416721
declare var XMLSerializer: {
@@ -17705,6 +17712,7 @@ type ServiceWorkerUpdateViaCache = "imports" | "all" | "none";
1770517712
type ShadowRootMode = "open" | "closed";
1770617713
type SpeechRecognitionErrorCode = "no-speech" | "aborted" | "audio-capture" | "network" | "not-allowed" | "service-not-allowed" | "bad-grammar" | "language-not-supported";
1770717714
type SpeechSynthesisErrorCode = "canceled" | "interrupted" | "audio-busy" | "audio-hardware" | "network" | "synthesis-unavailable" | "synthesis-failed" | "language-unavailable" | "voice-unavailable" | "text-too-long" | "invalid-argument";
17715+
type SupportedType = "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml";
1770817716
type TextTrackKind = "subtitles" | "captions" | "descriptions" | "chapters" | "metadata";
1770917717
type TextTrackMode = "disabled" | "hidden" | "showing";
1771017718
type TouchType = "direct" | "stylus";

inputfiles/addedTypes.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@
12311231
},
12321232
"SVGElement": {
12331233
"implements": [
1234+
"ElementCSSInlineStyle",
12341235
"GlobalEventHandlers",
12351236
"DocumentAndElementEventHandlers"
12361237
]
@@ -2097,7 +2098,8 @@
20972098
{
20982099
"name": "wbr"
20992100
}
2100-
]
2101+
],
2102+
"implements": ["ElementCSSInlineStyle"]
21012103
},
21022104
"HTMLFormElement": {
21032105
"element": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[Constructor, Exposed=Window]
2+
interface DOMParser {
3+
[NewObject] Document parseFromString(DOMString str, SupportedType type);
4+
};
5+
6+
enum SupportedType {
7+
"text/html",
8+
"text/xml",
9+
"application/xml",
10+
"application/xhtml+xml",
11+
"image/svg+xml"
12+
};
13+
14+
[Constructor, Exposed=Window]
15+
interface XMLSerializer {
16+
DOMString serializeToString(Node root);
17+
};
18+
19+
partial interface Element {
20+
[CEReactions, TreatNullAs=EmptyString] attribute DOMString innerHTML;
21+
[CEReactions, TreatNullAs=EmptyString] attribute DOMString outerHTML;
22+
[CEReactions] void insertAdjacentHTML(DOMString position, DOMString text);
23+
};
24+
25+
partial interface Range {
26+
[CEReactions, NewObject] DocumentFragment createContextualFragment(DOMString fragment);
27+
};

inputfiles/idlSources.json

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"url": "https://dom.spec.whatwg.org/",
2121
"title": "DOM"
2222
},
23+
{
24+
"url": "https://w3c.github.io/DOM-Parsing/",
25+
"title": "DOM Parsing and Serialization"
26+
},
2327
{
2428
"url": "https://encoding.spec.whatwg.org/",
2529
"title": "Encoding"

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"jsdom": "^11.11.0",
1717
"node-fetch": "^2.1.1",
1818
"print-diff": "^0.1.1",
19-
"typescript": "next",
19+
"typescript": "^2.9.2",
2020
"webidl2": "^13.0.2"
2121
}
2222
}

src/fetcher.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function fetchIDL(source: IDLSource) {
5454
}
5555

5656
function processComments(dom: DocumentFragment) {
57-
const elements = Array.from(dom.querySelectorAll("dl.domintro"));
57+
const elements = dom.querySelectorAll("dl.domintro");
5858
if (!elements.length) {
5959
return undefined;
6060
}
@@ -72,6 +72,9 @@ function processComments(dom: DocumentFragment) {
7272
}
7373
}
7474
}
75+
if (!Object.keys(result).length) {
76+
return undefined;
77+
}
7578
return JSON.stringify(result, undefined, 4);
7679
}
7780

0 commit comments

Comments
 (0)