Skip to content

Commit a75338e

Browse files
authored
feat(emitter): support differing accessor types (#996)
1 parent 1fd97d1 commit a75338e

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

baselines/dom.generated.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,8 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
45384538
/**
45394539
* Contains information about the current URL.
45404540
*/
4541-
location: Location;
4541+
get location(): Location;
4542+
set location(href: string | Location);
45424543
onfullscreenchange: ((this: Document, ev: Event) => any) | null;
45434544
onfullscreenerror: ((this: Document, ev: Event) => any) | null;
45444545
onpointerlockchange: ((this: Document, ev: Event) => any) | null;
@@ -18225,7 +18226,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler
1822518226
readonly innerHeight: number;
1822618227
readonly innerWidth: number;
1822718228
readonly length: number;
18228-
location: Location;
18229+
get location(): Location;
18230+
set location(href: string | Location);
1822918231
readonly locationbar: BarProp;
1823018232
readonly menubar: BarProp;
1823118233
readonly msContentScript: ExtensionScriptApis;

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"prettier": "^2.2.1",
3535
"print-diff": "^1.0.0",
3636
"styleless-innertext": "^1.1.2",
37-
"typescript": "^4.2.3",
38-
"webidl2": "^23.13.0"
37+
"typescript": "^4.3.0-dev.20210327",
38+
"webidl2": "^23.13.1"
3939
}
4040
}

src/emitter.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -882,11 +882,27 @@ export function emitWebIdl(
882882
if (!required && prefix) {
883883
pType += " | undefined";
884884
}
885-
const readOnlyModifier =
886-
p["read-only"] === 1 && prefix === "" ? "readonly " : "";
887-
printer.printLine(
888-
`${prefix}${readOnlyModifier}${p.name}${requiredModifier}: ${pType};`
889-
);
885+
if (!prefix && !p["read-only"] && p["put-forwards"]) {
886+
printer.printLine(`get ${p.name}${requiredModifier}(): ${pType};`);
887+
888+
const forwardingProperty =
889+
allInterfacesMap[pType].properties?.property[p["put-forwards"]];
890+
if (!forwardingProperty) {
891+
throw new Error("Couldn't find [PutForwards]");
892+
}
893+
const setterType = `${convertDomTypeToTsType(
894+
forwardingProperty
895+
)} | ${pType}`;
896+
printer.printLine(
897+
`set ${p.name}${requiredModifier}(${p["put-forwards"]}: ${setterType});`
898+
);
899+
} else {
900+
const readOnlyModifier =
901+
p["read-only"] === 1 && prefix === "" ? "readonly " : "";
902+
printer.printLine(
903+
`${prefix}${readOnlyModifier}${p.name}${requiredModifier}: ${pType};`
904+
);
905+
}
890906
}
891907

892908
if (p.stringifier) {

src/widlprocess.ts

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ function convertAttribute(
357357
exposed:
358358
getExtAttrConcatenated(attribute.extAttrs, "Exposed") ||
359359
inheritedExposure,
360+
"put-forwards": getExtAttr(attribute.extAttrs, "PutForwards")[0],
360361
};
361362
}
362363

0 commit comments

Comments
 (0)