@@ -170,6 +170,7 @@ Future<Map<String, dynamic>> _getAllCoverage(
170170 isolateReport,
171171 includeDart,
172172 functionCoverage,
173+ branchCoverage,
173174 coverableLineCache,
174175 scopedOutput);
175176 allCoverage.addAll (coverage);
@@ -244,6 +245,7 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
244245 SourceReport report,
245246 bool includeDart,
246247 bool functionCoverage,
248+ bool branchCoverage,
247249 Map <String , Set <int >>? coverableLineCache,
248250 Set <String > scopedOutput) async {
249251 final hitMaps = < Uri , HitMap > {};
@@ -262,7 +264,17 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
262264 return scripts[scriptRef];
263265 }
264266
265- HitMap getHitMap (Uri scriptUri) => hitMaps.putIfAbsent (scriptUri, HitMap .new );
267+ HitMap getHitMap (Uri scriptUri) => hitMaps.putIfAbsent (scriptUri, () {
268+ final hits = HitMap ();
269+ if (functionCoverage) {
270+ hits.funcNames = < int , String > {};
271+ hits.funcHits = < int , int > {};
272+ }
273+ if (branchCoverage) {
274+ hits.branchHits = < int , int > {};
275+ }
276+ return hits;
277+ });
266278
267279 Future <void > processFunction (FuncRef funcRef) async {
268280 final func = await service.getObject (isolateRef.id! , funcRef.id! ) as Func ;
@@ -290,8 +302,7 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
290302 return ;
291303 }
292304 final hits = getHitMap (Uri .parse (script.uri! ));
293- hits.funcHits ?? = < int , int > {};
294- (hits.funcNames ?? = < int , String > {})[line] = funcName;
305+ hits.funcNames! [line] = funcName;
295306 }
296307
297308 for (var range in report.ranges! ) {
@@ -385,13 +396,12 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
385396 hits.funcHits? .putIfAbsent (line, () => 0 );
386397 });
387398
388- final branchCoverage = range.branchCoverage;
389- if (branchCoverage != null ) {
390- hits.branchHits ?? = < int , int > {};
391- forEachLine (branchCoverage.hits, (line) {
399+ final branches = range.branchCoverage;
400+ if (branchCoverage && branches != null ) {
401+ forEachLine (branches.hits, (line) {
392402 hits.branchHits! .increment (line);
393403 });
394- forEachLine (branchCoverage .misses, (line) {
404+ forEachLine (branches .misses, (line) {
395405 hits.branchHits! .putIfAbsent (line, () => 0 );
396406 });
397407 }
0 commit comments