Skip to content

Commit 3c0df72

Browse files
committed
feat: works for runtime
1 parent 0608a19 commit 3c0df72

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/browser_runtime.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
/* wenyan-catsrc-ignore */
22

33
(() => {
4-
const { compile } = require("./parser");
4+
const { execute } = require("./parser");
55

66
const isDev = false;
77

88
async function run(script) {
99
const scoped = !!script.attributes.scoped;
10+
let code = script.innerText;
1011
if (script.src) {
1112
const response = await fetch(script.src);
12-
const code = await response.text();
13-
await exec(code.toString(), scoped);
14-
} else {
15-
await exec(script.innerText, scoped);
13+
code = (await response.text()).toString();
1614
}
17-
}
18-
19-
async function exec(code, scoped = false) {
20-
let compiled = compile("js", code, {
15+
execute(code, {
16+
scoped,
2117
logCallback: isDev ? console.log : () => {},
2218
resetVarCnt: false
2319
});
24-
25-
// wrap for scoped scripts that won't expose any variables to global
26-
if (scoped) compiled = `(()=>{${compiled}})()`;
27-
28-
// executing
29-
window.eval(compiled);
3020
}
3121

3222
document.addEventListener("DOMContentLoaded", async () => {

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ function evalCompiled(compiledCode, options = {}) {
818818
function execute(source, options = {}) {
819819
const { lang = "js" } = options;
820820
isLangSupportedForEval(lang);
821-
const compiled = compile(options.lang, source, options);
821+
const compiled = compile(lang, source, options);
822822
evalCompiled(compiled, options);
823823
}
824824

0 commit comments

Comments
 (0)