@@ -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,27 @@ 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 => {
83
- if ( lookup . regex ) {
87
+ if ( lookup ? .regex ) {
84
88
return true ;
85
89
}
86
90
87
91
// Look up references in case it's a variable or RegExp declaration.
88
92
const reference = findRootReference ( lookup ) ;
93
+
94
+ if ( ! reference ) {
95
+ return false ;
96
+ }
97
+
89
98
return reference . regex ?? reference . name === 'RegExp' ;
90
99
} ;
91
100
92
101
const booleanHandler = node => {
93
102
const firstArg = node . arguments [ 0 ] ;
94
103
104
+ if ( ! firstArg ) {
105
+ return ;
106
+ }
107
+
95
108
const isFunctionCall = firstArg . type === 'CallExpression' ;
96
109
if ( ! isFunctionCall || ! firstArg . callee . property ) {
97
110
return ;
@@ -144,6 +157,11 @@ const create = context => {
144
157
}
145
158
146
159
const matchee = secondArgumentIsRegex ? firstArg : secondArg ;
160
+
161
+ if ( ! matchee ) {
162
+ return ;
163
+ }
164
+
147
165
const regex = secondArgumentIsRegex ? secondArg : firstArg ;
148
166
149
167
const booleanFixer = assertion => fixer => {
@@ -179,7 +197,12 @@ const create = context => {
179
197
CallExpression : visitIf ( [
180
198
ava . isInTestFile ,
181
199
ava . isInTestNode ,
182
- ] ) ( node => {
200
+ ] ,
201
+ ) ( node => {
202
+ if ( ! node ?. callee ?. property ) {
203
+ return ;
204
+ }
205
+
183
206
const isAssertion = node . callee . type === 'MemberExpression'
184
207
&& util . getNameOfRootNodeObject ( node . callee ) === 't' ;
185
208
0 commit comments