Jesse McCarthy 36e58f4d4f Apply only to ObjectProperty.
Fix T6779. It should be possible to apply this to ES5 functions without
mutating ES2015 MethodDefinition's.
2015-12-08 16:46:45 -05:00

25 lines
634 B
JavaScript

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