From 4856533b22f8c0fc177b9f92a76434f0a7ecefb1 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 23 Nov 2024 10:31:38 +0100 Subject: [PATCH] making sure dependencies are formatted --- depell/src/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/depell/src/index.js b/depell/src/index.js index 5225667..5716dda 100644 --- a/depell/src/index.js +++ b/depell/src/index.js @@ -158,12 +158,13 @@ function wireUp(target) { const importRe = /@use\s*\(\s*"(([^"]|\\")+)"\s*\)/g; -/** @param {string} code +/** @param {WebAssembly.Instance} fmt + * @param {string} code * @param {string[]} roots * @param {Post[]} buf * @param {Set} prevRoots * @returns {void} */ -function loadCachedPackages(code, roots, buf, prevRoots) { +function loadCachedPackages(fmt, code, roots, buf, prevRoots) { buf[0].code = code; roots.length = 0; @@ -179,7 +180,10 @@ function loadCachedPackages(code, roots, buf, prevRoots) { for (let imp = roots.pop(); imp !== undefined; imp = roots.pop()) { if (prevRoots.has(imp)) continue; prevRoots.add(imp); - buf.push({ path: imp, code: localStorage.getItem("package-" + imp) ?? never() }); + + const fmtd = modifyCode(fmt, localStorage.getItem("package-" + imp) ?? never(), "fmt"); + if (typeof fmtd != "string") never(); + buf.push({ path: imp, code: fmtd }); for (const match of buf[buf.length - 1].code.matchAll(importRe)) { roots.push(match[1]); } @@ -275,7 +279,7 @@ async function bindCodeEdit(target) { return; } - loadCachedPackages(edit.value, ctx.keyBuf, packages, prevRoots); + loadCachedPackages(fmt, edit.value, ctx.keyBuf, packages, prevRoots); errors.textContent = compileCode(hbc, packages); const minified_size = modifyCode(fmt, edit.value, "minify")?.length; @@ -468,7 +472,6 @@ document.body.addEventListener('htmx:afterSwap', (ev) => { wireUp(ev.target); if (ev.target.tagName == "MAIN" || ev.target.tagName == "BODY") updateTab(ev['detail'].pathInfo.finalRequestPath); - console.log(ev); }); getFmtInstance().then(inst => { @@ -527,11 +530,11 @@ function runPost(target) { const output = target.querySelector("pre[id=compiler-output]"); if (!(output instanceof HTMLPreElement)) never(); - getHbcInstance().then(async hbc => { + Promise.all([getHbcInstance(), getFmtInstance()]).then(async ([hbc, fmt]) => { const ctx = { keyBuf: [], prevParams: new Set() }; - await fetchPackages(code.textContent ?? never(), new Set(), output, ctx); + await fetchPackages(code.innerText ?? never(), new Set(), output, ctx); const posts = [{ path: "this", code: "" }]; - loadCachedPackages(code.textContent ?? never(), ctx.keyBuf, posts, new Set()); + loadCachedPackages(fmt, code.innerText ?? never(), ctx.keyBuf, posts, new Set()); output.textContent = compileCode(hbc, posts); output.hidden = false; });