aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/collect_coverage_entries.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2019-01-25 09:35:25 +0800
committerfragosti <francesco.agosti93@gmail.com>2019-01-25 09:35:25 +0800
commita9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1 (patch)
treeac608e0471b472b76d9128d52c7099887b5cccfa /packages/sol-tracing-utils/src/collect_coverage_entries.ts
parenta8c3b4126e6b62f423a71dba7ba55a85e7e2bde7 (diff)
parent5b06595a6b6d459d53840d066fb204c0a9e3ed02 (diff)
downloaddexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar.gz
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar.bz2
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar.lz
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar.xz
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.tar.zst
dexon-0x-contracts-a9ca1f3174279dce6aa429d1c62a8f2ffb5ae5a1.zip
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into development
Diffstat (limited to 'packages/sol-tracing-utils/src/collect_coverage_entries.ts')
-rw-r--r--packages/sol-tracing-utils/src/collect_coverage_entries.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/packages/sol-tracing-utils/src/collect_coverage_entries.ts b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
index bdbcd613e..d5045b106 100644
--- a/packages/sol-tracing-utils/src/collect_coverage_entries.ts
+++ b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
@@ -3,34 +3,34 @@ import * as _ from 'lodash';
import * as parser from 'solidity-parser-antlr';
import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
-import { getLocationByOffset } from './source_maps';
-
-const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm;
+import { getOffsetToLocation } from './source_maps';
// Parsing source code for each transaction/code is slow and therefore we cache it
-const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {};
+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(coverageEntriesBySourceHash[sourceHash]) && !_.isUndefined(contractSource)) {
+ if (_.isUndefined(sourceHashToCoverageEntries[sourceHash]) && !_.isUndefined(contractSource)) {
const ast = parser.parse(contractSource, { range: true });
- const locationByOffset = getLocationByOffset(contractSource);
- const ignoreRangesBegingingAt = gatherRangesToIgnore(contractSource);
- const visitor = new ASTVisitor(locationByOffset, ignoreRangesBegingingAt);
+ const offsetToLocation = getOffsetToLocation(contractSource);
+ const ignoreRangesBeginningAt = _.isUndefined(ignoreRegexp)
+ ? []
+ : gatherRangesToIgnore(contractSource, ignoreRegexp);
+ const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBeginningAt);
parser.visit(ast, visitor);
- coverageEntriesBySourceHash[sourceHash] = visitor.getCollectedCoverageEntries();
+ sourceHashToCoverageEntries[sourceHash] = visitor.getCollectedCoverageEntries();
}
- const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash];
+ const coverageEntriesDescription = sourceHashToCoverageEntries[sourceHash];
return coverageEntriesDescription;
};
// 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);