es-tooling / module-replacements-codemods

MIT License
188 stars 26 forks source link

feat: add iterate-value #94

Closed 43081j closed 3 months ago

43081j commented 3 months ago

Adds a codemod for iterate-value.

This handles the following cases:

// with an inline arrow function (BEFORE)
iterate([], (v) => {});
// with an inline arrow function (AFTER)
for (const v of ([])) {};

// with a referenced function (BEFORE)
const fn = (v) => {};
iterate([], fn);
// with a referenced function (AFTER)
for (const value of ([])) { fn(value); };

// without a callback (BEFORE)
iterate([1, 1, 1]);
// without a callback (AFTER)
Array.from([1, 1, 1]);

the semi colon gets left behind on the for loops which feels awkward. however, i think people should be expected to run a formatter after using this codemod anyway since we're adding blocks of code rather than simple changes.