aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/instrument_solidity.ts
blob: ac58270cb2b20447e9f20079e4d8baec20aff2a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import * as SolidityParser from 'solidity-parser-sc';

import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
import { getLocationByOffset } from './source_maps';

export const collectCoverageEntries = (contractSource: string, fileName: string) => {
    const ast = SolidityParser.parse(contractSource);
    const locationByOffset = getLocationByOffset(contractSource);
    const astVisitor = new ASTVisitor(locationByOffset);
    astVisitor.walkAST(ast);
    const coverageEntries = astVisitor.getCollectedCoverageEntries();
    return coverageEntries;
};