diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 32683a28b..ffb46c24d 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -288,22 +288,6 @@ }, "interfaces": { "interface": { - "GPUPipelineError": { - // Web IDL optional argument can be followed by a required argument, but not in TS - // TODO: Maybe do this in the emitter? - "constructor": { - "signature": { - "0": { - "param": [ - { - "name": "message", - "optional": false - } - ] - } - } - } - }, "HTMLElement": { "properties": { "property": { diff --git a/src/build/widlprocess.ts b/src/build/widlprocess.ts index b7fc1c5e6..54d81a29f 100644 --- a/src/build/widlprocess.ts +++ b/src/build/widlprocess.ts @@ -340,15 +340,29 @@ function convertCallbackFunctions( }; } -function convertArgument(arg: webidl2.Argument): Browser.Param { +function hasRequiredArgumentAfter(arr: webidl2.Argument[], i: number): boolean { + for (let j = i + 1; j < arr.length; j++) { + if (!arr[j].optional && !arr[j].variadic) { + return true; + } + } + return false; +} + +function convertArgument( + arg: webidl2.Argument, + i: number, + arr: webidl2.Argument[], +): Browser.Param { const idlType = convertIdlType(arg.idlType); + const required = hasRequiredArgumentAfter(arr, i); if (hasExtAttr(arg.extAttrs, "LegacyNullToEmptyString")) { idlType.nullable = true; } return { name: arg.name, ...idlType, - optional: arg.optional, + optional: !required && arg.optional, variadic: arg.variadic, allowShared: hasExtAttr(arg.extAttrs, "AllowShared"), };