@@ -106,13 +106,14 @@ function isESTreeClassMember(node) {
106
106
}
107
107
108
108
/**
109
- * Returns true if the given node is an async function
110
- * @param {TSNode } node TypeScript AST node
111
- * @returns {boolean } is an async function
109
+ * Checks if a TSNode has a modifier
110
+ * @param {SyntaxKind } modifierKind TypeScript SyntaxKind modifier
111
+ * @param {TSNode } node TypeScript AST node
112
+ * @returns {boolean } has the modifier specified
112
113
*/
113
- function isAsyncFunction ( node ) {
114
+ function hasModifier ( modifierKind , node ) {
114
115
return ! ! node . modifiers && ! ! node . modifiers . length && node . modifiers . some ( function ( modifier ) {
115
- return modifier . kind === SyntaxKind . AsyncKeyword ;
116
+ return modifier . kind === modifierKind ;
116
117
} ) ;
117
118
}
118
119
@@ -905,9 +906,7 @@ module.exports = function(ast, extra) {
905
906
906
907
var functionDeclarationType = "FunctionDeclaration" ;
907
908
if ( node . modifiers && node . modifiers . length ) {
908
- var isDeclareFunction = node . modifiers . some ( function ( modifier ) {
909
- return modifier . kind === ts . SyntaxKind . DeclareKeyword ;
910
- } ) ;
909
+ var isDeclareFunction = hasModifier ( ts . SyntaxKind . DeclareKeyword , node ) ;
911
910
if ( isDeclareFunction ) {
912
911
functionDeclarationType = "DeclareFunction" ;
913
912
}
@@ -925,7 +924,7 @@ module.exports = function(ast, extra) {
925
924
id : convertChild ( node . name ) ,
926
925
generator : ! ! node . asteriskToken ,
927
926
expression : false ,
928
- async : isAsyncFunction ( node ) ,
927
+ async : hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
929
928
params : node . parameters . map ( convertChild ) ,
930
929
body : convertChild ( node . body )
931
930
} ) ;
@@ -1114,7 +1113,7 @@ module.exports = function(ast, extra) {
1114
1113
id : null ,
1115
1114
generator : false ,
1116
1115
expression : false ,
1117
- async : isAsyncFunction ( node ) ,
1116
+ async : hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
1118
1117
body : convertChild ( node . body ) ,
1119
1118
range : [ node . parameters . pos - 1 , result . range [ 1 ] ] ,
1120
1119
loc : {
@@ -1162,15 +1161,9 @@ module.exports = function(ast, extra) {
1162
1161
/**
1163
1162
* TypeScript class methods can be defined as "abstract"
1164
1163
*/
1165
- var methodDefinitionType = "MethodDefinition" ;
1166
- if ( node . modifiers && node . modifiers . length ) {
1167
- var isAbstractMethod = node . modifiers . some ( function ( modifier ) {
1168
- return modifier . kind === ts . SyntaxKind . AbstractKeyword ;
1169
- } ) ;
1170
- if ( isAbstractMethod ) {
1171
- methodDefinitionType = "TSAbstractMethodDefinition" ;
1172
- }
1173
- }
1164
+ var methodDefinitionType = hasModifier ( SyntaxKind . AbstractKeyword , node )
1165
+ ? "TSAbstractMethodDefinition"
1166
+ : "MethodDefinition" ;
1174
1167
1175
1168
assign ( result , {
1176
1169
type : methodDefinitionType ,
@@ -1206,6 +1199,7 @@ module.exports = function(ast, extra) {
1206
1199
case SyntaxKind . Constructor :
1207
1200
1208
1201
var constructorIsStatic = Boolean ( ts . getModifierFlags ( node ) & ts . ModifierFlags . Static ) ,
1202
+ constructorIsAbstract = hasModifier ( SyntaxKind . AbstractKeyword , node ) ,
1209
1203
firstConstructorToken = constructorIsStatic ? ts . findNextToken ( node . getFirstToken ( ) , ast ) : node . getFirstToken ( ) ,
1210
1204
constructorLoc = ast . getLineAndCharacterOfPosition ( node . parameters . pos - 1 ) ,
1211
1205
constructor = {
@@ -1275,7 +1269,7 @@ module.exports = function(ast, extra) {
1275
1269
}
1276
1270
1277
1271
assign ( result , {
1278
- type : "MethodDefinition" ,
1272
+ type : constructorIsAbstract ? "TSAbstractMethodDefinition" : "MethodDefinition" ,
1279
1273
key : constructorKey ,
1280
1274
value : constructor ,
1281
1275
computed : constructorIsComputed ,
@@ -1292,7 +1286,7 @@ module.exports = function(ast, extra) {
1292
1286
generator : ! ! node . asteriskToken ,
1293
1287
params : node . parameters . map ( convertChild ) ,
1294
1288
body : convertChild ( node . body ) ,
1295
- async : isAsyncFunction ( node ) ,
1289
+ async : hasModifier ( SyntaxKind . AbstractKeyword , node ) ,
1296
1290
expression : false
1297
1291
} ) ;
1298
1292
// Process returnType
@@ -1375,7 +1369,7 @@ module.exports = function(ast, extra) {
1375
1369
id : null ,
1376
1370
params : node . parameters . map ( convertChild ) ,
1377
1371
body : convertChild ( node . body ) ,
1378
- async : isAsyncFunction ( node ) ,
1372
+ async : hasModifier ( SyntaxKind . AsyncKeyword , node ) ,
1379
1373
expression : node . body . kind !== SyntaxKind . Block
1380
1374
} ) ;
1381
1375
// Process returnType
@@ -1501,9 +1495,7 @@ module.exports = function(ast, extra) {
1501
1495
range : [ node . getStart ( ) , node . end ] ,
1502
1496
loc : getLoc ( node , ast ) ,
1503
1497
accessibility : getTSNodeAccessibility ( node ) ,
1504
- isReadonly : node . modifiers . some ( function ( modifier ) {
1505
- return modifier . kind === SyntaxKind . ReadonlyKeyword ;
1506
- } ) ,
1498
+ isReadonly : hasModifier ( SyntaxKind . ReadonlyKeyword , node ) ,
1507
1499
parameter : result
1508
1500
} ;
1509
1501
}
@@ -1533,10 +1525,7 @@ module.exports = function(ast, extra) {
1533
1525
* TypeScript class declarations can be defined as "abstract"
1534
1526
*/
1535
1527
if ( node . kind === SyntaxKind . ClassDeclaration ) {
1536
- var isAbstractClass = node . modifiers . some ( function ( modifier ) {
1537
- return modifier . kind === ts . SyntaxKind . AbstractKeyword ;
1538
- } ) ;
1539
- if ( isAbstractClass ) {
1528
+ if ( hasModifier ( SyntaxKind . AbstractKeyword , node ) ) {
1540
1529
classNodeType = "TSAbstract" + classNodeType ;
1541
1530
}
1542
1531
}
0 commit comments