Skip to content

Commit 4d11b56

Browse files
committed
add tests, add to server
1 parent f98b73e commit 4d11b56

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Diff for: packages/svelte/src/compiler/phases/3-transform/server/visitors/CallExpression.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { CallExpression, Expression } from 'estree' */
1+
/** @import { ArrowFunctionExpression, CallExpression, Expression } from 'estree' */
22
/** @import { Context } from '../types.js' */
33
import { is_ignored } from '../../../../state.js';
44
import * as b from '../../../../utils/builders.js';
@@ -37,5 +37,17 @@ export function CallExpression(node, context) {
3737
return transform_inspect_rune(node, context);
3838
}
3939

40+
if (
41+
rune === '$state' &&
42+
(context.path.at(-1)?.type === 'ReturnStatement' ||
43+
(context.path.at(-1)?.type === 'ArrowFunctionExpression' &&
44+
/** @type {ArrowFunctionExpression} */ (context.path.at(-1)).body === node))
45+
) {
46+
if (node.arguments[0]) {
47+
return context.visit(node.arguments[0]);
48+
}
49+
return b.void0;
50+
}
51+
4052
context.next();
4153
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* index.svelte.js generated by Svelte VERSION */
2+
import * as $ from 'svelte/internal/client';
3+
4+
export default function proxy(object) {
5+
return $.proxy(object);
6+
}
7+
8+
export function createCounter() {
9+
let count = $.state(0);
10+
11+
$.update(count);
12+
}
13+
14+
export const proxy_in_arrow = (object) => $.proxy(object);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* index.svelte.js generated by Svelte VERSION */
2+
import * as $ from 'svelte/internal/server';
3+
4+
export default function proxy(object) {
5+
return object;
6+
}
7+
8+
export function createCounter() {
9+
let count = 0;
10+
11+
count++;
12+
}
13+
14+
export const proxy_in_arrow = (object) => object;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function proxy(object) {
2+
return $state(object);
3+
}
4+
export function createCounter() {
5+
let count = $state(0);
6+
count++;
7+
}
8+
export const proxy_in_arrow = object => $state(object);

0 commit comments

Comments
 (0)