Skip to content

Document potential byte-offset position 'hazard' #3

Open
@acutmore

Description

@acutmore

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions