rust-sourcemap icon indicating copy to clipboard operation
rust-sourcemap copied to clipboard

Eagerly remove useless mappings

Open loewenheim opened this issue 2 years ago • 0 comments

In a sourcemap, consecutive mappings to the same location are redundant, because a mapping always applies until the end of the line or the start of the next mapping. For example, consider a sourcemap containing the following mappings:

[…]
(17, 23) -> ("foo.bar", 95, 8)
(17, 31) -> ("foo.bar", 95, 8)
(18, 5)  -> ("foo.bar", 95, 8)
[…]

The middle mapping is redundant—it adds no information that isn't already covered by the first mapping. By contrast, the third mapping is relevant because it's on a new line.

Removing these redundant mappings could for example be done in SourceMapBuilder::into_sourcemap and/or as part of Sourcemap::rewrite.

We might want to consider doing this as part of #71.

loewenheim avatar Sep 07 '23 11:09 loewenheim