From b0e5c13a0cce40501a7d0fcbd822d6fa0cf87e10 Mon Sep 17 00:00:00 2001 From: Bashamega Date: Sun, 21 Dec 2025 07:11:14 +0200 Subject: [PATCH 1/2] Support constructor --- inputfiles/addedTypes.jsonc | 15 --------------- inputfiles/patches/url.kdl | 7 +++++++ src/build/patches.ts | 21 +++++++++++++++++---- 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 inputfiles/patches/url.kdl 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..ac9ebede5 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,19 @@ 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": { + if (constructor) { + throw new Error(`Multiple constructors found in ${type} "${name}"`); + } + constructor = handleMethodAndConstructor(child, true); + break; + } case "typeParameters": { typeParameters = handleTypeParameters(child); break; @@ -199,6 +207,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 +303,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[] = []; From 25a4b77c95e07bde88be78ccf9fed49aecb8fbdb Mon Sep 17 00:00:00 2001 From: Bashamega Date: Mon, 22 Dec 2025 12:11:40 +0200 Subject: [PATCH 2/2] Support multiple --- src/build/patches.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/build/patches.ts b/src/build/patches.ts index ac9ebede5..75bb59c83 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -190,10 +190,8 @@ function handleMixinAndInterfaces( break; } case "constructor": { - if (constructor) { - throw new Error(`Multiple constructors found in ${type} "${name}"`); - } - constructor = handleMethodAndConstructor(child, true); + const c = handleMethodAndConstructor(child, true); + constructor = merge(constructor, c); break; } case "typeParameters": {