@@ -66,46 +66,64 @@ export function renderElement(
66
66
placeholder : Comment | Node | null = null ,
67
67
skipRegistration = false ,
68
68
) {
69
+ if ( isFn ( el ) ) {
70
+ // @ts -expect-error
71
+ el = resolveRenderable ( el ) ;
72
+ }
69
73
if ( isEmpty ( el ) || el === '' ) {
70
74
return ;
71
75
}
72
- if ( ! isArray ( el ) ) {
73
- if ( isPrimitive ( el ) ) {
74
- let node = api . text ( el ) ;
75
- if ( skipRegistration !== true ) {
76
- ctx [ RENDERED_NODES_PROPERTY ] . push ( node ) ;
77
- }
78
- api . insert ( target , node , placeholder ) ;
79
- } else if ( ( el as HTMLElement ) . nodeType ) {
80
- if ( skipRegistration !== true ) {
81
- ctx [ RENDERED_NODES_PROPERTY ] . push ( el as Node ) ;
82
- }
83
- api . insert ( target , el as Node , placeholder ) ;
84
- } else if ( $nodes in el ) {
85
- el [ $nodes ] . forEach ( ( node ) => {
86
- // @ts -expect-error el.ctx
87
- renderElement ( api , el . ctx , target , node , placeholder ) ;
88
- } ) ;
89
- el [ $nodes ] . length = 0 ;
90
- // el.ctx![RENDERED_NODES_PROPERTY].reverse();
91
- } else if ( isFn ( el ) ) {
92
- // @ts -expect-error
93
- renderElement ( api , ctx , target , resolveRenderable ( el ) , placeholder , skipRegistration ) ;
94
- } else if ( isTagLike ( el ) ) {
95
- const node = api . text ( '' ) ;
76
+
77
+ const renderedNodes = ctx [ RENDERED_NODES_PROPERTY ] ;
78
+
79
+ if ( isPrimitive ( el ) ) {
80
+ const node = api . text ( el ) ;
81
+ if ( ! skipRegistration ) {
96
82
ctx [ RENDERED_NODES_PROPERTY ] . push ( node ) ;
97
- api . insert ( target , node , placeholder ) ;
98
- registerDestructor ( ctx , opcodeFor ( el , ( value ) => {
99
- api . textContent ( node , String ( value ?? '' ) ) ;
100
- } ) ) ;
101
- } else {
102
- throw new Error ( `Unknown element type ${ el } ` ) ;
103
83
}
104
- } else {
84
+ api . insert ( target , node , placeholder ) ;
85
+ return ;
86
+ }
87
+
88
+ if ( ( el as HTMLElement ) . nodeType ) {
89
+ if ( ! skipRegistration ) {
90
+ renderedNodes . push ( el as Node ) ;
91
+ }
92
+ api . insert ( target , el as Node , placeholder ) ;
93
+ return ;
94
+ }
95
+
96
+ if ( $nodes in el ) {
97
+ const nodes = el [ $nodes ] ;
98
+ const elCtx = el . ctx ! ;
99
+ for ( let i = 0 ; i < nodes . length ; i ++ ) {
100
+ renderElement ( api , elCtx , target , nodes [ i ] , placeholder ) ;
101
+ }
102
+ nodes . length = 0 ;
103
+ return ;
104
+ }
105
+
106
+ if ( isTagLike ( el ) ) {
107
+ const node = api . text ( '' ) ;
108
+ renderedNodes . push ( node ) ;
109
+ registerDestructor (
110
+ ctx ,
111
+ opcodeFor ( el , ( value ) => {
112
+ api . textContent ( node , String ( value ?? '' ) ) ;
113
+ } ) ,
114
+ ) ;
115
+ api . insert ( target , node , placeholder ) ;
116
+ return ;
117
+ }
118
+
119
+ if ( Array . isArray ( el ) ) {
105
120
for ( let i = 0 ; i < el . length ; i ++ ) {
106
121
renderElement ( api , ctx , target , el [ i ] , placeholder , true ) ;
107
122
}
123
+ return ;
108
124
}
125
+
126
+ throw new Error ( `Unknown element type ${ el } ` ) ;
109
127
}
110
128
111
129
export function renderComponent (
0 commit comments