@@ -113,6 +113,7 @@ pub extern crate swc_atoms as atoms;
113
113
extern crate swc_common as common;
114
114
115
115
use std:: {
116
+ cell:: RefCell ,
116
117
fs:: { read_to_string, File } ,
117
118
io:: ErrorKind ,
118
119
path:: { Path , PathBuf } ,
@@ -136,7 +137,7 @@ use swc_common::{
136
137
pub use swc_compiler_base:: { PrintArgs , TransformOutput } ;
137
138
pub use swc_config:: config_types:: { BoolConfig , BoolOr , BoolOrDataConfig } ;
138
139
use swc_ecma_ast:: { EsVersion , Program } ;
139
- use swc_ecma_codegen:: { to_code , Node } ;
140
+ use swc_ecma_codegen:: { to_code_with_comments , Node } ;
140
141
use swc_ecma_loader:: resolvers:: {
141
142
lru:: CachingResolver , node:: NodeModulesResolver , tsc:: TsConfigResolver ,
142
143
} ;
@@ -724,7 +725,7 @@ impl Compiler {
724
725
None
725
726
} ;
726
727
727
- self . apply_transforms ( handler, fm. clone ( ) , orig. as_ref ( ) , config)
728
+ self . apply_transforms ( handler, comments . clone ( ) , fm. clone ( ) , orig. as_ref ( ) , config)
728
729
} )
729
730
}
730
731
@@ -944,6 +945,7 @@ impl Compiler {
944
945
fn apply_transforms (
945
946
& self ,
946
947
handler : & Handler ,
948
+ comments : SingleThreadedComments ,
947
949
fm : Arc < SourceFile > ,
948
950
orig : Option < & sourcemap:: SourceMap > ,
949
951
config : BuiltInput < impl swc_ecma_visit:: Fold > ,
@@ -971,6 +973,12 @@ impl Compiler {
971
973
} ;
972
974
973
975
let dts_code = if emit_dts && program. is_module ( ) {
976
+ let ( leading, trailing) = comments. borrow_all ( ) ;
977
+
978
+ let leading = std:: rc:: Rc :: new ( RefCell :: new ( leading. clone ( ) ) ) ;
979
+ let trailing = std:: rc:: Rc :: new ( RefCell :: new ( trailing. clone ( ) ) ) ;
980
+
981
+ let comments = SingleThreadedComments :: from_leading_and_trailing ( leading, trailing) ;
974
982
let mut checker = FastDts :: new ( fm. name . clone ( ) ) ;
975
983
let mut module = program. clone ( ) . expect_module ( ) ;
976
984
@@ -983,7 +991,7 @@ impl Compiler {
983
991
. struct_span_err ( range. span , & issue. to_string ( ) )
984
992
. emit ( ) ;
985
993
}
986
- let dts_code = to_code ( & module) ;
994
+ let dts_code = to_code_with_comments ( Some ( & comments ) , & module) ;
987
995
Some ( dts_code)
988
996
} else {
989
997
None
0 commit comments