@@ -21,10 +21,19 @@ const create = context => {
21
21
22
22
let currentSegmentInfo ;
23
23
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
+
24
35
function segmentStart ( segment ) {
25
36
// A new CodePathSegment has started, create an "info" object to track this segments state.
26
- segmentInfoStack . push ( currentSegmentInfo ) ;
27
-
28
37
currentSegmentInfo = {
29
38
ended : false ,
30
39
prev : segment . prevSegments . map ( previousSegment => segmentInfoMap . get ( previousSegment . id ) )
@@ -34,12 +43,14 @@ const create = context => {
34
43
}
35
44
36
45
function segmentEnd ( ) {
37
- currentSegmentInfo = segmentInfoStack . pop ( ) ;
46
+ currentSegmentInfo = undefined ;
38
47
}
39
48
40
49
function checkForEndExpression ( node ) {
41
50
if ( isEndExpression ( node ) ) {
42
- currentSegmentInfo . ended = true ;
51
+ if ( currentSegmentInfo !== undefined ) {
52
+ currentSegmentInfo . ended = true ;
53
+ }
43
54
}
44
55
}
45
56
@@ -48,6 +59,12 @@ const create = context => {
48
59
return ;
49
60
}
50
61
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
+
51
68
const ended = [ currentSegmentInfo ]
52
69
. concat ( currentSegmentInfo . prev )
53
70
. filter ( info => info . ended ) ;
@@ -85,6 +102,8 @@ const create = context => {
85
102
checkStatement ( node ) ;
86
103
}
87
104
} ,
105
+ onCodePathStart : pathStart ,
106
+ onCodePathEnd : pathEnd ,
88
107
onCodePathSegmentStart : segmentStart ,
89
108
onCodePathSegmentEnd : segmentEnd ,
90
109
CallExpression : checkForEndExpression
0 commit comments