Skip to content

Commit 61ee193

Browse files
authored
Merge pull request github#6197 from asgerf/js/recompose
Approved by esbena
2 parents 0cf9c95 + 993cc29 commit 61ee193

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lgtm,codescanning
2+
* Improved analysis of React components that has passed through a higher-order component
3+
from the `recompose` library.

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import javascript
66

77
/**
88
* A call to a function that constructs a function composition `f(g(h(...)))` from a
9-
* series functions `f, g, h, ...`.
9+
* series of functions `f, g, h, ...`.
1010
*/
1111
class FunctionCompositionCall extends DataFlow::CallNode {
1212
FunctionCompositionCall::Range range;
@@ -35,7 +35,7 @@ class FunctionCompositionCall extends DataFlow::CallNode {
3535
}
3636

3737
/** Gets any of the functions being composed. */
38-
final DataFlow::Node getAnOperandFunction() { result = getOperandFunction(_) }
38+
final DataFlow::FunctionNode getAnOperandFunction() { result = getOperandFunction(_) }
3939

4040
/** Gets the number of functions being composed. */
4141
int getNumOperand() { result = range.getNumOperand() }
@@ -88,15 +88,17 @@ module FunctionCompositionCall {
8888
RightToLeft() {
8989
this = DataFlow::moduleImport(["compose-function"]).getACall()
9090
or
91-
this = DataFlow::moduleMember(["redux", "ramda", "@reduxjs/toolkit"], "compose").getACall()
91+
this =
92+
DataFlow::moduleMember(["redux", "ramda", "@reduxjs/toolkit", "recompose"], "compose")
93+
.getACall()
9294
or
9395
this = LodashUnderscore::member("flowRight").getACall()
9496
}
9597

9698
override DataFlow::Node getOperandNode(int i) { result = getEffectiveArgument(i) }
9799
}
98100

99-
/** A call whose arguments are functions `f,g,h` which are composed into `f(g(h(...))` */
101+
/** A call whose arguments are functions `f,g,h` which are composed into `h(g(f(...))` */
100102
private class LeftToRight extends WithArrayOverloading {
101103
LeftToRight() {
102104
this = DataFlow::moduleImport("just-compose").getACall()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ private DataFlow::SourceNode higherOrderComponentBuilder() {
777777
or
778778
result = DataFlow::moduleMember("redux-form", "reduxForm").getACall()
779779
or
780+
result = DataFlow::moduleMember("recompose", _).getACall()
781+
or
780782
result = reactRouterDom().getAPropertyRead("withRouter")
781783
or
782784
exists(FunctionCompositionCall compose |

javascript/ql/test/library-tests/frameworks/ReactJS/higherOrderComponent.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { compose } from 'redux';
44
import styled from 'styled-components';
55
import unknownFunction from 'somewhere';
66
import { hot } from 'react-hot-loader';
7+
import { withState } from 'recompose';
78

89
import { MyComponent } from './exportedComponent';
910

@@ -22,4 +23,6 @@ const withConnect = connect(mapStateToProps, mapDispatchToProps);
2223

2324
const ConnectedComponent = compose(withConnect, unknownFunction)(StyledComponent);
2425

25-
export default hot(module)(memo(ConnectedComponent));
26+
const ConnectedComponent2 = withState('counter', 'setCounter', 0)(ConnectedComponent);
27+
28+
export default hot(module)(memo(ConnectedComponent2));

0 commit comments

Comments
 (0)