@@ -1214,81 +1214,6 @@ module ClassNode {
1214
1214
DataFlow:: Node getADecorator ( ) { none ( ) }
1215
1215
}
1216
1216
1217
- /**
1218
- * An ES6 class as a `ClassNode` instance.
1219
- */
1220
- private class ES6Class extends Range , DataFlow:: ValueNode {
1221
- override ClassDefinition astNode ;
1222
-
1223
- override string getName ( ) { result = astNode .getName ( ) }
1224
-
1225
- override string describe ( ) { result = astNode .describe ( ) }
1226
-
1227
- override FunctionNode getConstructor ( ) { result = astNode .getConstructor ( ) .getBody ( ) .flow ( ) }
1228
-
1229
- override FunctionNode getInstanceMember ( string name , MemberKind kind ) {
1230
- exists ( MethodDeclaration method |
1231
- method = astNode .getMethod ( name ) and
1232
- not method .isStatic ( ) and
1233
- kind = MemberKind:: of ( method ) and
1234
- result = method .getBody ( ) .flow ( )
1235
- )
1236
- or
1237
- kind = MemberKind:: method ( ) and
1238
- result = this .getConstructor ( ) .getReceiver ( ) .getAPropertySource ( name )
1239
- }
1240
-
1241
- override FunctionNode getAnInstanceMember ( MemberKind kind ) {
1242
- exists ( MethodDeclaration method |
1243
- method = astNode .getAMethod ( ) and
1244
- not method .isStatic ( ) and
1245
- kind = MemberKind:: of ( method ) and
1246
- result = method .getBody ( ) .flow ( )
1247
- )
1248
- or
1249
- kind = MemberKind:: method ( ) and
1250
- result = this .getConstructor ( ) .getReceiver ( ) .getAPropertySource ( )
1251
- }
1252
-
1253
- override FunctionNode getStaticMember ( string name , MemberKind kind ) {
1254
- exists ( MethodDeclaration method |
1255
- method = astNode .getMethod ( name ) and
1256
- method .isStatic ( ) and
1257
- kind = MemberKind:: of ( method ) and
1258
- result = method .getBody ( ) .flow ( )
1259
- )
1260
- or
1261
- kind .isMethod ( ) and
1262
- result = this .getAPropertySource ( name )
1263
- }
1264
-
1265
- override FunctionNode getAStaticMember ( MemberKind kind ) {
1266
- exists ( MethodDeclaration method |
1267
- method = astNode .getAMethod ( ) and
1268
- method .isStatic ( ) and
1269
- kind = MemberKind:: of ( method ) and
1270
- result = method .getBody ( ) .flow ( )
1271
- )
1272
- or
1273
- kind .isMethod ( ) and
1274
- result = this .getAPropertySource ( )
1275
- }
1276
-
1277
- override DataFlow:: Node getASuperClassNode ( ) { result = astNode .getSuperClass ( ) .flow ( ) }
1278
-
1279
- override TypeAnnotation getFieldTypeAnnotation ( string fieldName ) {
1280
- exists ( FieldDeclaration field |
1281
- field .getDeclaringClass ( ) = astNode and
1282
- fieldName = field .getName ( ) and
1283
- result = field .getTypeAnnotation ( )
1284
- )
1285
- }
1286
-
1287
- override DataFlow:: Node getADecorator ( ) {
1288
- result = astNode .getADecorator ( ) .getExpression ( ) .flow ( )
1289
- }
1290
- }
1291
-
1292
1217
private DataFlow:: PropRef getAPrototypeReferenceInFile ( string name , File f ) {
1293
1218
result .getBase ( ) = AccessPath:: getAReferenceOrAssignmentTo ( name ) and
1294
1219
result .getPropertyName ( ) = "prototype" and
@@ -1313,12 +1238,16 @@ module ClassNode {
1313
1238
1314
1239
/**
1315
1240
* A function definition, targeted by a `new`-call or with prototype manipulation, seen as a `ClassNode` instance.
1241
+ * Or An ES6 class as a `ClassNode` instance.
1316
1242
*/
1317
1243
class FunctionStyleClass extends Range , DataFlow:: ValueNode {
1318
- override Function astNode ;
1244
+ override AST :: ValueNode astNode ;
1319
1245
AbstractFunction function ;
1320
1246
1321
1247
FunctionStyleClass ( ) {
1248
+ astNode instanceof ClassDefinition
1249
+ or
1250
+ astNode instanceof Function and
1322
1251
function .getFunction ( ) = astNode and
1323
1252
(
1324
1253
exists ( getAFunctionValueWithPrototype ( function ) )
@@ -1333,11 +1262,17 @@ module ClassNode {
1333
1262
)
1334
1263
}
1335
1264
1336
- override string getName ( ) { result = astNode .getName ( ) }
1265
+ override string getName ( ) {
1266
+ result = [ astNode .( Function ) .getName ( ) , astNode .( ClassDefinition ) .getName ( ) ]
1267
+ }
1337
1268
1338
- override string describe ( ) { result = astNode .describe ( ) }
1269
+ override string describe ( ) {
1270
+ result = [ astNode .( Function ) .describe ( ) , astNode .( ClassDefinition ) .describe ( ) ]
1271
+ }
1339
1272
1340
- override FunctionNode getConstructor ( ) { result = this }
1273
+ override FunctionNode getConstructor ( ) {
1274
+ result = this or result = astNode .( ClassDefinition ) .getConstructor ( ) .getBody ( ) .flow ( )
1275
+ }
1341
1276
1342
1277
private PropertyAccessor getAnAccessor ( MemberKind kind ) {
1343
1278
result .getObjectExpr ( ) = this .getAPrototypeReference ( ) .asExpr ( ) and
@@ -1362,6 +1297,13 @@ module ClassNode {
1362
1297
accessor .getName ( ) = name and
1363
1298
result = accessor .getInit ( ) .flow ( )
1364
1299
)
1300
+ or
1301
+ exists ( MethodDeclaration method |
1302
+ method = astNode .( ClassDefinition ) .getMethod ( name ) and
1303
+ not method .isStatic ( ) and
1304
+ kind = MemberKind:: of ( method ) and
1305
+ result = method .getBody ( ) .flow ( )
1306
+ )
1365
1307
}
1366
1308
1367
1309
override FunctionNode getAnInstanceMember ( MemberKind kind ) {
@@ -1375,14 +1317,35 @@ module ClassNode {
1375
1317
accessor = this .getAnAccessor ( kind ) and
1376
1318
result = accessor .getInit ( ) .flow ( )
1377
1319
)
1320
+ or
1321
+ exists ( MethodDeclaration method |
1322
+ method = astNode .( ClassDefinition ) .getAMethod ( ) and
1323
+ not method .isStatic ( ) and
1324
+ kind = MemberKind:: of ( method ) and
1325
+ result = method .getBody ( ) .flow ( )
1326
+ )
1378
1327
}
1379
1328
1380
1329
override FunctionNode getStaticMember ( string name , MemberKind kind ) {
1330
+ exists ( MethodDeclaration method |
1331
+ method = astNode .( ClassDefinition ) .getMethod ( name ) and
1332
+ method .isStatic ( ) and
1333
+ kind = MemberKind:: of ( method ) and
1334
+ result = method .getBody ( ) .flow ( )
1335
+ )
1336
+ or
1381
1337
kind .isMethod ( ) and
1382
1338
result = this .getAPropertySource ( name )
1383
1339
}
1384
1340
1385
1341
override FunctionNode getAStaticMember ( MemberKind kind ) {
1342
+ exists ( MethodDeclaration method |
1343
+ method = astNode .( ClassDefinition ) .getAMethod ( ) and
1344
+ method .isStatic ( ) and
1345
+ kind = MemberKind:: of ( method ) and
1346
+ result = method .getBody ( ) .flow ( )
1347
+ )
1348
+ or
1386
1349
kind .isMethod ( ) and
1387
1350
result = this .getAPropertySource ( )
1388
1351
}
@@ -1431,6 +1394,20 @@ module ClassNode {
1431
1394
this = inheritsCall .getArgument ( 0 ) .getALocalSource ( ) and
1432
1395
result = inheritsCall .getArgument ( 1 )
1433
1396
)
1397
+ or
1398
+ result = astNode .( ClassDefinition ) .getSuperClass ( ) .flow ( )
1399
+ }
1400
+
1401
+ override TypeAnnotation getFieldTypeAnnotation ( string fieldName ) {
1402
+ exists ( FieldDeclaration field |
1403
+ field .getDeclaringClass ( ) = astNode and
1404
+ fieldName = field .getName ( ) and
1405
+ result = field .getTypeAnnotation ( )
1406
+ )
1407
+ }
1408
+
1409
+ override DataFlow:: Node getADecorator ( ) {
1410
+ result = astNode .( ClassDefinition ) .getADecorator ( ) .getExpression ( ) .flow ( )
1434
1411
}
1435
1412
}
1436
1413
}
0 commit comments