From e92902f777a3cc6b7aa4667560344a5ca5bb0135 Mon Sep 17 00:00:00 2001 From: "Benjamin W. Broersma" Date: Fri, 13 Mar 2020 13:50:58 +0100 Subject: [PATCH 1/2] Add failing test case for each-block-keyed-else / #4536 --- .../samples/each-block-keyed-else/_config.js | 37 +++++++++++++++++++ .../samples/each-block-keyed-else/main.svelte | 12 ++++++ 2 files changed, 49 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-else/_config.js create mode 100644 test/runtime/samples/each-block-keyed-else/main.svelte diff --git a/test/runtime/samples/each-block-keyed-else/_config.js b/test/runtime/samples/each-block-keyed-else/_config.js new file mode 100644 index 000000000000..a5bf722a809d --- /dev/null +++ b/test/runtime/samples/each-block-keyed-else/_config.js @@ -0,0 +1,37 @@ +export default { + props: { + animals: ['alpaca', 'baboon', 'capybara'], + foo: 'something else' + }, + + html: ` + before +

alpaca

+

baboon

+

capybara

+ after + `, + + test({ assert, component, target }) { + component.animals = []; + assert.htmlEqual(target.innerHTML, ` + before +

no animals, but rather something else

+ after + `); + + component.foo = 'something other'; + assert.htmlEqual(target.innerHTML, ` + before +

no animals, but rather something other

+ after + `); + + component.animals = ['wombat']; + assert.htmlEqual(target.innerHTML, ` + before +

wombat

+ after + `); + } +}; diff --git a/test/runtime/samples/each-block-keyed-else/main.svelte b/test/runtime/samples/each-block-keyed-else/main.svelte new file mode 100644 index 000000000000..2a82653ff16a --- /dev/null +++ b/test/runtime/samples/each-block-keyed-else/main.svelte @@ -0,0 +1,12 @@ + + +before +{#each animals as animal (animal)} +

{animal}

+{:else} +

no animals, but rather {foo}

+{/each} +after From 7f36492a4e3b2d15226d7279e949f0b116e6d9e0 Mon Sep 17 00:00:00 2001 From: "r.proserpio" Date: Fri, 13 Mar 2020 20:43:46 +0100 Subject: [PATCH 2/2] fix failing test case for each-block-keyed-else (#4536 and #4549) --- src/compiler/compile/render_dom/wrappers/EachBlock.ts | 2 +- test/js/samples/each-block-keyed-animated/expected.js | 2 +- test/js/samples/each-block-keyed/expected.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index f0dfa5fbcc43..488f31dae076 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -423,7 +423,7 @@ export default class EachBlockWrapper extends Wrapper { if (all_dependencies.size) { block.chunks.update.push(b` if (${block.renderer.dirty(Array.from(all_dependencies))}) { - const ${this.vars.each_block_value} = ${snippet}; + ${this.vars.each_block_value} = ${snippet}; ${this.renderer.options.dev && b`@validate_each_argument(${this.vars.each_block_value});`} ${this.block.has_outros && b`@group_outros();`} diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 7fb81c27a226..8d6222c67644 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -93,7 +93,7 @@ function create_fragment(ctx) { }, p(ctx, [dirty]) { if (dirty & /*things*/ 1) { - const each_value = /*things*/ ctx[0]; + each_value = /*things*/ ctx[0]; for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r(); each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, fix_and_destroy_block, create_each_block, each_1_anchor, get_each_context); for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a(); diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index ad8c074e99f8..d6eeabf2ff63 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -78,7 +78,7 @@ function create_fragment(ctx) { }, p(ctx, [dirty]) { if (dirty & /*things*/ 1) { - const each_value = /*things*/ ctx[0]; + each_value = /*things*/ ctx[0]; each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block, each_1_anchor, get_each_context); } },