Skip to content

Commit b73a228

Browse files
committed
fix
1 parent 31a2398 commit b73a228

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export function SvelteBoundary(node, context) {
4848
if (child.type === 'ConstTag') {
4949
has_const = true;
5050
if (!context.state.options.experimental.async) {
51-
context.visit(child, { ...context.state, consts: const_tags });
51+
context.visit(child, {
52+
...context.state,
53+
consts: const_tags,
54+
scope: context.state.scopes.get(node.fragment) ?? context.state.scope
55+
});
5256
}
5357
}
5458
}

packages/svelte/tests/snapshot/samples/async-in-derived/_expected/client/index.svelte.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ export default function Async_in_derived($$anchor, $$props) {
2525

2626
{
2727
var consequent = ($$anchor) => {
28-
$.async_body($$anchor, async ($$anchor) => {
29-
const yes1 = (await $.save($.async_derived(async () => (await $.save(1))())))();
30-
const yes2 = (await $.save($.async_derived(async () => foo((await $.save(1))()))))();
28+
let yes1;
29+
let yes2;
30+
let no1;
31+
let no2;
3132

32-
const no1 = $.derived(() => (async () => {
33-
return await 1;
34-
})());
33+
var promises = $.run([
34+
async () => yes1 = (await $.save($.async_derived(async () => (await $.save(1))())))(),
35+
async () => yes2 = (await $.save($.async_derived(async () => foo((await $.save(1))()))))(),
3536

36-
const no2 = $.derived(() => (async () => {
37+
() => no1 = $.derived(() => (async () => {
3738
return await 1;
38-
})());
39+
})()),
3940

40-
if ($.aborted()) return;
41-
});
41+
() => no2 = $.derived(() => (async () => {
42+
return await 1;
43+
})())
44+
]);
4245
};
4346

4447
$.if(node, ($$render) => {

packages/svelte/tests/snapshot/samples/async-in-derived/_expected/server/index.svelte.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,38 @@ export default function Async_in_derived($$renderer, $$props) {
1818
}
1919
]);
2020

21-
$$renderer.async_block([], async ($$renderer) => {
22-
if (true) {
23-
$$renderer.push('<!--[-->');
24-
25-
const yes1 = (await $.save(1))();
26-
const yes2 = foo((await $.save(1))());
27-
28-
const no1 = (async () => {
29-
return await 1;
30-
})();
31-
32-
const no2 = (async () => {
33-
return await 1;
34-
})();
35-
} else {
36-
$$renderer.push('<!--[!-->');
37-
}
38-
});
21+
if (true) {
22+
$$renderer.push('<!--[-->');
23+
24+
let yes1;
25+
let yes2;
26+
let no1;
27+
let no2;
28+
29+
var promises = $$renderer.run([
30+
async () => {
31+
yes1 = (await $.save(1))();
32+
},
33+
34+
async () => {
35+
yes2 = foo((await $.save(1))());
36+
},
37+
38+
() => {
39+
no1 = (async () => {
40+
return await 1;
41+
})();
42+
},
43+
44+
() => {
45+
no2 = (async () => {
46+
return await 1;
47+
})();
48+
}
49+
]);
50+
} else {
51+
$$renderer.push('<!--[!-->');
52+
}
3953

4054
$$renderer.push(`<!--]-->`);
4155
});

0 commit comments

Comments
 (0)