JS: Move React test predicates into one file

This commit is contained in:
Asger F
2025-06-23 15:37:15 +02:00
parent 980d0f46fa
commit 8ff7182f3a
12 changed files with 56 additions and 76 deletions

View File

@@ -1,3 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent(ReactComponent c) { any() }

View File

@@ -1,5 +0,0 @@
import javascript
query predicate test_ReactComponent_getACandidatePropsValue(DataFlow::Node res) {
exists(ReactComponent c | res = c.getACandidatePropsValue(_))
}

View File

@@ -1,7 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_getACandidateStateSource(
ReactComponent c, DataFlow::SourceNode res
) {
res = c.getACandidateStateSource()
}

View File

@@ -1,5 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_getADirectPropsSource(ReactComponent c, DataFlow::SourceNode res) {
res = c.getADirectPropsAccess()
}

View File

@@ -1,7 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_getAPreviousStateSource(
ReactComponent c, DataFlow::SourceNode res
) {
res = c.getAPreviousStateSource()
}

View File

@@ -1,5 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_getAPropRead(ReactComponent c, string n, DataFlow::PropRead res) {
res = c.getAPropRead(n)
}

View File

@@ -1,5 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_getInstanceMethod(ReactComponent c, string n, Function res) {
res = c.getInstanceMethod(n)
}

View File

@@ -1,3 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_ReactComponent_ref(ReactComponent c, DataFlow::Node res) { res = c.ref() }

View File

@@ -1,17 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_JSXname(JsxElement element, JsxName jsxname, string name, string type) {
name = jsxname.getValue() and
(
jsxname instanceof Identifier and type = "Identifier"
or
jsxname instanceof ThisExpr and type = "thisExpr"
or
jsxname.(DotExpr).getBase() instanceof JsxName and type = "dot"
or
jsxname instanceof JsxQualifiedName and type = "qualifiedName"
) and
element.getNameExpr() = jsxname
}
query ThisExpr test_JsxName_this(JsxElement element) { result.getParentExpr+() = element }

View File

@@ -1,5 +0,0 @@
import semmle.javascript.frameworks.React
query predicate test_getADirectStateAccess(ReactComponent c, DataFlow::SourceNode res) {
res = c.getADirectStateAccess()
}

View File

@@ -1,3 +0,0 @@
import javascript
query predicate test_react(DataFlow::ValueNode nd) { react().flowsTo(nd) }

View File

@@ -1,14 +1,59 @@
import getADirectStateAccess
import ReactComponent_getInstanceMethod
import react
import ReactComponent_getAPreviousStateSource
import ReactComponent_ref
import ReactComponent_getACandidateStateSource
import ReactComponent_getADirectPropsSource
import ReactComponent_getACandidatePropsValue
import ReactComponent
import ReactComponent_getAPropRead
import ReactName
import javascript
import semmle.javascript.frameworks.React
query predicate test_getADirectStateAccess(ReactComponent c, DataFlow::SourceNode res) {
res = c.getADirectStateAccess()
}
query predicate test_ReactComponent_getInstanceMethod(ReactComponent c, string n, Function res) {
res = c.getInstanceMethod(n)
}
query predicate test_react(DataFlow::ValueNode nd) { react().flowsTo(nd) }
query predicate test_ReactComponent_getAPreviousStateSource(
ReactComponent c, DataFlow::SourceNode res
) {
res = c.getAPreviousStateSource()
}
query predicate test_ReactComponent_ref(ReactComponent c, DataFlow::Node res) { res = c.ref() }
query predicate test_ReactComponent_getACandidateStateSource(
ReactComponent c, DataFlow::SourceNode res
) {
res = c.getACandidateStateSource()
}
query predicate test_ReactComponent_getADirectPropsSource(ReactComponent c, DataFlow::SourceNode res) {
res = c.getADirectPropsAccess()
}
query predicate test_ReactComponent_getACandidatePropsValue(DataFlow::Node res) {
exists(ReactComponent c | res = c.getACandidatePropsValue(_))
}
query predicate test_ReactComponent(ReactComponent c) { any() }
query predicate test_ReactComponent_getAPropRead(ReactComponent c, string n, DataFlow::PropRead res) {
res = c.getAPropRead(n)
}
query predicate test_JSXname(JsxElement element, JsxName jsxname, string name, string type) {
name = jsxname.getValue() and
(
jsxname instanceof Identifier and type = "Identifier"
or
jsxname instanceof ThisExpr and type = "thisExpr"
or
jsxname.(DotExpr).getBase() instanceof JsxName and type = "dot"
or
jsxname instanceof JsxQualifiedName and type = "qualifiedName"
) and
element.getNameExpr() = jsxname
}
query ThisExpr test_JsxName_this(JsxElement element) { result.getParentExpr+() = element }
query DataFlow::SourceNode locationSource() { result = DOM::locationSource() }