I think the first part of the if statement is to allow you to do query.where(path).exists(), so we assume that the current path is true - okay, that makes sense.

It's the next part that's more confusing - if there's only one argument.

if path is a boolean, I would assume that's something of the case query.where(path).exists(true), but then shouldn't we be setting val to path, not to true all the time?

And what's the third case? Is that to allow you to do query.exists(path) and have that be the same as query.where(path).exists() or query.where(path).exists(true)?