refactor(service-worker): make second parameter to `Adapter#parseUrl()` optional (#27080)

PR Close #27080
This commit is contained in:
George Kalpakas 2019-03-20 23:29:14 +02:00 committed by Matias Niemelä
parent 41737bb4d3
commit b3dda0ebc1
3 changed files with 3 additions and 4 deletions

View File

@ -43,7 +43,7 @@ export class Adapter {
/**
* Extract the pathname of a URL.
*/
parseUrl(url: string, relativeTo: string): {origin: string, path: string} {
parseUrl(url: string, relativeTo?: string): {origin: string, path: string} {
const parsed = new URL(url, relativeTo);
return {origin: parsed.origin, path: parsed.pathname};
}

View File

@ -69,8 +69,7 @@ export abstract class AssetGroup {
// Determine the origin from the registration scope. This is used to differentiate between
// relative and absolute URLs.
this.origin =
this.adapter.parseUrl(this.scope.registration.scope, this.scope.registration.scope).origin;
this.origin = this.adapter.parseUrl(this.scope.registration.scope).origin;
}
async cacheStatus(url: string): Promise<UpdateCacheStatus> {

View File

@ -175,7 +175,7 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context
}, new MockHeaders());
}
parseUrl(url: string, relativeTo: string): {origin: string, path: string} {
parseUrl(url: string, relativeTo?: string): {origin: string, path: string} {
if (typeof URL === 'function') {
const obj = new URL(url, relativeTo);
return {origin: obj.origin, path: obj.pathname};