@@ -14,50 +14,55 @@ export default (
14
14
siblings : keySiblings = "siblings" ,
15
15
} = { } ,
16
16
) => {
17
- const configurable : PropertyDescriptor [ "configurable" ] = true ,
18
- getLeaves = (
17
+ const properties : PropertyDescriptorMap = {
18
+ [ keyBranch ] : {
19
+ get ( this : Record < string , unknown > ) {
20
+ const ret = [ this ] ;
21
+ while ( ret [ 0 ] ?. [ keyParent ] )
22
+ ret . unshift ( ret [ 0 ] [ keyParent ] as Record < string , unknown > ) ;
23
+ return ret ;
24
+ } ,
25
+ } ,
26
+ [ keyIndex ] : {
27
+ get ( this : Record < string , unknown > ) {
28
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) . findIndex (
29
+ ( sibling ) => this [ keyId ] === sibling [ keyId ] ,
30
+ ) ;
31
+ } ,
32
+ } ,
33
+ [ keyNext ] : {
34
+ get ( this : Record < string , unknown > ) {
35
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
36
+ ( this [ keyIndex ] as number ) + 1
37
+ ] ;
38
+ } ,
39
+ } ,
40
+ [ keyPrev ] : {
41
+ get ( this : Record < string , unknown > ) {
42
+ return ( this [ keySiblings ] as Record < string , unknown > [ ] ) [
43
+ ( this [ keyIndex ] as number ) - 1
44
+ ] ;
45
+ } ,
46
+ } ,
47
+ } ;
48
+ const getLeaves = (
19
49
siblings : { configurable ?: boolean ; value : Record < string , unknown > [ ] } ,
20
50
parent = { } ,
21
51
) =>
22
52
siblings . value . flatMap ( ( value ) : Record < string , unknown > [ ] => {
23
53
Object . defineProperties ( value , {
24
- [ keyBranch ] : {
25
- get : ( ) => {
26
- const ret = [ value ] ;
27
- while ( ret [ 0 ] ?. [ keyParent ] )
28
- ret . unshift ( ret [ 0 ] [ keyParent ] as Record < string , unknown > ) ;
29
- return ret ;
30
- } ,
31
- } ,
32
- [ keyIndex ] : {
33
- get : ( ) =>
34
- ( value [ keySiblings ] as Record < string , unknown > [ ] ) . findIndex (
35
- ( sibling ) => value [ keyId ] === sibling [ keyId ] ,
36
- ) ,
37
- } ,
38
- [ keyNext ] : {
39
- get : ( ) =>
40
- ( value [ keySiblings ] as Record < string , unknown > [ ] ) [
41
- ( value [ keyIndex ] as number ) + 1
42
- ] ,
43
- } ,
54
+ ...properties ,
44
55
[ keyParent ] : parent ,
45
- [ keyPrev ] : {
46
- get : ( ) =>
47
- ( value [ keySiblings ] as Record < string , unknown > [ ] ) [
48
- ( value [ keyIndex ] as number ) - 1
49
- ] ,
50
- } ,
51
56
[ keySiblings ] : siblings ,
52
57
} ) ;
53
58
return [
54
59
value ,
55
60
...getLeaves (
56
61
{
57
- configurable,
62
+ configurable : true ,
58
63
value : ( value [ keyChildren ] ?? [ ] ) as Record < string , unknown > [ ] ,
59
64
} ,
60
- { configurable, value } ,
65
+ { configurable : true , value } ,
61
66
) ,
62
67
] ;
63
68
} ) ,
0 commit comments