Skip to content

Commit

Permalink
remove parent wrap function
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 19, 2023
1 parent a5e5ff8 commit a421310
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ const collectFileCoverage = (item, coverageInfo, state) => {

// ========================================================================================================


// check first function in original source
// it could be the parent wrap function, should be removed
const isWrapFunction = (original, i, positionMapping, start, end) => {
if (original && i === 0) {
const left = positionMapping.getSlice(0, start);
const right = positionMapping.getSlice(end);
if (Util.isBlank(left) && Util.isBlank(right)) {
// console.log('=================================', state.sourcePath);
return true;
}
}

};


// https://github.com/demurgos/v8-coverage
/**
* @ranges is always non-empty. The first range is called the "root range".
Expand All @@ -287,7 +303,11 @@ const collectFileCoverage = (item, coverageInfo, state) => {
*/
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.

const addJsCoverage = (coverageInfo, block, range, index, positionMapping) => {
const addJsCoverage = (state, block, range, index) => {

const {
original, positionMapping, coverageInfo
} = state;

const {
branches, ranges, lineMap
Expand All @@ -298,6 +318,10 @@ const addJsCoverage = (coverageInfo, block, range, index, positionMapping) => {
startOffset, endOffset, count
} = range;

if (isWrapFunction(original, index, positionMapping, startOffset, endOffset)) {
return;
}

ranges.push({
start: startOffset,
end: endOffset,
Expand Down Expand Up @@ -397,15 +421,8 @@ const handleFunctionsCoverage = (state) => {
start, end, functionName, count
} = it;

// check first function in original source
// it could be the parent wrap function, should be removed
if (original && i === 0) {
const left = positionMapping.getSlice(0, start);
const right = positionMapping.getSlice(end);
if (Util.isBlank(left) && Util.isBlank(right)) {
// console.log('=================================', state.sourcePath);
return;
}
if (isWrapFunction(original, i, positionMapping, start, end)) {
return;
}

const sLoc = positionMapping.offsetToLocation(start);
Expand Down Expand Up @@ -476,7 +493,7 @@ const handleRangesCoverage = (state) => {
if (js) {
coverageList.forEach((block) => {
block.ranges.forEach((range, index) => {
addJsCoverage(coverageInfo, block, range, index, positionMapping);
addJsCoverage(state, block, range, index);
});
});
} else {
Expand Down Expand Up @@ -768,8 +785,7 @@ const handleOriginalRangesCoverage = (state, originalMap) => {
}

const { originalRange, originalState } = result;
const { coverageInfo, positionMapping } = originalState;
addJsCoverage(coverageInfo, block, originalRange, index, positionMapping);
addJsCoverage(originalState, block, originalRange, index);

});
});
Expand Down

0 comments on commit a421310

Please sign in to comment.