From 62ffbc042cc0a6acd0a7294f008e6a52c7eed234 Mon Sep 17 00:00:00 2001 From: cenfun Date: Tue, 19 Dec 2023 12:46:57 +0800 Subject: [PATCH] remove parent wrap function --- lib/converter/converter.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/converter/converter.js b/lib/converter/converter.js index cd4acdbc..214cba10 100644 --- a/lib/converter/converter.js +++ b/lib/converter/converter.js @@ -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; } - }; @@ -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, @@ -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);