Skip to content

Unintended Indentation in Template Literal with Line Breaks #1419

@knilink

Description

@knilink

When update BlockStatement body, template literals within the code are reformatted with unexpected indentations if containing line breaks.

Steps to Reproduce:

import { parse, print } from 'recast';
const ast = parse('{`\n`}');
// simply mutate the body by adding a empty statement
ast.program.body[0].body.push({ loc: null, type: 'EmptyStatement', comments: null });
console.log(print(ast).code);

Expected 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

recast@0.23.11

Ref facebook/jscodeshift#664

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions