diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 9b98539897..93e7126afa 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -229,12 +229,6 @@ const preprocessors = { const contexts = new Map(block.contexts); contexts.set(node.context, context); - if (node.destructuredContexts) { - for (const i = 0; i < node.destructuredContexts.length; i++) { - contexts.set(node.destructuredContexts[i], `${context}[${i}]`); - } - } - const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); @@ -244,6 +238,13 @@ const preprocessors = { const contextDependencies = new Map(block.contextDependencies); contextDependencies.set(node.context, dependencies); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${context}[${i}]`); + contextDependencies.set(node.destructuredContexts[i], dependencies); + } + } + node._block = block.child({ comment: createDebuggingComment(node, generator), name: generator.getUniqueName('create_each_block'), diff --git a/src/generators/server-side-rendering/visitors/EachBlock.ts b/src/generators/server-side-rendering/visitors/EachBlock.ts index 09342bf26b..b2e7c8ad58 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.ts +++ b/src/generators/server-side-rendering/visitors/EachBlock.ts @@ -18,18 +18,19 @@ export default function visitEachBlock( const contexts = new Map(block.contexts); contexts.set(node.context, node.context); - if (node.destructuredContexts) { - for (const i = 0; i < node.destructuredContexts.length; i++) { - contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); - } - } - const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); const contextDependencies = new Map(block.contextDependencies); contextDependencies.set(node.context, dependencies); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); + contextDependencies.set(node.destructuredContexts[i], dependencies); + } + } + const childBlock = block.child({ contexts, indexes, diff --git a/test/runtime/samples/each-block-destructured-array/_config.js b/test/runtime/samples/each-block-destructured-array/_config.js index cd29960426..99933effcf 100644 --- a/test/runtime/samples/each-block-destructured-array/_config.js +++ b/test/runtime/samples/each-block-destructured-array/_config.js @@ -9,5 +9,12 @@ export default { html: `
raccoon: hands
eagle: wings
- ` + `, + + test ( assert, component, target ) { + component.set({ animalPawsEntries: [['foo', 'bar']] }); + assert.htmlEqual( target.innerHTML, ` +foo: bar
+ `); + }, };