Cache code parsing
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
"@0xproject/subproviders": "^0.7.0",
|
||||
"@0xproject/utils": "^0.3.4",
|
||||
"glob": "^7.1.2",
|
||||
"ethereumjs-util": "^5.1.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"lodash": "^4.17.4",
|
||||
"solidity-coverage": "^0.4.10",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as fs from 'fs';
|
||||
import * as _ from 'lodash';
|
||||
import * as path from 'path';
|
||||
@@ -6,11 +7,19 @@ import * as SolidityParser from 'solidity-parser-sc';
|
||||
import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
|
||||
import { getLocationByOffset } from './source_maps';
|
||||
|
||||
// Parsing source code for each transaction/code is slow and therefore we cache it
|
||||
const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {};
|
||||
|
||||
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;
|
||||
const time = Date.now();
|
||||
const sourceHash = ethUtil.sha3(contractSource).toString('hex');
|
||||
if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) {
|
||||
const ast = SolidityParser.parse(contractSource);
|
||||
const locationByOffset = getLocationByOffset(contractSource);
|
||||
const astVisitor = new ASTVisitor(locationByOffset);
|
||||
astVisitor.walkAST(ast);
|
||||
coverageEntriesBySourceHash[sourceHash] = astVisitor.getCollectedCoverageEntries();
|
||||
}
|
||||
const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash];
|
||||
return coverageEntriesDescription;
|
||||
};
|
||||
|
||||
@@ -3,5 +3,10 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"../../node_modules/types-bn/index.d.ts",
|
||||
"../../node_modules/web3-typescript-typings/index.d.ts",
|
||||
"../../node_modules/types-ethereumjs-util/index.d.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user