From 24f7618fb811d956708e901a9780217386bc1eca Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 28 Mar 2021 01:29:28 +0100 Subject: [PATCH] feat(emitter): support differing accessor types --- baselines/dom.generated.d.ts | 6 ++++-- package.json | 4 ++-- src/emitter.ts | 26 +++++++++++++++++++++----- src/widlprocess.ts | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index bbede0481..1a8c1c6ee 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -4538,7 +4538,8 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad /** * Contains information about the current URL. */ - location: Location; + get location(): Location; + set location(href: string | Location); onfullscreenchange: ((this: Document, ev: Event) => any) | null; onfullscreenerror: ((this: Document, ev: Event) => any) | null; onpointerlockchange: ((this: Document, ev: Event) => any) | null; @@ -18225,7 +18226,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler readonly innerHeight: number; readonly innerWidth: number; readonly length: number; - location: Location; + get location(): Location; + set location(href: string | Location); readonly locationbar: BarProp; readonly menubar: BarProp; readonly msContentScript: ExtensionScriptApis; diff --git a/package.json b/package.json index b20ebb5f0..50b76472e 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "prettier": "^2.2.1", "print-diff": "^1.0.0", "styleless-innertext": "^1.1.2", - "typescript": "^4.2.3", - "webidl2": "^23.13.0" + "typescript": "^4.3.0-dev.20210327", + "webidl2": "^23.13.1" } } diff --git a/src/emitter.ts b/src/emitter.ts index ccc337c32..1e115218e 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -882,11 +882,27 @@ export function emitWebIdl( if (!required && prefix) { pType += " | undefined"; } - const readOnlyModifier = - p["read-only"] === 1 && prefix === "" ? "readonly " : ""; - printer.printLine( - `${prefix}${readOnlyModifier}${p.name}${requiredModifier}: ${pType};` - ); + if (!prefix && !p["read-only"] && p["put-forwards"]) { + printer.printLine(`get ${p.name}${requiredModifier}(): ${pType};`); + + const forwardingProperty = + allInterfacesMap[pType].properties?.property[p["put-forwards"]]; + if (!forwardingProperty) { + throw new Error("Couldn't find [PutForwards]"); + } + const setterType = `${convertDomTypeToTsType( + forwardingProperty + )} | ${pType}`; + printer.printLine( + `set ${p.name}${requiredModifier}(${p["put-forwards"]}: ${setterType});` + ); + } else { + const readOnlyModifier = + p["read-only"] === 1 && prefix === "" ? "readonly " : ""; + printer.printLine( + `${prefix}${readOnlyModifier}${p.name}${requiredModifier}: ${pType};` + ); + } } if (p.stringifier) { diff --git a/src/widlprocess.ts b/src/widlprocess.ts index 39db9325c..ca79fa224 100644 --- a/src/widlprocess.ts +++ b/src/widlprocess.ts @@ -357,6 +357,7 @@ function convertAttribute( exposed: getExtAttrConcatenated(attribute.extAttrs, "Exposed") || inheritedExposure, + "put-forwards": getExtAttr(attribute.extAttrs, "PutForwards")[0], }; }