1

I'm using Babel 6.1.2

$ babel --version
6.1.2 (babel-core 6.1.2)

When I compile ES6 code with anoymous function, I found the code is not transpiled to ECMAScript 5 Syntax at all.

$ echo "()=>1" | babel 
() => 1;

Does anyone have ideas about this? Thanks!

Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237

2 Answers2

3

From the official 6.0 release blogpost (https://babeljs.io/blog/2015/10/29/6.0.0/):

Since Babel is focusing on being a platform for JavaScript tooling and not an ES2015 transpiler, we’ve decided to make all of the plugins opt-in. This means when you install Babel it will no longer transpile your ES2015 code by default.

You will need plugins or presets to actually transpile your code.

https://babeljs.io/docs/plugins/#presets

Timon
  • 2,682
  • 1
  • 20
  • 33
1

Found a way:

Install the plugin

$ npm install babel-plugin-transform-es2015-arrow-functions

Add the following to .babelrc

{
  "plugins": ["transform-es2015-arrow-functions"]
}

Then it works

$ echo "() => 1" | babel --plugins transform-es2015-arrow-functions 
(function () {
  return 1;
});
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237