1
1
import * as b from '../../../utils/builders.js' ;
2
- import { extract_paths , is_simple_expression , unwrap_ts_expression } from '../../../utils/ast.js' ;
2
+ import {
3
+ extract_paths ,
4
+ is_simple_expression ,
5
+ object ,
6
+ unwrap_ts_expression
7
+ } from '../../../utils/ast.js' ;
3
8
import { error } from '../../../errors.js' ;
4
9
import {
5
10
PROPS_IS_LAZY_INITIAL ,
@@ -280,12 +285,13 @@ export function serialize_set_binding(node, context, fallback, options) {
280
285
error ( node , 'INTERNAL' , `Unexpected assignment type ${ assignee . type } ` ) ;
281
286
}
282
287
283
- let left = assignee ;
284
-
285
288
// Handle class private/public state assignment cases
286
- while ( left . type === 'MemberExpression' ) {
287
- if ( left . object . type === 'ThisExpression' && left . property . type === 'PrivateIdentifier' ) {
288
- const private_state = context . state . private_state . get ( left . property . name ) ;
289
+ if ( assignee . type === 'MemberExpression' ) {
290
+ if (
291
+ assignee . object . type === 'ThisExpression' &&
292
+ assignee . property . type === 'PrivateIdentifier'
293
+ ) {
294
+ const private_state = context . state . private_state . get ( assignee . property . name ) ;
289
295
const value = get_assignment_value ( node , context ) ;
290
296
if ( private_state !== undefined ) {
291
297
if ( state . in_constructor ) {
@@ -307,7 +313,7 @@ export function serialize_set_binding(node, context, fallback, options) {
307
313
} else {
308
314
return b . call (
309
315
'$.set' ,
310
- left ,
316
+ assignee ,
311
317
context . state . analysis . runes &&
312
318
! options ?. skip_proxy_and_freeze &&
313
319
should_proxy_or_freeze ( value , context . state . scope )
@@ -319,11 +325,11 @@ export function serialize_set_binding(node, context, fallback, options) {
319
325
}
320
326
}
321
327
} else if (
322
- left . object . type === 'ThisExpression' &&
323
- left . property . type === 'Identifier' &&
328
+ assignee . object . type === 'ThisExpression' &&
329
+ assignee . property . type === 'Identifier' &&
324
330
state . in_constructor
325
331
) {
326
- const public_state = context . state . public_state . get ( left . property . name ) ;
332
+ const public_state = context . state . public_state . get ( assignee . property . name ) ;
327
333
const value = get_assignment_value ( node , context ) ;
328
334
// See if we should wrap value in $.proxy
329
335
if (
@@ -342,11 +348,11 @@ export function serialize_set_binding(node, context, fallback, options) {
342
348
}
343
349
}
344
350
}
345
- // @ts -expect-error
346
- left = unwrap_ts_expression ( left . object ) ;
347
351
}
348
352
349
- if ( left . type !== 'Identifier' ) {
353
+ const left = object ( assignee ) ;
354
+
355
+ if ( left === null ) {
350
356
return fallback ( ) ;
351
357
}
352
358
0 commit comments