Skip to content

Commit 0dbba03

Browse files
committed
fix
1 parent 7c95a0e commit 0dbba03

File tree

1 file changed

+22
-13
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors/shared

1 file changed

+22
-13
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,29 @@ export function build_component(node, component_name, context, anchor = context.
179179
} else if (attribute.type === 'BindDirective') {
180180
const expression = /** @type {Expression} */ (context.visit(attribute.expression));
181181

182-
if (dev && attribute.name !== 'this' && !is_ignored(node, 'ownership_invalid_binding')) {
183-
context.state.analysis.needs_mutation_validation = true;
184-
binding_initializers.push(
185-
b.stmt(
186-
b.call(
187-
b.id('$$ownership_validator.binding'),
188-
b.literal(attribute.name),
189-
b.id(component_name),
190-
expression.type === 'SequenceExpression'
191-
? expression.expressions[0]
192-
: b.thunk(expression)
182+
if (
183+
dev &&
184+
attribute.name !== 'this' &&
185+
!is_ignored(node, 'ownership_invalid_binding') &&
186+
// bind:x={() => x.y, y => x.y = y} will be handled by the assignment expression binding validation
187+
attribute.expression.type !== 'SequenceExpression'
188+
) {
189+
const left = object(attribute.expression);
190+
const binding = left && context.state.scope.get(left.name);
191+
192+
if (binding?.kind === 'bindable_prop' || binding?.kind === 'prop') {
193+
context.state.analysis.needs_mutation_validation = true;
194+
binding_initializers.push(
195+
b.stmt(
196+
b.call(
197+
b.id('$$ownership_validator.binding'),
198+
b.literal(binding.node.name),
199+
b.id(component_name),
200+
b.thunk(expression)
201+
)
193202
)
194-
)
195-
);
203+
);
204+
}
196205
}
197206

198207
if (expression.type === 'SequenceExpression') {

0 commit comments

Comments
 (0)