From 37cdfc684c04c80c4849a75f9d7ce1e28f955f75 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 7 Dec 2019 20:24:24 +0800 Subject: [PATCH] fix: if inside bind await block contextual dependencies --- .../compile/render_dom/wrappers/AwaitBlock.ts | 5 ++-- test/runtime/samples/await-then-if/_config.js | 25 +++++++++++++++++++ .../runtime/samples/await-then-if/main.svelte | 13 ++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/await-then-if/_config.js create mode 100644 test/runtime/samples/await-then-if/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index 01153b1083..25c5312e65 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -71,6 +71,8 @@ export default class AwaitBlockWrapper extends Wrapper { this.not_static_content(); block.add_dependencies(this.node.expression.dependencies); + if (this.node.value) block.renderer.add_to_context(this.node.value, true); + if (this.node.error) block.renderer.add_to_context(this.node.error, true); let is_dynamic = false; let has_intros = false; @@ -118,9 +120,6 @@ export default class AwaitBlockWrapper extends Wrapper { if (has_outros) { block.add_outro(); } - - if (this.node.value) block.renderer.add_to_context(this.node.value, true); - if (this.node.error) block.renderer.add_to_context(this.node.error, true); } render( diff --git a/test/runtime/samples/await-then-if/_config.js b/test/runtime/samples/await-then-if/_config.js new file mode 100644 index 0000000000..b26688d9f3 --- /dev/null +++ b/test/runtime/samples/await-then-if/_config.js @@ -0,0 +1,25 @@ +let fulfil; + +const thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + props: { + thePromise + }, + + html: ` + loading... + `, + + async test({ assert, component, target }) { + fulfil([]); + + await thePromise; + + assert.htmlEqual(target.innerHTML, ` +

promise array is empty

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-then-if/main.svelte b/test/runtime/samples/await-then-if/main.svelte new file mode 100644 index 0000000000..d292067b30 --- /dev/null +++ b/test/runtime/samples/await-then-if/main.svelte @@ -0,0 +1,13 @@ + + +{#await thePromise} + loading... +{:then r} + {#if r.length < 1} +

promise array is empty

+ {:else} +

promise array is not empty

+ {/if} +{/await} \ No newline at end of file