fix: don't reassign bound imports on the server

fixes #13027
pull/13033/head
Simon Holthausen 2 years ago
parent e366c49a86
commit e965e57aaf

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't reassign bound imports on the server

@ -80,22 +80,28 @@ export function build_inline_component(node, expression, context) {
const value = build_attribute_value(attribute.value, context, false, true);
push_prop(b.prop('init', b.key(attribute.name), value));
} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
// TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child
push_prop(
b.get(attribute.name, [
b.return(/** @type {Expression} */ (context.visit(attribute.expression)))
])
);
push_prop(
b.set(attribute.name, [
b.stmt(
/** @type {Expression} */ (
context.visit(b.assignment('=', attribute.expression, b.id('$$value')))
)
),
b.stmt(b.assignment('=', b.id('$$settled'), b.false))
])
);
if (
// Don't reassign imports
attribute.expression.type !== 'Identifier' ||
attribute.expression.name !== attribute.name ||
context.state.scope.get(attribute.name)?.declaration_kind !== 'import'
) {
push_prop(
b.set(attribute.name, [
b.stmt(
/** @type {Expression} */ (
context.visit(b.assignment('=', attribute.expression, b.id('$$value')))
)
),
b.stmt(b.assignment('=', b.id('$$settled'), b.false))
])
);
}
}
}

Loading…
Cancel
Save