25 lines
No EOL
716 B
JavaScript
25 lines
No EOL
716 B
JavaScript
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);
|
|
} |