From 1a4e99431bf0cfc8c5db2235a935d62ebb8469b2 Mon Sep 17 00:00:00 2001 From: perissology Date: Mon, 25 Jun 2018 07:55:19 -0700 Subject: support ignoring entire contracts --- packages/sol-cov/src/ast_visitor.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'packages/sol-cov') diff --git a/packages/sol-cov/src/ast_visitor.ts b/packages/sol-cov/src/ast_visitor.ts index 49b7ac4bd..166cf13bd 100644 --- a/packages/sol-cov/src/ast_visitor.ts +++ b/packages/sol-cov/src/ast_visitor.ts @@ -23,11 +23,13 @@ export class ASTVisitor { private _modifiersStatementIds: number[] = []; private _statementMap: StatementMap = {}; private _locationByOffset: LocationByOffset; - private _ignoreRangesBeginingAt: number[]; + private _ignoreRangesBeginningAt: number[]; + // keep track of contract/function ranges that are to be ignored + // so we can also ignore any children nodes within the contract/function private _ignoreRangesWithin: Array<[number, number]> = []; - constructor(locationByOffset: LocationByOffset, ignoreRangesBeginingAt: number[] = []) { + constructor(locationByOffset: LocationByOffset, ignoreRangesBeginningAt: number[] = []) { this._locationByOffset = locationByOffset; - this._ignoreRangesBeginingAt = ignoreRangesBeginingAt; + this._ignoreRangesBeginningAt = ignoreRangesBeginningAt; } public getCollectedCoverageEntries(): CoverageEntriesDescription { const coverageEntriesDescription = { @@ -45,6 +47,11 @@ export class ASTVisitor { public FunctionDefinition(ast: Parser.FunctionDefinition): void { this._visitFunctionLikeDefinition(ast); } + public ContractDefinition(ast: Parser.ContractDefinition): void { + if (this._ignoreExpression(ast)) { + this._ignoreRangesWithin.push(ast.range as [number, number]); + } + } public ModifierDefinition(ast: Parser.ModifierDefinition): void { this._visitFunctionLikeDefinition(ast); } @@ -143,13 +150,10 @@ export class ASTVisitor { this._ignoreRangesWithin, ([rangeStart, rangeEnd]: [number, number]) => astStart >= rangeStart && astEnd <= rangeEnd, ); - return this._ignoreRangesBeginingAt.includes(astStart) || isRangeIgnored; + return this._ignoreRangesBeginningAt.includes(astStart) || isRangeIgnored; } private _visitFunctionLikeDefinition(ast: Parser.ModifierDefinition | Parser.FunctionDefinition): void { if (this._ignoreExpression(ast)) { - // we want to ignore everything within this function - // add this nodes range to the ignoreRangesWithin array - // so we can ignore any later nodes that are children of this node this._ignoreRangesWithin.push(ast.range as [number, number]); return; } -- cgit