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
15 changes: 0 additions & 15 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,6 @@
]
}
},
"URLSearchParams": {
"name": "URLSearchParams",
"constructor": {
"signature": {
"0": {
"param": [
{
"name": "init",
"additionalTypes": ["URLSearchParams"]
}
]
}
}
}
},
"NodeListOf": {
"name": "NodeListOf",
"typeParameters": [
Expand Down
7 changes: 7 additions & 0 deletions inputfiles/patches/url.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface URLSearchParams {
constructor signatureIndex=0 {
param init {
additionalTypes URLSearchParams
}
}
}
19 changes: 15 additions & 4 deletions src/build/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function handleMixinAndInterfaces(
const event: Event[] = [];
const property: Record<string, DeepPartial<Property>> = {};
let method: Record<string, DeepPartial<OverridableMethod>> = {};
let constructor: DeepPartial<OverridableMethod> | undefined;
let typeParameters = {};

for (const child of node.children) {
Expand All @@ -182,12 +183,17 @@ function handleMixinAndInterfaces(
}
case "method": {
const methodName = string(child.values[0]);
const m = handleMethod(child);
const m = handleMethodAndConstructor(child);
method = merge(method, {
[methodName]: m,
});
break;
}
case "constructor": {
const c = handleMethodAndConstructor(child, true);
constructor = merge(constructor, c);
break;
}
case "typeParameters": {
typeParameters = handleTypeParameters(child);
break;
Expand All @@ -199,6 +205,7 @@ function handleMixinAndInterfaces(

const interfaceObject = type === "interface" && {
...typeParameters,
...(constructor ? { constructor } : {}),
...optionalMember("exposed", "string", node.properties?.exposed),
...optionalMember("deprecated", "string", node.properties?.deprecated),
...optionalMember(
Expand Down Expand Up @@ -294,11 +301,15 @@ function handleParam(node: Node) {
}

/**
* Handles a child node of type "method" and adds it to the method object.
* Handles a child node of type "method" or "constructor" and adds it to the method or constructor object.
* @param child The child node to handle.
* @param isConstructor Whether the child node is a constructor.
*/
function handleMethod(child: Node): DeepPartial<OverridableMethod> {
const name = string(child.values[0]);
function handleMethodAndConstructor(
child: Node,
isConstructor: boolean = false,
): DeepPartial<OverridableMethod> {
const name = isConstructor ? undefined : string(child.values[0]);

let typeNode: Node | undefined;
const params: Partial<Param>[] = [];
Expand Down