(node: p.TSESTree.FunctionDeclaration, ctx: Context, restFunc: (() => Term) | null)
| 227 | } |
| 228 | |
| 229 | function 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 | |
| 244 | function convertType(node: p.TSESTree.TypeNode): Type { |
| 245 | switch (node.type) { |
no test coverage detected