From b3dda0ebc142c92e8f32131fb7772b083e3a85d3 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 20 Mar 2019 23:29:14 +0200 Subject: [PATCH] refactor(service-worker): make second parameter to `Adapter#parseUrl()` optional (#27080) PR Close #27080 --- packages/service-worker/worker/src/adapter.ts | 2 +- packages/service-worker/worker/src/assets.ts | 3 +-- packages/service-worker/worker/testing/scope.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/service-worker/worker/src/adapter.ts b/packages/service-worker/worker/src/adapter.ts index dfd30be040..2e2847d62e 100644 --- a/packages/service-worker/worker/src/adapter.ts +++ b/packages/service-worker/worker/src/adapter.ts @@ -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}; } diff --git a/packages/service-worker/worker/src/assets.ts b/packages/service-worker/worker/src/assets.ts index 8776eb1973..19843818f3 100644 --- a/packages/service-worker/worker/src/assets.ts +++ b/packages/service-worker/worker/src/assets.ts @@ -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 { diff --git a/packages/service-worker/worker/testing/scope.ts b/packages/service-worker/worker/testing/scope.ts index f357f4da41..265df3c3d6 100644 --- a/packages/service-worker/worker/testing/scope.ts +++ b/packages/service-worker/worker/testing/scope.ts @@ -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};