diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 4e83a117f..b258c6c08 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -96,21 +96,6 @@ ] } }, - "URLSearchParams": { - "name": "URLSearchParams", - "constructor": { - "signature": { - "0": { - "param": [ - { - "name": "init", - "additionalTypes": ["URLSearchParams"] - } - ] - } - } - } - }, "NodeListOf": { "name": "NodeListOf", "typeParameters": [ diff --git a/inputfiles/patches/url.kdl b/inputfiles/patches/url.kdl new file mode 100644 index 000000000..b4fbeb195 --- /dev/null +++ b/inputfiles/patches/url.kdl @@ -0,0 +1,7 @@ +interface URLSearchParams { + constructor signatureIndex=0 { + param init { + additionalTypes URLSearchParams + } + } +} diff --git a/src/build/patches.ts b/src/build/patches.ts index 26368e585..75bb59c83 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -168,6 +168,7 @@ function handleMixinAndInterfaces( const event: Event[] = []; const property: Record> = {}; let method: Record> = {}; + let constructor: DeepPartial | undefined; let typeParameters = {}; for (const child of node.children) { @@ -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; @@ -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( @@ -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 { - const name = string(child.values[0]); +function handleMethodAndConstructor( + child: Node, + isConstructor: boolean = false, +): DeepPartial { + const name = isConstructor ? undefined : string(child.values[0]); let typeNode: Node | undefined; const params: Partial[] = [];