UNPKG

3.02 kBJavaScriptView Raw
1"use strict";
2// deno-lint-ignore-file no-explicit-any no-explicit-any
3var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
4 if (kind === "m") throw new TypeError("Private method is not writable");
5 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
6 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
7 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
8};
9var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
13};
14var _a, _b, _c;
15var _WorkerLocationPolyfill_url;
16// @ts-ignore: Deno doesn't know about WorkerLocation
17class WorkerLocationPolyfill {
18 constructor(href) {
19 _WorkerLocationPolyfill_url.set(this, void 0);
20 __classPrivateFieldSet(this, _WorkerLocationPolyfill_url, new URL(href), "f");
21 }
22 get hash() { return ''; }
23 get host() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").host; }
24 get hostname() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").hostname; }
25 get href() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").href; }
26 get origin() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").origin; }
27 get pathname() { return '/'; }
28 get port() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").port; }
29 get protocol() { return __classPrivateFieldGet(this, _WorkerLocationPolyfill_url, "f").protocol; }
30 get search() { return ''; }
31 toString() { return this.href; }
32}
33_WorkerLocationPolyfill_url = new WeakMap();
34function defineProperty(url, writable = false) {
35 Object.defineProperty(self, 'location', {
36 configurable: false,
37 enumerable: true,
38 writable,
39 value: new WorkerLocationPolyfill(url),
40 });
41}
42function polyfillLocation(event) {
43 // @ts-ignore: Deno doesn't know about FetchEvent
44 const _event = event;
45 defineProperty(_event.request.url, true);
46}
47if (!('location' in self)) {
48 const envLoc = (_a = (self.WORKER_LOCATION)) !== null && _a !== void 0 ? _a : ((_c = (_b = self.process) === null || _b === void 0 ? void 0 : _b.env) === null || _c === void 0 ? void 0 : _c.WORKER_LOCATION);
49 if (envLoc) {
50 defineProperty(envLoc);
51 }
52 else {
53 self.addEventListener('fetch', polyfillLocation);
54 }
55}
56//# sourceMappingURL=index.js.map
\No newline at end of file