@@ -43,7 +43,7 @@ use swc_common::{FileName, SourceFile, SourceMap};
4343use swc_ecmascript:: ast:: EsVersion ;
4444use swc_ecmascript:: parser:: parse_file_as_module;
4545use swc_ecmascript:: transforms:: pass:: noop;
46- use swc_ecmascript:: visit:: Fold ;
46+ use swc_ecmascript:: visit:: { as_folder , Fold } ;
4747
4848pub mod amp_attributes;
4949mod auto_cjs;
@@ -104,9 +104,12 @@ pub struct TransformOptions {
104104
105105 #[ serde( default ) ]
106106 pub modularize_imports : Option < modularize_imports:: Config > ,
107+
108+ #[ serde( default ) ]
109+ pub coverage_instrument : Option < swc_coverage_instrument:: InstrumentOptions > ,
107110}
108111
109- pub fn custom_before_pass < ' a , C : Comments + ' a > (
112+ pub fn custom_before_pass < ' a , C : Comments + ' a + std :: clone :: Clone > (
110113 cm : Arc < SourceMap > ,
111114 file : Arc < SourceFile > ,
112115 opts : & ' a TransformOptions ,
@@ -193,8 +196,8 @@ pub fn custom_before_pass<'a, C: Comments + 'a>(
193196 Either :: Left ( swc_emotion:: EmotionTransformer :: new(
194197 config. clone( ) ,
195198 path,
196- cm,
197- comments,
199+ cm. clone ( ) ,
200+ comments. clone ( ) ,
198201 ) )
199202 } )
200203 } else {
@@ -205,7 +208,18 @@ pub fn custom_before_pass<'a, C: Comments + 'a>(
205208 match & opts. modularize_imports {
206209 Some ( config) => Either :: Left ( modularize_imports:: modularize_imports( config. clone( ) ) ) ,
207210 None => Either :: Right ( noop( ) ) ,
208- }
211+ } ,
212+ match & opts. coverage_instrument {
213+ Some ( config) => Either :: Left ( as_folder(
214+ swc_coverage_instrument:: create_coverage_instrumentation_visitor(
215+ cm,
216+ comments,
217+ config. clone( ) ,
218+ file. name. to_string( )
219+ )
220+ ) ) ,
221+ None => Either :: Right ( noop( ) ) ,
222+ } ,
209223 )
210224}
211225
0 commit comments