c8 icon indicating copy to clipboard operation
c8 copied to clipboard

Context-insensitive parsing of sourceMappingURL

Open lachrist opened this issue 1 year ago • 0 comments

  • Version: v18.13.0
  • Platform: Darwin softs-MBP 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64 x86_64
  • c8: 7.13.0

First of all, thanks for your work!

The current regexp-based parsing of sourcemap urls does not consider the context where sourceMappingURL= appears:

https://github.com/bcoe/c8/blob/854f9f6c2ea36e583ea02fa3f8a850804e671df3/lib/source-map-from-file.js#L41

This causes files where sourceMappingURL= appears in string literal to not be covered. It would also happens if sourceMappingURL= appears in non-tail comments.

// append-sourcemap-url.mjs

const appendSourcemapUrl = (content, sourcemap) =>
  `${content}\n//# sourceMappingURL=data:text/json,${encodeURIComponent(sourcemap)}`;

appendSourcemapUrl("123;", '{"version":3}');
npx c8 -- node append-sourcemap-url.mjs
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

lachrist avatar Apr 24 '23 10:04 lachrist