fix: ensure await scope shadowing is computed in the correct order (#12945)

* fix: ensure await scope shadowing is computed in the correct order

* Create popular-news-happen.md

* removed solo
pull/12940/head
Gautier Ben Aïm 1 month ago committed by GitHub
parent 78677e40ef
commit 9c2ca693a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: ensure `{#await}` scope shadowing is computed in the correct order

@ -11,6 +11,9 @@ import { create_derived_block_argument } from '../utils.js';
export function AwaitBlock(node, context) {
context.state.template.push('<!>');
// Visit {#await <expression>} first to ensure that scopes are in the correct order
const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression)));
let then_block;
let catch_block;
@ -45,7 +48,7 @@ export function AwaitBlock(node, context) {
b.call(
'$.await',
context.state.node,
b.thunk(/** @type {Expression} */ (context.visit(node.expression))),
expression,
node.pending
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.pending)))
: b.literal(null),

@ -0,0 +1,10 @@
import { test } from '../../test';
export default test({
html: '<div>Loading...</div>',
async test({ assert, target }) {
await Promise.resolve();
assert.htmlEqual(target.innerHTML, '<div>10</div>');
}
});

@ -0,0 +1,11 @@
<script>
const x = Promise.resolve(10);
</script>
<div>
{#await x}
Loading...
{:then x}
{x}
{/await}
</div>
Loading…
Cancel
Save