@@ -28,69 +28,36 @@ function getAttributes(serializedAXNodeRoot: TextSnapshotNode): string[] {
2828 `"${ serializedAXNodeRoot . name || '' } "` , // Corrected: Added quotes around name
2929 ] ;
3030
31- // Value properties
32- const valueProperties = [
33- 'value' ,
34- 'valuetext' ,
35- 'valuemin' ,
36- 'valuemax' ,
37- 'level' ,
38- 'autocomplete' ,
39- 'haspopup' ,
40- 'invalid' ,
41- 'orientation' ,
42- 'description' ,
43- 'keyshortcuts' ,
44- 'roledescription' ,
45- ] as const ;
46- for ( const property of valueProperties ) {
47- if (
48- property in serializedAXNodeRoot &&
49- serializedAXNodeRoot [ property ] !== undefined
50- ) {
51- attributes . push ( `${ property } ="${ serializedAXNodeRoot [ property ] } "` ) ;
52- }
53- }
54-
55- // Boolean properties that also have an 'able' attribute
56- const booleanPropertyMap = {
31+ const excluded = new Set ( [
32+ 'id' ,
33+ 'role' ,
34+ 'name' ,
35+ 'elementHandle' ,
36+ 'children' ,
37+ ] ) ;
38+
39+ const booleanPropertyMap : { [ key :string ] : string } = {
5740 disabled : 'disableable' ,
5841 expanded : 'expandable' ,
5942 focused : 'focusable' ,
6043 selected : 'selectable' ,
6144 } ;
62- for ( const [ property , ableAttribute ] of Object . entries ( booleanPropertyMap ) ) {
63- if ( property in serializedAXNodeRoot ) {
64- attributes . push ( ableAttribute ) ;
65- if ( serializedAXNodeRoot [ property as keyof typeof booleanPropertyMap ] ) {
66- attributes . push ( property ) ;
67- }
68- }
69- }
7045
71- const booleanProperties = [
72- 'modal' ,
73- 'multiline' ,
74- 'readonly' ,
75- 'required' ,
76- 'multiselectable' ,
77- ] as const ;
78-
79- for ( const property of booleanProperties ) {
80- if ( property in serializedAXNodeRoot && serializedAXNodeRoot [ property ] ) {
81- attributes . push ( property ) ;
46+ for ( const attr of Object . keys ( serializedAXNodeRoot ) . sort ( ) ) {
47+ if ( excluded . has ( attr ) ) {
48+ continue ;
8249 }
83- }
84-
85- // Mixed boolean/string attributes
86- for ( const property of [ 'pressed' , 'checked' ] as const ) {
87- if ( property in serializedAXNodeRoot ) {
88- attributes . push ( property ) ;
89- if ( serializedAXNodeRoot [ property ] ) {
90- attributes . push ( `${ property } ="${ serializedAXNodeRoot [ property ] } "` ) ;
50+ const value = ( serializedAXNodeRoot as unknown as { [ key : string ] : unknown } ) [ attr ] ;
51+ if ( typeof value === 'boolean' ) {
52+ if ( booleanPropertyMap [ attr ] ) {
53+ attributes . push ( booleanPropertyMap [ attr ] ) ;
9154 }
55+ if ( value ) {
56+ attributes . push ( attr ) ;
57+ }
58+ } else if ( typeof value === 'string' ) {
59+ attributes . push ( `${ attr } ="${ value } "` ) ;
9260 }
9361 }
94-
9562 return attributes ;
9663}
0 commit comments