Skip to content

Commit

Permalink
fix: hide and/or nodes when only one child is present
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
nlf committed Sep 25, 2023
1 parent 368d8d0 commit 1dfd6b9
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,40 @@ export function compileToMermaid (tree: Node): string {
addLine(`${previousIdentifier()}---${identifier(true)}>${node.assumption}]`);
}

if (node.or?.length) {
const orCount = node.or?.length ?? 0;
if (orCount === 1) {
indent();
// non-null assertion safe due to length check above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
addNode(node.or![0]);
dedent();
} else if (orCount > 1) {
indent();
addLine(`${previousIdentifier()}---${identifier(true)}(((OR)))`);
indent();
for (const child of node.or) {
// non-null assertion safe due to length check above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const child of node.or!) {
addNode(child);
}
dedent();
dedent();
}

if (node.and?.length) {
const andLength = node.and?.length ?? 0;
if (andLength === 1) {
indent();
// non-null assertion safe due to length check above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
addNode(node.and![0]);
dedent();
} else if (andLength > 1) {
indent();
addLine(`${previousIdentifier()}---${identifier(true)}(((AND)))`);
indent();
for (const child of node.and) {
// non-null assertion safe due to length check above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const child of node.and!) {
addNode(child);
}
dedent();
Expand Down

0 comments on commit 1dfd6b9

Please sign in to comment.