Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(emitter): support differing accessor types #996

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
26 changes: 21 additions & 5 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/widlprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ function convertAttribute(
exposed:
getExtAttrConcatenated(attribute.extAttrs, "Exposed") ||
inheritedExposure,
"put-forwards": getExtAttr(attribute.extAttrs, "PutForwards")[0],
};
}

Expand Down