@@ -66,6 +66,19 @@ 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+
6982 fn create_tracing_channel ( & self ) -> Stmt {
7083 let ch_str = ident ! ( format!( "tr_ch_apm${}" , self . config. get_identifier_name( ) ) ) ;
7184 let channel_string = Expr :: Lit ( Lit :: Str ( Str {
@@ -99,7 +112,7 @@ impl Instrumentation {
99112
100113 let original_params: Vec < Pat > = params. iter ( ) . map ( |p| p. pat . clone ( ) ) . collect ( ) ;
101114
102- let wrapped_fn = new_fn ( original_body, original_params) ;
115+ let wrapped_fn = self . new_fn ( original_body, original_params) ;
103116
104117 let traced_body = BlockStmt {
105118 span : Span :: default ( ) ,
@@ -110,7 +123,7 @@ impl Instrumentation {
110123 ] ,
111124 } ;
112125
113- let traced_fn = new_fn ( traced_body, vec ! [ ] ) ;
126+ let traced_fn = self . new_fn ( traced_body, vec ! [ ] ) ;
114127
115128 let id_name = self . config . get_identifier_name ( ) ;
116129 let ch_ident = ident ! ( format!( "tr_ch_apm${}" , & id_name) ) ;
@@ -385,21 +398,3 @@ pub fn get_script_start_index(script: &Script) -> usize {
385398 }
386399 0
387400}
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- }
0 commit comments