summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-04-11 17:19:36 -0400
committerGitHub <noreply@github.com>2020-04-11 17:19:36 -0400
commit637a9ecd6a3f3311601b4de36f6035ae63297f77 (patch)
tree291cf38b77bf2709b538fb4918d753c05511e1f1 /cli/js
parentda28fc1e7b4551281ad14d49c7fb396010ba0107 (diff)
dedup URLSearchParams, URL, Location, DOMStringList (#4719)
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/globals.ts4
-rw-r--r--cli/js/web/body.ts2
-rw-r--r--cli/js/web/dom_types.d.ts68
-rw-r--r--cli/js/web/dom_util.ts6
-rw-r--r--cli/js/web/fetch.ts2
-rw-r--r--cli/js/web/location.ts2
-rw-r--r--cli/js/web/url.ts5
-rw-r--r--cli/js/web/url_search_params.ts7
8 files changed, 10 insertions, 86 deletions
diff --git a/cli/js/globals.ts b/cli/js/globals.ts
index 059a70ee7..7e708d018 100644
--- a/cli/js/globals.ts
+++ b/cli/js/globals.ts
@@ -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),
diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts
index 7e398a535..472f3fda2 100644
--- a/cli/js/web/body.ts
+++ b/cli/js/web/body.ts
@@ -23,7 +23,7 @@ export type BodySource =
| Blob
| BufferSource
| domTypes.FormData
- | domTypes.URLSearchParams
+ | URLSearchParams
| domTypes.ReadableStream
| string;
diff --git a/cli/js/web/dom_types.d.ts b/cli/js/web/dom_types.d.ts
index bfdf18b8c..5ec6e8b1a 100644
--- a/cli/js/web/dom_types.d.ts
+++ b/cli/js/web/dom_types.d.ts
@@ -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;
-}
diff --git a/cli/js/web/dom_util.ts b/cli/js/web/dom_util.ts
index d12593e8e..4b9ce3f50 100644
--- a/cli/js/web/dom_util.ts
+++ b/cli/js/web/dom_util.ts
@@ -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;
}
diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts
index da6482ba3..5a5ac5cfe 100644
--- a/cli/js/web/fetch.ts
+++ b/cli/js/web/fetch.ts
@@ -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";
diff --git a/cli/js/web/location.ts b/cli/js/web/location.ts
index 9b59842b7..fe0ca2da2 100644
--- a/cli/js/web/location.ts
+++ b/cli/js/web/location.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 {
diff --git a/cli/js/web/url.ts b/cli/js/web/url.ts
index 374997a1e..374ddd252 100644
--- a/cli/js/web/url.ts
+++ b/cli/js/web/url.ts
@@ -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 {
diff --git a/cli/js/web/url_search_params.ts b/cli/js/web/url_search_params.ts
index 0e41bdbf2..221a70ab1 100644
--- a/cli/js/web/url_search_params.ts
+++ b/cli/js/web/url_search_params.ts
@@ -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;
}