@@ -367,11 +367,30 @@ impl<'a> Traverse<'a, TransformState<'a>> for TypeScriptAnnotations<'a, '_> {
367367 _ctx : & mut TraverseCtx < ' a > ,
368368 ) {
369369 // Remove declare declaration
370- stmts. retain (
371- |stmt| {
372- if let Some ( decl) = stmt. as_declaration ( ) { !decl. declare ( ) } else { true }
370+ stmts. retain ( |stmt| match stmt {
371+ // Remove `declare` declarations and type-only declarations,
372+ // such as `declare class A {}` and `type A = number;`.
373+ match_declaration ! ( Statement ) => {
374+ let declaration = stmt. to_declaration ( ) ;
375+ !( declaration. declare ( ) || declaration. is_type ( ) )
376+ }
377+ // Remove export `declare` declarations and type-only declarations,
378+ // such as `export declare class A {}` and `export type A = number;`.
379+ Statement :: ExportNamedDeclaration ( decl) => decl
380+ . declaration
381+ . as_ref ( )
382+ . is_none_or ( |declaration| !( declaration. declare ( ) || declaration. is_type ( ) ) ) ,
383+ Statement :: ExportDefaultDeclaration ( decl) => match & decl. declaration {
384+ // `export default declare class A {}`
385+ ExportDefaultDeclarationKind :: ClassExpression ( class) => !class. declare ,
386+ // `export default declare function A() {}`
387+ ExportDefaultDeclarationKind :: FunctionExpression ( func) => !func. declare ,
388+ // `export default interface A {}`
389+ ExportDefaultDeclarationKind :: TSInterfaceDeclaration ( _) => false ,
390+ _ => true ,
373391 } ,
374- ) ;
392+ _ => true ,
393+ } ) ;
375394 }
376395
377396 fn exit_statement ( & mut self , stmt : & mut Statement < ' a > , ctx : & mut TraverseCtx < ' a > ) {
0 commit comments