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

Function newIfNode

book/tiny-ts-parser.ts:656–671  ·  view source on GitHub ↗
(cond: Term, thn: Term, els: Term, loc: Location)

Source from the content-addressed store, hash-verified

654}
655
656function newIfNode(cond: Term, thn: Term, els: Term, loc: Location): Term {
657 if (cond.tag === "compare") {
658 if (cond.left.tag === "objectGet" && cond.left.obj.tag === "var" && cond.left.propName == "tag") {
659 if (cond.right.tag === "string") {
660 const varName = cond.left.obj.name;
661 const tagLabel = cond.right.s;
662 if (cond.op === "===") {
663 return { tag: "taggedUnionGet", varName, clauses: [{ tagLabel, term: thn }], defaultClause: els, loc };
664 } else if (cond.op === "!==") {
665 return { tag: "taggedUnionGet", varName, clauses: [{ tagLabel, term: els }], defaultClause: thn, loc };
666 }
667 }
668 }
669 }
670 return { tag: "if", cond, thn, els, loc };
671}
672
673// Convert estree expression node to our simplified node definition
674function convertExpr(node: p.TSESTree.Expression, ctx: Context): Term {

Callers 2

convertExprFunction · 0.85
convertStmtFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected