Let's say I have the following file
export default {
foo: 'bar'
}
How can I transform this file using jscodeshift so it wraps the object into function like this:
export default () => ({
foo: 'bar'
})
My main problem is how to use the api.jscodeshift.arrowFunctionExpression(), especially how to create the function body. Cause I think all I need to do, is to replace the ObjectExpression with a function that has the ObjectExpression as its body.
Found out by myself.
arrowFunctionExpressiontake a list params and then ablockStatement. This will generate the function:Then create a new
exportDefaultDeclarationand pass the function to it.