There is no reason that a similar project could not have been made via smaller modules using comment annotations.
This project really should be at least two projets: (1) one npm module for parsing the type signatures with the line numbers of the functions it applies to. (2) one module that takes in that intermediary representation and performs the AST transform for wrapping the functions.
I don't see why this couldn't have been accomplished with:
(1) the doctrine module [0] for parsing JSDoc comment blocks before functions
OR a custom module for recognizing a custom comment delimiter like //+ or
//! followed by the type annotation such as Haskell's type declaration
format.
(2) a module for parsing closure compiler JSDoc type signatures
(3) the racket-style higher order contracts module [1] for a way to do
run-time checking
(3) a module consisting of all the possible permutations of higher order
type checking functions based on rho-contracts
(4) the node-falafel module [2] for performing the actual AST transform
that wraps those contract functions around the function described by
the JSdoc comment.
Furthermore, this approach of breaking this up in to modules allows multiple people to propose alternative syntaxes for this for consideration in future versions of ECMAScript. I wouldn't be surprised if sweet.js could also be used for those
syntax approaches that go beyond comment-based annotations and involve modifying the syntax of the language itself.For those that built this at Google, please please please consider breaking this down into smaller composable modules. I'd love to be able to play with the subcomponents of this myself without having to adopt yet another language that doesn't parse with off the shelf tools [4].
[0] https://github.com/Constellation/doctrine
[1] https://github.com/sefaira/rho-contracts.js
[2] https://github.com/substack/node-falafel
[4] See JSX for the clusterfuck[6] that results when you add yet another format that needs to be parsed in a unique way with no real benefit that couldn't be accomplished just as easily without fucking with the standard language syntax. See Wadler's Law [5]