- transpiler now always returns an object

- emit transpiler metadata from evaluate / afterEval
- currently logging miniLocations from Repl.jsx
This commit is contained in:
Felix Roos 2023-07-02 14:15:54 +02:00
parent 5f271ed127
commit 8e717d2ea1
7 changed files with 25 additions and 19 deletions

View file

@ -37,8 +37,12 @@ function safeEval(str, options = {}) {
}
export const evaluate = async (code, transpiler) => {
let meta = {};
if (transpiler) {
code = transpiler(code); // transform syntactically correct js code to semantically usable code
// transform syntactically correct js code to semantically usable code
const transpiled = transpiler(code);
code = transpiled.output;
meta = transpiled;
}
// if no transpiler is given, we expect a single instruction (!wrapExpression)
const options = { wrapExpression: !!transpiler };
@ -48,5 +52,5 @@ export const evaluate = async (code, transpiler) => {
const message = `got "${typeof evaluated}" instead of pattern`;
throw new Error(message + (typeof evaluated === 'function' ? ', did you forget to call a function?' : '.'));
}
return { mode: 'javascript', pattern: evaluated };
return { mode: 'javascript', pattern: evaluated, meta };
};

View file

@ -35,11 +35,10 @@ export function repl({
}
try {
await beforeEval?.({ code });
let { pattern } = await _evaluate(code, transpiler);
let { pattern, meta } = await _evaluate(code, transpiler);
logger(`[eval] code updated`);
setPattern(pattern, autostart);
afterEval?.({ code, pattern });
afterEval?.({ code, pattern, meta });
return pattern;
} catch (err) {
// console.warn(`[repl] eval error: ${err.message}`);