Skip to content

Commit d858384

Browse files
committed
JS: Update Nest model
An external contribution added more uses of the now-deprecated getType() predicate while this PR was open.
1 parent 47a90c8 commit d858384

File tree

1 file changed

+9
-23
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks

1 file changed

+9
-23
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Nest.qll

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -539,46 +539,32 @@ module NestJS {
539539
)
540540
}
541541

542-
private DataFlow::Node getConcreteClassFromProviderTuple(DataFlow::SourceNode tuple) {
543-
result = tuple.getAPropertyWrite("useClass").getRhs()
542+
private DataFlow::ClassNode getConcreteClassFromProviderTuple(DataFlow::SourceNode tuple) {
543+
result = tuple.getAPropertyWrite("useClass").getRhs().asExpr().getNameBinding().getClassNode()
544544
or
545545
exists(DataFlow::FunctionNode f |
546546
f = tuple.getAPropertyWrite("useFactory").getRhs().getAFunctionValue() and
547-
result.getAstNode() = f.getFunction().getAReturnedExpr().getType().(ClassType).getClass()
547+
result = f.getFunction().getAReturnedExpr().getTypeBinding().getAnUnderlyingClass()
548548
)
549549
or
550-
result.getAstNode() =
551-
tuple.getAPropertyWrite("useValue").getRhs().asExpr().getType().(ClassType).getClass()
550+
result =
551+
tuple.getAPropertyWrite("useValue").getRhs().asExpr().getTypeBinding().getAnUnderlyingClass()
552552
}
553553

554-
private predicate providerPair(DataFlow::Node interface, DataFlow::Node concreteClass) {
554+
private predicate providerPair(DataFlow::ClassNode interface, DataFlow::ClassNode concreteClass) {
555555
exists(DataFlow::SourceNode tuple |
556556
tuple = providerTuple().getALocalSource() and
557-
interface = tuple.getAPropertyWrite("provide").getRhs() and
557+
interface =
558+
tuple.getAPropertyWrite("provide").getRhs().asExpr().getNameBinding().getClassNode() and
558559
concreteClass = getConcreteClassFromProviderTuple(tuple)
559560
)
560561
}
561562

562-
/** Gets the class being referenced at `node` without relying on the call graph. */
563-
private DataFlow::ClassNode getClassFromNode(DataFlow::Node node) {
564-
result = node.asExpr().getNameBinding().getClassNode()
565-
}
566-
567-
private predicate providerClassPair(
568-
DataFlow::ClassNode interface, DataFlow::ClassNode concreteClass
569-
) {
570-
exists(DataFlow::Node interfaceNode, DataFlow::Node concreteClassNode |
571-
providerPair(interfaceNode, concreteClassNode) and
572-
interface = getClassFromNode(interfaceNode) and
573-
concreteClass = getClassFromNode(concreteClassNode)
574-
)
575-
}
576-
577563
private class DependencyInjectionStep extends PreCallGraphStep {
578564
override predicate classInstanceSource(DataFlow::ClassNode cls, DataFlow::Node node) {
579565
exists(DataFlow::ClassNode interfaceClass |
580566
node.asExpr().getTypeBinding().getTypeDefinition() = interfaceClass.getAstNode() and
581-
providerClassPair(interfaceClass, cls)
567+
providerPair(interfaceClass, cls)
582568
)
583569
}
584570
}

0 commit comments

Comments
 (0)