@@ -14,12 +14,12 @@ use swc_ecma_ast::{
14
14
ArrayPat , ArrowExpr , AutoAccessor , BindingIdent , Class , ClassDecl , ClassMethod , ClassProp ,
15
15
Constructor , Decl , DefaultDecl , DoWhileStmt , EsVersion , ExportAll , ExportDecl ,
16
16
ExportDefaultDecl , ExportSpecifier , FnDecl , ForInStmt , ForOfStmt , ForStmt , GetterProp , IfStmt ,
17
- ImportDecl , ImportSpecifier , NamedExport , ObjectPat , Param , Pat , PrivateMethod , PrivateProp ,
18
- Program , ReturnStmt , SetterProp , Stmt , ThrowStmt , TsAsExpr , TsConstAssertion , TsEnumDecl ,
19
- TsExportAssignment , TsImportEqualsDecl , TsIndexSignature , TsInstantiation , TsModuleDecl ,
20
- TsModuleName , TsNamespaceDecl , TsNonNullExpr , TsParamPropParam , TsSatisfiesExpr ,
21
- TsTypeAliasDecl , TsTypeAnn , TsTypeAssertion , TsTypeParamDecl , TsTypeParamInstantiation ,
22
- VarDeclarator , WhileStmt , YieldExpr ,
17
+ ImportDecl , ImportSpecifier , ModuleDecl , ModuleItem , NamedExport , ObjectPat , Param , Pat ,
18
+ PrivateMethod , PrivateProp , Program , ReturnStmt , SetterProp , Stmt , ThrowStmt , TsAsExpr ,
19
+ TsConstAssertion , TsEnumDecl , TsExportAssignment , TsImportEqualsDecl , TsIndexSignature ,
20
+ TsInstantiation , TsModuleDecl , TsModuleName , TsNamespaceBody , TsNamespaceDecl , TsNonNullExpr ,
21
+ TsParamPropParam , TsSatisfiesExpr , TsTypeAliasDecl , TsTypeAnn , TsTypeAssertion ,
22
+ TsTypeParamDecl , TsTypeParamInstantiation , VarDeclarator , WhileStmt , YieldExpr ,
23
23
} ;
24
24
use swc_ecma_parser:: {
25
25
lexer:: Lexer ,
@@ -1034,7 +1034,7 @@ impl Visit for TsStrip {
1034
1034
}
1035
1035
1036
1036
fn visit_export_decl ( & mut self , n : & ExportDecl ) {
1037
- if n. decl . is_ts_declare ( ) {
1037
+ if n. decl . is_ts_declare ( ) || n . decl . is_uninstantiated ( ) {
1038
1038
self . add_replacement ( n. span ) ;
1039
1039
self . fix_asi ( n. span ) ;
1040
1040
return ;
@@ -1044,7 +1044,7 @@ impl Visit for TsStrip {
1044
1044
}
1045
1045
1046
1046
fn visit_export_default_decl ( & mut self , n : & ExportDefaultDecl ) {
1047
- if n. decl . is_ts_declare ( ) {
1047
+ if n. decl . is_ts_declare ( ) || n . decl . is_uninstantiated ( ) {
1048
1048
self . add_replacement ( n. span ) ;
1049
1049
self . fix_asi ( n. span ) ;
1050
1050
return ;
@@ -1054,7 +1054,7 @@ impl Visit for TsStrip {
1054
1054
}
1055
1055
1056
1056
fn visit_decl ( & mut self , n : & Decl ) {
1057
- if n. is_ts_declare ( ) {
1057
+ if n. is_ts_declare ( ) || n . is_uninstantiated ( ) {
1058
1058
self . add_replacement ( n. span ( ) ) ;
1059
1059
self . fix_asi ( n. span ( ) ) ;
1060
1060
return ;
@@ -1393,7 +1393,7 @@ trait IsTsDecl {
1393
1393
impl IsTsDecl for Decl {
1394
1394
fn is_ts_declare ( & self ) -> bool {
1395
1395
match self {
1396
- Self :: TsInterface { .. } | Self :: TsTypeAlias ( ..) => true ,
1396
+ Self :: TsInterface ( .. ) | Self :: TsTypeAlias ( ..) => true ,
1397
1397
1398
1398
Self :: TsModule ( module) => module. declare || matches ! ( module. id, TsModuleName :: Str ( ..) ) ,
1399
1399
Self :: TsEnum ( ref r#enum) => r#enum. declare ,
@@ -1419,12 +1419,67 @@ impl IsTsDecl for DefaultDecl {
1419
1419
fn is_ts_declare ( & self ) -> bool {
1420
1420
match self {
1421
1421
Self :: Class ( ..) => false ,
1422
- DefaultDecl :: Fn ( r#fn) => r#fn. function . body . is_none ( ) ,
1423
- DefaultDecl :: TsInterfaceDecl ( ..) => true ,
1422
+ Self :: Fn ( r#fn) => r#fn. function . body . is_none ( ) ,
1423
+ Self :: TsInterfaceDecl ( ..) => true ,
1424
1424
}
1425
1425
}
1426
1426
}
1427
1427
1428
+ trait IsUninstantiated {
1429
+ fn is_uninstantiated ( & self ) -> bool ;
1430
+ }
1431
+
1432
+ impl IsUninstantiated for TsNamespaceBody {
1433
+ fn is_uninstantiated ( & self ) -> bool {
1434
+ match self {
1435
+ Self :: TsModuleBlock ( block) => {
1436
+ block. body . iter ( ) . all ( IsUninstantiated :: is_uninstantiated)
1437
+ }
1438
+ Self :: TsNamespaceDecl ( decl) => decl. body . is_uninstantiated ( ) ,
1439
+ }
1440
+ }
1441
+ }
1442
+
1443
+ impl IsUninstantiated for ModuleItem {
1444
+ fn is_uninstantiated ( & self ) -> bool {
1445
+ match self {
1446
+ Self :: Stmt ( stmt) => stmt. is_uninstantiated ( ) ,
1447
+ Self :: ModuleDecl ( ModuleDecl :: ExportDecl ( ExportDecl { decl, .. } ) ) => {
1448
+ decl. is_uninstantiated ( )
1449
+ }
1450
+ _ => false ,
1451
+ }
1452
+ }
1453
+ }
1454
+
1455
+ impl IsUninstantiated for Stmt {
1456
+ fn is_uninstantiated ( & self ) -> bool {
1457
+ matches ! ( self , Self :: Decl ( decl) if decl. is_uninstantiated( ) )
1458
+ }
1459
+ }
1460
+
1461
+ impl IsUninstantiated for TsModuleDecl {
1462
+ fn is_uninstantiated ( & self ) -> bool {
1463
+ matches ! ( & self . body, Some ( body) if body. is_uninstantiated( ) )
1464
+ }
1465
+ }
1466
+
1467
+ impl IsUninstantiated for Decl {
1468
+ fn is_uninstantiated ( & self ) -> bool {
1469
+ match self {
1470
+ Self :: TsInterface ( ..) | Self :: TsTypeAlias ( ..) => true ,
1471
+ Self :: TsModule ( module) => module. is_uninstantiated ( ) ,
1472
+ _ => false ,
1473
+ }
1474
+ }
1475
+ }
1476
+
1477
+ impl IsUninstantiated for DefaultDecl {
1478
+ fn is_uninstantiated ( & self ) -> bool {
1479
+ matches ! ( self , Self :: TsInterfaceDecl ( ..) )
1480
+ }
1481
+ }
1482
+
1428
1483
trait U8Helper {
1429
1484
fn is_utf8_char_boundary ( & self ) -> bool ;
1430
1485
}
0 commit comments