mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-12 14:00:01 -04:00
start adding module rewriting support
This commit is contained in:
parent
8b97751692
commit
2dc6a47c41
2 changed files with 14 additions and 7 deletions
|
@ -248,13 +248,18 @@ function traverseParsedHtml(
|
|||
node.children[0] !== undefined
|
||||
) {
|
||||
let js = node.children[0].data;
|
||||
// node.attribs[`scramjet-attr-script-source-src`] = btoa(js);
|
||||
const module = node.attribs.type === "module" ? true : false;
|
||||
node.attribs["scramjet-attr-script-source-src"] = bytesToBase64(
|
||||
encoder.encode(js)
|
||||
);
|
||||
const htmlcomment = /<!--[\s\S]*?-->/g;
|
||||
js = js.replace(htmlcomment, "");
|
||||
node.children[0].data = rewriteJs(js, "(inline script element)", meta);
|
||||
node.children[0].data = rewriteJs(
|
||||
js,
|
||||
"(inline script element)",
|
||||
meta,
|
||||
module
|
||||
);
|
||||
}
|
||||
|
||||
if (node.name === "meta" && node.attribs["http-equiv"] !== undefined) {
|
||||
|
|
|
@ -22,7 +22,8 @@ const decoder = new TextDecoder();
|
|||
function rewriteJsWrapper(
|
||||
input: string | ArrayBuffer,
|
||||
source: string | null,
|
||||
meta: URLMeta
|
||||
meta: URLMeta,
|
||||
module: boolean
|
||||
): string | ArrayBuffer {
|
||||
let out: RewriterOutput;
|
||||
const before = performance.now();
|
||||
|
@ -31,7 +32,7 @@ function rewriteJsWrapper(
|
|||
out = rewrite_js(
|
||||
input,
|
||||
meta.base.href,
|
||||
false,
|
||||
module,
|
||||
source || "(unknown)",
|
||||
$scramjet
|
||||
);
|
||||
|
@ -39,7 +40,7 @@ function rewriteJsWrapper(
|
|||
out = rewrite_js_from_arraybuffer(
|
||||
new Uint8Array(input),
|
||||
meta.base.href,
|
||||
false,
|
||||
module,
|
||||
source || "(unknown)",
|
||||
$scramjet
|
||||
);
|
||||
|
@ -80,7 +81,8 @@ function rewriteJsWrapper(
|
|||
export function rewriteJs(
|
||||
js: string | ArrayBuffer,
|
||||
url: string | null,
|
||||
meta: URLMeta
|
||||
meta: URLMeta,
|
||||
module = false
|
||||
) {
|
||||
if (flagEnabled("naiiveRewriter", meta.origin)) {
|
||||
const text = typeof js === "string" ? js : new TextDecoder().decode(js);
|
||||
|
@ -88,7 +90,7 @@ export function rewriteJs(
|
|||
return rewriteJsNaiive(text);
|
||||
}
|
||||
|
||||
return rewriteJsWrapper(js, url, meta);
|
||||
return rewriteJsWrapper(js, url, meta, module);
|
||||
}
|
||||
|
||||
// 1. does not work with modules
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue