I frequently use this plugin to demo es6 features. But I often run into issues because --harmony flag doesn't support as much of es6 as babel does. ex. import 'modules'
(function (exports, require, module, __filename, __dirname) { import {Map, Lis
^^^^^^
SyntaxError: Unexpected reserved word
If i modify grammars.coffee :123/:126 to use babel-node instead of node, the files run perfectly.
Do you think its worth adding an option to override the Node REPL? or maybe even just a checkbox in the options to use babel if available?
Just a thought, but it might help some other people as well.
We have a script-options view that can be toggled to set the executable/program. That's currently the only cross-language solution we have right now.
It might be nice to think up, design, and mock up an alternative UI on top of Atom's to be able to pick between these options with a roll up similar to the language menu. Folks have faced the same thing between switching between Python2 and Python3.
For anyone searching for this, you can get this working relatively easy with Babel.js and latest Node Stable. To run ES6/7 files out of a project path for example:
→ mkdir test-es7
→ cd test-es7
→ npm init # hit enter a bunch of times - makes a package.json
→ npm i -D babel-cli babel-preset-es2015-node babel-plugin-transform-async-to-generator
Installs the Babel-CLI into your local node_modules/.bin
→ atom .
Best to open the project for atom from the shell, that way script will be able to find node and the local working directory automatically.
// index.js - ES7, async/await
console.log(process.versions)
function sleep (ms = 0) {
return new Promise(r => setTimeout(r, ms))
}
async function run () {
console.log('a')
await sleep(1000)
console.log('b')
}
run()
CMD-OPTION-P -> Script: Run Options, or CMD-SHIFT-I is the default keybind:
Copy/Paste doesn't work in it's text boxes, so you'll need to type these in, but it'll remember it for the Atom session.
./node_modules/.bin/babel-node--presets=es2015-node --plugins=transform-async-to-generatorHit the Run button, and you should see:
Javascript - test.js:11
{ http_parser: '2.5.0',
node: '5.0.0',
v8: '4.6.85.28',
uv: '1.7.5',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '47',
openssl: '1.0.2d' }
a
b
Finished in 2.038s
For anyone who is still looking for a solution. This worked for me.
npm i -D babel-preset-es2015-node babel-preset-stage-0
Put this .babelrc file into your project directory
{
"presets": ["es2015-node", "stage-0"]
}
Run your script in atom editor
@seethroughtrees @kriswill @akottr This has now been addressed in fc84ded7dad08466923071e6d6e4370aa6a36789, and should 'just work' by using the preconfigured Babel setup in this package instead of having to set it up locally every time or worse, globally.
Most helpful comment
For anyone searching for this, you can get this working relatively easy with Babel.js and latest Node Stable. To run ES6/7 files out of a project path for example:
Installs the Babel-CLI into your local node_modules/.bin
Best to open the project for atom from the shell, that way
scriptwill be able to find node and the local working directory automatically.CMD-OPTION-P->Script: Run Options, orCMD-SHIFT-Iis the default keybind:Copy/Paste doesn't work in it's text boxes, so you'll need to type these in, but it'll remember it for the Atom session.
./node_modules/.bin/babel-node--presets=es2015-node --plugins=transform-async-to-generatorHit the
Runbutton, and you should see:Finished in 2.038s