Don't try to visit ArrowFunctionExpression, they cannot be named

They will still be visited if the arrow functions are transformed to regular
functions.

Fixes #5004
This commit is contained in:
Diogo Franco (Kovensky)
2016-12-16 11:14:39 +09:00
parent e06faa99da
commit ccf2f56085
7 changed files with 23 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ import nameFunction from "babel-helper-function-name";
export default function () {
return {
visitor: {
"ArrowFunctionExpression|FunctionExpression": {
FunctionExpression: {
exit(path) {
if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
let replacement = nameFunction(path);

View File

@@ -0,0 +1,3 @@
const x = () => x;
const y = x => x();
const z = { z: () => y(x) }.z;

View File

@@ -0,0 +1,9 @@
const x = function x() {
return x;
};
const y = function y(x) {
return x();
};
const z = { z: function z() {
return y(x);
} }.z;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-arrow-functions"]
}

View File

@@ -0,0 +1,2 @@
export const x = ({x}) => x;
export const y = function () {};

View File

@@ -0,0 +1,2 @@
export const x = ({ x }) => x;
export const y = function y() {};

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name"]
}