@@ -10,6 +10,7 @@ pub(crate) enum FunctionType {
1010 FunctionDeclaration ,
1111 FunctionExpression ,
1212 Method ,
13+ PrivateMethod ,
1314}
1415
1516/// The kind of function - Sync or returns a promise
@@ -58,6 +59,14 @@ pub enum FunctionQuery {
5859 #[ cfg_attr( feature = "wasm" , tsify( optional) ) ]
5960 is_export_alias : bool ,
6061 } ,
62+ PrivateMethod {
63+ class_name : String ,
64+ private_method_name : String ,
65+ kind : FunctionKind ,
66+ #[ cfg_attr( feature = "serde" , serde( default ) ) ]
67+ #[ cfg_attr( feature = "wasm" , tsify( optional) ) ]
68+ index : usize ,
69+ } ,
6170 ClassConstructor {
6271 class_name : String ,
6372 #[ cfg_attr( feature = "serde" , serde( default ) ) ]
@@ -146,6 +155,16 @@ impl FunctionQuery {
146155 }
147156 }
148157
158+ #[ must_use]
159+ pub fn private_method ( class_name : & str , private_method_name : & str , kind : FunctionKind ) -> Self {
160+ FunctionQuery :: PrivateMethod {
161+ class_name : class_name. to_string ( ) ,
162+ private_method_name : private_method_name. to_string ( ) ,
163+ kind,
164+ index : 0 ,
165+ }
166+ }
167+
149168 #[ must_use]
150169 pub fn as_export_alias ( mut self ) -> Self {
151170 match & mut self {
@@ -161,7 +180,7 @@ impl FunctionQuery {
161180 | FunctionQuery :: FunctionExpression {
162181 is_export_alias, ..
163182 } => * is_export_alias = true ,
164- FunctionQuery :: ObjectMethod { .. } => { }
183+ FunctionQuery :: ObjectMethod { .. } | FunctionQuery :: PrivateMethod { .. } => { }
165184 }
166185 self
167186 }
@@ -172,7 +191,8 @@ impl FunctionQuery {
172191 FunctionQuery :: ClassMethod { kind, .. }
173192 | FunctionQuery :: ObjectMethod { kind, .. }
174193 | FunctionQuery :: FunctionDeclaration { kind, .. }
175- | FunctionQuery :: FunctionExpression { kind, .. } => kind,
194+ | FunctionQuery :: FunctionExpression { kind, .. }
195+ | FunctionQuery :: PrivateMethod { kind, .. } => kind,
176196 }
177197 }
178198
@@ -181,6 +201,10 @@ impl FunctionQuery {
181201 FunctionQuery :: ClassConstructor { .. } => "constructor" ,
182202 FunctionQuery :: ClassMethod { method_name, .. }
183203 | FunctionQuery :: ObjectMethod { method_name, .. } => method_name,
204+ FunctionQuery :: PrivateMethod {
205+ private_method_name,
206+ ..
207+ } => private_method_name,
184208 FunctionQuery :: FunctionDeclaration { function_name, .. } => function_name,
185209 FunctionQuery :: FunctionExpression {
186210 expression_name, ..
@@ -195,6 +219,7 @@ impl FunctionQuery {
195219 | FunctionQuery :: ObjectMethod { .. } => FunctionType :: Method ,
196220 FunctionQuery :: FunctionDeclaration { .. } => FunctionType :: FunctionDeclaration ,
197221 FunctionQuery :: FunctionExpression { .. } => FunctionType :: FunctionExpression ,
222+ FunctionQuery :: PrivateMethod { .. } => FunctionType :: PrivateMethod ,
198223 }
199224 }
200225
@@ -205,15 +230,17 @@ impl FunctionQuery {
205230 | FunctionQuery :: ClassMethod { index, .. }
206231 | FunctionQuery :: ObjectMethod { index, .. }
207232 | FunctionQuery :: FunctionDeclaration { index, .. }
208- | FunctionQuery :: FunctionExpression { index, .. } => * index,
233+ | FunctionQuery :: FunctionExpression { index, .. }
234+ | FunctionQuery :: PrivateMethod { index, .. } => * index,
209235 }
210236 }
211237
212238 #[ must_use]
213239 pub ( crate ) fn class_name ( & self ) -> Option < & str > {
214240 match self {
215241 FunctionQuery :: ClassConstructor { class_name, .. }
216- | FunctionQuery :: ClassMethod { class_name, .. } => Some ( class_name) ,
242+ | FunctionQuery :: ClassMethod { class_name, .. }
243+ | FunctionQuery :: PrivateMethod { class_name, .. } => Some ( class_name) ,
217244 _ => None ,
218245 }
219246 }
@@ -240,7 +267,7 @@ impl FunctionQuery {
240267 is_export_alias,
241268 ..
242269 } => Some ( ( expression_name, * is_export_alias) ) ,
243- FunctionQuery :: ObjectMethod { .. } => None ,
270+ FunctionQuery :: ObjectMethod { .. } | FunctionQuery :: PrivateMethod { .. } => None ,
244271 }
245272 }
246273
@@ -282,4 +309,10 @@ impl FunctionQuery {
282309 matches ! ( self . typ( ) , FunctionType :: Method ) && name == self . name ( ) ;
283310 self . maybe_increment_count ( matches_except_count, count)
284311 }
312+
313+ pub fn matches_private_method ( & self , count : & mut usize , name : & str ) -> bool {
314+ let matches_except_count =
315+ matches ! ( self . typ( ) , FunctionType :: PrivateMethod ) && name == self . name ( ) ;
316+ self . maybe_increment_count ( matches_except_count, count)
317+ }
285318}
0 commit comments