|
1 |
| -import CodeBuilder from '../../../utils/CodeBuilder.js'; |
2 | 1 | import deindent from '../../../utils/deindent.js';
|
3 | 2 | import visit from '../visit.js';
|
4 | 3 |
|
@@ -119,24 +118,13 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea
|
119 | 118 | const iteration = block.getUniqueName( `${each_block}_iteration` );
|
120 | 119 | const _iterations = block.getUniqueName( `_${each_block}_iterations` );
|
121 | 120 |
|
122 |
| - block.builders.create.addLine( `var ${lookup} = Object.create( null );` ); |
123 |
| - |
124 |
| - const create = new CodeBuilder(); |
125 |
| - |
126 |
| - create.addBlock( deindent` |
127 |
| - var ${key} = ${each_block_value}[${i}].${node.key}; |
128 |
| - ${iterations}[${i}] = ${lookup}[ ${key} ] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} ); |
129 |
| - ` ); |
130 |
| - |
131 |
| - if ( state.parentNode ) { |
132 |
| - create.addLine( |
133 |
| - `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );` |
134 |
| - ); |
135 |
| - } |
136 |
| - |
137 | 121 | block.builders.create.addBlock( deindent`
|
| 122 | + var ${lookup} = Object.create( null ); |
| 123 | +
|
138 | 124 | for ( var ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
|
139 |
| - ${create} |
| 125 | + var ${key} = ${each_block_value}[${i}].${node.key}; |
| 126 | + ${iterations}[${i}] = ${lookup}[ ${key} ] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} ); |
| 127 | + ${state.parentNode && `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`} |
140 | 128 | }
|
141 | 129 | ` );
|
142 | 130 |
|
@@ -206,21 +194,10 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea
|
206 | 194 | }
|
207 | 195 |
|
208 | 196 | function unkeyed ( generator, block, state, node, snippet, { create_each_block, each_block_value, iterations, i, params, anchor, mountOrIntro } ) {
|
209 |
| - const create = new CodeBuilder(); |
210 |
| - |
211 |
| - create.addLine( |
212 |
| - `${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );` |
213 |
| - ); |
214 |
| - |
215 |
| - if ( state.parentNode ) { |
216 |
| - create.addLine( |
217 |
| - `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );` |
218 |
| - ); |
219 |
| - } |
220 |
| - |
221 | 197 | block.builders.create.addBlock( deindent`
|
222 | 198 | for ( var ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
|
223 |
| - ${create} |
| 199 | + ${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} ); |
| 200 | + ${state.parentNode && `${iterations}[${i}].${mountOrIntro}( ${state.parentNode}, null );`} |
224 | 201 | }
|
225 | 202 | ` );
|
226 | 203 |
|
|
0 commit comments