Justin Ridgewell 28ae47a174 Stop mutating nodes (#5963)
* Stop mutating nodes

* Update tests

* linting
2017-07-18 13:24:07 -04:00

27 lines
554 B
JavaScript

export default function({ types: t }) {
return {
visitor: {
FunctionExpression: {
exit(path) {
const { node } = path;
if (!node.id) return;
path.replaceWith(
t.callExpression(
t.functionExpression(
null,
[],
t.blockStatement([
t.toStatement(node),
t.returnStatement(node.id),
]),
),
[],
),
);
},
},
},
};
}