Refactor check.js
Add type declarations, fix JSDoc, conform to Parser API in terms