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

Changing the indentation of a multiline string incorrectly modifies the string contents #420

Open
alangpierce opened this issue Aug 5, 2017 · 2 comments

Comments

@alangpierce
Copy link
Contributor

alangpierce commented Aug 5, 2017

If I start with this code:

const s = `
a
`;

function f() {
}

then run a codemod to move the declaration into the function, it produces this code:

function f() {
  const s = `
  a
  `;
}

This incorrectly changes the value of s to have two spaces before the "a" and two spaces at the end of the string. Instead, the indentation logic should be smart enough to not touch lines where the start of the line is inside a multiline string literal.

jscodeshift demo:
https://astexplorer.net/#/gist/572d85770a3af8257ec361968104b377/08e0bd4baf85bee6513a1349da98ce104c183860

@benjamn
Copy link
Owner

benjamn commented Aug 5, 2017

This is something I thought I fixed previously by introducing a notion of lines whose indentation is "locked": #216

Maybe that fix missed some cases?

@nickretallack
Copy link

nickretallack commented Apr 7, 2020

I'm having a similar issue. I explored it here:
zxbodya/flowts#8

Try these as test cases.

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

3 participants