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

Document potential byte-offset position 'hazard' #3

Open
acutmore opened this issue Feb 17, 2025 · 0 comments
Open

Document potential byte-offset position 'hazard' #3

acutmore opened this issue Feb 17, 2025 · 0 comments

Comments

@acutmore
Copy link

acutmore commented Feb 17, 2025

Hi @branchseer, as the author of ts-blank-space, let me first say that this project is awesome to see! I had hoped that someone would demonstrate an even faster approach that avoided allocating the AST nodes, this wasn't an option for ts-blank-space due to its decision to use TypeScript's official parser API.

One aspect of the 'type-stripping' approach that is perhaps not immediately clear is that it not only preserves the line+column position but it also preserves the full string byte offset. This can be important because the code-coverage data produced by V8 is reported as byte-offsets, not line+column.

This means that when extra characters are added, even if the line+column is either preserved or very close to the original, the byte-offsets will incrementally get further and further away. This is one of the reasons why ts-blank-space doesn't support syntax such as the legacy type assertions <T>{} because it (sometimes) requires adding an extra closing ) after the }.

I wonder if it would make sense to mention this more explicitly in the README?

p.s. I also agree that in the future range mappings may be of big help here.

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