Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: source mapping for branch statements (#518)
  • Loading branch information
ReneSchumacher committed Oct 12, 2021
1 parent cdc28f3 commit 3833708
Show file tree
Hide file tree
Showing 5 changed files with 1,429 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/istanbul-lib-source-maps/lib/transformer.js
Expand Up @@ -14,14 +14,15 @@ class SourceMapTransformer {
constructor(finder, opts = {}) {
this.finder = finder;
this.baseDir = opts.baseDir || process.cwd();
this.resolveMapping = opts.getMapping || getMapping;
}

processFile(fc, sourceMap, coverageMapper) {
let changes = 0;

Object.entries(fc.statementMap).forEach(([s, loc]) => {
const hits = fc.s[s];
const mapping = getMapping(sourceMap, loc, fc.path);
const mapping = this.resolveMapping(sourceMap, loc, fc.path);

if (mapping) {
changes += 1;
Expand All @@ -32,8 +33,17 @@ class SourceMapTransformer {

Object.entries(fc.fnMap).forEach(([f, fnMeta]) => {
const hits = fc.f[f];
const mapping = getMapping(sourceMap, fnMeta.decl, fc.path);
const spanMapping = getMapping(sourceMap, fnMeta.loc, fc.path);
const mapping = this.resolveMapping(
sourceMap,
fnMeta.decl,
fc.path
);

const spanMapping = this.resolveMapping(
sourceMap,
fnMeta.loc,
fc.path
);

if (
mapping &&
Expand All @@ -59,7 +69,7 @@ class SourceMapTransformer {
let skip;

branchMeta.locations.forEach((loc, i) => {
const mapping = getMapping(sourceMap, loc, fc.path);
const mapping = this.resolveMapping(sourceMap, loc, fc.path);
if (mapping) {
if (!source) {
source = mapping.source;
Expand All @@ -74,12 +84,16 @@ class SourceMapTransformer {
}
});

const locMapping = branchMeta.loc
? this.resolveMapping(sourceMap, branchMeta.loc, fc.path)
: null;

if (!skip && locs.length > 0) {
changes += 1;
const mappedCoverage = coverageMapper(source);
mappedCoverage.addBranch(
branchMeta.type,
locs[0] /* XXX */,
locMapping ? locMapping.loc : locs[0],
locs,
mappedHits
);
Expand Down

0 comments on commit 3833708

Please sign in to comment.