@@ -112,6 +112,13 @@ impl<'a> Expression<'a> {
112112 matches ! ( self , Self :: StringLiteral ( _) | Self :: TemplateLiteral ( _) )
113113 }
114114
115+ pub fn is_specific_string_literal ( & self , string : & str ) -> bool {
116+ match self {
117+ Self :: StringLiteral ( s) => s. value == string,
118+ _ => false ,
119+ }
120+ }
121+
115122 /// Determines whether the given expr is a `null` literal
116123 pub fn is_null ( & self ) -> bool {
117124 matches ! ( self , Expression :: NullLiteral ( _) )
@@ -129,13 +136,12 @@ impl<'a> Expression<'a> {
129136
130137 /// Determines whether the given expr is a `void 0`
131138 pub fn is_void_0 ( & self ) -> bool {
132- if let Self :: UnaryExpression ( expr ) = self
133- && expr. operator == UnaryOperator :: Void
134- && let Self :: NumberLiteral ( lit) = & expr . argument
135- && lit . value == 0.0 {
136- return true
139+ match self {
140+ Self :: UnaryExpression ( expr ) if expr. operator == UnaryOperator :: Void => {
141+ matches ! ( & expr . argument , Self :: NumberLiteral ( lit) if lit . value == 0.0 )
142+ }
143+ _ => false ,
137144 }
138- false
139145 }
140146
141147 /// Determines whether the given expr is a `0`
@@ -195,6 +201,10 @@ impl<'a> Expression<'a> {
195201 }
196202 }
197203
204+ pub fn is_identifier_reference ( & self ) -> bool {
205+ matches ! ( self , Expression :: Identifier ( _) )
206+ }
207+
198208 pub fn get_identifier_reference ( & self ) -> Option < & IdentifierReference > {
199209 match self . get_inner_expression ( ) {
200210 Expression :: Identifier ( ident) => Some ( ident) ,
@@ -355,9 +365,20 @@ impl<'a> PropertyKey<'a> {
355365 }
356366 }
357367
368+ pub fn is_specific_static_name ( & self , name : & str ) -> bool {
369+ self . static_name ( ) . is_some_and ( |n| n == name)
370+ }
371+
358372 pub fn is_private_identifier ( & self ) -> bool {
359373 matches ! ( self , Self :: PrivateIdentifier ( _) )
360374 }
375+
376+ pub fn is_specific_id ( & self , name : & str ) -> bool {
377+ match self {
378+ PropertyKey :: Identifier ( ident) => ident. name == name,
379+ _ => false ,
380+ }
381+ }
361382}
362383
363384#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -568,13 +589,12 @@ impl<'a> CallExpression<'a> {
568589 }
569590
570591 pub fn common_js_require ( & self ) -> Option < & StringLiteral > {
571- if let Expression :: Identifier ( ident) = & self . callee
572- && ident. name =="require"
573- && self . arguments . len ( ) == 1
574- && let Argument :: Expression ( Expression :: StringLiteral ( str_literal) ) = & self . arguments [ 0 ] {
575- Some ( str_literal)
576- } else {
577- None
592+ if !( self . callee . is_specific_id ( "require" ) && self . arguments . len ( ) == 1 ) {
593+ return None ;
594+ }
595+ match & self . arguments [ 0 ] {
596+ Argument :: Expression ( Expression :: StringLiteral ( str_literal) ) => Some ( str_literal) ,
597+ _ => None ,
578598 }
579599 }
580600}
0 commit comments