Skip to content

Commit a201480

Browse files
authored
chore: tidy up post-#10481 (#10503)
* simplify * replace snapshot test with runtime test * this is overkill --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 2c93c25 commit a201480

File tree

7 files changed

+21
-79
lines changed

7 files changed

+21
-79
lines changed

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

+5-20
Original file line numberDiff line numberDiff line change
@@ -362,25 +362,6 @@ function is_store_name(name) {
362362
return name[0] === '$' && /[A-Za-z_]/.test(name[1]);
363363
}
364364

365-
/**
366-
*
367-
* @param {Iterable<import('#compiler').Binding>} bindings
368-
*/
369-
function store_sub_exist(bindings) {
370-
for (const binding of bindings) {
371-
if (binding.kind === 'store_sub') {
372-
for (const reference of binding.references) {
373-
const node = reference.path.at(-1);
374-
375-
// hacky way to ensure the sub is not in a directive e.g. use:$store as it is unneeded
376-
if (node?.type !== 'RegularElement') {
377-
return true;
378-
}
379-
}
380-
}
381-
}
382-
}
383-
384365
/**
385366
* @param {import('estree').AssignmentExpression} node
386367
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types').ServerTransformState>} context
@@ -2108,7 +2089,11 @@ export function server_component(analysis, options) {
21082089
];
21092090
}
21102091

2111-
if (store_sub_exist(analysis.instance.scope.declarations.values())) {
2092+
if (
2093+
[...analysis.instance.scope.declarations.values()].some(
2094+
(binding) => binding.kind === 'store_sub'
2095+
)
2096+
) {
21122097
instance.body.unshift(b.const('$$store_subs', b.object([])));
21132098
template.body.push(b.stmt(b.call('$.unsubscribe_stores', b.id('$$store_subs'))));
21142099
}

packages/svelte/src/compiler/phases/scope.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,10 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
331331
}
332332

333333
/**
334-
* Reference store in transion:, use:, animate: directives
335334
* @type {import('zimmerframe').Visitor<import('#compiler').Directive, State, import('#compiler').SvelteNode>}
336335
*/
337336
const SvelteDirective = (node, context) => {
338-
const name = node.name;
339-
340-
if (name[0] === '$') {
341-
context.state.scope.reference(b.id(name), context.path);
342-
}
337+
context.state.scope.reference(b.id(node.name), context.path);
343338
};
344339

345340
walk(ast, state, {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<div>mounted</div>`,
5+
ssrHtml: `<div>hello</div>`
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import { writable } from 'svelte/store';
3+
4+
let action = writable((node) => {
5+
node.textContent = 'mounted';
6+
});
7+
</script>
8+
9+
<div use:$action>hello</div>

packages/svelte/tests/snapshot/samples/store-transition/_expected/client/main.svelte.js

-32
This file was deleted.

packages/svelte/tests/snapshot/samples/store-transition/_expected/server/main.svelte.js

-13
This file was deleted.

packages/svelte/tests/snapshot/samples/store-transition/main.svelte

-8
This file was deleted.

0 commit comments

Comments
 (0)