mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
rewriteJsNaiive
This commit is contained in:
parent
b2afb9c2ca
commit
613af1680e
1 changed files with 23 additions and 0 deletions
|
@ -35,3 +35,26 @@ export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. does not work with modules
|
||||||
|
// 2. cannot proxy import()
|
||||||
|
// 3. disables "use strict" optimizations
|
||||||
|
// 4. `location = ...` will fail
|
||||||
|
// 5. 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, origin?: URL) {
|
||||||
|
if ("window" in globalThis) origin ??= new URL(decodeUrl(location.href));
|
||||||
|
|
||||||
|
if (typeof js !== "string") {
|
||||||
|
js = new TextDecoder().decode(js);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
with ($s(window)) {
|
||||||
|
|
||||||
|
${js}
|
||||||
|
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue