aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/collect_coverage_entries.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-tracing-utils/src/collect_coverage_entries.ts')
-rw-r--r--packages/sol-tracing-utils/src/collect_coverage_entries.ts14
1 files changed, 7 insertions, 7 deletions
diff --git a/packages/sol-tracing-utils/src/collect_coverage_entries.ts b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
index 9e3591d74..d5045b106 100644
--- a/packages/sol-tracing-utils/src/collect_coverage_entries.ts
+++ b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
@@ -5,18 +5,18 @@ import * as parser from 'solidity-parser-antlr';
import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
import { getOffsetToLocation } from './source_maps';
-const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm;
-
// Parsing source code for each transaction/code is slow and therefore we cache it
const sourceHashToCoverageEntries: { [sourceHash: string]: CoverageEntriesDescription } = {};
-export const collectCoverageEntries = (contractSource: string) => {
+export const collectCoverageEntries = (contractSource: string, ignoreRegexp?: RegExp) => {
const sourceHash = ethUtil.sha3(contractSource).toString('hex');
if (_.isUndefined(sourceHashToCoverageEntries[sourceHash]) && !_.isUndefined(contractSource)) {
const ast = parser.parse(contractSource, { range: true });
const offsetToLocation = getOffsetToLocation(contractSource);
- const ignoreRangesBegingingAt = gatherRangesToIgnore(contractSource);
- const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBegingingAt);
+ const ignoreRangesBeginningAt = _.isUndefined(ignoreRegexp)
+ ? []
+ : gatherRangesToIgnore(contractSource, ignoreRegexp);
+ const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBeginningAt);
parser.visit(ast, visitor);
sourceHashToCoverageEntries[sourceHash] = visitor.getCollectedCoverageEntries();
}
@@ -25,12 +25,12 @@ export const collectCoverageEntries = (contractSource: string) => {
};
// Gather the start index of all code blocks preceeded by "/* solcov ignore next */"
-function gatherRangesToIgnore(contractSource: string): number[] {
+function gatherRangesToIgnore(contractSource: string, ignoreRegexp: RegExp): number[] {
const ignoreRangesStart = [];
let match;
do {
- match = IGNORE_RE.exec(contractSource);
+ match = ignoreRegexp.exec(contractSource);
if (match) {
const matchLen = match[0].length;
ignoreRangesStart.push(match.index + matchLen);