monocart-coverage-reports
Advanced tools
Comparing version 2.3.2 to 2.3.3
const Util = require('../utils/util.js'); | ||
const quickFindRange = (position, ranges) => { | ||
const quickFindRange = (position, ranges, startKey, endKey) => { | ||
let start = 0; | ||
@@ -9,7 +9,7 @@ let end = ranges.length - 1; | ||
const item = ranges[i]; | ||
if (position < item.startOffset) { | ||
if (position < item[startKey]) { | ||
end = i; | ||
continue; | ||
} | ||
if (position > item.endOffset) { | ||
if (position > item[endKey]) { | ||
start = i; | ||
@@ -22,3 +22,3 @@ continue; | ||
const endItem = ranges[end]; | ||
if (position < endItem.startOffset) { | ||
if (position < endItem[startKey]) { | ||
return ranges[start]; | ||
@@ -30,8 +30,8 @@ } | ||
const findInRanges = (start, end, ranges) => { | ||
const findInRanges = (start, end, ranges, startKey = 'startOffset', endKey = 'endOffset') => { | ||
if (!Util.isList(ranges)) { | ||
return; | ||
} | ||
const range = quickFindRange(start, ranges); | ||
if (start >= range.startOffset && end <= range.endOffset) { | ||
const range = quickFindRange(start, ranges, startKey, endKey); | ||
if (start >= range[startKey] && end <= range[endKey]) { | ||
return range; | ||
@@ -38,0 +38,0 @@ } |
@@ -29,3 +29,9 @@ const Util = require('../utils/util.js'); | ||
const { lineParser } = locator; | ||
const { lineParser, source } = locator; | ||
const maxLength = source.length; | ||
let startOffset = item.start; | ||
// extend left | ||
while (startOffset > 0 && Util.isBlank(source[startOffset - 1])) { | ||
startOffset -= 1; | ||
} | ||
@@ -41,3 +47,7 @@ // findLine 0-base | ||
const endLine = locator.getLine(line + n); | ||
const endOffset = endLine ? endLine.end : locator.source.length; | ||
let endOffset = endLine ? endLine.end : maxLength; | ||
// extend right | ||
while (endOffset < maxLength && Util.isBlank(source[endOffset + 1])) { | ||
endOffset += 1; | ||
} | ||
@@ -47,3 +57,3 @@ const nextItem = { | ||
n, | ||
startOffset: item.end, | ||
startOffset, | ||
endOffset | ||
@@ -55,2 +65,14 @@ }; | ||
// both v8 or c8 | ||
const hasIgnoreKey = (content) => { | ||
const v8Key = 'v8 ignore'; | ||
if (content.startsWith(v8Key)) { | ||
return v8Key.length; | ||
} | ||
const c8Key = 'c8 ignore'; | ||
if (content.startsWith(c8Key)) { | ||
return c8Key.length; | ||
} | ||
}; | ||
const getIgnoredRanges = (locator, options) => { | ||
@@ -78,8 +100,8 @@ if (!options.v8Ignore) { | ||
const v8IgnoreKey = 'v8 ignore'; | ||
if (!content.startsWith(v8IgnoreKey)) { | ||
const ignoreKey = hasIgnoreKey(content); | ||
if (!ignoreKey) { | ||
return; | ||
} | ||
content = content.slice(v8IgnoreKey.length).trim(); | ||
content = content.slice(ignoreKey).trim(); | ||
@@ -89,3 +111,3 @@ if (ignoreStart) { | ||
if (content === 'stop') { | ||
ignoreStart.endOffset = start; | ||
ignoreStart.endOffset = end; | ||
ignoreStart = null; | ||
@@ -100,5 +122,5 @@ } | ||
ignoreStart = { | ||
type: 'start', | ||
startOffset: end, | ||
endOffset: end | ||
type: 'start-stop', | ||
startOffset: start, | ||
endOffset: start | ||
}; | ||
@@ -105,0 +127,0 @@ list.push(ignoreStart); |
@@ -244,4 +244,7 @@ const Util = { | ||
isBlank: (codeStr) => { | ||
const blankBlock = /\S/; | ||
return !blankBlock.test(codeStr); | ||
if (typeof codeStr === 'string') { | ||
const blankBlock = /\S/; | ||
return !blankBlock.test(codeStr); | ||
} | ||
return false; | ||
}, | ||
@@ -248,0 +251,0 @@ |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.3.2", | ||
"version": "2.3.3", | ||
"description": "Monocart coverage reports", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
895370
6969