3 ms·
Adding to what Rich said, Sucrase takes a fair amount of inspiration from Bublé, and has a similar high-level approach of "pick a well-scoped subset of what Bab
by alangpierce 8y ago
Adding to what Rich said, Sucrase takes a fair amount of inspiration from Bublé, and has a similar high-level approach of "pick a well-scoped subset of what Babel solves, and focus on doing that really well". In Bublé's case, that's compiling many (but not all) ES6 features down to ES5. In Sucrase's case, that's compiling language extensions (plus some upcoming JS features like class fields) to modern JS. They solve different problems, so you would never pick between the two.
Architecturally, they both skip a bunch of work that Babel does (AST transformations and AST formatting), but Sucrase is a bit more ambitious. Bublé does a normal parse step and then does replacements using magic-string. The original hope was that Sucrase would be able to skip parsing and just tokenize the JS and do all of the necessary transforms from the tokens. It turns out that that's basically impossible, but Sucrase still tries to find a middle ground where it does something reminiscent of parsing but doesn't need to produce an AST at the end. It's still able to resolve variable scopes (which is needed for the TypeScript and imports transforms) by providing an array of scopes in addition to an array of tokens, and it provides enough useful context in the tokens to put the pieces together if necessary.