-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl.ts
More file actions
31 lines (25 loc) · 783 Bytes
/
repl.ts
File metadata and controls
31 lines (25 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { renderToString } from "wc-compiler";
onmessage = async (e) => {
console.log("Worker: Message received from main script", { e });
const input = e.data[0];
const language = e.data[1] ?? "javascript";
const props = e.data[2] ?? null;
const wrappingEntryTag = true;
console.log({ input, language, props });
let err;
let output;
try {
const inputURL = URL.createObjectURL(new Blob([input], { type: "application/javascript" }));
const { html } = await renderToString(new URL(inputURL), wrappingEntryTag, props);
output = html;
} catch (e) {
console.error(e);
err = e;
}
if (err) {
postMessage({ err });
} else {
console.log("Worker: Posting message back to main script", { output });
postMessage({ output });
}
};