@@ -60,6 +60,22 @@ export function handleBinding(
60
60
isSvelte5Plus : boolean
61
61
) : void {
62
62
const isGetSetBinding = attr . expression . type === 'SequenceExpression' ;
63
+ const [ get , set ] = isGetSetBinding ? ( attr . expression as SequenceExpression ) . expressions : [ ] ;
64
+
65
+ // bind this
66
+ if ( attr . name === 'this' && supportsBindThis . includes ( parent . type ) ) {
67
+ // bind:this is effectively only works bottom up - the variable is updated by the element, not
68
+ // the other way round. So we check if the instance is assignable to the variable.
69
+ // Note: If the component unmounts (it's inside an if block, or svelte:component this={null},
70
+ // the value becomes null, but we don't add it to the clause because it would introduce
71
+ // worse DX for the 99% use case, and because null !== undefined which others might use to type the declaration.
72
+ if ( isGetSetBinding ) {
73
+ element . appendToStartEnd ( [ '(' , [ set . start , getEnd ( set ) ] , `)(${ element . name } );` ] ) ;
74
+ } else {
75
+ appendOneWayBinding ( attr , ` = ${ element . name } ` , element ) ;
76
+ }
77
+ return ;
78
+ }
63
79
64
80
if ( ! isGetSetBinding ) {
65
81
// bind group on input
@@ -69,17 +85,6 @@ export function handleBinding(
69
85
return ;
70
86
}
71
87
72
- // bind this
73
- if ( attr . name === 'this' && supportsBindThis . includes ( parent . type ) ) {
74
- // bind:this is effectively only works bottom up - the variable is updated by the element, not
75
- // the other way round. So we check if the instance is assignable to the variable.
76
- // Note: If the component unmounts (it's inside an if block, or svelte:component this={null},
77
- // the value becomes null, but we don't add it to the clause because it would introduce
78
- // worse DX for the 99% use case, and because null !== undefined which others might use to type the declaration.
79
- appendOneWayBinding ( attr , ` = ${ element . name } ` , element ) ;
80
- return ;
81
- }
82
-
83
88
// one way binding
84
89
if ( oneWayBindingAttributes . has ( attr . name ) && element instanceof Element ) {
85
90
appendOneWayBinding ( attr , `= ${ element . name } .${ attr . name } ` , element ) ;
@@ -125,7 +130,6 @@ export function handleBinding(
125
130
]
126
131
] ;
127
132
128
- const [ get , set ] = isGetSetBinding ? ( attr . expression as SequenceExpression ) . expressions : [ ] ;
129
133
const value : TransformationArray | undefined = isShorthand
130
134
? preserveBind && element instanceof Element
131
135
? [ rangeWithTrailingPropertyAccess ( str . original , attr . expression ) ]
0 commit comments