From f0f0235591de45060ffa17a40de598a43ca79c84 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Tue, 2 Oct 2018 12:50:07 -0400 Subject: [PATCH] Account for empty initialization in loops --- lib/modules/coverage/contract_source.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/modules/coverage/contract_source.js b/lib/modules/coverage/contract_source.js index 734ee89fc..44b518ce4 100644 --- a/lib/modules/coverage/contract_source.js +++ b/lib/modules/coverage/contract_source.js @@ -249,18 +249,20 @@ class ContractSource { let sourceMap = new SourceMap(node.src); let bodySourceMap = new SourceMap(node.body.src); let forLoopDeclaration = sourceMap.subtract(bodySourceMap).toString(); - let initializationLocation = this.sourceMapToLocations(node.initializationExpression.src); location = this.sourceMapToLocations(forLoopDeclaration); + let markExpression = node.initializationExpression || node.loopExpression; + let expressionLocation = this.sourceMapToLocations(markExpression.src); + + if(!sourceMapToNodeType[markExpression.src]) sourceMapToNodeType[markExpression.src] = []; + sourceMapToNodeType[markExpression.src].push({type: 's', id: node.id, body: {loc: location}}); + markLocations = [expressionLocation]; + coverage.s[node.id] = 0; coverage.statementMap[node.id] = location; - if(!sourceMapToNodeType[node.initializationExpression.src]) sourceMapToNodeType[node.initializationExpression.src] = []; - sourceMapToNodeType[node.initializationExpression.src].push({type: 's', id: node.id, body: {loc: location}}); - children = node.body.statements; - markLocations = [initializationLocation]; break; }