@@ -405,16 +405,6 @@ function isTestCall(node, parent) {
405405/** @return {(node: Node) => boolean } */
406406const skipChainExpression = ( fn ) => ( node ) => {
407407 if ( node ?. type === "ChainExpression" ) {
408- // @ts -expect-error
409- if ( ! node . object ) {
410- // @ts -expect-error
411- node . object = node . expression . object ;
412- }
413- // @ts -expect-error
414- if ( ! node . property ) {
415- // @ts -expect-error
416- node . property = node . expression . property ;
417- }
418408 node = node . expression ;
419409 }
420410
@@ -429,6 +419,22 @@ const isMemberExpression = skipChainExpression(
429419 createTypeCheckFunction ( [ "MemberExpression" , "OptionalMemberExpression" ] ) ,
430420) ;
431421
422+ /**
423+ * Retrieves a property from a node, considering any ChainExpression.
424+ * If the node is a ChainExpression, the property is obtained from its expression.
425+ * Otherwise, the property is obtained directly from the node.
426+ *
427+ * @param {Node } node - The AST node to be processed.
428+ * @param {string } property - The property name to retrieve.
429+ * @returns The property value from the node or its expression.
430+ */
431+ function getChainProp ( node , property ) {
432+ if ( node . type === "ChainExpression" ) {
433+ return node . expression [ property ] ;
434+ }
435+ return node [ property ] ;
436+ }
437+
432438/**
433439 *
434440 * @param {any } node
@@ -769,7 +775,7 @@ function isSimpleCallArgument(node, depth = 2) {
769775 if ( isCallLikeExpression ( node ) ) {
770776 if (
771777 node . type === "ImportExpression" ||
772- isSimpleCallArgument ( node . callee , depth )
778+ isSimpleCallArgument ( getChainProp ( node , " callee" ) , depth )
773779 ) {
774780 const args = getCallArguments ( node ) ;
775781 return args . length <= depth && args . every ( isChildSimple ) ;
@@ -779,8 +785,8 @@ function isSimpleCallArgument(node, depth = 2) {
779785
780786 if ( isMemberExpression ( node ) ) {
781787 return (
782- isSimpleCallArgument ( node . object , depth ) &&
783- isSimpleCallArgument ( node . property , depth )
788+ isSimpleCallArgument ( getChainProp ( node , " object" ) , depth ) &&
789+ isSimpleCallArgument ( getChainProp ( node , " property" ) , depth )
784790 ) ;
785791 }
786792
@@ -1232,6 +1238,7 @@ export {
12321238 createTypeCheckFunction ,
12331239 getCallArguments ,
12341240 getCallArgumentSelector ,
1241+ getChainProp ,
12351242 getComments ,
12361243 getFunctionParameters ,
12371244 getLeftSide ,
0 commit comments