@@ -694,15 +694,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
694
694
695
695
case SyntaxKind . FunctionDeclaration : {
696
696
let functionDeclarationType = AST_NODE_TYPES . FunctionDeclaration ;
697
-
698
- if ( node . modifiers && node . modifiers . length ) {
699
- const isDeclareFunction = nodeUtils . hasModifier (
700
- SyntaxKind . DeclareKeyword ,
701
- node
702
- ) ;
703
- if ( isDeclareFunction ) {
704
- functionDeclarationType = AST_NODE_TYPES . DeclareFunction ;
705
- }
697
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
698
+ functionDeclarationType = AST_NODE_TYPES . TSDeclareFunction ;
706
699
}
707
700
708
701
Object . assign ( result , {
@@ -712,14 +705,18 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
712
705
expression : false ,
713
706
async : nodeUtils . hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
714
707
params : convertParameters ( node . parameters ) ,
715
- body : convertChild ( node . body )
708
+ body : convertChild ( node . body ) || undefined
716
709
} ) ;
717
710
718
711
// Process returnType
719
712
if ( node . type ) {
720
713
( result as any ) . returnType = convertTypeAnnotation ( node . type ) ;
721
714
}
722
715
716
+ if ( functionDeclarationType === AST_NODE_TYPES . TSDeclareFunction ) {
717
+ result . declare = true ;
718
+ }
719
+
723
720
// Process typeParameters
724
721
if ( node . typeParameters && node . typeParameters . length ) {
725
722
result . typeParameters = convertTSTypeParametersToTypeParametersDeclaration (
@@ -758,6 +755,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
758
755
kind : nodeUtils . getDeclarationKind ( node . declarationList )
759
756
} ) ;
760
757
758
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
759
+ result . declare = true ;
760
+ }
761
+
761
762
// check for exports
762
763
result = nodeUtils . fixExports ( node , result as any , ast ) ;
763
764
break ;
@@ -1618,6 +1619,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
1618
1619
) ;
1619
1620
}
1620
1621
1622
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
1623
+ result . declare = true ;
1624
+ }
1625
+
1621
1626
if ( node . decorators ) {
1622
1627
result . decorators = convertDecorators ( node . decorators ) ;
1623
1628
}
@@ -2245,40 +2250,26 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2245
2250
additionalOptions
2246
2251
} ) ;
2247
2252
2248
- /**
2249
- * Convert TypeAliasDeclaration node into VariableDeclaration
2250
- * to allow core rules such as "semi" to work automatically
2251
- */
2252
2253
case SyntaxKind . TypeAliasDeclaration : {
2253
- const typeAliasDeclarator = {
2254
- type : AST_NODE_TYPES . VariableDeclarator ,
2254
+ Object . assign ( result , {
2255
+ type : AST_NODE_TYPES . TSTypeAliasDeclaration ,
2255
2256
id : convertChild ( node . name ) ,
2256
- init : convertChild ( node . type ) ,
2257
- range : [ node . name . getStart ( ast ) , node . end ]
2258
- } ;
2257
+ typeAnnotation : convertChild ( node . type )
2258
+ } ) ;
2259
2259
2260
- ( typeAliasDeclarator as any ) . loc = nodeUtils . getLocFor (
2261
- typeAliasDeclarator . range [ 0 ] ,
2262
- typeAliasDeclarator . range [ 1 ] ,
2263
- ast
2264
- ) ;
2260
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
2261
+ result . declare = true ;
2262
+ }
2265
2263
2266
2264
// Process typeParameters
2267
2265
if ( node . typeParameters && node . typeParameters . length ) {
2268
- ( typeAliasDeclarator as any ) . typeParameters = convertTSTypeParametersToTypeParametersDeclaration (
2266
+ ( result as any ) . typeParameters = convertTSTypeParametersToTypeParametersDeclaration (
2269
2267
node . typeParameters
2270
2268
) ;
2271
2269
}
2272
2270
2273
- Object . assign ( result , {
2274
- type : AST_NODE_TYPES . VariableDeclaration ,
2275
- kind : nodeUtils . getDeclarationKind ( node ) ,
2276
- declarations : [ typeAliasDeclarator ]
2277
- } ) ;
2278
-
2279
2271
// check for exports
2280
2272
result = nodeUtils . fixExports ( node , result as any , ast ) ;
2281
-
2282
2273
break ;
2283
2274
}
2284
2275
@@ -2400,10 +2391,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2400
2391
}
2401
2392
2402
2393
const hasImplementsClause = interfaceHeritageClauses . length > 0 ;
2403
- const hasAbstractKeyword = nodeUtils . hasModifier (
2404
- SyntaxKind . AbstractKeyword ,
2405
- node
2406
- ) ;
2407
2394
const interfaceOpenBrace = nodeUtils . findNextToken (
2408
2395
interfaceLastClassToken ,
2409
2396
ast ,
@@ -2422,7 +2409,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2422
2409
} ;
2423
2410
2424
2411
Object . assign ( result , {
2425
- abstract : hasAbstractKeyword ,
2426
2412
type : AST_NODE_TYPES . TSInterfaceDeclaration ,
2427
2413
body : interfaceBody ,
2428
2414
id : convertChild ( node . name ) ,
@@ -2440,6 +2426,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
2440
2426
if ( node . decorators ) {
2441
2427
result . decorators = convertDecorators ( node . decorators ) ;
2442
2428
}
2429
+ if ( nodeUtils . hasModifier ( SyntaxKind . AbstractKeyword , node ) ) {
2430
+ result . abstract = true ;
2431
+ }
2432
+ if ( nodeUtils . hasModifier ( SyntaxKind . DeclareKeyword , node ) ) {
2433
+ result . declare = true ;
2434
+ }
2443
2435
// check for exports
2444
2436
result = nodeUtils . fixExports ( node , result as any , ast ) ;
2445
2437
0 commit comments