diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 64861d798..b69899a60 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -425,19 +425,6 @@ "legacyNamespace": "WebAssembly", "overrideType": "Function | Global | Memory | Table" }, - { - "name": "Exports", - "legacyNamespace": "WebAssembly", - "type": "record", - "subtype": [ - { - "type": "DOMString" - }, - { - "type": "ExportValue" - } - ] - }, { "name": "ModuleImports", "legacyNamespace": "WebAssembly", diff --git a/inputfiles/patches/wasm-js-api.kdl b/inputfiles/patches/wasm-js-api.kdl new file mode 100644 index 000000000..8ec4446c7 --- /dev/null +++ b/inputfiles/patches/wasm-js-api.kdl @@ -0,0 +1,6 @@ +typedef Exports legacyNamespace=WebAssembly { + type record union=#true { + type DOMString + type ExportValue + } +} diff --git a/src/build/patches.ts b/src/build/patches.ts index ac72d1742..50e15d318 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -59,11 +59,14 @@ function handleSingleTypeNode(type: Node): DeepPartial { if (!isTyped) { throw new Error("Expected a type node"); } + const typeValue = type.values[0]; const subType = type.children.length > 0 ? handleTyped(type.children) : undefined; + const isUnion = typeof type.properties.union == "boolean"; return { - ...optionalMember("type", "string", type.values[0]), - subtype: subType, + ...optionalMember("type", "string", typeValue), + subtype: + isUnion && typeof subType?.type !== "string" ? subType?.type : subType, ...optionalMember("nullable", "boolean", type.properties?.nullable), }; }