mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 22:10:01 -04:00
fix eslint stuff
This commit is contained in:
parent
300b48eb4c
commit
b891e8140b
4 changed files with 31 additions and 26 deletions
|
@ -125,6 +125,7 @@ function doUnrewrite(ctx: ProxyCtx) {
|
|||
|
||||
if (!rewrites) {
|
||||
console.warn("failed to get rewrites for tag", tag);
|
||||
|
||||
return ctx.return(stringified);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,26 @@ function rewriteJsWasm(
|
|||
};
|
||||
}
|
||||
|
||||
// 1. does not work with modules
|
||||
// 2. cannot proxy import()
|
||||
// 3. disables "use strict" optimizations
|
||||
// 4. i think the global state can get clobbered somehow
|
||||
//
|
||||
// if you can ensure all the preconditions are met this is faster than full rewrites
|
||||
function rewriteJsNaiive(js: string | ArrayBuffer) {
|
||||
if (typeof js !== "string") {
|
||||
js = new TextDecoder().decode(js);
|
||||
}
|
||||
|
||||
return `
|
||||
with (${$scramjet.config.globals.wrapfn}(globalThis)) {
|
||||
|
||||
${js}
|
||||
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
function rewriteJsInner(
|
||||
js: string | Uint8Array,
|
||||
url: string | null,
|
||||
|
@ -132,23 +152,3 @@ export function rewriteJsWithMap(
|
|||
) {
|
||||
return rewriteJsInner(js, url, meta, module);
|
||||
}
|
||||
|
||||
// 1. does not work with modules
|
||||
// 2. cannot proxy import()
|
||||
// 3. disables "use strict" optimizations
|
||||
// 4. i think the global state can get clobbered somehow
|
||||
//
|
||||
// if you can ensure all the preconditions are met this is faster than full rewrites
|
||||
export function rewriteJsNaiive(js: string | ArrayBuffer) {
|
||||
if (typeof js !== "string") {
|
||||
js = new TextDecoder().decode(js);
|
||||
}
|
||||
|
||||
return `
|
||||
with (${$scramjet.config.globals.wrapfn}(globalThis)) {
|
||||
|
||||
${js}
|
||||
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -237,12 +237,12 @@ async function handleResponse(
|
|||
const maybeHeaders = responseHeaders["set-cookie"] || [];
|
||||
for (const cookie in maybeHeaders) {
|
||||
if (client) {
|
||||
let promise = swtarget.dispatch(client, {
|
||||
const promise = swtarget.dispatch(client, {
|
||||
scramjet$type: "cookie",
|
||||
cookie,
|
||||
url: url.href,
|
||||
});
|
||||
if (destination != "document" && destination != "iframe") {
|
||||
if (destination !== "document" && destination !== "iframe") {
|
||||
await promise;
|
||||
}
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ async function rewriteBody(
|
|||
} else {
|
||||
return response.body;
|
||||
}
|
||||
case "script":
|
||||
case "script": {
|
||||
let { js, tag, map } = rewriteJsWithMap(
|
||||
new Uint8Array(await response.arrayBuffer()),
|
||||
response.finalURL,
|
||||
|
@ -370,7 +370,9 @@ async function rewriteBody(
|
|||
`${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");` +
|
||||
(js instanceof Uint8Array ? new TextDecoder().decode(js) : js);
|
||||
}
|
||||
return js;
|
||||
|
||||
return js as unknown as ArrayBuffer;
|
||||
}
|
||||
case "style":
|
||||
return rewriteCss(await response.text(), meta);
|
||||
case "sharedworker":
|
||||
|
|
|
@ -43,6 +43,7 @@ export class ScramjetServiceWorker extends EventTarget {
|
|||
const cb = this.syncPool[data.scramjet$token];
|
||||
delete this.syncPool[data.scramjet$token];
|
||||
cb(data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,13 +68,14 @@ export class ScramjetServiceWorker extends EventTarget {
|
|||
}
|
||||
|
||||
async dispatch(client: Client, data: MessageW2C): Promise<MessageC2W> {
|
||||
let token = this.synctoken++;
|
||||
const token = this.synctoken++;
|
||||
let cb: (val: MessageC2W) => void;
|
||||
let promise: Promise<MessageC2W> = new Promise((r) => (cb = r));
|
||||
const promise: Promise<MessageC2W> = new Promise((r) => (cb = r));
|
||||
this.syncPool[token] = cb;
|
||||
data.scramjet$token = token;
|
||||
|
||||
client.postMessage(data);
|
||||
|
||||
return await promise;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue