Files
vtj/packages/coder/src/parser/functions.ts
陈华春 1a34acc9b1 coder
2024-01-11 21:15:51 +08:00

17 lines
572 B
TypeScript

import { type JSFunction } from '@vtj/core';
import { replaceFunctionTag, parseValue, replaceComputedValue } from '../utils';
export function parseFunctionMap(
map: Record<string, JSFunction> = {},
computedKeys: string[] = []
) {
return Object.entries(map).map(([name, val]) => {
let handler = replaceFunctionTag(parseValue(val, false, false) as string);
handler = replaceComputedValue(handler, computedKeys);
if (handler.startsWith('async')) {
return `async ${name}${handler.replace(/^async/, '')}`;
}
return `${name}${handler}`;
});
}