Skip to content

Commit

Permalink
fix sort ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jun 14, 2024
1 parent 964911c commit 50961d4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/converter/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ const Util = require('../utils/util.js');

const { collectAstInfo } = require('./ast-visitor.js');

const sortRanges = (ranges) => {
ranges.sort((a, b) => {
if (a.startOffset === b.startOffset) {
return a.endOffset - b.endOffset;
}
return a.startOffset - b.startOffset;
});
};

const getCoverageInfo = (coverageList) => {
const functionMap = new Map();
const functionNameMap = new Map();
const functionStaticRanges = [];
const functionUncoveredRanges = [];

let rootRange;
coverageList.forEach((block) => {
const {
Expand Down Expand Up @@ -39,9 +49,7 @@ const getCoverageInfo = (coverageList) => {
functionRange.blockMap = blockMap;
// uncovered is unique
const blockUncoveredRanges = blockRanges.filter((it) => it.count === 0);
blockUncoveredRanges.sort((a, b) => {
return a.startOffset - b.startOffset;
});
sortRanges(blockUncoveredRanges);
functionRange.blockUncoveredRanges = blockUncoveredRanges;
functionRange.blockCoveredRanges = blockRanges.filter((it) => it.count > 0);
}
Expand All @@ -66,17 +74,15 @@ const getCoverageInfo = (coverageList) => {
functionStaticRanges.push(functionRange);
}

// uncovered is unique
// cache uncovered
if (functionRange.count === 0) {
functionUncoveredRanges.push(functionRange);
}

});

// sort ranges
functionUncoveredRanges.sort((a, b) => {
return a.startOffset - b.startOffset;
});
sortRanges(functionUncoveredRanges);

return {
functionMap,
Expand Down

0 comments on commit 50961d4

Please sign in to comment.