@@ -338,6 +338,7 @@ fn prefix_getters_setters(kind: ast::MethodKind, scope_name: &mut ScopeName) {
338338/// This is only possible if the expression is an identifier or a member expression.
339339fn infer_name_from_expr ( mut expr : & ast:: Expr ) -> Option < ScopeName > {
340340 let mut scope_name = ScopeName :: new ( ) ;
341+
341342 loop {
342343 match expr {
343344 ast:: Expr :: Ident ( ident) => {
@@ -354,6 +355,18 @@ fn infer_name_from_expr(mut expr: &ast::Expr) -> Option<ScopeName> {
354355 . push_front ( NameComponent :: ident ( ident. clone ( ) ) ) ;
355356 scope_name. components . push_front ( NameComponent :: interp ( "." ) ) ;
356357 }
358+
359+ if let Some ( computed_prop) = member. prop . as_computed ( ) {
360+ if let Some ( ( computed_name, need_delimiter) ) =
361+ computed_prop_name_to_component ( computed_prop)
362+ {
363+ scope_name. components . push_front ( computed_name) ;
364+ if need_delimiter {
365+ scope_name. components . push_front ( NameComponent :: interp ( "." ) ) ;
366+ }
367+ }
368+ }
369+
357370 expr = & member. obj ;
358371 }
359372
@@ -369,6 +382,24 @@ fn infer_name_from_expr(mut expr: &ast::Expr) -> Option<ScopeName> {
369382 }
370383}
371384
385+ fn computed_prop_name_to_component ( prop : & ast:: ComputedPropName ) -> Option < ( NameComponent , bool ) > {
386+ if let Some ( lit) = prop. expr . as_lit ( ) {
387+ if let ast:: Lit :: Str ( prop) = lit {
388+ return Some ( ( NameComponent :: interp ( prop. value . to_string ( ) ) , true ) ) ;
389+ }
390+
391+ if let ast:: Lit :: Num ( prop) = lit {
392+ return Some ( ( NameComponent :: interp ( format ! ( "[{}]" , prop. value) ) , false ) ) ;
393+ }
394+ }
395+
396+ if let Some ( ident) = prop. expr . as_ident ( ) {
397+ return Some ( ( NameComponent :: interp ( format ! ( "[{}]" , ident. sym) ) , false ) ) ;
398+ }
399+
400+ None
401+ }
402+
372403fn prop_name_to_component ( prop : & ast:: PropName ) -> NameComponent {
373404 match prop {
374405 ast:: PropName :: Ident ( ref i) => NameComponent :: ident ( i. clone ( ) ) ,
0 commit comments