Since both branches of this `if`/`else` block are so similar, we should see what we can do about removing them and merging their bodies. How about:

```javascript
while((elem = elem.next)) {
  if (isTag(elem) &&
    (untilNode && elem !== untilNode) ||
    (untilNodes && untilNodes.indexOf(elem) === -1)) {
    elems.push(elem);
  } else {
    break;
  }
}
```