@@ -21,10 +21,19 @@ const create = context => {
2121
2222 let currentSegmentInfo ;
2323
24+ function pathStart ( ) {
25+ if ( currentSegmentInfo !== undefined ) {
26+ segmentInfoStack . push ( currentSegmentInfo ) ;
27+ currentSegmentInfo = undefined ;
28+ }
29+ }
30+
31+ function pathEnd ( ) {
32+ currentSegmentInfo = segmentInfoStack . pop ( ) ;
33+ }
34+
2435 function segmentStart ( segment ) {
2536 // A new CodePathSegment has started, create an "info" object to track this segments state.
26- segmentInfoStack . push ( currentSegmentInfo ) ;
27-
2837 currentSegmentInfo = {
2938 ended : false ,
3039 prev : segment . prevSegments . map ( previousSegment => segmentInfoMap . get ( previousSegment . id ) )
@@ -34,12 +43,14 @@ const create = context => {
3443 }
3544
3645 function segmentEnd ( ) {
37- currentSegmentInfo = segmentInfoStack . pop ( ) ;
46+ currentSegmentInfo = undefined ;
3847 }
3948
4049 function checkForEndExpression ( node ) {
4150 if ( isEndExpression ( node ) ) {
42- currentSegmentInfo . ended = true ;
51+ if ( currentSegmentInfo !== undefined ) {
52+ currentSegmentInfo . ended = true ;
53+ }
4354 }
4455 }
4556
@@ -48,6 +59,12 @@ const create = context => {
4859 return ;
4960 }
5061
62+ // If there is no current segment (this occurs in unreachable code), then we
63+ // can't check whether `t.end()` was called
64+ if ( currentSegmentInfo === undefined ) {
65+ return ;
66+ }
67+
5168 const ended = [ currentSegmentInfo ]
5269 . concat ( currentSegmentInfo . prev )
5370 . filter ( info => info . ended ) ;
@@ -85,6 +102,8 @@ const create = context => {
85102 checkStatement ( node ) ;
86103 }
87104 } ,
105+ onCodePathStart : pathStart ,
106+ onCodePathEnd : pathEnd ,
88107 onCodePathSegmentStart : segmentStart ,
89108 onCodePathSegmentEnd : segmentEnd ,
90109 CallExpression : checkForEndExpression
0 commit comments