Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel not replacing arrow functions

I installed babel cli and created a .babelrc file with presets set to es2015. I've also installed the es2015 preset. But when I use the command babel script.js --out-file script-compiled.js and check the output file, I still find arrow function syntax (=>) in the code, and browsers that don't support arrow functions are unable to run my code even though it has been transpiled with babel. What might be going on here? If it matters, the project is using react and I'm using browserify to create app.js, and then passing that file to babel.

Edit: here's an example of code that isn't being properly converted:

  this._accountModel.fetch({
      success: (res) => {
        console.log('success');
      },
      error: () => {
        console.log('error');
      }
    });
like image 449
pdorns Avatar asked Nov 09 '22 18:11

pdorns


1 Answers

That preset includes the arrow transform. Reference : https://babeljs.io/docs/plugins/preset-es2015/

Most likely the project is configured wrong.

like image 141
basarat Avatar answered Nov 14 '22 21:11

basarat