| 82 | export class InternalFnParser extends Callable<(...args: unknown[]) => Fn> { |
| 83 | constructor($: InternalScope) { |
| 84 | const parse = (...signature: unknown[]) => { |
| 85 | const returnOperatorIndex = signature.indexOf(":") |
| 86 | const lastParamIndex = |
| 87 | returnOperatorIndex === -1 ? |
| 88 | signature.length - 1 |
| 89 | : returnOperatorIndex - 1 |
| 90 | |
| 91 | const paramDefs = signature.slice(0, lastParamIndex + 1) |
| 92 | |
| 93 | const paramTuple = $.parse(paramDefs) |
| 94 | |
| 95 | let returnType: BaseRoot = $.intrinsic.unknown |
| 96 | |
| 97 | if (returnOperatorIndex !== -1) { |
| 98 | if (returnOperatorIndex !== signature.length - 2) |
| 99 | return throwParseError(badFnReturnTypeMessage) |
| 100 | returnType = $.parse(signature[returnOperatorIndex + 1]) |
| 101 | } |
| 102 | |
| 103 | return (impl: Fn) => new InternalTypedFn(impl, paramTuple, returnType) |
| 104 | } |
| 105 | |
| 106 | // `raw` is an alias of `fn` itself with no type-level validation. It must |
| 107 | // reference `parse` directly rather than `$.fn`, which is still being |