Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original indentation gets lost when printing non-file node #1209

Open
Andarist opened this issue Oct 13, 2022 · 0 comments
Open

Original indentation gets lost when printing non-file node #1209

Andarist opened this issue Oct 13, 2022 · 0 comments

Comments

@Andarist
Copy link

I've attempted to only print a subset of the original file because I only want to replace that part through VS Code's WorkspaceEdits (I'm developing a VS Code extension). Replacing the whole file puts more pressure on the VS Code as it has to recompute syntax highlighting, code lenses, and more. And I know which part of the file I'd like to touch - so it's best to focus on that part.

However, I've discovered that in such a situation Recast dedents my result and removes the original indentation of this node.

Repro case

https://codesandbox.io/s/affectionate-curie-dvwykb?file=/src/index.js

import * as recast from "recast";
import * as babelParser from "recast/parsers/babel";

const ast = recast.parse(
  `
createMachine(
  {
    initial: 'foo'
  },
  {
    actions: {}
  }
)
`,
  {
    parser: babelParser
  }
);

const config = ast.program.body[0].expression.arguments[0];

config.properties[0].value = recast.types.builders.stringLiteral("REPLACED");

console.log(recast.print(config).code);

Actual

{
  initial: "REPLACED"
} 

Expected

  {
    initial: "REPLACED"
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant