@@ -61,17 +61,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
61
61
} = self . classes_stack . find_private_prop ( & field_expr. field ) ;
62
62
63
63
let span = field_expr. span ;
64
-
65
- if is_method || is_accessor {
66
- let prop_ident = prop_binding. create_read_expression ( ctx) ;
67
- return if is_assignment {
68
- // TODO: Handle assignment to private method or accessor
69
- None
70
- } else {
71
- Some ( self . create_assert_class_brand_for_private_method ( prop_ident, span, ctx) )
72
- } ;
73
- } ;
74
-
75
64
let object = ctx. ast . move_expression ( & mut field_expr. object ) ;
76
65
77
66
if self . private_fields_as_properties {
@@ -88,6 +77,11 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
88
77
let prop_ident = prop_binding. create_read_expression ( ctx) ;
89
78
90
79
let replacement = if is_static {
80
+ if is_assignment && ( is_method || is_accessor) {
81
+ // TODO: Handle assignment to static private method or static accessor
82
+ return None ;
83
+ }
84
+
91
85
// TODO: Ensure there are tests for nested classes with references to private static props
92
86
// of outer class inside inner class, to make sure we're getting the right `class_bindings`.
93
87
@@ -100,23 +94,37 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
100
94
) {
101
95
// `_prop._`
102
96
ctx. symbols_mut ( ) . delete_resolved_reference ( class_symbol_id, object_reference_id) ;
103
- Self :: create_underscore_member_expression ( prop_ident, span, ctx)
97
+ if is_method || is_accessor {
98
+ prop_ident
99
+ } else {
100
+ Self :: create_underscore_member_expression ( prop_ident, span, ctx)
101
+ }
104
102
} else {
105
103
// `_assertClassBrand(Class, object, _prop)._`
106
104
let class_binding = class_bindings. get_or_init_static_binding ( ctx) ;
107
105
let class_ident = class_binding. create_read_expression ( ctx) ;
108
-
109
- self . create_assert_class_brand_underscore (
110
- class_ident,
111
- object,
112
- prop_ident,
113
- span,
114
- ctx,
115
- )
106
+ if is_method || is_accessor {
107
+ self . create_assert_class_brand ( class_ident, object, prop_ident, span, ctx)
108
+ } else {
109
+ self . create_assert_class_brand_underscore (
110
+ class_ident,
111
+ object,
112
+ prop_ident,
113
+ span,
114
+ ctx,
115
+ )
116
+ }
116
117
}
117
118
} else if is_assignment {
119
+ if is_method || is_accessor {
120
+ // TODO: Handle assignment to private method or accessor
121
+ return None ;
122
+ }
118
123
// `_toSetter(_classPrivateFieldSet2, [_prop, object])._`
119
124
self . create_to_setter ( prop_ident, object, span, ctx)
125
+ } else if is_method || is_accessor {
126
+ let brand_ident = class_bindings. brand ( ) . create_read_expression ( ctx) ;
127
+ self . create_assert_class_brand ( brand_ident, object, prop_ident, span, ctx)
120
128
} else {
121
129
// `_classPrivateFieldGet2(_prop, object)`
122
130
self . create_private_field_get ( prop_ident, object, span, ctx)
@@ -278,13 +286,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
278
286
let span = field_expr. span ;
279
287
let prop_ident = prop_binding. create_read_expression ( ctx) ;
280
288
281
- if is_method || is_accessor {
282
- return (
283
- self . create_assert_class_brand_for_private_method ( prop_ident, span, ctx) ,
284
- ctx. ast . expression_this ( SPAN ) ,
285
- ) ;
286
- } ;
287
-
288
289
// `(object.#method)()`
289
290
// ^^^^^^^^^^^^^^^^ is a parenthesized expression
290
291
let object = ctx. ast . move_expression ( field_expr. object . get_inner_expression_mut ( ) ) ;
@@ -308,8 +309,13 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
308
309
)
309
310
. is_some ( )
310
311
{
311
- // `_prop._`
312
- let callee = Self :: create_underscore_member_expression ( prop_ident, span, ctx) ;
312
+ let callee = if is_method || is_accessor {
313
+ // `_prop`
314
+ prop_ident
315
+ } else {
316
+ // `_prop._`
317
+ Self :: create_underscore_member_expression ( prop_ident, span, ctx)
318
+ } ;
313
319
( callee, object)
314
320
} else {
315
321
let class_binding = class_bindings. get_or_init_static_binding ( ctx) ;
@@ -318,24 +324,36 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
318
324
// Make 2 copies of `object`
319
325
let ( object1, object2) = self . duplicate_object ( object, ctx) ;
320
326
321
- // `_assertClassBrand(Class, object, _prop)._`
322
- let assert_obj = self . create_assert_class_brand_underscore (
323
- class_ident,
324
- object1,
325
- prop_ident,
326
- span,
327
- ctx,
328
- ) ;
327
+ let assert_obj = if is_method || is_accessor {
328
+ // `_assertClassBrand(Class, object, _prop)._`
329
+ self . create_assert_class_brand ( class_ident, object1, prop_ident, span, ctx)
330
+ } else {
331
+ // `_assertClassBrand(Class, object, _prop)._`
332
+ self . create_assert_class_brand_underscore (
333
+ class_ident,
334
+ object1,
335
+ prop_ident,
336
+ span,
337
+ ctx,
338
+ )
339
+ } ;
340
+
329
341
( assert_obj, object2)
330
342
}
331
343
} else {
332
344
// `object.#prop(arg)` -> `_classPrivateFieldGet2(_prop, object).call(object, arg)`
333
345
// Make 2 copies of `object`
334
346
let ( object1, object2) = self . duplicate_object ( object, ctx) ;
335
347
336
- // `_classPrivateFieldGet2(_prop, object)`
337
- let get_call = self . create_private_field_get ( prop_ident, object1, span, ctx) ;
338
- ( get_call, object2)
348
+ let callee = if is_method || is_accessor {
349
+ // `(_Class_brand, this)`
350
+ let brand_ident = self . current_class ( ) . bindings . brand ( ) . create_read_expression ( ctx) ;
351
+ self . create_assert_class_brand ( brand_ident, object1, prop_ident, span, ctx)
352
+ } else {
353
+ // `_classPrivateFieldGet2(_prop, object)`
354
+ self . create_private_field_get ( prop_ident, object1, span, ctx)
355
+ } ;
356
+ ( callee, object2)
339
357
} ;
340
358
341
359
replacement
@@ -1795,19 +1813,6 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
1795
1813
)
1796
1814
}
1797
1815
1798
- /// `_assertClassBrand(_Class_brand, object, _prop)`
1799
- #[ inline]
1800
- fn create_assert_class_brand_for_private_method (
1801
- & self ,
1802
- value_or_prop_ident : Expression < ' a > ,
1803
- span : Span ,
1804
- ctx : & mut TraverseCtx < ' a > ,
1805
- ) -> Expression < ' a > {
1806
- let class_ident = self . current_class ( ) . bindings . brand ( ) . create_read_expression ( ctx) ;
1807
- let object = ctx. ast . expression_this ( SPAN ) ;
1808
- self . create_assert_class_brand ( class_ident, object, value_or_prop_ident, span, ctx)
1809
- }
1810
-
1811
1816
/// `_assertClassBrand(Class, object, _prop)._`
1812
1817
fn create_assert_class_brand_underscore (
1813
1818
& self ,
0 commit comments