@@ -51,6 +51,10 @@ const create = context => {
51
51
```
52
52
*/
53
53
const findRootReference = node => {
54
+ if ( ! node ) {
55
+ return ;
56
+ }
57
+
54
58
if ( node . type === 'Identifier' ) {
55
59
const reference = findReference ( node . name ) ;
56
60
@@ -80,18 +84,31 @@ const create = context => {
80
84
2. `RegExp` class can't be looked up so the function just checks for the name `RegExp`.
81
85
*/
82
86
const isRegExp = lookup => {
87
+ if ( ! lookup ) {
88
+ return false ;
89
+ }
90
+
83
91
if ( lookup . regex ) {
84
92
return true ;
85
93
}
86
94
87
95
// Look up references in case it's a variable or RegExp declaration.
88
96
const reference = findRootReference ( lookup ) ;
97
+
98
+ if ( ! reference ) {
99
+ return false ;
100
+ }
101
+
89
102
return reference . regex ?? reference . name === 'RegExp' ;
90
103
} ;
91
104
92
105
const booleanHandler = node => {
93
106
const firstArg = node . arguments [ 0 ] ;
94
107
108
+ if ( ! firstArg ) {
109
+ return ;
110
+ }
111
+
95
112
const isFunctionCall = firstArg . type === 'CallExpression' ;
96
113
if ( ! isFunctionCall || ! firstArg . callee . property ) {
97
114
return ;
@@ -144,6 +161,11 @@ const create = context => {
144
161
}
145
162
146
163
const matchee = secondArgumentIsRegex ? firstArg : secondArg ;
164
+
165
+ if ( ! matchee ) {
166
+ return ;
167
+ }
168
+
147
169
const regex = secondArgumentIsRegex ? secondArg : firstArg ;
148
170
149
171
const booleanFixer = assertion => fixer => {
@@ -179,7 +201,12 @@ const create = context => {
179
201
CallExpression : visitIf ( [
180
202
ava . isInTestFile ,
181
203
ava . isInTestNode ,
182
- ] ) ( node => {
204
+ ] ,
205
+ ) ( node => {
206
+ if ( ! node ?. callee ?. property ) {
207
+ return ;
208
+ }
209
+
183
210
const isAssertion = node . callee . type === 'MemberExpression'
184
211
&& util . getNameOfRootNodeObject ( node . callee ) === 't' ;
185
212
0 commit comments