diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 74c47ae0d..0cd1defdd 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -38143,13 +38143,13 @@ interface URL { declare var URL: { prototype: URL; - new(url: string | URL, base?: string | URL): URL; + new(url: string | URL | Location, base?: string | URL | Location): URL; /** * The **`URL.canParse()`** static method of the URL interface returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ - canParse(url: string | URL, base?: string | URL): boolean; + canParse(url: string | URL | Location, base?: string | URL | Location): boolean; /** * The **`createObjectURL()`** static method of the URL interface creates a string containing a blob URL pointing to the object given in the parameter. * @@ -38161,7 +38161,7 @@ declare var URL: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */ - parse(url: string | URL, base?: string | URL): URL | null; + parse(url: string | URL | Location, base?: string | URL | Location): URL | null; /** * The **`revokeObjectURL()`** static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL(). * @@ -42865,8 +42865,8 @@ interface XMLHttpRequest extends XMLHttpRequestEventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/open) */ - open(method: string, url: string | URL): void; - open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void; + open(method: string, url: string | URL | Location): void; + open(method: string, url: string | URL | Location, async: boolean, username?: string | null, password?: string | null): void; /** * The XMLHttpRequest method **`overrideMimeType()`** specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request. * diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index 61e3f2db2..0c8c31d5c 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -38117,13 +38117,13 @@ interface URL { declare var URL: { prototype: URL; - new(url: string | URL, base?: string | URL): URL; + new(url: string | URL | Location, base?: string | URL | Location): URL; /** * The **`URL.canParse()`** static method of the URL interface returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ - canParse(url: string | URL, base?: string | URL): boolean; + canParse(url: string | URL | Location, base?: string | URL | Location): boolean; /** * The **`createObjectURL()`** static method of the URL interface creates a string containing a blob URL pointing to the object given in the parameter. * @@ -38135,7 +38135,7 @@ declare var URL: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */ - parse(url: string | URL, base?: string | URL): URL | null; + parse(url: string | URL | Location, base?: string | URL | Location): URL | null; /** * The **`revokeObjectURL()`** static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL(). * @@ -42839,8 +42839,8 @@ interface XMLHttpRequest extends XMLHttpRequestEventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/open) */ - open(method: string, url: string | URL): void; - open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void; + open(method: string, url: string | URL | Location): void; + open(method: string, url: string | URL | Location, async: boolean, username?: string | null, password?: string | null): void; /** * The XMLHttpRequest method **`overrideMimeType()`** specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request. * diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index ec099f4f8..97005a267 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -38140,13 +38140,13 @@ interface URL { declare var URL: { prototype: URL; - new(url: string | URL, base?: string | URL): URL; + new(url: string | URL | Location, base?: string | URL | Location): URL; /** * The **`URL.canParse()`** static method of the URL interface returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ - canParse(url: string | URL, base?: string | URL): boolean; + canParse(url: string | URL | Location, base?: string | URL | Location): boolean; /** * The **`createObjectURL()`** static method of the URL interface creates a string containing a blob URL pointing to the object given in the parameter. * @@ -38158,7 +38158,7 @@ declare var URL: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */ - parse(url: string | URL, base?: string | URL): URL | null; + parse(url: string | URL | Location, base?: string | URL | Location): URL | null; /** * The **`revokeObjectURL()`** static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL(). * @@ -42862,8 +42862,8 @@ interface XMLHttpRequest extends XMLHttpRequestEventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/open) */ - open(method: string, url: string | URL): void; - open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void; + open(method: string, url: string | URL | Location): void; + open(method: string, url: string | URL | Location, async: boolean, username?: string | null, password?: string | null): void; /** * The XMLHttpRequest method **`overrideMimeType()`** specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request. * diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index c7be83a7a..40c5cc990 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -38140,13 +38140,13 @@ interface URL { declare var URL: { prototype: URL; - new(url: string | URL, base?: string | URL): URL; + new(url: string | URL | Location, base?: string | URL | Location): URL; /** * The **`URL.canParse()`** static method of the URL interface returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ - canParse(url: string | URL, base?: string | URL): boolean; + canParse(url: string | URL | Location, base?: string | URL | Location): boolean; /** * The **`createObjectURL()`** static method of the URL interface creates a string containing a blob URL pointing to the object given in the parameter. * @@ -38158,7 +38158,7 @@ declare var URL: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */ - parse(url: string | URL, base?: string | URL): URL | null; + parse(url: string | URL | Location, base?: string | URL | Location): URL | null; /** * The **`revokeObjectURL()`** static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL(). * @@ -42862,8 +42862,8 @@ interface XMLHttpRequest extends XMLHttpRequestEventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/open) */ - open(method: string, url: string | URL): void; - open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void; + open(method: string, url: string | URL | Location): void; + open(method: string, url: string | URL | Location, async: boolean, username?: string | null, password?: string | null): void; /** * The XMLHttpRequest method **`overrideMimeType()`** specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request. * diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index b20f538ba..8dabe6754 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1545,48 +1545,6 @@ } } }, - "URL": { - "constructor": { - "signature": { - "0": { - "param": [ - { - "name": "base", - "additionalTypes": ["URL"] - } - ] - } - } - }, - "methods": { - "method": { - "canParse": { - "signature": { - "0": { - "param": [ - { - "name": "base", - "additionalTypes": ["URL"] - } - ] - } - } - }, - "parse": { - "signature": { - "0": { - "param": [ - { - "name": "base", - "additionalTypes": ["URL"] - } - ] - } - } - } - } - } - }, "Client": { "properties": { "property": { diff --git a/inputfiles/patches/url.kdl b/inputfiles/patches/url.kdl index b4fbeb195..0bcdd93ff 100644 --- a/inputfiles/patches/url.kdl +++ b/inputfiles/patches/url.kdl @@ -5,3 +5,30 @@ interface URLSearchParams { } } } + +interface URL { + constructor signatureIndex=0 { + param url { + additionalTypes URL Location + } + param base { + additionalTypes URL Location + } + } + method canParse signatureIndex=0 { + param url { + additionalTypes URL Location + } + param base { + additionalTypes URL Location + } + } + method parse signatureIndex=0 { + param url { + additionalTypes URL Location + } + param base { + additionalTypes URL Location + } + } +} diff --git a/inputfiles/patches/xhr.kdl b/inputfiles/patches/xhr.kdl new file mode 100644 index 000000000..49ee3768a --- /dev/null +++ b/inputfiles/patches/xhr.kdl @@ -0,0 +1,12 @@ +interface XMLHttpRequest { + method open signatureIndex=0 { + param url { + additionalTypes URL Location + } + } + method open signatureIndex=1 { + param url { + additionalTypes URL Location + } + } +} diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 31e43749f..d9a33a56a 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -429,7 +429,11 @@ export function emitWebIdl( typeof obj.type === "string" ? [{ ...obj, additionalTypes: undefined }] : obj.type; - types.push(...(obj.additionalTypes ?? []).map((t) => ({ type: t }))); + types.push( + ...(obj.additionalTypes ?? []) + .filter((t) => isKnownType(t)) + .map((t) => ({ type: t })), + ); // propagate `any` const converted = types.map((t) => @@ -520,6 +524,18 @@ export function emitWebIdl( throw new Error("Unknown DOM type: " + objDomType); } + function isKnownType(type: string) { + return ( + baseTypeConversionMap.has(type) || + allInterfacesMap[type] || + allLegacyWindowAliases.includes(type) || + allCallbackFunctionsMap[type] || + allDictionariesMap[type] || + allEnumsMap[type] || + allTypedefsMap[type] + ); + } + function makeNullable(originalType: string) { switch (originalType) { case "any": @@ -795,7 +811,9 @@ export function emitWebIdl( p = resolvePromise(p); if (acceptsUrl(p)) { p = { ...p, additionalTypes: [...(p.additionalTypes ?? [])] }; - p.additionalTypes!.push("URL"); + if (!p.additionalTypes!.includes("URL")) { + p.additionalTypes!.push("URL"); + } } const pType = convertDomTypeToTsType(p); diff --git a/src/build/expose.ts b/src/build/expose.ts index 4c0c023c0..a60d45f3d 100644 --- a/src/build/expose.ts +++ b/src/build/expose.ts @@ -177,6 +177,9 @@ function deepFilterUnexposedTypes( unexposedTypes: Set, ) { return deepClone(webidl, (o) => { + if (o.additionalTypes) { + return filterUnexposedType(o, unexposedTypes); + } if (Array.isArray(o.type)) { return { ...o, @@ -237,13 +240,35 @@ function filterUnexposedType( unexposedTypes, ); if (filteredUnion.length) { - return { ...type, type: flattenType(filteredUnion) }; + return { + ...type, + type: flattenType(filteredUnion), + additionalTypes: filterAdditionalTypes( + type.additionalTypes, + unexposedTypes, + ), + }; } - } else if (type.overrideType || !unexposedTypes.has(type.type)) { - return type; + } else if (!type.overrideType && unexposedTypes.has(type.type)) { + return; + } else { + const additionalTypes = filterAdditionalTypes( + type.additionalTypes, + unexposedTypes, + ); + return additionalTypes ? { ...type, additionalTypes } : type; } } +function filterAdditionalTypes( + additionalTypes: string[] | undefined, + unexposedTypes: Set, +) { + return additionalTypes?.filter( + (additionalType) => !unexposedTypes.has(additionalType), + ); +} + function filterUnexposedTypeFromUnion( union: Browser.Typed[], unexposedTypes: Set,