File tree Expand file tree Collapse file tree 1 file changed +9
-26
lines changed Expand file tree Collapse file tree 1 file changed +9
-26
lines changed Original file line number Diff line number Diff line change 1
- import { createVNode } from './create-element' ;
1
+ import { EMPTY_ARR } from './constants' ;
2
+ import { createElement } from './create-element' ;
2
3
3
4
/**
4
5
* Clones the given VNode, optionally adding attributes/props and replacing its children.
@@ -8,33 +9,15 @@ import { createVNode } from './create-element';
8
9
* @returns {import('./internal').VNode }
9
10
*/
10
11
export function cloneElement ( vnode , props , children ) {
11
- let normalizedProps = Object . assign ( { } , vnode . props ) ,
12
- key ,
13
- ref ,
14
- i ;
15
-
16
- for ( i in props ) {
17
- if ( i == 'key' ) key = props [ i ] ;
18
- else if ( i == 'ref' ) ref = props [ i ] ;
19
- else normalizedProps [ i ] = props [ i ] ;
20
- }
21
-
22
12
if ( arguments . length > 3 ) {
23
- children = [ children ] ;
24
- for ( i = 3 ; i < arguments . length ; i ++ ) {
25
- children . push ( arguments [ i ] ) ;
26
- }
13
+ children = EMPTY_ARR . slice . call ( arguments , 2 ) ;
27
14
}
28
15
29
- if ( children !== undefined ) {
30
- normalizedProps . children = children ;
31
- }
32
-
33
- return createVNode (
34
- vnode . type ,
35
- normalizedProps ,
36
- key || vnode . key ,
37
- ref || vnode . ref ,
38
- 0
16
+ const clonedProps = Object . assign (
17
+ { key : vnode . key , ref : vnode . ref } ,
18
+ vnode . props ,
19
+ props
39
20
) ;
21
+
22
+ return createElement ( vnode . type , clonedProps , children ) ;
40
23
}
You can’t perform that action at this time.
0 commit comments