Skip to content

Commit 9b122dc

Browse files
committed
Modify the emitter to make sure a required param doesn't accure after an optional one
1 parent e471abc commit 9b122dc

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

inputfiles/overridingTypes.jsonc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,6 @@
288288
},
289289
"interfaces": {
290290
"interface": {
291-
"GPUPipelineError": {
292-
// Web IDL optional argument can be followed by a required argument, but not in TS
293-
// TODO: Maybe do this in the emitter?
294-
"constructor": {
295-
"signature": {
296-
"0": {
297-
"param": [
298-
{
299-
"name": "message",
300-
"optional": false
301-
}
302-
]
303-
}
304-
}
305-
}
306-
},
307291
"HTMLElement": {
308292
"properties": {
309293
"property": {

src/build/widlprocess.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,29 @@ function convertCallbackFunctions(
340340
};
341341
}
342342

343-
function convertArgument(arg: webidl2.Argument): Browser.Param {
343+
function hasRequiredArgumentAfter(arr: webidl2.Argument[], i: number): boolean {
344+
for (let j = i + 1; j < arr.length; j++) {
345+
if (!arr[j].optional && !arr[j].variadic) {
346+
return true;
347+
}
348+
}
349+
return false;
350+
}
351+
352+
function convertArgument(
353+
arg: webidl2.Argument,
354+
i: number,
355+
arr: webidl2.Argument[],
356+
): Browser.Param {
344357
const idlType = convertIdlType(arg.idlType);
358+
const required = hasRequiredArgumentAfter(arr, i);
345359
if (hasExtAttr(arg.extAttrs, "LegacyNullToEmptyString")) {
346360
idlType.nullable = true;
347361
}
348362
return {
349363
name: arg.name,
350364
...idlType,
351-
optional: arg.optional,
365+
optional: !required && arg.optional,
352366
variadic: arg.variadic,
353367
allowShared: hasExtAttr(arg.extAttrs, "AllowShared"),
354368
};

0 commit comments

Comments
 (0)