mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-27 09:19:53 +00:00
22 lines
596 B
TypeScript
22 lines
596 B
TypeScript
import { ExpressionSync } from '@/eval-estree-expression';
|
|
import type { JSExecutor, JSExecutorConfig } from './executor';
|
|
|
|
/**
|
|
* Execute JavaScript with a faked JS engine, limited features but works on workerd.
|
|
*/
|
|
export function executorVirtual(options: JSExecutorConfig): JSExecutor {
|
|
const sync = new ExpressionSync(options);
|
|
|
|
return {
|
|
expression(expression, context) {
|
|
return sync.evaluate(expression, context);
|
|
},
|
|
program(expression, context) {
|
|
return sync.evaluate(expression, context);
|
|
},
|
|
getExports() {
|
|
return sync.getExports();
|
|
},
|
|
};
|
|
}
|