@@ -12,7 +12,7 @@ import { state as source, set } from './reactivity/sources.js';
12
12
import { PROXY_PATH_SYMBOL , STATE_SYMBOL } from '#client/constants' ;
13
13
import { UNINITIALIZED } from '../../constants.js' ;
14
14
import * as e from './errors.js' ;
15
- import { get_stack , tag } from './dev/tracing.js' ;
15
+ import { get_stack , tag , tag_proxy } from './dev/tracing.js' ;
16
16
import { tracing_mode_flag } from '../flags/index.js' ;
17
17
18
18
// TODO move all regexes into shared module?
@@ -21,10 +21,9 @@ const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
21
21
/**
22
22
* @template T
23
23
* @param {T } value
24
- * @param {string } [path]
25
24
* @returns {T }
26
25
*/
27
- export function proxy ( value , path ) {
26
+ export function proxy ( value ) {
28
27
// if non-proxyable, or is already a proxy, return `value`
29
28
if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
30
29
return value ;
@@ -39,7 +38,7 @@ export function proxy(value, path) {
39
38
/** @type {Map<any, Source<any>> } */
40
39
var sources = new Map ( ) ;
41
40
var is_proxied_array = is_array ( value ) ;
42
- var version = DEV ? tag ( source ( 0 ) , ` ${ path } version` ) : source ( 0 ) ;
41
+ var version = source ( 0 ) ;
43
42
44
43
var stack = DEV && tracing_mode_flag ? get_stack ( 'CreatedAt' ) : null ;
45
44
var reaction = active_reaction ;
@@ -62,10 +61,12 @@ export function proxy(value, path) {
62
61
if ( is_proxied_array ) {
63
62
// We need to create the length source eagerly to ensure that
64
63
// mutations to the array are properly synced with our proxy
65
- const length_source = source ( /** @type {any[] } */ ( value ) . length , stack ) ;
66
- sources . set ( 'length' , DEV ? tag ( length_source , to_trace_name ( 'length' ) ) : length_source ) ;
64
+ sources . set ( 'length' , source ( /** @type {any[] } */ ( value ) . length , stack ) ) ;
67
65
}
68
66
67
+ /** Used in dev for $inspect.trace() */
68
+ var path = '' ;
69
+
69
70
/** @param {string | symbol } prop */
70
71
function to_trace_name ( prop ) {
71
72
if ( typeof prop === 'symbol' ) return `${ path } [Symbol(${ prop . description ?? '' } )]` ;
@@ -84,7 +85,7 @@ export function proxy(value, path) {
84
85
var label = to_trace_name ( prop ) ;
85
86
86
87
tag ( source , label ) ;
87
- source . v ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
88
+ tag_proxy ( source . v , label ) ;
88
89
}
89
90
}
90
91
@@ -107,13 +108,18 @@ export function proxy(value, path) {
107
108
108
109
if ( s === undefined ) {
109
110
s = with_parent ( ( ) => source ( descriptor . value , stack ) ) ;
110
- s = DEV && typeof prop === 'string' ? tag ( s , to_trace_name ( prop ) ) : s ;
111
111
sources . set ( prop , s ) ;
112
+
113
+ if ( DEV && typeof prop === 'string' ) {
114
+ tag ( s , to_trace_name ( prop ) ) ;
115
+ }
112
116
} else {
113
- set (
114
- s ,
115
- with_parent ( ( ) => proxy ( descriptor . value , to_trace_name ( prop ) ) )
116
- ) ;
117
+ var p = with_parent ( ( ) => proxy ( descriptor . value ) ) ;
118
+ set ( s , p ) ;
119
+
120
+ if ( DEV ) {
121
+ tag_proxy ( p , to_trace_name ( prop ) ) ;
122
+ }
117
123
}
118
124
119
125
return true ;
@@ -125,8 +131,12 @@ export function proxy(value, path) {
125
131
if ( s === undefined ) {
126
132
if ( prop in target ) {
127
133
const s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
128
- sources . set ( prop , DEV ? tag ( s , to_trace_name ( prop ) ) : s ) ;
134
+ sources . set ( prop , s ) ;
129
135
update_version ( version ) ;
136
+
137
+ if ( DEV ) {
138
+ tag ( s , to_trace_name ( prop ) ) ;
139
+ }
130
140
}
131
141
} else {
132
142
// When working with arrays, we need to also ensure we update the length when removing
@@ -160,10 +170,19 @@ export function proxy(value, path) {
160
170
161
171
// create a source, but only if it's an own property and not a prototype property
162
172
if ( s === undefined && ( ! exists || get_descriptor ( target , prop ) ?. writable ) ) {
163
- s = with_parent ( ( ) =>
164
- source ( proxy ( exists ? target [ prop ] : UNINITIALIZED , to_trace_name ( prop ) ) , stack )
165
- ) ;
166
- s = DEV ? tag ( s , to_trace_name ( prop ) ) : s ;
173
+ s = with_parent ( ( ) => {
174
+ var p = proxy ( exists ? target [ prop ] : UNINITIALIZED ) ;
175
+ var s = source ( p , stack ) ;
176
+
177
+ if ( DEV ) {
178
+ var label = to_trace_name ( prop ) ;
179
+ tag ( s , label ) ;
180
+ tag_proxy ( p , label ) ;
181
+ }
182
+
183
+ return s ;
184
+ } ) ;
185
+
167
186
sources . set ( prop , s ) ;
168
187
}
169
188
@@ -211,10 +230,19 @@ export function proxy(value, path) {
211
230
( active_effect !== null && ( ! has || get_descriptor ( target , prop ) ?. writable ) )
212
231
) {
213
232
if ( s === undefined ) {
214
- s = with_parent ( ( ) =>
215
- source ( has ? proxy ( target [ prop ] , to_trace_name ( prop ) ) : UNINITIALIZED , stack )
216
- ) ;
217
- s = DEV ? tag ( s , to_trace_name ( prop ) ) : s ;
233
+ s = with_parent ( ( ) => {
234
+ var p = has ? proxy ( target [ prop ] ) : UNINITIALIZED ;
235
+ var s = source ( p , stack ) ;
236
+
237
+ if ( DEV ) {
238
+ var label = to_trace_name ( prop ) ;
239
+ tag ( s , label ) ;
240
+ tag_proxy ( p , label ) ;
241
+ }
242
+
243
+ return s ;
244
+ } ) ;
245
+
218
246
sources . set ( prop , s ) ;
219
247
}
220
248
@@ -255,12 +283,12 @@ export function proxy(value, path) {
255
283
if ( s === undefined ) {
256
284
if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
257
285
s = with_parent ( ( ) => source ( undefined , stack ) ) ;
258
- var p = with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) ) ;
286
+ var p = with_parent ( ( ) => proxy ( value ) ) ;
259
287
260
288
if ( DEV ) {
261
289
var label = to_trace_name ( prop ) ;
262
290
tag ( s , label ) ;
263
- p ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
291
+ tag_proxy ( p , label ) ;
264
292
}
265
293
266
294
set ( s , p ) ;
@@ -269,11 +297,10 @@ export function proxy(value, path) {
269
297
} else {
270
298
has = s . v !== UNINITIALIZED ;
271
299
272
- p = with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) ) ;
300
+ p = with_parent ( ( ) => proxy ( value ) ) ;
273
301
274
302
if ( DEV ) {
275
- label = to_trace_name ( prop ) ;
276
- p ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
303
+ tag_proxy ( p , to_trace_name ( prop ) ) ;
277
304
}
278
305
279
306
set ( s , p ) ;
0 commit comments