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.
Another option is to use
j.template.expressionwhich is a tagged template that lets you interpolate JavaScript with existing nodes:Complete example: