mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
8 years ago
4 changed files with 57 additions and 24 deletions
@ -0,0 +1,17 @@ |
|||
export default function clone ( node ) { |
|||
if ( !node ) return node; |
|||
if ( typeof node !== 'object' ) return node; |
|||
|
|||
if ( Array.isArray( node ) ) { |
|||
const cloned = new Array( node.length ); |
|||
for ( let i = 0; i < node.length; i += 1 ) cloned[i] = clone( node[i] ); |
|||
return cloned; |
|||
} |
|||
|
|||
const cloned = {}; |
|||
for ( const key in node ) { |
|||
cloned[ key ] = clone( node[ key ] ); |
|||
} |
|||
|
|||
return cloned; |
|||
} |
Loading…
Reference in new issue