Rewrite in JS to use JSDoc
Allows eager returns for tests.