diff options
Diffstat (limited to 'source/github-helpers/github-url.ts')
-rw-r--r-- | source/github-helpers/github-url.ts | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/source/github-helpers/github-url.ts b/source/github-helpers/github-url.ts index 139bf1a3..1966ee2a 100644 --- a/source/github-helpers/github-url.ts +++ b/source/github-helpers/github-url.ts @@ -1,6 +1,6 @@ import {getCurrentBranch} from '.'; -export default class GitHubURL extends URL { +export default class GitHubURL { // @ts-expect-error https://github.com/microsoft/TypeScript/issues/26792 user: string; // @ts-expect-error @@ -14,15 +14,22 @@ export default class GitHubURL extends URL { assign = Object.assign.bind(null, this); + private internalUrl: URL; + constructor(url: string) { - super(url); - this.pathname = super.pathname; + // Use Facade pattern instead of inheritance #3193 + this.internalUrl = new URL(url); + this.pathname = this.internalUrl.pathname; } toString() { return this.href; } + toJSON() { + return this.href; + } + private disambiguateReference(ambiguousReference: string[]): {branch: string; filePath: string} { const branch = ambiguousReference[0]; const filePathFromSearch = this.searchParams.getAll('path[]').join('/'); @@ -68,7 +75,33 @@ export default class GitHubURL extends URL { get href() { // Update the actual underlying URL - super.pathname = this.pathname; - return super.href; + this.internalUrl.pathname = this.pathname; + return this.internalUrl.href; + } + + set href(href) { + this.internalUrl.href = href; + } + + // Proxy all other getters/setters to internalUrl + + get hash(): string { + return this.internalUrl.hash; + } + + set hash(hash) { + this.internalUrl.hash = hash; + } + + get search(): string { + return this.internalUrl.search; + } + + set search(search) { + this.internalUrl.search = search; + } + + get searchParams(): URLSearchParams { + return this.internalUrl.searchParams; } } |