@@ -108,7 +108,7 @@ function componentRule(rule, context) {
108
108
var components = new Components ( ) ;
109
109
110
110
// Utilities for component detection
111
- context . react = {
111
+ var utils = {
112
112
113
113
/**
114
114
* Check if the node is a React ES5 component
@@ -176,9 +176,9 @@ function componentRule(rule, context) {
176
176
*/
177
177
getParentComponent : function ( ) {
178
178
return (
179
- context . react . getParentES6Component ( ) ||
180
- context . react . getParentES5Component ( ) ||
181
- context . react . getParentStatelessComponent ( )
179
+ utils . getParentES6Component ( ) ||
180
+ utils . getParentES5Component ( ) ||
181
+ utils . getParentStatelessComponent ( )
182
182
) ;
183
183
} ,
184
184
@@ -191,7 +191,7 @@ function componentRule(rule, context) {
191
191
var scope = context . getScope ( ) ;
192
192
while ( scope ) {
193
193
var node = scope . block && scope . block . parent && scope . block . parent . parent ;
194
- if ( node && context . react . isES5Component ( node ) ) {
194
+ if ( node && utils . isES5Component ( node ) ) {
195
195
return node ;
196
196
}
197
197
scope = scope . upper ;
@@ -210,7 +210,7 @@ function componentRule(rule, context) {
210
210
scope = scope . upper ;
211
211
}
212
212
var node = scope && scope . block ;
213
- if ( ! node || ! context . react . isES6Component ( node ) ) {
213
+ if ( ! node || ! utils . isES6Component ( node ) ) {
214
214
return null ;
215
215
}
216
216
return node ;
@@ -316,57 +316,57 @@ function componentRule(rule, context) {
316
316
// Component detection instructions
317
317
var detectionInstructions = {
318
318
ClassDeclaration : function ( node ) {
319
- if ( ! context . react . isES6Component ( node ) ) {
319
+ if ( ! utils . isES6Component ( node ) ) {
320
320
return ;
321
321
}
322
322
components . add ( node , 2 ) ;
323
323
} ,
324
324
325
325
ClassProperty : function ( node ) {
326
- node = context . react . getParentComponent ( ) ;
326
+ node = utils . getParentComponent ( ) ;
327
327
if ( ! node ) {
328
328
return ;
329
329
}
330
330
components . add ( node , 2 ) ;
331
331
} ,
332
332
333
333
ObjectExpression : function ( node ) {
334
- if ( ! context . react . isES5Component ( node ) ) {
334
+ if ( ! utils . isES5Component ( node ) ) {
335
335
return ;
336
336
}
337
337
components . add ( node , 2 ) ;
338
338
} ,
339
339
340
340
FunctionExpression : function ( node ) {
341
- node = context . react . getParentComponent ( ) ;
341
+ node = utils . getParentComponent ( ) ;
342
342
if ( ! node ) {
343
343
return ;
344
344
}
345
345
components . add ( node , 1 ) ;
346
346
} ,
347
347
348
348
FunctionDeclaration : function ( node ) {
349
- node = context . react . getParentComponent ( ) ;
349
+ node = utils . getParentComponent ( ) ;
350
350
if ( ! node ) {
351
351
return ;
352
352
}
353
353
components . add ( node , 1 ) ;
354
354
} ,
355
355
356
356
ArrowFunctionExpression : function ( node ) {
357
- node = context . react . getParentComponent ( ) ;
357
+ node = utils . getParentComponent ( ) ;
358
358
if ( ! node ) {
359
359
return ;
360
360
}
361
- if ( node . expression && context . react . isReturningJSX ( node ) ) {
361
+ if ( node . expression && utils . isReturningJSX ( node ) ) {
362
362
components . add ( node , 2 ) ;
363
363
} else {
364
364
components . add ( node , 1 ) ;
365
365
}
366
366
} ,
367
367
368
368
ThisExpression : function ( node ) {
369
- node = context . react . getParentComponent ( ) ;
369
+ node = utils . getParentComponent ( ) ;
370
370
if ( ! node || ! / F u n c t i o n / . test ( node . type ) ) {
371
371
return ;
372
372
}
@@ -375,10 +375,10 @@ function componentRule(rule, context) {
375
375
} ,
376
376
377
377
ReturnStatement : function ( node ) {
378
- if ( ! context . react . isReturningJSX ( node ) ) {
378
+ if ( ! utils . isReturningJSX ( node ) ) {
379
379
return ;
380
380
}
381
- node = context . react . getParentComponent ( ) ;
381
+ node = utils . getParentComponent ( ) ;
382
382
if ( ! node ) {
383
383
return ;
384
384
}
@@ -387,7 +387,7 @@ function componentRule(rule, context) {
387
387
} ;
388
388
389
389
// Update the provided rule instructions to add the component detection
390
- var ruleInstructions = rule ( context , components ) ;
390
+ var ruleInstructions = rule ( context , components , utils ) ;
391
391
var updatedRuleInstructions = util . _extend ( { } , ruleInstructions ) ;
392
392
Object . keys ( detectionInstructions ) . forEach ( function ( instruction ) {
393
393
updatedRuleInstructions [ instruction ] = function ( node ) {
0 commit comments