Skip to content

Commit

Permalink
fix: if inside bind await block contextual dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Dec 7, 2019
1 parent 6945862 commit 6188acf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions test/runtime/samples/await-then-if/_config.js
Original file line number Diff line number Diff line change
@@ -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, `
<p>promise array is empty</p>
`);
}
};
13 changes: 13 additions & 0 deletions test/runtime/samples/await-then-if/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
export let thePromise;
</script>

{#await thePromise}
loading...
{:then r}
{#if r.length < 1}
<p>promise array is empty</p>
{:else}
<p>promise array is not empty</p>
{/if}
{/await}

0 comments on commit 6188acf

Please sign in to comment.