flowts icon indicating copy to clipboard operation
flowts copied to clipboard

Recast strips leading whitespace based on the first line of a template literal in a function

Open nickretallack opened this issue 6 years ago • 1 comments

Input:

/* @flow */
() =>
  `
  x
`

Output is the same regardless of the --no-prettier setting:

() => `
x
`;

It also fails verification:

verification failed, diff after stripping type annotations:
- Expected
+ Received

  () => `
-   x
+ x
  `;

If you pass --no-recast it leaves the code unchanged.

Here's a similar example that it leaves unchanged:

/* @flow */
() => `
  x
`

It converts this example into the example above:

/* @flow */
() => 
`
  x
`

If you input this:

/* @flow */
() =>
  `
    x
`

It gives you this:

() => `
  x
`;

Very interesting! It seems like it's trying to do something nice for you, by looking at the first line of the template and stripping that amount of whitespace from the following lines. In another context, that'd be pretty cool. But here, I just want it to leave my code alone.

nickretallack avatar Apr 05 '20 20:04 nickretallack

should be fixed here https://github.com/zxbodya/babel-plugin-flow-to-typescript/commit/d41cd25f515322f491c285807b7a00e9fbcf32df

zxbodya avatar Apr 18 '20 12:04 zxbodya