flaska/benchmark/mapl_compiler.mjs

25 lines
716 B
JavaScript
Raw Normal View History

2024-11-02 12:44:54 +00:00
import { getExternalKeys } from '@mapl/compiler';
import { compileRouter as compileRouterContent } from '@mapl/router';
const PATH = "__req_p";
const REQ = '__req';
const PARAMS = `${REQ}_ps`;
export function compileRouter(root) {
const state = {
contentBuilder: [],
declarationBuilders: [],
externalValues: [],
compileItem: (item, state, hasParam) => {
state.contentBuilder.push(`return [f${state.externalValues.push(item)},${hasParam ? PARAMS : '[]'}];`);
}
};
compileRouterContent(root, state);
// eslint-disable-next-line
return Function(
...getExternalKeys(state),
`return (${PATH})=>{${state.contentBuilder.join('')}return null;}`
)(...state.externalValues);
}