Logan Smyth 17b711fa70 Merge pull request #5008 from babel/fix-5004
Don't try to visit ArrowFunctionExpression, they cannot be named
2017-01-15 11:47:52 -08:00

25 lines
614 B
JavaScript

import nameFunction from "babel-helper-function-name";
export default function () {
return {
visitor: {
FunctionExpression: {
exit(path) {
if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
const replacement = nameFunction(path);
if (replacement) path.replaceWith(replacement);
}
}
},
ObjectProperty(path) {
const value = path.get("value");
if (value.isFunction()) {
const newNode = nameFunction(value);
if (newNode) value.replaceWith(newNode);
}
}
}
};
}