MCPcopy Create free account
hub / github.com/LambdaNote/support-ts-tapl / getRecFunc

Function getRecFunc

article/utils.ts:229–242  ·  view source on GitHub ↗
(node: p.TSESTree.FunctionDeclaration, ctx: Context, restFunc: (() => Term) | null)

Source from the content-addressed store, hash-verified

227}
228
229function getRecFunc(node: p.TSESTree.FunctionDeclaration, ctx: Context, restFunc: (() => Term) | null): Term {
230 if (!node.id) error("function name is required", node);
231 if (!node.returnType) error("function return type is required", node);
232 const funcName = node.id.name;
233 if (node.typeParameters) error("type parameter is not supported for function declaration", node);
234 const params = node.params.map((param) => {
235 const { name, type } = getParam(param);
236 return { name, type: simplifyType(type, ctx) };
237 });
238 const retType = simplifyType(convertType(node.returnType.typeAnnotation), ctx);
239 const body = convertStmts(node.body.body, true, ctx);
240 const rest: Term = restFunc ? restFunc() : { tag: "var", name: funcName, loc: node.loc };
241 return { tag: "recFunc", funcName, params, retType, body, rest, loc: node.loc };
242}
243
244function convertType(node: p.TSESTree.TypeNode): Type {
245 switch (node.type) {

Callers 1

convertStmtFunction · 0.70

Calls 5

errorFunction · 0.70
getParamFunction · 0.70
simplifyTypeFunction · 0.70
convertTypeFunction · 0.70
convertStmtsFunction · 0.70

Tested by

no test coverage detected