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

Function convertProgram

book/tiny-ts-parser.ts:998–1020  ·  view source on GitHub ↗
(nodes: p.TSESTree.Statement[])

Source from the content-addressed store, hash-verified

996
997// Convert estree program nodes to our simplified node definition
998function convertProgram(nodes: p.TSESTree.Statement[]): Term {
999 const globalTypeAliasMap: TypeAliasMap = {};
1000
1001 const stmts = nodes.filter((node) => {
1002 switch (node.type) {
1003 case "ImportDeclaration":
1004 return false;
1005 case "TSTypeAliasDeclaration": {
1006 const name = node.id.name;
1007 const typeParams = node.typeParameters ? node.typeParameters.params.map((param) => param.name.name) : null;
1008 const type = convertType(node.typeAnnotation);
1009 globalTypeAliasMap[name] = { typeParams, type };
1010 return false;
1011 }
1012 default:
1013 return true;
1014 }
1015 });
1016
1017 const ctx = { globalTypeAliasMap, typeVarBindings: {} };
1018
1019 return convertStmts(stmts, false, ctx);
1020}
1021
1022// ---
1023// Parse functions

Callers 1

parseFunction · 0.70

Calls 2

convertTypeFunction · 0.70
convertStmtsFunction · 0.70

Tested by

no test coverage detected