From 8b88992ba9f66fe4b8f824da4d5be8e5d7c6cf4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zdunek?= Date: Fri, 3 Apr 2020 22:45:08 +0200 Subject: [PATCH] move destructuring to the beginning of await block updates --- .../compile/render_dom/wrappers/AwaitBlock.ts | 2 +- .../samples/await-then-destruct-if/_config.js | 15 ++++++++++++ .../await-then-destruct-if/main.svelte | 24 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-then-destruct-if/_config.js create mode 100644 test/runtime/samples/await-then-destruct-if/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index d6ac17f0ce..f4f1fe3be9 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -60,7 +60,7 @@ class AwaitBlockBranch extends Wrapper { this.block.chunks.declarations.push(b`(${node.pattern} = #ctx[${index}])`); if (this.block.has_update_method) { - this.block.chunks.update.push(b`(${node.pattern} = #ctx[${index}])`); + this.block.chunks.update.unshift(b`(${node.pattern} = #ctx[${index}])`); } } } diff --git a/test/runtime/samples/await-then-destruct-if/_config.js b/test/runtime/samples/await-then-destruct-if/_config.js new file mode 100644 index 0000000000..5901f67fa8 --- /dev/null +++ b/test/runtime/samples/await-then-destruct-if/_config.js @@ -0,0 +1,15 @@ +export default { + async test({ assert, target, component }) { + await Promise.resolve(); + + component.fail = 'wrong'; + + assert.htmlEqual( + target.innerHTML, + ` + correct + correct + ` + ); + } +}; diff --git a/test/runtime/samples/await-then-destruct-if/main.svelte b/test/runtime/samples/await-then-destruct-if/main.svelte new file mode 100644 index 0000000000..e3224e3339 --- /dev/null +++ b/test/runtime/samples/await-then-destruct-if/main.svelte @@ -0,0 +1,24 @@ + + +{#await $object then { result }} + {#if result} + correct + {:else} + {fail} + {/if} +{/await} + +{#await $array then [result]} + {#if result} + correct + {:else} + {fail} + {/if} +{/await}