Prebake in settings

Update prebake without reload
This commit is contained in:
John Björk 2026-01-30 20:52:15 +01:00
parent b4e171f5b4
commit 9f2237e11d
No known key found for this signature in database
GPG key ID: 303B6ADF2F569B0A
11 changed files with 292 additions and 37 deletions

View file

@ -3,3 +3,4 @@ import { transpiler } from './transpiler.mjs';
export * from './transpiler.mjs';
export const evaluate = (code) => _evaluate(code, transpiler);
export const evaluateUserPrebake = (code) => _evaluate(code, transpiler, { prebake: true });

View file

@ -25,6 +25,7 @@ export function transpiler(input, options = {}) {
emitMiniLocations = true,
emitWidgets = true,
blockBased = false,
prebake = false,
range = [],
} = options;
@ -260,7 +261,9 @@ export function transpiler(input, options = {}) {
// For block-based eval, add silence as the return value when block ends with declaration
body.push(silenceExpression);
} else {
throw new Error('unexpected ast format without body expression');
if (!prebake) {
throw new Error('unexpected ast format without body expression');
}
}
}
@ -273,7 +276,7 @@ export function transpiler(input, options = {}) {
}
// add return to last statement
if (addReturn) {
if (addReturn && !prebake) {
const { expression } = body[body.length - 1];
body[body.length - 1] = {
type: 'ReturnStatement',