@@ -174,23 +174,32 @@ export function build_component(node, component_name, context, anchor = context.
174
174
} else if ( attribute . type === 'BindDirective' ) {
175
175
const expression = /** @type {Expression } */ ( context . visit ( attribute . expression ) ) ;
176
176
177
- if ( dev && attribute . name !== 'this' && attribute . expression . type !== 'SequenceExpression' ) {
178
- const left = object ( attribute . expression ) ;
179
- let binding ;
177
+ if ( dev && attribute . name !== 'this' ) {
178
+ let should_add_owner = true ;
180
179
181
- if ( left ?. type === 'Identifier' ) {
182
- binding = context . state . scope . get ( left . name ) ;
180
+ if ( attribute . expression . type !== 'SequenceExpression' ) {
181
+ const left = object ( attribute . expression ) ;
182
+
183
+ if ( left ?. type === 'Identifier' ) {
184
+ const binding = context . state . scope . get ( left . name ) ;
185
+
186
+ // Only run ownership addition on $state fields.
187
+ // Theoretically someone could create a `$state` while creating `$state.raw` or inside a `$derived.by`,
188
+ // but that feels so much of an edge case that it doesn't warrant a perf hit for the common case.
189
+ if ( binding ?. kind === 'derived' || binding ?. kind === 'raw_state' ) {
190
+ should_add_owner = false ;
191
+ }
192
+ }
183
193
}
184
194
185
- // Only run ownership addition on $state fields.
186
- // Theoretically someone could create a `$state` while creating `$state.raw` or inside a `$derived.by`,
187
- // but that feels so much of an edge case that it doesn't warrant a perf hit for the common case.
188
- if ( binding ?. kind !== 'derived' && binding ?. kind !== 'raw_state' ) {
195
+ if ( should_add_owner ) {
189
196
binding_initializers . push (
190
197
b . stmt (
191
198
b . call (
192
199
b . id ( '$.add_owner_effect' ) ,
193
- b . thunk ( expression ) ,
200
+ expression . type === 'SequenceExpression'
201
+ ? expression . expressions [ 0 ]
202
+ : b . thunk ( expression ) ,
194
203
b . id ( component_name ) ,
195
204
is_ignored ( node , 'ownership_invalid_binding' ) && b . true
196
205
)
0 commit comments