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

Function getRecFunc

book/tiny-ts-parser.ts:576–589  ·  view source on GitHub ↗
(node: p.TSESTree.FunctionDeclaration, ctx: Context, restFunc: (() => Term) | null)

Source from the content-addressed store, hash-verified

574}
575
576function getRecFunc(node: p.TSESTree.FunctionDeclaration, ctx: Context, restFunc: (() => Term) | null): Term {
577 if (!node.id) error("function name is required", node);
578 if (!node.returnType) error("function return type is required", node);
579 const funcName = node.id.name;
580 if (node.typeParameters) error("type parameter is not supported for function declaration", node);
581 const params = node.params.map((param) => {
582 const { name, type } = getParam(param);
583 return { name, type: simplifyType(type, ctx) };
584 });
585 const retType = simplifyType(convertType(node.returnType.typeAnnotation), ctx);
586 const body = convertStmts(node.body.body, true, ctx);
587 const rest: Term = restFunc ? restFunc() : { tag: "var", name: funcName, loc: node.loc };
588 return { tag: "recFunc", funcName, params, retType, body, rest, loc: node.loc };
589}
590
591// Convert estree type node to our simplified node definition
592function convertType(node: p.TSESTree.TypeNode): 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