Skip to content

Commit c207d9f

Browse files
Bashamegasaschanaz
andauthored
Support KDL constructor (#2305)
Co-authored-by: saschanaz <saschanaz@users.noreply.github.com>
1 parent 40acd9f commit c207d9f

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

inputfiles/addedTypes.jsonc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,6 @@
9696
]
9797
}
9898
},
99-
"URLSearchParams": {
100-
"name": "URLSearchParams",
101-
"constructor": {
102-
"signature": {
103-
"0": {
104-
"param": [
105-
{
106-
"name": "init",
107-
"additionalTypes": ["URLSearchParams"]
108-
}
109-
]
110-
}
111-
}
112-
}
113-
},
11499
"NodeListOf": {
115100
"name": "NodeListOf",
116101
"typeParameters": [

inputfiles/patches/url.kdl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface URLSearchParams {
2+
constructor signatureIndex=0 {
3+
param init {
4+
additionalTypes URLSearchParams
5+
}
6+
}
7+
}

src/build/patches.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ function handleMixinAndInterfaces(
168168
const event: Event[] = [];
169169
const property: Record<string, DeepPartial<Property>> = {};
170170
let method: Record<string, DeepPartial<OverridableMethod>> = {};
171+
let constructor: DeepPartial<OverridableMethod> | undefined;
171172
let typeParameters = {};
172173

173174
for (const child of node.children) {
@@ -182,12 +183,17 @@ function handleMixinAndInterfaces(
182183
}
183184
case "method": {
184185
const methodName = string(child.values[0]);
185-
const m = handleMethod(child);
186+
const m = handleMethodAndConstructor(child);
186187
method = merge(method, {
187188
[methodName]: m,
188189
});
189190
break;
190191
}
192+
case "constructor": {
193+
const c = handleMethodAndConstructor(child, true);
194+
constructor = merge(constructor, c);
195+
break;
196+
}
191197
case "typeParameters": {
192198
typeParameters = handleTypeParameters(child);
193199
break;
@@ -199,6 +205,7 @@ function handleMixinAndInterfaces(
199205

200206
const interfaceObject = type === "interface" && {
201207
...typeParameters,
208+
...(constructor ? { constructor } : {}),
202209
...optionalMember("exposed", "string", node.properties?.exposed),
203210
...optionalMember("deprecated", "string", node.properties?.deprecated),
204211
...optionalMember(
@@ -294,11 +301,15 @@ function handleParam(node: Node) {
294301
}
295302

296303
/**
297-
* Handles a child node of type "method" and adds it to the method object.
304+
* Handles a child node of type "method" or "constructor" and adds it to the method or constructor object.
298305
* @param child The child node to handle.
306+
* @param isConstructor Whether the child node is a constructor.
299307
*/
300-
function handleMethod(child: Node): DeepPartial<OverridableMethod> {
301-
const name = string(child.values[0]);
308+
function handleMethodAndConstructor(
309+
child: Node,
310+
isConstructor: boolean = false,
311+
): DeepPartial<OverridableMethod> {
312+
const name = isConstructor ? undefined : string(child.values[0]);
302313

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

0 commit comments

Comments
 (0)