11use crate :: ast:: * ;
22
3- use std:: { cell:: Cell , fmt, hash:: Hash } ;
3+ use std:: { borrow :: Cow , cell:: Cell , fmt, hash:: Hash } ;
44
55use oxc_allocator:: { Box , FromIn , Vec } ;
6- use oxc_span:: { Atom , CompactStr , GetSpan , SourceType , Span } ;
6+ use oxc_span:: { Atom , GetSpan , SourceType , Span } ;
77use oxc_syntax:: {
88 operator:: UnaryOperator ,
99 reference:: { ReferenceFlag , ReferenceId } ,
@@ -332,20 +332,20 @@ impl<'a> ObjectExpression<'a> {
332332}
333333
334334impl < ' a > PropertyKey < ' a > {
335- pub fn static_name ( & self ) -> Option < CompactStr > {
335+ pub fn static_name ( & self ) -> Option < Cow < ' a , str > > {
336336 match self {
337- Self :: StaticIdentifier ( ident) => Some ( ident. name . to_compact_str ( ) ) ,
338- Self :: StringLiteral ( lit) => Some ( lit. value . to_compact_str ( ) ) ,
339- Self :: RegExpLiteral ( lit) => Some ( lit. regex . to_string ( ) . into ( ) ) ,
340- Self :: NumericLiteral ( lit) => Some ( lit. value . to_string ( ) . into ( ) ) ,
341- Self :: BigIntLiteral ( lit) => Some ( lit. raw . to_compact_str ( ) ) ,
342- Self :: NullLiteral ( _) => Some ( "null" . into ( ) ) ,
337+ Self :: StaticIdentifier ( ident) => Some ( Cow :: Borrowed ( ident. name . as_str ( ) ) ) ,
338+ Self :: StringLiteral ( lit) => Some ( Cow :: Borrowed ( lit. value . as_str ( ) ) ) ,
339+ Self :: RegExpLiteral ( lit) => Some ( Cow :: Owned ( lit. regex . to_string ( ) ) ) ,
340+ Self :: NumericLiteral ( lit) => Some ( Cow :: Owned ( lit. value . to_string ( ) ) ) ,
341+ Self :: BigIntLiteral ( lit) => Some ( Cow :: Borrowed ( lit. raw . as_str ( ) ) ) ,
342+ Self :: NullLiteral ( _) => Some ( Cow :: Borrowed ( "null" ) ) ,
343343 Self :: TemplateLiteral ( lit) => lit
344344 . expressions
345345 . is_empty ( )
346346 . then ( || lit. quasi ( ) )
347347 . flatten ( )
348- . map ( |quasi| quasi . to_compact_str ( ) ) ,
348+ . map ( std :: convert :: Into :: into ) ,
349349 _ => None ,
350350 }
351351 }
@@ -369,9 +369,9 @@ impl<'a> PropertyKey<'a> {
369369 }
370370 }
371371
372- pub fn name ( & self ) -> Option < CompactStr > {
372+ pub fn name ( & self ) -> Option < Cow < ' a , str > > {
373373 if self . is_private_identifier ( ) {
374- self . private_name ( ) . map ( |name| name. to_compact_str ( ) )
374+ self . private_name ( ) . map ( |name| Cow :: Borrowed ( name. as_str ( ) ) )
375375 } else {
376376 self . static_name ( )
377377 }
@@ -1237,7 +1237,7 @@ impl<'a> ClassElement<'a> {
12371237 }
12381238 }
12391239
1240- pub fn static_name ( & self ) -> Option < CompactStr > {
1240+ pub fn static_name ( & self ) -> Option < Cow < ' a , str > > {
12411241 match self {
12421242 Self :: TSIndexSignature ( _) | Self :: StaticBlock ( _) => None ,
12431243 Self :: MethodDefinition ( def) => def. key . static_name ( ) ,
@@ -1424,8 +1424,8 @@ impl<'a> ImportDeclarationSpecifier<'a> {
14241424 ImportDeclarationSpecifier :: ImportDefaultSpecifier ( specifier) => & specifier. local ,
14251425 }
14261426 }
1427- pub fn name ( & self ) -> CompactStr {
1428- self . local ( ) . name . to_compact_str ( )
1427+ pub fn name ( & self ) -> Cow < ' a , str > {
1428+ Cow :: Borrowed ( self . local ( ) . name . as_str ( ) )
14291429 }
14301430}
14311431
0 commit comments