diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 0df481561..ddc7f8e6e 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -12234,7 +12234,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/defaultView) */ - readonly defaultView: (WindowProxy & typeof globalThis) | null; + readonly defaultView: Globalized | null; /** * **`document.designMode`** controls whether the entire document is editable. Valid values are "on" and "off". According to the specification, this property is meant to default to "off". Firefox follows this standard. The earlier versions of Chrome and IE default to "inherit". Starting in Chrome 43, the default is "off" and "inherit" is no longer supported. In IE6-10, the value is capitalized. * @@ -39699,7 +39699,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ - readonly self: Window & typeof globalThis; + readonly self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -39742,7 +39742,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ - readonly window: Window & typeof globalThis; + readonly window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -41881,7 +41881,7 @@ declare var scrollbars: BarProp; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ -declare var self: Window & typeof globalThis; +declare var self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -41924,7 +41924,7 @@ declare var visualViewport: VisualViewport | null; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ -declare var window: Window & typeof globalThis; +declare var window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -42450,6 +42450,7 @@ type GLsizei = number; type GLsizeiptr = number; type GLuint = number; type GLuint64 = number; +type Globalized = T & typeof globalThis; type HTMLOrSVGImageElement = HTMLImageElement | SVGImageElement; type HTMLOrSVGScriptElement = HTMLScriptElement | SVGScriptElement; type HashAlgorithmIdentifier = AlgorithmIdentifier; diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index d10659836..b62fc77db 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -12223,7 +12223,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/defaultView) */ - readonly defaultView: (WindowProxy & typeof globalThis) | null; + readonly defaultView: Globalized | null; /** * **`document.designMode`** controls whether the entire document is editable. Valid values are "on" and "off". According to the specification, this property is meant to default to "off". Firefox follows this standard. The earlier versions of Chrome and IE default to "inherit". Starting in Chrome 43, the default is "off" and "inherit" is no longer supported. In IE6-10, the value is capitalized. * @@ -39673,7 +39673,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ - readonly self: Window & typeof globalThis; + readonly self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -39716,7 +39716,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ - readonly window: Window & typeof globalThis; + readonly window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -41855,7 +41855,7 @@ declare var scrollbars: BarProp; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ -declare var self: Window & typeof globalThis; +declare var self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -41898,7 +41898,7 @@ declare var visualViewport: VisualViewport | null; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ -declare var window: Window & typeof globalThis; +declare var window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -42424,6 +42424,7 @@ type GLsizei = number; type GLsizeiptr = number; type GLuint = number; type GLuint64 = number; +type Globalized = T & typeof globalThis; type HTMLOrSVGImageElement = HTMLImageElement | SVGImageElement; type HTMLOrSVGScriptElement = HTMLScriptElement | SVGScriptElement; type HashAlgorithmIdentifier = AlgorithmIdentifier; diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index 2e5b922e6..5a65b6325 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -12231,7 +12231,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/defaultView) */ - readonly defaultView: (WindowProxy & typeof globalThis) | null; + readonly defaultView: Globalized | null; /** * **`document.designMode`** controls whether the entire document is editable. Valid values are "on" and "off". According to the specification, this property is meant to default to "off". Firefox follows this standard. The earlier versions of Chrome and IE default to "inherit". Starting in Chrome 43, the default is "off" and "inherit" is no longer supported. In IE6-10, the value is capitalized. * @@ -39696,7 +39696,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ - readonly self: Window & typeof globalThis; + readonly self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -39739,7 +39739,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ - readonly window: Window & typeof globalThis; + readonly window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -41878,7 +41878,7 @@ declare var scrollbars: BarProp; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ -declare var self: Window & typeof globalThis; +declare var self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -41921,7 +41921,7 @@ declare var visualViewport: VisualViewport | null; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ -declare var window: Window & typeof globalThis; +declare var window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -42447,6 +42447,7 @@ type GLsizei = number; type GLsizeiptr = number; type GLuint = number; type GLuint64 = number; +type Globalized = T & typeof globalThis; type HTMLOrSVGImageElement = HTMLImageElement | SVGImageElement; type HTMLOrSVGScriptElement = HTMLScriptElement | SVGScriptElement; type HashAlgorithmIdentifier = AlgorithmIdentifier; diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index 3773a12d8..651fd2bf0 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -12231,7 +12231,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/defaultView) */ - readonly defaultView: (WindowProxy & typeof globalThis) | null; + readonly defaultView: Globalized | null; /** * **`document.designMode`** controls whether the entire document is editable. Valid values are "on" and "off". According to the specification, this property is meant to default to "off". Firefox follows this standard. The earlier versions of Chrome and IE default to "inherit". Starting in Chrome 43, the default is "off" and "inherit" is no longer supported. In IE6-10, the value is capitalized. * @@ -39696,7 +39696,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ - readonly self: Window & typeof globalThis; + readonly self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -39739,7 +39739,7 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ - readonly window: Window & typeof globalThis; + readonly window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -41878,7 +41878,7 @@ declare var scrollbars: BarProp; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self) */ -declare var self: Window & typeof globalThis; +declare var self: Globalized; /** * The **`speechSynthesis`** read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. * @@ -41921,7 +41921,7 @@ declare var visualViewport: VisualViewport | null; * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window) */ -declare var window: Window & typeof globalThis; +declare var window: Globalized; /** * **`window.alert()`** instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. * @@ -42447,6 +42447,7 @@ type GLsizei = number; type GLsizeiptr = number; type GLuint = number; type GLuint64 = number; +type Globalized = T & typeof globalThis; type HTMLOrSVGImageElement = HTMLImageElement | SVGImageElement; type HTMLOrSVGScriptElement = HTMLScriptElement | SVGScriptElement; type HashAlgorithmIdentifier = AlgorithmIdentifier; diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 1e86d1786..af78932f2 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -408,12 +408,6 @@ "onorientationchange": { "deprecated": true }, - "self": { - "overrideType": "Window & typeof globalThis" - }, - "window": { - "overrideType": "Window & typeof globalThis" - }, "pageXOffset": { // While this is indeed an alias of scrollX, it's not a vendor prefixed legacy as aliases usually are. "deprecated": false @@ -539,10 +533,6 @@ }, "properties": { "property": { - "defaultView": { - "name": "defaultView", - "overrideType": "WindowProxy & typeof globalThis" - }, "documentElement": { "name": "documentElement", "overrideType": "HTMLElement", @@ -2798,13 +2788,6 @@ } }, "WorkerGlobalScope": { - "properties": { - "property": { - "self": { - "overrideType": "WorkerGlobalScope & typeof globalThis" - } - } - }, "events": { "event": [ { diff --git a/inputfiles/patches/dom.kdl b/inputfiles/patches/dom.kdl index 146a24389..4a1652375 100644 --- a/inputfiles/patches/dom.kdl +++ b/inputfiles/patches/dom.kdl @@ -11,6 +11,14 @@ interface EventListenerObject noInterfaceObject=#true { } } +interface Document { + property defaultView { + type Globalized { + type WindowProxy + } + } +} + enum InsertPosition { beforebegin beforeend diff --git a/inputfiles/patches/html.kdl b/inputfiles/patches/html.kdl index 00b0380a4..5ef00f86a 100644 --- a/inputfiles/patches/html.kdl +++ b/inputfiles/patches/html.kdl @@ -69,8 +69,22 @@ interface HTMLInputElement { } } +interface Window { + property self type=Globalized + property window type=Globalized +} + +interface WorkerGlobalScope { + // We must declare it in overrideType, because Window doesn't exist in WebWorkers + property self overrideType="WorkerGlobalScope & typeof globalThis" +} + typedef SelectionDirection overrideType=#""forward" | "backward" | "none""# +typedef Globalized overrideType="T & typeof globalThis" { + typeParameters T default="Window" +} + dictionary StructuredSerializeOptions { member transfer { type { diff --git a/src/build/patches.ts b/src/build/patches.ts index f2484e436..ba3efae53 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -448,9 +448,25 @@ function handleMember(c: Node): DeepPartial { * @param node The typedef node to handle. */ function handleTypedef(node: Node): DeepPartial { - const typeNodes = node.children.filter((c) => c.name === "type"); + // Support type params: collect "type" and "typeParameters" child nodes + const typeNodes: Node[] = []; + let typeParameters = {}; + + for (const c of node.children) { + switch (c.name) { + case "type": + typeNodes.push(c); + break; + case "typeParameters": + typeParameters = handleTypeParameters(c); + break; + default: + throw new Error(`Unexpected child "${c.name}"`); + } + } return { name: string(node.values[0]), + ...typeParameters, ...handleTyped(typeNodes), ...optionalMember( "legacyNamespace",