mirror of
https://github.com/github/codeql.git
synced 2026-02-12 05:01:06 +01:00
Add react precallgraphstep useRef
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Added PreCallGraphStep flow model for React's `useRef` hook.
|
||||
@@ -612,6 +612,25 @@ private class UseStateStep extends PreCallGraphStep {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Step through a `useRef` call.
|
||||
*
|
||||
* It returns a pair of the initial state, and an object with a single property (current) potentially containing an input value.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const inputRef1 = useRef(initialValue);
|
||||
* ```
|
||||
*/
|
||||
private class UseRefStep extends PreCallGraphStep {
|
||||
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
|
||||
exists(DataFlow::CallNode call | call = react().getAMemberCall("useRef") |
|
||||
pred = call.getArgument(0) and // initial state
|
||||
succ = call.getAPropertyRead("current")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A step through a React context object.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user