Skip to content

Commit a2f6665

Browse files
slowcheetahzloirock
authored andcommitted
Fallbacks for DOM
1 parent 41fdc1c commit a2f6665

32 files changed

+340
-110
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
declare module 'core-js/internals/web/url' {
2+
interface URL {
3+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */
4+
hash: string;
5+
6+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */
7+
host: string;
8+
9+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */
10+
hostname: string;
11+
12+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */
13+
href: string;
14+
15+
toString(): string;
16+
17+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/origin) */
18+
readonly origin: string;
19+
20+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */
21+
password: string;
22+
23+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */
24+
pathname: string;
25+
26+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */
27+
port: string;
28+
29+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */
30+
protocol: string;
31+
32+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */
33+
search: string;
34+
35+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/searchParams) */
36+
readonly searchParams: URLSearchParams;
37+
38+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */
39+
username: string;
40+
41+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/toJSON) */
42+
toJSON(): string;
43+
}
44+
45+
interface URLConstructor {
46+
prototype: URL;
47+
48+
new(url: string | URL, base?: string | URL): URL;
49+
50+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */
51+
canParse(url: string | URL, base?: string | URL): boolean;
52+
53+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) */
54+
createObjectURL(obj: any): string;
55+
56+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */
57+
parse(url: string | URL, base?: string | URL): URL | null;
58+
59+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) */
60+
revokeObjectURL(url: string): void;
61+
}
62+
63+
var URL: URLConstructor;
64+
65+
interface URLSearchParams {
66+
readonly size: number;
67+
append(name: string, value: string): void;
68+
delete(name: string, value?: string): void;
69+
get(name: string): string | null;
70+
getAll(name: string): string[];
71+
has(name: string, value?: string): boolean;
72+
set(name: string, value: string): void;
73+
sort(): void;
74+
forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void;
75+
[Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
76+
entries(): URLSearchParamsIterator<[string, string]>;
77+
keys(): URLSearchParamsIterator<string>;
78+
values(): URLSearchParamsIterator<string>;
79+
}
80+
81+
interface URLSearchParamsConstructor {
82+
prototype: URLSearchParams;
83+
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
84+
}
85+
86+
var URLSearchParams: URLSearchParamsConstructor;
87+
88+
interface URLSearchParamsIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
89+
[Symbol.iterator](): URLSearchParamsIterator<T>;
90+
}
91+
}

packages/core-js-types/src/base/pure/web/url-search-params.d.ts renamed to packages/core-js-types/src/base/pure/core-js-types/url-search-params.d.ts

File renamed without changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/// <reference types="./url-search-params.d.ts" />
2+
3+
declare namespace CoreJS {
4+
export interface CoreJSURL {
5+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */
6+
hash: string;
7+
8+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */
9+
host: string;
10+
11+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */
12+
hostname: string;
13+
14+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */
15+
href: string;
16+
17+
toString(): string;
18+
19+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/origin) */
20+
readonly origin: string;
21+
22+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */
23+
password: string;
24+
25+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */
26+
pathname: string;
27+
28+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */
29+
port: string;
30+
31+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */
32+
protocol: string;
33+
34+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */
35+
search: string;
36+
37+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/searchParams) */
38+
readonly searchParams: CoreJSURLSearchParams;
39+
40+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */
41+
username: string;
42+
43+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/toJSON) */
44+
toJSON(): string;
45+
}
46+
47+
export interface CoreJSURLConstructor {
48+
new(url: string, base?: string): CoreJSURL;
49+
50+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */
51+
canParse(url: string, base?: string): boolean;
52+
53+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) */
54+
createObjectURL(obj: any): string;
55+
56+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */
57+
parse(url: string, base?: string): CoreJSURL | null;
58+
59+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) */
60+
revokeObjectURL(url: string): void;
61+
}
62+
63+
var CoreJSURL: CoreJSURLConstructor;
64+
}
File renamed without changes.

packages/core-js-types/src/base/pure/web/url-parse.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="./url.d.ts" />
1+
/// <reference types="../core-js-types/url" />
22

33
declare namespace CoreJS {
44
export type URLParse = (url: string | CoreJSURL, base?: string | CoreJSURL) => CoreJSURL | null;
Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1 @@
1-
/// <reference types="./url-search-params.d.ts" />
2-
3-
declare namespace CoreJS {
4-
export interface CoreJSURL {
5-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */
6-
hash: string;
7-
8-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */
9-
host: string;
10-
11-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */
12-
hostname: string;
13-
14-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */
15-
href: string;
16-
17-
toString(): string;
18-
19-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/origin) */
20-
readonly origin: string;
21-
22-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */
23-
password: string;
24-
25-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */
26-
pathname: string;
27-
28-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */
29-
port: string;
30-
31-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */
32-
protocol: string;
33-
34-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */
35-
search: string;
36-
37-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/searchParams) */
38-
readonly searchParams: CoreJSURLSearchParams;
39-
40-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */
41-
username: string;
42-
43-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/toJSON) */
44-
toJSON(): string;
45-
}
46-
47-
export interface CoreJSURLConstructor {
48-
new(url: string, base?: string): CoreJSURL;
49-
50-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */
51-
canParse(url: string, base?: string): boolean;
52-
53-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) */
54-
createObjectURL(obj: any): string;
55-
56-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */
57-
parse(url: string, base?: string): CoreJSURL | null;
58-
59-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) */
60-
revokeObjectURL(url: string): void;
61-
}
62-
63-
var CoreJSURL: CoreJSURLConstructor;
64-
}
1+
/// <reference types="../core-js-types/url" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
type _DOMException = typeof globalThis extends { onmessage: any } ? {} : DOMException;
2+
interface DOMException extends Error {
3+
readonly code: number;
4+
readonly message: string;
5+
readonly name: string;
6+
readonly INDEX_SIZE_ERR: 1;
7+
readonly DOMSTRING_SIZE_ERR: 2;
8+
readonly HIERARCHY_REQUEST_ERR: 3;
9+
readonly WRONG_DOCUMENT_ERR: 4;
10+
readonly INVALID_CHARACTER_ERR: 5;
11+
readonly NO_DATA_ALLOWED_ERR: 6;
12+
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
13+
readonly NOT_FOUND_ERR: 8;
14+
readonly NOT_SUPPORTED_ERR: 9;
15+
readonly INUSE_ATTRIBUTE_ERR: 10;
16+
readonly INVALID_STATE_ERR: 11;
17+
readonly SYNTAX_ERR: 12;
18+
readonly INVALID_MODIFICATION_ERR: 13;
19+
readonly NAMESPACE_ERR: 14;
20+
readonly INVALID_ACCESS_ERR: 15;
21+
readonly VALIDATION_ERR: 16;
22+
readonly TYPE_MISMATCH_ERR: 17;
23+
readonly SECURITY_ERR: 18;
24+
readonly NETWORK_ERR: 19;
25+
readonly ABORT_ERR: 20;
26+
readonly URL_MISMATCH_ERR: 21;
27+
readonly QUOTA_EXCEEDED_ERR: 22;
28+
readonly TIMEOUT_ERR: 23;
29+
readonly INVALID_NODE_TYPE_ERR: 24;
30+
readonly DATA_CLONE_ERR: 25;
31+
}
32+
33+
declare global {
34+
interface DOMException extends _DOMException {}
35+
36+
var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T
37+
: {
38+
prototype: DOMException;
39+
new(message?: string, name?: string): DOMException;
40+
new(message?: string, options?: { name?: string; cause?: unknown }): DOMException;
41+
readonly INDEX_SIZE_ERR: 1;
42+
readonly DOMSTRING_SIZE_ERR: 2;
43+
readonly HIERARCHY_REQUEST_ERR: 3;
44+
readonly WRONG_DOCUMENT_ERR: 4;
45+
readonly INVALID_CHARACTER_ERR: 5;
46+
readonly NO_DATA_ALLOWED_ERR: 6;
47+
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
48+
readonly NOT_FOUND_ERR: 8;
49+
readonly NOT_SUPPORTED_ERR: 9;
50+
readonly INUSE_ATTRIBUTE_ERR: 10;
51+
readonly INVALID_STATE_ERR: 11;
52+
readonly SYNTAX_ERR: 12;
53+
readonly INVALID_MODIFICATION_ERR: 13;
54+
readonly NAMESPACE_ERR: 14;
55+
readonly INVALID_ACCESS_ERR: 15;
56+
readonly VALIDATION_ERR: 16;
57+
readonly TYPE_MISMATCH_ERR: 17;
58+
readonly SECURITY_ERR: 18;
59+
readonly NETWORK_ERR: 19;
60+
readonly ABORT_ERR: 20;
61+
readonly URL_MISMATCH_ERR: 21;
62+
readonly QUOTA_EXCEEDED_ERR: 22;
63+
readonly TIMEOUT_ERR: 23;
64+
readonly INVALID_NODE_TYPE_ERR: 24;
65+
readonly DATA_CLONE_ERR: 25;
66+
};
67+
}
68+
69+
export {};

packages/core-js-types/src/base/web/iterable-dom-collections.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// use only with DOM lib
2+
3+
// Fallbacks for DOM types
4+
interface Element {} // @type-options no-export
5+
interface Node {} // @type-options no-export
6+
interface HTMLOptionElement {} // @type-options no-export
7+
28
interface ArrayIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> { // @type-options no-export
39
[Symbol.iterator](): ArrayIterator<T>;
410
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare global {
2+
var self: typeof globalThis extends { onmessage: any; self: infer T } ? T : {
3+
URL?: typeof URL;
4+
};
5+
}
6+
7+
export {};
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
/// <reference types="../pure/web/url.d.ts" />
2-
3-
declare namespace CoreJS {
4-
export type URLParse = (url: string | CoreJSURL, base?: string | CoreJSURL) => CoreJSURL | null;
5-
}
1+
// empty
2+
// Moved to ../core-js-modules/url.d.ts

0 commit comments

Comments
 (0)