diff --git a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js index 0bed5390b7..e6fc43a269 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js @@ -362,25 +362,6 @@ function is_store_name(name) { return name[0] === '$' && /[A-Za-z_]/.test(name[1]); } -/** - * - * @param {Iterable} bindings - */ -function store_sub_exist(bindings) { - for (const binding of bindings) { - if (binding.kind === 'store_sub') { - for (const reference of binding.references) { - const node = reference.path.at(-1); - - // hacky way to ensure the sub is not in a directive e.g. use:$store as it is unneeded - if (node?.type !== 'RegularElement') { - return true; - } - } - } - } -} - /** * @param {import('estree').AssignmentExpression} node * @param {import('zimmerframe').Context} context @@ -2108,7 +2089,11 @@ export function server_component(analysis, options) { ]; } - if (store_sub_exist(analysis.instance.scope.declarations.values())) { + if ( + [...analysis.instance.scope.declarations.values()].some( + (binding) => binding.kind === 'store_sub' + ) + ) { instance.body.unshift(b.const('$$store_subs', b.object([]))); template.body.push(b.stmt(b.call('$.unsubscribe_stores', b.id('$$store_subs')))); } diff --git a/packages/svelte/src/compiler/phases/scope.js b/packages/svelte/src/compiler/phases/scope.js index 9a766b4612..aae6b97549 100644 --- a/packages/svelte/src/compiler/phases/scope.js +++ b/packages/svelte/src/compiler/phases/scope.js @@ -331,15 +331,10 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) { } /** - * Reference store in transion:, use:, animate: directives * @type {import('zimmerframe').Visitor} */ const SvelteDirective = (node, context) => { - const name = node.name; - - if (name[0] === '$') { - context.state.scope.reference(b.id(name), context.path); - } + context.state.scope.reference(b.id(node.name), context.path); }; walk(ast, state, { diff --git a/packages/svelte/tests/runtime-runes/samples/store-directive/_config.js b/packages/svelte/tests/runtime-runes/samples/store-directive/_config.js new file mode 100644 index 0000000000..f16d1c959f --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/store-directive/_config.js @@ -0,0 +1,6 @@ +import { test } from '../../test'; + +export default test({ + html: `
mounted
`, + ssrHtml: `
hello
` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/store-directive/main.svelte b/packages/svelte/tests/runtime-runes/samples/store-directive/main.svelte new file mode 100644 index 0000000000..48d774f39d --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/store-directive/main.svelte @@ -0,0 +1,9 @@ + + +
hello
diff --git a/packages/svelte/tests/snapshot/samples/store-transition/_expected/client/main.svelte.js b/packages/svelte/tests/snapshot/samples/store-transition/_expected/client/main.svelte.js deleted file mode 100644 index 4c9320d933..0000000000 --- a/packages/svelte/tests/snapshot/samples/store-transition/_expected/client/main.svelte.js +++ /dev/null @@ -1,32 +0,0 @@ -// main.svelte (Svelte VERSION) -// Note: compiler output will change before 5.0 is released! -import "svelte/internal/disclose-version"; -import * as $ from "svelte/internal"; -import { writable } from 'svelte/store'; - -var frag = $.template(`
Hello!
Hello!
`, true); - -export default function Main($$anchor, $$props) { - $.push($$props, false); - - const $$subscriptions = {}; - - $.unsubscribe_on_destroy($$subscriptions); - - const $animate = () => $.store_get(animate, "$animate", $$subscriptions); - const animate = writable(); - - $.init(); - - /* Init */ - var fragment = $.open_frag($$anchor, true, frag); - var div = $.child_frag(fragment); - - $.in(div, $animate, () => ({ duration: 750, x: 0, y: -200 }), false); - - var div_1 = $.sibling($.sibling(div, true)); - - $.action(div_1, ($$node) => $animate()($$node)); - $.close_frag($$anchor, fragment); - $.pop(); -} \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/store-transition/_expected/server/main.svelte.js b/packages/svelte/tests/snapshot/samples/store-transition/_expected/server/main.svelte.js deleted file mode 100644 index d9b85e3ca5..0000000000 --- a/packages/svelte/tests/snapshot/samples/store-transition/_expected/server/main.svelte.js +++ /dev/null @@ -1,13 +0,0 @@ -// main.svelte (Svelte VERSION) -// Note: compiler output will change before 5.0 is released! -import * as $ from "svelte/internal/server"; -import { writable } from 'svelte/store'; - -export default function Main($$payload, $$props) { - $.push(false); - - const animate = writable(); - - $$payload.out += `
Hello!
Hello!
`; - $.pop(); -} \ No newline at end of file diff --git a/packages/svelte/tests/snapshot/samples/store-transition/main.svelte b/packages/svelte/tests/snapshot/samples/store-transition/main.svelte deleted file mode 100644 index ef1d7d4392..0000000000 --- a/packages/svelte/tests/snapshot/samples/store-transition/main.svelte +++ /dev/null @@ -1,8 +0,0 @@ - - -
Hello!
-
Hello!