fix: `@attach` opt's you into runes mode

attach-runes-mode
paoloricciuti 4 months ago
parent 42e7e8168d
commit ccdf3a7ad4

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: `@attach` opt's you into runes mode

@ -7,6 +7,9 @@ Attachments are functions that run when an element is mounted to the DOM. Option
> [!NOTE]
> Attachments are available in Svelte 5.29 and newer.
> [!NOTE]
> Attachments also opt you in for runes mode so if you use them in a legacy component you would have to also migrate that component.
```svelte
<!--- file: App.svelte --->
<script>

@ -9,6 +9,6 @@ The following pages document these features for
- people still using Svelte 3/4
- people using Svelte 5, but with components that haven't yet been migrated
Since Svelte 3/4 syntax still works in Svelte 5, we will distinguish between _legacy mode_ and _runes mode_. Once a component is in runes mode (which you can opt into by using runes, or by explicitly setting the `runes: true` compiler option), legacy mode features are no longer available.
Since Svelte 3/4 syntax still works in Svelte 5, we will distinguish between _legacy mode_ and _runes mode_. Once a component is in runes mode (which you can opt into by using runes or attachments, or by explicitly setting the `runes: true` compiler option), legacy mode features are no longer available.
If you're exclusively interested in the Svelte 3/4 syntax, you can browse its documentation at [v4.svelte.dev](https://v4.svelte.dev).

@ -403,7 +403,23 @@ export function analyze_component(root, source, options) {
const component_name = get_component_name(options.filename);
const runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);
let runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);
// if we are not in runes mode by the bindings we need to check if there's any attachment
if (!runes) {
// we need to do it beforehand otherwise we would not be in runes mode until we hit an attachment
walk(
/** @type {AST.SvelteNode} */ (template.ast),
{},
{
AttachTag(_, context) {
runes = true;
// once we found one we can stop the traversal
context.stop();
}
}
);
}
if (!runes) {
for (let check of synthetic_stores_legacy_check) {

Loading…
Cancel
Save