Skip to content

Commit a342fa3

Browse files
author
Esben Sparre Andreasen
committed
JS: support React getSnapshotBeforeUpdate
1 parent 67b1487 commit a342fa3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ abstract class ReactComponent extends ASTNode {
207207
// getDerivedStateFromProps: (props, state)
208208
callback = getStaticMethod("getDerivedStateFromProps").flow() and
209209
stateParameterIndex = 1
210+
or
211+
// getSnapshotBeforeUpdate: (prevProps, prevState)
212+
callback = getInstanceMethod("getSnapshotBeforeUpdate").flow() and
213+
stateParameterIndex = 1
210214
)
211215
}
212216

@@ -258,6 +262,11 @@ abstract class ReactComponent extends ASTNode {
258262
// getDerivedStateFromProps: (props, state)
259263
callback = getStaticMethod("getDerivedStateFromProps").flow() and
260264
propsParameterIndex = 0
265+
or
266+
// getSnapshotBeforeUpdate: (prevProps, prevState)
267+
callback = getInstanceMethod("getSnapshotBeforeUpdate").flow() and
268+
propsParameterIndex = 0
269+
261270
)
262271
}
263272

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| rare-lifecycle-methods.js:1:1:11:1 | class C ... }\\n} | rare-lifecycle-methods.js:2:44:2:48 | state |
2+
| rare-lifecycle-methods.js:1:1:11:1 | class C ... }\\n} | rare-lifecycle-methods.js:8:40:8:48 | prevState |
23
| statePropertyReads.js:1:1:13:1 | class R ... }\\n} | statePropertyReads.js:7:24:7:32 | prevState |
34
| statePropertyReads.js:1:1:13:1 | class R ... }\\n} | statePropertyReads.js:10:35:10:43 | prevState |

0 commit comments

Comments
 (0)