Skip to content

Commit a166761

Browse files
Stadlydummdidumm
andauthored
fix: treat concise arrow function bodies as implicit returns when calculating blockers (#18613)
Fixes #18612. A concise arrow body does not contain a `ReturnStatement` which we traverse in full calculate_blockers (else we bail on functions), so short-cut to `touch` there. --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent a4c60cc commit a166761

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎.changeset/light-pandas-attack.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: treat concise arrow function bodies as implicit returns when calculating blockers

‎packages/svelte/src/compiler/phases/2-analyze/index.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,15 @@ function calculate_blockers(instance, analysis) {
12351235
? /** @type {ESTree.FunctionExpression | ESTree.ArrowFunctionExpression} */ (fn.init)
12361236
: fn;
12371237

1238-
trace_references(
1239-
init.body,
1240-
reads_writes,
1241-
reads_writes,
1242-
/** @type {Scope} */ (instance.scopes.get(init))
1243-
);
1238+
const fn_scope = /** @type {Scope} */ (instance.scopes.get(init));
1239+
1240+
if (init.body.type === 'BlockStatement') {
1241+
trace_references(init.body, reads_writes, reads_writes, fn_scope);
1242+
} else {
1243+
// A concise arrow body is an implicit return, so treat it like the
1244+
// `ReturnStatement` visitor in `trace_references` would.
1245+
touch(init.body, fn_scope, reads_writes);
1246+
}
12441247

12451248
const max = [...reads_writes].reduce((max, binding) => {
12461249
if (binding.blocker) {

‎packages/svelte/tests/runtime-runes/samples/async-bind-factory-function-remote/_config.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { test } from '../../test';
33

44
export default test({
55
mode: ['async-server', 'client', 'hydrate'],
6-
ssrHtml: 'true true true true true',
6+
ssrHtml: 'true true true true true true',
77

88
async test({ assert, target }) {
99
await new Promise((resolve) => setTimeout(resolve, 10));
1010
await tick();
1111

12-
assert.htmlEqual(target.innerHTML, 'true true true true true');
12+
assert.htmlEqual(target.innerHTML, 'true true true true true true');
1313
}
1414
});

‎packages/svelte/tests/runtime-runes/samples/async-bind-factory-function-remote/main.svelte‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
const indirect = () => checkedFactory()();
2222
return indirect;
2323
}
24+
25+
const arrow = () => () => checked;
2426
</script>
2527

2628
<!-- force into separate effects -->
@@ -39,3 +41,6 @@
3941
{#if true}
4042
{indirectChecked2()()}
4143
{/if}
44+
{#if true}
45+
{arrow()()}
46+
{/if}

0 commit comments

Comments
 (0)