import type { ReactElement, ReactElementFiber } from '../element/types'; function findTexts(element: ReactElement, texts: string[]): string[] { if (!element) { return texts; } if (!element.props) { return texts; } if (typeof element.props === 'string') { texts.push(element.props); return texts; } if (!element.props.children) { return texts; } if (typeof element.props.children !== 'object') { texts.push(element.props.children.toString()); return texts; } return findTextsByChildren(element.props.children, texts); } function findTextsByChildren(children: any, texts: string[]): string[] { if (!children) { return texts; } if (typeof children === 'string') { texts.push(children); return texts; } if (!children.length) { return findTexts(children, texts); } for (let i = 0; i < children.length; i++) { findTexts(children[i], texts); } return texts; } export default function getTexts(node: ReactElementFiber): string[] { if (!node || !node.memoizedProps) { return []; } const texts = findTextsByChildren(node.memoizedProps.children, []); return texts; }