rollup icon indicating copy to clipboard operation
rollup copied to clipboard

Improve sourcemap tracing with interpolation

Open mkropf opened this issue 7 years ago • 1 comments

Feature Use Case

As of my understanding, the chain of source transforms and corresponding sourcemaps gets collapsed into a final sourcemap by tracing each final codechunk to its origins. As it appears to me, the trace only works when the final token (line,column) positions have corresponding positions in the mapping chain. When a mapping in the chain has more coarse positions, it doesn't work? Example: An identifier token in the result has position (3,34), line 3 is traced to map line 6, column 34 is traced to a position in map line 6, chunk of col 34. When map line 6 does not have such a chunk, tracing ends. So map must have chunks for every token, or, when it is token agnostic, for every character.

Most plugins use MagicString for mapping, which provides character-position granularity, but we should not rely on that?

Feature Proposal

Sourcemap collapse tracing should be able to interpolate to the next known position when an intermediate sourcemap does not supply an entry for the position being traced.

mkropf avatar Oct 17 '19 07:10 mkropf

Definitely sounds worthwhile, but I would believe this to be a slightly exploratory topic. I would be very interested if someone were to try tackling this! So PRs and POCs welcome.

lukastaegert avatar Oct 17 '19 07:10 lukastaegert