Flattens a nested disjunction node to a list.

/a|b|c|d/

{{{a, b}, c}, d} -> [a, b, c, d]
function disjunctionToList(node) {
  if (node.type !== 'Disjunction') {
    throw new TypeError(`Expected "Disjunction" node, got "${node.type}"`);
  }

  const list = [];

  if (node.left && node.left.type === 'Disjunction') {
    list.push(...disjunctionToList(node.left), node.right);
  } else {
    list.push(node.left, node.right);
  }

  return list;
}