Transition to ES6

Is there a way to port the ES5 code to ES6? I was looking for some examples regarding the use of the latest Node.js, and this always gave me an error, even with the harmony flag. The error included an invalid syntax message even for the let keyword. I wrote the v8 console options and it seems all inclusive ..

I am trying to migrate my http://twee.io framework

+5
source share
3 answers

ES5 code will already work with ES6 code. For nodejs, just install the babel kernel:

npm install babel-core --save

and you will also need npm install babel-preset-es2015 --save

create a .babelrc file with the following:

 { "presets": [ "es2015"], "ignore": "node_modules" } 

run the node application through (assuming your file is app.js)

babel-node app

Alternatively, you can add require('babel-core/register'); to the beginning of your node project, and any code below will be crowded with babel ...

The recommended way is to create something like main.js with the following contents:

 require('babel-core/register'); require('./app.js'); 

then just run node main.

+3
source

There is no automated tool for converting ES5 to ES6. You need to learn the features of ES6 and then convert the ES5 code to ES6 based on your needs.

I posted a video on how to migrate from existing ES5 code to ES6

https://www.youtube.com/watch?v=vK0mYvK3nkE

Hope this helps someone who is trying to compare and find out.

+1
source

Turn your ES5 code into readable ES6 with Lebab . enter link description here

0
source

Source: https://habr.com/ru/post/1214203/


All Articles