Skip to content

Commit 7adad75

Browse files
committed
support implicit returns in arrow functions
1 parent 5c3a153 commit 7adad75

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export function CallExpression(node, context) {
115115
if (
116116
(!(parent.type === 'VariableDeclarator' || parent.type === 'ReturnStatement') ||
117117
get_parent(context.path, -3).type === 'ConstTag') &&
118-
!(parent.type === 'PropertyDefinition' && !parent.static && !parent.computed)
118+
!(parent.type === 'PropertyDefinition' && !parent.static && !parent.computed) &&
119+
!(parent.type === 'ArrowFunctionExpression' && parent.body === node)
119120
) {
120121
e.state_invalid_placement(node, rune);
121122
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { should_proxy } from '../utils.js';
1111
* @param {Context} context
1212
*/
1313
export function CallExpression(node, context) {
14+
const parent = context.path.at(-1);
1415
switch (get_rune(node, context.state.scope)) {
1516
case '$host':
1617
return b.id('$$props.$$host');
@@ -35,7 +36,10 @@ export function CallExpression(node, context) {
3536
case '$inspect().with':
3637
return transform_inspect_rune(node, context);
3738
case '$state':
38-
if (context.path.at(-1)?.type === 'ReturnStatement') {
39+
if (
40+
parent?.type === 'ReturnStatement' ||
41+
(parent?.type === 'ArrowFunctionExpression' && parent.body === node)
42+
) {
3943
if (
4044
node.arguments[0] &&
4145
should_proxy(

0 commit comments

Comments
 (0)