Skip to content

Commit 9ff3d2e

Browse files
author
Esben Sparre Andreasen
committed
JS: introduce ReactComponent::getStaticMethod
1 parent 0d62191 commit 9ff3d2e

File tree

1 file changed

+21
-0
lines changed
  • javascript/ql/src/semmle/javascript/frameworks

1 file changed

+21
-0
lines changed

javascript/ql/src/semmle/javascript/frameworks/React.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ abstract class ReactComponent extends ASTNode {
3434
*/
3535
abstract Function getInstanceMethod(string name);
3636

37+
/**
38+
* Gets a static method of this component with the given name.
39+
*/
40+
abstract Function getStaticMethod(string name);
41+
3742
/**
3843
* Gets the abstract value that represents this component.
3944
*/
@@ -272,6 +277,10 @@ class FunctionalComponent extends ReactComponent, Function {
272277
name = "render" and result = this
273278
}
274279

280+
override Function getStaticMethod(string name) {
281+
none()
282+
}
283+
275284
override DataFlow::SourceNode getADirectPropsAccess() {
276285
result = DataFlow::parameterNode(getParameter(0))
277286
}
@@ -302,6 +311,14 @@ private abstract class SharedReactPreactClassComponent extends ReactComponent, C
302311
result = ClassDefinition.super.getInstanceMethod(name)
303312
}
304313

314+
override Function getStaticMethod(string name) {
315+
exists(MethodDeclaration decl |
316+
decl = getMethod(name) and
317+
decl.isStatic() and
318+
result = decl.getBody()
319+
)
320+
}
321+
305322
override DataFlow::SourceNode getADirectPropsAccess() {
306323
result.(DataFlow::PropRef).accesses(ref(), "props") or
307324
result = DataFlow::parameterNode(getConstructor().getBody().getParameter(0))
@@ -428,6 +445,10 @@ class ES5Component extends ReactComponent, ObjectExpr {
428445
result = getPropertyByName(name).getInit()
429446
}
430447

448+
override Function getStaticMethod(string name) {
449+
none()
450+
}
451+
431452
override DataFlow::SourceNode getADirectPropsAccess() {
432453
result.(DataFlow::PropRef).accesses(ref(), "props")
433454
}

0 commit comments

Comments
 (0)