(cond: Term, thn: Term, els: Term, loc: Location)
| 654 | } |
| 655 | |
| 656 | function 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 |
| 674 | function convertExpr(node: p.TSESTree.Expression, ctx: Context): Term { |
no outgoing calls
no test coverage detected