Skip to content

Commit

Permalink
fix: clone might return '{}' on undefined object
Browse files Browse the repository at this point in the history
  • Loading branch information
citrizon committed Dec 21, 2024
1 parent 76343da commit 165bc4d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ function clone(obj) {
for ( key in obj ) {
if ( obj.hasOwnProperty( key ) ) {
val = obj[ key ];
if ( Array.isArray( val ) && val !== null )
if ( val === null || typeof val === 'undefined' )
return val;
if ( Array.isArray( val ) )
ret[ key ] = val.map( clone );
else if ( typeof val === 'object' && val !== null )
else if ( typeof val === 'object' )
ret[ key ] = clone( val );
else ret[ key ] = val;
}
Expand Down

0 comments on commit 165bc4d

Please sign in to comment.