11use std:: { cell:: Cell , fmt, hash:: Hash } ;
22
33use oxc_allocator:: { Box , Vec } ;
4- use oxc_span:: { Atom , SourceType , Span } ;
4+ use oxc_span:: { Atom , CompactStr , SourceType , Span } ;
55use oxc_syntax:: {
66 operator:: {
77 AssignmentOperator , BinaryOperator , LogicalOperator , UnaryOperator , UpdateOperator ,
@@ -212,7 +212,7 @@ impl<'a> Expression<'a> {
212212 }
213213 }
214214
215- pub fn is_specific_member_access ( & ' a self , object : & str , property : & str ) -> bool {
215+ pub fn is_specific_member_access ( & self , object : & str , property : & str ) -> bool {
216216 match self . get_inner_expression ( ) {
217217 Expression :: MemberExpression ( expr) => expr. is_specific_member_access ( object, property) ,
218218 Expression :: ChainExpression ( chain) => {
@@ -466,19 +466,22 @@ pub enum PropertyKey<'a> {
466466}
467467
468468impl < ' a > PropertyKey < ' a > {
469- pub fn static_name ( & self ) -> Option < Atom < ' a > > {
469+ pub fn static_name ( & self ) -> Option < CompactStr > {
470470 match self {
471- Self :: Identifier ( ident) => Some ( ident. name . clone ( ) ) ,
471+ Self :: Identifier ( ident) => Some ( ident. name . to_compact_str ( ) ) ,
472472 Self :: PrivateIdentifier ( _) => None ,
473473 Self :: Expression ( expr) => match expr {
474- Expression :: StringLiteral ( lit) => Some ( lit. value . clone ( ) ) ,
475- Expression :: RegExpLiteral ( lit) => Some ( Atom :: from ( lit. regex . to_string ( ) ) ) ,
476- Expression :: NumericLiteral ( lit) => Some ( Atom :: from ( lit. value . to_string ( ) ) ) ,
477- Expression :: BigintLiteral ( lit) => Some ( lit. raw . clone ( ) ) ,
474+ Expression :: StringLiteral ( lit) => Some ( lit. value . to_compact_str ( ) ) ,
475+ Expression :: RegExpLiteral ( lit) => Some ( lit. regex . to_string ( ) . into ( ) ) ,
476+ Expression :: NumericLiteral ( lit) => Some ( lit. value . to_string ( ) . into ( ) ) ,
477+ Expression :: BigintLiteral ( lit) => Some ( lit. raw . to_compact_str ( ) ) ,
478478 Expression :: NullLiteral ( _) => Some ( "null" . into ( ) ) ,
479- Expression :: TemplateLiteral ( lit) => {
480- lit. expressions . is_empty ( ) . then ( || lit. quasi ( ) ) . flatten ( ) . cloned ( )
481- }
479+ Expression :: TemplateLiteral ( lit) => lit
480+ . expressions
481+ . is_empty ( )
482+ . then ( || lit. quasi ( ) )
483+ . flatten ( )
484+ . map ( Atom :: to_compact_str) ,
482485 _ => None ,
483486 } ,
484487 }
@@ -496,16 +499,16 @@ impl<'a> PropertyKey<'a> {
496499 matches ! ( self , Self :: PrivateIdentifier ( _) )
497500 }
498501
499- pub fn private_name ( & self ) -> Option < Atom < ' a > > {
502+ pub fn private_name ( & self ) -> Option < & Atom < ' a > > {
500503 match self {
501- Self :: PrivateIdentifier ( ident) => Some ( ident. name . clone ( ) ) ,
504+ Self :: PrivateIdentifier ( ident) => Some ( & ident. name ) ,
502505 _ => None ,
503506 }
504507 }
505508
506- pub fn name ( & self ) -> Option < Atom < ' a > > {
509+ pub fn name ( & self ) -> Option < CompactStr > {
507510 if self . is_private_identifier ( ) {
508- self . private_name ( )
511+ self . private_name ( ) . map ( Atom :: to_compact_str )
509512 } else {
510513 self . static_name ( )
511514 }
@@ -758,7 +761,7 @@ impl<'a> CallExpression<'a> {
758761 }
759762 }
760763
761- pub fn is_symbol_or_symbol_for_call ( & ' a self ) -> bool {
764+ pub fn is_symbol_or_symbol_for_call ( & self ) -> bool {
762765 // TODO: is 'Symbol' reference to global object
763766 match & self . callee {
764767 Expression :: Identifier ( id) => id. name == "Symbol" ,
@@ -2017,7 +2020,7 @@ impl<'a> ClassElement<'a> {
20172020 }
20182021 }
20192022
2020- pub fn static_name ( & self ) -> Option < Atom > {
2023+ pub fn static_name ( & self ) -> Option < CompactStr > {
20212024 match self {
20222025 Self :: TSIndexSignature ( _) | Self :: StaticBlock ( _) => None ,
20232026 Self :: MethodDefinition ( def) => def. key . static_name ( ) ,
0 commit comments