File tree 1 file changed +6
-1
lines changed
packages/eslint-plugin-react-hooks/src
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -1429,7 +1429,7 @@ function scanForDeclaredBareFunctions({
1429
1429
*/
1430
1430
function getDependency ( node ) {
1431
1431
if (
1432
- node . parent . type === 'MemberExpression' &&
1432
+ ( node . parent . type === 'MemberExpression' || node . parent . type === 'OptionalMemberExpression' ) &&
1433
1433
node . parent . object === node &&
1434
1434
node . parent . property . name !== 'current' &&
1435
1435
! node . parent . computed &&
@@ -1456,6 +1456,7 @@ function getDependency(node) {
1456
1456
* (foo) -> 'foo'
1457
1457
* foo.(bar) -> 'foo.bar'
1458
1458
* foo.bar.(baz) -> 'foo.bar.baz'
1459
+ * foo?.(bar) -> 'foo?.bar'
1459
1460
* Otherwise throw.
1460
1461
*/
1461
1462
function toPropertyAccessString ( node ) {
@@ -1465,6 +1466,10 @@ function toPropertyAccessString(node) {
1465
1466
const object = toPropertyAccessString ( node . object ) ;
1466
1467
const property = toPropertyAccessString ( node . property ) ;
1467
1468
return `${ object } .${ property } ` ;
1469
+ } else if ( node . type === 'OptionalMemberExpression' && ! node . computed ) {
1470
+ const object = toPropertyAccessString ( node . object ) ;
1471
+ const property = toPropertyAccessString ( node . property ) ;
1472
+ return `${ object } ?.${ property } ` ;
1468
1473
} else {
1469
1474
throw new Error ( `Unsupported node type: ${ node . type } ` ) ;
1470
1475
}
You can’t perform that action at this time.
0 commit comments