Built-in 6to5 support
February 4, 2015 kevinsawicki
Update
Since this post was originally published the 6to5 library was renamed to babel so packages should now use the "use babel";
pragma in their JavaScript files.
See atom/atom#5579 for more details.
Original Post
Starting with yesterday’s 0.177 release, Atom now has built-in support for preprocessing JavaScript files using the 6to5 library.
This allows you to use new ECMAScript 6 features in your packages that aren’t yet implemented in the versions of Chromium and io.js that ship with Atom.
To use this in your packages, make "use 6to5";
the very first line of any .js
files you’d like to transform using 6to5. So, for example, here is a package’s main.js
file that uses the new ES6 arrow functions:
"use 6to5";
exports.activate = () => console.log('this package was activated')
exports.deactivate = () => console.log('this package was deactivated')
Since arrow functions aren’t natively supported yet, the code will be converted on-the-fly to:
exports.activate = function () {
return console.log("this package was activated");
};
exports.deactivate = function () {
return console.log("this package was deactivated");
};
The 6to5 support uses the same caching strategy that is used for CoffeeScript, CSON, and Less files, so using it in your packages shouldn’t negatively impact startup time.
A huge thanks goes out to Michael Bolin from Facebook, who added this feature. You can check out pull request #5299 for the discussion and implementation details.
Check out the Learn ES6 article on 6to5.org for more information about all the great new ES6 features.