mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
dedup URLSearchParams, URL, Location, DOMStringList (#4719)
This commit is contained in:
parent
da28fc1e7b
commit
637a9ecd6a
8 changed files with 10 additions and 86 deletions
|
@ -213,8 +213,8 @@ export const windowOrWorkerGlobalScopeProperties = {
|
|||
DOMException: nonEnumerable(domException.DOMExceptionImpl),
|
||||
Event: nonEnumerable(event.EventImpl),
|
||||
EventTarget: nonEnumerable(eventTarget.EventTargetImpl),
|
||||
URL: nonEnumerable(url.URL),
|
||||
URLSearchParams: nonEnumerable(urlSearchParams.URLSearchParams),
|
||||
URL: nonEnumerable(url.URLImpl),
|
||||
URLSearchParams: nonEnumerable(urlSearchParams.URLSearchParamsImpl),
|
||||
Headers: nonEnumerable(headers.Headers),
|
||||
FormData: nonEnumerable(formData.FormData),
|
||||
TextEncoder: nonEnumerable(textEncoding.TextEncoder),
|
||||
|
|
|
@ -23,7 +23,7 @@ export type BodySource =
|
|||
| Blob
|
||||
| BufferSource
|
||||
| domTypes.FormData
|
||||
| domTypes.URLSearchParams
|
||||
| URLSearchParams
|
||||
| domTypes.ReadableStream
|
||||
| string;
|
||||
|
||||
|
|
68
cli/js/web/dom_types.d.ts
vendored
68
cli/js/web/dom_types.d.ts
vendored
|
@ -47,29 +47,6 @@ export interface ProgressEventInit extends EventInit {
|
|||
total?: number;
|
||||
}
|
||||
|
||||
export class URLSearchParams {
|
||||
constructor(
|
||||
init?: string[][] | Record<string, string> | string | URLSearchParams
|
||||
);
|
||||
append(name: string, value: string): void;
|
||||
delete(name: string): void;
|
||||
get(name: string): string | null;
|
||||
getAll(name: string): string[];
|
||||
has(name: string): boolean;
|
||||
set(name: string, value: string): void;
|
||||
sort(): void;
|
||||
toString(): string;
|
||||
forEach(
|
||||
callbackfn: (value: string, key: string, parent: this) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
[Symbol.iterator](): IterableIterator<[string, string]>;
|
||||
entries(): IterableIterator<[string, string]>;
|
||||
keys(): IterableIterator<string>;
|
||||
values(): IterableIterator<string>;
|
||||
static toString(): string;
|
||||
}
|
||||
|
||||
export interface UIEventInit extends EventInit {
|
||||
detail?: number;
|
||||
// adjust Window -> Node
|
||||
|
@ -654,48 +631,3 @@ export interface ResponseConstructor {
|
|||
error(): Response;
|
||||
redirect(url: string, status?: number): Response;
|
||||
}
|
||||
|
||||
export class DOMStringList {
|
||||
readonly length: number;
|
||||
contains(string: string): boolean;
|
||||
item(index: number): string | null;
|
||||
[index: number]: string;
|
||||
[Symbol.iterator](): IterableIterator<string>;
|
||||
}
|
||||
|
||||
export class Location {
|
||||
readonly ancestorOrigins: DOMStringList;
|
||||
hash: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
href: string;
|
||||
toString(): string;
|
||||
readonly origin: string;
|
||||
pathname: string;
|
||||
port: string;
|
||||
protocol: string;
|
||||
search: string;
|
||||
assign(url: string): void;
|
||||
reload(): void;
|
||||
replace(url: string): void;
|
||||
}
|
||||
|
||||
export class URL {
|
||||
constructor(url: string, base?: string | URL);
|
||||
hash: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
href: string;
|
||||
toString(): string;
|
||||
readonly origin: string;
|
||||
password: string;
|
||||
pathname: string;
|
||||
port: string;
|
||||
protocol: string;
|
||||
search: string;
|
||||
readonly searchParams: URLSearchParams;
|
||||
username: string;
|
||||
toJSON(): string;
|
||||
static createObjectURL(object: any): string;
|
||||
static revokeObjectURL(url: string): void;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import * as domTypes from "./dom_types.d.ts";
|
||||
|
||||
export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
|
||||
export function getDOMStringList(arr: string[]): DOMStringList {
|
||||
Object.defineProperties(arr, {
|
||||
contains: {
|
||||
value(searchElement: string): boolean {
|
||||
|
@ -16,5 +14,5 @@ export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
|
|||
},
|
||||
},
|
||||
});
|
||||
return arr as string[] & domTypes.DOMStringList;
|
||||
return arr as string[] & DOMStringList;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import { read } from "../ops/io.ts";
|
|||
import { close } from "../ops/resources.ts";
|
||||
import { Buffer } from "../buffer.ts";
|
||||
import { FormData } from "./form_data.ts";
|
||||
import { URL } from "./url.ts";
|
||||
import { URLSearchParams } from "./url_search_params.ts";
|
||||
import { fetch as opFetch, FetchResponse } from "../ops/fetch.ts";
|
||||
import { DomFileImpl } from "./dom_file.ts";
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { URL } from "./url.ts";
|
||||
import { notImplemented } from "../util.ts";
|
||||
import { DOMStringList, Location } from "./dom_types.d.ts";
|
||||
import { getDOMStringList } from "./dom_util.ts";
|
||||
|
||||
export class LocationImpl implements Location {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { customInspect } from "./console.ts";
|
||||
import * as domTypes from "./dom_types.d.ts";
|
||||
import { urls, URLSearchParams } from "./url_search_params.ts";
|
||||
import { urls } from "./url_search_params.ts";
|
||||
import { getRandomValues } from "../ops/get_random_values.ts";
|
||||
|
||||
interface URLParts {
|
||||
|
@ -139,7 +138,7 @@ function resolvePathFromBase(path: string, basePath: string): string {
|
|||
/** @internal */
|
||||
export const parts = new WeakMap<URL, URLParts>();
|
||||
|
||||
export class URL implements domTypes.URL {
|
||||
export class URLImpl implements URL {
|
||||
#searchParams!: URLSearchParams;
|
||||
|
||||
[customInspect](): string {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import * as domTypes from "./dom_types.d.ts";
|
||||
import { URL, parts } from "./url.ts";
|
||||
import { parts } from "./url.ts";
|
||||
import { isIterable, requiredArguments } from "./util.ts";
|
||||
|
||||
/** @internal */
|
||||
|
@ -45,7 +44,7 @@ function handleArrayInitialization(
|
|||
}
|
||||
}
|
||||
|
||||
export class URLSearchParams implements domTypes.URLSearchParams {
|
||||
export class URLSearchParamsImpl implements URLSearchParams {
|
||||
#params: Array<[string, string]> = [];
|
||||
|
||||
constructor(init: string | string[][] | Record<string, string> = "") {
|
||||
|
@ -63,7 +62,7 @@ export class URLSearchParams implements domTypes.URLSearchParams {
|
|||
return;
|
||||
}
|
||||
|
||||
if (init instanceof URLSearchParams) {
|
||||
if (init instanceof URLSearchParamsImpl) {
|
||||
this.#params = [...init.#params];
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue