@@ -4,8 +4,9 @@ import { normalizeType } from '../../snapshot-processing.ts';
44import { collectIosScrollIndicatorPresentation } from './scroll.ts' ;
55import {
66 areRectsApproximatelyEqual ,
7- collectDescendants ,
7+ findDescendant ,
88 findLargestViewportRect ,
9+ forEachDescendant ,
910 isRepeatedStaticNode ,
1011 isScrollableSnapshotType ,
1112 isSemanticActionNode ,
@@ -35,9 +36,13 @@ function collectIosReactNativeOverlayWrapperSuppression(
3536 return ;
3637 }
3738
38- const hasVisibleBannerDescendant = collectDescendants ( nodes , position ) . some (
39- ( descendant ) =>
40- descendant . label ?. trim ( ) === nodeLabel && isReactNativeCollapsedWarningBanner ( descendant ) ,
39+ const hasVisibleBannerDescendant = Boolean (
40+ findDescendant (
41+ nodes ,
42+ position ,
43+ ( descendant ) =>
44+ descendant . label ?. trim ( ) === nodeLabel && isReactNativeCollapsedWarningBanner ( descendant ) ,
45+ ) ,
4146 ) ;
4247 if ( hasVisibleBannerDescendant ) {
4348 suppressedIndexes . add ( node . index ) ;
@@ -81,59 +86,66 @@ function collectRepeatedStaticSuppressionForNode(
8186 nodeLabel : string ,
8287 suppressedIndexes : Set < number > ,
8388) : void {
84- const descendants = collectDescendants ( nodes , position ) ;
8589 const type = normalizeType ( node . type ?? '' ) ;
8690 if ( type === 'statictext' || type === 'link' ) {
87- suppressRepeatedStaticDescendants ( descendants , nodeLabel , suppressedIndexes ) ;
91+ suppressRepeatedStaticDescendants ( nodes , position , nodeLabel , suppressedIndexes ) ;
8892 return ;
8993 }
9094 if ( type !== 'other' ) {
9195 return ;
9296 }
93- if ( hasEquivalentSemanticDescendant ( descendants , nodeLabel ) ) {
97+ if ( hasEquivalentSemanticDescendant ( nodes , position , nodeLabel ) ) {
9498 suppressedIndexes . add ( node . index ) ;
9599 return ;
96100 }
97- suppressRepeatedStaticDescendants ( descendants , nodeLabel , suppressedIndexes ) ;
101+ suppressRepeatedStaticDescendants ( nodes , position , nodeLabel , suppressedIndexes ) ;
98102}
99103
100104function hasEquivalentSemanticDescendant (
101- descendants : RawSnapshotNode [ ] ,
105+ nodes : RawSnapshotNode [ ] ,
106+ position : number ,
102107 nodeLabel : string ,
103108) : boolean {
104- return descendants . some ( ( descendant ) => {
105- const type = normalizeType ( descendant . type ?? '' ) ;
106- return (
107- ( type === 'link' || type === 'searchfield' || isScrollableSnapshotType ( descendant . type ) ) &&
108- descendant . label ?. trim ( ) === nodeLabel
109- ) ;
110- } ) ;
109+ return Boolean (
110+ findDescendant ( nodes , position , ( descendant ) => {
111+ const type = normalizeType ( descendant . type ?? '' ) ;
112+ return (
113+ ( type === 'link' || type === 'searchfield' || isScrollableSnapshotType ( descendant . type ) ) &&
114+ descendant . label ?. trim ( ) === nodeLabel
115+ ) ;
116+ } ) ,
117+ ) ;
111118}
112119
113120function suppressRepeatedStaticDescendants (
114- descendants : RawSnapshotNode [ ] ,
121+ nodes : RawSnapshotNode [ ] ,
122+ position : number ,
115123 label : string ,
116124 suppressedIndexes : Set < number > ,
117125) : void {
118- for ( const descendant of descendants ) {
126+ forEachDescendant ( nodes , position , ( descendant ) => {
119127 if ( isRepeatedStaticNode ( descendant , label ) ) {
120128 suppressedIndexes . add ( descendant . index ) ;
121129 }
122- }
130+ } ) ;
123131}
124132
125133function collectIosActionWrapperSuppression (
126134 nodes : RawSnapshotNode [ ] ,
127135 suppressedIndexes : Set < number > ,
128136) : void {
129137 forEachOtherNodeWithLabel ( nodes , ( node , nodeLabel , position ) => {
130- const semanticDescendant = collectDescendants ( nodes , position ) . find (
131- ( descendant ) =>
138+ if ( ! node . rect ) {
139+ return ;
140+ }
141+ const semanticDescendant = findDescendant ( nodes , position , ( descendant ) => {
142+ return (
132143 isSemanticActionNode ( descendant ) &&
133144 descendant . label ?. trim ( ) === nodeLabel &&
134145 ( areRectsApproximatelyEqual ( descendant . rect , node . rect ) ||
135- isIosBackdropDismissWrapper ( node , descendant ) ) ,
136- ) ;
146+ isIosBackdropDismissWrapper ( node , descendant ) )
147+ ) ;
148+ } ) ;
137149 if ( semanticDescendant ) {
138150 suppressedIndexes . add ( node . index ) ;
139151 }
@@ -193,9 +205,9 @@ function collectIosOffscreenKeyboardSuppression(
193205 }
194206 suppressedIndexes . add ( node . index ) ;
195207 suppressOffscreenKeyboardAncestors ( node , nodes , suppressedIndexes , screenBottom ) ;
196- for ( const descendant of collectDescendants ( nodes , position ) ) {
208+ forEachDescendant ( nodes , position , ( descendant ) => {
197209 suppressedIndexes . add ( descendant . index ) ;
198- }
210+ } ) ;
199211 }
200212}
201213
@@ -255,8 +267,9 @@ function collectIosSearchToolbarSuppression(
255267 if ( node . label !== 'Toolbar' ) {
256268 continue ;
257269 }
258- const descendants = collectDescendants ( nodes , position ) ;
259- const innerSearch = descendants . find (
270+ const innerSearch = findDescendant (
271+ nodes ,
272+ position ,
260273 ( candidate ) =>
261274 normalizeType ( candidate . type ?? '' ) === 'searchfield' && candidate . label === 'Search' ,
262275 ) ;
@@ -276,14 +289,14 @@ function suppressSearchToolbarDescendants(
276289 keptSearchIndex : number | null ,
277290 suppressedIndexes : Set < number > ,
278291) : void {
279- for ( const descendant of collectDescendants ( nodes , position ) ) {
292+ forEachDescendant ( nodes , position , ( descendant ) => {
280293 if ( descendant . index === keptSearchIndex ) {
281- continue ;
294+ return ;
282295 }
283296 if ( shouldSuppressIosSearchToolbarDescendant ( descendant ) ) {
284297 suppressedIndexes . add ( descendant . index ) ;
285298 }
286- }
299+ } ) ;
287300}
288301
289302function suppressToolbarAncestors (
0 commit comments