diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index c26d2a07b0..22515206c1 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -462,7 +462,7 @@ export default class EachBlockWrapper extends Wrapper { `; } else { destroy = deindent` - for (; #i < ${iterations}.length; #i += 1) { + for (${this.block.hasUpdateMethod ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${iterations}.length; #i += 1) { ${iterations}[#i].d(1); } ${iterations}.length = ${this.vars.each_block_value}.${length}; diff --git a/test/runtime/samples/each-block-index-only/_config.js b/test/runtime/samples/each-block-index-only/_config.js new file mode 100644 index 0000000000..33184f7407 --- /dev/null +++ b/test/runtime/samples/each-block-index-only/_config.js @@ -0,0 +1,27 @@ +export default { + data: { + things: [0, 0, 0, 0, 0] + }, + + html: ` +

0

+

1

+

2

+

3

+

4

+ `, + + test(assert, component, target) { + console.group('set'); + component.set({ + things: [0, 0, 0] + }); + console.groupEnd(); + + assert.htmlEqual(target.innerHTML, ` +

0

+

1

+

2

+ `); + } +}; diff --git a/test/runtime/samples/each-block-index-only/main.html b/test/runtime/samples/each-block-index-only/main.html new file mode 100644 index 0000000000..83fb0e6b8e --- /dev/null +++ b/test/runtime/samples/each-block-index-only/main.html @@ -0,0 +1,3 @@ +{#each things as _, i} +

{i}

+{/each}