@@ -11,12 +11,13 @@ use swc_common::{
11
11
BytePos , FileName , Mark , SourceMap , Span , Spanned ,
12
12
} ;
13
13
use swc_ecma_ast:: {
14
- ArrowExpr , BindingIdent , Class , ClassDecl , ClassMethod , ClassProp , EsVersion , ExportAll ,
15
- ExportDecl , ExportSpecifier , FnDecl , ImportDecl , ImportSpecifier , NamedExport , Param , Pat ,
16
- Program , TsAsExpr , TsConstAssertion , TsEnumDecl , TsExportAssignment , TsImportEqualsDecl ,
17
- TsIndexSignature , TsInstantiation , TsInterfaceDecl , TsModuleDecl , TsModuleName ,
18
- TsNamespaceDecl , TsNonNullExpr , TsParamPropParam , TsSatisfiesExpr , TsTypeAliasDecl , TsTypeAnn ,
19
- TsTypeAssertion , TsTypeParamDecl , TsTypeParamInstantiation , VarDecl ,
14
+ ArrowExpr , BindingIdent , Class , ClassDecl , ClassMethod , ClassProp , Decl , DoWhileStmt ,
15
+ EsVersion , ExportAll , ExportDecl , ExportSpecifier , FnDecl , ForInStmt , ForOfStmt , ForStmt ,
16
+ IfStmt , ImportDecl , ImportSpecifier , NamedExport , Param , Pat , Program , Stmt , TsAsExpr ,
17
+ TsConstAssertion , TsEnumDecl , TsExportAssignment , TsImportEqualsDecl , TsIndexSignature ,
18
+ TsInstantiation , TsInterfaceDecl , TsModuleDecl , TsModuleName , TsNamespaceDecl , TsNonNullExpr ,
19
+ TsParamPropParam , TsSatisfiesExpr , TsTypeAliasDecl , TsTypeAnn , TsTypeAssertion ,
20
+ TsTypeParamDecl , TsTypeParamInstantiation , VarDecl , WhileStmt ,
20
21
} ;
21
22
use swc_ecma_parser:: {
22
23
lexer:: Lexer ,
@@ -910,8 +911,76 @@ impl Visit for TsStrip {
910
911
911
912
n. visit_children_with ( self ) ;
912
913
}
914
+
915
+ fn visit_if_stmt ( & mut self , n : & IfStmt ) {
916
+ n. visit_children_with ( self ) ;
917
+
918
+ if n. cons . is_ts_stmt ( ) {
919
+ self . add_overwrite ( n. cons . span_lo ( ) , b';' ) ;
920
+ }
921
+
922
+ if let Some ( alt) = & n. alt {
923
+ if alt. is_ts_stmt ( ) {
924
+ self . add_overwrite ( alt. span_lo ( ) , b';' ) ;
925
+ }
926
+ }
927
+ }
928
+
929
+ fn visit_for_stmt ( & mut self , n : & ForStmt ) {
930
+ n. visit_children_with ( self ) ;
931
+
932
+ if n. body . is_ts_stmt ( ) {
933
+ self . add_overwrite ( n. body . span_lo ( ) , b';' ) ;
934
+ }
935
+ }
936
+
937
+ fn visit_for_in_stmt ( & mut self , n : & ForInStmt ) {
938
+ n. visit_children_with ( self ) ;
939
+
940
+ if n. body . is_ts_stmt ( ) {
941
+ self . add_overwrite ( n. body . span_lo ( ) , b';' ) ;
942
+ }
943
+ }
944
+
945
+ fn visit_for_of_stmt ( & mut self , n : & ForOfStmt ) {
946
+ n. visit_children_with ( self ) ;
947
+
948
+ if n. body . is_ts_stmt ( ) {
949
+ self . add_overwrite ( n. body . span_lo ( ) , b';' ) ;
950
+ }
951
+ }
952
+
953
+ fn visit_while_stmt ( & mut self , n : & WhileStmt ) {
954
+ n. visit_children_with ( self ) ;
955
+
956
+ if n. body . is_ts_stmt ( ) {
957
+ self . add_overwrite ( n. body . span_lo ( ) , b';' ) ;
958
+ }
959
+ }
960
+
961
+ fn visit_do_while_stmt ( & mut self , n : & DoWhileStmt ) {
962
+ n. visit_children_with ( self ) ;
963
+
964
+ if n. body . is_ts_stmt ( ) {
965
+ self . add_overwrite ( n. body . span_lo ( ) , b';' ) ;
966
+ }
967
+ }
913
968
}
914
969
970
+ trait IsTsStmt {
971
+ fn is_ts_stmt ( & self ) -> bool ;
972
+ }
973
+
974
+ impl IsTsStmt for Stmt {
975
+ fn is_ts_stmt ( & self ) -> bool {
976
+ match self {
977
+ Stmt :: Decl ( Decl :: TsInterface { .. } | Decl :: TsTypeAlias ( ..) ) => true ,
978
+ Stmt :: Decl ( Decl :: TsModule ( n) ) => n. declare || matches ! ( n. id, TsModuleName :: Str ( ..) ) ,
979
+ Stmt :: Decl ( Decl :: TsEnum ( e) ) => e. declare ,
980
+ _ => false ,
981
+ }
982
+ }
983
+ }
915
984
trait U8Helper {
916
985
fn is_utf8_char_boundary ( & self ) -> bool ;
917
986
}
0 commit comments