Skip to content

Commit 933c22d

Browse files
authored
feat(emitter): support differing accessor types (#88)
1 parent 9a4d336 commit 933c22d

7 files changed

Lines changed: 36 additions & 15 deletions

File tree

baselines/dom.generated.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4320,7 +4320,8 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
43204320
/**
43214321
* Contains information about the current URL.
43224322
*/
4323-
location: Location;
4323+
get location(): Location;
4324+
set location(href: string | Location);
43244325
onfullscreenchange: ((this: Document, ev: Event) => any) | null;
43254326
onfullscreenerror: ((this: Document, ev: Event) => any) | null;
43264327
onpointerlockchange: ((this: Document, ev: Event) => any) | null;
@@ -16958,7 +16959,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler
1695816959
readonly innerHeight: number;
1695916960
readonly innerWidth: number;
1696016961
readonly length: number;
16961-
location: Location;
16962+
get location(): Location;
16963+
set location(href: string | Location);
1696216964
/**
1696316965
* Returns true if the location bar is visible; otherwise, returns false.
1696416966
*/

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"prettier": "^2.2.1",
5252
"print-diff": "^1.0.0",
5353
"styleless-innertext": "^1.1.2",
54-
"typescript": "^4.2.4",
54+
"typescript": "^4.3.0-dev.20210327",
5555
"webidl2": "^23.13.1"
5656
},
5757
"files": [

src/build/emitter.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,27 @@ export function emitWebIdl(
793793
if (p.optional && prefix) {
794794
pType += " | undefined";
795795
}
796-
const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : "";
797796
const optionalModifier = !p.optional || prefix ? "" : "?";
798-
printer.printLine(
799-
`${prefix}${readOnlyModifier}${p.name}${optionalModifier}: ${pType};`
800-
);
797+
if (!prefix && !p.readonly && p.putForwards) {
798+
printer.printLine(`get ${p.name}${optionalModifier}(): ${pType};`);
799+
800+
const forwardingProperty =
801+
allInterfacesMap[pType].properties?.property[p.putForwards];
802+
if (!forwardingProperty) {
803+
throw new Error("Couldn't find [PutForwards]");
804+
}
805+
const setterType = `${convertDomTypeToTsType(
806+
forwardingProperty
807+
)} | ${pType}`;
808+
printer.printLine(
809+
`set ${p.name}${optionalModifier}(${p.putForwards}: ${setterType});`
810+
);
811+
} else {
812+
const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : "";
813+
printer.printLine(
814+
`${prefix}${readOnlyModifier}${p.name}${optionalModifier}: ${pType};`
815+
);
816+
}
801817
}
802818

803819
if (p.stringifier) {

src/build/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface Property extends Typed {
3131
eventHandler?: string;
3232
readonly?: boolean;
3333
replaceable?: string;
34-
"put-forwards"?: string;
34+
putForwards?: string;
3535
stringifier?: boolean;
3636
tags?: string;
3737
"property-descriptor-not-enumerable"?: string;

src/build/widlprocess.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ function convertAttribute(
362362
exposed:
363363
getExtAttrConcatenated(attribute.extAttrs, "Exposed") ||
364364
inheritedExposure,
365+
putForwards: getExtAttr(attribute.extAttrs, "PutForwards")[0],
365366
};
366367
}
367368

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
document.location.href.padStart(3);
2+
document.location = "abc";

0 commit comments

Comments
 (0)