[util/collapserange] Don't depend on function definition order inside block

Closes #1128