@@ -16,7 +16,7 @@ export function collectIosWebSemanticPresentation(
1616 nodes : RawSnapshotNode [ ] ,
1717 context : SnapshotTreeRuleContext ,
1818) : void {
19- const repeatedStaticTextByParent = collectRepeatedStaticTextByParent ( nodes ) ;
19+ const childrenByParent = collectChildrenByParent ( nodes ) ;
2020
2121 for ( const node of nodes ) {
2222 if ( normalizeType ( node . type ?? '' ) === 'element(58)' ) {
@@ -26,7 +26,7 @@ export function collectIosWebSemanticPresentation(
2626 const presentation = classifyIosWebTextWrapper (
2727 node ,
2828 context . sourceNodesByIndex ,
29- repeatedStaticTextByParent ,
29+ childrenByParent ,
3030 ) ;
3131 if ( presentation ?. kind === 'suppress' ) {
3232 context . suppressedIndexes . add ( node . index ) ;
@@ -49,20 +49,35 @@ type IosWebTextWrapperPresentation =
4949function classifyIosWebTextWrapper (
5050 node : RawSnapshotNode ,
5151 byIndex : ReadonlyMap < number , RawSnapshotNode > ,
52- repeatedStaticTextByParent : Map < number , Set < string > > ,
52+ childrenByParent : ReadonlyMap < number , RawSnapshotNode [ ] > ,
5353) : IosWebTextWrapperPresentation | null {
5454 if ( normalizeType ( node . type ?? '' ) !== 'other' ) return null ;
5555 const webView = findNearestAncestor ( node , byIndex , isWebView ) ;
5656 const label = node . label ?. trim ( ) ;
5757 if ( ! webView || ! label ) return null ;
5858 if ( isDocumentTitleWrapper ( node , webView , label ) ) return { kind : 'suppress' } ;
59- if ( ! repeatedStaticTextByParent . get ( node . index ) ?. has ( label ) ) return null ;
59+ if ( ! isWebTextLeafWrapper ( node , label , childrenByParent ) ) return null ;
6060 return {
6161 kind : 'semantic' ,
6262 type : isHtmlHeadingLevel ( node . value ) ? 'Heading' : 'StaticText' ,
6363 } ;
6464}
6565
66+ function isWebTextLeafWrapper (
67+ node : RawSnapshotNode ,
68+ label : string ,
69+ childrenByParent : ReadonlyMap < number , RawSnapshotNode [ ] > ,
70+ ) : boolean {
71+ const children = childrenByParent . get ( node . index ) ;
72+ if ( children ?. length !== 1 ) return false ;
73+ const text = children [ 0 ] ! ;
74+ return (
75+ normalizeType ( text . type ?? '' ) === 'statictext' &&
76+ text . label ?. trim ( ) === label &&
77+ ! childrenByParent . has ( text . index )
78+ ) ;
79+ }
80+
6681function isDocumentTitleWrapper (
6782 node : RawSnapshotNode ,
6883 webView : RawSnapshotNode ,
@@ -75,19 +90,15 @@ function isDocumentTitleWrapper(
7590 ) ;
7691}
7792
78- function collectRepeatedStaticTextByParent ( nodes : RawSnapshotNode [ ] ) : Map < number , Set < string > > {
79- const labelsByParent = new Map < number , Set < string > > ( ) ;
93+ function collectChildrenByParent ( nodes : RawSnapshotNode [ ] ) : Map < number , RawSnapshotNode [ ] > {
94+ const childrenByParent = new Map < number , RawSnapshotNode [ ] > ( ) ;
8095 for ( const node of nodes ) {
81- if ( typeof node . parentIndex !== 'number' || normalizeType ( node . type ?? '' ) !== 'statictext' ) {
82- continue ;
83- }
84- const label = node . label ?. trim ( ) ;
85- if ( ! label ) continue ;
86- const labels = labelsByParent . get ( node . parentIndex ) ?? new Set < string > ( ) ;
87- labels . add ( label ) ;
88- labelsByParent . set ( node . parentIndex , labels ) ;
96+ if ( typeof node . parentIndex !== 'number' ) continue ;
97+ const children = childrenByParent . get ( node . parentIndex ) ?? [ ] ;
98+ children . push ( node ) ;
99+ childrenByParent . set ( node . parentIndex , children ) ;
89100 }
90- return labelsByParent ;
101+ return childrenByParent ;
91102}
92103
93104function isWebView ( node : RawSnapshotNode ) : boolean {
0 commit comments