|
|
|
|
@ -362,6 +362,25 @@ function is_store_name(name) {
|
|
|
|
|
return name[0] === '$' && /[A-Za-z_]/.test(name[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {Iterable<import('#compiler').Binding>} bindings
|
|
|
|
|
*/
|
|
|
|
|
function is_store_exists(bindings) {
|
|
|
|
|
for (const binding of bindings) {
|
|
|
|
|
if (binding.kind === 'store_sub') {
|
|
|
|
|
for (const reference of binding.references) {
|
|
|
|
|
const node = reference.path.at(-1);
|
|
|
|
|
|
|
|
|
|
// make sure it is not a sub 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<import('#compiler').SvelteNode, import('./types').ServerTransformState>} context
|
|
|
|
|
@ -2089,15 +2108,10 @@ export function server_component(analysis, options) {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
[...analysis.instance.scope.declarations.values()].some(
|
|
|
|
|
(binding) => binding.kind === 'store_sub'
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
if (is_store_exists(analysis.instance.scope.declarations.values())) {
|
|
|
|
|
instance.body.unshift(b.const('$$store_subs', b.object([])));
|
|
|
|
|
template.body.push(b.stmt(b.call('$.unsubscribe_stores', b.id('$$store_subs'))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Propagate values of bound props upwards if they're undefined in the parent and have a value.
|
|
|
|
|
// Don't do this as part of the props retrieval because people could eagerly mutate the prop in the instance script.
|
|
|
|
|
/** @type {import('estree').Property[]} */
|
|
|
|
|
|