fix eslint stuff

This commit is contained in:
Percs 2025-03-11 00:25:31 -05:00
parent 300b48eb4c
commit b891e8140b
4 changed files with 31 additions and 26 deletions

View file

@ -125,6 +125,7 @@ function doUnrewrite(ctx: ProxyCtx) {
if (!rewrites) { if (!rewrites) {
console.warn("failed to get rewrites for tag", tag); console.warn("failed to get rewrites for tag", tag);
return ctx.return(stringified); return ctx.return(stringified);
} }

View file

@ -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( function rewriteJsInner(
js: string | Uint8Array, js: string | Uint8Array,
url: string | null, url: string | null,
@ -132,23 +152,3 @@ export function rewriteJsWithMap(
) { ) {
return rewriteJsInner(js, url, meta, module); 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}
}
`;
}

View file

@ -237,12 +237,12 @@ async function handleResponse(
const maybeHeaders = responseHeaders["set-cookie"] || []; const maybeHeaders = responseHeaders["set-cookie"] || [];
for (const cookie in maybeHeaders) { for (const cookie in maybeHeaders) {
if (client) { if (client) {
let promise = swtarget.dispatch(client, { const promise = swtarget.dispatch(client, {
scramjet$type: "cookie", scramjet$type: "cookie",
cookie, cookie,
url: url.href, url: url.href,
}); });
if (destination != "document" && destination != "iframe") { if (destination !== "document" && destination !== "iframe") {
await promise; await promise;
} }
} }
@ -358,7 +358,7 @@ async function rewriteBody(
} else { } else {
return response.body; return response.body;
} }
case "script": case "script": {
let { js, tag, map } = rewriteJsWithMap( let { js, tag, map } = rewriteJsWithMap(
new Uint8Array(await response.arrayBuffer()), new Uint8Array(await response.arrayBuffer()),
response.finalURL, response.finalURL,
@ -370,7 +370,9 @@ async function rewriteBody(
`${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");` + `${globalThis.$scramjet.config.globals.pushsourcemapfn}([${map.join(",")}], "${tag}");` +
(js instanceof Uint8Array ? new TextDecoder().decode(js) : js); (js instanceof Uint8Array ? new TextDecoder().decode(js) : js);
} }
return js;
return js as unknown as ArrayBuffer;
}
case "style": case "style":
return rewriteCss(await response.text(), meta); return rewriteCss(await response.text(), meta);
case "sharedworker": case "sharedworker":

View file

@ -43,6 +43,7 @@ export class ScramjetServiceWorker extends EventTarget {
const cb = this.syncPool[data.scramjet$token]; const cb = this.syncPool[data.scramjet$token];
delete this.syncPool[data.scramjet$token]; delete this.syncPool[data.scramjet$token];
cb(data); cb(data);
return; return;
} }
@ -67,13 +68,14 @@ export class ScramjetServiceWorker extends EventTarget {
} }
async dispatch(client: Client, data: MessageW2C): Promise<MessageC2W> { async dispatch(client: Client, data: MessageW2C): Promise<MessageC2W> {
let token = this.synctoken++; const token = this.synctoken++;
let cb: (val: MessageC2W) => void; 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; this.syncPool[token] = cb;
data.scramjet$token = token; data.scramjet$token = token;
client.postMessage(data); client.postMessage(data);
return await promise; return await promise;
} }