jscodeshift
jscodeshift copied to clipboard
Incorrect behavior after comment removal
See this example.
I am trying to remove some comments which can appear before or after object properties. And I want to preserve the location (leading/trailing) of other comments. However, after running the codemod, the comments that should be untouched are rearranged.
Code:
const opts = {
// Good comment
// REMOVE_ME
banner: true,
// REMOVE_ME
// Nice
};
CodeMod:
export default function transformer(file, api, { buildFlag1 }) {
const j = api.jscodeshift;
return j(file.source)
.find(j.Comment)
.filter((path) => path.value.value.trim() === "REMOVE_ME")
.forEach((path) => {
console.log(path.node);
path.prune();
})
.toSource();
}
module.exports.parser = "flow";
Expected
const opts = {
// Good comment
banner: true,
// Nice
};
Actual
const opts = {
// Good comment
// Nice
banner: true,
};
🐞 Is this a bug in jscodeshift?