@@ -8,8 +8,6 @@ import javascript
88 * Provides classes implementing data-flow for Immutable.
99 */
1010private module Immutable {
11- private import DataFlow:: PseudoProperties
12-
1311 /**
1412 * An API entrypoint for the global `Immutable` variable.
1513 */
@@ -40,33 +38,35 @@ private module Immutable {
4038 }
4139
4240 /**
43- * Gets the immutable collection where `pred` has been stored using the pseudoproperty `prop`.
41+ * An instance of any immutable collection.
42+ */
43+ API:: Node immutableCollection ( ) { result = immutableMap ( ) }
44+
45+ /**
46+ * Gets the immutable collection where `pred` has been stored using the name `prop`.
4447 */
4548 DataFlow:: SourceNode storeStep ( DataFlow:: Node pred , string prop ) {
46- exists ( DataFlow:: CallNode call , string key |
47- call = immutableImport ( ) .getMember ( "Map" ) .getACall ( )
48- |
49- prop = mapValueKey ( key ) and
50- pred = call .getOptionArgument ( 0 , key ) and
49+ exists ( DataFlow:: CallNode call | call = immutableImport ( ) .getMember ( "Map" ) .getACall ( ) |
50+ pred = call .getOptionArgument ( 0 , prop ) and
5151 result = call
5252 )
5353 or
5454 exists ( DataFlow:: CallNode call | call = immutableMap ( ) .getMember ( "set" ) .getACall ( ) |
55- prop = mapValue ( call .getArgument ( 0 ) ) and
55+ call .getArgument ( 0 ) . mayHaveStringValue ( prop ) and
5656 pred = call .getArgument ( 1 ) and
5757 result = call
5858 )
5959 }
6060
6161 /**
62- * Gets the value that was stored in the immutable collection `pred` under the pseudoproperty `prop`.
62+ * Gets the value that was stored in the immutable collection `pred` under the name `prop`.
6363 */
6464 DataFlow:: Node loadStep ( DataFlow:: Node pred , string prop ) {
6565 // map.get()
6666 exists ( DataFlow:: MethodCallNode call | call = immutableMap ( ) .getMember ( "get" ) .getACall ( ) |
67+ call .getArgument ( 0 ) .mayHaveStringValue ( prop ) and
6768 pred = call .getReceiver ( ) and
68- result = call and
69- prop = mapValue ( call .getArgument ( 0 ) )
69+ result = call
7070 )
7171 }
7272
@@ -79,6 +79,12 @@ private module Immutable {
7979 pred = call .getReceiver ( ) and
8080 result = call
8181 )
82+ or
83+ // toJS() or any immutable collection converts it to a plain JavaScript object/array.
84+ exists ( DataFlow:: CallNode call | call = immutableCollection ( ) .getMember ( "toJS" ) .getACall ( ) |
85+ pred = call .getReceiver ( ) and
86+ result = call
87+ )
8288 }
8389
8490 /**
0 commit comments