• Home
Name Date Size #Lines LOC

..--

scripts/07-Sep-2024-3919

.babelrcD07-Sep-2024597 1817

README.mdD07-Sep-20241.6 KiB6542

package.jsonD07-Sep-20241.1 KiB3130

README.md

1# Converting incompatible features with Babel
2To run ES6 sources with JerryScript that use unsupported language features, you can use Babel to transpile your code, which will output a semantically equivalent source file, where the unsupported features are replaced with ES5.1 code.
3Babel is a JavaScript compiler that is used to convert ES2015+ code into a backward-compatible version. You can find more information [here](https://babeljs.io/).
4
5## Example
6
7```javascript
8//Before
9const fn = () => 1;
10
11//After conversion
12
13var fn = function fn() {
14  return 1;
15};
16```
17## Table of Contents
18* **[Getting ready](#getting-ready)**
19  * Installing node.js and npm
20* **[Using babel](#using-babel)**
21* **[Missing features/Polyfill](#missing-features)**
22
23## Getting ready [](#getting-ready)
24
25### 1. **Node.js and npm**
26
27Start by updating the packages with
28
29`$ sudo apt update`
30
31Install `nodejs` using the apt package manager
32
33`$ sudo apt install nodejs`
34
35Check the version of **node.js** to verify that it installed
36
37```bash
38$ nodejs --version
39Output: v8.10.0
40```
41
42Next up is installing **npm** with the following command
43
44`$ sudo apt install npm`
45
46Verify installation by typing:
47
48```bash
49$ npm --version
50Output: 6.10.2
51```
52
53### 2. Using babel [](#using-babel)
54
55Assuming you're in the tools/babel folder,
56
57`$ sudo npm install`
58
59After installing the dependencies it is ready to use.
60
61Place the files/directories you want transpiled to the babel folder and run
62
63`$ npm run transpile [name of input file/directory] [(OPTIONAL)name of output file/directory]`
64
65If you want to use the same name, then only give the name once.