Unintended Indentation in Template Literal with Line Breaks
Author: knilinkCreated Apr 1, 2025Updated Apr 1, 2025
When update BlockStatement body, template literals within the code are reformatted with unexpeted indentations.
Steps to Reproduce:
Transformer Code (transform.js):
module.exports = function (fileInfo, api, options) {
const j = api.jscodeshift;
const root = j(fileInfo.source);
root.find(j.BlockStatement).forEach((path) => {
path.node.body = [
...path.node.body,
// simply mutate the body by adding a empty statement
j.emptyStatement(),
];
});
return root.toSource();
};Source File (test.js):
Create a test file by
echo -e "{\`\n\`}" > test.jsthen the content should be
{`
`}Run the transformer
npx jscodeshift -t transform.js test.jsExpected Result:
if it's supposed to format the code then it should be
{
`
`
}Actual Result:
{
`
`
}where the indentation is unexpectedly added after the line break in template literal
Version
Source: facebook/jscodeshift