Skip to content

Commit cd09e5d

Browse files
committed
this is overkill
1 parent 5122dc0 commit cd09e5d

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

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

Lines changed: 5 additions & 20 deletions
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
}

0 commit comments

Comments
 (0)