Skip to content

process: add lineLength to source-map-cache

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Problem

I realized when integrating source-map functionality with coverage that we're missing a piece of information necessary to support tools like ts-node:

  • V8's coverage implementation is based on absolute byte offset, whereas Source Map V3 is based on line/column offset.
  • when code is transpiled in memory (using hooks like require.extensions) we lack enough information to translate from bytes to lines/columns.

we end up with a bad reports that look like this, due to missing information:

Screen Shot 2019-10-06 at 11 25 03 AM

👆 note that exactly the wrong code is highlighted 😆

Solution

If we track the line lengths of the source file that source maps were extracted from, this provides enough information to remap from byte offset to line/column offset.

I've introduced an additional value into the cache, lineLengths, to facilitate this.

we can now generate the following report:

Screen Shot 2019-10-06 at 11 28 07 AM

Merge request reports

Loading