@@ -12,7 +12,7 @@ import { state as source, set } from './reactivity/sources.js';
1212import { PROXY_PATH_SYMBOL , STATE_SYMBOL } from '#client/constants' ;
1313import { UNINITIALIZED } from '../../constants.js' ;
1414import * 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' ;
1616import { tracing_mode_flag } from '../flags/index.js' ;
1717
1818// TODO move all regexes into shared module?
@@ -21,10 +21,9 @@ const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
2121/**
2222 * @template T
2323 * @param {T } value
24- * @param {string } [path]
2524 * @returns {T }
2625 */
27- export function proxy ( value , path ) {
26+ export function proxy ( value ) {
2827 // if non-proxyable, or is already a proxy, return `value`
2928 if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
3029 return value ;
@@ -39,7 +38,7 @@ export function proxy(value, path) {
3938 /** @type {Map<any, Source<any>> } */
4039 var sources = new Map ( ) ;
4140 var is_proxied_array = is_array ( value ) ;
42- var version = DEV ? tag ( source ( 0 ) , ` ${ path } version` ) : source ( 0 ) ;
41+ var version = source ( 0 ) ;
4342
4443 var stack = DEV && tracing_mode_flag ? get_stack ( 'CreatedAt' ) : null ;
4544 var reaction = active_reaction ;
@@ -62,10 +61,12 @@ export function proxy(value, path) {
6261 if ( is_proxied_array ) {
6362 // We need to create the length source eagerly to ensure that
6463 // 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 ) ) ;
6765 }
6866
67+ /** Used in dev for $inspect.trace() */
68+ var path = '' ;
69+
6970 /** @param {string | symbol } prop */
7071 function to_trace_name ( prop ) {
7172 if ( typeof prop === 'symbol' ) return `${ path } [Symbol(${ prop . description ?? '' } )]` ;
@@ -84,7 +85,7 @@ export function proxy(value, path) {
8485 var label = to_trace_name ( prop ) ;
8586
8687 tag ( source , label ) ;
87- source . v ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
88+ tag_proxy ( source . v , label ) ;
8889 }
8990 }
9091
@@ -107,13 +108,18 @@ export function proxy(value, path) {
107108
108109 if ( s === undefined ) {
109110 s = with_parent ( ( ) => source ( descriptor . value , stack ) ) ;
110- s = DEV && typeof prop === 'string' ? tag ( s , to_trace_name ( prop ) ) : s ;
111111 sources . set ( prop , s ) ;
112+
113+ if ( DEV && typeof prop === 'string' ) {
114+ tag ( s , to_trace_name ( prop ) ) ;
115+ }
112116 } 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+ }
117123 }
118124
119125 return true ;
@@ -125,8 +131,12 @@ export function proxy(value, path) {
125131 if ( s === undefined ) {
126132 if ( prop in target ) {
127133 const s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
128- sources . set ( prop , DEV ? tag ( s , to_trace_name ( prop ) ) : s ) ;
134+ sources . set ( prop , s ) ;
129135 update_version ( version ) ;
136+
137+ if ( DEV ) {
138+ tag ( s , to_trace_name ( prop ) ) ;
139+ }
130140 }
131141 } else {
132142 // When working with arrays, we need to also ensure we update the length when removing
@@ -160,10 +170,19 @@ export function proxy(value, path) {
160170
161171 // create a source, but only if it's an own property and not a prototype property
162172 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+
167186 sources . set ( prop , s ) ;
168187 }
169188
@@ -211,10 +230,19 @@ export function proxy(value, path) {
211230 ( active_effect !== null && ( ! has || get_descriptor ( target , prop ) ?. writable ) )
212231 ) {
213232 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+
218246 sources . set ( prop , s ) ;
219247 }
220248
@@ -255,12 +283,12 @@ export function proxy(value, path) {
255283 if ( s === undefined ) {
256284 if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
257285 s = with_parent ( ( ) => source ( undefined , stack ) ) ;
258- var p = with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) ) ;
286+ var p = with_parent ( ( ) => proxy ( value ) ) ;
259287
260288 if ( DEV ) {
261289 var label = to_trace_name ( prop ) ;
262290 tag ( s , label ) ;
263- p ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
291+ tag_proxy ( p , label ) ;
264292 }
265293
266294 set ( s , p ) ;
@@ -269,11 +297,10 @@ export function proxy(value, path) {
269297 } else {
270298 has = s . v !== UNINITIALIZED ;
271299
272- p = with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) ) ;
300+ p = with_parent ( ( ) => proxy ( value ) ) ;
273301
274302 if ( DEV ) {
275- label = to_trace_name ( prop ) ;
276- p ?. [ PROXY_PATH_SYMBOL ] ?. ( label ) ;
303+ tag_proxy ( p , to_trace_name ( prop ) ) ;
277304 }
278305
279306 set ( s , p ) ;
0 commit comments