Skip to content

Commit 9c2ca69

Browse files
authored
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
1 parent 78677e4 commit 9c2ca69

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

.changeset/popular-news-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: ensure `{#await}` scope shadowing is computed in the correct order

packages/svelte/src/compiler/phases/3-transform/client/visitors/AwaitBlock.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { create_derived_block_argument } from '../utils.js';
1111
export function AwaitBlock(node, context) {
1212
context.state.template.push('<!>');
1313

14+
// Visit {#await <expression>} first to ensure that scopes are in the correct order
15+
const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression)));
16+
1417
let then_block;
1518
let catch_block;
1619

@@ -45,7 +48,7 @@ export function AwaitBlock(node, context) {
4548
b.call(
4649
'$.await',
4750
context.state.node,
48-
b.thunk(/** @type {Expression} */ (context.visit(node.expression))),
51+
expression,
4952
node.pending
5053
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.pending)))
5154
: b.literal(null),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '<div>Loading...</div>',
5+
6+
async test({ assert, target }) {
7+
await Promise.resolve();
8+
assert.htmlEqual(target.innerHTML, '<div>10</div>');
9+
}
10+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
const x = Promise.resolve(10);
3+
</script>
4+
5+
<div>
6+
{#await x}
7+
Loading...
8+
{:then x}
9+
{x}
10+
{/await}
11+
</div>

0 commit comments

Comments
 (0)