Skip to content

Commit e4ea0cc

Browse files
committed
Merged ES6Class into FunctionStyleClass
1 parent 008dd3f commit e4ea0cc

File tree

1 file changed

+56
-79
lines changed
  • javascript/ql/lib/semmle/javascript/dataflow

1 file changed

+56
-79
lines changed

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 56 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,81 +1214,6 @@ module ClassNode {
12141214
DataFlow::Node getADecorator() { none() }
12151215
}
12161216

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-
12921217
private DataFlow::PropRef getAPrototypeReferenceInFile(string name, File f) {
12931218
result.getBase() = AccessPath::getAReferenceOrAssignmentTo(name) and
12941219
result.getPropertyName() = "prototype" and
@@ -1313,12 +1238,16 @@ module ClassNode {
13131238

13141239
/**
13151240
* 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.
13161242
*/
13171243
class FunctionStyleClass extends Range, DataFlow::ValueNode {
1318-
override Function astNode;
1244+
override AST::ValueNode astNode;
13191245
AbstractFunction function;
13201246

13211247
FunctionStyleClass() {
1248+
astNode instanceof ClassDefinition
1249+
or
1250+
astNode instanceof Function and
13221251
function.getFunction() = astNode and
13231252
(
13241253
exists(getAFunctionValueWithPrototype(function))
@@ -1333,11 +1262,17 @@ module ClassNode {
13331262
)
13341263
}
13351264

1336-
override string getName() { result = astNode.getName() }
1265+
override string getName() {
1266+
result = [astNode.(Function).getName(), astNode.(ClassDefinition).getName()]
1267+
}
13371268

1338-
override string describe() { result = astNode.describe() }
1269+
override string describe() {
1270+
result = [astNode.(Function).describe(), astNode.(ClassDefinition).describe()]
1271+
}
13391272

1340-
override FunctionNode getConstructor() { result = this }
1273+
override FunctionNode getConstructor() {
1274+
result = this or result = astNode.(ClassDefinition).getConstructor().getBody().flow()
1275+
}
13411276

13421277
private PropertyAccessor getAnAccessor(MemberKind kind) {
13431278
result.getObjectExpr() = this.getAPrototypeReference().asExpr() and
@@ -1362,6 +1297,13 @@ module ClassNode {
13621297
accessor.getName() = name and
13631298
result = accessor.getInit().flow()
13641299
)
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+
)
13651307
}
13661308

13671309
override FunctionNode getAnInstanceMember(MemberKind kind) {
@@ -1375,14 +1317,35 @@ module ClassNode {
13751317
accessor = this.getAnAccessor(kind) and
13761318
result = accessor.getInit().flow()
13771319
)
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+
)
13781327
}
13791328

13801329
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
13811337
kind.isMethod() and
13821338
result = this.getAPropertySource(name)
13831339
}
13841340

13851341
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
13861349
kind.isMethod() and
13871350
result = this.getAPropertySource()
13881351
}
@@ -1431,6 +1394,20 @@ module ClassNode {
14311394
this = inheritsCall.getArgument(0).getALocalSource() and
14321395
result = inheritsCall.getArgument(1)
14331396
)
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()
14341411
}
14351412
}
14361413
}

0 commit comments

Comments
 (0)