@@ -688,15 +688,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
688
688
689
689
case SyntaxKind . FunctionDeclaration : {
690
690
let functionDeclarationType = AST_NODE_TYPES . FunctionDeclaration ;
691
-
692
- if ( node . modifiers && node . modifiers . length ) {
693
- const isDeclareFunction = nodeUtils . hasModifier (
694
- SyntaxKind . DeclareKeyword ,
695
- node
696
- ) ;
697
- if ( isDeclareFunction ) {
698
- functionDeclarationType = AST_NODE_TYPES . DeclareFunction ;
699
- }
691
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
692
+ functionDeclarationType = AST_NODE_TYPES . TSDeclareFunction ;
700
693
}
701
694
702
695
Object . assign ( result , {
@@ -706,14 +699,18 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
706
699
expression : false ,
707
700
async : nodeUtils . hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
708
701
params : convertParameters ( node . parameters ) ,
709
- body : convertChild ( node . body )
702
+ body : convertChild ( node . body ) || undefined
710
703
} ) ;
711
704
712
705
// Process returnType
713
706
if ( node . type ) {
714
707
( result as any ) . returnType = convertTypeAnnotation ( node . type ) ;
715
708
}
716
709
710
+ if ( functionDeclarationType === AST_NODE_TYPES . TSDeclareFunction ) {
711
+ result . declare = true ;
712
+ }
713
+
717
714
// Process typeParameters
718
715
if ( node . typeParameters && node . typeParameters . length ) {
719
716
result . typeParameters = convertTSTypeParametersToTypeParametersDeclaration (
@@ -752,6 +749,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
752
749
kind : nodeUtils . getDeclarationKind ( node . declarationList )
753
750
} ) ;
754
751
752
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
753
+ result . declare = true ;
754
+ }
755
+
755
756
// check for exports
756
757
result = nodeUtils . fixExports ( node , result as any , ast ) ;
757
758
break ;
@@ -1612,6 +1613,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
1612
1613
) ;
1613
1614
}
1614
1615
1616
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
1617
+ result . declare = true ;
1618
+ }
1619
+
1615
1620
if ( node . decorators ) {
1616
1621
result . decorators = convertDecorators ( node . decorators ) ;
1617
1622
}
@@ -2394,10 +2399,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2394
2399
}
2395
2400
2396
2401
const hasImplementsClause = interfaceHeritageClauses . length > 0 ;
2397
- const hasAbstractKeyword = nodeUtils . hasModifier (
2398
- SyntaxKind . AbstractKeyword ,
2399
- node
2400
- ) ;
2401
2402
const interfaceOpenBrace = nodeUtils . findNextToken (
2402
2403
interfaceLastClassToken ,
2403
2404
ast ,
@@ -2416,7 +2417,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2416
2417
} ;
2417
2418
2418
2419
Object . assign ( result , {
2419
- abstract : hasAbstractKeyword ,
2420
2420
type : AST_NODE_TYPES . TSInterfaceDeclaration ,
2421
2421
body : interfaceBody ,
2422
2422
id : convertChild ( node . name ) ,
@@ -2434,6 +2434,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2434
2434
if ( node . decorators ) {
2435
2435
result . decorators = convertDecorators ( node . decorators ) ;
2436
2436
}
2437
+ if ( nodeUtils . hasModifier ( SyntaxKind . AbstractKeyword , node ) ) {
2438
+ result . abstract = true ;
2439
+ }
2440
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
2441
+ result . declare = true ;
2442
+ }
2437
2443
// check for exports
2438
2444
result = nodeUtils . fixExports ( node , result as any , ast ) ;
2439
2445
0 commit comments