-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Offer Babel transpilation within the CoffeeScript compiler? #4696
Comments
If all of these things are true ...
... I think this sounds like an awesome feature. I feel like we should decide on this before the 2.0 release, and possibly even implement it before the 2.0 release since it makes things a lot easier to get started. |
Yeah, I was thinking about this whole writing the docs. It would make the docs so much easier to write if we didn't have to keep referring to “and wire up your build chain to use Babel.” That's probably a sign. If we really want to make things easy, we could make the Babel transpilation enabled by default. The issue there would be how to do that without forcing Babel to be a dependency. Maybe the transpilation happens automatically if Babel is installed? Then the docs get very easy, they just need to say that Babel should be installed. The flag would only be needed then if you wanted to disable transpilation while Babel is installed. This would also open up new possibilities for our tests. All the JSX and modules tests could get rewritten to compile with transpilation on, and the result executed (rather than compared as a string). |
Precisely what CS2 output features do we depend on Babel to compile? |
It’s a question of what runtimes you want to support. Modules and JSX are unsupported by any runtime, though I guess modules are beginning to be supported in browsers, if not Node. Async functions are only supported by Node 7.6+ and Chrome 55+ and other very new browsers. You can use the CoffeeScript compiler itself as a proxy for general ES2015 features, as it uses arrow functions and default values and destructuring and lots of other common features, if not generators and async functions. But the CoffeeScript compiler doesn’t run at all in Node 4, only 6 and above. The browser compiler doesn’t run in Safari 9, only 10+. Node 4 and Safari 9 are each only two years old. So CS2 doesn’t “depend on” Babel, per se. In #4697 I made it an optional dependency, and you can run the CoffeeScript compiler without it (but you wouldn’t be able to use the |
To answer your question another way: the I was wondering if it made sense to somehow let the user choose which transpiler they wanted to use, for example if they prefer Traceur (which also has the required |
This can be closed now, right? |
Yes. Fixed by #4697. |
So inside
Cakefile
we already have a functiontranspile
that takes JavaScript input (the output from the CoffeeScript compiler) and pipes it through Babel, to get a more compatible JavaScript output. We’re currently usingtranspile
to generate the browser compiler.js
file, and the code for the docs site.What if we added a flag (shudder) that told the compiler to run its final output through
transpile
before returning or saving it? Then people could use the CoffeeScript 2 compiler without necessarily needing to wire together a build chain. We would also need to provide some way for the user to set Babel’s options, probably via babelrc.Some concerns:
optionalDependencies
key inpackage.json
, so that Babel wouldn’t get automatically installed; and ifcompile
is run with this new flag, we could throw an error if Babel isn’trequire
-able.transpile
don’t bother with source maps, but we would want to make sure that source maps work with this. There’s some great code in the Meteor CoffeeScript package that sends code through the CoffeeScript compiler, then through Babel, and merges the source maps from each compiler. We would probably want to adapt this.The latter point is probably the strongest reason to do this. I’m still waiting on some good examples from #4615, so I don’t know how good or bad the current situation is regarding source maps surviving double compilation (CoffeeScript then Babel); but if it’s not great, then maybe this is something we should take on, as source map juggling is probably beyond the capabilities of most build chains or the developers assembling them.
The text was updated successfully, but these errors were encountered: