Skip to content

Commit

Permalink
fix root function range for startOffset (vitest wrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Feb 26, 2025
1 parent 2a23cd4 commit 26eb298
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,16 +1231,10 @@ const filterCoverageList = (item) => {
// the inline sourcemap could be removed
const maxOffset = source.length;

const rootFunctionInfo = {
root: true,
ranges: [{
startOffset: minOffset,
endOffset: maxOffset,
count: 1
}]
};
const wrapperList = [];

const coverageList = functions.filter((block) => {

const { ranges } = block;

// first one is function coverage info
Expand All @@ -1250,31 +1244,37 @@ const filterCoverageList = (item) => {
return true;
}

// blocks
const len = ranges.length;
if (len > 1) {
for (let i = 1; i < len; i++) {
const range = ranges[i];
if (range.startOffset >= minOffset && range.endOffset <= maxOffset) {
rootFunctionInfo.ranges.push(range);
}
}
}
wrapperList.push(block);

return false;
});

// first one for root function
if (rootFunctionInfo.ranges.length > 1) {
coverageList.unshift(rootFunctionInfo);
}

const rootFunctionInfo = wrapperList.length ? wrapperList.pop() : {
root: true,
ranges: [{
startOffset: minOffset,
endOffset: maxOffset,
count: 1
}]
};

coverageList.unshift(rootFunctionInfo);

// if (item.sourcePath.includes('PlaceB.tsx')) {
// console.log(coverageList);
// }

return coverageList;
};

const initJsCoverageList = (item) => {
const coverageList = filterCoverageList(item);

// if (item.sourcePath.includes('PlaceB.tsx')) {
// console.log(coverageList[0]);
// }

// function could be covered even it is defined after an uncovered return, see case closures.js
// fix uncovered range if there are covered ranges in uncovered range

Expand Down

0 comments on commit 26eb298

Please sign in to comment.