1
+ /* eslint-disable no-control-regex */
2
+
1
3
import { str as crc32_str } from "crc-32" ;
2
4
3
5
import { getCollectionHandlers , shouldInstrument } from "./shouldInstrument" ;
4
6
import { weakMemoizeArray } from "./weakMemoize" ;
5
7
import { EDGE , memoizedBuildTrie } from "./objectTrie" ;
6
8
import { addDiffer , resetDiffers } from "./differs" ;
7
9
import { proxyPolyfill } from './proxy-polyfill' ;
10
+ import { escapeKey , unescapeKey } from "./escapeKey" ;
8
11
9
12
const hasProxy = typeof Proxy !== 'undefined' ;
10
13
const ProxyConstructor = hasProxy ? Proxy : proxyPolyfill ( ) ;
@@ -98,7 +101,7 @@ export function proxyfy(state, report, suffix = '', fingerPrint, ProxyMap, contr
98
101
if ( nextItem . done && ! nextItem . value ) {
99
102
return ;
100
103
}
101
- return proxyValue ( subKey , nextItem . value )
104
+ return proxyValue ( subKey , subKey , nextItem . value )
102
105
}
103
106
} ;
104
107
} ;
@@ -110,8 +113,8 @@ export function proxyfy(state, report, suffix = '', fingerPrint, ProxyMap, contr
110
113
}
111
114
} ;
112
115
113
- const proxyValue = ( key , value ) => {
114
- const thisId = report ( suffix , key ) ;
116
+ const proxyValue = ( key , reportValue , value ) => {
117
+ const thisId = report ( suffix , reportValue ) ;
115
118
const type = typeof value ;
116
119
117
120
@@ -122,9 +125,9 @@ export function proxyfy(state, report, suffix = '', fingerPrint, ProxyMap, contr
122
125
if ( hasCollectionHandlers ) {
123
126
switch ( key ) {
124
127
case 'get' :
125
- return key => proxyValue ( key , state . get ( key ) ) ;
128
+ return key => proxyValue ( key , escapeKey ( key ) , state . get ( key ) ) ;
126
129
case 'has' :
127
- return key => proxyValue ( key , state . has ( key ) ) ;
130
+ return key => proxyValue ( key , escapeKey ( key ) , state . has ( key ) ) ;
128
131
case 'keys' :
129
132
return ( ) => state . keys ( ) ;
130
133
case 'values' :
@@ -173,7 +176,7 @@ export function proxyfy(state, report, suffix = '', fingerPrint, ProxyMap, contr
173
176
}
174
177
175
178
if ( typeof prop === 'string' ) {
176
- return proxyValue ( prop , storedValue ) ;
179
+ return proxyValue ( prop , escapeKey ( prop ) , storedValue ) ;
177
180
}
178
181
179
182
return storedValue ;
@@ -249,7 +252,7 @@ const memoizedCollectValuables = weakMemoizeArray(collectValuables);
249
252
const get = ( target , path ) => {
250
253
let result = target ;
251
254
for ( let i = 1 ; i < path . length && result ; ++ i ) {
252
- const key = path [ i ] ;
255
+ const key = unescapeKey ( path [ i ] ) ;
253
256
if ( key [ 0 ] === '!' ) {
254
257
if ( key === objectKeysMarker ) {
255
258
return Object . keys ( result ) . map ( crc32_str ) . reduce ( ( acc , x ) => acc ^ x , 0 ) ;
0 commit comments