Skip to content

Commit e13b35e

Browse files
committed
cleanup logic
1 parent d7367dc commit e13b35e

File tree

4 files changed

+1
-18
lines changed

4 files changed

+1
-18
lines changed

packages/svelte/src/compiler/errors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ const runes = {
176176
'invalid-state-location': () =>
177177
`$state() can only be used as a variable declaration initializer or a class field`,
178178
'invalid-effect-location': () => `$effect() can only be used as an expression statement`,
179-
'invalid-effect-root-location': () =>
180-
`$effect.root() can only be used as a variable declaration initializer`,
181179
/**
182180
* @param {boolean} is_binding
183181
* @param {boolean} show_details

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,6 @@ function validate_call_expression(node, scope, path) {
524524
if (node.arguments.length < 1 || node.arguments.length > 2) {
525525
error(node, 'invalid-rune-args-length', '$effect.root', [1, 2]);
526526
}
527-
if (parent.type === 'VariableDeclarator') return;
528-
error(node, 'invalid-effect-root-location');
529527
}
530528
}
531529

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const javascript_visitors_runes = {
135135
for (const declarator of node.declarations) {
136136
const init = declarator.init;
137137
const rune = get_rune(init, state.scope);
138-
if (!rune || rune === '$effect.active') {
138+
if (!rune || rune === '$effect.active' || rune === '$effect.root') {
139139
if (init != null && is_hoistable_function(init)) {
140140
const hoistable_function = visit(init);
141141
state.hoisted.push(
@@ -209,17 +209,6 @@ export const javascript_visitors_runes = {
209209
continue;
210210
}
211211
const args = /** @type {import('estree').CallExpression} */ (declarator.init).arguments;
212-
213-
if (rune === '$effect.root') {
214-
const serialized_args = /** @type {import('estree').Expression[]} */ (
215-
args.map((arg) => visit(arg))
216-
);
217-
declarations.push(
218-
b.declarator(declarator.id, b.call('$.user_root_effect', ...serialized_args))
219-
);
220-
continue;
221-
}
222-
223212
const value =
224213
args.length === 0
225214
? b.id('undefined')

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ This allows you to (for example) add things like subscriptions without causing m
191191
The `$effect.root` rune is an advanced feature that creates a non-tracked scope that doesn't auto-cleanup. This is useful for
192192
nested effects that you want to manually control. This rune also allows for creation of effects outside of the component initialisation phase.
193193

194-
> `$effect.root` can only be used in variable declaration initializer, this is to ensure the return signature (the cleanup function) is always used.
195-
196194
```svelte
197195
<script>
198196
let count = $state(0);

0 commit comments

Comments
 (0)