@sebastianwessel/quickjs
Version:
A typescript package to execute JavaScript and TypeScript code in a WebAssembly QuickJS sandbox
23 lines (22 loc) • 668 B
JavaScript
import { handleEvalError } from '../handleEvalError.js';
export const createValidateCodeFunction = (input) => {
const { ctx } = input;
return async (code, filename = '/src/index.js', evalOptions) => {
try {
ctx
.unwrapResult(ctx.evalCode(code, filename, {
strict: true,
strip: true,
backtraceBarrier: true,
...evalOptions,
type: 'module',
compileOnly: true,
}))
.dispose();
return { ok: true };
}
catch (err) {
return handleEvalError(err);
}
};
};