Skip to content

Commit

Permalink
fix function name offset
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 19, 2023
1 parent 8369330 commit 75534d2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ const initAstCoverage = (coverageList, ast, functions) => {
... range
};

if (!countMap.has(startOffset)) {
countMap.set(startOffset, functionInfo);
const nameOffset = functionName ? startOffset + functionName.length : null;

// already exists just add name offset
if (countMap.has(startOffset) && nameOffset) {
countMap.set(nameOffset, functionInfo);
return;
}

// the position after function name, offset move right
if (functionName) {
const nameOffset = startOffset + functionName.length;
if (!countMap.has(nameOffset)) {
countMap.set(nameOffset, functionInfo);
// add normal offset
countMap.set(startOffset, functionInfo);

// add name offset, the position after name, move right
if (nameOffset) {
if (countMap.has(nameOffset)) {
// console.log('====================================', functionInfo);
return;
}
countMap.set(nameOffset, functionInfo);
}

});
Expand Down

0 comments on commit 75534d2

Please sign in to comment.