import { NodePath } from '@babel/traverse' ; import * as t from '@babel/types' ; export function findTopmostFunction ( jsxPath ) { const isFunction = ( path ) => path . isArrowFunctionExpression ( ) || path . isFunctionDeclaration ( ) || path . isFunctionExpression ( ) ; let compFn = jsxPath . findParent ( isFunction ) ; while ( compFn ) { const parent = compFn . findParent ( isFunction ) ; if ( parent ) { compFn = parent ; } else { break ; } } if ( ! compFn ) { return null ; } return compFn ; }