@@ -66,19 +66,6 @@ impl Instrumentation {
6666 self . has_injected = false ;
6767 }
6868
69- fn new_fn ( & self , body : BlockStmt , params : Vec < Pat > ) -> ArrowExpr {
70- ArrowExpr {
71- params,
72- body : Box :: new ( body. into ( ) ) ,
73- is_async : self . config . function_query . kind ( ) . is_async ( ) ,
74- is_generator : false ,
75- type_params : None ,
76- return_type : None ,
77- span : Span :: default ( ) ,
78- ctxt : SyntaxContext :: empty ( ) ,
79- }
80- }
81-
8269 fn create_tracing_channel ( & self ) -> Stmt {
8370 let ch_str = ident ! ( format!( "tr_ch_apm${}" , self . config. get_identifier_name( ) ) ) ;
8471 let channel_string = Expr :: Lit ( Lit :: Str ( Str {
@@ -112,7 +99,7 @@ impl Instrumentation {
11299
113100 let original_params: Vec < Pat > = params. iter ( ) . map ( |p| p. pat . clone ( ) ) . collect ( ) ;
114101
115- let wrapped_fn = self . new_fn ( original_body, original_params) ;
102+ let wrapped_fn = new_fn ( original_body, original_params) ;
116103
117104 let traced_body = BlockStmt {
118105 span : Span :: default ( ) ,
@@ -123,7 +110,7 @@ impl Instrumentation {
123110 ] ,
124111 } ;
125112
126- let traced_fn = self . new_fn ( traced_body, vec ! [ ] ) ;
113+ let traced_fn = new_fn ( traced_body, vec ! [ ] ) ;
127114
128115 let id_name = self . config . get_identifier_name ( ) ;
129116 let ch_ident = ident ! ( format!( "tr_ch_apm${}" , & id_name) ) ;
@@ -398,3 +385,22 @@ pub fn get_script_start_index(script: &Script) -> usize {
398385 }
399386 0
400387}
388+
389+ #[ must_use]
390+ pub fn new_fn ( body : BlockStmt , params : Vec < Pat > ) -> ArrowExpr {
391+ ArrowExpr {
392+ params,
393+ body : Box :: new ( body. into ( ) ) ,
394+ // if we set this to `true` and it's an async function,
395+ // it will wrap the original promise in a new native one
396+ // which may not be semantically correct in cases where custom
397+ // promises are returned
398+ is_async : false ,
399+ is_generator : false ,
400+ type_params : None ,
401+ return_type : None ,
402+ span : Span :: default ( ) ,
403+ ctxt : SyntaxContext :: empty ( ) ,
404+ }
405+ }
406+
0 commit comments