A source map is a claim, and nothing checks whether it is true
A source map is a claim about two files: that this position in the built output came from that position in a source file. I had never thought of it as a claim that could be false until a stack trace sent me to a line that had nothing to do with the crash. The build had gained a step. Something small, a licence banner prepended at the end of the pipeline, after the bundler had already written the…
A source map is a claim linking positions within built output files to their origins in source files. Its validity can be questioned, even when the map appears structurally sound. An analysis of 371 mappings from bundles generated by esbuild and TypeScript reveals that while 26 mappings carried names, none violated the three checks established for verifying mapping accuracy.
These checks include ensuring mappings do not extend beyond the line's end, do not land within identifiers, and that the source text at the mapped position begins with the declared name. When three additional lines were prepended to a bundle, 93 mappings showed 2 generated sources, with 5 landings on a token and 88 not, all positions matching the map's assertions, except for 1:6 and 1:22 which extend beyond the line's length.
This discrepancy indicates the map's inaccuracy due to changes in the file after the map's generation. The tool 'sourcemap-truth' distinguishes between a map being incorrect and one that cannot be validated due to a lack of source content, providing a simple binary output to indicate truthfulness. This tool highlights the broader issue of verification challenges when two artifacts (like a source map and its source files) are meant to describe each other but lack a reliable means of checking their mutual accuracy.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.