@@ -62,13 +62,10 @@ module Redux {
62
62
StoreCreation ( ) { this = range }
63
63
64
64
/** Gets a reference to the store. */
65
- DataFlow:: SourceNode ref ( ) {
66
- // We happen to know that all store-creation sources have API nodes, so just reuse the API node type tracking
67
- exists ( API:: Node apiNode |
68
- apiNode .getAnImmediateUse ( ) = this and
69
- result = apiNode .getAUse ( )
70
- )
71
- }
65
+ DataFlow:: SourceNode ref ( ) { result = asApiNode ( ) .getAUse ( ) }
66
+
67
+ /** Gets an API node that refers to this store creation. */
68
+ API:: Node asApiNode ( ) { result .getAnImmediateUse ( ) = this }
72
69
73
70
/** Gets the data flow node holding the root reducer for this store. */
74
71
DataFlow:: Node getReducerArg ( ) { result = range .getReducerArg ( ) }
@@ -751,57 +748,34 @@ module Redux {
751
748
}
752
749
753
750
/**
754
- * A source of the `dispatch` function, used as starting point for `getADispatchFunctionReference `.
751
+ * A source of the `dispatch` function, used as starting point for `getADispatchFunctionNode `.
755
752
*/
756
- abstract private class DispatchFunctionSource extends DataFlow :: SourceNode { }
753
+ abstract private class DispatchFunctionSource extends API :: Node { }
757
754
758
755
/**
759
756
* A value that is dispatched, that is, flows to the first argument of `dispatch`
760
757
* (but where the call to `dispatch` is not necessarily explicit in the code).
761
758
*
762
- * Used as starting point for `getADispatchedValueSource `.
759
+ * Used as starting point for `getADispatchedValueNode `.
763
760
*/
764
- abstract private class DispatchedValueSink extends DataFlow:: Node { }
765
-
766
- private class StoreDispatchSource extends DispatchFunctionSource {
767
- StoreDispatchSource ( ) { this = any ( StoreCreation c ) .ref ( ) .getAPropertyRead ( "dispatch" ) }
768
- }
761
+ abstract private class DispatchedValueSink extends API:: Node { }
769
762
770
- /** Gets a data flow node referring to the `dispatch` function. */
771
- private DataFlow:: SourceNode getADispatchFunctionReference ( DataFlow:: TypeTracker t ) {
772
- t .start ( ) and
763
+ /** Gets an API node referring to the Redux `dispatch` function. */
764
+ API:: Node getADispatchFunctionNode ( ) {
773
765
result instanceof DispatchFunctionSource
774
766
or
775
- // When using the redux-thunk middleware, dispatching a function value results in that
776
- // function being invoked with (dispatch, getState).
777
- // We simply assume redux-thunk middleware is always installed.
778
- t .start ( ) and
779
- result = getADispatchedValueSource ( ) .( DataFlow:: FunctionNode ) .getParameter ( 0 )
780
- or
781
- exists ( DataFlow:: TypeTracker t2 | result = getADispatchFunctionReference ( t2 ) .track ( t2 , t ) )
767
+ result = getADispatchedValueNode ( ) .getParameter ( 0 )
782
768
}
783
769
784
- /** Gets a data flow node referring to the `dispatch` function. */
785
- DataFlow:: SourceNode getADispatchFunctionReference ( ) {
786
- result = getADispatchFunctionReference ( DataFlow:: TypeTracker:: end ( ) )
787
- }
788
-
789
- /** Gets a data flow node that is dispatched as an action. */
790
- private DataFlow:: SourceNode getADispatchedValueSource ( DataFlow:: TypeBackTracker t ) {
791
- t .start ( ) and
792
- result = any ( DispatchedValueSink d ) .getALocalSource ( )
793
- or
794
- t .start ( ) and
795
- result = getADispatchFunctionReference ( ) .getACall ( ) .getArgument ( 0 ) .getALocalSource ( )
770
+ /** Gets an API node corresponding to a value being passed to the `dispatch` function. */
771
+ API:: Node getADispatchedValueNode ( ) {
772
+ result instanceof DispatchedValueSink
796
773
or
797
- exists ( DataFlow :: TypeBackTracker t2 | result = getADispatchedValueSource ( t2 ) . backtrack ( t2 , t ) )
774
+ result = getADispatchFunctionNode ( ) . getParameter ( 0 )
798
775
}
799
776
800
- /**
801
- * Gets a data flow node that is dispatched as an action, that is, it flows to the first argument of `dispatch`.
802
- */
803
- DataFlow:: SourceNode getADispatchedValueSource ( ) {
804
- result = getADispatchedValueSource ( DataFlow:: TypeBackTracker:: end ( ) )
777
+ private class StoreDispatchSource extends DispatchFunctionSource {
778
+ StoreDispatchSource ( ) { this = any ( StoreCreation c ) .asApiNode ( ) .getMember ( "dispatch" ) }
805
779
}
806
780
807
781
/** Gets the `action` parameter of a reducer that isn't behind an implied type guard. */
@@ -823,7 +797,7 @@ module Redux {
823
797
/** The return value of a function flowing into `bindActionCreators`, seen as a value that is dispatched. */
824
798
private class BindActionDispatchSink extends DispatchedValueSink {
825
799
BindActionDispatchSink ( ) {
826
- this = any ( BindActionCreatorsCall c ) .getParameter ( 0 ) .getAMember ( ) .getReturn ( ) . getARhs ( )
800
+ this = any ( BindActionCreatorsCall c ) .getParameter ( 0 ) .getAMember ( ) .getReturn ( )
827
801
}
828
802
}
829
803
@@ -958,7 +932,7 @@ module Redux {
958
932
*/
959
933
private DataFlow:: ObjectLiteralNode getAManuallyDispatchedValue ( string actionType ) {
960
934
result .getAPropertyWrite ( "type" ) .getRhs ( ) .mayHaveStringValue ( actionType ) and
961
- result = getADispatchedValueSource ( )
935
+ result = getADispatchedValueNode ( ) . getAValueReachingRhs ( )
962
936
}
963
937
964
938
/**
@@ -1054,8 +1028,7 @@ module Redux {
1054
1028
/** A call to `useDispatch`, as a source of the `dispatch` function. */
1055
1029
private class UseDispatchFunctionSource extends DispatchFunctionSource {
1056
1030
UseDispatchFunctionSource ( ) {
1057
- this =
1058
- API:: moduleImport ( "react-redux" ) .getMember ( "useDispatch" ) .getReturn ( ) .getAnImmediateUse ( )
1031
+ this = API:: moduleImport ( "react-redux" ) .getMember ( "useDispatch" ) .getReturn ( )
1059
1032
}
1060
1033
}
1061
1034
@@ -1136,9 +1109,9 @@ module Redux {
1136
1109
/**
1137
1110
* An API entry point corresponding to a `connect` function which we couldn't recognize exactly.
1138
1111
*
1139
- * The `connect` call is recognized based on an argument being named either `mapStateToProps` or `mapDispatchToProps`.
1112
+ * The `connect` call is recognized based on an argument being named either `mapStateToProps` or `mapDispatchToProps`.
1140
1113
* Used to catch cases where the `connect` function was not recognized by API graphs (usually because of it being
1141
- * wrapped in another function, which API graphs won't look through).
1114
+ * wrapped in another function, which API graphs won't look through).
1142
1115
*/
1143
1116
private class HeuristicConnectEntryPoint extends API:: EntryPoint {
1144
1117
HeuristicConnectEntryPoint ( ) { this = "react-redux-connect" }
@@ -1197,15 +1170,13 @@ module Redux {
1197
1170
1198
1171
/** The first argument to `mapDispatchToProps` as a source of the `dispatch` function */
1199
1172
private class MapDispatchToPropsArg extends DispatchFunctionSource {
1200
- MapDispatchToPropsArg ( ) {
1201
- this = any ( ConnectCall c ) .getMapDispatchToProps ( ) .getParameter ( 0 ) .getAnImmediateUse ( )
1202
- }
1173
+ MapDispatchToPropsArg ( ) { this = any ( ConnectCall c ) .getMapDispatchToProps ( ) .getParameter ( 0 ) }
1203
1174
}
1204
1175
1205
1176
/** If `mapDispatchToProps` is an object, each method's return value is dispatched. */
1206
1177
private class MapDispatchToPropsMember extends DispatchedValueSink {
1207
1178
MapDispatchToPropsMember ( ) {
1208
- this = any ( ConnectCall c ) .getMapDispatchToProps ( ) .getAMember ( ) .getReturn ( ) . getARhs ( )
1179
+ this = any ( ConnectCall c ) .getMapDispatchToProps ( ) .getAMember ( ) .getReturn ( )
1209
1180
}
1210
1181
}
1211
1182
0 commit comments