I'm new to jscodeshift and AST but I'm trying to do a conversion for my existing forEach loops and convert them to regular for loops.
I want to covert the below:
[
`foo`,
`bar`
].forEach(test => {
console.log(test);
});
To this:
for(const test of [`foo`, `bar`]) {
console.log(test);
}
export default (file, api) => {
const j = api.jscodeshift;
const root = j(file.source);
// What do I do here to transform the forEach to a regular for loop?
return root.toSource();
};
I've been looking through some of the docs and searching but I can't find a way to do this.
The is what I was looking for.