TypeStat icon indicating copy to clipboard operation
TypeStat copied to clipboard

SNC ! off by one character in BOM-encoded file

Open markjm opened this issue 4 years ago • 2 comments
trafficstars

🐛 Bug Report TypeStat version: 0.5.2 TypeScript version: 4.4.4 Node version: 16.x

Seems files with BOM encoding mess up the character position for SNC. Perhaps this is an "issue" (using the term loosely) with Typescript's character position reporting @DanielRosenwasser?

Reproduction https://github.com/markjm/demos-by-commit/tree/typestat-demo-3

markjm avatar Oct 26 '21 20:10 markjm

Easy fix (and the one I will be using) is to just stop using BOM-encoded files :), but submitting the bug for posterity

markjm avatar Oct 26 '21 21:10 markjm

Thanks for the report @markjm! Yes, I suspect this is an issue with TypeScript's character position reporting. The createNonNullAssertion function inside TypeStat places the "!" at a position equal to node.end. In with_bom.ts that's 75.

On Windows after creating a new without_bom.ts file identical to with_bom.ts but in non-BOM UTF-8, the position is still 75.

JoshuaKGoldberg avatar Oct 27 '21 05:10 JoshuaKGoldberg

Closing off as an old external issue. Please let me know if there's anything TypeStat should do!

JoshuaKGoldberg avatar May 26 '23 18:05 JoshuaKGoldberg