diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 5c5e2bf570..07fb763f82 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -114,12 +114,7 @@ export default class Block { this.aliases = new Map(); this.variables = new Map(); - // this.getUniqueName = this.generator.getUniqueNameMaker([]); // TODO this is wrong... we probably don't need this any more - - const getUniqueName = this.generator.getUniqueNameMaker([]); // TODO this is wrong... we probably don't need this any more - this.getUniqueName = name => { - return getUniqueName(name); - } + this.getUniqueName = this.generator.getUniqueNameMaker([]); // TODO this is wrong... we probably don't need this any more this.hasUpdateMethod = false; // determined later } diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index 4d3479d26d..11a8a0c632 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -69,7 +69,8 @@ export default class EachBlock extends Node { if (this.destructuredContexts) { for (let i = 0; i < this.destructuredContexts.length; i += 1) { - this.block.contexts.set(this.destructuredContexts[i], `${context}[${i}]`); + const context = this.block.getUniqueName(this.destructuredContexts[i]); + this.block.contexts.set(this.destructuredContexts[i], context); } } @@ -78,12 +79,11 @@ export default class EachBlock extends Node { `${this.block.indexName}: #i` ]; - // if (this.destructuredContexts) { - // for (let i = 0; i < this.destructuredContexts.length; i += 1) { - // contexts.set(this.destructuredContexts[i], `${context}[${i}]`); - // this.contextProps.push(`${this.destructuredContexts[i]}: ${this.block.listName}[#i][${i}]`); - // } - // } + if (this.destructuredContexts) { + for (let i = 0; i < this.destructuredContexts.length; i += 1) { + this.contextProps.push(`${this.destructuredContexts[i]}: ${this.block.listName}[#i][${i}]`); + } + } this.generator.blocks.push(this.block); this.initChildren(this.block, stripWhitespace, nextSibling); diff --git a/src/generators/server-side-rendering/visitors/EachBlock.ts b/src/generators/server-side-rendering/visitors/EachBlock.ts index 9a5ec300ca..491a9fbc1c 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.ts +++ b/src/generators/server-side-rendering/visitors/EachBlock.ts @@ -11,9 +11,7 @@ export default function visitEachBlock( block.contextualise(node.expression); const { dependencies, snippet } = node.metadata; - const context = node.destructuredContexts ? `[${node.destructuredContexts.join(', ')}]` : node.context; - - const open = `\${ ${node.else ? `${snippet}.length ? ` : ''}${snippet}.map(${node.index ? `(${context}, ${node.index})` : `(${context})`} => \``; + const open = `\${ ${node.else ? `${snippet}.length ? ` : ''}${snippet}.map(${node.index ? `(${node.context}, ${node.index})` : `(${node.context})`} => \``; generator.append(open); // TODO should this be the generator's job? It's duplicated between diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 866f90aa55..3b76fb9ad7 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -284,7 +284,7 @@ function create_main_fragment(component, state) { // (1:0) {{#each comments as comment, i}} function create_each_block(component, state) { - var comment = state.comment; + var comment = state.comment, i = state.i; var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; return { @@ -325,6 +325,7 @@ function create_each_block(component, state) { p: function update(changed, state) { comment = state.comment; + i = state.i; if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 6ea50f4ae4..c86a3a2edf 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -84,7 +84,7 @@ function create_main_fragment(component, state) { // (1:0) {{#each comments as comment, i}} function create_each_block(component, state) { - var comment = state.comment; + var comment = state.comment, i = state.i; var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; return { @@ -125,6 +125,7 @@ function create_each_block(component, state) { p: function update(changed, state) { comment = state.comment; + i = state.i; if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; }