It is sufficient to traverse direct children to match something like :has(> foo).
Created attachment 445189 [details] Patch
Committed r286180 (244563@main): <https://commits.webkit.org/244563@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 445189 [details].
<rdar://problem/85767760>