Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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().
*
Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 5 additions & 5 deletions baselines/ts5.5/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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().
*
Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 5 additions & 5 deletions baselines/ts5.6/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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().
*
Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 5 additions & 5 deletions baselines/ts5.9/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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().
*
Expand Down Expand Up @@ -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.
*
Expand Down
42 changes: 0 additions & 42 deletions inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
27 changes: 27 additions & 0 deletions inputfiles/patches/url.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

This comment was marked as resolved.

12 changes: 12 additions & 0 deletions inputfiles/patches/xhr.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface XMLHttpRequest {
method open signatureIndex=0 {
param url {
additionalTypes URL Location
}
}
method open signatureIndex=1 {
param url {
additionalTypes URL Location
}
}
}
22 changes: 20 additions & 2 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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);

Expand Down
31 changes: 28 additions & 3 deletions src/build/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ function deepFilterUnexposedTypes(
unexposedTypes: Set<string>,
) {
return deepClone(webidl, (o) => {
if (o.additionalTypes) {
return filterUnexposedType(o, unexposedTypes);
}
if (Array.isArray(o.type)) {
return {
...o,
Expand Down Expand Up @@ -237,13 +240,35 @@ function filterUnexposedType<T extends Browser.Typed>(
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<string>,
) {
return additionalTypes?.filter(
(additionalType) => !unexposedTypes.has(additionalType),
);
}

function filterUnexposedTypeFromUnion(
union: Browser.Typed[],
unexposedTypes: Set<string>,
Expand Down