Skip to content

Proposal: Offer Babel transpilation within the CoffeeScript compiler? #4696

@GeoffreyBooth

Description

@GeoffreyBooth

So inside Cakefile we already have a function transpile 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 using transpile 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:

  • We currently have no production dependencies, and we like it that way. But we could add Babel to the optionalDependencies key in package.json, so that Babel wouldn’t get automatically installed; and if compile is run with this new flag, we could throw an error if Babel isn’t require-able.
  • The current uses of 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions