File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,24 +102,28 @@ export const camelcase = (input: string): string => {
102102}
103103
104104export function setDotProp (
105- obj : { [ k : string ] : any } ,
105+ obj : Record < string , any > ,
106106 keys : string [ ] ,
107107 val : any ,
108108) : void {
109- let i = 0
110- const length = keys . length
111- let t = obj
112- let x
113- for ( ; i < length ; ++ i ) {
114- x = t [ keys [ i ] ]
115- t = t [ keys [ i ] ] =
116- i === length - 1
117- ? val
118- : x == null
119- ? ! ! ~ keys [ i + 1 ] . indexOf ( '.' ) || ! ( + keys [ i + 1 ] > - 1 )
120- ? { }
121- : [ ]
122- : x
109+ let current = obj
110+
111+ for ( let i = 0 ; i < keys . length ; i ++ ) {
112+ const key = keys [ i ]
113+ const isLastKey = i === keys . length - 1
114+
115+ if ( isLastKey ) {
116+ current [ key ] = val
117+ return
118+ }
119+
120+ if ( current [ key ] == null ) {
121+ const nextKey = keys [ i + 1 ]
122+ const nextKeyIsArrayIndex = + nextKey > - 1
123+ current [ key ] = nextKeyIsArrayIndex ? [ ] : { }
124+ }
125+
126+ current = current [ key ]
123127 }
124128}
125129
You can’t perform that action at this time.
0 commit comments