diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts
index 0c49c38028..a51b668b41 100644
--- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts
+++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts
@@ -448,7 +448,7 @@ export default class EachBlockWrapper extends Wrapper {
block.chunks.mount.push(b`
for (let #i = 0; #i < ${view_length}; #i += 1) {
- ${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
+ ${iterations}[#i] && ${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
}
`);
@@ -542,7 +542,7 @@ export default class EachBlockWrapper extends Wrapper {
block.chunks.mount.push(b`
for (let #i = 0; #i < ${view_length}; #i += 1) {
- ${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
+ ${iterations}[#i] && ${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
}
`);
diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js
index 02be04c26e..e238a7662e 100644
--- a/test/js/samples/debug-foo-bar-baz-things/expected.js
+++ b/test/js/samples/debug-foo-bar-baz-things/expected.js
@@ -114,7 +114,7 @@ function create_fragment(ctx) {
},
m: function mount(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert_dev(target, t0, anchor);
diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js
index 84dedb0a91..668c551e44 100644
--- a/test/js/samples/debug-foo/expected.js
+++ b/test/js/samples/debug-foo/expected.js
@@ -108,7 +108,7 @@ function create_fragment(ctx) {
},
m: function mount(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert_dev(target, t0, anchor);
diff --git a/test/js/samples/debug-no-dependencies/expected.js b/test/js/samples/debug-no-dependencies/expected.js
index 8107b890a6..03a60ed7dc 100644
--- a/test/js/samples/debug-no-dependencies/expected.js
+++ b/test/js/samples/debug-no-dependencies/expected.js
@@ -86,7 +86,7 @@ function create_fragment(ctx) {
},
m: function mount(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert_dev(target, each_1_anchor, anchor);
diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js
index 8c9bb83b5b..5d95548e7e 100644
--- a/test/js/samples/deconflict-builtins/expected.js
+++ b/test/js/samples/deconflict-builtins/expected.js
@@ -63,7 +63,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert(target, each_1_anchor, anchor);
diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js
index bb5a04e952..91de902614 100644
--- a/test/js/samples/each-block-array-literal/expected.js
+++ b/test/js/samples/each-block-array-literal/expected.js
@@ -63,7 +63,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
for (let i = 0; i < 5; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert(target, each_1_anchor, anchor);
diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js
index e91f77ecd8..c2b7c42433 100644
--- a/test/js/samples/each-block-changed-check/expected.js
+++ b/test/js/samples/each-block-changed-check/expected.js
@@ -104,7 +104,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert(target, t0, anchor);
diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js
index 6f7c22a086..ef53cac73e 100644
--- a/test/js/samples/each-block-keyed-animated/expected.js
+++ b/test/js/samples/each-block-keyed-animated/expected.js
@@ -87,7 +87,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert(target, each_1_anchor, anchor);
diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js
index a275697d8e..f99afe0fbf 100644
--- a/test/js/samples/each-block-keyed/expected.js
+++ b/test/js/samples/each-block-keyed/expected.js
@@ -72,7 +72,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
- each_blocks[i].m(target, anchor);
+ each_blocks[i] && each_blocks[i].m(target, anchor);
}
insert(target, each_1_anchor, anchor);
diff --git a/test/runtime/samples/each-blocks-nested-c/_config.js b/test/runtime/samples/each-blocks-nested-c/_config.js
new file mode 100644
index 0000000000..49f0dbea4e
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-c/_config.js
@@ -0,0 +1,43 @@
+export default {
+ html: `
+
+
+
+ | 1-a |
+ 1-b |
+ 1-c |
+
+
+ | 2-a |
+ 2-b |
+ 2-c |
+
+
+ | 3-a |
+ 3-b |
+ 3-c |
+
+
`,
+ async test({ assert, target, window }) {
+ const button = target.querySelector('button');
+ const event = new window.MouseEvent('click');
+ await button.dispatchEvent(event);
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+ | 1-a |
+ 1-c |
+
+
+ | 3-a |
+ 3-c |
+
+
+ | 2-a |
+ 2-c |
+
+
+ `);
+ }
+};
diff --git a/test/runtime/samples/each-blocks-nested-c/main.svelte b/test/runtime/samples/each-blocks-nested-c/main.svelte
new file mode 100644
index 0000000000..86be97f1c6
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-c/main.svelte
@@ -0,0 +1,25 @@
+
+
+
+
+
+ {#each rows as row (row)}
+
+ {#each columns as column}
+ |
+
+ |
+ {/each}
+
+ {/each}
+
diff --git a/test/runtime/samples/each-blocks-nested-c/sub.svelte b/test/runtime/samples/each-blocks-nested-c/sub.svelte
new file mode 100644
index 0000000000..9405c650f2
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-c/sub.svelte
@@ -0,0 +1,5 @@
+
+{row}-{column}
diff --git a/test/runtime/samples/each-blocks-nested-d/_config.js b/test/runtime/samples/each-blocks-nested-d/_config.js
new file mode 100644
index 0000000000..49f0dbea4e
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-d/_config.js
@@ -0,0 +1,43 @@
+export default {
+ html: `
+
+
+
+ | 1-a |
+ 1-b |
+ 1-c |
+
+
+ | 2-a |
+ 2-b |
+ 2-c |
+
+
+ | 3-a |
+ 3-b |
+ 3-c |
+
+
`,
+ async test({ assert, target, window }) {
+ const button = target.querySelector('button');
+ const event = new window.MouseEvent('click');
+ await button.dispatchEvent(event);
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+ | 1-a |
+ 1-c |
+
+
+ | 3-a |
+ 3-c |
+
+
+ | 2-a |
+ 2-c |
+
+
+ `);
+ }
+};
diff --git a/test/runtime/samples/each-blocks-nested-d/main.svelte b/test/runtime/samples/each-blocks-nested-d/main.svelte
new file mode 100644
index 0000000000..809f0fc0f0
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-d/main.svelte
@@ -0,0 +1,25 @@
+
+
+
+
+
+ {#each rows as row}
+
+ {#each columns as column}
+ |
+
+ |
+ {/each}
+
+ {/each}
+
diff --git a/test/runtime/samples/each-blocks-nested-d/sub.svelte b/test/runtime/samples/each-blocks-nested-d/sub.svelte
new file mode 100644
index 0000000000..9405c650f2
--- /dev/null
+++ b/test/runtime/samples/each-blocks-nested-d/sub.svelte
@@ -0,0 +1,5 @@
+
+{row}-{column}