Files
babel/packages/babel-plugin-transform-es2015-function-name/src/index.js
2017-06-27 12:15:00 -05:00

25 lines
616 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);
}
},
},
};
}