Skip to content

Commit 67b1487

Browse files
author
Esben Sparre Andreasen
committed
JS: support React shouldComponentUpdate
1 parent 417dac7 commit 67b1487

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ abstract class ReactComponent extends ASTNode {
182182
)
183183
or
184184
result.flowsToExpr(getStaticMethod("getDerivedStateFromProps").getAReturnedExpr())
185+
or
186+
// shouldComponentUpdate: (nextProps, nextState)
187+
result = DataFlow::parameterNode(getInstanceMethod("shouldComponentUpdate").getParameter(1))
185188
}
186189

187190
/**
@@ -216,6 +219,9 @@ abstract class ReactComponent extends ASTNode {
216219
result.flowsTo(getComponentCreatorSource().getAnInvocation().getArgument(0))
217220
or
218221
result = getADefaultPropsSource()
222+
or
223+
// shouldComponentUpdate: (nextProps, nextState)
224+
result = DataFlow::parameterNode(getInstanceMethod("shouldComponentUpdate").getParameter(0))
219225
}
220226

221227
/**

javascript/ql/test/library-tests/frameworks/ReactJS/ReactComponent_getACandidateStateSource.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| es6.js:14:1:20:1 | class H ... }\\n} | es6.js:18:22:18:31 | { baz: 42} |
22
| rare-lifecycle-methods.js:1:1:11:1 | class C ... }\\n} | rare-lifecycle-methods.js:3:16:3:17 | {} |
3+
| rare-lifecycle-methods.js:1:1:11:1 | class C ... }\\n} | rare-lifecycle-methods.js:5:38:5:46 | nextState |
34
| statePropertyReads.js:1:1:13:1 | class R ... }\\n} | statePropertyReads.js:7:45:7:56 | prevState.p3 |
45
| statePropertyWrites.js:1:1:34:1 | class W ... };\\n} | statePropertyWrites.js:8:18:8:19 | {} |
56
| statePropertyWrites.js:1:1:34:1 | class W ... };\\n} | statePropertyWrites.js:12:18:12:19 | {} |

0 commit comments

Comments
 (0)