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

Function convertProgram

article/utils.ts:442–467  ·  view source on GitHub ↗
(nodes: p.TSESTree.Statement[])

Source from the content-addressed store, hash-verified

440}
441
442function convertProgram(nodes: p.TSESTree.Statement[]): Term {
443 const globalTypeAliasMap: TypeAliasMap = {
444 "Boolean": { typeParams: null, type: { tag: "Boolean" } },
445 "Number": { typeParams: null, type: { tag: "Number" } },
446 };
447
448 const stmts = nodes.filter((node) => {
449 switch (node.type) {
450 case "ImportDeclaration":
451 return false;
452 case "TSTypeAliasDeclaration": {
453 const name = node.id.name;
454 const typeParams = node.typeParameters ? node.typeParameters.params.map((param) => param.name.name) : null;
455 const type = convertType(node.typeAnnotation);
456 globalTypeAliasMap[name] = { typeParams, type };
457 return false;
458 }
459 default:
460 return true;
461 }
462 });
463
464 const ctx = { globalTypeAliasMap, typeVarBindings: {} };
465
466 return convertStmts(stmts, false, ctx);
467}
468
469type ExtractTagsSub<T, K> = T extends Type | Term ? ExtractTags<T, K>
470 : T extends Type[] ? ExtractTags<Type, K>[]

Callers 1

parseFunction · 0.70

Calls 2

convertTypeFunction · 0.70
convertStmtsFunction · 0.70

Tested by

no test coverage detected