@@ -181,18 +181,36 @@ function buildTouchMessage(
181181 x : number | undefined ,
182182 y : number | undefined ,
183183) : string | undefined {
184- if ( typeof extra ?. text === 'string' ) {
185- return `Filled ${ Array . from ( extra . text ) . length } chars` ;
186- }
187- const ref = typeof extra ?. ref === 'string' ? extra . ref : undefined ;
188- const selector = typeof extra ?. selector === 'string' ? extra . selector : undefined ;
189- const pointSuffix = x === undefined || y === undefined ? '' : ` (${ x } , ${ y } )` ;
190- const label = ref ? `@${ ref } ` : ( selector ?? '' ) ;
191- if ( ! label ) {
192- if ( x === undefined || y === undefined ) return undefined ;
193- return extra ?. gesture === 'longpress' ? `Long pressed (${ x } , ${ y } )` : `Tapped (${ x } , ${ y } )` ;
194- }
195- return buildTouchTargetMessage ( label , extra ?? { } , pointSuffix ) ;
184+ const fillText = readString ( extra , 'text' ) ;
185+ if ( fillText !== undefined ) return `Filled ${ Array . from ( fillText ) . length } chars` ;
186+
187+ const pointSuffix = buildPointSuffix ( x , y ) ;
188+ const label = buildTouchTargetLabel ( extra ) ;
189+ if ( label ) return buildTouchTargetMessage ( label , extra ?? { } , pointSuffix ) ;
190+ if ( ! pointSuffix ) return undefined ;
191+
192+ return buildPointTouchMessage ( extra , pointSuffix ) ;
193+ }
194+
195+ function readString ( data : Record < string , unknown > | undefined , key : string ) : string | undefined {
196+ const value = data ?. [ key ] ;
197+ return typeof value === 'string' ? value : undefined ;
198+ }
199+
200+ function buildPointSuffix ( x : number | undefined , y : number | undefined ) : string {
201+ return x === undefined || y === undefined ? '' : ` (${ x } , ${ y } )` ;
202+ }
203+
204+ function buildTouchTargetLabel ( extra : Record < string , unknown > | undefined ) : string | undefined {
205+ const ref = readString ( extra , 'ref' ) ;
206+ return ref === undefined ? readString ( extra , 'selector' ) : `@${ ref } ` ;
207+ }
208+
209+ function buildPointTouchMessage (
210+ extra : Record < string , unknown > | undefined ,
211+ pointSuffix : string ,
212+ ) : string {
213+ return extra ?. gesture === 'longpress' ? `Long pressed${ pointSuffix } ` : `Tapped${ pointSuffix } ` ;
196214}
197215
198216function buildTouchTargetMessage (
0 commit comments