refactor(service-worker): make second parameter to `Adapter#parseUrl()` optional (#27080)
PR Close #27080
This commit is contained in:
parent
41737bb4d3
commit
b3dda0ebc1
|
@ -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};
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in New Issue