Cache code parsing
This commit is contained in:
		@@ -23,6 +23,7 @@
 | 
				
			|||||||
        "@0xproject/subproviders": "^0.7.0",
 | 
					        "@0xproject/subproviders": "^0.7.0",
 | 
				
			||||||
        "@0xproject/utils": "^0.3.4",
 | 
					        "@0xproject/utils": "^0.3.4",
 | 
				
			||||||
        "glob": "^7.1.2",
 | 
					        "glob": "^7.1.2",
 | 
				
			||||||
 | 
					        "ethereumjs-util": "^5.1.1",
 | 
				
			||||||
        "istanbul": "^0.4.5",
 | 
					        "istanbul": "^0.4.5",
 | 
				
			||||||
        "lodash": "^4.17.4",
 | 
					        "lodash": "^4.17.4",
 | 
				
			||||||
        "solidity-coverage": "^0.4.10",
 | 
					        "solidity-coverage": "^0.4.10",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import * as ethUtil from 'ethereumjs-util';
 | 
				
			||||||
import * as fs from 'fs';
 | 
					import * as fs from 'fs';
 | 
				
			||||||
import * as _ from 'lodash';
 | 
					import * as _ from 'lodash';
 | 
				
			||||||
import * as path from 'path';
 | 
					import * as path from 'path';
 | 
				
			||||||
@@ -6,11 +7,19 @@ import * as SolidityParser from 'solidity-parser-sc';
 | 
				
			|||||||
import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
 | 
					import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor';
 | 
				
			||||||
import { getLocationByOffset } from './source_maps';
 | 
					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) => {
 | 
					export const collectCoverageEntries = (contractSource: string, fileName: string) => {
 | 
				
			||||||
    const ast = SolidityParser.parse(contractSource);
 | 
					    const time = Date.now();
 | 
				
			||||||
    const locationByOffset = getLocationByOffset(contractSource);
 | 
					    const sourceHash = ethUtil.sha3(contractSource).toString('hex');
 | 
				
			||||||
    const astVisitor = new ASTVisitor(locationByOffset);
 | 
					    if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) {
 | 
				
			||||||
    astVisitor.walkAST(ast);
 | 
					        const ast = SolidityParser.parse(contractSource);
 | 
				
			||||||
    const coverageEntries = astVisitor.getCollectedCoverageEntries();
 | 
					        const locationByOffset = getLocationByOffset(contractSource);
 | 
				
			||||||
    return coverageEntries;
 | 
					        const astVisitor = new ASTVisitor(locationByOffset);
 | 
				
			||||||
 | 
					        astVisitor.walkAST(ast);
 | 
				
			||||||
 | 
					        coverageEntriesBySourceHash[sourceHash] = astVisitor.getCollectedCoverageEntries();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash];
 | 
				
			||||||
 | 
					    return coverageEntriesDescription;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,5 +3,10 @@
 | 
				
			|||||||
    "compilerOptions": {
 | 
					    "compilerOptions": {
 | 
				
			||||||
        "outDir": "lib"
 | 
					        "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