Skip to content

Commit 7442135

Browse files
committed
revise
1 parent d2079ce commit 7442135

File tree

1 file changed

+7
-3
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,13 @@ function serialize_bind_this(bind_this, context, node) {
918918
/** @type {import('estree').Expression[]} */
919919
const args = [node, b.arrow([b.id('$$value'), ...ids], update), b.arrow([...ids], bind_this_id)];
920920
// If we're mutating a property, then it might already be non-existent.
921-
// We can use an optional member accessor to avoid any runtime issues.
922-
if (bind_this_id.type === 'MemberExpression') {
923-
bind_this_id.optional = true;
921+
// If we make all the object nodes optional, then it avoids any runtime exceptions.
922+
/** @type {import('estree').Expression | import('estree').Super} */
923+
let bind_node = bind_this_id;
924+
925+
while (bind_node?.type === 'MemberExpression') {
926+
bind_node.optional = true;
927+
bind_node = bind_node.object;
924928
}
925929
if (each_ids.size) {
926930
args.push(b.thunk(b.array(Array.from(each_ids.values()).map((id) => id[1]))));

0 commit comments

Comments
 (0)