From bf7f4db1797f21c1bb393d5f90932c83056a11bc 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 734ee89f..44b518ce 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; }