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 a421310 commit 62ffbc0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,13 @@ 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;
}
const isWrapFunction = (positionMapping, start, end) => {
const left = positionMapping.getSlice(0, start);
const right = positionMapping.getSlice(end);
if (Util.isBlank(left) && Util.isBlank(right)) {
// console.log('=================================', state.sourcePath);
return true;
}

};


Expand All @@ -305,23 +302,25 @@ const isWrapFunction = (original, i, positionMapping, start, end) => {

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

const {
original, positionMapping, coverageInfo
} = state;
const { positionMapping, coverageInfo } = state;

const {
branches, ranges, lineMap
} = coverageInfo;

const { isBlockCoverage } = block;
const {
startOffset, endOffset, count
} = range;

if (isWrapFunction(original, index, positionMapping, startOffset, endOffset)) {
return;
// check first range
if (!ranges.length) {
if (isWrapFunction(positionMapping, startOffset, endOffset)) {
return;
}
}

const { isBlockCoverage } = block;

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

if (isWrapFunction(original, i, positionMapping, start, end)) {
return;
// check first function
if (original && i === 0) {
if (isWrapFunction(positionMapping, start, end)) {
return;
}
}

const sLoc = positionMapping.offsetToLocation(start);
Expand Down

0 comments on commit 62ffbc0

Please sign in to comment.