Open
Description
Run the following:
echo 'x => ({ x: () => x });' | babel --plugins transform-es2015-function-name
Expected output is the unchanged input:
x => ({ x: () => x });
But instead we get the following:
_x => ({ x: () => _x });
In a real-world project, we use webpack with babel-loader in a config like:
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015'],
plugins: ['angularjs-annotate'],
cacheDirectory: ''
}
},
/* ... */
]
Where the es2015
preset contains transform-es2015-function-name
.
But this results in some of our controllers not being able to find certain dependencies.
Not sure if this is an upstream bug, or if this should be dealt with here. The generated code is otherwise valid, and I guess upstream could argue that nothing is wrong here.
This is on babel 6.18.0 and babel-plugin-transform-es2015-function-name 6.9.0. Our app, where we get the missing dependency errors, uses babel-plugin-angularjs-annotate 0.6.0.
Some more scenario's:
// BAD: replace arrow function with regular function
function foo(x) { return { x: () => x }; };
// function foo(_x) {
// return { x: () => _x };
// }
// GOOD: replace `x` return with something else
x => ({ x: () => 7 });
// x => ({ x: () => 7 });
// GOOD: replace property name with something else
x => ({ z: () => x });
// x => ({ z: () => x });
// GOOD: use method syntax
x => ({ x() { return x; } });
// x => ({ x() {
// return x;
// } });