Skip to content
Open
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
1 change: 0 additions & 1 deletion inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@
"name": "StyleMedia",
"exposed": "Window",
"noInterfaceObject": true,
"deprecated": true,
"properties": {
"property": {
"type": {
Expand Down
2 changes: 2 additions & 0 deletions inputfiles/patches/cssom.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ interface CSSStyleDeclaration \
forwardExtends=CSSStyleProperties

interface CSSStyleProperties replaceReference=CSSStyleDeclaration

interface StyleMedia deprecated=#true
16 changes: 12 additions & 4 deletions src/build/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ type DeepPartial<T> = T extends object
? { [K in keyof T]?: DeepPartial<T[K]> }
: T;

function optionalMember<const T>(prop: string, type: T, value?: Value) {
function optionalMember<const T>(prop: string, type: T | T[], value?: Value) {
if (value === undefined) {
return {};
}
if (typeof value !== type) {
throw new Error(`Expected type ${value} for ${prop}`);
const types = Array.isArray(type) ? type : [type];
const valueType = typeof value;
if (!types.includes(valueType as T)) {
throw new Error(
`Expected type ${types.join(" or ")} for ${prop}, but got ${valueType}`,
);
}
return {
[prop]: value as T extends "string"
Expand Down Expand Up @@ -169,7 +173,11 @@ function handleMixinandInterfaces(

const interfaceObject = type === "interface" && {
...optionalMember("exposed", "string", node.properties?.exposed),
...optionalMember("deprecated", "string", node.properties?.deprecated),
...optionalMember(
"deprecated",
["string", "boolean"],
node.properties?.deprecated,
),
...optionalMember(
"noInterfaceObject",
"boolean",
Expand Down